# HG changeset patch # User Wuzzy # Date 1542583161 -3600 # Node ID 8edbdd3a1fe74195c034a57698aad6a540caa3a0 # Parent e590fb0f2567f0b64c1d5cbe5ef4899b155730b7 Get rid of table.maxn in all Lua code diff -r e590fb0f2567 -r 8edbdd3a1fe7 share/hedgewars/Data/Scripts/Multiplayer/Continental_supplies.lua --- a/share/hedgewars/Data/Scripts/Multiplayer/Continental_supplies.lua Sun Nov 18 21:01:16 2018 +0100 +++ b/share/hedgewars/Data/Scripts/Multiplayer/Continental_supplies.lua Mon Nov 19 00:19:21 2018 +0100 @@ -452,16 +452,16 @@ end function SpawnRandomCrate(x,y,strength) - local tot=table.maxn(CS.WEAPONS_SUPPORT)+table.maxn(CS.WEAPONS_DAMAGE) + local tot=#CS.WEAPONS_SUPPORT + #CS.WEAPONS_DAMAGE local rand=GetRandom(tot)+1 - if(rand>table.maxn(CS.WEAPONS_SUPPORT)) + if(rand > #CS.WEAPONS_SUPPORT) then - local weapon=rand-table.maxn(CS.WEAPONS_SUPPORT) + local weapon = rand - #CS.WEAPONS_SUPPORT while(wepNotValidBorder(CS.WEAPONS_DAMAGE[weapon][1])==false) do - if(weapon>=table.maxn(CS.WEAPONS_DAMAGE)) + if(weapon >= #CS.WEAPONS_DAMAGE) then weapon=0 end @@ -582,7 +582,7 @@ if(rand_weaponset_power < power) then - local numberofweapons=table.maxn(weptype) + local numberofweapons = #weptype local random_weapon = math.abs(GetRandom(numberofweapons)+1) @@ -909,8 +909,8 @@ continentinfo[4]={} if(icon==1000) then - local mid=table.maxn(CS.WEAPONS_DAMAGE) - local max=mid+table.maxn(CS.WEAPONS_SUPPORT) + local mid = #CS.WEAPONS_DAMAGE + local max = mid + #CS.WEAPONS_SUPPORT local ic=(string.byte(string) % max)+1 if(ic>mid) @@ -1233,7 +1233,7 @@ if(CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)]==0) then - CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)]=GetRandom(table.maxn(CS.CONTINENT_INFORMATION))+1 + CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)]=GetRandom(#CS.CONTINENT_INFORMATION)+1 SetContinentWeapons() end local currCont=CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)] @@ -1589,13 +1589,13 @@ then CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)]=CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)] + direction - if(CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)]> table.maxn(CS.CONTINENT_INFORMATION)) + if(CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)]> #CS.CONTINENT_INFORMATION) then CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)]=1 end if(CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)]<=0) then - CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)]=table.maxn(CS.CONTINENT_INFORMATION) + CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)] = #CS.CONTINENT_INFORMATION end SetContinentWeapons() @@ -1687,7 +1687,7 @@ PlaySound(sndPlaced) if(CurrentHedgehog and CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)]==0) then - CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)]=GetRandom(table.maxn(CS.CONTINENT_INFORMATION))+1 + CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)]=GetRandom(#CS.CONTINENT_INFORMATION)+1 SetContinentWeapons() HideMission() ShowContinentLabel(0) @@ -1708,7 +1708,7 @@ then if(GetCurAmmoType()==amSwitch) then - CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)]=GetRandom(table.maxn(CS.CONTINENT_INFORMATION))+1 + CS.TEAM_CONTINENT[GetHogTeamName(CurrentHedgehog)]=GetRandom(#CS.CONTINENT_INFORMATION)+1 SetContinentWeapons() SetWeapon(amSkip) PlaySound(sndMineTick) diff -r e590fb0f2567 -r 8edbdd3a1fe7 share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua --- a/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua Sun Nov 18 21:01:16 2018 +0100 +++ b/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua Mon Nov 19 00:19:21 2018 +0100 @@ -30,7 +30,7 @@ local ammo = getTeamValue(name, "ammo") -- If there is no ammo, get a random one from the list and store it if ammo == nil then - ammo = weapons[GetRandom(table.maxn(weapons)) + 1] + ammo = weapons[GetRandom(#weapons) + 1] setTeamValue(name, "ammo", ammo) end -- Add the ammo for the hog diff -r e590fb0f2567 -r 8edbdd3a1fe7 share/hedgewars/Data/Scripts/Tracker.lua --- a/share/hedgewars/Data/Scripts/Tracker.lua Sun Nov 18 21:01:16 2018 +0100 +++ b/share/hedgewars/Data/Scripts/Tracker.lua Mon Nov 19 00:19:21 2018 +0100 @@ -34,7 +34,7 @@ if trackingTeams and GetGearType(gear) == gtHedgehog then hogs = teams[GetHogTeamName(gear)] if hogs ~= nil then - if table.maxn(hogs) == 1 then + if #hogs == 1 then hogs = nil else for k, hog in ipairs(hogs) do @@ -89,7 +89,7 @@ hogs = teams[GetHogTeamName(gear)] if hogs ~= nil then - if table.maxn(hogs) == 1 then + if #hogs == 1 then hogs = nil else for k, hog in ipairs(hogs) do @@ -286,7 +286,7 @@ -- Run a function on hogs in a clan function runOnHogsInClan(func, clan) - for i = 1, table.maxn(clans) do + for i = 1, ClansCount do if clans[i] == clan then for k, hog in ipairs(teams[i]) do func(hog) @@ -297,7 +297,7 @@ -- Run a function on hogs in other clans function runOnHogsInOtherClans(func, clan) - for i = 1, table.maxn(clans) do + for i = 1, ClansCount do if clans[i] ~= clan then for k, hog in ipairs(teams[i]) do func(hog)