hedgewars/uAIActions.pas
author nemo
Sat, 09 Feb 2013 20:28:05 -0500
changeset 8492 67d2ad3b3ce9
parent 7901 a86ccf3da9ca
child 9080 9b42757d7e71
permissions -rw-r--r--
Allow moving after firing cleaver. This changes multishoot behaviour quite a bit. Needs a lot of testing.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
     1
(*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 883
diff changeset
     2
 * Hedgewars, a free turn based strategy game
6700
e04da46ee43c the most important commit of the year
koda
parents: 6580
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
     4
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 165
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
57c2ef19f719 Relicense to GPL
unc0rr
parents: 165
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
57c2ef19f719 Relicense to GPL
unc0rr
parents: 165
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
     8
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 165
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
57c2ef19f719 Relicense to GPL
unc0rr
parents: 165
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57c2ef19f719 Relicense to GPL
unc0rr
parents: 165
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57c2ef19f719 Relicense to GPL
unc0rr
parents: 165
diff changeset
    12
 * GNU General Public License for more details.
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    13
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 165
diff changeset
    14
 * You should have received a copy of the GNU General Public License
57c2ef19f719 Relicense to GPL
unc0rr
parents: 165
diff changeset
    15
 * along with this program; if not, write to the Free Software
57c2ef19f719 Relicense to GPL
unc0rr
parents: 165
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
71
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    17
 *)
5f56c6979496 - Changed falling damage scoring
unc0rr
parents: 70
diff changeset
    18
2630
079ef82eac75 revamped file access and debug display
koda
parents: 2599
diff changeset
    19
{$INCLUDE "options.inc"}
079ef82eac75 revamped file access and debug display
koda
parents: 2599
diff changeset
    20
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    21
unit uAIActions;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    22
interface
4357
a1fcfc341a52 Introduce unit uTypes in order to remove some cyclic unit dependencies
unC0Rr
parents: 3407
diff changeset
    23
uses uFloat, uTypes;
2630
079ef82eac75 revamped file access and debug display
koda
parents: 2599
diff changeset
    24
3165
3ec07a7d8456 just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents: 2630
diff changeset
    25
const MAXACTIONS     = 96;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    26
    aia_none       = 0;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    27
    aia_Left       = 1;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    28
    aia_Right      = 2;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    29
    aia_Timer      = 3;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    30
    aia_attack     = 4;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    31
    aia_Up         = 5;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    32
    aia_Down       = 6;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    33
    aia_Switch     = 7;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    34
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    35
    aia_Weapon     = $8000;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    36
    aia_WaitXL     = $8001;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    37
    aia_WaitXR     = $8002;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    38
    aia_LookLeft   = $8003;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    39
    aia_LookRight  = $8004;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    40
    aia_AwareExpl  = $8005;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    41
    aia_HJump      = $8006;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    42
    aia_LJump      = $8007;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    43
    aia_Skip       = $8008;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    44
    aia_Wait       = $8009;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    45
    aia_Put        = $800A;
7197
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
    46
    aia_waitAngle  = $800B;
7416
2f2f78fc65a3 AI uses cake! Known issues: AI could damage itself for no reason, could let cake go looping in a hole with exit closed by AI hog.
unc0rr
parents: 7197
diff changeset
    47
    aia_waitAmmoXY = $800C;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    48
    
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    49
    aim_push       = $8000;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    50
    aim_release    = $8001;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    51
    ai_specmask    = $8000;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    52
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 17
diff changeset
    53
type TAction = record
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    54
        Action: Longword;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    55
        X, Y, Param: LongInt;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    56
        Time: Longword;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    57
        end;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    58
        
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    59
    TActions = record
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    60
        Count, Pos: Longword;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    61
        actions: array[0..Pred(MAXACTIONS)] of TAction;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    62
        Score: LongInt;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    63
        isWalkingToABetterPlace: boolean;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
    64
        end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    65
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 369
diff changeset
    66
