Step 1. Add current hedgehog as top bit of bottom byte.
authornemo
Sat, 23 Jun 2012 21:37:47 -0400
changeset 7270 93e92e82d5c8
parent 7268 3a61c53346a8
child 7272 71df899c4163
Step 1. Add current hedgehog as top bit of bottom byte.
hedgewars/GSHandlers.inc
hedgewars/uCollisions.pas
hedgewars/uLandGraphics.pas
hedgewars/uScript.pas
hedgewars/uTeams.pas
--- a/hedgewars/GSHandlers.inc	Sat Jun 23 22:44:11 2012 +0400
+++ b/hedgewars/GSHandlers.inc	Sat Jun 23 21:37:47 2012 -0400
@@ -2768,7 +2768,7 @@
             CurrentTeam^.CurrHedgehog := Succ(CurrentTeam^.CurrHedgehog) mod (CurrentTeam^.HedgehogsNumber);
         until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) and (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^.Damage = 0);
 
-        CurrentHedgehog := @CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog];
+        SwitchCurrentHedgehog(@CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]);
         AmmoMenuInvalidated:= true; 
 
         HHGear := CurrentHedgehog^.Gear;
--- a/hedgewars/uCollisions.pas	Sat Jun 23 22:44:11 2012 +0400
+++ b/hedgewars/uCollisions.pas	Sat Jun 23 21:37:47 2012 -0400
@@ -82,7 +82,7 @@
     X:= hwRound(Gear^.X);
     Y:= hwRound(Gear^.Y);
     Radius:= Gear^.Radius;
-    ChangeRoundInLand(X, Y, Radius - 1, true);
+    ChangeRoundInLand(X, Y, Radius - 1, true, Gear = CurrentHedgehog^.Gear);
     cGear:= Gear
     end;
 Gear^.CollisionIndex:= Count;
@@ -103,7 +103,7 @@
 if Gear^.CollisionIndex >= 0 then
     begin
     with cinfos[Gear^.CollisionIndex] do
-        ChangeRoundInLand(X, Y, Radius - 1, false);
+        ChangeRoundInLand(X, Y, Radius - 1, false, Gear = CurrentHedgehog^.Gear);
     cinfos[Gear^.CollisionIndex]:= cinfos[Pred(Count)];
     cinfos[Gear^.CollisionIndex].cGear^.CollisionIndex:= Gear^.CollisionIndex;
     Gear^.CollisionIndex:= -1;
--- a/hedgewars/uLandGraphics.pas	Sat Jun 23 22:44:11 2012 +0400
+++ b/hedgewars/uLandGraphics.pas	Sat Jun 23 21:37:47 2012 -0400
@@ -36,7 +36,7 @@
 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte);
 procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt);
 procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword);
-procedure ChangeRoundInLand(X, Y, Radius: LongInt; doSet: boolean);
+procedure ChangeRoundInLand(X, Y, Radius: LongInt; doSet, isCurrent: boolean);
 function  LandBackPixel(x, y: LongInt): LongWord;
 procedure DrawLine(X1, Y1, X2, Y2: LongInt; Color: Longword);
 procedure DrawThickLine(X1, Y1, X2, Y2, radius: LongInt; color: Longword);
@@ -99,46 +99,62 @@
             Land[y - dx, i]:= Value;
 end;
 
-procedure ChangeCircleLines(x, y, dx, dy: LongInt; doSet: boolean);
+procedure ChangeCircleLines(x, y, dx, dy: LongInt; doSet, isCurrent: boolean);
 var i: LongInt;
 begin
 if not doSet then
     begin
     if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
         for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
-            if (Land[y + dy, i] > 0) and (Land[y + dy, i] < 256) then
-                dec(Land[y + dy, i]); // check > 0 because explosion can erase collision data
+            if isCurrent then 
+                Land[y + dy, i]:= Land[y + dy, i] and $FF7F
+            else if Land[y + dy, i] and $007F > 0 then
+                Land[y + dy, i]:= (Land[y + dy, i] and $FF80) or ((Land[y + dy, i] and $7F) - 1);
     if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
         for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
