hedgewars/HHHandlers.inc
changeset 927 2c1675344a6f
parent 926 d231e007452a
child 928 b9064b48b001
equal deleted inserted replaced
926:d231e007452a 927:2c1675344a6f
    17  *)
    17  *)
    18 
    18 
    19 ////////////////////////////////////////////////////////////////////////////////
    19 ////////////////////////////////////////////////////////////////////////////////
    20 procedure ChangeAmmo(Gear: PGear);
    20 procedure ChangeAmmo(Gear: PGear);
    21 var slot: Longword;
    21 var slot: Longword;
    22     caSlot, caAmmo: PLongword;
       
    23 begin
    22 begin
    24 slot:= Gear^.MsgParam;
    23 slot:= Gear^.MsgParam;
    25 
    24 
    26 with PHedgehog(Gear^.Hedgehog)^ do
    25 with PHedgehog(Gear^.Hedgehog)^ do
    27      begin
    26 	begin
    28      if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0) or (AttacksNum > 0)
    27 	if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0) or (AttacksNum > 0)
    29         or ((Gear^.State and gstHHDriven) = 0) then exit;
    28 		or ((Gear^.State and gstHHDriven) = 0) then exit;
    30 
    29 
    31      Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump or gm_Slot);
    30 	Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump or gm_Slot);
    32 
    31 
    33      if CurAmmoGear = nil then begin caSlot:= @CurSlot; caAmmo:= @CurAmmo end
    32 	if CurSlot = slot then
    34                           else begin caSlot:= @AltSlot; caAmmo:= @AltAmmo end;
    33 		begin
    35 
    34 		inc(CurAmmo);
    36      if caSlot^ = slot then
    35 		if (CurAmmo > cMaxSlotAmmoIndex) or (Ammo^[slot, CurAmmo].Count = 0) then CurAmmo:= 0
    37         begin
    36 		end else
    38         inc(caAmmo^);
    37 	if Ammo^[slot, 0].Count > 0 then
    39         if (caAmmo^ > cMaxSlotAmmoIndex) or (Ammo^[slot, caAmmo^].Count = 0) then caAmmo^:= 0
    38 		begin
    40         end else
    39 		CurSlot:= slot;
    41      if Ammo^[slot, 0].Count > 0 then
    40 		CurAmmo:= 0
    42         begin
    41 		end;
    43         caSlot^:= slot;
    42 	end;
    44         caAmmo^:= 0;
    43 
    45         end;
       
    46      end;
       
    47 ApplyAmmoChanges(PHedgehog(Gear^.Hedgehog)^)
    44 ApplyAmmoChanges(PHedgehog(Gear^.Hedgehog)^)
    48 end;
    45 end;
    49 
    46 
    50 procedure HHSetWeapon(Gear: PGear);
    47 procedure HHSetWeapon(Gear: PGear);
    51 var t: LongInt;
    48 var t: LongInt;
   474    begin
   471    begin
   475    CurAmmoGear^.Message:= Gear^.Message;
   472    CurAmmoGear^.Message:= Gear^.Message;
   476    exit
   473    exit
   477    end;
   474    end;
   478 
   475 
       
   476 if ((Gear^.Message and gm_Attack) <> 0) or
       
   477    ((Gear^.State and gstAttacking) <> 0) then Attack(Gear); // should be before others to avoid desync with '/put' msg and changing weapon msgs
       
   478 
   479 if ((Gear^.Message and gm_Slot) <> 0) then ChangeAmmo(Gear);
   479 if ((Gear^.Message and gm_Slot) <> 0) then ChangeAmmo(Gear);
   480 
   480 
   481 if ((Gear^.Message and gm_Weapon) <> 0) then HHSetWeapon(Gear);
   481 if ((Gear^.Message and gm_Weapon) <> 0) then HHSetWeapon(Gear);
   482 
   482 
   483 if ((Gear^.Message and gm_Timer) <> 0) then HHSetTimer(Gear);
   483 if ((Gear^.Message and gm_Timer) <> 0) then HHSetTimer(Gear);
   484 
       
   485 if ((Gear^.Message and gm_Attack) <> 0) or
       
   486    ((Gear^.State and gstAttacking) <> 0) then Attack(Gear);
       
   487 
   484 
   488 if (Gear^.State and gstMoving) <> 0 then
   485 if (Gear^.State and gstMoving) <> 0 then
   489    begin
   486    begin
   490    if ((Gear^.Message and gm_HJump) <> 0) and
   487    if ((Gear^.Message and gm_HJump) <> 0) and
   491       ((Gear^.State and gstHHJumping) <> 0) and
   488       ((Gear^.State and gstHHJumping) <> 0) and