procedure AddAction(var Actions: TActions; Action: Longword; Param: LongInt; TimeDelta: Longword; X, Y: LongInt);
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 17
diff changeset
    67
procedure ProcessAction(var Actions: TActions; Me: PGear);
369
2aed85310727 AI compiles, but doesn't work
unc0rr
parents: 351
diff changeset
    68
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    69
implementation
7671
43f38923bc6e Fix some warnings
unc0rr
parents: 7433
diff changeset
    70
uses uAIMisc, uAI, uAmmos, uVariables, uCommands, uUtils, uIO{$IFDEF TRACEAIACTIONS}, uConsole{$ENDIF};
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    71
7028
0f60591f3a16 old typed const moved to their proper unit
koda
parents: 6982
diff changeset
    72
var PrevX: LongInt = 0;
0f60591f3a16 old typed const moved to their proper unit
koda
parents: 6982
diff changeset
    73
    timedelta: Longword = 0;
0f60591f3a16 old typed const moved to their proper unit
koda
parents: 6982
diff changeset
    74
7901
a86ccf3da9ca Update ai actions tracing subsystem
unc0rr
parents: 7721
diff changeset
    75
const ActionIdToStr: array[0..7] of string[16] = (
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    76
{aia_none}           '',
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    77
{aia_Left}           'left',
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    78
{aia_Right}          'right',
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    79
{aia_Timer}          'timer',
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    80
{aia_attack}         'attack',
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    81
{aia_Up}             'up',
6393
701eb3f3556a Make AI use switcher when:
unc0rr
parents: 5419
diff changeset
    82
{aia_Down}           'down',
7901
a86ccf3da9ca Update ai actions tracing subsystem
unc0rr
parents: 7721
diff changeset
    83
{aia_Switch}         'switch'
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 17
diff changeset
    84
                     );
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    85
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 75
diff changeset
    86
{$IFDEF TRACEAIACTIONS}
7901
a86ccf3da9ca Update ai actions tracing subsystem
unc0rr
parents: 7721
diff changeset
    87
const SpecActionIdToStr: array[$8000..$800C] of string[16] = (
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 75
diff changeset
    88
{aia_Weapon}             'aia_Weapon',
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 75
diff changeset
    89
{aia_WaitX}              'aia_WaitX',
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 75
diff changeset
    90
{aia_WaitY}              'aia_WaitY',
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 75
diff changeset
    91
{aia_LookLeft}           'aia_LookLeft',
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 75
diff changeset
    92
{aia_LookRight}          'aia_LookRight',
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 75
diff changeset
    93
{aia_AwareExpl}          'aia_AwareExpl',
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 75
diff changeset
    94
{aia_HJump}              'aia_HJump',
144
e6084b0c9316 - Fix 'new team' regression
unc0rr
parents: 143
diff changeset
    95
{aia_LJump}              'aia_LJump',
193
56885ea29202 Fix bots regressions
unc0rr
parents: 183
diff changeset
    96
{aia_Skip}               'aia_Skip',
7901
a86ccf3da9ca Update ai actions tracing subsystem
unc0rr
parents: 7721
diff changeset
    97
{aia_Wait}               'aia_Wait',
a86ccf3da9ca Update ai actions tracing subsystem
unc0rr
parents: 7721
diff changeset
    98
{aia_Put}                'aia_Put',
a86ccf3da9ca Update ai actions tracing subsystem
unc0rr
parents: 7721
diff changeset
    99
{aia_waitAngle}          'aia_waitAngle',
a86ccf3da9ca Update ai actions tracing subsystem
unc0rr
parents: 7721
diff changeset
   100
{aia_waitAmmoXY}         'aia_waitAmmoXY'
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 75
diff changeset
   101
);
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 75
diff changeset
   102
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 75
diff changeset
   103
procedure DumpAction(Action: TAction; Me: PGear);
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 75
diff changeset
   104
