Add GetHogFort to Lua API
authorWuzzy <almikes@aol.com>
Wed, 23 Nov 2016 19:39:01 +0100
changeset 12051 553f97b1e4fe
parent 12050 f71e34babe8c
child 12052 7163626748e0
Add GetHogFort to Lua API
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Wed Nov 23 18:57:08 2016 +0100
+++ b/ChangeLog.txt	Wed Nov 23 19:39:01 2016 +0100
@@ -121,6 +121,7 @@
  + New call: GetVisualGearType(vgUid) -- returns the visual gear type
  + New call: SetAmmoTexts(ammoType, name, caption, description) -- Overwrite displayed name and description of an ammo type
  + 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 hook: onVisualGearAdd(vgUid) -- called when a visual gear is added
  + New hook: onVisualGearDelete(vgUid) -- called when a visual gear is deleted
  + New variable: AirMinesNum -- Number of air mines being placed on a medium-sized map
--- a/hedgewars/uScript.pas	Wed Nov 23 18:57:08 2016 +0100
+++ b/hedgewars/uScript.pas	Wed Nov 23 19:39:01 2016 +0100
@@ -1362,6 +1362,23 @@
     lc_gethogflag:= 1
 end;
 
+function lc_gethogfort(L : Plua_State) : LongInt; Cdecl;
+var gear : PGear;
+begin
+    if CheckLuaParamCount(L, 1, 'GetHogFort', 'gearUid') then
+        begin
+        gear:= GearByUID(lua_tointeger(L, 1));
+        // TODO error messages
+        if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
+            lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.FortName))
+        else
+            lua_pushnil(L);
+        end
+    else
+        lua_pushnil(L); // return value on stack (nil)
+    lc_gethogfort:= 1
+end;
+
 function lc_ishoglocal(L : Plua_State) : LongInt; Cdecl;
 var gear : PGear;
 begin
@@ -3405,6 +3422,7 @@
 lua_register(luaState, _P'SetClanColor', @lc_setclancolor);
 lua_register(luaState, _P'GetHogVoicepack', @lc_gethogvoicepack);
 lua_register(luaState, _P'GetHogFlag', @lc_gethogflag);
+lua_register(luaState, _P'GetHogFort', @lc_gethogfort);
 lua_register(luaState, _P'GetHogGrave', @lc_gethoggrave);
 lua_register(luaState, _P'IsHogLocal', @lc_ishoglocal);
 lua_register(luaState, _P'GetHogTeamName', @lc_gethogteamname);