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.

Difference between revisions of "User:Fleeting Frames/UnsuspendSelectedBuilding"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
(Initial writeup)
 
m (pre to source lang lua)
Line 1: Line 1:
 
Save as UnsuspendSelectedBuilding.lua into /hack/scripts folder.
 
Save as UnsuspendSelectedBuilding.lua into /hack/scripts folder.
  
<pre>
+
<source lang="lua">
 
--auto-unsuspend selected building.
 
--auto-unsuspend selected building.
  
Line 89: Line 89:
 
true)
 
true)
 
end
 
end
</pre>
+
</source>

Revision as of 00:52, 4 July 2019

Save as UnsuspendSelectedBuilding.lua into /hack/scripts folder.

--auto-unsuspend selected building.

local bld = dfhack.gui.getSelectedBuilding(true)
utils = require 'utils';
if not bld.construction_stage then qerror("Building " .. utils.getBuildingName(bld) .. " isn't constructed in stages.") end


local function repeatfunction(rfunc)
	--repeats a function every 10 frames, until the function returns false or nil
	local myrfunc
	
	myrfunc = function ()
	  timeoutid = dfhack.timeout(10, "ticks", function(options)
		if rfunc() then myrfunc() end
	   end)
	end
	
	myrfunc()
end

function AnnounceStart(bld)
		dfhack.gui.makeAnnouncement(
			df.announcement_type.JOB_OVERWRITTEN,
			{D_DISPLAY = true},
			xyz2pos(bld.centerx,bld.centery, bld.z),
			"Started unsuspending " .. utils.getBuildingName(bld) .. ".",
			COLOR_GREEN,
			true)
end

function AnnounceEnd(bld)
		dfhack.gui.makeAnnouncement(
			df.announcement_type.QUOTA_FILLED,
			{D_DISPLAY = true},
			xyz2pos(bld.centerx,bld.centery, bld.z),
			"Completed building " .. utils.getBuildingName(bld) .. ".",
			COLOR_GREEN,
			true)
end

function getConstructionJob(building)
	for _, attachedjob in ipairs(building.jobs) do
		if attachedjob.job_type == 68 then
			return attachedjob
		end
	end
end

watchedbuildings = watchedbuildings or {}

if (bld and not watchedbuildings[tostring(bld)]) then
	if bld.flags.exists == false then
		local bldjob=getConstructionJob(bld)
		if bldjob then
			local myBldStr=tostring(bld)
			if(watchedbuildings[myBldStr] ~= false) then --don't set repeatfunc when there's already one
				repeatfunction(
					function()
						if(watchedbuildings[myBldStr]) then 
							local bld = df.building.find(watchedbuildings[myBldStr])
							local bldjob = bld and getConstructionJob(bld)
							if bld and bldjob then
								bldjob.flags.suspend=false
								if bld.flags.exists == false then 
									return true
								end
							end
						end
						watchedbuildings[tostring(bld)] = nil --if didn't return, end is at hand
						AnnounceEnd(bld) 
					end
				)
			end
			watchedbuildings[tostring(bld)]=bld.id
			AnnounceStart(bld)
		end
	end
elseif (bld and watchedbuildings[tostring(bld)]) then
	watchedbuildings[tostring(bld)] = false
	dfhack.gui.makeAnnouncement(
		df.announcement_type.JOB_OVERWRITTEN,
		{D_DISPLAY = true},
		xyz2pos(bld.centerx,bld.centery, bld.z),
		"Stopped unsuspending " .. utils.getBuildingName(bld) .. ".",
	COLOR_GREEN,
	true)
end