Lua API: SetTurnTimePaused/GetTurnTimePaused
authorWuzzy <Wuzzy2@mail.ru>
Sun, 09 Dec 2018 17:12:47 +0100
changeset 14394 d670e4efe1ed
parent 14393 c2cd3f64b9f7
child 14395 f39d34d78028
Lua API: SetTurnTimePaused/GetTurnTimePaused
ChangeLog.txt
hedgewars/uGears.pas
hedgewars/uScript.pas
hedgewars/uVariables.pas
--- a/ChangeLog.txt	Sun Dec 09 16:54:22 2018 +0100
+++ b/ChangeLog.txt	Sun Dec 09 17:12:47 2018 +0100
@@ -4,6 +4,8 @@
  + New chat command: “/help room” (shows room chat commands within the game)
 
 Lua API:
+ + New call: SetTurnTimePaused(isPaused): Call with true to pause turn time, false to unpause
+ + New call: GetTurnTimePaused(): Returns true if turn time is paused due to Lua
  + Params explode, poison in the SpawnFake*Crate functions now optional and default to false
 
 ====================== 0.9.25 ======================
--- a/hedgewars/uGears.pas	Sun Dec 09 16:54:22 2018 +0100
+++ b/hedgewars/uGears.pas	Sun Dec 09 17:12:47 2018 +0100
@@ -1147,7 +1147,8 @@
     or (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_DoesntStopTimerWhileAttacking <> 0)
     or ((GameFlags and gfInfAttack) <> 0) and (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_DoesntStopTimerWhileAttackingInInfAttackMode <> 0)
     or (CurrentHedgehog^.CurAmmoType = amSniperRifle))
-    and (not(isInMultiShoot and ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_DoesntStopTimerInMultiShoot) <> 0)));
+    and (not(isInMultiShoot and ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_DoesntStopTimerInMultiShoot) <> 0)))
+    and (not LuaClockPaused);
 end;
 
 
--- a/hedgewars/uScript.pas	Sun Dec 09 16:54:22 2018 +0100
+++ b/hedgewars/uScript.pas	Sun Dec 09 17:12:47 2018 +0100
@@ -3303,6 +3303,22 @@
     lc_setreadytimeleft:= 0;
 end;
 
+function lc_setturntimepaused(L : Plua_State) : LongInt; Cdecl;
+begin
+    if CheckLuaParamCount(L, 1, 'SetTurnTimePaused', 'isPaused') then
+        LuaClockPaused:= lua_toboolean(L, 1);
+    lc_setturntimepaused:= 0;
+end;
+
+function lc_getturntimepaused(L : Plua_State) : LongInt; Cdecl;
+begin
+    if CheckLuaParamCount(L, 0, 'GetTurnTimePaused', '') then
+        lua_pushboolean(L, LuaClockPaused)
+    else
+        lua_pushnil(L);
+    lc_getturntimepaused:= 1;
+end;
+
 function lc_startghostpoints(L : Plua_State) : LongInt; Cdecl;
 begin
     if CheckLuaParamCount(L, 1, 'StartGhostPoints', 'count') then
@@ -4337,6 +4353,8 @@
 lua_register(luaState, _P'Explode', @lc_explode);
 lua_register(luaState, _P'SetTurnTimeLeft', @lc_setturntimeleft);
 lua_register(luaState, _P'SetReadyTimeLeft', @lc_setreadytimeleft);
+lua_register(luaState, _P'SetTurnTimePaused', @lc_setturntimepaused);
+lua_register(luaState, _P'GetTurnTimePaused', @lc_getturntimepaused);
 // drawn map functions
 lua_register(luaState, _P'AddPoint', @lc_addPoint);
 lua_register(luaState, _P'FlushPoints', @lc_flushPoints);
--- a/hedgewars/uVariables.pas	Sun Dec 09 16:54:22 2018 +0100
+++ b/hedgewars/uVariables.pas	Sun Dec 09 17:12:47 2018 +0100
@@ -261,6 +261,9 @@
     LuaEndTurnRequested: boolean;
     LuaNoEndTurnTaunts: boolean;
 
+    // whether Lua requested to pause the clock
+    LuaClockPaused: boolean;
+
     MaskedSounds : array[TSound] of boolean;
 
     LastVoice : TVoice;