Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/Lua API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3607,6 +3607,15 @@ Native functions:
``start`` and ``end`` are tables containing positions (see
``xyz2pos``). ``name`` is used as the basis for the filename.

buildingplan
============

Native functions:

* ``bool isPlannableBuilding(df::building_type type)`` returns whether the building type is handled by buildingplan
* ``void addPlannedBuilding(df::building *bld)`` suspends the building jobs and adds the building to the monitor list
* ``void doCycle()`` runs a check for whether buildlings in the monitor list can be assigned items and unsuspended. This method runs automatically twice a game day, so you only need to call it directly if you want buildingplan to do a check right now.

burrows
=======

Expand Down
2 changes: 1 addition & 1 deletion plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ if(BUILD_SUPPORTED)
dfhack_plugin(blueprint blueprint.cpp LINK_LIBRARIES lua)
dfhack_plugin(burrows burrows.cpp LINK_LIBRARIES lua)
dfhack_plugin(building-hacks building-hacks.cpp LINK_LIBRARIES lua)
dfhack_plugin(buildingplan buildingplan.cpp LINK_LIBRARIES buildingplan-lib)
dfhack_plugin(buildingplan buildingplan.cpp LINK_LIBRARIES lua buildingplan-lib)
dfhack_plugin(changeitem changeitem.cpp)
dfhack_plugin(changelayer changelayer.cpp)
dfhack_plugin(changevein changevein.cpp)
Expand Down
5 changes: 0 additions & 5 deletions plugins/buildingplan-lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,6 @@ bool Planner::allocatePlannedBuilding(df::building_type type)
return false;
}

for (auto iter = newinst->jobs.begin(); iter != newinst->jobs.end(); iter++)
{
(*iter)->flags.bits.suspend = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why did this move to addPlannedBuilding?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addPlannedBuilding is an API method, but it didn't seem to enforce the supposed invariant that planned buildings are suspended. Refactoring the functionality into the method itself seemed cleaner than making it a separate API method or reimplementing the suspension in Lua.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see allocatePlannedBuilding calling addPlannedBuilding now (the door check was between this removed section and that call, but didn't need to be).

}

if (type == building_type::Door)
{
auto door = virtual_cast<df::building_doorst>(newinst);
Expand Down
5 changes: 5 additions & 0 deletions plugins/buildingplan-lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ class Planner

void addPlannedBuilding(df::building *bld)
{
for (auto iter = bld->jobs.begin(); iter != bld->jobs.end(); iter++)
{
(*iter)->flags.bits.suspend = true;
}

PlannedBuilding pb(bld, &default_item_filters[bld->getType()]);
planned_buildings.push_back(pb);
}
Expand Down
22 changes: 22 additions & 0 deletions plugins/buildingplan.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "LuaTools.h"
#include "buildingplan-lib.h"

DFHACK_PLUGIN("buildingplan");
Expand Down Expand Up @@ -414,3 +415,24 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan

return CR_OK;
}

// Lua API section

static bool isPlannableBuilding(df::building_type type) {
return planner.isPlanableBuilding(type);
}

static void addPlannedBuilding(df::building *bld) {
planner.addPlannedBuilding(bld);
}

static void doCycle() {
planner.doCycle();
}

DFHACK_PLUGIN_LUA_FUNCTIONS {
DFHACK_LUA_FUNCTION(isPlannableBuilding),
DFHACK_LUA_FUNCTION(addPlannedBuilding),
DFHACK_LUA_FUNCTION(doCycle),
DFHACK_LUA_END
};
13 changes: 13 additions & 0 deletions plugins/lua/buildingplan.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local _ENV = mkmodule('plugins.buildingplan')

--[[

Native functions:

* bool isPlannableBuilding(df::building_type type)
* void addPlannedBuilding(df::building *bld)
* void doCycle()

--]]

return _ENV