hedgewars/uAIActions.pas
changeset 369 2aed85310727
parent 351 29bc9c36ad5f
child 371 731ad6d27bd1
equal deleted inserted replaced
368:fe71e55d2d7b 369:2aed85310727
    18 
    18 
    19 unit uAIActions;
    19 unit uAIActions;
    20 interface
    20 interface
    21 uses uGears, uFloat;
    21 uses uGears, uFloat;
    22 {$INCLUDE options.inc}
    22 {$INCLUDE options.inc}
    23 (*const MAXACTIONS = 96;
    23 const MAXACTIONS = 96;
    24       aia_none       = 0;
    24       aia_none       = 0;
    25       aia_Left       = 1;
    25       aia_Left       = 1;
    26       aia_Right      = 2;
    26       aia_Right      = 2;
    27       aia_Timer      = 3;
    27       aia_Timer      = 3;
    28       aia_attack     = 4;
    28       aia_attack     = 4;
    53                 Count, Pos: Longword;
    53                 Count, Pos: Longword;
    54                 actions: array[0..Pred(MAXACTIONS)] of TAction;
    54                 actions: array[0..Pred(MAXACTIONS)] of TAction;
    55                 Score: integer;
    55                 Score: integer;
    56                 end;
    56                 end;
    57 
    57 
    58 procedure AddAction(var Actions: TActions; Action, Param, TimeDelta: Longword; const X: integer = 0; Y: integer = 0);
    58 procedure AddAction(var Actions: TActions; Action, Param, TimeDelta: Longword; X, Y: integer);
    59 procedure ProcessAction(var Actions: TActions; Me: PGear);
    59 procedure ProcessAction(var Actions: TActions; Me: PGear);
    60 *)
    60 
    61 implementation
    61 implementation
    62 (*uses uMisc, uTeams, uConsts, uConsole, uAIMisc;
    62 uses uMisc, uTeams, uConsts, uConsole, uAIMisc;
    63 
    63 
    64 const ActionIdToStr: array[0..6] of string[16] = (
    64 const ActionIdToStr: array[0..6] of string[16] = (
    65 {aia_none}           '',
    65 {aia_none}           '',
    66 {aia_Left}           'left',
    66 {aia_Left}           'left',
    67 {aia_Right}          'right',
    67 {aia_Right}          'right',
    95       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)));
    96    end
    96    end
    97 end;
    97 end;
    98 {$ENDIF}
    98 {$ENDIF}
    99 
    99 
   100 procedure AddAction(var Actions: TActions; Action, Param, TimeDelta: Longword; const X: integer = 0; Y: integer = 0);
   100 procedure AddAction(var Actions: TActions; Action, Param, TimeDelta: Longword; X, Y: integer);
   101 begin
   101 begin
   102 with Actions do
   102 with Actions do
   103      begin
   103      begin
   104      actions[Count].Action:= Action;
   104      actions[Count].Action:= Action;
   105      actions[Count].Param:= Param;
   105      actions[Count].Param:= Param;
   117 
   117 
   118     procedure CheckHang;
   118     procedure CheckHang;
   119     const PrevX: integer = 0;
   119     const PrevX: integer = 0;
   120           timedelta: Longword = 0;
   120           timedelta: Longword = 0;
   121     begin
   121     begin
   122     if Round(Me.X) <> PrevX then
   122     if hwRound(Me^.X) <> PrevX then
   123        begin
   123        begin
   124        PrevX:= Round(Me.X);
   124        PrevX:= hwRound(Me^.X);
   125        timedelta:= 0
   125        timedelta:= 0
   126        end else
   126        end else
   127        begin
   127        begin
   128        inc(timedelta);
   128        inc(timedelta);
   129        if timedelta > 2500 then
   129        if timedelta > 2500 then
   144      DumpAction(Actions.actions[Actions.Pos], Me);
   144      DumpAction(Actions.actions[Actions.Pos], Me);
   145      {$ENDIF}
   145      {$ENDIF}
   146      if (Action and ai_specmask) <> 0 then
   146      if (Action and ai_specmask) <> 0 then
   147         case Action of
   147         case Action of
   148            aia_Weapon: SetWeapon(TAmmoType(Param));
   148            aia_Weapon: SetWeapon(TAmmoType(Param));
   149            aia_WaitXL: if round(Me.X) = Param then Time:= GameTicks
   149            aia_WaitXL: if hwRound(Me^.X) = Param then Time:= GameTicks
   150                           else if Round(Me.X) < Param then
   150                           else if hwRound(Me^.X) < Param then
   151                                begin
   151                                begin
   152                                OutError('AI: WaitXL assert');
   152                                OutError('AI: WaitXL assert', false);
   153                                Actions.Count:= 0
   153                                Actions.Count:= 0
   154                                end
   154                                end
   155                           else begin CheckHang; exit end;
   155                           else begin CheckHang; exit end;
   156            aia_WaitXR: if round(Me.X) = Param then Time:= GameTicks
   156            aia_WaitXR: if hwRound(Me^.X) = Param then Time:= GameTicks
   157                           else if Round(Me.X) > Param then
   157                           else if hwRound(Me^.X) > Param then
   158                                begin
   158                                begin
   159                                OutError('AI: WaitXR assert');
   159                                OutError('AI: WaitXR assert', false);
   160                                Actions.Count:= 0
   160                                Actions.Count:= 0
   161                                end
   161                                end
   162                           else begin CheckHang; exit end;
   162                           else begin CheckHang; exit end;
   163          aia_LookLeft: if Me.dX >= 0 then
   163          aia_LookLeft: if not Me^.dX.isNegative then
   164                           begin
   164                           begin
   165                           ParseCommand('+left');
   165                           ParseCommand('+left', true);
   166                           exit
   166                           exit
   167                           end else ParseCommand('-left');
   167                           end else ParseCommand('-left', true);
   168         aia_LookRight: if Me.dX < 0 then
   168         aia_LookRight: if Me^.dX.isNegative then
   169                           begin
   169                           begin
   170                           ParseCommand('+right');
   170                           ParseCommand('+right', true);
   171                           exit
   171                           exit
   172                           end else ParseCommand('-right');
   172                           end else ParseCommand('-right', true);
   173         aia_AwareExpl: AwareOfExplosion(X, Y, Param);
   173         aia_AwareExpl: AwareOfExplosion(X, Y, Param);
   174             aia_HJump: ParseCommand('hjump');
   174             aia_HJump: ParseCommand('hjump', true);
   175             aia_LJump: ParseCommand('ljump');
   175             aia_LJump: ParseCommand('ljump', true);
   176              aia_Skip: ParseCommand('skip');
   176              aia_Skip: ParseCommand('skip', true);
   177              end else
   177              end else
   178         begin
   178         begin
   179         s:= ActionIdToStr[Action];
   179         s:= ActionIdToStr[Action];
   180         if (Param and ai_specmask) <> 0 then
   180         if (Param and ai_specmask) <> 0 then
   181            case Param of
   181            case Param of
   182              aim_push: s:= '+' + s;
   182              aim_push: s:= '+' + s;
   183           aim_release: s:= '-' + s;
   183           aim_release: s:= '-' + s;
   184              end
   184              end
   185           else if Param <> 0 then s:= s + ' ' + inttostr(Param);
   185           else if Param <> 0 then s:= s + ' ' + inttostr(Param);
   186         ParseCommand(s)
   186         ParseCommand(s, true)
   187         end
   187         end
   188      end;
   188      end;
   189 inc(Actions.Pos);
   189 inc(Actions.Pos);
   190 if Actions.Pos <= Actions.Count then
   190 if Actions.Pos <= Actions.Count then
   191    inc(Actions.actions[Actions.Pos].Time, GameTicks);
   191    inc(Actions.actions[Actions.Pos].Time, GameTicks);
   192 until false
   192 until false
   193 end;
   193 end;
   194 *)
   194 
   195 end.
   195 end.