--- a/hedgewars/uGearsHedgehog.pas Sat Apr 22 19:30:24 2017 +0200
+++ b/hedgewars/uGearsHedgehog.pas Sat Apr 22 20:37:51 2017 +0200
@@ -52,10 +52,9 @@
end;
// Shouldn't more of this ammo switching stuff be moved to uAmmos ?
-function ChangeAmmo(HHGear: PGear; reverse: boolean): boolean;
+function ChangeAmmo(HHGear: PGear): boolean;
var slot, i: Longword;
- ammoidx,
- ammochangedir: LongInt;
+ ammoidx: LongInt;
prevAmmo: TAmmoType;
begin
ChangeAmmo:= false;
@@ -66,21 +65,13 @@
HHGear^.Message:= HHGear^.Message and (not gmSlot);
prevAmmo:= CurAmmoType;
ammoidx:= 0;
- if (reverse = true) then
- ammochangedir:= -1
- else
- ammochangedir:= 1;
-
if (((HHGear^.State and (gstAttacking or gstAttacked)) <> 0) and (GameFlags and gfInfAttack = 0))
or ((HHGear^.State and gstHHDriven) = 0) then
exit;
ChangeAmmo:= true;
-
- if CurAmmoType = amNothing then
- ammoidx:= cMaxSlotAmmoIndex
- else
- while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> CurAmmoType) do
- inc(ammoidx);
+
+ while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> CurAmmoType) do
+ inc(ammoidx);
if (MultiShootAttacks > 0) then
begin
@@ -97,12 +88,12 @@
MultiShootAttacks:= 0;
HHGear^.Message:= HHGear^.Message and (not (gmLJump or gmHJump));
- if (Ammoz[CurAmmoType].Slot = slot) and (CurAmmoType <> amNothing) then
+ if Ammoz[CurAmmoType].Slot = slot then
begin
i:= 0;
repeat
- inc(ammoidx, ammochangedir);
- if (ammoidx < 0) or (ammoidx > cMaxSlotAmmoIndex) then
+ inc(ammoidx);
+ if (ammoidx > cMaxSlotAmmoIndex) then
begin
inc(i);
CurAmmoType:= amNothing;
@@ -110,33 +101,29 @@
//TryDo(i < 2, 'Engine bug: no ammo in current slot', true)
end;
until (i = 1) or ((Ammo^[slot, ammoidx].Count > 0)
- and (Ammo^[slot, ammoidx].AmmoType <> amNothing)
and (Team^.Clan^.TurnNumber > Ammoz[Ammo^[slot, ammoidx].AmmoType].SkipTurns))
end
else
begin
- if reverse then
- i:= cMaxSlotAmmoIndex
- else
- i:= 0;
+ i:= 0;
// check whether there is ammo in slot
- while (ammoidx >= 0) and (i <= cMaxSlotAmmoIndex) and
- ((Ammo^[slot, i].Count = 0) or (Team^.Clan^.TurnNumber <= Ammoz[Ammo^[slot, i].AmmoType].SkipTurns) or (Ammo^[slot, i].AmmoType = amNothing))
- do inc(i, ammochangedir);
+ 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
+ if i <= cMaxSlotAmmoIndex then
ammoidx:= i
else ammoidx:= -1
end;
if ammoidx >= 0 then
CurAmmoType:= Ammo^[slot, ammoidx].AmmoType;
- // Try again in the next or previous slot
- if (CurAmmoType = prevAmmo) and (((reverse = false) and (slot < cMaxSlotIndex)) or ((reverse = true) and (slot > 0))) then
+ // Try again in the next slot
+ if (CurAmmoType = prevAmmo) and (slot < cMaxSlotIndex) then
begin
- inc(slot, ammochangedir);
+ inc(slot);
HHGear^.MsgParam:= slot;
- ChangeAmmo(HHGear, reverse)
+ ChangeAmmo(HHGear)
end
end
end;
@@ -167,7 +154,7 @@
with Hedgehog^ do
while (CurAmmoType <> weap) and (t >= 0) do
begin
- s:= ChangeAmmo(HHGear, false);
+ s:= ChangeAmmo(HHGear);
if HHGear^.State <> prevState then // so we can keep gstAttacked out of consideration when looping
newState:= HHGear^.State;
HHGear^.State:= prevState;
@@ -1326,18 +1313,8 @@
if (CurAmmoGear = nil)
or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0) then
begin
- // Press slot key to select weapon slot
if ((HHGear^.Message and gmSlot) <> 0) then
- if ((HHGear^.Message and gmPrecise) <> 0) then
- begin
- // Reverse weapon selection by holding down the Precise key
- HHGear^.Message := HHGear^.Message and (not gmPrecise);
- if ChangeAmmo(HHGear, true) then ApplyAmmoChanges(Hedgehog^);
- HHGear^.Message:= HHGear^.Message or gmPrecise
- end
- else
- // Select next weapon
- if ChangeAmmo(HHGear, false) then ApplyAmmoChanges(Hedgehog^);
+ if ChangeAmmo(HHGear) then ApplyAmmoChanges(Hedgehog^);
if ((HHGear^.Message and gmWeapon) <> 0) then
HHSetWeapon(HHGear);