Merge remote-tracking branch 'myk002/quickfort_buildingplan' into develop

develop
lethosor 2020-08-17 23:43:05 -04:00
commit 19a4d1df5a
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
6 changed files with 50 additions and 6 deletions

@ -3607,6 +3607,15 @@ Native functions:
``start`` and ``end`` are tables containing positions (see ``start`` and ``end`` are tables containing positions (see
``xyz2pos``). ``name`` is used as the basis for the filename. ``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 burrows
======= =======

@ -110,7 +110,7 @@ if(BUILD_SUPPORTED)
dfhack_plugin(blueprint blueprint.cpp LINK_LIBRARIES lua) dfhack_plugin(blueprint blueprint.cpp LINK_LIBRARIES lua)
dfhack_plugin(burrows burrows.cpp LINK_LIBRARIES lua) dfhack_plugin(burrows burrows.cpp LINK_LIBRARIES lua)
dfhack_plugin(building-hacks building-hacks.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(changeitem changeitem.cpp)
dfhack_plugin(changelayer changelayer.cpp) dfhack_plugin(changelayer changelayer.cpp)
dfhack_plugin(changevein changevein.cpp) dfhack_plugin(changevein changevein.cpp)

@ -623,11 +623,6 @@ bool Planner::allocatePlannedBuilding(df::building_type type)
return false; return false;
} }
for (auto iter = newinst->jobs.begin(); iter != newinst->jobs.end(); iter++)
{
(*iter)->flags.bits.suspend = true;
}
if (type == building_type::Door) if (type == building_type::Door)
{ {
auto door = virtual_cast<df::building_doorst>(newinst); auto door = virtual_cast<df::building_doorst>(newinst);

@ -403,6 +403,11 @@ public:
void addPlannedBuilding(df::building *bld) 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()]); PlannedBuilding pb(bld, &default_item_filters[bld->getType()]);
planned_buildings.push_back(pb); planned_buildings.push_back(pb);
} }

@ -1,3 +1,4 @@
#include "LuaTools.h"
#include "buildingplan-lib.h" #include "buildingplan-lib.h"
DFHACK_PLUGIN("buildingplan"); DFHACK_PLUGIN("buildingplan");
@ -414,3 +415,24 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
return CR_OK; 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,13 @@
local _ENV = mkmodule('plugins.buildingplan')
--[[
Native functions:
* bool isPlannableBuilding(df::building_type type)
* void addPlannedBuilding(df::building *bld)
* void doCycle()
--]]
return _ENV