-            if (Land[y - dy, i] > 0) and (Land[y - dy, i] < 256) then
-                dec(Land[y - dy, i]);
+            if isCurrent then 
+                Land[y - dy, i]:= Land[y - dy, i] and $FF7F
+            else if Land[y - dy, i] and $007F > 0 then
+                Land[y - dy, i]:= (Land[y - dy, i] and $FF80) or ((Land[y - dy, i] and $7F) - 1);
     if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
         for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
-            if (Land[y + dx, i] > 0) and (Land[y + dx, i] < 256) then
-                dec(Land[y + dx, i]);
+            if isCurrent then 
+                Land[y + dx, i]:= Land[y + dx, i] and $FF7F
+            else if Land[y + dx, i] and $007F > 0 then
+                Land[y + dx, i]:= (Land[y + dx, i] and $FF80) or ((Land[y + dx, i] and $7F) - 1);
     if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
         for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
-            if (Land[y - dx, i] > 0) and (Land[y - dx, i] < 256) then
-                dec(Land[y - dx, i]);
+            if isCurrent then 
+                Land[y - dx, i]:= Land[y - dx, i] and $FF7F
+            else if Land[y - dx, i] and $007F > 0 then
+                Land[y - dx, i]:= (Land[y - dx, i] and $FF80) or ((Land[y - dx, i] and $7F) - 1)
     end
 else
     begin
     if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
         for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
-            if (Land[y + dy, i] < 256) then
-                inc(Land[y + dy, i]);
-    if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
-        for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
-            if (Land[y - dy, i] < 256) then
-                inc(Land[y - dy, i]);
-    if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
-        for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
-            if (Land[y + dx, i] < 256) then
-                inc(Land[y + dx, i]);
-    if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
-        for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
-            if (Land[y - dx, i] < 256) then
-                inc(Land[y - dx, i]);
+            if isCurrent then 
+                Land[y + dy, i]:= Land[y + dy, i] or $80
+            else if Land[y + dy, i] and $007F < 127 then
+                Land[y + dy, i]:= (Land[y + dy, i] and $FF80) or ((Land[y + dy, i] and $7F) + 1);
+    if ((y - dy) and LAND_HEIGHT_MASK) = 0 then                                                   
+        for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do                                  
+            if isCurrent then                                                                     
+                Land[y - dy, i]:= Land[y - dy, i] or $80                                          
+            else if Land[y - dy, i] and $007F < 127 then                                          
+                Land[y - dy, i]:= (Land[y - dy, i] and $FF80) or ((Land[y - dy, i] and $7F) + 1);
+    if ((y + dx) and LAND_HEIGHT_MASK) = 0 then                                                   
+        for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do                                  
+            if isCurrent then                                                                     
+                Land[y + dx, i]:= Land[y + dx, i] or $80                                          
+            else if Land[y + dx, i] and $007F < 127 then                                          
+                Land[y + dx, i]:= (Land[y + dx, i] and $FF80) or ((Land[y + dx, i] and $7F) + 1);
+    if ((y - dx) and LAND_HEIGHT_MASK) = 0 then                                                   
+        for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do                                  
+            if isCurrent then                                                                     
+                Land[y - dx, i]:= Land[y - dx, i] or $80                                          
+            else if Land[y - dx, i] and $007F < 127 then                                          
+                Land[y - dx, i]:= (Land[y - dx, i] and $FF80) or ((Land[y - dx, i] and $7F) + 1)
     end
 end;
 
@@ -164,7 +180,7 @@
     FillCircleLines(x, y, dx, dy, Value);
 end;
 
