# HG changeset patch
# User Wuzzy <Wuzzy2@mail.ru>
# Date 1518109839 -3600
# Node ID fa402ce826c28223b1ce34960d60f99a3a4e4004
# Parent  9400a272c88fc93d340f745f3dd3d5a992231716
Add callback: onEndTurn

diff -r 9400a272c88f -r fa402ce826c2 ChangeLog.txt
--- a/ChangeLog.txt	Thu Feb 08 15:44:08 2018 +0100
+++ b/ChangeLog.txt	Thu Feb 08 18:10:39 2018 +0100
@@ -29,6 +29,7 @@
 
 Lua API:
  + New call: WriteLnToChat(string): Add a line in the chat
+ + New callback: onEndTurn(): Called at the end of a turn (when gears have settled)
  * Fix call: SetWeapon(amNothing) now unselects weapon
  * Fix global: TotalRounds was stuck at -1 for several turns
 
diff -r 9400a272c88f -r fa402ce826c2 hedgewars/uGears.pas
--- a/hedgewars/uGears.pas	Thu Feb 08 15:44:08 2018 +0100
+++ b/hedgewars/uGears.pas	Thu Feb 08 18:10:39 2018 +0100
@@ -62,7 +62,7 @@
 
 var delay: LongWord;
     delay2: LongWord;
-    step: (stDelay, stChDmg, stSweep, stTurnReact,
+    step: (stInit, stDelay, stChDmg, stSweep, stTurnReact,
     stAfterDelay, stChWin, stWater, stChWin2, stHealth,
     stSpawn, stNTurn);
     NewTurnTick: LongWord;
@@ -253,6 +253,11 @@
 
 if AllInactive then
 case step of
+    stInit:
+        begin
+        ScriptCall('onEndTurn');
+        inc(step)
+        end;
     stDelay:
         begin
         if delay = 0 then