- Bots can use mortar
authorunc0rr
Mon, 16 Jun 2008 20:40:59 +0000
changeset 994 ea415d03968c
parent 993 4319810f23c1
child 995 6c48c6b2a65c
- Bots can use mortar - Show hp of current hedgehog when it's his turn
hedgewars.kdevelop
hedgewars/uAIAmmoTests.pas
hedgewars/uGears.pas
--- a/hedgewars.kdevelop	Thu Jun 12 10:50:05 2008 +0000
+++ b/hedgewars.kdevelop	Mon Jun 16 20:40:59 2008 +0000
@@ -98,6 +98,23 @@
       <path>CMakeFiles/CompilerIdC/CMakeCCompilerId.c</path>
       <path>CMakeFiles/CompilerIdCXX</path>
       <path>CMakeFiles/CompilerIdCXX/CMakeCXXCompilerId.cpp</path>
+      <path>Makefile</path>
+      <path>QTfrontend/qrc_hedgewars.cxx</path>
+      <path>misc</path>
+      <path>misc/fbsd-port</path>
+      <path>misc/fbsd-port/Makefile</path>
+      <path>share/Makefile</path>
+      <path>share/hedgewars/Data/Fonts/Makefile</path>
+      <path>share/hedgewars/Data/Forts/Makefile</path>
+      <path>share/hedgewars/Data/Graphics/Makefile</path>
+      <path>share/hedgewars/Data/Locale/Makefile</path>
+      <path>share/hedgewars/Data/Makefile</path>
+      <path>share/hedgewars/Data/Maps/Makefile</path>
+      <path>share/hedgewars/Data/Music/Makefile</path>
+      <path>share/hedgewars/Data/Sounds/Makefile</path>
+      <path>share/hedgewars/Data/Themes/Makefile</path>
+      <path>share/hedgewars/Data/Trainings/Makefile</path>
+      <path>share/hedgewars/Makefile</path>
     </blacklist>
     <general>
       <activedir/>
--- a/hedgewars/uAIAmmoTests.pas	Thu Jun 12 10:50:05 2008 +0000
+++ b/hedgewars/uAIAmmoTests.pas	Mon Jun 16 20:40:59 2008 +0000
@@ -30,6 +30,7 @@
 
 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
 function TestGrenade(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
+function TestMortar(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
 function TestDesertEagle(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
 function TestBaseballBat(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
@@ -65,7 +66,7 @@
                   (proc: nil;              flags: 0), // amGirder
                   (proc: nil;              flags: amtest_OnTurn), // amTeleport
                   (proc: nil;              flags: 0), // amSwitch
-                  (proc: nil;              flags: 0), // amMortar
+                  (proc: @TestMortar;      flags: 0), // amMortar
                   (proc: nil;              flags: 0)  // amKamikaze
                   );
 
@@ -159,7 +160,7 @@
     EX:= hwRound(x);
     EY:= hwRound(y);
     if t < 50 then CheckTrace:= RateExplosion(Me, EX, EY, 101)
-              else CheckTrace:= Low(LongInt)
+              else CheckTrace:= BadTurn
     end;
 
 begin
@@ -189,6 +190,80 @@
 TestGrenade:= Result
 end;
 
+function TestMortar(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
+const tDelta = 24;
+var Vx, Vy, r: hwFloat;
+    Score, EX, EY, Result: LongInt;
+    TestTime: Longword;
+
+	function CheckTrace: LongInt;
+	var x, y, dY: hwFloat;
+	begin
+	x:= Me^.X;
+	y:= Me^.Y;
+	dY:= -Vy;
+	repeat
+		x:= x + Vx;
+		y:= y + dY;
+		dY:= dY + cGravity;
+		EX:= hwRound(x);
+		EY:= hwRound(y);
+	until TestColl(EX, EY, 5) or (EY > 1000);
+	if EY < 1000 then
+		begin
+		CheckTrace:= RateExplosion(Me, EX, EY, 91);
+		if (CheckTrace = 0)
+			and (not dY.isNegative) then CheckTrace:= - abs(Targ.Y - EY) div 32;
+		end
+	else
+		CheckTrace:= BadTurn
+	end;
+
+	function Solve: LongWord;
+	var A, B, D, T: hwFloat;
+		C: LongInt;
+	begin
+	A:= hwSqr(cGravity) * _0_25;
+	B:= - cGravity * (Targ.Y - hwRound(Me^.Y)) - _1;
+	C:= sqr(Targ.Y - hwRound(Me^.Y)) + sqr(Targ.X - hwRound(Me^.X));
+	D:= hwSqr(B) - (A * C * 4);
+	if D.isNegative = false then
+		begin
+		D:= ( - B + hwSqrt(D)) * _0_5 / A;
+		if D.isNegative = false then
+			T:= hwSqrt(D)
+		else
+			T:= _0;
+		Solve:= hwRound(T)
+		end else Solve:= 0
+	end;
+
+begin
+Result:= BadTurn;
+ap.ExplR:= 0;
+
+
+TestTime:= Solve;
+
+if TestTime = 0 then exit;
+
+	Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime);
+	Vy:= cGravity * (TestTime div 2) - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(TestTime);
+
+	Score:= CheckTrace;
+	if Result < Score then
+		begin
+		ap.Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random(Level));
+		ap.Power:= 1;
+		ap.ExplR:= 100;
+		ap.ExplX:= EX;
+		ap.ExplY:= EY;
+		Result:= Score
+		end;
+
+TestMortar:= Result
+end;
+
 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
 var Vx, Vy, x, y: hwFloat;
     rx, ry, Result: LongInt;
--- a/hedgewars/uGears.pas	Thu Jun 12 10:50:05 2008 +0000
+++ b/hedgewars/uGears.pas	Mon Jun 16 20:40:59 2008 +0000
@@ -303,6 +303,7 @@
                 Result^.Elasticity:= _0_3
                 end;
       gtMortar: begin
+                Result^.Radius:= 4;
                 Result^.Elasticity:= _0_2;
                 Result^.Friction:= _0_08
                 end;
@@ -706,7 +707,9 @@
 	end;
 
 with PHedgehog(Gear^.Hedgehog)^ do
-	if (Gear^.State{ and not gstAnimation}) = 0 then
+	begin
+	if ((Gear^.State{ and not gstAnimation}) = 0)
+		or (bShowFinger and ((Gear^.State and gstHHDriven) <> 0)) then
 	begin
 	t:= hwRound(Gear^.Y) - cHHRadius - 12 + WorldDy;
 	if (cTagsMask and 1) <> 0 then
@@ -724,8 +727,8 @@
 		dec(t, Team^.NameTagTex^.h + 2);
 		DrawCentered(hwRound(Gear^.X) + WorldDx, t, Team^.NameTagTex)
 		end
-	end else // Current hedgehog
-	if (Gear^.State and gstHHDriven) <> 0 then
+	end;
+	if (Gear^.State and gstHHDriven) <> 0 then // Current hedgehog
 		begin
 		if bShowFinger and ((Gear^.State and gstHHDriven) <> 0) then
 			DrawSprite(sprFinger, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 64 + WorldDy,
@@ -744,7 +747,8 @@
 							Round(hwRound(Gear^.Y) - Cos(Gear^.Angle*pi/cMaxAngle) * 60) + WorldDy, 0,
 							hwSign(Gear^.dX) * (Gear^.Angle * 180.0) / cMaxAngle)
 					end
-			end;
+			end
+	end
 end;
 
 procedure DrawGears;