- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE
authorunc0rr
Sun, 18 May 2008 10:54:43 +0000
changeset 941 b5222ddafe1f
parent 940 769adb0ad082
child 942 b41af014d85e
- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE - Initial implementation of weapon activation only after some turns
hedgewars/HHHandlers.inc
hedgewars/uAI.pas
hedgewars/uAmmos.pas
hedgewars/uConsts.pas
hedgewars/uTeams.pas
--- a/hedgewars/HHHandlers.inc	Sat May 17 22:21:45 2008 +0000
+++ b/hedgewars/HHHandlers.inc	Sun May 18 10:54:43 2008 +0000
@@ -18,7 +18,7 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure ChangeAmmo(Gear: PGear);
-var slot: Longword;
+var slot, i: Longword;
 begin
 slot:= Gear^.MsgParam;
 
@@ -32,14 +32,30 @@
 
 	if CurSlot = slot then
 		begin
+		i:= 0;
+		repeat
 		inc(CurAmmo);
-		if (CurAmmo > cMaxSlotAmmoIndex) or (Ammo^[slot, CurAmmo].Count = 0) then CurAmmo:= 0
+		if (CurAmmo > cMaxSlotAmmoIndex) then
+			begin
+			CurAmmo:= 0;
+			inc(i);
+			TryDo(i < 2, 'Engine bug: no ammo in current slot', true)
+			end;
+		until (Ammo^[slot, CurAmmo].Count > 0) and (Team^.Clan^.TurnNumber > Ammoz[Ammo^[slot, CurAmmo].AmmoType].SkipTurns)
 		end else
-	if Ammo^[slot, 0].Count > 0 then
 		begin
-		CurSlot:= slot;
-		CurAmmo:= 0
-		end;
+		i:= 0;
+		// check whether there's ammo in slot
+		while (i <= cMaxSlotAmmoIndex)
+		  and ((Ammo^[slot, i].Count = 0)
+		       or (Team^.Clan^.TurnNumber <= Ammoz[Ammo^[slot, i].AmmoType].SkipTurns)) do inc(i);
+		
+		if i <= cMaxSlotAmmoIndex then
+			begin
+			CurSlot:= slot;
+			CurAmmo:= i
+			end
+		end
 	end;
 
 ApplyAmmoChanges(PHedgehog(Gear^.Hedgehog)^)
@@ -50,6 +66,9 @@
     weap: TAmmoType;
 begin
 weap:= TAmmoType(Gear^.MsgParam);
+
+if PHedgehog(Gear^.Hedgehog)^.Team^.Clan^.TurnNumber <= Ammoz[weap].SkipTurns then exit; // weapon isn't activated yet
+
 Gear^.MsgParam:= Ammoz[weap].Slot;
 
 t:= cMaxSlotAmmoIndex;
--- a/hedgewars/uAI.pas	Sat May 17 22:21:45 2008 +0000
+++ b/hedgewars/uAI.pas	Sun May 18 10:54:43 2008 +0000
@@ -129,7 +129,7 @@
                    MadeActions: TActions;
                    Hedgehog: TGear;
                    end;
-                   
+
 var Stack: record
            Count: Longword;
            States: array[0..Pred(cBranchStackSize)] of TStackEntry;
@@ -310,6 +310,7 @@
    OutError('AI: no targets!?', false);
    exit
    end;
+
 FillBonuses((Me^.State and gstAttacked) <> 0);
 for a:= Low(TAmmoType) to High(TAmmoType) do
     CanUseAmmo[a]:= Assigned(AmmoTests[a].proc) and HHHasAmmo(PHedgehog(Me^.Hedgehog)^, a);
--- a/hedgewars/uAmmos.pas	Sat May 17 22:21:45 2008 +0000
+++ b/hedgewars/uAmmos.pas	Sun May 18 10:54:43 2008 +0000
@@ -107,7 +107,12 @@
         if hhammo^[slot, ami].Count > 0 then
            ammos[hhammo^[slot, ami].AmmoType]:= hhammo^[slot, ami].Count;
 
-if ammos[ammo] <> AMMO_INFINITE then inc(ammos[ammo], Ammoz[ammo].NumberInCase);
+if ammos[ammo] <> AMMO_INFINITE then
+   begin
+   inc(ammos[ammo], Ammoz[ammo].NumberInCase);
+   if ammos[ammo] > AMMO_INFINITE then ammos[ammo]:= AMMO_INFINITE
+   end;
+
 FillAmmoStore(hhammo, ammos)
 end;
 
