support start() markers in test blueprints

develop
myk002 2022-02-16 17:12:28 -08:00 committed by Myk
parent 0303e182a8
commit 5ab541c17e
1 changed files with 25 additions and 14 deletions

@ -9,6 +9,7 @@
-- width (required) -- width (required)
-- height (required) -- height (required)
-- depth (default is 1) -- depth (default is 1)
-- start (cursor offset for input blueprints, default is 1,1)
-- --
-- depends on blueprint, buildingplan, and dig-now plugins (as well as the -- depends on blueprint, buildingplan, and dig-now plugins (as well as the
-- quickfort script, of course) -- quickfort script, of course)
@ -22,6 +23,7 @@
config.mode = 'fortress' config.mode = 'fortress'
local argparse = require('argparse')
local blueprint = require('plugins.blueprint') local blueprint = require('plugins.blueprint')
local quickfort_list = reqscript('internal/quickfort/list') local quickfort_list = reqscript('internal/quickfort/list')
local quickfort_command = reqscript('internal/quickfort/command') local quickfort_command = reqscript('internal/quickfort/command')
@ -120,6 +122,11 @@ local function get_blueprint_sets()
spec.width = get_positive_int(spec.width, 'width', basename) spec.width = get_positive_int(spec.width, 'width', basename)
spec.height = get_positive_int(spec.height, 'height', basename) spec.height = get_positive_int(spec.height, 'height', basename)
spec.depth = get_positive_int(spec.depth, 'depth', basename) spec.depth = get_positive_int(spec.depth, 'depth', basename)
if spec.start then
local start_spec = argparse.numberList(spec.start, basename, 2)
spec.start = {x=get_positive_int(start_spec[1], 'startx', basename),
y=get_positive_int(start_spec[2], 'starty', basename)}
end
end end
return sets return sets
@ -179,20 +186,22 @@ local function get_test_area(area, spec)
end end
end end
local function get_cursor_arg(pos) local function get_cursor_arg(pos, start)
return ('--cursor=%d,%d,%d'):format(pos.x, pos.y, pos.z) start = start or {x=1, y=1}
return ('--cursor=%d,%d,%d'):format(pos.x+start.x-1, pos.y+start.y-1, pos.z)
end end
local function quickfort_cmd(cmd, listnum, pos) local function quickfort_cmd(cmd, listnum, pos, start)
dfhack.run_script('quickfort', cmd, '-q', listnum, get_cursor_arg(pos)) dfhack.run_script('quickfort', cmd, '-q', listnum,
get_cursor_arg(pos, start))
end end
local function quickfort_run(listnum, pos) local function quickfort_run(listnum, pos, start)
quickfort_cmd('run', listnum, pos) quickfort_cmd('run', listnum, pos, start)
end end
local function quickfort_undo(listnum, pos) local function quickfort_undo(listnum, pos, start)
quickfort_cmd('undo', listnum, pos) quickfort_cmd('undo', listnum, pos, start)
end end
local function designate_area(pos, spec) local function designate_area(pos, spec)
@ -259,11 +268,13 @@ function test.end_to_end()
local area = {width=0, height=0, depth=0} local area = {width=0, height=0, depth=0}
for basename,set in pairs(sets) do for basename,set in pairs(sets) do
local spec = set.spec
print(('running quickfort ecosystem test: "%s": %s'): print(('running quickfort ecosystem test: "%s": %s'):
format(basename, set.spec.description)) format(basename, spec.description))
-- find an unused area of the map that meets requirements, else skip -- find an unused area of the map that meets requirements, else skip
if not get_test_area(area, set.spec) then if not get_test_area(area, spec) then
print(('cannot find unused map area to test set "%s"; skipping'): print(('cannot find unused map area to test set "%s"; skipping'):
format(basename)) format(basename))
goto continue goto continue
@ -273,9 +284,9 @@ function test.end_to_end()
-- there is no #dig blueprint) -- there is no #dig blueprint)
local phases = set.phases local phases = set.phases
if phases.dig then if phases.dig then
quickfort_run(phases.dig.listnum, area.pos) quickfort_run(phases.dig.listnum, area.pos, spec.start)
else else
designate_area(area.pos, set.spec) designate_area(area.pos, spec)
end end
-- run dig-now to dig out designated tiles -- run dig-now to dig out designated tiles
@ -284,7 +295,7 @@ function test.end_to_end()
-- quickfort run remaining blueprints -- quickfort run remaining blueprints
for _,phase_name in ipairs(phase_names) do for _,phase_name in ipairs(phase_names) do
if phase_name ~= 'dig' and phases[phase_name] then if phase_name ~= 'dig' and phases[phase_name] then
quickfort_run(phases[phase_name].listnum, area.pos) quickfort_run(phases[phase_name].listnum, area.pos, spec.start)
if phase_name == 'track' then if phase_name == 'track' then
run_dig_now(area) run_dig_now(area)
end end
@ -297,7 +308,7 @@ function test.end_to_end()
-- quickfort undo blueprints -- quickfort undo blueprints
for _,phase_name in ipairs(phase_names) do for _,phase_name in ipairs(phase_names) do
if phases[phase_name] then if phases[phase_name] then
quickfort_undo(phases[phase_name].listnum, area.pos) quickfort_undo(phases[phase_name].listnum, area.pos, spec.start)
end end
end end