Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function GuessOne(teamID, allyID, xmin, zmin, xmax, zmax, startPointTable)
-- guess based on metal spots within startbox --

-- check if mex list generation worked and retrieve if so
local metalSpots = GG["resource_spot_finder"] and GG["resource_spot_finder"].metalSpotsList or nil
local resourceSpotFinder = (GG and GG["resource_spot_finder"]) or (WG and WG["resource_spot_finder"])
local metalSpots = resourceSpotFinder and resourceSpotFinder.metalSpotsList or nil
if not metalSpots or #metalSpots == 0 then
return -1,-1
end
Expand Down
1 change: 1 addition & 0 deletions language/en/interface.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"gpuMemory": "GPU Memory: %{gpuUsage}%%",
"pointClickTooltip": "Click to go to the last point set by the player",
"aiName": "%{name} (AI)",
"aiPlaceMe": "Place me!",
"desynced": "desynced",
"chat": {
"needSupport": "I need unit support!",
Expand Down
1 change: 1 addition & 0 deletions language/test_unicode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ return {
gpuMemory = "GPU Memory: %{gpuUsage}%%",
pointClickTooltip = "Click to go to the last point set by the player",
aiName = "%{name} (AI)",
aiPlaceMe = "Place me!",
chat = {
needSupport = "I need unit support!",
needEnergy = "I need energy!",
Expand Down
63 changes: 51 additions & 12 deletions luarules/gadgets/game_initial_spawn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ if gadgetHandler:IsSyncedCode() then
----------------------------------------------------------------
-- Start Point Guesser
----------------------------------------------------------------
include("luarules/gadgets/lib_startpoint_guesser.lua") -- start point guessing routines
VFS.Include("common/lib_startpoint_guesser.lua")

----------------------------------------------------------------
-- FFA start points (provided by `game_ffa_start_setup`)
Expand Down Expand Up @@ -311,6 +311,32 @@ if gadgetHandler:IsSyncedCode() then
if not playerIsSpec and (draftMode ~= nil and draftMode ~= "disabled") then
DraftRecvLuaMsg(msg, playerID, playerIsSpec, playerTeam, allyTeamID)
end

if string.sub(msg, 1, 17) == "aiPlacedPosition:" then
local data = string.sub(msg, 18)
local teamID, x, z = string.match(data, "(%d+):([%d%.]+):([%d%.]+)")
if teamID and x and z then
teamID = tonumber(teamID)
x = tonumber(x)
z = tonumber(z)

local _, _, _, _, _, aiAllyTeamID = Spring.GetTeamInfo(teamID, false)
local _, _, senderIsSpec, senderTeam, senderAllyTeamID = spGetPlayerInfo(playerID, false)

if senderIsSpec or (aiAllyTeamID ~= senderAllyTeamID and not Spring.IsCheatingEnabled()) then
return false
end

if x == 0 and z == 0 then
spSetTeamRulesParam(teamID, "aiPlacedX", nil, { public = true })
spSetTeamRulesParam(teamID, "aiPlacedZ", nil, { public = true })
else
spSetTeamRulesParam(teamID, "aiPlacedX", x, { public = true })
spSetTeamRulesParam(teamID, "aiPlacedZ", z, { public = true })
end
return true
end
end
end

----------------------------------------------------------------
Expand Down Expand Up @@ -544,17 +570,21 @@ if gadgetHandler:IsSyncedCode() then
local function spawnRegularly(teamID, allyTeamID)
local x, _, z = Spring.GetTeamStartPosition(teamID)
local xmin, zmin, xmax, zmax = spGetAllyTeamStartBox(allyTeamID)

-- if its choose-in-game mode, see if we need to autoplace anyone
if Game.startPosType == 2 then
if not startPointTable[teamID] or startPointTable[teamID][1] < 0 then
-- guess points for the ones classified in startPointTable as not genuine
x, z = GuessStartSpot(teamID, allyTeamID, xmin, zmin, xmax, zmax, startPointTable)
else
-- fallback
if x <= 0 or z <= 0 then
x = (xmin + xmax) / 2
z = (zmin + zmax) / 2

local aiPlacedX = spGetTeamRulesParam(teamID, "aiPlacedX")
local aiPlacedZ = spGetTeamRulesParam(teamID, "aiPlacedZ")
if aiPlacedX and aiPlacedZ then
x = aiPlacedX
z = aiPlacedZ
else
if Game.startPosType == 2 then
if not startPointTable[teamID] or startPointTable[teamID][1] < 0 then
x, z = GuessStartSpot(teamID, allyTeamID, xmin, zmin, xmax, zmax, startPointTable)
else
if x <= 0 or z <= 0 then
x = (xmin + xmax) / 2
z = (zmin + zmax) / 2
end
end
end
end
Expand All @@ -566,6 +596,15 @@ if gadgetHandler:IsSyncedCode() then
-- Spawning
----------------------------------------------------------------
function gadget:GameStart()
-- Add manually placed AI positions to startPointTable for spacing calculations
for teamID, allyTeamID in pairs(teams) do
local aiPlacedX = spGetTeamRulesParam(teamID, "aiPlacedX")
local aiPlacedZ = spGetTeamRulesParam(teamID, "aiPlacedZ")
if aiPlacedX and aiPlacedZ then
startPointTable[teamID] = {aiPlacedX, aiPlacedZ}
end
end

-- if this a FFA match with automatic spawning (i.e. no start boxes) and a list of start points was provided by
-- `game_ffa_start_setup` for the ally teams in this match
if isFFA and Game.startPosType == 1 and GG.ffaStartPoints then
Expand Down
Loading
Loading