Timer as hedgehog message (avoid possible desync in very rare cases)
authorunc0rr
Sun, 11 May 2008 19:21:58 +0000
changeset 926 d231e007452a
parent 925 c20156328529
child 927 2c1675344a6f
Timer as hedgehog message (avoid possible desync in very rare cases)
hedgewars/CCHandlers.inc
hedgewars/HHHandlers.inc
hedgewars/uConsts.pas
--- a/hedgewars/CCHandlers.inc	Sat May 10 16:26:53 2008 +0000
+++ b/hedgewars/CCHandlers.inc	Sun May 11 19:21:58 2008 +0000
@@ -282,14 +282,12 @@
 begin
 if (s[0] <> #1) or (s[1] < '1') or (s[1] > '5') or (CurrentTeam = nil) then exit;
 bShowFinger:= false;
-with CurrentHedgehog^ do
-     if (Ammo^[CurSlot, CurAmmo].Propz and ammoprop_Timerable) <> 0 then
-        begin
-        Ammo^[CurSlot, CurAmmo].Timer:= 1000 * (byte(s[1]) - 48);
-        with CurrentTeam^ do
-             ApplyAmmoChanges(Hedgehogs[CurrHedgehog]);
-        if not CurrentTeam^.ExtDriven then SendIPC(s);
-        end
+if not CurrentTeam^.ExtDriven then SendIPC(s);
+with CurrentHedgehog^.Gear^ do
+     begin
+     Message:= Message or gm_Timer;
+     MsgParam:= byte(s[1]) - ord('0')
+     end
 end;
 
 procedure chSlot(var s: shortstring);
--- a/hedgewars/HHHandlers.inc	Sat May 10 16:26:53 2008 +0000
+++ b/hedgewars/HHHandlers.inc	Sun May 11 19:21:58 2008 +0000
@@ -59,13 +59,26 @@
 Gear^.Message:= Gear^.Message and not gm_Weapon;
 
 with PHedgehog(Gear^.Hedgehog)^ do
-     while (Ammo^[CurSlot, CurAmmo].AmmoType <> weap) and (t >= 0) do
-           begin
-           ChangeAmmo(Gear);
-           dec(t)
-           end
+	while (Ammo^[CurSlot, CurAmmo].AmmoType <> weap) and (t >= 0) do
+		begin
+		ChangeAmmo(Gear);
+		dec(t)
+		end
 end;
 
+procedure HHSetTimer(Gear: PGear);
+begin
+Gear^.Message:= Gear^.Message and not gm_Timer;
+with PHedgehog(Gear^.Hedgehog)^ do
+	if (Ammo^[CurSlot, CurAmmo].Propz and ammoprop_Timerable) <> 0 then
+		begin
+		Ammo^[CurSlot, CurAmmo].Timer:= 1000 * Gear^.MsgParam;
+		with CurrentTeam^ do
+			ApplyAmmoChanges(Hedgehogs[CurrHedgehog]);
+		end;
+end;
+
+
 procedure Attack(Gear: PGear);
 var xx, yy: hwFloat;
 begin
@@ -467,6 +480,8 @@
 
 if ((Gear^.Message and gm_Weapon) <> 0) then HHSetWeapon(Gear);
 
+if ((Gear^.Message and gm_Timer) <> 0) then HHSetTimer(Gear);
+
 if ((Gear^.Message and gm_Attack) <> 0) or
    ((Gear^.State and gstAttacking) <> 0) then Attack(Gear);
 
--- a/hedgewars/uConsts.pas	Sat May 10 16:26:53 2008 +0000
+++ b/hedgewars/uConsts.pas	Sun May 11 19:21:58 2008 +0000
@@ -183,6 +183,7 @@
       gm_Destroy= $00000100;
       gm_Slot   = $00000200; // with param
       gm_Weapon = $00000400; // with param
+      gm_Timer  = $00000800; // with param
 
       cMaxSlotIndex       = 8;
       cMaxSlotAmmoIndex   = 2;