expose basic buildingplan functionality to Lua

develop
Myk Taylor 2020-08-12 15:12:53 -07:00
parent f2b0f012c9
commit 42108a64b9
5 changed files with 31 additions and 6 deletions

@ -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)

@ -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;
}
if (type == building_type::Door)
{
auto door = virtual_cast<df::building_doorst>(newinst);

@ -403,6 +403,11 @@ public:
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);
}

@ -1,3 +1,4 @@
#include "LuaTools.h"
#include "buildingplan-lib.h"
DFHACK_PLUGIN("buildingplan");
@ -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
};

@ -0,0 +1,3 @@
local _ENV = mkmodule('plugins.buildingplan')
return _ENV