diff --git a/LuaRules/Gadgets/Include/startbox_utilities.lua b/LuaRules/Gadgets/Include/startbox_utilities.lua index 785a6bd68f..63cbaf84e0 100644 --- a/LuaRules/Gadgets/Include/startbox_utilities.lua +++ b/LuaRules/Gadgets/Include/startbox_utilities.lua @@ -81,7 +81,7 @@ local function ParseBoxes () if not startboxStringLoadedBoxes then if Game.mapSizeZ > Game.mapSizeX then - startBoxConfig[0] = { + startBoxConfig[1] = { boxes = {{ {0, 0}, {0, Game.mapSizeZ * 0.2}, @@ -94,7 +94,7 @@ local function ParseBoxes () nameLong = "North", nameShort = "N" } - startBoxConfig[1] = { + startBoxConfig[2] = { boxes = {{ {0, Game.mapSizeZ * 0.8}, {0, Game.mapSizeZ}, @@ -108,7 +108,7 @@ local function ParseBoxes () nameShort = "S" } else - startBoxConfig[0] = { + startBoxConfig[1] = { boxes = {{ {0, 0}, {0, Game.mapSizeZ}, @@ -121,7 +121,7 @@ local function ParseBoxes () nameLong = "West", nameShort = "W" } - startBoxConfig[1] = { + startBoxConfig[2] = { boxes = {{ {Game.mapSizeX * 0.8, 0}, {Game.mapSizeX * 0.8, Game.mapSizeZ}, @@ -155,20 +155,13 @@ local function ParseBoxes () end end - --[[ If the boxes start from 1, shift down (allyteams start from 0). - At some point the internals could be rewritten so that configs - starting from 0 would be shifted up instead (since this is how - Lua generally works) but from the PoV of somebody writing map - configs this is transparent so it's just a code neatness thing - that can wait until later. Note that this deprecates 0-indexing, - even though that is how ~all gameside configs still look (that - would be another mechanical task to perform at some point). ]] - if startBoxConfig[1] and not startBoxConfig[0] then - Spring.Echo("1-indexed startbox detected, shifting") + -- If the boxes start from 0, shift up (Allyteams start from 1) + if startBoxConfig[0] and not startBoxConfig[1] then + Spring.Echo("0-indexed startbox detected, shifting") local ret = {} for boxID, box in pairs(startBoxConfig) do - ret[boxID - 1] = box + ret[boxID + 1] = box end startBoxConfig = ret end diff --git a/LuaRules/Gadgets/start_boxes.lua b/LuaRules/Gadgets/start_boxes.lua index ceb7f540e2..daec7de9f2 100644 --- a/LuaRules/Gadgets/start_boxes.lua +++ b/LuaRules/Gadgets/start_boxes.lua @@ -58,7 +58,7 @@ local function GetBoxID(allyTeamID) if not teamID then return end - local boxID = Spring.GetTeamRulesParam(teamID, "start_box_id") + local boxID = Spring.GetTeamRulesParam(teamID, "start_box_id") + 1 -- default to 1-indexed return boxID end @@ -337,6 +337,7 @@ local function GetTeamNames (allyTeamID) then local boxID = Spring.GetTeamRulesParam(teamList[1], "start_box_id") if boxID then + boxID = boxID + 1 -- default to 1-indexed local box = startboxConfig[boxID] if box.nameLong and box.nameShort then return box.nameLong, box.nameShort, clanLongName, clanShortName @@ -417,7 +418,7 @@ function gadget:Initialize() for i = 1, #allyTeamList do local allyTeamID = allyTeamList[i] - local boxID = allyTeamList[i] + local boxID = allyTeamList[i] + 1 -- default to 1-indexed if startboxConfig[boxID] then local teamList = Spring.GetTeamList(allyTeamID) or {} for j = 1, #teamList do @@ -520,6 +521,9 @@ function gadget:AllowStartPosition(playerID, teamID, readyState, x, y, z, rx, ry end local boxID = Spring.GetTeamRulesParam(teamID, "start_box_id") + if boxID then + boxID = boxID + 1 -- default to 1-indexed + end if (not boxID) or CheckStartbox(boxID, x, z) then Spring.SetTeamRulesParam (teamID, "valid_startpos", 1) @@ -539,6 +543,9 @@ function gadget:RecvSkirmishAIMessage(teamID, dataStr) end local boxID = Spring.GetTeamRulesParam(teamID, "start_box_id") + if boxID then + boxID = boxID + 1 -- default to 1-indexed + end local xz = dataStr:sub(command:len()+1) local slash = xz:find("/",1,true) @@ -573,8 +580,9 @@ function gadget:RecvSkirmishAIMessage(teamID, dataStr) local enemyteams = Spring.GetTeamList(value) local _,value1 = next(enemyteams) if value1 then - local enemybox = Spring.GetTeamRulesParam(value1, "start_box_id") + local enemybox = Spring.GetTeamRulesParam(value1, "start_box_id") if (enemybox) then + enemybox = enemybox + 1 -- default to 1-indexed enemyboxes[enemybox] = true end end