Lua API: IsHogLocal(gearUid)
authorsheepluva
Fri, 16 Sep 2016 00:01:43 +0200
changeset 11852 38e7206a5df4
parent 11851 6bf91006d630
child 11853 6a0d6b00dac8
Lua API: IsHogLocal(gearUid)
hedgewars/uGearsHedgehog.pas
hedgewars/uGearsUtils.pas
hedgewars/uScript.pas
--- a/hedgewars/uGearsHedgehog.pas	Thu Sep 15 23:16:49 2016 +0200
+++ b/hedgewars/uGearsHedgehog.pas	Fri Sep 16 00:01:43 2016 +0200
@@ -660,10 +660,7 @@
     if cnt <> 0 then AddAmmo(HH, ammo, cnt)
     else AddAmmo(HH, ammo);
 
-    if (not (HH.Team^.ExtDriven
-    or (HH.BotLevel > 0)))
-    or (HH.Team^.Clan^.ClanIndex = LocalClan)
-    or (GameType = gmtDemo)  then
+    if IsHogLocal(@HH) or (GameType = gmtDemo)  then
         begin
         if cnt <> 0 then
             s:= trammo[Ammoz[ammo].NameId] + ansistring(' (+' + IntToStr(cnt) + ')')
--- a/hedgewars/uGearsUtils.pas	Thu Sep 15 23:16:49 2016 +0200
+++ b/hedgewars/uGearsUtils.pas	Fri Sep 16 00:01:43 2016 +0200
@@ -57,6 +57,7 @@
 
 function WorldWrap(var Gear: PGear): boolean;
 
+function IsHogLocal(HH: PHedgehog): boolean;
 
 
 function MakeHedgehogsStep(Gear: PGear) : boolean;
@@ -1589,4 +1590,9 @@
     PlaySound(sndMelonImpact, true)
 end;
 
+function IsHogLocal(HH: PHedgehog): boolean;
+begin
+    IsHogLocal:= (not (HH^.Team^.ExtDriven or (HH^.BotLevel > 0))) or (HH^.Team^.Clan^.ClanIndex = LocalClan);
+end;
+
 end.
--- a/hedgewars/uScript.pas	Thu Sep 15 23:16:49 2016 +0200
+++ b/hedgewars/uScript.pas	Fri Sep 16 00:01:43 2016 +0200
@@ -1307,6 +1307,7 @@
     if CheckLuaParamCount(L, 1, 'GetHogFlag', '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^.Flag))
         else
@@ -1317,12 +1318,30 @@
     lc_gethogflag:= 1
 end;
 
+function lc_ishoglocal(L : Plua_State) : LongInt; Cdecl;
+var gear : PGear;
+begin
+    if CheckLuaParamCount(L, 1, 'IsHogLocal', '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_pushboolean(L, IsHogLocal(gear^.Hedgehog))
+        else
+            lua_pushnil(L);
+        end
+    else
+        lua_pushnil(L); // return value on stack (nil)
+    lc_ishoglocal:= 1
+end;
+
 function lc_gethogteamname(L : Plua_State) : LongInt; Cdecl;
 var gear : PGear;
 begin
     if CheckLuaParamCount(L, 1, 'GetHogTeamName', 'gearUid') then
         begin
         gear:= GearByUID(lua_tointeger(L, 1));
+        // TODO error messages
         if (gear <> nil) and ((gear^.Kind = gtHedgehog) or (gear^.Kind = gtGrave)) and (gear^.Hedgehog <> nil) then
             lua_pushstring(L, str2pchar(gear^.Hedgehog^.Team^.TeamName))
         else
@@ -3325,6 +3344,7 @@
 lua_register(luaState, _P'GetHogVoicepack', @lc_gethogvoicepack);
 lua_register(luaState, _P'GetHogFlag', @lc_gethogflag);
 lua_register(luaState, _P'GetHogGrave', @lc_gethoggrave);
+lua_register(luaState, _P'IsHogLocal', @lc_ishoglocal);
 lua_register(luaState, _P'GetHogTeamName', @lc_gethogteamname);
 lua_register(luaState, _P'SetHogTeamName', @lc_sethogteamname);
 lua_register(luaState, _P'GetHogName', @lc_gethogname);