hedgewars/uGearsHandlers.pas
branchsdl2transition
changeset 11362 ed5a6478e710
parent 11046 47a8c19ecb60
child 13607 212036414957
--- a/hedgewars/uGearsHandlers.pas	Tue Nov 10 18:16:35 2015 +0100
+++ b/hedgewars/uGearsHandlers.pas	Tue Nov 10 20:43:13 2015 +0100
@@ -1,6 +1,6 @@
 (*
  * Hedgewars, a free turn based strategy game
- * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com>
+ * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -13,7 +13,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *)
 
 {$INCLUDE "options.inc"}
@@ -23,7 +23,7 @@
 
 uses uTypes;
 
-procedure cakeStep(Gear: PGear);
+function cakeStep(Gear: PGear): boolean;
 
 implementation
 
@@ -31,19 +31,24 @@
 
 
 
-const dirs: array[0..3] of TPoint =   ((X: 0; Y: -1), (X: 1; Y: 0),(X: 0; Y: 1),(X: -1; Y: 0));
+const dirs: array[0..3] of TPoint = ((x: 0;  y: -1),
+                                     (x: 1;  y:  0),
+                                     (x: 0;  y:  1),
+                                     (x: -1; y:  0));
 
 procedure PrevAngle(Gear: PGear; dA: LongInt); inline;
 begin
+    inc(Gear^.WDTimer);
     Gear^.Angle := (LongInt(Gear^.Angle) - dA) and 3
 end;
 
 procedure NextAngle(Gear: PGear; dA: LongInt); inline;
 begin
+    inc(Gear^.WDTimer);
     Gear^.Angle := (LongInt(Gear^.Angle) + dA) and 3
 end;
 
-procedure cakeStep(Gear: PGear);
+function cakeStep(Gear: PGear): boolean;
 var
     xx, yy, xxn, yyn: LongInt;
     dA: LongInt;
@@ -57,30 +62,40 @@
     if (xx = 0) then
         if TestCollisionYwithGear(Gear, yy) <> 0 then
             PrevAngle(Gear, dA)
-    else
-        begin
-        Gear^.Tag := 0;
-        Gear^.Y := Gear^.Y + int2hwFloat(yy);
-        if TestCollisionXwithGear(Gear, xxn) = 0 then
+        else
             begin
-            Gear^.X := Gear^.X + int2hwFloat(xxn);
-            NextAngle(Gear, dA)
+            Gear^.Tag := 0;
+
+            if TestCollisionXwithGear(Gear, xxn) <> 0 then
+                Gear^.WDTimer:= 0;
+
+            Gear^.Y := Gear^.Y + int2hwFloat(yy);
+            if TestCollisionXwithGear(Gear, xxn) = 0 then
+                begin
+                Gear^.X := Gear^.X + int2hwFloat(xxn);
+                NextAngle(Gear, dA)
+                end
             end;
-        end;
 
     if (yy = 0) then
         if TestCollisionXwithGear(Gear, xx) <> 0 then
             PrevAngle(Gear, dA)
-    else
-        begin
-        Gear^.Tag := 0;
-        Gear^.X := Gear^.X + int2hwFloat(xx);
-        if TestCollisionYwithGear(Gear, yyn) = 0 then
+        else
             begin
-            Gear^.Y := Gear^.Y + int2hwFloat(yyn);
-            NextAngle(Gear, dA)
+            Gear^.Tag := 0;
+
+            if TestCollisionYwithGear(Gear, yyn) <> 0 then
+                Gear^.WDTimer:= 0;
+
+            Gear^.X := Gear^.X + int2hwFloat(xx);
+            if TestCollisionYwithGear(Gear, yyn) = 0 then
+                begin
+                Gear^.Y := Gear^.Y + int2hwFloat(yyn);
+                NextAngle(Gear, dA)
+                end
             end;
-        end;
+
+    cakeStep:= Gear^.WDTimer < 4
 end;
 
 end.