Merge pull request #3001 from myk002/myk_buildingplan_pressure_plates

[buildingplan] fix handling of pressure plates
develop
Myk 2023-03-10 00:17:57 -08:00 committed by GitHub
commit a37d2c09bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 3 deletions

@ -32,7 +32,17 @@ local function get_cur_area_dims(placement_data)
math.abs(selection_pos.z - pos.z) + 1 math.abs(selection_pos.z - pos.z) + 1
end end
local function is_pressure_plate()
return uibs.building_type == df.building_type.Trap
and uibs.building_subtype == df.trap_type.PressurePlate
end
local function get_quantity(filter, hollow, placement_data) local function get_quantity(filter, hollow, placement_data)
if is_pressure_plate() then
local flags = uibs.plate_info.flags
return (flags.units and 1 or 0) + (flags.water and 1 or 0) +
(flags.magma and 1 or 0) + (flags.track and 1 or 0)
end
local quantity = filter.quantity or 1 local quantity = filter.quantity or 1
local dimx, dimy, dimz = get_cur_area_dims(placement_data) local dimx, dimy, dimz = get_cur_area_dims(placement_data)
if quantity < 1 then if quantity < 1 then
@ -87,8 +97,7 @@ end
local pressure_plate_panel_frame = {t=4, h=37, w=46, r=28} local pressure_plate_panel_frame = {t=4, h=37, w=46, r=28}
local function has_pressure_plate_panel() local function has_pressure_plate_panel()
return uibs.building_type == df.building_type.Trap return is_pressure_plate()
and uibs.building_subtype == df.trap_type.PressurePlate
end end
local function is_over_options_panel() local function is_over_options_panel()
@ -667,6 +676,10 @@ function PlannerOverlay:place_building(placement_data, chosen_items)
local blds = {} local blds = {}
local hollow = self.subviews.hollow:getOptionValue() local hollow = self.subviews.hollow:getOptionValue()
local subtype = uibs.building_subtype local subtype = uibs.building_subtype
local filters = get_cur_filters()
if is_pressure_plate() then
filters[1].quantity = get_quantity()
end
for z=p1.z,p2.z do for y=p1.y,p2.y do for x=p1.x,p2.x do for z=p1.z,p2.z do for y=p1.y,p2.y do for x=p1.x,p2.x do
if hollow and x ~= p1.x and x ~= p2.x and y ~= p1.y and y ~= p2.y then if hollow and x ~= p1.x and x ~= p2.x and y ~= p1.y and y ~= p2.y then
goto continue goto continue
@ -678,7 +691,7 @@ function PlannerOverlay:place_building(placement_data, chosen_items)
local bld, err = dfhack.buildings.constructBuilding{pos=pos, local bld, err = dfhack.buildings.constructBuilding{pos=pos,
type=uibs.building_type, subtype=subtype, custom=uibs.custom_type, type=uibs.building_type, subtype=subtype, custom=uibs.custom_type,
width=placement_data.width, height=placement_data.height, width=placement_data.width, height=placement_data.height,
direction=uibs.direction} direction=uibs.direction, filters=filters}
if err then if err then
-- it's ok if some buildings fail to build -- it's ok if some buildings fail to build
goto continue goto continue
@ -692,6 +705,7 @@ function PlannerOverlay:place_building(placement_data, chosen_items)
if k == 'dump_x_shift' then bld.dump_x_shift = uibs.dump_x_shift end if k == 'dump_x_shift' then bld.dump_x_shift = uibs.dump_x_shift end
if k == 'dump_y_shift' then bld.dump_y_shift = uibs.dump_y_shift end if k == 'dump_y_shift' then bld.dump_y_shift = uibs.dump_y_shift end
if k == 'speed' then bld.speed = uibs.speed end if k == 'speed' then bld.speed = uibs.speed end
if k == 'plate_info' then utils.assign(bld.plate_info, uibs.plate_info) end
end end
table.insert(blds, bld) table.insert(blds, bld)
::continue:: ::continue::