hedgewars/uAIMisc.pas
changeset 3370 37f4f83fedb1
parent 3236 4ab3917d7d44
child 3407 dcc129c4352e
equal deleted inserted replaced
3369:c7289e42f0ee 3370:37f4f83fedb1
    20 
    20 
    21 unit uAIMisc;
    21 unit uAIMisc;
    22 interface
    22 interface
    23 uses SDLh, uConsts, uGears, uFloat;
    23 uses SDLh, uConsts, uGears, uFloat;
    24 
    24 
       
    25 const MAXBONUS = 1024;
       
    26 
    25 type TTarget = record
    27 type TTarget = record
    26                Point: TPoint;
    28                Point: TPoint;
    27                Score: LongInt;
    29                Score: LongInt;
    28                end;
    30                end;
    29      TTargets = record
    31      TTargets = record
    34      TGoInfo = record
    36      TGoInfo = record
    35                Ticks: Longword;
    37                Ticks: Longword;
    36                FallPix: Longword;
    38                FallPix: Longword;
    37                JumpType: TJumpType;
    39                JumpType: TJumpType;
    38                end;
    40                end;
       
    41      TBonus = record
       
    42               X, Y: LongInt;
       
    43               Radius: LongInt;
       
    44               Score: LongInt;
       
    45               end;
    39 
    46 
    40 procedure initModule;
    47 procedure initModule;
    41 procedure freeModule;
    48 procedure freeModule;
    42 
    49 
    43 procedure FillTargets;
    50 procedure FillTargets;
    44 procedure FillBonuses(isAfterAttack: boolean);
    51 procedure FillBonuses(isAfterAttack: boolean; filter: TGearsType = []);
    45 procedure AwareOfExplosion(x, y, r: LongInt);
    52 procedure AwareOfExplosion(x, y, r: LongInt);
    46 function RatePlace(Gear: PGear): LongInt;
    53 function RatePlace(Gear: PGear): LongInt;
    47 function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean;
    54 function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean;
    48 function TestColl(x, y, r: LongInt): boolean;
    55 function TestColl(x, y, r: LongInt): boolean;
    49 function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt;
    56 function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt;
    53 function AIrndSign(num: LongInt): LongInt;
    60 function AIrndSign(num: LongInt): LongInt;
    54 
    61 
    55 var ThinkingHH: PGear;
    62 var ThinkingHH: PGear;
    56     Targets: TTargets;
    63     Targets: TTargets;
    57 
    64 
    58 implementation
       
    59 uses uTeams, uMisc, uLand, uCollisions;
       
    60 
       
    61 type TBonus = record
       
    62               X, Y: LongInt;
       
    63               Radius: LongInt;
       
    64               Score: LongInt;
       
    65               end;
       
    66 
       
    67 const KillScore = 200;
       
    68       MAXBONUS = 1024;
       
    69 
       
    70 var friendlyfactor: LongInt = 300;
       
    71     KnownExplosion: record
       
    72                     X, Y, Radius: LongInt
       
    73                     end = (X: 0; Y: 0; Radius: 0);
       
    74     bonuses: record
    65     bonuses: record
    75              Count: Longword;
    66              Count: Longword;
    76              ar: array[0..Pred(MAXBONUS)] of TBonus;
    67              ar: array[0..Pred(MAXBONUS)] of TBonus;
    77              end;
    68              end;
    78 
    69 
       
    70 implementation
       
    71 uses uTeams, uMisc, uLand, uCollisions;
       
    72 
       
    73 
       
    74 const KillScore = 200;
       
    75 
       
    76 var friendlyfactor: LongInt = 300;
       
    77     KnownExplosion: record
       
    78                     X, Y, Radius: LongInt
       
    79                     end = (X: 0; Y: 0; Radius: 0); 
    79 
    80 
    80 procedure FillTargets;
    81 procedure FillTargets;
    81 var i, t: Longword;
    82 var i, t: Longword;
    82     f, e: Longword;
    83     f, e: Longword;
    83 begin
    84 begin
   112 
   113 
   113 if e > f then friendlyfactor:= 300 + (e - f) * 30
   114 if e > f then friendlyfactor:= 300 + (e - f) * 30
   114 else friendlyfactor:= max(30, 300 - f * 80 div e)
   115 else friendlyfactor:= max(30, 300 - f * 80 div e)
   115 end;
   116 end;
   116 
   117 
   117 procedure FillBonuses(isAfterAttack: boolean);
   118 procedure FillBonuses(isAfterAttack: boolean; filter: TGearsType);
   118 var Gear: PGear;
   119 var Gear: PGear;
   119     MyClan: PClan;
   120     MyClan: PClan;
   120 
   121 
   121     procedure AddBonus(x, y: LongInt; r: Longword; s: LongInt);
   122     procedure AddBonus(x, y: LongInt; r: Longword; s: LongInt);
   122     begin
   123     begin
   132 bonuses.Count:= 0;
   133 bonuses.Count:= 0;
   133 MyClan:= PHedgehog(ThinkingHH^.Hedgehog)^.Team^.Clan;
   134 MyClan:= PHedgehog(ThinkingHH^.Hedgehog)^.Team^.Clan;
   134 Gear:= GearsList;
   135 Gear:= GearsList;
   135 while Gear <> nil do
   136 while Gear <> nil do
   136     begin
   137     begin
   137     case Gear^.Kind of
   138 	if (filter = []) or (Gear^.Kind in filter) then
   138         gtCase: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 33, 25);
   139       case Gear^.Kind of
   139         gtFlame: if (Gear^.State and gsttmpFlag) <> 0 then
   140           gtCase: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 33, 25);
   140                 AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 20, -50);
   141           gtFlame: if (Gear^.State and gsttmpFlag) <> 0 then
   141         gtMine: if (Gear^.State and gstAttacking) = 0 then
   142                   AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 20, -50);
   142                 AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50)
   143           gtMine: if (Gear^.State and gstAttacking) = 0 then
   143             else
   144                   AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50)
   144                 AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on
   145               else
   145         gtDynamite: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -75);
   146                   AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on
   146         gtHedgehog: begin
   147           gtDynamite: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -75);
   147                     if Gear^.Damage >= Gear^.Health then
   148           gtHedgehog: begin
   148                         AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 60, -25)
   149                       if Gear^.Damage >= Gear^.Health then
   149                     else
   150                           AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 60, -25)
   150                         if isAfterAttack and (ThinkingHH^.Hedgehog <> Gear^.Hedgehog) then
   151                       else
   151                             if (MyClan = PHedgehog(Gear^.Hedgehog)^.Team^.Clan) then
   152                           if isAfterAttack and (ThinkingHH^.Hedgehog <> Gear^.Hedgehog) then
   152                                 AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend
   153                               if (MyClan = PHedgehog(Gear^.Hedgehog)^.Team^.Clan) then
   153                             else
   154                                   AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend
   154                                 AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3)
   155                               else
   155                     end;
   156                                   AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3)
   156         end;
   157                       end;
       
   158           end;
   157     Gear:= Gear^.NextGear
   159     Gear:= Gear^.NextGear
   158     end;
   160     end;
   159 if isAfterAttack and (KnownExplosion.Radius > 0) then
   161 if isAfterAttack and (KnownExplosion.Radius > 0) then
   160    with KnownExplosion do
   162    with KnownExplosion do
   161         AddBonus(X, Y, Radius + 10, -Radius);
   163         AddBonus(X, Y, Radius + 10, -Radius);