@@ -151,7 +156,8 @@
 while (ami <= cMaxSlotAmmoIndex) do
       begin
       with Hedgehog.Ammo^[Slot, ami] do
-            if (AmmoType = Ammo) and (Count > 0) then exit(true);
+            if (AmmoType = Ammo) then
+               exit((Count > 0) and (Hedgehog.Team^.Clan^.TurnNumber > Ammoz[AmmoType].SkipTurns));
       inc(ami)
       end;
 HHHasAmmo:= false
@@ -164,7 +170,7 @@
 
 with Hedgehog do
      begin
-     if (Ammo^[CurSlot, CurAmmo].Count = 0)then
+     if (Ammo^[CurSlot, CurAmmo].Count = 0) then
         begin
         CurAmmo:= 0;
         CurSlot:= 0;
--- a/hedgewars/uConsts.pas	Sat May 17 22:21:45 2008 +0000
+++ b/hedgewars/uConsts.pas	Sun May 18 10:54:43 2008 +0000
@@ -436,6 +436,7 @@
                                   TimeAfterTurn: Longword;
                                   minAngle, maxAngle: Longword;
                                   isDamaging: boolean;
+                                  SkipTurns: Longword;
                                   PosCount: Longword;
                                   PosSprite: TSprite;
                                   end = (
@@ -456,6 +457,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: true;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidClusterBomb;
@@ -475,6 +477,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: true;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidBazooka;
@@ -493,6 +496,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: true;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidUFO;
@@ -512,6 +516,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: true;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidShotgun;
@@ -529,6 +534,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: true;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidPickHammer;
@@ -549,6 +555,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: false;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidSkip;
@@ -566,6 +573,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: false;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidRope;
@@ -586,6 +594,7 @@
                                    minAngle: 0;
                                    maxAngle: cMaxAngle div 2;
                                    isDamaging: false;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidMine;
@@ -606,6 +615,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: true;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidDEagle;
@@ -623,6 +633,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: true;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidDynamite;
@@ -643,6 +654,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: true;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidFirePunch;
@@ -662,6 +674,7 @@
                                    MinAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: true;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidWhip;
@@ -679,6 +692,7 @@
                                    MinAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: true;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidBaseballBat;
@@ -696,6 +710,7 @@
                                    minAngle: 0;
                                    maxAngle: cMaxAngle div 2;
                                    isDamaging: true;
+                                   SkipTurns: 2;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidParachute;
@@ -717,6 +732,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: false;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidAirAttack;
@@ -737,6 +753,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: true;
+                                   SkipTurns: 5;
                                    PosCount: 2;
                                    PosSprite: sprAmAirplane),
                                   (NameId: sidMineStrike;
@@ -757,6 +774,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: true;
+                                   SkipTurns: 5;
                                    PosCount: 2;
                                    PosSprite: sprAmAirplane),
                                   (NameId: sidBlowTorch;
@@ -774,6 +792,7 @@
                                    minAngle: 768;
                                    maxAngle: 1280;
                                    isDamaging: false;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidGirder;
@@ -794,6 +813,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: false;
+                                   SkipTurns: 0;
                                    PosCount: 8;
                                    PosSprite: sprAmGirder),
                                   (NameId: sidTeleport;
@@ -815,6 +835,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: false;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidSwitch;
@@ -834,6 +855,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: false;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater),
                                   (NameId: sidMortar;
@@ -851,6 +873,7 @@
                                    minAngle: 0;
                                    maxAngle: 0;
                                    isDamaging: true;
+                                   SkipTurns: 0;
                                    PosCount: 1;
                                    PosSprite: sprWater)
                                   );
--- a/hedgewars/uTeams.pas	Sat May 17 22:21:45 2008 +0000
+++ b/hedgewars/uTeams.pas	Sun May 18 10:54:43 2008 +0000
@@ -68,6 +68,7 @@
              CurrTeam: LongWord;
              ClanHealth: LongInt;
              ClanIndex: LongInt;
+             TurnNumber: LongWord;
              end;
 
 var CurrentTeam: PTeam = nil;
@@ -181,6 +182,9 @@
      InsertGearToList(Gear);
      FollowGear:= Gear
      end;
+
+inc(CurrentTeam^.Clan^.TurnNumber);
+
 ResetKbd;
 
 cWindSpeed:= rndSign(GetRandom * cMaxWindSpeed);