Kill the Kitchen module (which was never really a proper module to begin with)

develop
Quietust 2012-01-16 21:22:42 -06:00
parent a9eb555b99
commit 9d8c67b710
3 changed files with 213 additions and 266 deletions

@ -30,9 +30,9 @@ distribution.
#include "Module.h" #include "Module.h"
#include "Types.h" #include "Types.h"
#include "VersionInfo.h" #include "VersionInfo.h"
#include "modules/Materials.h"
#include "modules/Items.h"
#include "Core.h" #include "Core.h"
#include "modules/Items.h"
/** /**
* \defgroup grp_kitchen Kitchen settings * \defgroup grp_kitchen Kitchen settings
* @ingroup grp_modules * @ingroup grp_modules
@ -40,6 +40,8 @@ distribution.
namespace DFHack namespace DFHack
{ {
namespace Simple
{
namespace Kitchen namespace Kitchen
{ {
typedef uint8_t t_exclusionType; typedef uint8_t t_exclusionType;
@ -52,45 +54,33 @@ const t_itemSubtype limitSubtype = 0; // used to store limit as an entry in the
const t_exclusionType limitExclusion = 4; // used to store limit as an entry in the exclusion list const t_exclusionType limitExclusion = 4; // used to store limit as an entry in the exclusion list
/** /**
* Kitchen exclusions manipulator class. Currently geared towards plants and seeds. * Kitchen exclusions manipulator. Currently geared towards plants and seeds.
* @ingroup grp_kitchen * \ingroup grp_modules
* \ingroup grp_kitchen
*/ */
class DFHACK_EXPORT Exclusions
{
public:
/// ctor
Exclusions(DFHack::Core& core_);
/// dtor
~Exclusions();
/// print the exclusion list, with the material index also translated into its token (for organics) - for debug really
void debug_print() const;
/// remove this material from the exclusion list if it is in it // print the exclusion list, with the material index also translated into its token (for organics) - for debug really
void allowPlantSeedCookery(t_materialIndex materialIndex); DFHACK_EXPORT void debug_print(Core &);
/// add this material to the exclusion list, if it is not already in it // remove this material from the exclusion list if it is in it
void denyPlantSeedCookery(t_materialIndex materialIndex); DFHACK_EXPORT void allowPlantSeedCookery(t_materialIndex materialIndex);
/// fills a map with info from the limit info storage entries in the exclusion list // add this material to the exclusion list, if it is not already in it
void fillWatchMap(std::map<t_materialIndex, unsigned int>& watchMap) const; DFHACK_EXPORT void denyPlantSeedCookery(t_materialIndex materialIndex);
/// removes a limit info storage entry from the exclusion list if it's present // fills a map with info from the limit info storage entries in the exclusion list
void removeLimit(t_materialIndex materialIndex); DFHACK_EXPORT void fillWatchMap(std::map<t_materialIndex, unsigned int>& watchMap);
/// add a limit info storage item to the exclusion list, or alters an existing one // removes a limit info storage entry from the exclusion list if it's present
void setLimit(t_materialIndex materialIndex, unsigned int limit); DFHACK_EXPORT void removeLimit(t_materialIndex materialIndex);
/// clears all limit info storage items from the exclusion list // add a limit info storage item to the exclusion list, or alters an existing one
void clearLimits(); DFHACK_EXPORT void setLimit(t_materialIndex materialIndex, unsigned int limit);
/// the size of the exclusions vectors (they are all the same size - if not, there is a problem!) // clears all limit info storage items from the exclusion list
std::size_t size() const; DFHACK_EXPORT void clearLimits();
private:
class Private;
Private* d;
};
DFHACK_EXPORT std::size_t size();
}
} }
} }