begin
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 75
diff changeset
   105
if (Action.Action and ai_specmask) = 0 then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   106
    WriteLnToConsole('AI action: '+ActionIdToStr[Action.Action])
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   107
else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   108
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   109
    WriteLnToConsole('AI action: '+SpecActionIdToStr[Action.Action]);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   110
    if (Action.Action = aia_WaitXL) or (Action.Action = aia_WaitXR) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   111
        WriteLnToConsole('AI action Wait X = '+IntToStr(Action.Param)+', current X = '+IntToStr(hwRound(Me^.X)))
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   112
        
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   113
    else if (Action.Action = aia_AwareExpl) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   114
        WriteLnToConsole('Aware X = ' + IntToStr(Action.X) + ', Y = ' + IntToStr(Action.Y));
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   115
    end
80
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 75
diff changeset
   116
end;
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 75
diff changeset
   117
{$ENDIF}
3c3dc6a148ca - Fixed bug with hedgehog under water using rope
unc0rr
parents: 75
diff changeset
   118
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 369
diff changeset
   119
procedure AddAction(var Actions: TActions; Action: Longword; Param: LongInt; TimeDelta: Longword; X, Y: LongInt);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   120
begin
7433
c7fff3e61d49 - Implement AI land marks which only used to tracks visited areas on the map for now. Significantly reduces wasting of cpu time by AI checking same place several times (10x or even more in rare cases)
unc0rr
parents: 7416
diff changeset
   121
if Actions.Count < MAXACTIONS then
c7fff3e61d49 - Implement AI land marks which only used to tracks visited areas on the map for now. Significantly reduces wasting of cpu time by AI checking same place several times (10x or even more in rare cases)
unc0rr
parents: 7416
diff changeset
   122
    with Actions do
c7fff3e61d49 - Implement AI land marks which only used to tracks visited areas on the map for now. Significantly reduces wasting of cpu time by AI checking same place several times (10x or even more in rare cases)
unc0rr
parents: 7416
diff changeset
   123
        begin
c7fff3e61d49 - Implement AI land marks which only used to tracks visited areas on the map for now. Significantly reduces wasting of cpu time by AI checking same place several times (10x or even more in rare cases)
unc0rr
parents: 7416
diff changeset
   124
        actions[Count].Action:= Action;
c7fff3e61d49 - Implement AI land marks which only used to tracks visited areas on the map for now. Significantly reduces wasting of cpu time by AI checking same place several times (10x or even more in rare cases)
unc0rr
parents: 7416
diff changeset
   125
        actions[Count].Param:= Param;
c7fff3e61d49 - Implement AI land marks which only used to tracks visited areas on the map for now. Significantly reduces wasting of cpu time by AI checking same place several times (10x or even more in rare cases)
unc0rr
parents: 7416
diff changeset
   126
        actions[Count].X:= X;
c7fff3e61d49 - Implement AI land marks which only used to tracks visited areas on the map for now. Significantly reduces wasting of cpu time by AI checking same place several times (10x or even more in rare cases)
unc0rr
parents: 7416
diff changeset
   127
        actions[Count].Y:= Y;
c7fff3e61d49 - Implement AI land marks which only used to tracks visited areas on the map for now. Significantly reduces wasting of cpu time by AI checking same place several times (10x or even more in rare cases)
unc0rr
parents: 7416
diff changeset
   128
        if Count > 0 then
c7fff3e61d49 - Implement AI land marks which only used to tracks visited areas on the map for now. Significantly reduces wasting of cpu time by AI checking same place several times (10x or even more in rare cases)
unc0rr
parents: 7416
diff changeset
   129
            actions[Count].Time:= TimeDelta
c7fff3e61d49 - Implement AI land marks which only used to tracks visited areas on the map for now. Significantly reduces wasting of cpu time by AI checking same place several times (10x or even more in rare cases)
unc0rr
parents: 7416
diff changeset
   130
        else
