hedgewars/uAIMisc.pas
changeset 70 82d93eeecebe
parent 66 9643d75baf1e
child 71 5f56c6979496
equal deleted inserted replaced
69:d8a526934b9f 70:82d93eeecebe
    10                 Count: Longword;
    10                 Count: Longword;
    11                 ar: array[0..cMaxHHIndex*5] of TTarget;
    11                 ar: array[0..cMaxHHIndex*5] of TTarget;
    12                 end;
    12                 end;
    13 
    13 
    14 procedure FillTargets;
    14 procedure FillTargets;
    15 procedure FillBonuses;
    15 procedure FillBonuses(isAfterAttack: boolean);
    16 function CheckBonuses(Gear: PGear): integer;
    16 function RatePlace(Gear: PGear): integer;
    17 function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
    17 function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
    18 function TestColl(x, y, r: integer): boolean;
    18 function TestColl(x, y, r: integer): boolean;
    19 function RateExplosion(Me: PGear; x, y, r: integer): integer;
    19 function RateExplosion(Me: PGear; x, y, r: integer): integer;
    20 function HHGo(Gear: PGear): boolean;
    20 function HHGo(Gear: PGear): boolean;
    21 
    21 
    27 const KillScore = 200;
    27 const KillScore = 200;
    28       MAXBONUS = 1024;
    28       MAXBONUS = 1024;
    29       
    29       
    30 type TBonus = record
    30 type TBonus = record
    31               X, Y: integer;
    31               X, Y: integer;
    32               Radius: Longword;
    32               Radius: integer;
    33               Score: integer;
    33               Score: integer;
    34               end;
    34               end;
    35 var bonuses: record
    35 var bonuses: record
    36              Count: Longword;
    36              Count: Longword;
    37              ar: array[0..Pred(MAXBONUS)] of TBonus;
    37              ar: array[0..Pred(MAXBONUS)] of TBonus;
    60              end;
    60              end;
    61       t:= t.Next
    61       t:= t.Next
    62       end
    62       end
    63 end;
    63 end;
    64 
    64 
    65 procedure FillBonuses;
    65 procedure FillBonuses(isAfterAttack: boolean);
    66 var Gear: PGear;
    66 var Gear: PGear;
       
    67     MyColor: Longword;
    67 
    68 
    68     procedure AddBonus(x, y: integer; r: Longword; s: integer);
    69     procedure AddBonus(x, y: integer; r: Longword; s: integer);
    69     begin
    70     begin
    70     bonuses.ar[bonuses.Count].x:= x;
    71     bonuses.ar[bonuses.Count].x:= x;
    71     bonuses.ar[bonuses.Count].y:= y;
    72     bonuses.ar[bonuses.Count].y:= y;
    75     TryDo(bonuses.Count <= MAXBONUS, 'Bonuses overflow', true)
    76     TryDo(bonuses.Count <= MAXBONUS, 'Bonuses overflow', true)
    76     end;
    77     end;
    77 
    78 
    78 begin
    79 begin
    79 bonuses.Count:= 0;
    80 bonuses.Count:= 0;
       
    81 MyColor:= PHedgehog(ThinkingHH.Hedgehog).Team.Color;
    80 Gear:= GearsList;
    82 Gear:= GearsList;
    81 while Gear <> nil do
    83 while Gear <> nil do
    82       begin
    84       begin
    83       case Gear.Kind of
    85       case Gear.Kind of
    84            gtCase: AddBonus(round(Gear.X), round(Gear.Y), 32, 25);
    86            gtCase: AddBonus(round(Gear.X), round(Gear.Y), 33, 25);
    85            gtMine: AddBonus(round(Gear.X), round(Gear.Y), 45, -50);
    87            gtMine: AddBonus(round(Gear.X), round(Gear.Y), 46, -50);
    86            gtAmmo_Bomb: AddBonus(round(Gear.X), round(Gear.Y), 50, -100);
    88            gtDynamite: AddBonus(round(Gear.X), round(Gear.Y), 150, -75);
    87            gtHedgehog: if Gear.Damage >= Gear.Health then AddBonus(round(Gear.X), round(Gear.Y), 50, -25);
    89            gtHedgehog: begin
       
    90                        if Gear.Damage >= Gear.Health then AddBonus(round(Gear.X), round(Gear.Y), 50, -25);
       
    91                        if isAfterAttack
       
    92                           and (ThinkingHH.Hedgehog <> Gear.Hedgehog)
       
    93                           and (MyColor = PHedgehog(Gear.Hedgehog).Team.Color) then AddBonus(round(Gear.X), round(Gear.Y), 100, -1);
       
    94                        end;
    88            end;
    95            end;
    89       Gear:= Gear.NextGear
    96       Gear:= Gear.NextGear
    90       end
    97       end
    91 end;
    98 end;
    92 
    99 
    93 function CheckBonuses(Gear: PGear): integer;
   100 function RatePlace(Gear: PGear): integer;
    94 var i: integer;
   101 var i, r: integer;
    95 begin
   102 begin
    96 Result:= 0;
   103 Result:= 0;
    97 for i:= 0 to Pred(bonuses.Count) do
   104 for i:= 0 to Pred(bonuses.Count) do
    98     with bonuses.ar[i] do
   105     with bonuses.ar[i] do
    99          if sqrt(sqr(Gear.X - X) + sqr(Gear.Y - y)) <= Radius then
   106          begin
   100             inc(Result, Score) 
   107          r:= round(sqrt(sqr(Gear.X - X) + sqr(Gear.Y - y)));
       
   108          if r < Radius then
       
   109             inc(Result, Score * (Radius - r))
       
   110          end;
   101 end;
   111 end;
   102 
   112 
   103 function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
   113 function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
   104 const piDIVMaxAngle: Extended = pi/cMaxAngle;
   114 const piDIVMaxAngle: Extended = pi/cMaxAngle;
   105 asm
   115 asm
   149             else
   159             else
   150                if Score > 0 then inc(Result, dmg)
   160                if Score > 0 then inc(Result, dmg)
   151                             else dec(Result, dmg * 3)
   161                             else dec(Result, dmg * 3)
   152             end;
   162             end;
   153          end;
   163          end;
       
   164 Result:= Result * 1024
   154 end;
   165 end;
   155 
   166 
   156 function HHGo(Gear: PGear): boolean;
   167 function HHGo(Gear: PGear): boolean;
   157 var pX, pY: integer;
   168 var pX, pY: integer;
   158 begin
   169 begin