Skip to content
Draft
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: 18 additions & 5 deletions luaui/Widgets/gui_pregame_build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ local BUILD_SQUARE_SIZE = SQUARE_SIZE * 2
local BUILDING_COUNT_FUDGE_FACTOR = 1.4
local BUILDING_DETECTION_TOLERANCE = 10
local HALF = 0.5
local MAX_DRAG_BUILD_COUNT = 200

local function buildFacingHandler(command, line, args)
if not (preGamestartPlayer and selBuildQueueDefID) then
Expand Down Expand Up @@ -336,6 +337,17 @@ local function fillRow(startX, startZ, stepX, stepZ, count, facing)
return result
end

local function truncateBuildPositions(result)
if #result > MAX_DRAG_BUILD_COUNT then
local truncated = {}
for i = 1, MAX_DRAG_BUILD_COUNT do
truncated[i] = result[i]
end
return truncated
end
return result
end

local function calculateBuildingPlacementSteps(unitDefID, startPos, endPos, spacing, facing)
local buildingWidth, buildingHeight = GetBuildingDimensions(unitDefID, facing)
local delta = { x = endPos.x - startPos.x, z = endPos.z - startPos.z }
Expand Down Expand Up @@ -380,7 +392,8 @@ local function getBuildPositionsLine(unitDefID, facing, startPos, endPos, spacin
xStep = zStep * delta.x / (delta.z ~= 0 and delta.z or 1)
end

return fillRow(snappedStart.x, snappedStart.z, xStep, zStep, xGreaterThanZ and xCount or zCount, facing)
local result = fillRow(snappedStart.x, snappedStart.z, xStep, zStep, xGreaterThanZ and xCount or zCount, facing)
return truncateBuildPositions(result)
end

local function getBuildPositionsGrid(unitDefID, facing, startPos, endPos, spacing)
Expand All @@ -403,8 +416,8 @@ local function getBuildPositionsGrid(unitDefID, facing, startPos, endPos, spacin
end
currentRowZ = currentRowZ + zStep
end
return result

return truncateBuildPositions(result)
end

local function getBuildPositionsBox(unitDefID, facing, startPos, endPos, spacing)
Expand Down Expand Up @@ -433,8 +446,8 @@ local function getBuildPositionsBox(unitDefID, facing, startPos, endPos, spacing
elseif zCount == 1 then
table.append(result, fillRow(snappedStart.x, snappedStart.z, xStep, 0, xCount, facing))
end
return result

return truncateBuildPositions(result)
end

local function getBuildPositionsAround(unitDefID, facing, target)
Expand Down
Loading