Skip to content

Commit

Permalink
Fix for build-now walls flashing red (DFHack#394)
Browse files Browse the repository at this point in the history
* Partial fix for build-now walls flashing red

DFHack/dfhack#2174

* Revert to actually correct no_build_item behaviour & fix bug

* Update build-now.lua

* Implement reuse_construction

except I'm still missing stuff, it's still a floor when you build a wall

* All good except for get_original_tile(type)

* Update build-now.lua

Co-authored-by: Myk <[email protected]>

* Update build-now.lua

Co-authored-by: Myk <[email protected]>

* Update build-now.lua

Co-authored-by: Myk <[email protected]>
  • Loading branch information
Tachytaenius and myk002 authored Jun 4, 2022
1 parent 1ff42c6 commit a1f31a8
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions build-now.lua
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,20 @@ local function pos_cmp(a, b)
return utils.compare(a.z, b.z)
end

local function get_original_tiletype(pos)
-- TODO
return dfhack.maps.getTileType(pos)
end

local function reuse_construction(construction, item)
construction.item_type = item:getType()
construction.item_subtype = item:getSubtype()
construction.mat_type = item:getMaterial()
construction.mat_index = item:getMaterialIndex()
construction.flags.top_of_wall = false
construction.flags.no_build_item = true
end

local function create_and_link_construction(pos, item, top_of_wall)
local construction = df.construction:new()
utils.assign(construction.pos, pos)
Expand All @@ -368,7 +382,7 @@ local function create_and_link_construction(pos, item, top_of_wall)
construction.mat_index = item:getMaterialIndex()
construction.flags.top_of_wall = top_of_wall
construction.flags.no_build_item = not top_of_wall
construction.original_tile = dfhack.maps.getTileType(pos)
construction.original_tile = get_original_tiletype(pos)
utils.insert_sorted(df.global.world.constructions, construction,
'pos', pos_cmp)
end
Expand Down Expand Up @@ -435,9 +449,21 @@ local function build_construction(bld)
local construction_type = bld.type
dfhack.buildings.deconstruct(bld)

-- add entries to df.global.world.constructions and adjust tiletypes for
-- the construction itself
create_and_link_construction(pos, item, false)
-- check if we're building on a construction (i.e. building a construction on top of a wall)
local tiletype = dfhack.maps.getTileType(pos)
local tileattrs = df.tiletype.attrs[tiletype]
if tileattrs.material == df.tiletype_material.CONSTRUCTION then
-- modify the construction to the new type
local construction, found = utils.binsearch(df.global.world.constructions, pos, 'pos', pos_cmp)
if not found then
error('Could not find construction entry for construction tile at ' .. pos.x .. ', ' .. pos.y .. ', ' .. pos.z)
end
reuse_construction(construction, item)
else
-- add entry to df.global.world.constructions
create_and_link_construction(pos, item, false)
end
-- adjust tiletypes for the construction itself
set_tiletype(pos, const_to_tile[construction_type])
if construction_type == df.construction_type.Wall then
dig_now.link_adjacent_smooth_walls(pos)
Expand Down

0 comments on commit a1f31a8

Please sign in to comment.