# HG changeset patch
# User nemo
# Date 1418051687 18000
# Node ID 8e8b320eefad7262ef5f0976c35058646ce9cc50
# Parent  35d059bd09320a769c5b68f79e22a4f7f37d078e
nil out CurrentHedgehog in FreeModule, add a test for nil'd CurrentHedgehog in DelCI since I'd still like to use DeleteGear for the other stuff it does.  Move some variable initialiasations in AI Misc to hopefully avoid some uninit val errors.

diff -r 35d059bd0932 -r 8e8b320eefad hedgewars/uAIMisc.pas
--- a/hedgewars/uAIMisc.pas	Mon Dec 08 09:35:14 2014 -0500
+++ b/hedgewars/uAIMisc.pas	Mon Dec 08 10:14:47 2014 -0500
@@ -556,6 +556,7 @@
                 pX:= Point.x;
                 pY:= Point.y;
                 fallDmg:= 0;
+                dX:= 0;
                 if (Flags and afTrackFall <> 0) and (Score > 0) and (dmg < Score) then
                     begin
                     dX:= (0.005 * dmg + 0.01) / Density;
@@ -741,10 +742,11 @@
                 end;
             if dmg > 0 then
                 begin
+                fallDmg:= 0;
+                pX:= Point.x;
+                pY:= Point.y;
                 if (not dead) and (Score > 0) and (dmg < Score) then
                     begin
-                    pX:= Point.x;
-                    pY:= Point.y;
                     dX:= gdX * dmg / Density;
                     dY:= gdY * dmg / Density;
                     if dX < 0 then dX:= dX - 0.01
diff -r 35d059bd0932 -r 8e8b320eefad hedgewars/uCollisions.pas
--- a/hedgewars/uCollisions.pas	Mon Dec 08 09:35:14 2014 -0500
+++ b/hedgewars/uCollisions.pas	Mon Dec 08 10:14:47 2014 -0500
@@ -97,7 +97,7 @@
 if Gear^.CollisionIndex >= 0 then
     begin
     with cinfos[Gear^.CollisionIndex] do
-        ChangeRoundInLand(X, Y, Radius - 1, false, (Gear = CurrentHedgehog^.Gear) or ((Gear^.Kind = gtCase) and (Gear^.State and gstFrozen = 0)));
+        ChangeRoundInLand(X, Y, Radius - 1, false, ((CurrentHedgehog <> nil) and (Gear = CurrentHedgehog^.Gear)) or ((Gear^.Kind = gtCase) and (Gear^.State and gstFrozen = 0)));
     cinfos[Gear^.CollisionIndex]:= cinfos[Pred(Count)];
     cinfos[Gear^.CollisionIndex].cGear^.CollisionIndex:= Gear^.CollisionIndex;
     Gear^.CollisionIndex:= -1;
diff -r 35d059bd0932 -r 8e8b320eefad hedgewars/uTeams.pas
--- a/hedgewars/uTeams.pas	Mon Dec 08 09:35:14 2014 -0500
+++ b/hedgewars/uTeams.pas	Mon Dec 08 10:14:47 2014 -0500
@@ -845,6 +845,7 @@
 procedure freeModule;
 var i, h: LongWord;
 begin
+CurrentHedgehog:= nil;
 if TeamsCount > 0 then
     begin
     for i:= 0 to Pred(TeamsCount) do