hedgewars/uAIAmmoTests.pas
changeset 15658 34c32a11203e
parent 15656 21dece8f55fe
child 15659 fd1a580a35d6
equal deleted inserted replaced
15657:e229d0cacd37 15658:34c32a11203e
    24 const
    24 const
    25     amtest_Rare            = $00000001; // check only several positions
    25     amtest_Rare            = $00000001; // check only several positions
    26     amtest_NoTarget        = $00000002; // each pos, but no targetting
    26     amtest_NoTarget        = $00000002; // each pos, but no targetting
    27     amtest_MultipleAttacks = $00000004; // test could result in multiple attacks, set AttacksNum
    27     amtest_MultipleAttacks = $00000004; // test could result in multiple attacks, set AttacksNum
    28     amtest_NoTrackFall     = $00000008; // skip fall tracing.  
    28     amtest_NoTrackFall     = $00000008; // skip fall tracing.  
       
    29     amtest_LaserSight      = $00000010; // supports laser sighting
    29 
    30 
    30 var windSpeed: real;
    31 var windSpeed: real;
       
    32     aiLaserSighting: boolean;
    31 
    33 
    32 type TAttackParams = record
    34 type TAttackParams = record
    33         Time, Bounce, AttacksNum: Longword;
    35         Time, Bounce, AttacksNum: Longword;
    34         Angle, Power: LongInt;
    36         Angle, Power: LongInt;
    35         ExplX, ExplY, ExplR: LongInt;
    37         ExplX, ExplY, ExplR: LongInt;
    79             (proc: nil;              flags: 0), // amNothing
    81             (proc: nil;              flags: 0), // amNothing
    80             (proc: @TestGrenade;     flags: 0), // amGrenade
    82             (proc: @TestGrenade;     flags: 0), // amGrenade
    81             (proc: @TestClusterBomb; flags: 0), // amClusterBomb
    83             (proc: @TestClusterBomb; flags: 0), // amClusterBomb
    82             (proc: @TestBazooka;     flags: 0), // amBazooka
    84             (proc: @TestBazooka;     flags: 0), // amBazooka
    83             (proc: @TestBee;         flags: amtest_Rare), // amBee
    85             (proc: @TestBee;         flags: amtest_Rare), // amBee
    84             (proc: @TestShotgun;     flags: 0), // amShotgun
    86             (proc: @TestShotgun;     flags: amtest_LaserSight), // amShotgun
    85             (proc: nil;              flags: 0), // amPickHammer
    87             (proc: nil;              flags: 0), // amPickHammer
    86             (proc: nil;              flags: 0), // amSkip
    88             (proc: nil;              flags: 0), // amSkip
    87             (proc: nil;              flags: 0), // amRope
    89             (proc: nil;              flags: 0), // amRope
    88             (proc: @TestMine;        flags: amtest_NoTarget), // amMine
    90             (proc: @TestMine;        flags: amtest_NoTarget), // amMine
    89             (proc: @TestDesertEagle; flags: amtest_MultipleAttacks), // amDEagle
    91             (proc: @TestDesertEagle; flags: amtest_MultipleAttacks or amtest_LaserSight), // amDEagle
    90             (proc: @TestDynamite;    flags: amtest_NoTarget), // amDynamite
    92             (proc: @TestDynamite;    flags: amtest_NoTarget), // amDynamite
    91             (proc: @TestFirePunch;   flags: amtest_NoTarget), // amFirePunch
    93             (proc: @TestFirePunch;   flags: amtest_NoTarget), // amFirePunch
    92             (proc: @TestWhip;        flags: amtest_NoTarget), // amWhip
    94             (proc: @TestWhip;        flags: amtest_NoTarget), // amWhip
    93             (proc: @TestBaseballBat; flags: amtest_NoTarget), // amBaseballBat
    95             (proc: @TestBaseballBat; flags: amtest_NoTarget), // amBaseballBat
    94             (proc: nil;              flags: 0), // amParachute
    96             (proc: nil;              flags: 0), // amParachute
    98             (proc: nil;              flags: 0), // amGirder
   100             (proc: nil;              flags: 0), // amGirder
    99             (proc: nil;              flags: 0), // amTeleport
   101             (proc: nil;              flags: 0), // amTeleport
   100             //(proc: @TestTeleport;    flags: amtest_OnTurn), // amTeleport
   102             //(proc: @TestTeleport;    flags: amtest_OnTurn), // amTeleport
   101             (proc: nil;              flags: 0), // amSwitch
   103             (proc: nil;              flags: 0), // amSwitch
   102             (proc: @TestMortar;      flags: 0), // amMortar
   104             (proc: @TestMortar;      flags: 0), // amMortar
   103             (proc: @TestKamikaze;    flags: 0), // amKamikaze
   105             (proc: @TestKamikaze;    flags: amtest_LaserSight), // amKamikaze
   104             (proc: @TestCake;        flags: amtest_Rare or amtest_NoTarget), // amCake
   106             (proc: @TestCake;        flags: amtest_Rare or amtest_NoTarget), // amCake
   105             (proc: @TestSeduction;   flags: amtest_NoTarget), // amSeduction
   107             (proc: @TestSeduction;   flags: amtest_NoTarget), // amSeduction
   106             (proc: @TestWatermelon;  flags: 0), // amWatermelon
   108             (proc: @TestWatermelon;  flags: 0), // amWatermelon
   107             (proc: nil;              flags: 0), // amHellishBomb
   109             (proc: nil;              flags: 0), // amHellishBomb
   108             (proc: nil;              flags: 0), // amNapalm
   110             (proc: nil;              flags: 0), // amNapalm
   109             (proc: @TestDrillRocket; flags: 0), // amDrill
   111             (proc: @TestDrillRocket; flags: 0), // amDrill
   110             (proc: nil;              flags: 0), // amBallgun
   112             (proc: nil;              flags: 0), // amBallgun
   111             (proc: @TestRCPlane;     flags: 0), // amRCPlane
   113             (proc: @TestRCPlane;     flags: amtest_LaserSight), // amRCPlane
   112             (proc: nil;              flags: 0), // amLowGravity
   114             (proc: nil;              flags: 0), // amLowGravity
   113             (proc: nil;              flags: 0), // amExtraDamage
   115             (proc: nil;              flags: 0), // amExtraDamage
   114             (proc: nil;              flags: 0), // amInvulnerable
   116             (proc: nil;              flags: 0), // amInvulnerable
   115             (proc: nil;              flags: 0), // amExtraTime
   117             (proc: nil;              flags: 0), // amExtraTime
   116             (proc: nil;              flags: 0), // amLaserSight
   118             (proc: nil;              flags: 0), // amLaserSight
   132             (proc: nil;              flags: 0), // amTardis
   134             (proc: nil;              flags: 0), // amTardis
   133             (proc: nil;              flags: 0), // amLandGun
   135             (proc: nil;              flags: 0), // amLandGun
   134             (proc: nil;              flags: 0), // amIceGun
   136             (proc: nil;              flags: 0), // amIceGun
   135             (proc: @TestKnife;       flags: 0), // amKnife
   137             (proc: @TestKnife;       flags: 0), // amKnife
   136             (proc: nil;              flags: 0), // amRubber
   138             (proc: nil;              flags: 0), // amRubber
   137             (proc: @TestAirMine;     flags: 0), // amAirMine
   139             (proc: @TestAirMine;     flags: amtest_LaserSight), // amAirMine
   138             (proc: nil;              flags: 0), // amCreeper
   140             (proc: nil;              flags: 0), // amCreeper
   139             (proc: @TestMinigun;     flags: 0)  // amMinigun
   141             (proc: @TestMinigun;     flags: amtest_LaserSight)  // amMinigun
   140             );
   142             );
   141 
   143 
   142 implementation
   144 implementation
   143 uses uVariables, uUtils, uGearsHandlers;
   145 uses uVariables, uUtils, uGearsHandlers;
   144 
   146 
   485         if (Level < 3) and (range <= 600) and (meY >= ry) and
   487         if (Level < 3) and (range <= 600) and (meY >= ry) and
   486             (((ap.Angle < 0) and (windSpeed > 0)) or ((ap.Angle > 0) and (windSpeed < 0))) then
   488             (((ap.Angle < 0) and (windSpeed > 0)) or ((ap.Angle > 0) and (windSpeed < 0))) then
   487             exit(BadTurn);
   489             exit(BadTurn);
   488 
   490 
   489         // Apply inaccuracy
   491         // Apply inaccuracy
   490         if (not cLaserSighting) then
   492         if (not aiLaserSighting) then
   491             inc(ap.Angle, + AIrndSign(random((Level - 1) * 9)));
   493             inc(ap.Angle, + AIrndSign(random((Level - 1) * 9)));
   492 
   494 
   493         if (valueResult <= 0) then
   495         if (valueResult <= 0) then
   494             valueResult:= BadTurn;
   496             valueResult:= BadTurn;
   495         exit(valueResult)
   497         exit(valueResult)
   974 
   976 
   975 Vx:= (Targ.Point.X - x) * 1 / 1024;
   977 Vx:= (Targ.Point.X - x) * 1 / 1024;
   976 Vy:= (Targ.Point.Y - y) * 1 / 1024;
   978 Vy:= (Targ.Point.Y - y) * 1 / 1024;
   977 ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
   979 ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
   978 // Apply inaccuracy
   980 // Apply inaccuracy
   979 if (not cLaserSighting) then
   981 if (not aiLaserSighting) then
   980     inc(ap.Angle, + AIrndSign(random((Level - 1) * 10)));
   982     inc(ap.Angle, + AIrndSign(random((Level - 1) * 10)));
   981 repeat
   983 repeat
   982     x:= x + vX;
   984     x:= x + vX;
   983     y:= y + vY;
   985     y:= y + vY;
   984     rx:= trunc(x);
   986     rx:= trunc(x);
  1031 t:= 2 / sqrt(sqr(Targ.Point.X - x)+sqr(Targ.Point.Y-y));
  1033 t:= 2 / sqrt(sqr(Targ.Point.X - x)+sqr(Targ.Point.Y-y));
  1032 Vx:= (Targ.Point.X - x) * t;
  1034 Vx:= (Targ.Point.X - x) * t;
  1033 Vy:= (Targ.Point.Y - y) * t;
  1035 Vy:= (Targ.Point.Y - y) * t;
  1034 ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
  1036 ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
  1035 // Apply inaccuracy
  1037 // Apply inaccuracy
  1036 if (not cLaserSighting) then
  1038 if (not aiLaserSighting) then
  1037     inc(ap.Angle, + AIrndSign(random((Level - 1) * 10)));
  1039     inc(ap.Angle, + AIrndSign(random((Level - 1) * 10)));
  1038 d:= 0;
  1040 d:= 0;
  1039 
  1041 
  1040 ix:= trunc(x);
  1042 ix:= trunc(x);
  1041 iy:= trunc(y);
  1043 iy:= trunc(y);
  1317         dx:= (Targ.Point.X - x) * t;
  1319         dx:= (Targ.Point.X - x) * t;
  1318         dy:= (Targ.Point.Y - y) * t;
  1320         dy:= (Targ.Point.Y - y) * t;
  1319 
  1321 
  1320         ap.Angle:= DxDy2AttackAnglef(dx, -dy);
  1322         ap.Angle:= DxDy2AttackAnglef(dx, -dy);
  1321         // Apply inaccuracy
  1323         // Apply inaccuracy
  1322         if (not cLaserSighting) then
  1324         if (not aiLaserSighting) then
  1323             inc(ap.Angle, + AIrndSign(random((Level - 1) * 10)));
  1325             inc(ap.Angle, + AIrndSign(random((Level - 1) * 10)));
  1324         end;
  1326         end;
  1325 
  1327 
  1326     if dx >= 0 then cx:= 0.45 else cx:= -0.45;
  1328     if dx >= 0 then cx:= 0.45 else cx:= -0.45;
  1327 
  1329 
  2212             exit(BadTurn);
  2214             exit(BadTurn);
  2213         ap.Power:= ((range + cHHRadius*2) * cMaxPower) div MAX_RANGE;
  2215         ap.Power:= ((range + cHHRadius*2) * cMaxPower) div MAX_RANGE;
  2214 
  2216 
  2215         // Apply inaccuracy
  2217         // Apply inaccuracy
  2216         inc(ap.Power, (random(93*(Level-1)) - 31*(Level-1))); // Level 1 spread: -124 .. 248
  2218         inc(ap.Power, (random(93*(Level-1)) - 31*(Level-1))); // Level 1 spread: -124 .. 248
  2217         if (not cLaserSighting) then
  2219         if (not aiLaserSighting) then
  2218             inc(ap.Angle, + AIrndSign(random((Level - 1) * 10)));
  2220             inc(ap.Angle, + AIrndSign(random((Level - 1) * 10)));
  2219 
  2221 
  2220         if (valueResult <= 0) then
  2222         if (valueResult <= 0) then
  2221             valueResult:= BadTurn;
  2223             valueResult:= BadTurn;
  2222         exit(valueResult)
  2224         exit(valueResult)
  2259 // Minigun angle is limited
  2261 // Minigun angle is limited
  2260 if (ap.Angle < Ammoz[amMinigun].minAngle) or (ap.Angle > Ammoz[amMinigun].maxAngle) then
  2262 if (ap.Angle < Ammoz[amMinigun].minAngle) or (ap.Angle > Ammoz[amMinigun].maxAngle) then
  2261     exit(BadTurn);
  2263     exit(BadTurn);
  2262 
  2264 
  2263 // Apply inaccuracy
  2265 // Apply inaccuracy
  2264 if (not cLaserSighting) then
  2266 if (not aiLaserSighting) then
  2265     inc(ap.Angle, + AIrndSign(random((Level - 1) * 10)));
  2267     inc(ap.Angle, + AIrndSign(random((Level - 1) * 10)));
  2266 repeat
  2268 repeat
  2267     x:= x + vX;
  2269     x:= x + vX;
  2268     y:= y + vY;
  2270     y:= y + vY;
  2269     rx:= trunc(x);
  2271     rx:= trunc(x);