Lua API: Add EnableSwitchHog to manually enable hog switching
authorWuzzy <Wuzzy2@mail.ru>
Fri, 04 May 2018 14:38:01 +0200
changeset 13383 c53530142442
parent 13382 03e4d9b5b09c
child 13384 4dd503978c0a
Lua API: Add EnableSwitchHog to manually enable hog switching
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Fri May 04 01:39:22 2018 +0200
+++ b/ChangeLog.txt	Fri May 04 14:38:01 2018 +0200
@@ -25,6 +25,7 @@
 Lua API:
  + New call: Retreat(time [, respectGetAwayTimeFactor): Force current turn into retreating mode
  + New call: GetAmmoTimer(gearUid, ammoType): Returns current set timer for given ammoType and hog gear in ms. Returns nil for non-timerable ammo
+ + New call: EnableSwitchHog(): Enable hog switching
  + New parameter: SetAmmoTexts: 5th param. showExtra: Set to false to hide texts like “Not yet available”
 
 ====================== 0.9.24.1 ====================
--- a/hedgewars/uScript.pas	Fri May 04 01:39:22 2018 +0200
+++ b/hedgewars/uScript.pas	Fri May 04 14:38:01 2018 +0200
@@ -1677,6 +1677,19 @@
     lc_switchhog:= 0
 end;
 
+function lc_enableswitchhog(L : Plua_State) : LongInt; Cdecl;
+var gear: PGear;
+begin
+    if CheckLuaParamCount(L, 0, 'EnableSwitchHog', '') then
+        begin
+        gear:= AddGear(hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y), gtSwitcher, 0, _0, _0, 0);
+        CurAmmoGear:= gear;
+        lastGearByUID:= gear;
+        bShowFinger:= false;
+        end;
+    lc_enableswitchhog:= 0;
+end;
+
 function lc_addammo(L : Plua_State) : LongInt; Cdecl;
 var gear : PGear;
     at, n, c: LongInt;
@@ -3966,6 +3979,7 @@
 lua_register(luaState, _P'GetZoom', @lc_getzoom);
 lua_register(luaState, _P'HogSay', @lc_hogsay);
 lua_register(luaState, _P'SwitchHog', @lc_switchhog);
+lua_register(luaState, _P'EnableSwitchHog', @lc_enableswitchhog);
 lua_register(luaState, _P'HogTurnLeft', @lc_hogturnleft);
 lua_register(luaState, _P'GetGearElasticity', @lc_getgearelasticity);
 lua_register(luaState, _P'SetGearElasticity', @lc_setgearelasticity);