-procedure ChangeRoundInLand(X, Y, Radius: LongInt; doSet: boolean);
+procedure ChangeRoundInLand(X, Y, Radius: LongInt; doSet, isCurrent: boolean);
 var dx, dy, d: LongInt;
 begin
 dx:= 0;
@@ -172,7 +188,7 @@
 d:= 3 - 2 * Radius;
 while (dx < dy) do
     begin
-    ChangeCircleLines(x, y, dx, dy, doSet);
+    ChangeCircleLines(x, y, dx, dy, doSet, isCurrent);
     if (d < 0) then
         d:= d + 4 * dx + 6
     else
@@ -183,7 +199,7 @@
     inc(dx)
     end;
 if (dx = dy) then
-    ChangeCircleLines(x, y, dx, dy, doSet)
+    ChangeCircleLines(x, y, dx, dy, doSet, isCurrent)
 end;
 
 procedure FillLandCircleLines0(x, y, dx, dy: LongInt);
--- a/hedgewars/uScript.pas	Sat Jun 23 22:44:11 2012 +0400
+++ b/hedgewars/uScript.pas	Sat Jun 23 21:37:47 2012 -0400
@@ -973,10 +973,9 @@
             prevgear^.Z := cHHZ;
             RemoveGearFromList(prevgear);
             InsertGearToList(prevgear);
-
-            CurrentHedgehog := gear^.Hedgehog;
-// yes, this will muck up turn sequence
-            CurrentTeam := gear^.Hedgehog^.Team;
+            
+            SwitchCurrentHedgehog(gear^.Hedgehog);
+            CurrentTeam:= CurrentHedgehog^.Team;
 
             gear^.State:= gear^.State or gstHHDriven;
             gear^.Active := true;
--- a/hedgewars/uTeams.pas	Sat Jun 23 22:44:11 2012 +0400
+++ b/hedgewars/uTeams.pas	Sat Jun 23 21:37:47 2012 -0400
@@ -35,6 +35,7 @@
 procedure RestoreTeamsFromSave;
 function  CheckForWin: boolean;
 procedure TeamGoneEffect(var Team: TTeam);
+procedure SwitchCurrentHedgehog(newHog: PHedgehog);
 
 implementation
 uses uLocale, uAmmos, uChat, uVariables, uUtils, uIO, uCaptions, uCommands, uDebug, uScript,
@@ -184,7 +185,7 @@
         end
 until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil);
 
-CurrentHedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]);
+SwitchCurrentHedgehog(@(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]));
 {$IFDEF USE_TOUCH_INTERFACE}
 if (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NoCrosshair) = 0 then
     begin
@@ -488,7 +489,7 @@
 with CurrentTeam^ do
     begin
     SplitBySpace(id, s);
-    CurrentHedgehog:= @Hedgehogs[HedgehogsNumber];
+    SwitchCurrentHedgehog(@Hedgehogs[HedgehogsNumber]);
     val(id, CurrentHedgehog^.BotLevel, c);
     Gear:= AddGear(0, 0, gtHedgehog, 0, _0, _0, 0);
     SplitBySpace(s, id);
@@ -618,6 +619,21 @@
 RecountAllTeamsHealth();
 end;
 
+procedure SwitchCurrentHedgehog(newHog: PHedgehog);
+var oldCI, newCI: boolean;
+    oldHH: PHedgehog;
+begin
+    oldCI:= (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.Gear^.CollisionIndex >= 0);
+    newCI:= (newHog^.Gear <> nil) and (newHog^.Gear^.CollisionIndex >= 0);
+    if oldCI then DeleteCI(CurrentHedgehog^.Gear);
+    if newCI then DeleteCI(newHog^.Gear);
+    oldHH:= CurrentHedgehog;
+    CurrentHedgehog:= newHog;
+    if oldCI then AddGearCI(oldHH^.Gear);
+    if newCI then AddGearCI(newHog^.Gear)
+end;
+
+
 procedure initModule;
 begin
 RegisterVariable('addhh', @chAddHH, false);