Lua API: Add functons: GetTeamIndex and GetTeamClan
authorWuzzy <Wuzzy2@mail.ru>
Fri, 16 Feb 2018 19:49:46 +0100
changeset 13020 d1e7f2420f00
parent 13019 880662cf41ee
child 13021 af35e22fb533
Lua API: Add functons: GetTeamIndex and GetTeamClan
ChangeLog.txt
hedgewars/uScript.pas
--- a/ChangeLog.txt	Fri Feb 16 19:16:35 2018 +0100
+++ b/ChangeLog.txt	Fri Feb 16 19:49:46 2018 +0100
@@ -62,6 +62,8 @@
  + New call: SetLaserSight(bool): Toggle laser sight
  + New call: GetWind(): Returns current wind (approximation) from -100 to 100
  + New call: GetTeamName(teamIdx): Returns name of team with given index (starts at 0)
+ + New call: GetTeamIndex(teamname): Returns index of team with given name
+ + New call: GetTeamClan(teamname): Returns clan of team with given name
  + New call: SpawnSupplyCrate(x, y, content, [, amount]): Spawn ammo or utility crate, depending on content
  + New call: HealHog(gearUid, healthBoost[, showMessage[, tint]]): Heal hedgehog with graphical effects and message
  + New call: SetTeamLabel(teamname[, label]): Set an arbitrary label for a team, will be displayed next to the team bar
--- a/hedgewars/uScript.pas	Fri Feb 16 19:16:35 2018 +0100
+++ b/hedgewars/uScript.pas	Fri Feb 16 19:49:46 2018 +0100
@@ -2166,6 +2166,48 @@
     lc_getteamname:= 1;
 end;
 
+function lc_getteamindex(L : Plua_state) : LongInt; Cdecl;
+var i: LongInt;
+    found: boolean;
+begin
+    found:= false;
+    if CheckLuaParamCount(L, 1, 'GetTeamIndex', 'teamname') then
+        if TeamsCount > 0 then
+            for i:= 0 to Pred(TeamsCount) do
+                begin
+                // skip teams that don't have matching name
+                if TeamsArray[i]^.TeamName <> lua_tostring(L, 1) then
+                    continue;
+                lua_pushnumber(L, i);
+                found:= true;
+                break;
+                end;
+    if (not found) then
+        lua_pushnil(L);
+    lc_getteamindex:= 1;
+end;
+
+function lc_getteamclan(L : Plua_state) : LongInt; Cdecl;
+var i: LongInt;
+    found: boolean;
+begin
+    found:= false;
+    if CheckLuaParamCount(L, 1, 'GetTeamClan', 'teamname') then
+        if TeamsCount > 0 then
+            for i:= 0 to Pred(TeamsCount) do
+                begin
+                // skip teams that don't have matching name
+                if TeamsArray[i]^.TeamName <> lua_tostring(L, 1) then
+                    continue;
+                lua_pushnumber(L, TeamsArray[i]^.Clan^.ClanIndex);
+                found:= true;
+                break;
+                end;
+    if (not found) then
+        lua_pushnil(L);
+    lc_getteamclan:= 1;
+end;
+
 function lc_dismissteam(L : Plua_State) : LongInt; Cdecl;
 var HHGear: PGear;
     i, h  : LongInt;
@@ -3753,6 +3795,8 @@
 lua_register(luaState, _P'SetAmmoDelay', @lc_setammodelay);
 lua_register(luaState, _P'PlaySound', @lc_playsound);
 lua_register(luaState, _P'GetTeamName', @lc_getteamname);
+lua_register(luaState, _P'GetTeamIndex', @lc_getteamindex);
+lua_register(luaState, _P'GetTeamClan', @lc_getteamclan);
 lua_register(luaState, _P'AddTeam', @lc_addteam);
 lua_register(luaState, _P'SetTeamLabel', @lc_setteamlabel);
 lua_register(luaState, _P'AddHog', @lc_addhog);