Show the ammo menu of the last local non-bot team when not local turn. needs testing
authornemo
Wed, 24 Feb 2010 01:55:59 +0000
changeset 2855 7e6adeb57427
parent 2854 7aac108149d9
child 2856 cc70797a0b75
Show the ammo menu of the last local non-bot team when not local turn. needs testing
hedgewars/CCHandlers.inc
hedgewars/uAmmos.pas
hedgewars/uConsole.pas
hedgewars/uTeams.pas
hedgewars/uWorld.pas
--- a/hedgewars/CCHandlers.inc	Tue Feb 23 23:54:38 2010 +0000
+++ b/hedgewars/CCHandlers.inc	Wed Feb 24 01:55:59 2010 +0000
@@ -602,16 +602,18 @@
 
 procedure chAmmoMenu(var s: shortstring);
 begin
-if CheckNoTeamOrHH then exit;
-with CurrentTeam^ do
-     with Hedgehogs[CurrHedgehog] do
-          begin
-          bSelected:= false;
+if CheckNoTeamOrHH then 
+   bShowAmmoMenu:= true
+else
+   with CurrentTeam^ do
+        with Hedgehogs[CurrHedgehog] do
+             begin
+             bSelected:= false;
 
-          if bShowAmmoMenu then bShowAmmoMenu:= false
-          else if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0) or (MultiShootAttacks > 0)
-               or ((Gear^.State and gstHHDriven) = 0) then else bShowAmmoMenu:= true
-          end
+             if bShowAmmoMenu then bShowAmmoMenu:= false
+             else if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0) or (MultiShootAttacks > 0)
+                  or ((Gear^.State and gstHHDriven) = 0) then else bShowAmmoMenu:= true
+             end
 end;
 
 procedure chFullScr(var s: shortstring);
--- a/hedgewars/uAmmos.pas	Tue Feb 23 23:54:38 2010 +0000
+++ b/hedgewars/uAmmos.pas	Wed Feb 24 01:55:59 2010 +0000
@@ -37,6 +37,7 @@
 procedure SetWeapon(weap: TAmmoType);
 procedure DisableSomeWeapons;
 procedure ResetWeapons;
+function GetAmmoByNum(num: Longword): PHHAmmo;
 
 var shoppa: boolean;
 
--- a/hedgewars/uConsole.pas	Tue Feb 23 23:54:38 2010 +0000
+++ b/hedgewars/uConsole.pas	Wed Feb 24 01:55:59 2010 +0000
@@ -267,7 +267,7 @@
 	RegisterVariable('say'     , vtCommand, @chSay          , true );
 	RegisterVariable('hogsay'  , vtCommand, @chHogSay       , true );
 	RegisterVariable('team'    , vtCommand, @chTeamSay      , true );
-	RegisterVariable('ammomenu', vtCommand, @chAmmoMenu     , false);
+	RegisterVariable('ammomenu', vtCommand, @chAmmoMenu     , true);
 	RegisterVariable('+precise', vtCommand, @chPrecise_p    , false);
 	RegisterVariable('-precise', vtCommand, @chPrecise_m    , false);
 	RegisterVariable('+left'   , vtCommand, @chLeft_p       , false);
--- a/hedgewars/uTeams.pas	Tue Feb 23 23:54:38 2010 +0000
+++ b/hedgewars/uTeams.pas	Wed Feb 24 01:55:59 2010 +0000
@@ -98,7 +98,8 @@
     TeamsCount: Longword;
     ClansArray: array[0..Pred(cMaxTeams)] of PClan;
     ClansCount: Longword;
-    LocalClan: Longword;  // first non-bot, non-extdriven clan
+    LocalClan: Longword;  // last non-bot, non-extdriven clan
+    LocalAmmo: Longword;  // last non-bot, non-extdriven clan's first team's ammo index
     CurMinAngle, CurMaxAngle: Longword;
 
 procedure init_uTeams;
@@ -347,7 +348,10 @@
    with TeamsArray[t]^ do
       begin
       if (not ExtDriven) and (Hedgehogs[0].BotLevel = 0) then
