v50 Steam/Premium information for editors
- v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
- Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.
Editing User:Fleeting Frames/constructmultiz
Jump to navigation
Jump to search
Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 3: | Line 3: | ||
<source lang="lua"> | <source lang="lua"> | ||
--lets one construct simultaneously on z-axis | --lets one construct simultaneously on z-axis | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
local helptext = [===[ | local helptext = [===[ | ||
constructonmultiplezlevels | constructonmultiplezlevels | ||
========================== | ========================== | ||
− | version 1. | + | version 1.01 (beta) |
Script to construct multiple z-levels of buildings at once. | Script to construct multiple z-levels of buildings at once. | ||
Currently uses general seeking for matching material and type, | Currently uses general seeking for matching material and type, | ||
Line 57: | Line 33: | ||
qerror("") | qerror("") | ||
end | end | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
function getCurHeightAndDepth() | function getCurHeightAndDepth() | ||
Line 81: | Line 50: | ||
end | end | ||
return 0, 0 --if found nothing, reset to nothing | return 0, 0 --if found nothing, reset to nothing | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
Line 612: | Line 91: | ||
constructMultiZPowerState(false) | constructMultiZPowerState(false) | ||
--first, remove old binds | --first, remove old binds | ||
− | |||
curheight = height+curheight | curheight = height+curheight | ||
curdepth = depth+curdepth | curdepth = depth+curdepth | ||
Line 623: | Line 101: | ||
constructMultiZPowerState(true) | constructMultiZPowerState(true) | ||
--then add new bindings | --then add new bindings | ||
− | |||
end | end | ||
local indipresent, indi = pcall(function() return dfhack.script_environment('gui/indicator_screen') end) | local indipresent, indi = pcall(function() return dfhack.script_environment('gui/indicator_screen') end) | ||
Line 629: | Line 106: | ||
local changeHeight --defined below | local changeHeight --defined below | ||
+ | local gui = require 'gui' | ||
local dlg = require 'gui.dialogs' | local dlg = require 'gui.dialogs' | ||
− | |||
− | |||
function numberprompt (above, initialvalue) | function numberprompt (above, initialvalue) | ||
local retvalue = tostring(initialvalue) | local retvalue = tostring(initialvalue) | ||
Line 692: | Line 168: | ||
myrfunc() | myrfunc() | ||
end | end | ||
− | + | ||
− | local function isInBuildType() | + | local function isInBuildType() |
return dfhack.gui.getFocusString(df.global.gview.view.child):find("dwarfmode/Build/Type") | return dfhack.gui.getFocusString(df.global.gview.view.child):find("dwarfmode/Build/Type") | ||
end | end | ||
local notincountdown = true | local notincountdown = true | ||
local function multizonInput(self, keys) | local function multizonInput(self, keys) | ||
− | oldInput(self, keys) | + | oldInput(self, keys) |
− | |||
− | |||
− | |||
− | |||
if (dfhack.gui.getFocusString(df.global.gview.view.child):find("dwarfmode/Build/Position/Construction") | if (dfhack.gui.getFocusString(df.global.gview.view.child):find("dwarfmode/Build/Position/Construction") | ||
or (keys.SELECT and | or (keys.SELECT and | ||
Line 714: | Line 186: | ||
dfhack.timeout(math.floor(2*df.global.enabler.fps), "frames", function() | dfhack.timeout(math.floor(2*df.global.enabler.fps), "frames", function() | ||
texts[1].text = "" | texts[1].text = "" | ||
− | if indi.indicator_screen_version >= 1.1 | + | if indi.indicator_screen_version >= 1.1 then |
self._native.parent.child = nil | self._native.parent.child = nil | ||
repeatfunction(function() | repeatfunction(function() | ||
indi.placeOnTop(self._native) | indi.placeOnTop(self._native) | ||
− | notincountdown = true | + | notincountdown = true |
end, isInBuildType, 10) | end, isInBuildType, 10) | ||
else self:dismiss() end | else self:dismiss() end | ||
Line 753: | Line 225: | ||
− | function getFlag( | + | function getFlag(object, flag) |
− | -- Utility function for safely requesting info from | + | -- Utility function for safely requesting info from userdata |
− | + | -- Returns nil if the object doesn't have flag attribute, else returns it's value | |
− | + | -- Because well, ordinarily, {}[flag] returns nil. | |
− | + | -- However, if object is unit - or some other type, it may instead throw an error | |
− | if | + | local a = {} |
− | if not | + | if not object or not flag then return nil end |
− | for | + | --Crash is still possible for attempting to pairs a nil |
− | + | for index, value in pairs(object) do | |
− | + | a[index] = value | |
− | |||
− | |||
end | end | ||
− | + | local returnvalue = a[flag] | |
+ | a = nil --lua automatically garbage cleans tables without variable that links to them. | ||
+ | return returnvalue | ||
end | end | ||
Line 792: | Line 264: | ||
local zpositive = tonumber(args[1]) -- 0 0 should equal nothing being done | local zpositive = tonumber(args[1]) -- 0 0 should equal nothing being done | ||
local znegative = tonumber(args[2]) | local znegative = tonumber(args[2]) | ||
− | |||
− | |||
− | if zpositive > 0 or znegative | + | |
+ | if zpositive > 0 or znegative > 0 then | ||
local buildings = require('dfhack.buildings') | local buildings = require('dfhack.buildings') | ||
Line 812: | Line 283: | ||
local tostring2 = tostring | local tostring2 = tostring | ||
local tadd = table.insert --tadd is less missleading than tin or tins | local tadd = table.insert --tadd is less missleading than tin or tins | ||
− | function copy1building(lbd | + | function copy1building(lbd, zoffset) |
bd = {} | bd = {} | ||
− | bd.x = lbd.x1 | + | bd.x = lbd.x1 |
bd.width = 1+lbd.x2-lbd.x1 | bd.width = 1+lbd.x2-lbd.x1 | ||
bd.height = 1+lbd.y2-lbd.y1 | bd.height = 1+lbd.y2-lbd.y1 | ||
− | bd.y = lbd.y1 | + | bd.y = lbd.y1 |
bd.z = lbd.z+zoffset | bd.z = lbd.z+zoffset | ||
Line 831: | Line 302: | ||
or (bd.type == df.building_type.Trap and bd.subtype == 4 )) then -- All traps other than weapon trap | or (bd.type == df.building_type.Trap and bd.subtype == 4 )) then -- All traps other than weapon trap | ||
argumenttable = {material = {mat_type = lbd.mat_type, mat_index = lbd.mat_index,}} | argumenttable = {material = {mat_type = lbd.mat_type, mat_index = lbd.mat_index,}} | ||
− | if | + | if getFlag(lbd.jobs[0].items, 0) then |
argumenttable.material.item_type = | argumenttable.material.item_type = | ||
df.item_type[tostring2(lbd.jobs[0].items[0].item):gsub("st:.*",""):gsub("<item_",""):upper()] | df.item_type[tostring2(lbd.jobs[0].items[0].item):gsub("st:.*",""):gsub("<item_",""):upper()] | ||
Line 980: | Line 451: | ||
if (getFlag(createdbuilding,"is_vertical") or getFlag(createdbuilding,"direction") ) | if (getFlag(createdbuilding,"is_vertical") or getFlag(createdbuilding,"direction") ) | ||
and bd.type ~= df.building_type.Bridge then --bridges are already perfect in x and y | and bd.type ~= df.building_type.Bridge then --bridges are already perfect in x and y | ||
− | createdbuilding.x1 = lbd.x1 | + | createdbuilding.x1 = lbd.x1 |
− | createdbuilding.y1 = lbd.y1 | + | createdbuilding.y1 = lbd.y1 |
− | createdbuilding.x2 = lbd.x2 | + | createdbuilding.x2 = lbd.x2 |
− | createdbuilding.y2 = lbd.y2 | + | createdbuilding.y2 = lbd.y2 |
end | end | ||
− | createdbuilding.centerx = lbd.centerx | + | createdbuilding.centerx = lbd.centerx |
− | createdbuilding.centery = lbd.centery | + | createdbuilding.centery = lbd.centery |
--constructbuilding tends to round center up where df rounds down. | --constructbuilding tends to round center up where df rounds down. | ||
if flippedPumps % 2 ~= 0 and bd.type == df.building_type.ScrewPump then | if flippedPumps % 2 ~= 0 and bd.type == df.building_type.ScrewPump then | ||
--screw pump direction was swapped, so it'd center tile has to be swapped as well | --screw pump direction was swapped, so it'd center tile has to be swapped as well | ||
− | --otherwise dwarf tries to build it on impassable tile. | + | --otherwise dwarf tries to build it on impassable tile. |
if createdbuilding.direction % 2 == 0 then --northsouth | if createdbuilding.direction % 2 == 0 then --northsouth | ||
createdbuilding.centery = createdbuilding.centery == createdbuilding.y1 and createdbuilding.y2 or createdbuilding.y1 | createdbuilding.centery = createdbuilding.centery == createdbuilding.y1 and createdbuilding.y2 or createdbuilding.y1 | ||
Line 1,002: | Line 473: | ||
local lenb = #df.global.world.buildings.all --changes during usage so must save beforehand | local lenb = #df.global.world.buildings.all --changes during usage so must save beforehand | ||
local w,h | local w,h | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
if getBuildingTypeIndex(tostring(df.global.world.buildings.all[lenb-1])) ~= 34 then | if getBuildingTypeIndex(tostring(df.global.world.buildings.all[lenb-1])) ~= 34 then | ||
--not construction | --not construction | ||
Line 1,015: | Line 480: | ||
h = df.global.world.building_height | h = df.global.world.building_height | ||
end | end | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
for i = 1, w*h do | for i = 1, w*h do | ||
if zpositive > 0 then | if zpositive > 0 then | ||
for zoff = 1, zpositive do | for zoff = 1, zpositive do | ||
− | copy1building(df.global.world.buildings.all[lenb-i] | + | copy1building(df.global.world.buildings.all[lenb-i],zoff) |
− | |||
end | end | ||
end | end | ||
if znegative > 0 then | if znegative > 0 then | ||
for zoff = -1, -znegative, -1 do | for zoff = -1, -znegative, -1 do | ||
− | copy1building(df.global.world.buildings.all[lenb-i] | + | copy1building(df.global.world.buildings.all[lenb-i],zoff) |
− | |||
end | end | ||
end | end | ||
end | end | ||
− | + | ||
− | |||
− | |||
end | end | ||
end | end | ||
</source> | </source> |