Make seedwatch work on linux, still with ugly hacks.

develop
Petr Mrázek 2011-10-27 03:31:13 +02:00
parent 8838d8c3d6
commit 61be3413e3
2 changed files with 451 additions and 390 deletions

@ -107,7 +107,12 @@ struct t_itemref : public t_virtual
struct df_contaminant struct df_contaminant
{ {
// fixme: figure it out int16_t material;
int32_t mat_index;
int16_t mat_state; // FIXME: enum or document in text
int16_t temperature;
int16_t temperature_fraction; // maybe...
int32_t size; ///< 1-24=spatter, 25-49=smear, 50-* = coating
}; };
/** /**
@ -146,6 +151,10 @@ public:
int32_t mystery5; int32_t mystery5;
// 5C L, 64 W - pointer to vector of contaminants // 5C L, 64 W - pointer to vector of contaminants
std::vector <df_contaminant *> * contaminants; std::vector <df_contaminant *> * contaminants;
// 60 L, 6C W - temperature in Urists
int16_t temperature;
// 62 L, 6E W - temperature fraction (maybe, just a guess)
int16_t temperature_fraction;
public: public:
// 0x0 // 0x0
virtual int32_t getType(); virtual int32_t getType();

@ -13,15 +13,13 @@
#include "dfhack/modules/Materials.h" #include "dfhack/modules/Materials.h"
typedef int32_t t_materialIndex; typedef int32_t t_materialIndex;
typedef int16_t t_materialSubindex, t_itemType, t_itemSubtype; typedef int16_t t_material, t_itemType, t_itemSubtype;
typedef int8_t t_exclusionType; typedef int8_t t_exclusionType;
const unsigned int seedLimit = 400; // a limit on the limits which can be placed on seeds const unsigned int seedLimit = 400; // a limit on the limits which can be placed on seeds
const t_itemType seedType = 52; // from df.magmawiki.com/index.php/Item_token
const t_itemType plantType = 53; // from df.magmawiki.com/index.php/Item_token
const t_itemSubtype organicSubtype = -1; // seems to fixed const t_itemSubtype organicSubtype = -1; // seems to fixed
const t_exclusionType cookingExclusion = 1; // seems to be fixed const t_exclusionType cookingExclusion = 1; // seems to be fixed
const t_itemType limitType = 0; // used to store limit as an entry in the exclusion list const t_itemType limitType = 0; // used to store limit as an entry in the exclusion list. 0 = BAR
const t_itemSubtype limitSubtype = 0; // used to store limit as an entry in the exclusion list const t_itemSubtype limitSubtype = 0; // 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 const t_exclusionType limitExclusion = 4; // used to store limit as an entry in the exclusion list
const int buffer = 20; // seed number buffer - 20 is reasonable const int buffer = 20; // seed number buffer - 20 is reasonable
@ -31,428 +29,482 @@ std::map<std::string, std::string> abbreviations; // abbreviations for the stand
bool ignoreSeeds(DFHack::t_itemflags& f) // seeds with the following flags should not be counted bool ignoreSeeds(DFHack::t_itemflags& f) // seeds with the following flags should not be counted
{ {
return return
f.dump || f.dump ||
f.forbid || f.forbid ||
f.garbage_colect || f.garbage_colect ||
f.hidden || f.hidden ||
f.hostile || f.hostile ||
f.on_fire || f.on_fire ||
f.rotten || f.rotten ||
f.trader || f.trader ||
f.in_building || f.in_building ||
f.in_job; f.in_job;
}; };
void updateCountAndSubindices(DFHack::Core& core, std::map<t_materialIndex, unsigned int>& seedCount, std::map<t_materialIndex, t_materialSubindex>& seedSubindices, std::map<t_materialIndex, t_materialSubindex>& plantSubindices) // fills seedCount, seedSubindices and plantSubindices void updateCountAndSubindices(DFHack::Core& core, std::map<t_materialIndex, unsigned int>& seedCount, std::map<t_materialIndex, t_material>& seedSubindices, std::map<t_materialIndex, t_material>& plantSubindices) // fills seedCount, seedSubindices and plantSubindices
{ {
DFHack::Items& itemsModule = *core.getItems(); DFHack::Items& itemsModule = *core.getItems();
itemsModule.Start(); itemsModule.Start();
std::vector<DFHack::t_item*> items; std::vector<DFHack::df_item*> items;
itemsModule.readItemVector(items); itemsModule.readItemVector(items);
DFHack::dfh_item item; DFHack::df_item * item;
std::size_t size = items.size(); std::size_t size = items.size();
for(std::size_t i = 0; i < size; ++i) for(std::size_t i = 0; i < size; ++i)
{ {
itemsModule.readItem(items[i], item); item = items[i];
t_materialIndex materialIndex = item.matdesc.index; t_materialIndex materialIndex = item->getMaterialIndex();
switch(item.matdesc.itemType) switch(item->getType())
{ {
case seedType: case DFHack::Items::SEEDS:
seedSubindices[materialIndex] = item.matdesc.subIndex; seedSubindices[materialIndex] = item->getMaterial();
if(!ignoreSeeds(item.base->flags)) ++seedCount[materialIndex]; if(!ignoreSeeds(item->flags)) ++seedCount[materialIndex];
break; break;
case plantType: case DFHack::Items::PLANT:
plantSubindices[materialIndex] = item.matdesc.subIndex; plantSubindices[materialIndex] = item->getMaterial();
break; break;
} }
} }
itemsModule.Finish(); itemsModule.Finish();
}; };
void printHelp(DFHack::Core& core) // prints help void printHelp(DFHack::Core& core) // prints help
{ {
core.con.print("\ne.g. #seedwatch MUSHROOM_HELMET_PLUMP 30\n"); core.con.print(
core.con.print("This is how to add an item to the watch list.\n"); "\ne.g. #seedwatch MUSHROOM_HELMET_PLUMP 30\n"
core.con.print("MUSHROOM_HELMET_PLUMP is the plant token for plump helmets (found in raws)\n"); "This is how to add an item to the watch list.\n"
core.con.print("The number of available plump helmet seeds is counted each tick\n"); "MUSHROOM_HELMET_PLUMP is the plant token for plump helmets (found in raws)\n"
core.con.print("If it falls below 30, plump helmets and plump helmet seeds will be excluded from cookery.\n"); "The number of available plump helmet seeds is counted each tick\n"
core.con.print("%i is the buffer, therefore if the number rises above 30 + %i, then cooking will be allowed.\n", buffer, buffer); "If it falls below 30, plump helmets and plump helmet seeds will be excluded from cookery.\n"
if(!abbreviations.empty()) "%i is the buffer, therefore if the number rises above 30 + %i, then cooking will be allowed.\n", buffer, buffer);
{ if(!abbreviations.empty())
core.con.print("You can use these abbreviations for the plant tokens:\n"); {
for(std::map<std::string, std::string>::const_iterator i = abbreviations.begin(); i != abbreviations.end(); ++i) core.con.print("You can use these abbreviations for the plant tokens:\n");
{ for(std::map<std::string, std::string>::const_iterator i = abbreviations.begin(); i != abbreviations.end(); ++i)
core.con.print("%s -> %s\n", i->first.c_str(), i->second.c_str()); {
} core.con.print("%s -> %s\n", i->first.c_str(), i->second.c_str());
} }
core.con.print("e.g. #seedwatch ph 30\nis the same as #seedwatch MUSHROOM_HELMET_PLUMP 30\n\n"); }
core.con.print("e.g. #seedwatch all 30\nAdds all which are in the abbreviation list to the watch list, the limit being 30.\n\n"); core.con.print(
core.con.print("e.g. #seedwatch MUSHROOM_HELMET_PLUMP\nRemoves MUSHROOM_HELMET_PLUMP from the watch list.\n\n"); "e.g. #seedwatch ph 30\nis the same as #seedwatch MUSHROOM_HELMET_PLUMP 30\n\n"
core.con.print("#seedwatch all\nClears the watch list.\n\n"); "e.g. #seedwatch all 30\nAdds all which are in the abbreviation list to the watch list, the limit being 30.\n\n"
core.con.print("#seedwatch start\nStart seedwatch watch.\n\n"); "e.g. #seedwatch MUSHROOM_HELMET_PLUMP\nRemoves MUSHROOM_HELMET_PLUMP from the watch list.\n\n"
core.con.print("#seedwatch stop\nStop seedwatch watch.\n\n"); "#seedwatch all\nClears the watch list.\n\n"
core.con.print("#seedwatch info\nDisplay whether seedwatch is watching, and the watch list.\n\n"); "#seedwatch start\nStart seedwatch watch.\n\n"
core.con.print("#seedwatch clear\nClears the watch list.\n"); "#seedwatch stop\nStop seedwatch watch.\n\n"
"#seedwatch info\nDisplay whether seedwatch is watching, and the watch list.\n\n"
"#seedwatch clear\nClears the watch list.\n"
);
}; };
std::string searchAbbreviations(std::string in) // searches abbreviations, returns expansion if so, returns original if not
// searches abbreviations, returns expansion if so, returns original if not
std::string searchAbbreviations(std::string in)
{ {
if(abbreviations.count(in) > 0) return abbreviations[in]; if(abbreviations.count(in) > 0)
return in; {
return abbreviations[in];
}
else
{
return in;
}
}; };
class t_kitchenExclusions // helps to organise access to the cooking exclusions // helps to organise access to the cooking exclusions
class t_kitchenExclusions
{ {
public: public:
t_kitchenExclusions(DFHack::Core& core_) // constructor t_kitchenExclusions(DFHack::Core& core_) // constructor
: core(core_) : core(core_)
, itemTypes (*((std::vector<t_itemType >*)(start(core_) ))) // using the kludge in start , itemTypes (*((std::vector<t_itemType >*)(addr(core_,0))))
, itemSubtypes (*((std::vector<t_itemSubtype >*)(start(core_) + 0x10))) // further kludge offset , itemSubtypes (*((std::vector<t_itemSubtype >*)(addr(core_,1))))
, materialSubindices(*((std::vector<t_materialSubindex>*)(start(core_) + 0x20))) // further kludge offset , materials (*((std::vector<t_material >*)(addr(core_,2))))
, materialIndices (*((std::vector<t_materialIndex >*)(start(core_) + 0x30))) // further kludge offset , materialIndices (*((std::vector<t_materialIndex>*)(addr(core_,3))))
, exclusionTypes (*((std::vector<t_exclusionType >*)(start(core_) + 0x40))) // further kludge offset , exclusionTypes (*((std::vector<t_exclusionType>*)(addr(core_,4))))
{ {
}; };
void print() // print the exclusion list, with the material index also translated into its token (for organics) - for debug really void print() // print the exclusion list, with the material index also translated into its token (for organics) - for debug really
{ {
core.con.print("Kitchen Exclusions\n"); core.con.print("Kitchen Exclusions\n");
DFHack::Materials& materialsModule= *core.getMaterials(); DFHack::Materials& materialsModule= *core.getMaterials();
materialsModule.ReadOrganicMaterials(); materialsModule.ReadOrganicMaterials();
for(std::size_t i = 0; i < size(); ++i) for(std::size_t i = 0; i < size(); ++i)
{ {
core.con.print("%2u: IT:%2i IS:%i MI:%2i MS:%3i ET:%i %s\n", i, itemTypes[i], itemSubtypes[i], materialIndices[i], materialSubindices[i], exclusionTypes[i], materialsModule.organic[materialIndices[i]].id.c_str()); core.con.print("%2u: IT:%2i IS:%i MI:%2i MS:%3i ET:%i %s\n", i, itemTypes[i], itemSubtypes[i], materialIndices[i], materials[i], exclusionTypes[i], materialsModule.organic[materialIndices[i]].id.c_str());
} }
core.con.print("\n"); core.con.print("\n");
}; };
void allowCookery(t_materialIndex materialIndex) // remove this material from the exclusion list if it is in it void allowCookery(t_materialIndex materialIndex) // remove this material from the exclusion list if it is in it
{ {
bool match = false; bool match = false;
do do
{ {
match = false; match = false;
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(materialIndices[i] == materialIndex && (itemTypes[i] == seedType || itemTypes[i] == plantType) && exclusionTypes[i] == cookingExclusion) if(materialIndices[i] == materialIndex
{ && (itemTypes[i] == DFHack::Items::SEEDS || itemTypes[i] == DFHack::Items::PLANT)
match = true; && exclusionTypes[i] == cookingExclusion
matchIndex = i; )
} {
} match = true;
if(match) matchIndex = i;
{ }
itemTypes.erase(itemTypes.begin() + matchIndex); }
itemSubtypes.erase(itemSubtypes.begin() + matchIndex); if(match)
materialIndices.erase(materialIndices.begin() + matchIndex); {
materialSubindices.erase(materialSubindices.begin() + matchIndex); itemTypes.erase(itemTypes.begin() + matchIndex);
exclusionTypes.erase(exclusionTypes.begin() + matchIndex); itemSubtypes.erase(itemSubtypes.begin() + matchIndex);
} materialIndices.erase(materialIndices.begin() + matchIndex);
} while(match); materials.erase( materials.begin() + matchIndex);
}; exclusionTypes.erase(exclusionTypes.begin() + matchIndex);
void denyCookery(t_materialIndex materialIndex, std::map<t_materialIndex, t_materialSubindex>& seedSubindices, std::map<t_materialIndex, t_materialSubindex>& plantSubindices) // add this material to the exclusion list, if it is not already in it }
{ } while(match);
if(seedSubindices.count(materialIndex) > 0) };
{
bool alreadyIn = false; // add this material to the exclusion list, if it is not already in it
for(std::size_t i = 0; i < size(); ++i) void denyCookery(t_materialIndex materialIndex, std::map<t_materialIndex, t_material>& seedMaterials, std::map<t_materialIndex, t_material>& plantMaterials)
{ {
if(materialIndices[i] == materialIndex && itemTypes[i] == seedType && exclusionTypes[i] == cookingExclusion) if( seedMaterials.count(materialIndex) > 0)
{ {
alreadyIn = true; bool alreadyIn = false;
} for(std::size_t i = 0; i < size(); ++i)
} {
if(!alreadyIn) if(materialIndices[i] == materialIndex
{ && itemTypes[i] == DFHack::Items::SEEDS
itemTypes.push_back(seedType); && exclusionTypes[i] == cookingExclusion)
itemSubtypes.push_back(organicSubtype); {
materialIndices.push_back(materialIndex); alreadyIn = true;
materialSubindices.push_back(seedSubindices[materialIndex]); }
exclusionTypes.push_back(cookingExclusion); }
} if(!alreadyIn)
} {
if(plantSubindices.count(materialIndex) > 0) itemTypes.push_back(DFHack::Items::SEEDS);
{ itemSubtypes.push_back(organicSubtype);
bool alreadyIn = false; materials.push_back( seedMaterials[materialIndex]);
for(std::size_t i = 0; i < size(); ++i) materialIndices.push_back(materialIndex);
{ exclusionTypes.push_back(cookingExclusion);
if(materialIndices[i] == materialIndex && itemTypes[i] == plantType && exclusionTypes[i] == cookingExclusion) }
{ }
alreadyIn = true; if( plantMaterials.count(materialIndex) > 0)
} {
} bool alreadyIn = false;
if(!alreadyIn) for(std::size_t i = 0; i < size(); ++i)
{ {
itemTypes.push_back(plantType); if(materialIndices[i] == materialIndex
itemSubtypes.push_back(organicSubtype); && itemTypes[i] == DFHack::Items::PLANT
materialIndices.push_back(materialIndex); && exclusionTypes[i] == cookingExclusion)
materialSubindices.push_back(plantSubindices[materialIndex]); {
exclusionTypes.push_back(cookingExclusion); alreadyIn = true;
} }
} }
}; if(!alreadyIn)
void fillWatchMap(std::map<t_materialIndex, unsigned int>& watchMap) // fills a map with info from the limit info storage entries in the exclusion list {
{ itemTypes.push_back(DFHack::Items::PLANT);
watchMap.clear(); itemSubtypes.push_back(organicSubtype);
for(std::size_t i = 0; i < size(); ++i) materials.push_back(plantMaterials[materialIndex]);
{ materialIndices.push_back(materialIndex);
if(itemTypes[i] == limitType && itemSubtypes[i] == limitSubtype && exclusionTypes[i] == limitExclusion) exclusionTypes.push_back(cookingExclusion);
{ }
watchMap[materialIndices[i]] = (unsigned int) materialSubindices[i]; }
} };
}
}; // fills a map with info from the limit info storage entries in the exclusion list
void removeLimit(t_materialIndex materialIndex) // removes a limit info storage entry from the exclusion list if it is in it void fillWatchMap(std::map<t_materialIndex, unsigned int>& watchMap)
{ {
bool match = false; watchMap.clear();
do for(std::size_t i = 0; i < size(); ++i)
{ {
match = false; if(itemTypes[i] == limitType && itemSubtypes[i] == limitSubtype && exclusionTypes[i] == limitExclusion)
std::size_t matchIndex = 0; {
for(std::size_t i = 0; i < size(); ++i) watchMap[materialIndices[i]] = (unsigned int) materials[i];
{ }
if(itemTypes[i] == limitType && itemSubtypes[i] == limitSubtype && materialIndices[i] == materialIndex && exclusionTypes[i] == limitExclusion) }
{ };
match = true;
matchIndex = i; // removes a limit info storage entry from the exclusion list if it is in it
} void removeLimit(t_materialIndex materialIndex)
} {
if(match) bool match = false;
{ do
itemTypes.erase(itemTypes.begin() + matchIndex); {
itemSubtypes.erase(itemSubtypes.begin() + matchIndex); match = false;
materialIndices.erase(materialIndices.begin() + matchIndex); std::size_t matchIndex = 0;
materialSubindices.erase(materialSubindices.begin() + matchIndex); for(std::size_t i = 0; i < size(); ++i)
exclusionTypes.erase(exclusionTypes.begin() + matchIndex); {
} if(itemTypes[i] == limitType
} while(match); && itemSubtypes[i] == limitSubtype
}; && materialIndices[i] == materialIndex
void setLimit(t_materialIndex materialIndex, unsigned int limit) // add a limit info storage item to the exclusion list, or alters an existing one && exclusionTypes[i] == limitExclusion)
{ {
removeLimit(materialIndex); match = true;
if(limit > seedLimit) limit = seedLimit; matchIndex = i;
}
}
if(match)
{
itemTypes.erase(itemTypes.begin() + matchIndex);
itemSubtypes.erase(itemSubtypes.begin() + matchIndex);
materials.erase(materials.begin() + matchIndex);
materialIndices.erase(materialIndices.begin() + matchIndex);
exclusionTypes.erase(exclusionTypes.begin() + matchIndex);
}
} while(match);
};
// add a limit info storage item to the exclusion list, or alters an existing one
void setLimit(t_materialIndex materialIndex, unsigned int limit)
{
removeLimit(materialIndex);
if(limit > seedLimit) limit = seedLimit;
itemTypes.push_back(limitType); itemTypes.push_back(limitType);
itemSubtypes.push_back(limitSubtype); itemSubtypes.push_back(limitSubtype);
materialIndices.push_back(materialIndex); materialIndices.push_back(materialIndex);
materialSubindices.push_back((t_materialSubindex) (limit < seedLimit) ? limit : seedLimit); materials.push_back((t_material) (limit < seedLimit) ? limit : seedLimit);
exclusionTypes.push_back(limitExclusion); exclusionTypes.push_back(limitExclusion);
}; };
void clearLimits() // clears all limit info storage items from the exclusion list void clearLimits() // clears all limit info storage items from the exclusion list
{ {
bool match = false; bool match = false;
do do
{ {
match = false; match = false;
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(itemTypes[i] == limitType && itemSubtypes[i] == limitSubtype && exclusionTypes[i] == limitExclusion) if(itemTypes[i] == limitType
{ && itemSubtypes[i] == limitSubtype
match = true; && exclusionTypes[i] == limitExclusion)
matchIndex = i; {
} match = true;
} matchIndex = i;
if(match) }
{ }
itemTypes.erase(itemTypes.begin() + matchIndex); if(match)
itemSubtypes.erase(itemSubtypes.begin() + matchIndex); {
materialIndices.erase(materialIndices.begin() + matchIndex); itemTypes.erase(itemTypes.begin() + matchIndex);
materialSubindices.erase(materialSubindices.begin() + matchIndex); itemSubtypes.erase(itemSubtypes.begin() + matchIndex);
exclusionTypes.erase(exclusionTypes.begin() + matchIndex); materialIndices.erase(materialIndices.begin() + matchIndex);
} materials.erase( materials.begin() + matchIndex);
} while(match); exclusionTypes.erase(exclusionTypes.begin() + matchIndex);
}; }
} while(match);
};
private: private:
DFHack::Core& core; DFHack::Core& core;
std::vector<t_itemType>& itemTypes; // the item types vector of the kitchen exclusion list 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_itemSubtype>& itemSubtypes; // the item subtype vector of the kitchen exclusion list
std::vector<t_materialSubindex>& materialSubindices; // the material subindex vector of the kitchen exclusion list std::vector<t_material>& materials; // 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_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 std::vector<t_exclusionType>& exclusionTypes; // the exclusion type vector of the kitchen excluions list
std::size_t size() // the size of the exclusions vectors (they are all the same size - if not, there is a problem!) std::size_t size() // the size of the exclusions vectors (they are all the same size - if not, there is a problem!)
{ {
return itemTypes.size(); return itemTypes.size();
}; };
static uint32_t start(const DFHack::Core& core) // the kludge for the exclusion position in memory //FIXME: ugly, ugly hack. Use memory.xml instead.
{ static uint32_t addr(const DFHack::Core& core, int index)
return core.p->getBase() + 0x014F0BB4 - 0x400000; {
}; #ifdef LINUX_BUILD
return 0x93f2b00 + 0xC * index;
#else
return core.p->getBase() + 0x014F0BB4 - 0x400000 + 0x10 * index;
#endif
};
}; };
DFhackCExport DFHack::command_result df_seedwatch(DFHack::Core* pCore, std::vector<std::string>& parameters) DFhackCExport DFHack::command_result df_seedwatch(DFHack::Core* pCore, std::vector<std::string>& parameters)
{ {
DFHack::Core& core = *pCore; DFHack::Core& core = *pCore;
if(!core.isValid()) return DFHack::CR_FAILURE; if(!core.isValid())
core.Suspend(); {
return DFHack::CR_FAILURE;
}
core.Suspend();
DFHack::Materials& materialsModule = *core.getMaterials(); DFHack::Materials& materialsModule = *core.getMaterials();
materialsModule.ReadOrganicMaterials(); materialsModule.ReadOrganicMaterials();
std::vector<DFHack::t_matgloss>& organics = materialsModule.organic; std::vector<DFHack::t_matgloss>& organics = materialsModule.organic;
std::map<std::string, t_materialIndex> materialsReverser; std::map<std::string, t_materialIndex> materialsReverser;
for(std::size_t i = 0; i < organics.size(); ++i) for(std::size_t i = 0; i < organics.size(); ++i)
{ {
materialsReverser[organics[i].id] = i; materialsReverser[organics[i].id] = i;
} }
std::string par; std::string par;
int limit; int limit;
switch(parameters.size()) switch(parameters.size())
{ {
case 0: case 0:
printHelp(core); printHelp(core);
break; break;
case 1: case 1:
par = parameters[0]; par = parameters[0];
if(par == "help") printHelp(core); if(par == "help") printHelp(core);
else if(par == "?") printHelp(core); else if(par == "?") printHelp(core);
else if(par == "start") else if(par == "start")
{ {
running = true; running = true;
core.con.print("seedwatch supervision started.\n"); core.con.print("seedwatch supervision started.\n");
} }
else if(par == "stop") else if(par == "stop")
{ {
running = false; running = false;
core.con.print("seedwatch supervision stopped.\n"); core.con.print("seedwatch supervision stopped.\n");
} }
else if(par == "clear") else if(par == "clear")
{ {
t_kitchenExclusions kitchenExclusions(core); t_kitchenExclusions kitchenExclusions(core);
kitchenExclusions.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")
{ {
core.con.print("seedwatch Info:\n"); core.con.print("seedwatch Info:\n");
if(running) core.con.print("seedwatch is supervising. Use 'seedwatch stop' to stop supervision.\n"); if(running)
else core.con.print("seedwatch is not supervising. Use 'seedwatch start' to start supervision.\n"); {
t_kitchenExclusions kitchenExclusions(core); core.con.print("seedwatch is supervising. Use 'seedwatch stop' to stop supervision.\n");
std::map<t_materialIndex, unsigned int> watchMap; }
kitchenExclusions.fillWatchMap(watchMap); else
if(watchMap.empty()) core.con.print("The watch list is empty.\n"); {
else core.con.print("seedwatch is not supervising. Use 'seedwatch start' to start supervision.\n");
{ }
core.con.print("The watch list is:\n"); t_kitchenExclusions kitchenExclusions(core);
for(std::map<t_materialIndex, unsigned int>::const_iterator i = watchMap.begin(); i != watchMap.end(); ++i) std::map<t_materialIndex, unsigned int> watchMap;
{ kitchenExclusions.fillWatchMap(watchMap);
core.con.print("%s : %u\n", organics[i->first].id.c_str(), i->second); if(watchMap.empty())
} {
} core.con.print("The watch list is empty.\n");
/*kitchenExclusions.print();*/ }
} else
else {
{ core.con.print("The watch list is:\n");
std::string token = searchAbbreviations(par); for(std::map<t_materialIndex, unsigned int>::const_iterator i = watchMap.begin(); i != watchMap.end(); ++i)
if(materialsReverser.count(token) > 0) {
{ core.con.print("%s : %u\n", organics[i->first].id.c_str(), i->second);
t_kitchenExclusions kitchenExclusions(core); }
kitchenExclusions.removeLimit(materialsReverser[token]); }
core.con.print("%s is not being watched\n", token.c_str()); }
} else if(par == "debug")
else {
{ t_kitchenExclusions kitchenExclusions(core);
core.con.print("%s has not been found as a material.\n", token.c_str()); std::map<t_materialIndex, unsigned int> watchMap;
} kitchenExclusions.fillWatchMap(watchMap);
} kitchenExclusions.print();
break; }
case 2: else
limit = atoi(parameters[1].c_str()); {
if(limit < 0) limit = 0; std::string token = searchAbbreviations(par);
if(parameters[0] == "all") if(materialsReverser.count(token) > 0)
{ {
for(std::map<std::string, std::string>::const_iterator i = abbreviations.begin(); i != abbreviations.end(); ++i) t_kitchenExclusions kitchenExclusions(core);
{ kitchenExclusions.removeLimit(materialsReverser[token]);
t_kitchenExclusions kitchenExclusions(core); core.con.print("%s is not being watched\n", token.c_str());
if(materialsReverser.count(i->second) > 0) kitchenExclusions.setLimit(materialsReverser[i->second], limit); }
} else
} {
else core.con.print("%s has not been found as a material.\n", token.c_str());
{ }
std::string token = searchAbbreviations(parameters[0]); }
if(materialsReverser.count(token) > 0) break;
{ case 2:
t_kitchenExclusions kitchenExclusions(core); limit = atoi(parameters[1].c_str());
kitchenExclusions.setLimit(materialsReverser[token], limit); if(limit < 0) limit = 0;
core.con.print("%s is being watched.\n", token.c_str()); if(parameters[0] == "all")
} {
else for(std::map<std::string, std::string>::const_iterator i = abbreviations.begin(); i != abbreviations.end(); ++i)
{ {
core.con.print("%s has not been found as a material.\n", token.c_str()); t_kitchenExclusions kitchenExclusions(core);
} if(materialsReverser.count(i->second) > 0) kitchenExclusions.setLimit(materialsReverser[i->second], limit);
} }
break; }
default: else
printHelp(core); {
break; std::string token = searchAbbreviations(parameters[0]);
} if(materialsReverser.count(token) > 0)
{
t_kitchenExclusions kitchenExclusions(core);
kitchenExclusions.setLimit(materialsReverser[token], limit);
core.con.print("%s is being watched.\n", token.c_str());
}
else
{
core.con.print("%s has not been found as a material.\n", token.c_str());
}
}
break;
default:
printHelp(core);
break;
}
core.Resume(); core.Resume();
return DFHack::CR_OK; return DFHack::CR_OK;
} }
DFhackCExport const char* plugin_name(void) 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 DFHack::command_result plugin_init(DFHack::Core* pCore, std::vector<DFHack::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(DFHack::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";
abbreviations["bw"] = "WEED_BLADE"; abbreviations["bw"] = "WEED_BLADE";
abbreviations["cw"] = "GRASS_WHEAT_CAVE"; abbreviations["cw"] = "GRASS_WHEAT_CAVE";
abbreviations["dc"] = "MUSHROOM_CUP_DIMPLE"; abbreviations["dc"] = "MUSHROOM_CUP_DIMPLE";
abbreviations["fb"] = "BERRIES_FISHER"; abbreviations["fb"] = "BERRIES_FISHER";
abbreviations["hr"] = "ROOT_HIDE"; abbreviations["hr"] = "ROOT_HIDE";
abbreviations["kb"] = "BULB_KOBOLD"; abbreviations["kb"] = "BULB_KOBOLD";
abbreviations["lg"] = "GRASS_LONGLAND"; abbreviations["lg"] = "GRASS_LONGLAND";
abbreviations["mr"] = "ROOT_MUCK"; abbreviations["mr"] = "ROOT_MUCK";
abbreviations["pb"] = "BERRIES_PRICKLE"; abbreviations["pb"] = "BERRIES_PRICKLE";
abbreviations["ph"] = "MUSHROOM_HELMET_PLUMP"; abbreviations["ph"] = "MUSHROOM_HELMET_PLUMP";
abbreviations["pt"] = "GRASS_TAIL_PIG"; abbreviations["pt"] = "GRASS_TAIL_PIG";
abbreviations["qb"] = "BUSH_QUARRY"; abbreviations["qb"] = "BUSH_QUARRY";
abbreviations["rr"] = "REED_ROPE"; abbreviations["rr"] = "REED_ROPE";
abbreviations["rw"] = "WEED_RAT"; abbreviations["rw"] = "WEED_RAT";
abbreviations["sb"] = "BERRY_SUN"; abbreviations["sb"] = "BERRY_SUN";
abbreviations["sp"] = "POD_SWEET"; abbreviations["sp"] = "POD_SWEET";
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 DFHack::CR_OK;
} }
DFhackCExport DFHack::command_result plugin_onupdate(DFHack::Core* pCore) DFhackCExport DFHack::command_result plugin_onupdate(DFHack::Core* pCore)
{ {
if(running) if(running)
{ {
DFHack::Core& core = *pCore; DFHack::Core& core = *pCore;
std::map<t_materialIndex, unsigned int> seedCount; // the number of seeds std::map<t_materialIndex, unsigned int> seedCount; // the number of seeds
std::map<t_materialIndex, t_materialSubindex> seedSubindices; // holds information needed to add entries to the cooking exclusions std::map<t_materialIndex, t_material> seedSubindices; // holds information needed to add entries to the cooking exclusions
std::map<t_materialIndex, t_materialSubindex> plantSubindices; // holds information need to add entries to the cooking exclusions std::map<t_materialIndex, t_material> plantSubindices; // holds information need to add entries to the cooking exclusions
updateCountAndSubindices(core, seedCount, seedSubindices, plantSubindices); updateCountAndSubindices(core, seedCount, seedSubindices, plantSubindices);
t_kitchenExclusions kitchenExclusions(core); t_kitchenExclusions kitchenExclusions(core);
std::map<t_materialIndex, unsigned int> watchMap; std::map<t_materialIndex, unsigned int> watchMap;
kitchenExclusions.fillWatchMap(watchMap); kitchenExclusions.fillWatchMap(watchMap);
for(std::map<t_materialIndex, unsigned int>::const_iterator i = watchMap.begin(); i != watchMap.end(); ++i) for(std::map<t_materialIndex, unsigned int>::const_iterator i = watchMap.begin(); i != watchMap.end(); ++i)
{ {
if(seedCount[i->first] <= i->second) if(seedCount[i->first] <= i->second)
{ {
kitchenExclusions.denyCookery(i->first, seedSubindices, plantSubindices); kitchenExclusions.denyCookery(i->first, seedSubindices, plantSubindices);
} }
else if(i->second + buffer < seedCount[i->first]) else if(i->second + buffer < seedCount[i->first])
{ {
kitchenExclusions.allowCookery(i->first); kitchenExclusions.allowCookery(i->first);
} }
} }
} }
return DFHack::CR_OK; return DFHack::CR_OK;
} }
DFhackCExport DFHack::command_result plugin_shutdown(DFHack::Core* pCore) DFhackCExport DFHack::command_result plugin_shutdown(DFHack::Core* pCore)
{ {
return DFHack::CR_OK; return DFHack::CR_OK;
} }