Loop through all owned items of all units.

develop
JapaMala 2019-04-27 07:53:23 -05:00
parent bc05c9b1a1
commit 78bd70c858
1 changed files with 34 additions and 2 deletions

@ -9,12 +9,15 @@
// DF data structure definition headers
#include "DataDefs.h"
#include "modules/Maps.h"
#include "modules/Units.h"
#include "modules/World.h"
#include "df/manager_order.h"
#include "df/world.h"
using namespace DFHack;
using namespace DFHack::Units;
using namespace df::enums;
// A plugin must be able to return its name and version.
@ -29,12 +32,14 @@ DFHACK_PLUGIN("autoclothing");
REQUIRE_GLOBAL(world);
// Only run if this is enabled
DFHACK_PLUGIN_IS_ENABLED(active);
DFHACK_PLUGIN_IS_ENABLED(autoclothing_enabled);
// Here go all the command declarations...
// mostly to allow having the mandatory stuff on top of the file and commands on the bottom
command_result autoclothing(color_ostream &out, std::vector <std::string> & parameters);
static void do_autoclothing();
// Mandatory init function. If you have some global state, create it here.
DFhackCExport command_result plugin_init(color_ostream &out, std::vector <PluginCommand> &commands)
{
@ -85,7 +90,20 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
DFhackCExport command_result plugin_onupdate ( color_ostream &out )
{
// whetever. You don't need to suspend DF execution here.
if (!autoclothing_enabled)
return CR_OK;
if (!Maps::IsValid())
return CR_OK;
if (DFHack::World::ReadPauseState())
return CR_OK;
if ((world->frame_counter + 500) % 1200 != 0) // Check every day, but not the same day as other things
return CR_OK;
do_autoclothing();
return CR_OK;
}
@ -111,3 +129,17 @@ command_result autoclothing(color_ostream &out, std::vector <std::string> & para
// Give control back to DF.
return CR_OK;
}
static void do_autoclothing()
{
for (auto&& unit : world->units.active)
{
if (!isCitizen(unit))
continue;
for (auto&& ownedItem : unit->owned_items)
{
}
}
}