New Lua call: Retreat, to force turn into Retreat time
authorWuzzy <Wuzzy2@mail.ru>
Sat, 21 Apr 2018 17:17:42 +0200
changeset 13345 85644a45e988
parent 13344 450e37b2b4d4
child 13346 0c3f612edc19
New Lua call: Retreat, to force turn into Retreat time
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Thu Apr 19 15:48:00 2018 +0200
+++ b/ChangeLog.txt	Sat Apr 21 17:17:42 2018 +0200
@@ -1,5 +1,9 @@
 + features
 * bugfixes
+====================== 0.9.25 ======================
+Lua API:
+ + New call: Retreat(time [, respectGetAwayTimeFactor): Force current turn into retreating mode
+
 ====================== 0.9.24.1 ====================
  * Fix crash when portable portal device is fired at reduced graphics quality
  * Fix possible crash when starting Hedgewars frontend in fullscreen mode
--- a/hedgewars/uScript.pas	Thu Apr 19 15:48:00 2018 +0200
+++ b/hedgewars/uScript.pas	Sat Apr 21 17:17:42 2018 +0200
@@ -1926,6 +1926,35 @@
     lc_endturn:= 0
 end;
 
+function lc_retreat(L : Plua_State) : LongInt; Cdecl;
+var n, time: LongInt;
+    respectFactor: Boolean;
+const
+    call = 'Retreat';
+    params = 'time [, respectGetAwayTimeFactor]';
+begin
+    if CheckAndFetchParamCount(L, 1, 2, call, params, n) then
+        begin
+        IsGetAwayTime:= true;
+        AttackBar:= 0;
+        time:= Trunc(lua_tonumber(L, 1));
+        if n = 2 then
+            respectFactor:= lua_toboolean(L, 2)
+        else
+            respectFactor:= True;
+        if respectFactor then
+            TurnTimeLeft:= (time * cGetAwayTime) div 100
+        else
+            TurnTimeLeft:= time;
+        if ((CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil)) then
+            begin
+            CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstAttacked;
+            CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State and (not gstAttacking);
+            end;
+        end;
+    lc_retreat:= 0
+end;
+
 function lc_skipturn(L : Plua_State): LongInt; Cdecl;
 begin
     L:= L; // avoid compiler hint
@@ -3830,6 +3859,7 @@
 lua_register(luaState, _P'GetGearType', @lc_getgeartype);
 lua_register(luaState, _P'EndGame', @lc_endgame);
 lua_register(luaState, _P'EndTurn', @lc_endturn);
+lua_register(luaState, _P'Retreat', @lc_retreat);
 lua_register(luaState, _P'SkipTurn', @lc_skipturn);
 lua_register(luaState, _P'GetTeamStats', @lc_getteamstats);
 lua_register(luaState, _P'SendStat', @lc_sendstat);