Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions LuaRules/Gadgets/Include/startbox_utilities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -94,7 +94,7 @@ local function ParseBoxes ()
nameLong = "North",
nameShort = "N"
}
startBoxConfig[1] = {
startBoxConfig[2] = {
boxes = {{
{0, Game.mapSizeZ * 0.8},
{0, Game.mapSizeZ},
Expand All @@ -108,7 +108,7 @@ local function ParseBoxes ()
nameShort = "S"
}
else
startBoxConfig[0] = {
startBoxConfig[1] = {
boxes = {{
{0, 0},
{0, Game.mapSizeZ},
Expand All @@ -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},
Expand Down Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions LuaRules/Gadgets/start_boxes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down