# HG changeset patch # User unc0rr # Date 1255366381 0 # Node ID 23242609c44b4a185d5c94f40b243e4d244a7ae6 # Parent b87046cd8ae47d6aaa2653d073c7a0ade93094a8 Real fix to ammo slot overflow (bug triggered by r2411 fix) diff -r b87046cd8ae4 -r 23242609c44b hedgewars/uAmmos.pas --- a/hedgewars/uAmmos.pas Mon Oct 12 16:50:42 2009 +0000 +++ b/hedgewars/uAmmos.pas Mon Oct 12 16:53:01 2009 +0000 @@ -221,10 +221,10 @@ begin CurAmmo:= 0; CurSlot:= 0; - while (CurSlot < cMaxSlotIndex) and (Ammo^[CurSlot, CurAmmo].Count = 0) do - inc(CurSlot) + while (CurSlot <= cMaxSlotIndex) and (Ammo^[CurSlot, CurAmmo].Count = 0) do inc(CurSlot); + TryDo(CurSlot <= cMaxSlotIndex, 'Ammo slot index overflow', true) end; - + //bad things could happen here in case CurSlot is overflowing ApplyAngleBounds(Hedgehog, Ammo^[CurSlot, CurAmmo].AmmoType); @@ -255,15 +255,17 @@ procedure SwitchNotHeldAmmo(var Hedgehog: THedgehog); begin with Hedgehog do - if ((Ammo^[CurSlot, CurAmmo].Propz and ammoprop_DontHold) <> 0) or - (Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0) then - begin - CurAmmo:= 0; - CurSlot:= 0; - while (CurSlot < cMaxSlotIndex) and - ((Ammo^[CurSlot, CurAmmo].Count = 0) or - (Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0)) - do inc(CurSlot) + if ((Ammo^[CurSlot, CurAmmo].Propz and ammoprop_DontHold) <> 0) or + (Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0) then + begin + CurAmmo:= 0; + CurSlot:= 0; + while (CurSlot <= cMaxSlotIndex) and + ((Ammo^[CurSlot, CurAmmo].Count = 0) or + (Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0)) + do + inc(CurSlot); + TryDo(CurSlot <= cMaxSlotIndex, 'Ammo slot index overflow', true) end end; diff -r b87046cd8ae4 -r 23242609c44b hedgewars/uTeams.pas --- a/hedgewars/uTeams.pas Mon Oct 12 16:50:42 2009 +0000 +++ b/hedgewars/uTeams.pas Mon Oct 12 16:53:01 2009 +0000 @@ -208,7 +208,10 @@ procedure AfterSwitchHedgehog; var g: PGear; begin +inc(CurrentTeam^.Clan^.TurnNumber); + SwitchNotHeldAmmo(CurrentHedgehog^); + with CurrentHedgehog^ do begin with Gear^ do @@ -222,8 +225,6 @@ FollowGear:= Gear end; -inc(CurrentTeam^.Clan^.TurnNumber); - ResetKbd; cWindSpeed:= rndSign(GetRandom * cMaxWindSpeed);