Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c8517eb

Browse files
committed
optionally don't place constructions on constructed floors/ramps
1 parent 005a4b6 commit c8517eb

4 files changed

Lines changed: 48 additions & 10 deletions

File tree

plugins/buildingplan/buildingplan.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ DFhackCExport command_result plugin_shutdown (color_ostream &out) {
248248
return CR_OK;
249249
}
250250

251-
static void validate_config(color_ostream &out, bool verbose = false) {
251+
static void validate_materials_config(color_ostream &out, bool verbose = false) {
252252
if (config.get_bool(CONFIG_BLOCKS)
253253
|| config.get_bool(CONFIG_BOULDERS)
254254
|| config.get_bool(CONFIG_LOGS)
@@ -307,7 +307,9 @@ DFhackCExport command_result plugin_load_site_data (color_ostream &out) {
307307
DEBUG(control,out).print("no config found in this save; initializing\n");
308308
config = World::AddPersistentSiteData(CONFIG_KEY);
309309
}
310-
validate_config(out);
310+
if (config.get_int(CONFIG_RECONSTRUCT) == -1)
311+
config.set_bool(CONFIG_RECONSTRUCT, true);
312+
validate_materials_config(out);
311313

312314
DEBUG(control,out).print("loading persisted state\n");
313315

@@ -548,6 +550,8 @@ static void printStatus(color_ostream &out) {
548550
out.print(" use boulders: %s\n", config.get_bool(CONFIG_BOULDERS) ? "yes" : "no");
549551
out.print(" use logs: %s\n", config.get_bool(CONFIG_LOGS) ? "yes" : "no");
550552
out.print(" use bars: %s\n", config.get_bool(CONFIG_BARS) ? "yes" : "no");
553+
out.print(" plan constructions on tiles with existing constructed floors/ramps when using box select: %s\n",
554+
config.get_bool(CONFIG_RECONSTRUCT) ? "yes" : "no");
551555
out.print("\n");
552556

553557
size_t bld_count = 0;
@@ -598,12 +602,14 @@ static bool setSetting(color_ostream &out, string name, bool value) {
598602
config.set_bool(CONFIG_LOGS, value);
599603
else if (name == "bars")
600604
config.set_bool(CONFIG_BARS, value);
605+
else if (name == "reconstruct")
606+
config.set_bool(CONFIG_RECONSTRUCT, value);
601607
else {
602608
out.printerr("unrecognized setting: '%s'\n", name.c_str());
603609
return false;
604610
}
605611

606-
validate_config(out, true);
612+
validate_materials_config(out, true);
607613
call_buildingplan_lua(&out, "signal_reset");
608614
return true;
609615
}
@@ -747,6 +753,7 @@ static int getGlobalSettings(lua_State *L) {
747753
settings.emplace("logs", config.get_bool(CONFIG_LOGS));
748754
settings.emplace("boulders", config.get_bool(CONFIG_BOULDERS));
749755
settings.emplace("bars", config.get_bool(CONFIG_BARS));
756+
settings.emplace("reconstruct", config.get_bool(CONFIG_RECONSTRUCT));
750757
Lua::Push(L, settings);
751758
return 1;
752759
}

plugins/buildingplan/buildingplan.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ enum ConfigValues {
2222
CONFIG_BOULDERS = 2,
2323
CONFIG_LOGS = 3,
2424
CONFIG_BARS = 4,
25+
CONFIG_RECONSTRUCT = 5,
2526
};
2627

2728
enum FilterConfigValues {

plugins/lua/buildingplan/filterselection.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,23 @@ function GlobalSettingsPage:init()
495495
label_width=8,
496496
on_change=self:callback('update_setting', 'bars'),
497497
},
498+
widgets.Panel{
499+
frame={h=1},
500+
},
501+
widgets.ToggleHotkeyLabel{
502+
view_id='reconstruct',
503+
frame={l=0},
504+
key='CUSTOM_M',
505+
label='Multi-rebuild',
506+
on_change=self:callback('update_setting', 'reconstruct'),
507+
},
508+
widgets.Label{
509+
text={
510+
' Plan constructions on tiles with existing', NEWLINE,
511+
' constructed floors/ramps when using box select.'
512+
},
513+
text_pen=COLOR_GRAY,
514+
},
498515
}
499516

500517
self:init_settings()
@@ -507,6 +524,7 @@ function GlobalSettingsPage:init_settings()
507524
subviews.logs:setOption(settings.logs)
508525
subviews.boulders:setOption(settings.boulders)
509526
subviews.bars:setOption(settings.bars)
527+
subviews.reconstruct:setOption(settings.reconstruct)
510528
end
511529

512530
function GlobalSettingsPage:update_setting(setting, val)

plugins/lua/buildingplan/planneroverlay.lua

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ end
112112
-- adjusted from CycleHotkeyLabel on the planner panel
113113
local weapon_quantity = 1
114114

115-
-- TODO: this should account for erroring constructions
115+
-- ** TODO: this should account for erroring constructions
116116
local function get_quantity(filter, hollow, bounds)
117117
if is_pressure_plate() then
118118
local flags = uibs.plate_info.flags
@@ -873,14 +873,24 @@ function PlannerOverlay:render(dc)
873873
PlannerOverlay.super.render(self, dc)
874874
end
875875

876+
local function tile_is_construction(pos)
877+
local tt = dfhack.maps.getTileType(pos)
878+
if not tt then return false end
879+
return df.tiletype.attrs[tt].material == df.tiletype_material.CONSTRUCTION
880+
end
881+
876882
local ONE_BY_ONE = xy2pos(1, 1)
877883

884+
local function can_place_construction(can_reconstruct, pos)
885+
return dfhack.buildings.checkFreeTiles(pos, ONE_BY_ONE) and (can_reconstruct or not tile_is_construction(pos))
886+
end
887+
878888
function PlannerOverlay:onRenderFrame(dc, rect)
879889
PlannerOverlay.super.onRenderFrame(self, dc, rect)
880890

891+
local buildingplan = require('plugins.buildingplan')
881892
if reset_counts_flag then
882893
self:reset()
883-
local buildingplan = require('plugins.buildingplan')
884894
self.subviews.engraved:setOption(buildingplan.getSpecials(
885895
uibs.building_type, uibs.building_subtype, uibs.custom_type).engraved or false)
886896
self.subviews.empty:setOption(buildingplan.getSpecials(
@@ -898,12 +908,14 @@ function PlannerOverlay:onRenderFrame(dc, rect)
898908

899909
local hollow = self.subviews.hollow:getOptionValue()
900910
local default_pen = (self.saved_selection_pos or #uibs.errors == 0) and pens.GOOD_TILE_PEN or pens.BAD_TILE_PEN
911+
local can_reconstruct = buildingplan.getGlobalSettings().reconstruct
901912

902-
local get_pen_fn = is_construction() and function(pos)
903-
return dfhack.buildings.checkFreeTiles(pos, ONE_BY_ONE) and pens.GOOD_TILE_PEN or pens.BAD_TILE_PEN
904-
end or function()
905-
return default_pen
906-
end
913+
local get_pen_fn = is_construction() and
914+
function(pos)
915+
return can_place_construction(can_reconstruct, pos) and pens.GOOD_TILE_PEN or pens.BAD_TILE_PEN
916+
end or function()
917+
return default_pen
918+
end
907919

908920
local function get_overlay_pen(pos)
909921
if not hollow then return get_pen_fn(pos) end

0 commit comments

Comments
 (0)