hedgewars/uAIMisc.pas
changeset 6986 409dd3851309
parent 6952 7f70f37bbf08
child 6990 40e5af28d026
equal deleted inserted replaced
6985:caa41003f42c 6986:409dd3851309
    48 procedure freeModule;
    48 procedure freeModule;
    49 
    49 
    50 procedure FillTargets;
    50 procedure FillTargets;
    51 procedure FillBonuses(isAfterAttack: boolean);
    51 procedure FillBonuses(isAfterAttack: boolean);
    52 procedure AwareOfExplosion(x, y, r: LongInt); inline;
    52 procedure AwareOfExplosion(x, y, r: LongInt); inline;
    53 function RatePlace(Gear: PGear): LongInt;
    53 
    54 function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
    54 function  RatePlace(Gear: PGear): LongInt;
    55 function TestColl(x, y, r: LongInt): boolean; inline;
    55 function  TestColl(x, y, r: LongInt): boolean; inline;
    56 function TraceShoveFall(Me: PGear; x, y, dX, dY: Real): LongInt;
    56 function  TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
    57 function RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord = 0): LongInt;
    57 function  TraceShoveFall(Me: PGear; x, y, dX, dY: Real): LongInt;
    58 function RateShove(Me: PGear; x, y, r, power, kick: LongInt; gdX, gdY: real; Flags: LongWord): LongInt;
    58 
    59 function RateShotgun(Me: PGear; gdX, gdY: real; x, y: LongInt): LongInt;
    59 function  RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; inline;
    60 function RateHammer(Me: PGear): LongInt;
    60 function  RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord): LongInt;
    61 function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean;
    61 function  RateShove(Me: PGear; x, y, r, power, kick: LongInt; gdX, gdY: real; Flags: LongWord): LongInt;
    62 function AIrndSign(num: LongInt): LongInt;
    62 function  RateShotgun(Me: PGear; gdX, gdY: real; x, y: LongInt): LongInt;
       
    63 function  RateHammer(Me: PGear): LongInt;
       
    64 
       
    65 function  HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean;
       
    66 function  AIrndSign(num: LongInt): LongInt;
    63 
    67 
    64 var ThinkingHH: PGear;
    68 var ThinkingHH: PGear;
    65     Targets: TTargets;
    69     Targets: TTargets;
    66 
    70 
    67     bonuses: record
    71     bonuses: record
   176 if isAfterAttack and (KnownExplosion.Radius > 0) then
   180 if isAfterAttack and (KnownExplosion.Radius > 0) then
   177     with KnownExplosion do
   181     with KnownExplosion do
   178         AddBonus(X, Y, Radius + 10, -Radius);
   182         AddBonus(X, Y, Radius + 10, -Radius);
   179 end;
   183 end;
   180 
   184 
   181 procedure AwareOfExplosion(x, y, r: LongInt);
   185 procedure AwareOfExplosion(x, y, r: LongInt); inline;
   182 begin
   186 begin
   183 KnownExplosion.X:= x;
   187     KnownExplosion.X:= x;
   184 KnownExplosion.Y:= y;
   188     KnownExplosion.Y:= y;
   185 KnownExplosion.Radius:= r
   189     KnownExplosion.Radius:= r
   186 end;
   190 end;
   187 
   191 
   188 function RatePlace(Gear: PGear): LongInt;
   192 function RatePlace(Gear: PGear): LongInt;
   189 var i, r: LongInt;
   193 var i, r: LongInt;
   190     rate: LongInt;
   194     rate: LongInt;
   207     RatePlace:= rate;
   211     RatePlace:= rate;
   208 end;
   212 end;
   209 
   213 
   210 // Wrapper to test various approaches.  If it works reasonably, will just replace.
   214 // Wrapper to test various approaches.  If it works reasonably, will just replace.
   211 // Right now, converting to hwFloat is a tad inefficient since the x/y were hwFloat to begin with...
   215 // Right now, converting to hwFloat is a tad inefficient since the x/y were hwFloat to begin with...
   212 function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean;
   216 function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
   213 var MeX, MeY: LongInt;
   217 var MeX, MeY: LongInt;
   214 begin
   218 begin
   215     if ((x and LAND_WIDTH_MASK) = 0) and ((y and LAND_HEIGHT_MASK) = 0) then
   219     if ((x and LAND_WIDTH_MASK) = 0) and ((y and LAND_HEIGHT_MASK) = 0) then
   216         begin
   220         begin
   217         MeX:= hwRound(Me^.X);
   221         MeX:= hwRound(Me^.X);
   221             exit(false);
   225             exit(false);
   222         end;
   226         end;
   223     exit(TestColl(x, y, r))
   227     exit(TestColl(x, y, r))
   224 end;
   228 end;
   225 
   229 
   226 function TestColl(x, y, r: LongInt): boolean;
   230 function TestColl(x, y, r: LongInt): boolean; inline;
   227 var b: boolean;
   231 var b: boolean;
   228 begin
   232 begin
   229 b:= (((x-r) and LAND_WIDTH_MASK) = 0)and(((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] <> 0);
   233 b:= (((x-r) and LAND_WIDTH_MASK) = 0)and(((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] <> 0);
   230 if b then
   234 if b then
   231     exit(true);
   235     exit(true);
   309         if (y > cWaterLine) or (x > 4096) or (x < 0) then exit(-1); // returning -1 for drowning so it can be considered in the Rate routine
   313         if (y > cWaterLine) or (x > 4096) or (x < 0) then exit(-1); // returning -1 for drowning so it can be considered in the Rate routine
   310         end;
   314         end;
   311 end;
   315 end;
   312 
   316 
   313 // Flags are not defined yet but 1 for checking drowning and 2 for assuming land erasure.
   317 // Flags are not defined yet but 1 for checking drowning and 2 for assuming land erasure.
   314 function RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord = 0): LongInt;
   318 function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt;
       
   319 begin
       
   320     RateExplosion:= RateExplosion(Me, x, y, r, 0);
       
   321 end;
       
   322 
       
   323 function RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord): LongInt;
   315 var i, fallDmg, dmg, dmgBase, rate, erasure: LongInt;
   324 var i, fallDmg, dmg, dmgBase, rate, erasure: LongInt;
   316     dX, dY, dmgMod: real;
   325     dX, dY, dmgMod: real;
   317 begin
   326 begin
   318 fallDmg:= 0;
   327 fallDmg:= 0;
   319 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;
   328 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent;