Skip to content

Commit

Permalink
Fix template creation with 1x1 (walls) or 3x3 (smd) structures in it (F…
Browse files Browse the repository at this point in the history
…AForever#4716)

Old templates will still have the problem as described. New templates properly work with structures with a footprint of 1x1 (walls) and 3x3 (strategic missile defenses)
  • Loading branch information
The-Balthazar authored Feb 20, 2023
1 parent 4600290 commit 0937374
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lua/ui/game/build_templates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,25 @@ local Prefs = import("/lua/user/prefs.lua")
local templates = Prefs.GetFromCurrentProfile('build_templates') or {}
local UIUtil = import("/lua/ui/uiutil.lua")

local function TemplateAxisOffset(unitbp, axe)
return (math.mod(math.ceil(unitbp.Footprint and unitbp.Footprint[axe] or unitbp[axe] or 1), 2) == 1 and 0 or 0.5)
end

function CreateBuildTemplate()
GenerateBuildTemplateFromSelection()
local template = GetActiveBuildTemplate()
ClearBuildTemplates()
if not table.empty(template) then
if next(template) then
local str1bp = __blueprints[ template[3][1] ]
local s1Xoffset = TemplateAxisOffset(str1bp, 'SizeX')
local s1Yoffset = TemplateAxisOffset(str1bp, 'SizeZ')
if s1Xoffset ~= 0 or s1Yoffset ~= 0 then
for i=3, table.getn(template) do
local str = template[i]
str[3] = str[3] + s1Xoffset
str[4] = str[4] + s1Yoffset
end
end
AddTemplate(template)
end
end
Expand Down

0 comments on commit 0937374

Please sign in to comment.