hedgewars/uAIMisc.pas
changeset 7628 bc7b1d228a2c
parent 7471 ce5d3e39361e
child 7651 4cd85eebc54b
equal deleted inserted replaced
7533:7ee319134713 7628:bc7b1d228a2c
    84     walkbonuses: record
    84     walkbonuses: record
    85         Count: Longword;
    85         Count: Longword;
    86         ar: array[0..Pred(MAXBONUS div 8)] of TBonus;  // don't use too many
    86         ar: array[0..Pred(MAXBONUS div 8)] of TBonus;  // don't use too many
    87         end;
    87         end;
    88 
    88 
       
    89 const KillScore = 200;
       
    90 var friendlyfactor: LongInt = 300;
       
    91        
    89 implementation
    92 implementation
    90 uses uCollisions, uVariables, uUtils, uDebug, uLandTexture;
    93 uses uCollisions, uVariables, uUtils, uDebug, uLandTexture;
    91 
    94 
    92 const KillScore = 200;
    95 var 
    93 
       
    94 var friendlyfactor: LongInt = 300;
       
    95     KnownExplosion: record
    96     KnownExplosion: record
    96         X, Y, Radius: LongInt
    97         X, Y, Radius: LongInt
    97         end = (X: 0; Y: 0; Radius: 0);
    98         end = (X: 0; Y: 0; Radius: 0);
    98 
    99 
    99 procedure FillTargets;
   100 procedure FillTargets;
   168 Gear:= GearsList;
   169 Gear:= GearsList;
   169 while Gear <> nil do
   170 while Gear <> nil do
   170     begin
   171     begin
   171         case Gear^.Kind of
   172         case Gear^.Kind of
   172             gtCase:
   173             gtCase:
   173             AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 33, 25);
   174                 AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y) + 3, 37, 25);
   174             gtFlame:
   175             gtFlame:
   175                 if (Gear^.State and gsttmpFlag) <> 0 then
   176                 if (Gear^.State and gsttmpFlag) <> 0 then
   176                     AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 20, -50);
   177                     AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 20, -50);
   177 // avoid mines unless they are very likely to be duds, or are duds. also avoid if they are about to blow 
   178 // avoid mines unless they are very likely to be duds, or are duds. also avoid if they are about to blow 
   178             gtMine:
   179             gtMine:
   369     while true do
   370     while true do
   370     begin
   371     begin
   371         x:= x + dX;
   372         x:= x + dX;
   372         y:= y + dY;
   373         y:= y + dY;
   373         dY:= dY + cGravityf;
   374         dY:= dY + cGravityf;
   374 (*
   375 
   375         if ((trunc(y) and LAND_HEIGHT_MASK) = 0) and ((trunc(x) and LAND_WIDTH_MASK) = 0) then 
   376 {        if ((trunc(y) and LAND_HEIGHT_MASK) = 0) and ((trunc(x) and LAND_WIDTH_MASK) = 0) then 
   376             begin
   377             begin
   377             LandPixels[trunc(y), trunc(x)]:= v;
   378             LandPixels[trunc(y), trunc(x)]:= v;
   378             UpdateLandTexture(trunc(X), 1, trunc(Y), 1, true);
   379             UpdateLandTexture(trunc(X), 1, trunc(Y), 1, true);
   379             end;
   380             end;}
   380 *)
   381 
   381 
   382 
   382         // consider adding dX/dY calc here for fall damage
   383         // consider adding dX/dY calc here for fall damage
   383         if TestCollExcludingObjects(trunc(x), trunc(y), cHHRadius) then
   384         if TestCollExcludingObjects(trunc(x), trunc(y), cHHRadius) then
   384         begin
   385         begin
   385             if 0.4 < dY then
   386             if 0.4 < dY then
   437                      fallDmg:= trunc(TraceFall(x, y, Point.x, Point.y, dX, dY, 0) * dmgMod)
   438                      fallDmg:= trunc(TraceFall(x, y, Point.x, Point.y, dX, dY, 0) * dmgMod)
   438                 else fallDmg:= trunc(TraceFall(x, y, Point.x, Point.y, dX, dY, erasure) * dmgMod)
   439                 else fallDmg:= trunc(TraceFall(x, y, Point.x, Point.y, dX, dY, erasure) * dmgMod)
   439                 end;
   440                 end;
   440             if fallDmg < 0 then // drowning. score healthier hogs higher, since their death is more likely to benefit the AI
   441             if fallDmg < 0 then // drowning. score healthier hogs higher, since their death is more likely to benefit the AI
   441                 if Score > 0 then
   442                 if Score > 0 then
   442                     inc(rate, KillScore + Score div 10)   // Add a bit of a bonus for bigger hog drownings
   443                     inc(rate, (KillScore + Score div 10) * 1024)   // Add a bit of a bonus for bigger hog drownings
   443                 else
   444                 else
   444                     dec(rate, KillScore * friendlyfactor div 100 - Score div 10) // and more of a punishment for drowning bigger friendly hogs
   445                     dec(rate, (KillScore * friendlyfactor div 100 - Score div 10) * 1024) // and more of a punishment for drowning bigger friendly hogs
   445             else if (dmg+fallDmg) >= abs(Score) then
   446             else if (dmg+fallDmg) >= abs(Score) then
   446                 if Score > 0 then
   447                 if Score > 0 then
   447                     inc(rate, KillScore)
   448                     inc(rate, KillScore * 1024 + (dmg + fallDmg)) // tiny bonus for dealing more damage than needed to kill
   448                 else
   449                 else
   449                     dec(rate, KillScore * friendlyfactor div 100)
   450                     dec(rate, KillScore * friendlyfactor div 100 * 1024)
   450             else
   451             else
   451                 if Score > 0 then
   452                 if Score > 0 then
   452                     inc(rate, dmg+fallDmg)
   453                     inc(rate, (dmg + fallDmg) * 1024)
   453                 else dec(rate, (dmg+fallDmg) * friendlyfactor div 100)
   454                 else dec(rate, (dmg + fallDmg) * friendlyfactor div 100 * 1024)
   454             end;
   455             end;
   455         end;
   456         end;
   456 RateExplosion:= rate * 1024;
   457 RateExplosion:= rate;
   457 end;
   458 end;
   458 
   459 
   459 function RateShove(Me: PGear; x, y, r, power, kick: LongInt; gdX, gdY: real; Flags: LongWord): LongInt;
   460 function RateShove(Me: PGear; x, y, r, power, kick: LongInt; gdX, gdY: real; Flags: LongWord): LongInt;
   460 var i, fallDmg, dmg, rate: LongInt;
   461 var i, fallDmg, dmg, rate: LongInt;
   461     dX, dY, dmgMod: real;
   462     dX, dY, dmgMod: real;
   622             exit(false)
   623             exit(false)
   623         end
   624         end
   624 end;
   625 end;
   625 
   626 
   626 repeat
   627 repeat
       
   628         {if ((hwRound(Gear^.Y) and LAND_HEIGHT_MASK) = 0) and ((hwRound(Gear^.X) and LAND_WIDTH_MASK) = 0) then 
       
   629             begin
       
   630             LandPixels[hwRound(Gear^.Y), hwRound(Gear^.X)]:= Gear^.Hedgehog^.Team^.Clan^.Color;
       
   631             UpdateLandTexture(hwRound(Gear^.X), 1, hwRound(Gear^.Y), 1, true);
       
   632             end;}
       
   633             
   627     if not (hwRound(Gear^.Y) + cHHRadius < cWaterLine) then
   634     if not (hwRound(Gear^.Y) + cHHRadius < cWaterLine) then
   628         exit(false);
   635         exit(false);
   629     if (Gear^.State and gstMoving) <> 0 then
   636     if (Gear^.State and gstMoving) <> 0 then
   630     begin
   637     begin
   631         if (GoInfo.Ticks = 350) then
   638         if (GoInfo.Ticks = 350) then
   643         if (Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, -1) <> 0) then
   650         if (Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, -1) <> 0) then
   644             Gear^.dY:= _0;
   651             Gear^.dY:= _0;
   645         Gear^.Y:= Gear^.Y + Gear^.dY;
   652         Gear^.Y:= Gear^.Y + Gear^.dY;
   646         if (not Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, 1) <> 0) then
   653         if (not Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, 1) <> 0) then
   647             begin
   654             begin
   648             Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping);
   655             Gear^.State:= Gear^.State and (not (gstMoving or gstHHJumping));
   649             Gear^.dY:= _0;
   656             Gear^.dY:= _0;
   650             case JumpType of
   657             case JumpType of
   651                 jmpHJump:
   658                 jmpHJump:
   652                     if bY - hwRound(Gear^.Y) > 5 then
   659                     if bY - hwRound(Gear^.Y) > 5 then
   653                         begin
   660                         begin
   671 
   678 
   672 function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean;
   679 function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean;
   673 var pX, pY, tY: LongInt;
   680 var pX, pY, tY: LongInt;
   674 begin
   681 begin
   675 HHGo:= false;
   682 HHGo:= false;
       
   683 Gear^.CollisionMask:= $FF7F;
   676 AltGear^:= Gear^;
   684 AltGear^:= Gear^;
   677 
   685 
   678 GoInfo.Ticks:= 0;
   686 GoInfo.Ticks:= 0;
   679 GoInfo.FallPix:= 0;
   687 GoInfo.FallPix:= 0;
   680 GoInfo.JumpType:= jmpNone;
   688 GoInfo.JumpType:= jmpNone;
   681 tY:= hwRound(Gear^.Y);
   689 tY:= hwRound(Gear^.Y);
   682 repeat
   690 repeat
       
   691         {if ((hwRound(Gear^.Y) and LAND_HEIGHT_MASK) = 0) and ((hwRound(Gear^.X) and LAND_WIDTH_MASK) = 0) then 
       
   692             begin
       
   693             LandPixels[hwRound(Gear^.Y), hwRound(Gear^.X)]:= random($FFFFFFFF);//Gear^.Hedgehog^.Team^.Clan^.Color;
       
   694             UpdateLandTexture(hwRound(Gear^.X), 1, hwRound(Gear^.Y), 1, true);
       
   695             end;}
       
   696 
   683     pX:= hwRound(Gear^.X);
   697     pX:= hwRound(Gear^.X);
   684     pY:= hwRound(Gear^.Y);
   698     pY:= hwRound(Gear^.Y);
   685     if pY + cHHRadius >= cWaterLine then
   699     if pY + cHHRadius >= cWaterLine then
   686         begin
   700         begin
   687         if AltGear^.Hedgehog^.BotLevel < 4 then
   701         if AltGear^.Hedgehog^.BotLevel < 4 then
   694         begin
   708         begin
   695         inc(GoInfo.Ticks);
   709         inc(GoInfo.Ticks);
   696         Gear^.dY:= Gear^.dY + cGravity;
   710         Gear^.dY:= Gear^.dY + cGravity;
   697         if Gear^.dY > _0_4 then
   711         if Gear^.dY > _0_4 then
   698             begin
   712             begin
   699             Goinfo.FallPix:= 0;
   713             GoInfo.FallPix:= 0;
   700             // try ljump instead of fall with damage
   714             // try ljump instead of fall with damage
   701             HHJump(AltGear, jmpLJump, GoInfo); 
   715             HHJump(AltGear, jmpLJump, GoInfo); 
   702             if AltGear^.Hedgehog^.BotLevel < 4 then
   716             if AltGear^.Hedgehog^.BotLevel < 4 then
   703                 AddWalkBonus(pX, tY, 175, -20);
   717                 AddWalkBonus(pX, tY, 175, -20);
   704             exit(false)
   718             exit(false)
   707         if hwRound(Gear^.Y) > pY then
   721         if hwRound(Gear^.Y) > pY then
   708             inc(GoInfo.FallPix);
   722             inc(GoInfo.FallPix);
   709         if TestCollisionYwithGear(Gear, 1) <> 0 then
   723         if TestCollisionYwithGear(Gear, 1) <> 0 then
   710             begin
   724             begin
   711             inc(GoInfo.Ticks, 410);
   725             inc(GoInfo.Ticks, 410);
   712             Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping);
   726             Gear^.State:= Gear^.State and (not (gstMoving or gstHHJumping));
   713             Gear^.dY:= _0;
   727             Gear^.dY:= _0;
   714             // try ljump instead of fall
   728             // try ljump instead of fall
   715             HHJump(AltGear, jmpLJump, GoInfo);
   729             HHJump(AltGear, jmpLJump, GoInfo);
   716             exit(true)
   730             exit(true)
   717             end;
   731             end;