lua API functions to enable or disable game flags
authormartin_bede
Tue, 08 Jan 2013 00:40:20 +0400
changeset 8366 67c7ba2b82a3
parent 8365 fbd799a1e95b
child 8367 2506ed09f4be
child 8368 6feae8073965
lua API functions to enable or disable game flags
hedgewars/uScript.pas
share/hedgewars/Data/Missions/Training/Basic_Training_-_Bazooka.lua
--- a/hedgewars/uScript.pas	Mon Jan 07 08:35:29 2013 -0500
+++ b/hedgewars/uScript.pas	Tue Jan 08 00:40:20 2013 +0400
@@ -37,6 +37,7 @@
 procedure ScriptLoad(name : shortstring);
 procedure ScriptOnGameInit;
 procedure ScriptOnScreenResize;
+procedure ScriptSetInteger(name : shortstring; value : LongInt);
 
 procedure ScriptCall(fname : shortstring);
 function ScriptCall(fname : shortstring; par1: LongInt) : LongInt;
@@ -224,6 +225,30 @@
     lc_hidemission:= 0;
 end;
 
+function lc_enablegameflags(L : Plua_State) : LongInt; Cdecl;
+var i : integer;
+begin
+    for i:= 1 to lua_gettop(L) do
+        if (GameFlags and lua_tointeger(L, i)) = 0 then
+            GameFlags += lua_tointeger(L, i);
+    ScriptSetInteger('GameFlags', GameFlags);
+end;
+
+function lc_disablegameflags(L : Plua_State) : LongInt; Cdecl;
+var i : integer;
+begin
+    for i:= 1 to lua_gettop(L) do
+        if (GameFlags and lua_tointeger(L, i)) <> 0 then
+            GameFlags -= lua_tointeger(L, i);
+    ScriptSetInteger('GameFlags', GameFlags);
+end;
+
+function lc_cleargameflags(L : Plua_State) : LongInt; Cdecl;
+begin
+    GameFlags:= 0;
+    ScriptSetInteger('GameFlags', GameFlags);
+end;
+
 function lc_addcaption(L : Plua_State) : LongInt; Cdecl;
 begin
     if lua_gettop(L) = 1 then
@@ -2335,6 +2360,9 @@
 lua_register(luaState, _P'GetInputMask', @lc_getinputmask);
 lua_register(luaState, _P'SetInputMask', @lc_setinputmask);
 lua_register(luaState, _P'AddGear', @lc_addgear);
+lua_register(luaState, _P'EnableGameFlags', @lc_enablegameflags);
+lua_register(luaState, _P'DisableGameFlags', @lc_disablegameflags);
+lua_register(luaState, _P'ClearGameFlags', @lc_cleargameflags);
 lua_register(luaState, _P'DeleteGear', @lc_deletegear);
 lua_register(luaState, _P'AddVisualGear', @lc_addvisualgear);
 lua_register(luaState, _P'DeleteVisualGear', @lc_deletevisualgear);
--- a/share/hedgewars/Data/Missions/Training/Basic_Training_-_Bazooka.lua	Mon Jan 07 08:35:29 2013 -0500
+++ b/share/hedgewars/Data/Missions/Training/Basic_Training_-_Bazooka.lua	Tue Jan 08 00:40:20 2013 +0400
@@ -64,7 +64,15 @@
 	-- The base number for the random number generator
 	Seed = 1
 	-- Game settings and rules
-	GameFlags = gfMultiWeapon + gfOneClanMode + gfSolidLand
+    EnableGameFlags(gfMultiWeapon, gfOneClanMode, gfSolidLand)
+    -- Uncommenting this wouldn't do anything
+    --EnableGameFlags(gfMultiWeapon, gfOneClanMode, gfSolidLand)
+    -- Neither this
+    --DisableGameFlags(gfArtillery)
+    -- Uncommenting this would make the terrain damageable
+    --DisableGameFlags(gfSolidLand)
+    -- Uncommenting this would remove all flags set previously
+    --ClearGameFlags()
 	-- The time the player has to move each round (in ms)
 	TurnTime = 60000
 	-- The frequency of crate drops