hedgewars/uAIActions.pas
changeset 193 56885ea29202
parent 183 57c2ef19f719
child 194 88652abdce9a
equal deleted inserted replaced
192:b644f61e803f 193:56885ea29202
    28       aia_attack     = 4;
    28       aia_attack     = 4;
    29       aia_Up         = 5;
    29       aia_Up         = 5;
    30       aia_Down       = 6;
    30       aia_Down       = 6;
    31 
    31 
    32       aia_Weapon     = $80000000;
    32       aia_Weapon     = $80000000;
    33       aia_WaitX      = $80000001;
    33       aia_WaitXL     = $80000001;
    34       aia_WaitY      = $80000002;
    34       aia_WaitXR     = $80000002;
    35       aia_LookLeft   = $80000003;
    35       aia_LookLeft   = $80000003;
    36       aia_LookRight  = $80000004;
    36       aia_LookRight  = $80000004;
    37       aia_AwareExpl  = $80000005;
    37       aia_AwareExpl  = $80000005;
    38       aia_HJump      = $80000006;
    38       aia_HJump      = $80000006;
    39       aia_LJump      = $80000007;
    39       aia_LJump      = $80000007;
    40       aia_Skip       = $80000008;
    40       aia_Skip       = $80000008;
       
    41       aia_Wait       = $80000009;
    41 
    42 
    42       aim_push       = $80000000;
    43       aim_push       = $80000000;
    43       aim_release    = $80000001;
    44       aim_release    = $80000001;
    44       ai_specmask    = $80000000;
    45       ai_specmask    = $80000000;
    45 
    46 
    69 {aia_Up}             'up',
    70 {aia_Up}             'up',
    70 {aia_Down}           'down'
    71 {aia_Down}           'down'
    71                      );
    72                      );
    72 
    73 
    73 {$IFDEF TRACEAIACTIONS}
    74 {$IFDEF TRACEAIACTIONS}
    74 const SpecActionIdToStr: array[$80000000..$80000008] of string[16] = (
    75 const SpecActionIdToStr: array[$80000000..$80000009] of string[16] = (
    75 {aia_Weapon}             'aia_Weapon',
    76 {aia_Weapon}             'aia_Weapon',
    76 {aia_WaitX}              'aia_WaitX',
    77 {aia_WaitX}              'aia_WaitX',
    77 {aia_WaitY}              'aia_WaitY',
    78 {aia_WaitY}              'aia_WaitY',
    78 {aia_LookLeft}           'aia_LookLeft',
    79 {aia_LookLeft}           'aia_LookLeft',
    79 {aia_LookRight}          'aia_LookRight',
    80 {aia_LookRight}          'aia_LookRight',
    80 {aia_AwareExpl}          'aia_AwareExpl',
    81 {aia_AwareExpl}          'aia_AwareExpl',
    81 {aia_HJump}              'aia_HJump',
    82 {aia_HJump}              'aia_HJump',
    82 {aia_LJump}              'aia_LJump',
    83 {aia_LJump}              'aia_LJump',
    83 {aia_Skip}               'aia_Skip'
    84 {aia_Skip}               'aia_Skip',
       
    85 {aia_Wait}               'aia_Wait'
    84 );
    86 );
    85 
    87 
    86 procedure DumpAction(Action: TAction; Me: PGear);
    88 procedure DumpAction(Action: TAction; Me: PGear);
    87 begin
    89 begin
    88 if (Action.Action and ai_specmask) = 0 then
    90 if (Action.Action and ai_specmask) = 0 then
    89    WriteLnToConsole('AI action: '+ActionIdToStr[Action.Action])
    91    WriteLnToConsole('AI action: '+ActionIdToStr[Action.Action])
    90 else begin
    92 else begin
    91    WriteLnToConsole('AI action: '+SpecActionIdToStr[Action.Action]);
    93    WriteLnToConsole('AI action: '+SpecActionIdToStr[Action.Action]);
    92    if Action.Action = aia_WaitX then
    94    if (Action.Action = aia_WaitXL) or (Action.Action = aia_WaitXR) then
    93       WriteLnToConsole('AI action Wait X = '+inttostr(Action.Param)+', current X = '+inttostr(round(Me.X)));
    95       WriteLnToConsole('AI action Wait X = '+inttostr(Action.Param)+', current X = '+inttostr(round(Me.X)));
    94    end
    96    end
    95 end;
    97 end;
    96 {$ENDIF}
    98 {$ENDIF}
    97 
    99 
   121      DumpAction(Actions.actions[Actions.Pos], Me);
   123      DumpAction(Actions.actions[Actions.Pos], Me);
   122      {$ENDIF}
   124      {$ENDIF}
   123      if (Action and ai_specmask) <> 0 then
   125      if (Action and ai_specmask) <> 0 then
   124         case Action of
   126         case Action of
   125            aia_Weapon: SetWeapon(TAmmoType(Param));
   127            aia_Weapon: SetWeapon(TAmmoType(Param));
   126             aia_WaitX: if round(Me.X) = Param then Time:= GameTicks
   128            aia_WaitXL: if round(Me.X) = Param then Time:= GameTicks
   127                                               else exit;
   129                           else if Round(Me.X) < Param then
   128             aia_WaitY: if round(Me.Y) = Param then Time:= GameTicks
   130                                begin
   129                                               else exit;
   131                                OutError('AI: WaitXL assert');
       
   132                                Actions.Count:= 0
       
   133                                end
       
   134                           else exit;
       
   135            aia_WaitXR: if round(Me.X) = Param then Time:= GameTicks
       
   136                           else if Round(Me.X) > Param then
       
   137                                begin
       
   138                                OutError('AI: WaitXR assert');
       
   139                                Actions.Count:= 0
       
   140                                end
       
   141                           else exit;
   130          aia_LookLeft: if Me.dX >= 0 then
   142          aia_LookLeft: if Me.dX >= 0 then
   131                           begin
   143                           begin
   132                           ParseCommand('+left');
   144                           ParseCommand('+left');
   133                           exit
   145                           exit
   134                           end else ParseCommand('-left');
   146                           end else ParseCommand('-left');
   139                           end else ParseCommand('-right');
   151                           end else ParseCommand('-right');
   140         aia_AwareExpl: AwareOfExplosion(X, Y, Param);
   152         aia_AwareExpl: AwareOfExplosion(X, Y, Param);
   141             aia_HJump: ParseCommand('hjump');
   153             aia_HJump: ParseCommand('hjump');
   142             aia_LJump: ParseCommand('ljump');
   154             aia_LJump: ParseCommand('ljump');
   143              aia_Skip: ParseCommand('skip');
   155              aia_Skip: ParseCommand('skip');
       
   156              aia_Wait: if Param > GameTicks then exit
       
   157                           else with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
       
   158                                     Gear.State:= Gear.State and not gstHHThinking
   144              end else
   159              end else
   145         begin
   160         begin
   146         s:= ActionIdToStr[Action];
   161         s:= ActionIdToStr[Action];
   147         if (Param and ai_specmask) <> 0 then
   162         if (Param and ai_specmask) <> 0 then
   148            case Param of
   163            case Param of