hedgewars/uAIMisc.pas
changeset 7208 62e36dc45098
parent 7164 fad64b97947e
child 7210 2ff30b79d2b0
equal deleted inserted replaced
7206:ce46b56ae9f5 7208:62e36dc45098
    57 procedure FillBonuses(isAfterAttack: boolean);
    57 procedure FillBonuses(isAfterAttack: boolean);
    58 procedure AwareOfExplosion(x, y, r: LongInt); inline;
    58 procedure AwareOfExplosion(x, y, r: LongInt); inline;
    59 
    59 
    60 function  RatePlace(Gear: PGear): LongInt;
    60 function  RatePlace(Gear: PGear): LongInt;
    61 function  TestColl(x, y, r: LongInt): boolean; inline;
    61 function  TestColl(x, y, r: LongInt): boolean; inline;
       
    62 function  TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
    62 function  TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
    63 function  TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
    63 function  TraceShoveFall(Me: PGear; x, y, dX, dY: Real): LongInt;
    64 function  TraceShoveFall(x, y, dX, dY: Real): LongInt;
    64 
    65 
    65 function  RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; inline;
    66 function  RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; inline;
    66 function  RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord): LongInt;
    67 function  RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord): LongInt;
    67 function  RateShove(Me: PGear; x, y, r, power, kick: LongInt; gdX, gdY: real; Flags: LongWord): LongInt;
    68 function  RateShove(Me: PGear; x, y, r, power, kick: LongInt; gdX, gdY: real; Flags: LongWord): LongInt;
    68 function  RateShotgun(Me: PGear; gdX, gdY: real; x, y: LongInt): LongInt;
    69 function  RateShotgun(Me: PGear; gdX, gdY: real; x, y: LongInt): LongInt;
   234             exit(false);
   235             exit(false);
   235     end;
   236     end;
   236     TestCollExcludingMe:= TestColl(x, y, r)
   237     TestCollExcludingMe:= TestColl(x, y, r)
   237 end;
   238 end;
   238 
   239 
       
   240 function TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
       
   241 var b: boolean;
       
   242 begin
       
   243     b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] and $FF00 <> 0);
       
   244     if b then
       
   245         exit(true);
       
   246     
       
   247     b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x-r] and $FF00 <> 0);
       
   248     if b then
       
   249         exit(true);
       
   250     
       
   251     b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x+r] and $FF00 <> 0);
       
   252     if b then
       
   253         exit(true);
       
   254     
       
   255     b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x+r] and $FF00 <> 0);
       
   256     if b then
       
   257         exit(true);
       
   258     
       
   259     TestCollExcludingObjects:= false;
       
   260 end;
       
   261 
   239 function TestColl(x, y, r: LongInt): boolean; inline;
   262 function TestColl(x, y, r: LongInt): boolean; inline;
   240 var b: boolean;
   263 var b: boolean;
   241 begin
   264 begin
   242     b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] <> 0);
   265     b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] <> 0);
   243     if b then
   266     if b then
   309         if (y > cWaterLine) or (x > 4096) or (x < 0) then
   332         if (y > cWaterLine) or (x > 4096) or (x < 0) then
   310             exit(-1);
   333             exit(-1);
   311     end;
   334     end;
   312 end;
   335 end;
   313 
   336 
   314 function TraceShoveFall(Me: PGear; x, y, dX, dY: Real): LongInt;
   337 function TraceShoveFall(x, y, dX, dY: Real): LongInt;
   315 var dmg: LongInt;
   338 var dmg: LongInt;
   316 begin
   339 begin
   317     while true do
   340     while true do
   318     begin
   341     begin
   319         x:= x + dX;
   342         x:= x + dX;
   320         y:= y + dY;
   343         y:= y + dY;
   321         dY:= dY + cGravityf;
   344         dY:= dY + cGravityf;
   322         // consider adding dX/dY calc here for fall damage
   345         if TestCollExcludingObjects(trunc(x), trunc(y), cHHRadius) then
   323         if TestCollExcludingMe(Me, trunc(x), trunc(y), cHHRadius) then
       
   324         begin
   346         begin
   325             if 0.4 < dY then
   347             if 0.4 < dY then
   326             begin
   348             begin
   327                 dmg := 1 + trunc((abs(dY) - 0.4) * 70);
   349                 dmg := 1 + trunc((abs(dY) - 0.4) * 70);
   328                 if dmg >= 1 then
   350                 if dmg >= 1 then
   416             end;
   438             end;
   417         if dmg > 0 then
   439         if dmg > 0 then
   418             begin
   440             begin
   419             if (Flags and afSetSkip <> 0) then skip:= true;
   441             if (Flags and afSetSkip <> 0) then skip:= true;
   420             if (Flags and afTrackFall <> 0) then 
   442             if (Flags and afTrackFall <> 0) then 
   421                 fallDmg:= trunc(TraceShoveFall(Me, Point.x, Point.y - 2, dX, dY) * dmgMod);
   443                 fallDmg:= trunc(TraceShoveFall(Point.x, Point.y - 2, dX, dY) * dmgMod);
   422             if fallDmg < 0 then // drowning. score healthier hogs higher, since their death is more likely to benefit the AI
   444             if fallDmg < 0 then // drowning. score healthier hogs higher, since their death is more likely to benefit the AI
   423                 if Score > 0 then
   445                 if Score > 0 then
   424                     inc(rate, KillScore + Score div 10)   // Add a bit of a bonus for bigger hog drownings
   446                     inc(rate, KillScore + Score div 10)   // Add a bit of a bonus for bigger hog drownings
   425                 else
   447                 else
   426                     dec(rate, KillScore * friendlyfactor div 100 - Score div 10) // and more of a punishment for drowning bigger friendly hogs
   448                     dec(rate, KillScore * friendlyfactor div 100 - Score div 10) // and more of a punishment for drowning bigger friendly hogs