forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKitchen.cpp
More file actions
169 lines (141 loc) · 5.49 KB
/
Kitchen.cpp
File metadata and controls
169 lines (141 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include "Internal.h"
#include <string>
#include <sstream>
#include <vector>
#include <cstdio>
#include <map>
#include <set>
using namespace std;
#include "VersionInfo.h"
#include "MemAccess.h"
#include "Types.h"
#include "Error.h"
#include "modules/Kitchen.h"
#include "ModuleFactory.h"
#include "Core.h"
using namespace DFHack;
#include "DataDefs.h"
#include "df/world.h"
#include "df/plotinfost.h"
#include "df/item_type.h"
#include "df/plant_raw.h"
using namespace df::enums;
using df::global::world;
using df::global::plotinfo;
void Kitchen::debug_print(color_ostream &out)
{
out.print("Kitchen Exclusions\n");
for(std::size_t i = 0; i < size(); ++i)
{
out.print("%2zu: IT:%2i IS:%i MT:%3i MI:%2i ET:%i %s\n",
i,
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].whole,
(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"
);
}
out.print("\n");
}
static df::kitchen_exc_type get_cook_type(){
df::kitchen_exc_type cook_type;
cook_type.bits.Cook = true;
return cook_type;
}
void Kitchen::allowPlantSeedCookery(int32_t plant_id)
{
if (plant_id < 0 || (size_t)plant_id >= world->raws.plants.all.size())
return;
df::plant_raw *type = world->raws.plants.all[plant_id];
static df::kitchen_exc_type cook_type = get_cook_type();
removeExclusion(cook_type, item_type::SEEDS, -1,
type->material_defs.type[plant_material_def::seed],
type->material_defs.idx[plant_material_def::seed]);
removeExclusion(cook_type, item_type::PLANT, -1,
type->material_defs.type[plant_material_def::basic_mat],
type->material_defs.idx[plant_material_def::basic_mat]);
}
void Kitchen::denyPlantSeedCookery(int32_t plant_id)
{
if (plant_id < 0 || (size_t)plant_id >= world->raws.plants.all.size())
return;
df::plant_raw *type = world->raws.plants.all[plant_id];
static df::kitchen_exc_type cook_type = get_cook_type();
addExclusion(cook_type, item_type::SEEDS, -1,
type->material_defs.type[plant_material_def::seed],
type->material_defs.idx[plant_material_def::seed]);
addExclusion(cook_type, item_type::PLANT, -1,
type->material_defs.type[plant_material_def::basic_mat],
type->material_defs.idx[plant_material_def::basic_mat]);
}
bool Kitchen::isPlantCookeryAllowed(int32_t plant_id) {
if (plant_id < 0 || (size_t)plant_id >= world->raws.plants.all.size())
return false;
df::plant_raw *type = world->raws.plants.all[plant_id];
static df::kitchen_exc_type cook_type = get_cook_type();
return findExclusion(cook_type, item_type::PLANT, -1,
type->material_defs.type[plant_material_def::basic_mat],
type->material_defs.idx[plant_material_def::basic_mat]) < 0;
}
bool Kitchen::isSeedCookeryAllowed(int32_t plant_id) {
if (plant_id < 0 || (size_t)plant_id >= world->raws.plants.all.size())
return false;
df::plant_raw *type = world->raws.plants.all[plant_id];
static df::kitchen_exc_type cook_type = get_cook_type();
return findExclusion(cook_type, item_type::SEEDS, -1,
type->material_defs.type[plant_material_def::seed],
type->material_defs.idx[plant_material_def::seed]) < 0;
}
size_t Kitchen::size()
{
return plotinfo->kitchen.item_types.size();
}
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++)
{
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].whole == type.whole)
{
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)
{
// exactly one flag must be set
if (!type.whole || type.whole > 2)
return false;
if (findExclusion(type, item_type, item_subtype, mat_type, mat_index) >= 0)
return false;
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);
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;
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);
return true;
}