+          begin
           LocalClan:= Clan^.ClanIndex + 1;
+          LocalAmmo:= Hedgehogs[0].AmmoStore
+          end;
       th:= 0;
       for i:= 0 to cMaxHHIndex do
           if Hedgehogs[i].Gear <> nil then
--- a/hedgewars/uWorld.pas	Tue Feb 23 23:54:38 2010 +0000
+++ b/hedgewars/uWorld.pas	Wed Feb 24 01:55:59 2010 +0000
@@ -112,6 +112,7 @@
 const MENUSPEED = 15;
 var x, y, i, t, l, g: LongInt;
     Slot, Pos: LongInt;
+    Ammo: PHHAmmo;
 begin
 if (TurnTimeLeft = 0) or (((CurAmmoGear = nil) or ((CurAmmoGear^.Ammo^.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu) then bShowAmmoMenu:= false;
 if bShowAmmoMenu then
@@ -136,88 +137,87 @@
    else
        if AMxShift < 210 then inc(AMxShift, MENUSPEED);
    end;
-
-if CurrentTeam = nil then exit;
+if (CurrentTeam <> nil) and (CurrentHedgehog <> nil) and (not CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel = 0) then
+   Ammo:= CurrentHedgehog^.Ammo
+else 
+   Ammo:= GetAmmoByNum(LocalAmmo);
 Slot:= 0;
 Pos:= -1;
-with CurrentHedgehog^ do
-	begin
-	if Ammo = nil then exit;
-	SlotsNum:= 0;
-	x:= (cScreenWidth shr 1) - 210 + AMxShift;
-	y:= cScreenHeight - 40;
-	dec(y);
-	DrawSprite(sprAMBorders, x, y, 0);
-	dec(y);
-	DrawSprite(sprAMBorders, x, y, 1);
-	dec(y, 33);
-	DrawSprite(sprAMSlotName, x, y, 0);
-	for i:= cMaxSlotIndex downto 0 do
-		if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
+if Ammo = nil then exit;
+SlotsNum:= 0;
+x:= (cScreenWidth shr 1) - 210 + AMxShift;
+y:= cScreenHeight - 40;
+dec(y);
+DrawSprite(sprAMBorders, x, y, 0);
+dec(y);
+DrawSprite(sprAMBorders, x, y, 1);
+dec(y, 33);
+DrawSprite(sprAMSlotName, x, y, 0);
+for i:= cMaxSlotIndex downto 0 do
+	if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
+		begin
+		if (cScreenHeight - CursorPoint.Y >= y - 33) and (cScreenHeight - CursorPoint.Y < y) then Slot:= i;
+		dec(y, 33);
+		inc(SlotsNum);
+		DrawSprite(sprAMSlot, x, y, 0);
+		DrawSprite(sprAMSlotKeys, x + 2, y + 1, i);
+		t:= 0;
+                    g:= 0;
+		while (t <= cMaxSlotAmmoIndex) and (Ammo^[i, t].Count > 0) do
 			begin
-			if (cScreenHeight - CursorPoint.Y >= y - 33) and (cScreenHeight - CursorPoint.Y < y) then Slot:= i;
-			dec(y, 33);
-			inc(SlotsNum);
-			DrawSprite(sprAMSlot, x, y, 0);
-			DrawSprite(sprAMSlotKeys, x + 2, y + 1, i);
-			t:= 0;
-                        g:= 0;
-			while (t <= cMaxSlotAmmoIndex) and (Ammo^[i, t].Count > 0) do
+			if (Ammo^[i, t].AmmoType <> amNothing) then
 				begin
-				if (Ammo^[i, t].AmmoType <> amNothing) then
-					begin
-					l:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
+				l:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
 
-					if l >= 0 then
-						begin
-						DrawSprite(sprAMAmmosBW, x + g * 33 + 35, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
-                        if l < 100 then DrawSprite(sprTurnsLeft, x + g * 33 + 51, y + 17, l);
-						end else
-						DrawSprite(sprAMAmmos, x + g * 33 + 35, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
-					if (Slot = i)
-					and (CursorPoint.X >= x + g * 33 + 35)
-					and (CursorPoint.X < x + g * 33 + 68) then
-						begin
-						if (l < 0) then DrawSprite(sprAMSelection, x + g * 33 + 35, y + 1, 0);
-						Pos:= t;
-						end;
-					inc(g)
+				if l >= 0 then
+					begin
+					DrawSprite(sprAMAmmosBW, x + g * 33 + 35, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
+                    if l < 100 then DrawSprite(sprTurnsLeft, x + g * 33 + 51, y + 17, l);
+					end else
+					DrawSprite(sprAMAmmos, x + g * 33 + 35, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
+				if (Slot = i)
+				and (CursorPoint.X >= x + g * 33 + 35)
+				and (CursorPoint.X < x + g * 33 + 68) then
+					begin
+					if (l < 0) then DrawSprite(sprAMSelection, x + g * 33 + 35, y + 1, 0);
+					Pos:= t;
 					end;
-					inc(t)
-				end
-			end;
-	dec(y, 1);
-	DrawSprite(sprAMBorders, x, y, 0);
+				inc(g)
+				end;
+				inc(t)
+			end
+		end;
+dec(y, 1);
+DrawSprite(sprAMBorders, x, y, 0);
 
-	if (Pos >= 0) then
-		begin
-		if (Ammo^[Slot, Pos].Count > 0) and (Ammo^[Slot, Pos].AmmoType <> amNothing) then
-			if (amSel <> Ammo^[Slot, Pos].AmmoType) or (WeaponTooltipTex = nil) then
-				begin
-				amSel:= Ammo^[Slot, Pos].AmmoType;
-				RenderWeaponTooltip(amSel)
-				end;
-			
-			DrawTexture(cScreenWidth div 2 - 200 + AMxShift, cScreenHeight - 68, Ammoz[Ammo^[Slot, Pos].AmmoType].NameTex);
+if (Pos >= 0) then
+	begin
+	if (Ammo^[Slot, Pos].Count > 0) and (Ammo^[Slot, Pos].AmmoType <> amNothing) then
+		if (amSel <> Ammo^[Slot, Pos].AmmoType) or (WeaponTooltipTex = nil) then
+			begin
+			amSel:= Ammo^[Slot, Pos].AmmoType;
+			RenderWeaponTooltip(amSel)
+			end;
+		
+		DrawTexture(cScreenWidth div 2 - 200 + AMxShift, cScreenHeight - 68, Ammoz[Ammo^[Slot, Pos].AmmoType].NameTex);
 
-			if Ammo^[Slot, Pos].Count < AMMO_INFINITE then
-				DrawTexture(cScreenWidth div 2 + AMxShift - 35, cScreenHeight - 68, CountTexz[Ammo^[Slot, Pos].Count]);
+		if Ammo^[Slot, Pos].Count < AMMO_INFINITE then
+			DrawTexture(cScreenWidth div 2 + AMxShift - 35, cScreenHeight - 68, CountTexz[Ammo^[Slot, Pos].Count]);
 
-			if bSelected and (Ammoz[Ammo^[Slot, Pos].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber < 0) then
-				begin
-				bShowAmmoMenu:= false;
-				SetWeapon(Ammo^[Slot, Pos].AmmoType);
-				bSelected:= false;
-				FreeWeaponTooltip;
-				exit
-				end;
-		end
-	else
-		FreeWeaponTooltip;
-	
-	if (WeaponTooltipTex <> nil) and (AMxShift = 0) then
-		ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, y);
-	end;
+		if bSelected and (Ammoz[Ammo^[Slot, Pos].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber < 0) then
+			begin
+			bShowAmmoMenu:= false;
+			SetWeapon(Ammo^[Slot, Pos].AmmoType);
+			bSelected:= false;
+			FreeWeaponTooltip;
+			exit
+			end;
+	end
+else
+	FreeWeaponTooltip;
+
+if (WeaponTooltipTex <> nil) and (AMxShift = 0) then
+	ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, y);
 
 bSelected:= false;
 if AMxShift = 0 then DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)