@ -9,79 +9,46 @@
#include <set> #include <set>
using namespace std; using namespace std;
#include "Types.h"
#include "VersionInfo.h" #include "VersionInfo.h"
#include "MemAccess.h" #include "MemAccess.h"
#include "modules/Materials.h" #include "Types.h"
#include "modules/Items.h" #include "Error.h"
#include "modules/Units.h"
#include "modules/kitchen.h" #include "modules/kitchen.h"
#include "ModuleFactory.h" #include "ModuleFactory.h"
#include "Core.h" #include "Core.h"
#include "Virtual.h" using namespace DFHack;
#include "df/item_type.h" using namespace DFHack::Simple;
namespace DFHack
{
namespace Kitchen
{
class Exclusions::Private
{
public:
Private (DFHack::Core& core_)
: core(core_)
, itemTypes (*((std::vector<t_itemType >*)(addr(core_,0))))
, itemSubtypes (*((std::vector<t_itemSubtype >*)(addr(core_,1))))
, materialTypes (*((std::vector<t_materialType >*)(addr(core_,2))))
, materialIndices (*((std::vector<t_materialIndex>*)(addr(core_,3))))
, exclusionTypes (*((std::vector<t_exclusionType>*)(addr(core_,4))))
{
};
DFHack::Core& core;
std::vector<t_itemType>& itemTypes; // the item types vector of the kitchen exclusion list
std::vector<t_itemSubtype>& itemSubtypes; // the item subtype vector of the kitchen exclusion list
std::vector<t_materialType>& materialTypes; // the material subindex vector of the kitchen exclusion list
std::vector<t_materialIndex>& materialIndices; // the material index vector of the kitchen exclusion list
std::vector<t_exclusionType>& exclusionTypes; // the exclusion type vector of the kitchen excluions list
static void * addr(const DFHack::Core& core, int index) #include "DataDefs.h"
{ #include "df/world.h"
static char * start = core.vinfo->getAddress("kitchen_limits"); #include "df/ui.h"
return start + sizeof(std::vector<int>) * index; #include "df/item_type.h"
}; #include "df/plant_raw.h"
};
Exclusions::Exclusions(Core & c) using namespace df::enums;
{ using df::global::world;
d = new Private(c); using df::global::ui;
};
Exclusions::~Exclusions() void Kitchen::debug_print(Core &core)
{ {
delete d; core.con.print("Kitchen Exclusions\n");
};
void Exclusions::debug_print() const
{
d->core.con.print("Kitchen Exclusions\n");
Materials& materialsModule= *d->core.getMaterials();
for(std::size_t i = 0; i < size(); ++i) for(std::size_t i = 0; i < size(); ++i)
{ {
d->core.con.print("%2u: IT:%2i IS:%i MT:%3i MI:%2i ET:%i %s\n", core.con.print("%2u: IT:%2i IS:%i MT:%3i MI:%2i ET:%i %s\n",
i, i,
d->itemTypes[i], ui->kitchen.item_types[i],
d->itemSubtypes[i], ui->kitchen.item_subtypes[i],
d->materialTypes[i], ui->kitchen.mat_types[i],
d->materialIndices[i], ui->kitchen.mat_indices[i],
d->exclusionTypes[i], ui->kitchen.exc_types[i],
materialsModule.df_organic->at(d->materialIndices[i])->ID.c_str() (ui->kitchen.mat_types[i] >= 419 && ui->kitchen.mat_types[i] <= 618) ? world->raws.plants.all[ui->kitchen.mat_indices[i]]->id.c_str() : "n/a"
); );
} }
d->core.con.print("\n"); core.con.print("\n");
} }
void Exclusions::allowPlantSeedCookery(t_materialIndex materialIndex) void Kitchen::allowPlantSeedCookery(t_materialIndex materialIndex)
{ {
bool match = false; bool match = false;
do do
{ {
@ -89,9 +56,9 @@ namespace Kitchen
std::size_t matchIndex = 0; std::size_t matchIndex = 0;
for(std::size_t i = 0; i < size(); ++i) for(std::size_t i = 0; i < size(); ++i)
{ {
if(d->materialIndices[i] == materialIndex if(ui->kitchen.mat_indices[i] == materialIndex
&& (d->itemTypes[i] == df::item_type::SEEDS || d->itemTypes[i] == df::item_type::PLANT) && (ui->kitchen.item_types[i] == df::item_type::SEEDS || ui->kitchen.item_types[i] == df::item_type::PLANT)
&& d->exclusionTypes[i] == cookingExclusion && ui->kitchen.exc_types[i] == cookingExclusion
) )
{ {
match = true; match = true;
@ -100,64 +67,63 @@ namespace Kitchen
} }
if(match) if(match)
{ {
d->itemTypes.erase(d->itemTypes.begin() + matchIndex); ui->kitchen.item_types.erase(ui->kitchen.item_types.begin() + matchIndex);
d->itemSubtypes.erase(d->itemSubtypes.begin() + matchIndex); ui->kitchen.item_subtypes.erase(ui->kitchen.item_subtypes.begin() + matchIndex);
d->materialIndices.erase(d->materialIndices.begin() + matchIndex); ui->kitchen.mat_indices.erase(ui->kitchen.mat_indices.begin() + matchIndex);
d->materialTypes.erase(d->materialTypes.begin() + matchIndex); ui->kitchen.mat_types.erase(ui->kitchen.mat_types.begin() + matchIndex);
d->exclusionTypes.erase(d->exclusionTypes.begin() + matchIndex); ui->kitchen.exc_types.erase(ui->kitchen.exc_types.begin() + matchIndex);
} }
} while(match); } while(match);
}; };
void Exclusions::denyPlantSeedCookery(t_materialIndex materialIndex) void Kitchen::denyPlantSeedCookery(t_materialIndex materialIndex)
{ {
Materials *mats = d->core.getMaterials(); df::plant_raw *type = world->raws.plants.all[materialIndex];
df_plant_type *type = mats->df_organic->at(materialIndex);
bool SeedAlreadyIn = false; bool SeedAlreadyIn = false;
bool PlantAlreadyIn = false; bool PlantAlreadyIn = false;
for(std::size_t i = 0; i < size(); ++i) for(std::size_t i = 0; i < size(); ++i)
{ {
if(d->materialIndices[i] == materialIndex if(ui->kitchen.mat_indices[i] == materialIndex
&& d->exclusionTypes[i] == cookingExclusion) && ui->kitchen.exc_types[i] == cookingExclusion)
{ {
if(d->itemTypes[i] == df::item_type::SEEDS) if(ui->kitchen.item_types[i] == df::item_type::SEEDS)
SeedAlreadyIn = true; SeedAlreadyIn = true;
else if (d->itemTypes[i] == df::item_type::PLANT) else if (ui->kitchen.item_types[i] == df::item_type::PLANT)
PlantAlreadyIn = true; PlantAlreadyIn = true;
} }
} }
if(!SeedAlreadyIn) if(!SeedAlreadyIn)
{ {
d->itemTypes.push_back(df::item_type::SEEDS); ui->kitchen.item_types.push_back(df::item_type::SEEDS);
d->itemSubtypes.push_back(organicSubtype); ui->kitchen.item_subtypes.push_back(organicSubtype);
d->materialTypes.push_back(type->material_type_seed); ui->kitchen.mat_types.push_back(type->material_defs.type_seed);
d->materialIndices.push_back(materialIndex); ui->kitchen.mat_indices.push_back(materialIndex);
d->exclusionTypes.push_back(cookingExclusion); ui->kitchen.exc_types.push_back(cookingExclusion);
} }
if(!PlantAlreadyIn) if(!PlantAlreadyIn)
{ {
d->itemTypes.push_back(df::item_type::PLANT); ui->kitchen.item_types.push_back(df::item_type::PLANT);
d->itemSubtypes.push_back(organicSubtype); ui->kitchen.item_subtypes.push_back(organicSubtype);
d->materialTypes.push_back(type->material_type_basic_mat); ui->kitchen.mat_types.push_back(type->material_defs.type_basic_mat);
d->materialIndices.push_back(materialIndex); ui->kitchen.mat_indices.push_back(materialIndex);
d->exclusionTypes.push_back(cookingExclusion); ui->kitchen.exc_types.push_back(cookingExclusion);
} }
}; };
void Exclusions::fillWatchMap(std::map<t_materialIndex, unsigned int>& watchMap) const void Kitchen::fillWatchMap(std::map<t_materialIndex, unsigned int>& watchMap)
{ {
watchMap.clear(); watchMap.clear();
for(std::size_t i = 0; i < size(); ++i) for(std::size_t i = 0; i < size(); ++i)
{ {
if(d->itemTypes[i] == limitType && d->itemSubtypes[i] == limitSubtype && d->exclusionTypes[i] == limitExclusion) if(ui->kitchen.item_subtypes[i] == limitType && ui->kitchen.item_subtypes[i] == limitSubtype && ui->kitchen.exc_types[i] == limitExclusion)
{ {
watchMap[d->materialIndices[i]] = (unsigned int) d->materialTypes[i]; watchMap[ui->kitchen.mat_indices[i]] = (unsigned int) ui->kitchen.mat_types[i];
} }
} }
}; };
void Exclusions::removeLimit(t_materialIndex materialIndex) void Kitchen::removeLimit(t_materialIndex materialIndex)
{ {
bool match = false; bool match = false;
do do
{ {
@ -165,10 +131,10 @@ namespace Kitchen
std::size_t matchIndex = 0; std::size_t matchIndex = 0;
for(std::size_t i = 0; i < size(); ++i) for(std::size_t i = 0; i < size(); ++i)
{ {
if(d->itemTypes[i] == limitType if(ui->kitchen.item_types[i] == limitType
&& d->itemSubtypes[i] == limitSubtype && ui->kitchen.item_subtypes[i] == limitSubtype
&& d->materialIndices[i] == materialIndex && ui->kitchen.mat_indices[i] == materialIndex
&& d->exclusionTypes[i] == limitExclusion) && ui->kitchen.exc_types[i] == limitExclusion)
{ {
match = true; match = true;
matchIndex = i; matchIndex = i;
@ -176,31 +142,31 @@ namespace Kitchen
} }
if(match) if(match)
{ {
d->itemTypes.erase(d->itemTypes.begin() + matchIndex); ui->kitchen.item_types.erase(ui->kitchen.item_types.begin() + matchIndex);
d->itemSubtypes.erase(d->itemSubtypes.begin() + matchIndex); ui->kitchen.item_subtypes.erase(ui->kitchen.item_subtypes.begin() + matchIndex);
d->materialTypes.erase(d->materialTypes.begin() + matchIndex); ui->kitchen.mat_types.erase(ui->kitchen.mat_types.begin() + matchIndex);
d->materialIndices.erase(d->materialIndices.begin() + matchIndex); ui->kitchen.mat_indices.erase(ui->kitchen.mat_indices.begin() + matchIndex);
d->exclusionTypes.erase(d->exclusionTypes.begin() + matchIndex); ui->kitchen.exc_types.erase(ui->kitchen.exc_types.begin() + matchIndex);
} }
} while(match); } while(match);
}; };
void Exclusions::setLimit(t_materialIndex materialIndex, unsigned int limit) void Kitchen::setLimit(t_materialIndex materialIndex, unsigned int limit)
{ {
removeLimit(materialIndex); removeLimit(materialIndex);
if(limit > seedLimit) if(limit > seedLimit)
{ {
limit = seedLimit; limit = seedLimit;
} }
d->itemTypes.push_back(limitType); ui->kitchen.item_types.push_back(limitType);
d->itemSubtypes.push_back(limitSubtype); ui->kitchen.item_subtypes.push_back(limitSubtype);
d->materialIndices.push_back(materialIndex); ui->kitchen.mat_indices.push_back(materialIndex);
d->materialTypes.push_back((t_materialType) (limit < seedLimit) ? limit : seedLimit); ui->kitchen.mat_types.push_back((t_materialType) (limit < seedLimit) ? limit : seedLimit);
d->exclusionTypes.push_back(limitExclusion); ui->kitchen.exc_types.push_back(limitExclusion);
}; };
void Exclusions::clearLimits() void Kitchen::clearLimits()
{ {
bool match = false; bool match = false;
do do
{ {
@ -208,9 +174,9 @@ namespace Kitchen
std::size_t matchIndex; std::size_t matchIndex;
for(std::size_t i = 0; i < size(); ++i) for(std::size_t i = 0; i < size(); ++i)
{ {
if(d->itemTypes[i] == limitType if(ui->kitchen.item_types[i] == limitType
&& d->itemSubtypes[i] == limitSubtype && ui->kitchen.item_subtypes[i] == limitSubtype
&& d->exclusionTypes[i] == limitExclusion) && ui->kitchen.exc_types[i] == limitExclusion)
{ {
match = true; match = true;
matchIndex = i; matchIndex = i;
@ -218,17 +184,16 @@ namespace Kitchen
} }
if(match) if(match)
{ {
d->itemTypes.erase(d->itemTypes.begin() + matchIndex); ui->kitchen.item_types.erase(ui->kitchen.item_types.begin() + matchIndex);
d->itemSubtypes.erase(d->itemSubtypes.begin() + matchIndex); ui->kitchen.item_subtypes.erase(ui->kitchen.item_subtypes.begin() + matchIndex);
d->materialIndices.erase(d->materialIndices.begin() + matchIndex); ui->kitchen.mat_indices.erase(ui->kitchen.mat_indices.begin() + matchIndex);
d->materialTypes.erase(d->materialTypes.begin() + matchIndex); ui->kitchen.mat_types.erase(ui->kitchen.mat_types.begin() + matchIndex);
d->exclusionTypes.erase(d->exclusionTypes.begin() + matchIndex); ui->kitchen.exc_types.erase(ui->kitchen.exc_types.begin() + matchIndex);
} }
} while(match); } while(match);
}; };
size_t Exclusions::size() const
{ size_t Kitchen::size()
return d->itemTypes.size(); {
}; return ui->kitchen.item_types.size();
}
}; };

@ -8,15 +8,14 @@
#include "Core.h" #include "Core.h"
#include "Export.h" #include "Export.h"
#include "PluginManager.h" #include "PluginManager.h"
#include "modules/Materials.h"
#include "modules/Items.h" #include "modules/Items.h"
#include "modules/World.h" #include "modules/World.h"
#include "modules/kitchen.h" #include "modules/kitchen.h"
#include "VersionInfo.h" #include "VersionInfo.h"
#include "df/item_flags.h" #include "df/item_flags.h"
using DFHack::t_materialType; using namespace DFHack;
using DFHack::t_materialIndex; using namespace DFHack::Simple;
const int buffer = 20; // seed number buffer - 20 is reasonable const int buffer = 20; // seed number buffer - 20 is reasonable
bool running = false; // whether seedwatch is counting the seeds or not bool running = false; // whether seedwatch is counting the seeds or not
@ -39,7 +38,7 @@ bool ignoreSeeds(df::item_flags& f) // seeds with the following flags should not
f.bits.in_job; f.bits.in_job;
}; };
void printHelp(DFHack::Core& core) // prints help void printHelp(Core& core) // prints help
{ {
core.con.print( core.con.print(
"Watches the numbers of seeds available and enables/disables seed and plant cooking.\n" "Watches the numbers of seeds available and enables/disables seed and plant cooking.\n"
@ -93,17 +92,17 @@ std::string searchAbbreviations(std::string in)
} }
}; };
DFhackCExport DFHack::command_result df_seedwatch(DFHack::Core* pCore, std::vector<std::string>& parameters) DFhackCExport command_result df_seedwatch(Core* pCore, std::vector<std::string>& parameters)
{ {
DFHack::Core& core = *pCore; Core& core = *pCore;
if(!core.isValid()) if(!core.isValid())
{ {
return DFHack::CR_FAILURE; return CR_FAILURE;
} }
core.Suspend(); core.Suspend();
DFHack::Materials& materialsModule = *core.getMaterials(); Materials& materialsModule = *core.getMaterials();
std::vector<DFHack::t_matgloss> organics; std::vector<t_matgloss> organics;
materialsModule.CopyOrganicMaterials(organics); materialsModule.CopyOrganicMaterials(organics);
std::map<std::string, t_materialIndex> materialsReverser; std::map<std::string, t_materialIndex> materialsReverser;
@ -112,17 +111,17 @@ DFhackCExport DFHack::command_result df_seedwatch(DFHack::Core* pCore, std::vect
materialsReverser[organics[i].id] = i; materialsReverser[organics[i].id] = i;
} }
DFHack::World *w = core.getWorld(); World *w = core.getWorld();
DFHack::t_gamemodes gm; t_gamemodes gm;
w->ReadGameMode(gm);// FIXME: check return value w->ReadGameMode(gm);// FIXME: check return value
// if game mode isn't fortress mode // if game mode isn't fortress mode
if(gm.g_mode != DFHack::GAMEMODE_DWARF || gm.g_type != DFHack::GAMETYPE_DWARF_MAIN) if(gm.g_mode != GAMEMODE_DWARF || gm.g_type != GAMETYPE_DWARF_MAIN)
{ {
// just print the help // just print the help
printHelp(core); printHelp(core);
core.Resume(); core.Resume();
return DFHack::CR_OK; return CR_OK;
} }
std::string par; std::string par;
@ -148,8 +147,7 @@ DFhackCExport DFHack::command_result df_seedwatch(DFHack::Core* pCore, std::vect
} }
else if(par == "clear") else if(par == "clear")
{ {
DFHack::Kitchen::Exclusions kitchenExclusions(core); Kitchen::clearLimits();
kitchenExclusions.clearLimits();
core.con.print("seedwatch watchlist cleared\n"); core.con.print("seedwatch watchlist cleared\n");
} }
else if(par == "info") else if(par == "info")
@ -163,9 +161,8 @@ DFhackCExport DFHack::command_result df_seedwatch(DFHack::Core* pCore, std::vect
{ {
core.con.print("seedwatch is not supervising. Use 'seedwatch start' to start supervision.\n"); core.con.print("seedwatch is not supervising. Use 'seedwatch start' to start supervision.\n");
} }
DFHack::Kitchen::Exclusions kitchenExclusions(core);
std::map<t_materialIndex, unsigned int> watchMap; std::map<t_materialIndex, unsigned int> watchMap;
kitchenExclusions.fillWatchMap(watchMap); Kitchen::fillWatchMap(watchMap);
if(watchMap.empty()) if(watchMap.empty())
{ {
core.con.print("The watch list is empty.\n"); core.con.print("The watch list is empty.\n");
@ -181,10 +178,9 @@ DFhackCExport DFHack::command_result df_seedwatch(DFHack::Core* pCore, std::vect
} }
else if(par == "debug") else if(par == "debug")
{ {
DFHack::Kitchen::Exclusions kitchenExclusions(core);
std::map<t_materialIndex, unsigned int> watchMap; std::map<t_materialIndex, unsigned int> watchMap;
kitchenExclusions.fillWatchMap(watchMap); Kitchen::fillWatchMap(watchMap);
kitchenExclusions.debug_print(); Kitchen::debug_print(core);
} }
/* /*
else if(par == "dumpmaps") else if(par == "dumpmaps")
@ -209,8 +205,7 @@ DFhackCExport DFHack::command_result df_seedwatch(DFHack::Core* pCore, std::vect
std::string token = searchAbbreviations(par); std::string token = searchAbbreviations(par);
if(materialsReverser.count(token) > 0) if(materialsReverser.count(token) > 0)
{ {
DFHack::Kitchen::Exclusions kitchenExclusions(core); Kitchen::removeLimit(materialsReverser[token]);
kitchenExclusions.removeLimit(materialsReverser[token]);
core.con.print("%s is not being watched\n", token.c_str()); core.con.print("%s is not being watched\n", token.c_str());
} }
else else
@ -226,8 +221,7 @@ DFhackCExport DFHack::command_result df_seedwatch(DFHack::Core* pCore, std::vect
{ {
for(std::map<std::string, std::string>::const_iterator i = abbreviations.begin(); i != abbreviations.end(); ++i) for(std::map<std::string, std::string>::const_iterator i = abbreviations.begin(); i != abbreviations.end(); ++i)
{ {
DFHack::Kitchen::Exclusions kitchenExclusions(core); if(materialsReverser.count(i->second) > 0) Kitchen::setLimit(materialsReverser[i->second], limit);
if(materialsReverser.count(i->second) > 0) kitchenExclusions.setLimit(materialsReverser[i->second], limit);
} }
} }
else else
@ -235,8 +229,7 @@ DFhackCExport DFHack::command_result df_seedwatch(DFHack::Core* pCore, std::vect
std::string token = searchAbbreviations(parameters[0]); std::string token = searchAbbreviations(parameters[0]);
if(materialsReverser.count(token) > 0) if(materialsReverser.count(token) > 0)
{ {
DFHack::Kitchen::Exclusions kitchenExclusions(core); Kitchen::setLimit(materialsReverser[token], limit);
kitchenExclusions.setLimit(materialsReverser[token], limit);
core.con.print("%s is being watched.\n", token.c_str()); core.con.print("%s is being watched.\n", token.c_str());
} }
else else
@ -251,7 +244,7 @@ DFhackCExport DFHack::command_result df_seedwatch(DFHack::Core* pCore, std::vect
} }
core.Resume(); core.Resume();
return DFHack::CR_OK; return CR_OK;
} }
DFhackCExport const char* plugin_name(void) DFhackCExport const char* plugin_name(void)
@ -259,10 +252,10 @@ DFhackCExport const char* plugin_name(void)
return "seedwatch"; return "seedwatch";
} }
DFhackCExport DFHack::command_result plugin_init(DFHack::Core* pCore, std::vector<DFHack::PluginCommand>& commands) DFhackCExport command_result plugin_init(Core* pCore, std::vector<PluginCommand>& commands)
{ {
commands.clear(); commands.clear();
commands.push_back(DFHack::PluginCommand("seedwatch", "Switches cookery based on quantity of seeds, to keep reserves", df_seedwatch)); commands.push_back(PluginCommand("seedwatch", "Switches cookery based on quantity of seeds, to keep reserves", df_seedwatch));
// fill in the abbreviations map, with abbreviations for the standard plants // fill in the abbreviations map, with abbreviations for the standard plants
abbreviations["bs"] = "SLIVER_BARB"; abbreviations["bs"] = "SLIVER_BARB";
abbreviations["bt"] = "TUBER_BLOATED"; abbreviations["bt"] = "TUBER_BLOATED";
@ -285,14 +278,14 @@ DFhackCExport DFHack::command_result plugin_init(DFHack::Core* pCore, std::vecto
abbreviations["vh"] = "HERB_VALLEY"; abbreviations["vh"] = "HERB_VALLEY";
abbreviations["ws"] = "BERRIES_STRAW_WILD"; abbreviations["ws"] = "BERRIES_STRAW_WILD";
abbreviations["wv"] = "VINE_WHIP"; abbreviations["wv"] = "VINE_WHIP";
return DFHack::CR_OK; return CR_OK;
} }
DFhackCExport DFHack::command_result plugin_onstatechange(DFHack::Core* pCore, DFHack::state_change_event event) DFhackCExport command_result plugin_onstatechange(Core* pCore, state_change_event event)
{ {
switch (event) { switch (event) {
case DFHack::SC_GAME_LOADED: case SC_GAME_LOADED:
case DFHack::SC_GAME_UNLOADED: case SC_GAME_UNLOADED:
if (running) if (running)
pCore->con.printerr("seedwatch deactivated due to game load/unload\n"); pCore->con.printerr("seedwatch deactivated due to game load/unload\n");
running = false; running = false;
@ -301,34 +294,34 @@ DFhackCExport DFHack::command_result plugin_onstatechange(DFHack::Core* pCore, D
break; break;
} }
return DFHack::CR_OK; return CR_OK;
} }
DFhackCExport DFHack::command_result plugin_onupdate(DFHack::Core* pCore) DFhackCExport command_result plugin_onupdate(Core* pCore)
{ {
if (running) if (running)
{ {
// reduce processing rate // reduce processing rate
static int counter = 0; static int counter = 0;
if (++counter < 500) if (++counter < 500)
return DFHack::CR_OK; return CR_OK;
counter = 0; counter = 0;
DFHack::Core& core = *pCore; Core& core = *pCore;
DFHack::World *w = core.getWorld(); World *w = core.getWorld();
DFHack::t_gamemodes gm; t_gamemodes gm;
w->ReadGameMode(gm);// FIXME: check return value w->ReadGameMode(gm);// FIXME: check return value
// if game mode isn't fortress mode // if game mode isn't fortress mode
if(gm.g_mode != DFHack::GAMEMODE_DWARF || gm.g_type != DFHack::GAMETYPE_DWARF_MAIN) if(gm.g_mode != GAMEMODE_DWARF || gm.g_type != GAMETYPE_DWARF_MAIN)
{ {
// stop running. // stop running.
running = false; running = false;
core.con.printerr("seedwatch deactivated due to game mode switch\n"); core.con.printerr("seedwatch deactivated due to game mode switch\n");
return DFHack::CR_OK; return CR_OK;
} }
// this is dwarf mode, continue // this is dwarf mode, continue
std::map<t_materialIndex, unsigned int> seedCount; // the number of seeds std::map<t_materialIndex, unsigned int> seedCount; // the number of seeds
DFHack::Items& itemsModule = *core.getItems(); Items& itemsModule = *core.getItems();
itemsModule.Start(); itemsModule.Start();
std::vector<df::item*> items; std::vector<df::item*> items;
itemsModule.readItemVector(items); itemsModule.readItemVector(items);
@ -349,25 +342,24 @@ DFhackCExport DFHack::command_result plugin_onupdate(DFHack::Core* pCore)
} }
itemsModule.Finish(); itemsModule.Finish();
DFHack::Kitchen::Exclusions kitchenExclusions(core);
std::map<t_materialIndex, unsigned int> watchMap; std::map<t_materialIndex, unsigned int> watchMap;
kitchenExclusions.fillWatchMap(watchMap); Kitchen::fillWatchMap(watchMap);
for(auto i = watchMap.begin(); i != watchMap.end(); ++i) for(auto i = watchMap.begin(); i != watchMap.end(); ++i)
{ {
if(seedCount[i->first] <= i->second) if(seedCount[i->first] <= i->second)
{ {
kitchenExclusions.denyPlantSeedCookery(i->first); Kitchen::denyPlantSeedCookery(i->first);
} }
else if(i->second + buffer < seedCount[i->first]) else if(i->second + buffer < seedCount[i->first])
{ {
kitchenExclusions.allowPlantSeedCookery(i->first); Kitchen::allowPlantSeedCookery(i->first);
} }
} }
} }
return DFHack::CR_OK; return CR_OK;
} }
DFhackCExport DFHack::command_result plugin_shutdown(DFHack::Core* pCore) DFhackCExport command_result plugin_shutdown(Core* pCore)
{ {
return DFHack::CR_OK; return CR_OK;
} }