hedgewars/uAIMisc.pas
changeset 6770 7d2c6cdb816a
parent 6769 44ad49a3a126
child 6771 87a947097d00
equal deleted inserted replaced
6769:44ad49a3a126 6770:7d2c6cdb816a
    52 procedure AwareOfExplosion(x, y, r: LongInt); inline;
    52 procedure AwareOfExplosion(x, y, r: LongInt); inline;
    53 function RatePlace(Gear: PGear): LongInt;
    53 function RatePlace(Gear: PGear): LongInt;
    54 function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
    54 function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
    55 function TestColl(x, y, r: LongInt): boolean; inline;
    55 function TestColl(x, y, r: LongInt): boolean; inline;
    56 function RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord = 0): LongInt;
    56 function RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord = 0): LongInt;
    57 function RateShove(Me: PGear; x, y, r, power: LongInt): LongInt;
    57 function RateShove(Me: PGear; x, y, r, power, kick: LongInt; gdX, gdY: real; Flags: LongWord): LongInt;
    58 function RateShotgun(Me: PGear; x, y: LongInt): LongInt;
    58 function RateShotgun(Me: PGear; x, y: LongInt): LongInt;
    59 function RateHammer(Me: PGear): LongInt;
    59 function RateHammer(Me: PGear): LongInt;
    60 function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean;
    60 function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean;
    61 function AIrndSign(num: LongInt): LongInt;
    61 function AIrndSign(num: LongInt): LongInt;
    62 
    62 
   265         begin
   265         begin
   266         x:= x + dX;
   266         x:= x + dX;
   267         y:= y + dY;
   267         y:= y + dY;
   268         dY:= dY + cGravityf;
   268         dY:= dY + cGravityf;
   269         skipLandCheck:= skipLandCheck and (r <> 0) and (abs(eX-x) + abs(eY-y) < r) and ((abs(eX-x) < rCorner) or (abs(eY-y) < rCorner));
   269         skipLandCheck:= skipLandCheck and (r <> 0) and (abs(eX-x) + abs(eY-y) < r) and ((abs(eX-x) < rCorner) or (abs(eY-y) < rCorner));
       
   270         // consider adding dX/dY calc here for fall damage
   270         if not skipLandCheck and TestCollWithLand(trunc(x), trunc(y), cHHRadius) then exit(false);
   271         if not skipLandCheck and TestCollWithLand(trunc(x), trunc(y), cHHRadius) then exit(false);
       
   272         if (y > cWaterLine) or (x > 4096) or (x < 0) then exit(true);
       
   273         end;
       
   274 end;
       
   275 
       
   276 function TraceShoveDrown(Me: PGear; x, y, dX, dY: Real): boolean;
       
   277 begin
       
   278     while true do
       
   279         begin
       
   280         x:= x + dX;
       
   281         y:= y + dY;
       
   282         dY:= dY + cGravityf;
       
   283         // consider adding dX/dY calc here for fall damage
       
   284         if TestCollExcludingMe(Me, trunc(x), trunc(y), cHHRadius) then exit(false);
   271         if (y > cWaterLine) or (x > 4096) or (x < 0) then exit(true);
   285         if (y > cWaterLine) or (x > 4096) or (x < 0) then exit(true);
   272         end;
   286         end;
   273 end;
   287 end;
   274 
   288 
   275 // Flags are not defined yet but 1 for checking drowning and 2 for assuming land erasure.
   289 // Flags are not defined yet but 1 for checking drowning and 2 for assuming land erasure.
   303                 dX:= 0.005 * dmg + 0.01;
   317                 dX:= 0.005 * dmg + 0.01;
   304                 dY:= dX;
   318                 dY:= dX;
   305                 end;
   319                 end;
   306             if (Flags and 1 <> 0) and TraceDrown(x, y, Point.x, Point.y, dX, dY, erasure) then
   320             if (Flags and 1 <> 0) and TraceDrown(x, y, Point.x, Point.y, dX, dY, erasure) then
   307                 if Score > 0 then
   321                 if Score > 0 then
   308                     begin
       
   309                     inc(rate, KillScore)
   322                     inc(rate, KillScore)
   310                     end
       
   311                 else
   323                 else
   312                     dec(rate, KillScore * friendlyfactor div 100)
   324                     dec(rate, KillScore * friendlyfactor div 100)
   313             else if dmg >= abs(Score) then
   325             else if dmg >= abs(Score) then
   314                 if Score > 0 then
   326                 if Score > 0 then
   315                     inc(rate, KillScore)
   327                     inc(rate, KillScore)
   323             end;
   335             end;
   324         end;
   336         end;
   325 RateExplosion:= rate * 1024;
   337 RateExplosion:= rate * 1024;
   326 end;
   338 end;
   327 
   339 
   328 function RateShove(Me: PGear; x, y, r, power: LongInt): LongInt;
   340 function RateShove(Me: PGear; x, y, r, power, kick: LongInt; gdX, gdY: real; Flags: LongWord): LongInt;
   329 var i, dmg, rate: LongInt;
   341 var i, dmg, rate: LongInt;
       
   342     dX, dY: real;
   330 begin
   343 begin
   331 Me:= Me; // avoid compiler hint
   344 Me:= Me; // avoid compiler hint
   332 rate:= 0;
   345 rate:= 0;
   333 for i:= 0 to Pred(Targets.Count) do
   346 for i:= 0 to Pred(Targets.Count) do
   334     with Targets.ar[i] do
   347     with Targets.ar[i] do
   335         begin
   348         begin
   336         dmg:= r - hwRound(DistanceI(Point.x - x, Point.y - y));
   349         dmg:= 0;
       
   350         if abs(Point.x - x) + abs(Point.y - y) < r then
       
   351             dmg:= r - hwRound(DistanceI(Point.x - x, Point.y - y));
   337         dmg:= hwRound(_0_01 * cDamageModifier * dmg * cDamagePercent);
   352         dmg:= hwRound(_0_01 * cDamageModifier * dmg * cDamagePercent);
   338         if dmg > 0 then
   353         if dmg > 0 then
   339             begin
   354             begin
   340             if power >= abs(Score) then
   355             if Flags and 1 <> 0 then
       
   356                 begin
       
   357                 dX:= gdX * 0.005 * kick;
       
   358                 dY:= gdY * 0.005 * kick;
       
   359                 end;
       
   360             if (Flags and 1 <> 0) and TraceShoveDrown(Me, Point.x, Point.y, dX, dY) then
       
   361                 if Score > 0 then
       
   362                     inc(rate, KillScore)
       
   363                 else
       
   364                     dec(rate, KillScore * friendlyfactor div 100)
       
   365             else if power >= abs(Score) then
   341                 if Score > 0 then
   366                 if Score > 0 then
   342                     inc(rate, KillScore)
   367                     inc(rate, KillScore)
   343                 else
   368                 else
   344                     dec(rate, KillScore * friendlyfactor div 100)
   369                     dec(rate, KillScore * friendlyfactor div 100)
   345             else
   370             else