hedgewars/uAIAmmoTests.pas
changeset 994 ea415d03968c
parent 983 d21ad13cd17d
child 998 65792c4e6f01
equal deleted inserted replaced
993:4319810f23c1 994:ea415d03968c
    28                      AttackPutX, AttackPutY: LongInt;
    28                      AttackPutX, AttackPutY: LongInt;
    29                      end;
    29                      end;
    30 
    30 
    31 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    31 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    32 function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    32 function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
       
    33 function TestMortar(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    33 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    34 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    34 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    35 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    35 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    36 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    36 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    37 function TestFirePunch(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    37 function TestAirAttack(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    38 function TestAirAttack(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
    63                   (proc: nil;              flags: 0), // amMineStrike
    64                   (proc: nil;              flags: 0), // amMineStrike
    64                   (proc: nil;              flags: 0), // amBlowTorch
    65                   (proc: nil;              flags: 0), // amBlowTorch
    65                   (proc: nil;              flags: 0), // amGirder
    66                   (proc: nil;              flags: 0), // amGirder
    66                   (proc: nil;              flags: amtest_OnTurn), // amTeleport
    67                   (proc: nil;              flags: amtest_OnTurn), // amTeleport
    67                   (proc: nil;              flags: 0), // amSwitch
    68                   (proc: nil;              flags: 0), // amSwitch
    68                   (proc: nil;              flags: 0), // amMortar
    69                   (proc: @TestMortar;      flags: 0), // amMortar
    69                   (proc: nil;              flags: 0)  // amKamikaze
    70                   (proc: nil;              flags: 0)  // amKamikaze
    70                   );
    71                   );
    71 
    72 
    72 const BadTurn = Low(LongInt) div 4;
    73 const BadTurn = Low(LongInt) div 4;
    73 
    74 
   157       dec(t)
   158       dec(t)
   158     until TestColl(hwRound(x), hwRound(y), 5) or (t = 0);
   159     until TestColl(hwRound(x), hwRound(y), 5) or (t = 0);
   159     EX:= hwRound(x);
   160     EX:= hwRound(x);
   160     EY:= hwRound(y);
   161     EY:= hwRound(y);
   161     if t < 50 then CheckTrace:= RateExplosion(Me, EX, EY, 101)
   162     if t < 50 then CheckTrace:= RateExplosion(Me, EX, EY, 101)
   162               else CheckTrace:= Low(LongInt)
   163               else CheckTrace:= BadTurn
   163     end;
   164     end;
   164 
   165 
   165 begin
   166 begin
   166 Result:= BadTurn;
   167 Result:= BadTurn;
   167 TestTime:= 0;
   168 TestTime:= 0;
   185         Result:= Score
   186         Result:= Score
   186         end;
   187         end;
   187      end
   188      end
   188 until (TestTime = 4000);
   189 until (TestTime = 4000);
   189 TestGrenade:= Result
   190 TestGrenade:= Result
       
   191 end;
       
   192 
       
   193 function TestMortar(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
       
   194 const tDelta = 24;
       
   195 var Vx, Vy, r: hwFloat;
       
   196     Score, EX, EY, Result: LongInt;
       
   197     TestTime: Longword;
       
   198 
       
   199 	function CheckTrace: LongInt;
       
   200 	var x, y, dY: hwFloat;
       
   201 	begin
       
   202 	x:= Me^.X;
       
   203 	y:= Me^.Y;
       
   204 	dY:= -Vy;
       
   205 	repeat
       
   206 		x:= x + Vx;
       
   207 		y:= y + dY;
       
   208 		dY:= dY + cGravity;
       
   209 		EX:= hwRound(x);
       
   210 		EY:= hwRound(y);
       
   211 	until TestColl(EX, EY, 5) or (EY > 1000);
       
   212 	if EY < 1000 then
       
   213 		begin
       
   214 		CheckTrace:= RateExplosion(Me, EX, EY, 91);
       
   215 		if (CheckTrace = 0)
       
   216 			and (not dY.isNegative) then CheckTrace:= - abs(Targ.Y - EY) div 32;
       
   217 		end
       
   218 	else
       
   219 		CheckTrace:= BadTurn
       
   220 	end;
       
   221 
       
   222 	function Solve: LongWord;
       
   223 	var A, B, D, T: hwFloat;
       
   224 		C: LongInt;
       
   225 	begin
       
   226 	A:= hwSqr(cGravity) * _0_25;
       
   227 	B:= - cGravity * (Targ.Y - hwRound(Me^.Y)) - _1;
       
   228 	C:= sqr(Targ.Y - hwRound(Me^.Y)) + sqr(Targ.X - hwRound(Me^.X));
       
   229 	D:= hwSqr(B) - (A * C * 4);
       
   230 	if D.isNegative = false then
       
   231 		begin
       
   232 		D:= ( - B + hwSqrt(D)) * _0_5 / A;
       
   233 		if D.isNegative = false then
       
   234 			T:= hwSqrt(D)
       
   235 		else
       
   236 			T:= _0;
       
   237 		Solve:= hwRound(T)
       
   238 		end else Solve:= 0
       
   239 	end;
       
   240 
       
   241 begin
       
   242 Result:= BadTurn;
       
   243 ap.ExplR:= 0;
       
   244 
       
   245 
       
   246 TestTime:= Solve;
       
   247 
       
   248 if TestTime = 0 then exit;
       
   249 
       
   250 	Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime);
       
   251 	Vy:= cGravity * (TestTime div 2) - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(TestTime);
       
   252 
       
   253 	Score:= CheckTrace;
       
   254 	if Result < Score then
       
   255 		begin
       
   256 		ap.Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random(Level));
       
   257 		ap.Power:= 1;
       
   258 		ap.ExplR:= 100;
       
   259 		ap.ExplX:= EX;
       
   260 		ap.ExplY:= EY;
       
   261 		Result:= Score
       
   262 		end;
       
   263 
       
   264 TestMortar:= Result
   190 end;
   265 end;
   191 
   266 
   192 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   267 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   193 var Vx, Vy, x, y: hwFloat;
   268 var Vx, Vy, x, y: hwFloat;
   194     rx, ry, Result: LongInt;
   269     rx, ry, Result: LongInt;