New Lua call: EndTurn to end turn
authorWuzzy <almikes@aol.com>
Wed, 19 Apr 2017 17:50:31 +0200
changeset 12291 b4dde7035fe2
parent 12290 3cdd664f6d0c
child 12292 faf1b93422ba
New Lua call: EndTurn to end turn
ChangeLog.txt
hedgewars/uGearsHedgehog.pas
hedgewars/uScript.pas
hedgewars/uVariables.pas
--- a/ChangeLog.txt	Wed Apr 19 08:35:31 2017 -0400
+++ b/ChangeLog.txt	Wed Apr 19 17:50:31 2017 +0200
@@ -229,6 +229,7 @@
  + New call: SetAmmoDescriptionAppendix(ammoType, descAppend) -- Append a custom text to the description of an ammo type without overwriting it
  + New call: GetHogFort(gearUid) -- Returns the name of the fort of the hog's team
  + New call: PlaceRubber(x, y, frameIdx) -- Places a rubber
+ + New call: EndTurn([noTaunts]) -- Ends the current turn
  + New hook: onVisualGearAdd(vgUid) -- called when a visual gear is added
  + New hook: onVisualGearDelete(vgUid) -- called when a visual gear is deleted
  + New hook: onUsedAmmo(ammoType) -- called when ammo has been finished using (e.g. after both shotgun shots)
--- a/hedgewars/uGearsHedgehog.pas	Wed Apr 19 08:35:31 2017 -0400
+++ b/hedgewars/uGearsHedgehog.pas	Wed Apr 19 17:50:31 2017 +0200
@@ -1232,14 +1232,14 @@
 else if not isInMultiShoot then
     AllInactive:= false;
 
-if (TurnTimeLeft = 0) or (HHGear^.Damage > 0) then
+if (TurnTimeLeft = 0) or (HHGear^.Damage > 0) or (LuaEndTurnRequested = true) then
     begin
     if (Hedgehog^.CurAmmoType = amKnife) then
        LoadHedgehogHat(Hedgehog^, Hedgehog^.Hat);
     if TagTurnTimeLeft = 0 then
         TagTurnTimeLeft:= TurnTimeLeft;
     TurnTimeLeft:= 0;
-    if ((HHGear^.State and gstAttacked) = 0) and (HHGear^.Damage = 0) then
+    if ((HHGear^.State and gstAttacked) = 0) and (HHGear^.Damage = 0) and (LuaNoEndTurnTaunts = false) then
         begin
         AddVoice(sndBoring, Hedgehog^.Team^.voicepack);
         if (GameFlags and gfInfAttack = 0) then
@@ -1251,6 +1251,8 @@
     isCursorVisible:= false;
     HHGear^.State:= HHGear^.State and (not (gstHHDriven or gstAnimation or gstAttacking));
     AttackBar:= 0;
+    LuaEndTurnRequested:= false;
+    LuaNoEndTurnTaunts:= false;
     if HHGear^.Damage > 0 then
         HHGear^.State:= HHGear^.State and (not (gstHHJumping or gstHHHJump));
     exit
--- a/hedgewars/uScript.pas	Wed Apr 19 08:35:31 2017 -0400
+++ b/hedgewars/uScript.pas	Wed Apr 19 17:50:31 2017 +0200
@@ -1861,6 +1861,19 @@
     lc_endgame:= 0
 end;
 
+function lc_endturn(L : Plua_State) : LongInt; Cdecl;
+var n: LongInt;
+const
+    call = 'EndTurn';
+    params = '[noTaunts]';
+begin
+    if CheckAndFetchParamCount(L, 0, 1, call, params, n) then
+        if n >= 1 then
+            LuaNoEndTurnTaunts:= lua_toboolean(L, 1);
+    LuaEndTurnRequested:= true;
+    lc_endturn:= 0
+end;
+
 function lc_sendstat(L : Plua_State) : LongInt; Cdecl;
 var statInfo : TStatInfoType;
     i, n     : LongInt;
@@ -3392,6 +3405,7 @@
 lua_register(luaState, _P'WriteLnToConsole', @lc_writelntoconsole);
 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'SendStat', @lc_sendstat);
 lua_register(luaState, _P'SendHealthStatsOff', @lc_sendhealthstatsoff);
 lua_register(luaState, _P'FindPlace', @lc_findplace);
--- a/hedgewars/uVariables.pas	Wed Apr 19 08:35:31 2017 -0400
+++ b/hedgewars/uVariables.pas	Wed Apr 19 17:50:31 2017 +0200
@@ -245,6 +245,10 @@
 
     LuaTemplateNumber : LongWord;
 
+    // for EndTurn Lua call
+    LuaEndTurnRequested: boolean;
+    LuaNoEndTurnTaunts: boolean;
+
     LastVoice : TVoice;
 
     mobileRecord: TMobileRecord;
@@ -2834,6 +2838,9 @@
 
     LuaTemplateNumber:= 0;
 
+    LuaEndTurnRequested:= false;
+    LuaNoEndTurnTaunts:= false;
+
     UIDisplay:= uiAll;
     LocalMessage:= 0;