c7fff3e61d49 - Implement AI land marks which only used to tracks visited areas on the map for now. Significantly reduces wasting of cpu time by AI checking same place several times (10x or even more in rare cases)
unc0rr
parents: 7416
diff changeset
   131
            actions[Count].Time:= GameTicks + TimeDelta;
c7fff3e61d49 - Implement AI land marks which only used to tracks visited areas on the map for now. Significantly reduces wasting of cpu time by AI checking same place several times (10x or even more in rare cases)
unc0rr
parents: 7416
diff changeset
   132
        inc(Count);
c7fff3e61d49 - Implement AI land marks which only used to tracks visited areas on the map for now. Significantly reduces wasting of cpu time by AI checking same place several times (10x or even more in rare cases)
unc0rr
parents: 7416
diff changeset
   133
        end
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   134
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   135
6474
42e9773eedfd - Improve renderer a bit, disallow nested functions
unc0rr
parents: 6395
diff changeset
   136
procedure CheckHang(Me: PGear);
42e9773eedfd - Improve renderer a bit, disallow nested functions
unc0rr
parents: 6395
diff changeset
   137
begin
42e9773eedfd - Improve renderer a bit, disallow nested functions
unc0rr
parents: 6395
diff changeset
   138
if hwRound(Me^.X) <> PrevX then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   139
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   140
    PrevX:= hwRound(Me^.X);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   141
    timedelta:= 0
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   142
    end else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   143
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   144
        inc(timedelta);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   145
        if timedelta > 1700 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   146
            begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   147
            timedelta:= 0;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   148
            FreeActionsList
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   149
            end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   150
        end
6474
42e9773eedfd - Improve renderer a bit, disallow nested functions
unc0rr
parents: 6395
diff changeset
   151
end;
42e9773eedfd - Improve renderer a bit, disallow nested functions
unc0rr
parents: 6395
diff changeset
   152
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 17
diff changeset
   153
procedure ProcessAction(var Actions: TActions; Me: PGear);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   154
var s: shortstring;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   155
begin
194
88652abdce9a Fixed weird bots behavior
unc0rr
parents: 193
diff changeset
   156
repeat
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 17
diff changeset
   157
if Actions.Pos >= Actions.Count then exit;
7197
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   158
64
9df467527ae5 - Start AI rewrite
unc0rr
parents: 17
diff changeset
   159
with Actions.actions[Actions.Pos] do
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   160
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   161
    if Time > GameTicks then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   162
        exit;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   163
    {$IFDEF TRACEAIACTIONS}
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   164
    DumpAction(Actions.actions[Actions.Pos], Me);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   165
    {$ENDIF}
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   166
    if (Action and ai_specmask) <> 0 then
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   167
        case Action of
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   168
            aia_Weapon: 
7197
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   169
                SetWeapon(TAmmoType(Param));
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   170
            
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   171
            aia_WaitXL: 
7197
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   172
                if hwRound(Me^.X) = Param then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   173
                    begin
7197
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   174
                    Action:= aia_LookLeft;
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   175
                    Time:= GameTicks;
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   176
                    exit
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   177
                    end
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   178
                    else if hwRound(Me^.X) < Param then
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   179
                        begin
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   180
                        //OutError('AI: WaitXL assert (' + IntToStr(hwRound(Me^.X)) + ' < ' + IntToStr(Param) + ')', false);
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   181
                        FreeActionsList;
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   182
                        exit
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   183
                        end
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   184
                    else
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   185
                        begin 
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   186
                        CheckHang(Me);
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   187
                        exit
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   188
                        end;
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   189
                            
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   190
            aia_WaitXR: 
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   191
                if hwRound(Me^.X) = Param then
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   192
                    begin
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   193
                    Action:= aia_LookRight;
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   194
                    Time:= GameTicks;
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   195
                    exit
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   196
                    end
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   197
                    else if hwRound(Me^.X) > Param then
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   198
                        begin
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   199
                        //OutError('AI: WaitXR assert (' + IntToStr(hwRound(Me^.X)) + ' > ' + IntToStr(Param) + ')', false);
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   200
                        FreeActionsList;
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   201
                        exit
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   202
                        end
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   203
                    else
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   204
                        begin 
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   205
                        CheckHang(Me);
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   206
                        exit
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   207
                        end;
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   208
            aia_LookLeft:
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   209
                if not Me^.dX.isNegative then
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   210
                    begin
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   211
                    ParseCommand('+left', true);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   212
                    exit
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   213
                    end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   214
                else
