hedgewars/HHHandlers.inc
changeset 941 b5222ddafe1f
parent 931 ab4d98858a40
child 952 9dd48265e0b9
equal deleted inserted replaced
940:769adb0ad082 941:b5222ddafe1f
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17  *)
    17  *)
    18 
    18 
    19 ////////////////////////////////////////////////////////////////////////////////
    19 ////////////////////////////////////////////////////////////////////////////////
    20 procedure ChangeAmmo(Gear: PGear);
    20 procedure ChangeAmmo(Gear: PGear);
    21 var slot: Longword;
    21 var slot, i: Longword;
    22 begin
    22 begin
    23 slot:= Gear^.MsgParam;
    23 slot:= Gear^.MsgParam;
    24 
    24 
    25 with PHedgehog(Gear^.Hedgehog)^ do
    25 with PHedgehog(Gear^.Hedgehog)^ do
    26 	begin
    26 	begin
    30 
    30 
    31 	Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump or gm_Slot);
    31 	Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump or gm_Slot);
    32 
    32 
    33 	if CurSlot = slot then
    33 	if CurSlot = slot then
    34 		begin
    34 		begin
       
    35 		i:= 0;
       
    36 		repeat
    35 		inc(CurAmmo);
    37 		inc(CurAmmo);
    36 		if (CurAmmo > cMaxSlotAmmoIndex) or (Ammo^[slot, CurAmmo].Count = 0) then CurAmmo:= 0
    38 		if (CurAmmo > cMaxSlotAmmoIndex) then
       
    39 			begin
       
    40 			CurAmmo:= 0;
       
    41 			inc(i);
       
    42 			TryDo(i < 2, 'Engine bug: no ammo in current slot', true)
       
    43 			end;
       
    44 		until (Ammo^[slot, CurAmmo].Count > 0) and (Team^.Clan^.TurnNumber > Ammoz[Ammo^[slot, CurAmmo].AmmoType].SkipTurns)
    37 		end else
    45 		end else
    38 	if Ammo^[slot, 0].Count > 0 then
       
    39 		begin
    46 		begin
    40 		CurSlot:= slot;
    47 		i:= 0;
    41 		CurAmmo:= 0
    48 		// check whether there's ammo in slot
    42 		end;
    49 		while (i <= cMaxSlotAmmoIndex)
       
    50 		  and ((Ammo^[slot, i].Count = 0)
       
    51 		       or (Team^.Clan^.TurnNumber <= Ammoz[Ammo^[slot, i].AmmoType].SkipTurns)) do inc(i);
       
    52 		
       
    53 		if i <= cMaxSlotAmmoIndex then
       
    54 			begin
       
    55 			CurSlot:= slot;
       
    56 			CurAmmo:= i
       
    57 			end
       
    58 		end
    43 	end;
    59 	end;
    44 
    60 
    45 ApplyAmmoChanges(PHedgehog(Gear^.Hedgehog)^)
    61 ApplyAmmoChanges(PHedgehog(Gear^.Hedgehog)^)
    46 end;
    62 end;
    47 
    63 
    48 procedure HHSetWeapon(Gear: PGear);
    64 procedure HHSetWeapon(Gear: PGear);
    49 var t: LongInt;
    65 var t: LongInt;
    50     weap: TAmmoType;
    66     weap: TAmmoType;
    51 begin
    67 begin
    52 weap:= TAmmoType(Gear^.MsgParam);
    68 weap:= TAmmoType(Gear^.MsgParam);
       
    69 
       
    70 if PHedgehog(Gear^.Hedgehog)^.Team^.Clan^.TurnNumber <= Ammoz[weap].SkipTurns then exit; // weapon isn't activated yet
       
    71 
    53 Gear^.MsgParam:= Ammoz[weap].Slot;
    72 Gear^.MsgParam:= Ammoz[weap].Slot;
    54 
    73 
    55 t:= cMaxSlotAmmoIndex;
    74 t:= cMaxSlotAmmoIndex;
    56 
    75 
    57 Gear^.Message:= Gear^.Message and not gm_Weapon;
    76 Gear^.Message:= Gear^.Message and not gm_Weapon;