2011-10-29 20:20:54 -06:00
|
|
|
|
|
|
|
#include "Internal.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
using namespace std;
|
|
|
|
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "VersionInfo.h"
|
|
|
|
#include "MemAccess.h"
|
2012-01-16 20:22:42 -07:00
|
|
|
#include "Types.h"
|
|
|
|
#include "Error.h"
|
2018-05-17 18:09:57 -06:00
|
|
|
#include "modules/Kitchen.h"
|
2011-10-29 20:20:54 -06:00
|
|
|
#include "ModuleFactory.h"
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
2012-01-16 20:22:42 -07:00
|
|
|
using namespace DFHack;
|
|
|
|
|
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "df/world.h"
|
2023-01-05 18:11:01 -07:00
|
|
|
#include "df/plotinfost.h"
|
2012-01-16 19:16:16 -07:00
|
|
|
#include "df/item_type.h"
|
2012-01-16 20:22:42 -07:00
|
|
|
#include "df/plant_raw.h"
|
|
|
|
|
|
|
|
using namespace df::enums;
|
|
|
|
using df::global::world;
|
2023-01-05 18:11:01 -07:00
|
|
|
using df::global::plotinfo;
|
2011-10-29 20:20:54 -06:00
|
|
|
|
2020-06-29 19:35:07 -06:00
|
|
|
// Special values used by "seedwatch" plugin to store seed limits
|
|
|
|
const df::enums::item_type::item_type SEEDLIMIT_ITEMTYPE = df::enums::item_type::BAR;
|
|
|
|
const int16_t SEEDLIMIT_ITEMSUBTYPE = 0;
|
|
|
|
const int16_t SEEDLIMIT_MAX = 400; // Maximum permitted seed limit
|
|
|
|
const df::kitchen_exc_type SEEDLIMIT_EXCTYPE = df::kitchen_exc_type(4);
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
void Kitchen::debug_print(color_ostream &out)
|
2011-10-29 20:20:54 -06:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Kitchen Exclusions\n");
|
2012-01-16 20:22:42 -07:00
|
|
|
for(std::size_t i = 0; i < size(); ++i)
|
|
|
|
{
|
2018-06-11 10:57:06 -06:00
|
|
|
out.print("%2zu: IT:%2i IS:%i MT:%3i MI:%2i ET:%i %s\n",
|
2012-01-16 20:22:42 -07:00
|
|
|
i,
|
2023-01-05 18:11:01 -07:00
|
|
|
plotinfo->kitchen.item_types[i],
|
|
|
|
plotinfo->kitchen.item_subtypes[i],
|
|
|
|
plotinfo->kitchen.mat_types[i],
|
|
|
|
plotinfo->kitchen.mat_indices[i],
|
|
|
|
plotinfo->kitchen.exc_types[i],
|
|
|
|
(plotinfo->kitchen.mat_types[i] >= 419 && plotinfo->kitchen.mat_types[i] <= 618) ? world->raws.plants.all[plotinfo->kitchen.mat_indices[i]]->id.c_str() : "n/a"
|
2012-01-16 20:22:42 -07:00
|
|
|
);
|
|
|
|
}
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("\n");
|
2012-01-16 20:22:42 -07:00
|
|
|
}
|
|
|
|
|
2020-06-29 19:35:07 -06:00
|
|
|
void Kitchen::allowPlantSeedCookery(int32_t plant_id)
|
2011-10-29 20:20:54 -06:00
|
|
|
{
|
2020-06-29 19:35:07 -06:00
|
|
|
df::plant_raw *type = world->raws.plants.all[plant_id];
|
|
|
|
|
|
|
|
removeExclusion(df::kitchen_exc_type::Cook, item_type::SEEDS, -1,
|
|
|
|
type->material_defs.type[plant_material_def::seed],
|
|
|
|
type->material_defs.idx[plant_material_def::seed]);
|
|
|
|
|
|
|
|
removeExclusion(df::kitchen_exc_type::Cook, item_type::PLANT, -1,
|
|
|
|
type->material_defs.type[plant_material_def::basic_mat],
|
|
|
|
type->material_defs.idx[plant_material_def::basic_mat]);
|
2018-05-17 17:34:03 -06:00
|
|
|
}
|
2011-10-29 20:20:54 -06:00
|
|
|
|
2020-06-29 19:35:07 -06:00
|
|
|
void Kitchen::denyPlantSeedCookery(int32_t plant_id)
|
2012-01-16 20:22:42 -07:00
|
|
|
{
|
2020-06-29 19:35:07 -06:00
|
|
|
df::plant_raw *type = world->raws.plants.all[plant_id];
|
|
|
|
|
|
|
|
addExclusion(df::kitchen_exc_type::Cook, item_type::SEEDS, -1,
|
|
|
|
type->material_defs.type[plant_material_def::seed],
|
|
|
|
type->material_defs.idx[plant_material_def::seed]);
|
|
|
|
|
|
|
|
addExclusion(df::kitchen_exc_type::Cook, item_type::PLANT, -1,
|
|
|
|
type->material_defs.type[plant_material_def::basic_mat],
|
|
|
|
type->material_defs.idx[plant_material_def::basic_mat]);
|
2018-05-17 17:34:03 -06:00
|
|
|
}
|
2011-10-29 20:20:54 -06:00
|
|
|
|
2020-06-29 19:35:07 -06:00
|
|
|
void Kitchen::fillWatchMap(std::map<int32_t, int16_t>& watchMap)
|
2012-01-16 20:22:42 -07:00
|
|
|
{
|
|
|
|
watchMap.clear();
|
2020-06-29 19:35:07 -06:00
|
|
|
for (std::size_t i = 0; i < size(); ++i)
|
2011-10-29 20:20:54 -06:00
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
if (plotinfo->kitchen.item_subtypes[i] == SEEDLIMIT_ITEMTYPE &&
|
|
|
|
plotinfo->kitchen.item_subtypes[i] == SEEDLIMIT_ITEMSUBTYPE &&
|
|
|
|
plotinfo->kitchen.exc_types[i] == SEEDLIMIT_EXCTYPE)
|
2011-10-29 20:20:54 -06:00
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
watchMap[plotinfo->kitchen.mat_indices[i]] = plotinfo->kitchen.mat_types[i];
|
2012-01-16 20:22:42 -07:00
|
|
|
}
|
|
|
|
}
|
2018-05-17 17:34:03 -06:00
|
|
|
}
|
2011-10-29 20:20:54 -06:00
|
|
|
|
2020-06-29 19:35:07 -06:00
|
|
|
int Kitchen::findLimit(int32_t plant_id)
|
2012-01-16 20:22:42 -07:00
|
|
|
{
|
2020-06-29 19:35:07 -06:00
|
|
|
for (size_t i = 0; i < size(); ++i)
|
2011-10-29 20:20:54 -06:00
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
if (plotinfo->kitchen.item_types[i] == SEEDLIMIT_ITEMTYPE &&
|
|
|
|
plotinfo->kitchen.item_subtypes[i] == SEEDLIMIT_ITEMSUBTYPE &&
|
|
|
|
plotinfo->kitchen.mat_indices[i] == plant_id &&
|
|
|
|
plotinfo->kitchen.exc_types[i] == SEEDLIMIT_EXCTYPE)
|
2011-10-29 20:20:54 -06:00
|
|
|
{
|
2020-06-29 19:35:07 -06:00
|
|
|
return int(i);
|
2011-10-29 20:20:54 -06:00
|
|
|
}
|
2020-06-29 19:35:07 -06:00
|
|
|
}
|
|
|
|
return -1;
|
2018-05-17 17:34:03 -06:00
|
|
|
}
|
2011-10-29 20:20:54 -06:00
|
|
|
|
2020-06-29 19:35:07 -06:00
|
|
|
bool Kitchen::removeLimit(int32_t plant_id)
|
2012-01-16 20:22:42 -07:00
|
|
|
{
|
2020-06-29 19:35:07 -06:00
|
|
|
int i = findLimit(plant_id);
|
|
|
|
if (i < 0)
|
|
|
|
return false;
|
|
|
|
|
2023-01-05 18:11:01 -07:00
|
|
|
plotinfo->kitchen.item_types.erase(plotinfo->kitchen.item_types.begin() + i);
|
|
|
|
plotinfo->kitchen.item_subtypes.erase(plotinfo->kitchen.item_subtypes.begin() + i);
|
|
|
|
plotinfo->kitchen.mat_types.erase(plotinfo->kitchen.mat_types.begin() + i);
|
|
|
|
plotinfo->kitchen.mat_indices.erase(plotinfo->kitchen.mat_indices.begin() + i);
|
|
|
|
plotinfo->kitchen.exc_types.erase(plotinfo->kitchen.exc_types.begin() + i);
|
2020-06-29 19:35:07 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Kitchen::setLimit(int32_t plant_id, int16_t limit)
|
|
|
|
{
|
|
|
|
if (limit > SEEDLIMIT_MAX)
|
|
|
|
limit = SEEDLIMIT_MAX;
|
|
|
|
|
|
|
|
int i = findLimit(plant_id);
|
|
|
|
if (i < 0)
|
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
plotinfo->kitchen.item_types.push_back(SEEDLIMIT_ITEMTYPE);
|
|
|
|
plotinfo->kitchen.item_subtypes.push_back(SEEDLIMIT_ITEMSUBTYPE);
|
|
|
|
plotinfo->kitchen.mat_types.push_back(limit);
|
|
|
|
plotinfo->kitchen.mat_indices.push_back(plant_id);
|
|
|
|
plotinfo->kitchen.exc_types.push_back(SEEDLIMIT_EXCTYPE);
|
2020-06-29 19:35:07 -06:00
|
|
|
}
|
|
|
|
else
|
2011-10-29 20:20:54 -06:00
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
plotinfo->kitchen.mat_types[i] = limit;
|
2012-01-16 20:22:42 -07:00
|
|
|
}
|
2020-06-29 19:35:07 -06:00
|
|
|
return true;
|
2018-05-17 17:34:03 -06:00
|
|
|
}
|
2011-10-29 20:20:54 -06:00
|
|
|
|
2012-01-16 20:22:42 -07:00
|
|
|
void Kitchen::clearLimits()
|
|
|
|
{
|
2020-06-29 19:35:07 -06:00
|
|
|
for (size_t i = 0; i < size(); ++i)
|
2011-10-29 20:20:54 -06:00
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
if (plotinfo->kitchen.item_types[i] == SEEDLIMIT_ITEMTYPE &&
|
|
|
|
plotinfo->kitchen.item_subtypes[i] == SEEDLIMIT_ITEMSUBTYPE &&
|
|
|
|
plotinfo->kitchen.exc_types[i] == SEEDLIMIT_EXCTYPE)
|
2011-10-29 20:20:54 -06:00
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
removeLimit(plotinfo->kitchen.mat_indices[i]);
|
2020-06-29 19:35:07 -06:00
|
|
|
--i;
|
2011-10-29 20:20:54 -06:00
|
|
|
}
|
2020-06-29 19:35:07 -06:00
|
|
|
}
|
2018-05-17 17:34:03 -06:00
|
|
|
}
|
2011-10-29 20:20:54 -06:00
|
|
|
|
2012-01-16 20:22:42 -07:00
|
|
|
size_t Kitchen::size()
|
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
return plotinfo->kitchen.item_types.size();
|
2018-05-17 17:34:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int Kitchen::findExclusion(df::kitchen_exc_type type,
|
|
|
|
df::item_type item_type, int16_t item_subtype,
|
|
|
|
int16_t mat_type, int32_t mat_index)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < size(); i++)
|
|
|
|
{
|
2023-01-05 18:11:01 -07:00
|
|
|
if (plotinfo->kitchen.item_types[i] == item_type &&
|
|
|
|
plotinfo->kitchen.item_subtypes[i] == item_subtype &&
|
|
|
|
plotinfo->kitchen.mat_types[i] == mat_type &&
|
|
|
|
plotinfo->kitchen.mat_indices[i] == mat_index &&
|
|
|
|
plotinfo->kitchen.exc_types[i] == type)
|
2018-05-17 17:34:03 -06:00
|
|
|
{
|
|
|
|
return int(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Kitchen::addExclusion(df::kitchen_exc_type type,
|
|
|
|
df::item_type item_type, int16_t item_subtype,
|
|
|
|
int16_t mat_type, int32_t mat_index)
|
|
|
|
{
|
|
|
|
if (findExclusion(type, item_type, item_subtype, mat_type, mat_index) >= 0)
|
|
|
|
return false;
|
|
|
|
|
2023-01-05 18:11:01 -07:00
|
|
|
plotinfo->kitchen.item_types.push_back(item_type);
|
|
|
|
plotinfo->kitchen.item_subtypes.push_back(item_subtype);
|
|
|
|
plotinfo->kitchen.mat_types.push_back(mat_type);
|
|
|
|
plotinfo->kitchen.mat_indices.push_back(mat_index);
|
|
|
|
plotinfo->kitchen.exc_types.push_back(type);
|
2018-05-17 17:34:03 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Kitchen::removeExclusion(df::kitchen_exc_type type,
|
|
|
|
df::item_type item_type, int16_t item_subtype,
|
|
|
|
int16_t mat_type, int32_t mat_index)
|
|
|
|
{
|
|
|
|
int i = findExclusion(type, item_type, item_subtype, mat_type, mat_index);
|
|
|
|
if (i < 0)
|
|
|
|
return false;
|
|
|
|
|
2023-01-05 18:11:01 -07:00
|
|
|
plotinfo->kitchen.item_types.erase(plotinfo->kitchen.item_types.begin() + i);
|
|
|
|
plotinfo->kitchen.item_subtypes.erase(plotinfo->kitchen.item_subtypes.begin() + i);
|
|
|
|
plotinfo->kitchen.mat_types.erase(plotinfo->kitchen.mat_types.begin() + i);
|
|
|
|
plotinfo->kitchen.mat_indices.erase(plotinfo->kitchen.mat_indices.begin() + i);
|
|
|
|
plotinfo->kitchen.exc_types.erase(plotinfo->kitchen.exc_types.begin() + i);
|
2018-05-17 17:34:03 -06:00
|
|
|
return true;
|
|
|
|
}
|