7197
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   215
                    ParseCommand('-left', true);
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   216
            aia_LookRight:
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   217
                if Me^.dX.isNegative then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   218
                    begin
7197
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   219
                    ParseCommand('+right', true);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   220
                    exit
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   221
                    end
7197
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   222
                else ParseCommand('-right', true);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   223
            aia_AwareExpl:
7197
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   224
                AwareOfExplosion(X, Y, Param);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   225
            
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   226
            aia_HJump:
7197
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   227
                ParseCommand('hjump', true);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   228
            
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   229
            aia_LJump:
7197
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   230
                ParseCommand('ljump', true);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   231
            
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   232
            aia_Skip:
7197
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   233
                ParseCommand('skip', true);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   234
            
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   235
            aia_Put:
7197
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   236
                doPut(X, Y, true);
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   237
                
5a9775b97c7e - TestSniperRifle ftw (still needs some consts adjustments, because AI seems to love sniper rifle too much)
unc0rr
parents: 7132
diff changeset
   238
            aia_waitAngle:
7721
2b1ad418ba39 - Fix warnings and hints
unc0rr
parents: 7671
diff changeset
   239
                if LongInt(Me^.Angle) <> Abs(Param) then exit;
7416
2f2f78fc65a3 AI uses cake! Known issues: AI could damage itself for no reason, could let cake go looping in a hole with exit closed by AI hog.
unc0rr
parents: 7197
diff changeset
   240
2f2f78fc65a3 AI uses cake! Known issues: AI could damage itself for no reason, could let cake go looping in a hole with exit closed by AI hog.
unc0rr
parents: 7197
diff changeset
   241
            aia_waitAmmoXY:
7901
a86ccf3da9ca Update ai actions tracing subsystem
unc0rr
parents: 7721
diff changeset
   242
                if (CurAmmoGear <> nil) and ((hwRound(CurAmmoGear^.X) <> X) or (hwRound(CurAmmoGear^.Y) <> Y)) then 
a86ccf3da9ca Update ai actions tracing subsystem
unc0rr
parents: 7721
diff changeset
   243
                    exit;
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   244
            end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   245
        else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   246
            begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   247
            s:= ActionIdToStr[Action];
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   248
            if (Param and ai_specmask) <> 0 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   249
                case Param of
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   250
                aim_push:
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   251
                s:= '+' + s;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   252
                
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   253
                aim_release:
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   254
                s:= '-' + s;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   255
            end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   256
        else if Param <> 0 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   257
            s:= s + ' ' + IntToStr(Param);
369
2aed85310727 AI compiles, but doesn't work
unc0rr
parents: 351
diff changeset
   258
        ParseCommand(s, true)
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   259
        end
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   260
    end;
66
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   261
inc(Actions.Pos);
9643d75baf1e Many AI improvements, bots do think in separate thread
unc0rr
parents: 64
diff changeset
   262
if Actions.Pos <= Actions.Count then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6535
diff changeset
   263
    inc(Actions.actions[Actions.Pos].Time, GameTicks);
194
88652abdce9a Fixed weird bots behavior
unc0rr
parents: 193
diff changeset
   264
until false
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   265
end;
369
2aed85310727 AI compiles, but doesn't work
unc0rr
parents: 351
diff changeset
   266
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   267
end.