4
4
#include " building/industry.h"
5
5
#include " building/model.h"
6
6
#include " building/building_storage_yard.h"
7
+ #include " building/building_granary.h"
7
8
#include " city/city.h"
8
9
#include " city/warning.h"
9
10
#include " graphics/window.h"
@@ -23,10 +24,22 @@ struct available_data_t {
23
24
available_data_t g_available_data;
24
25
25
26
static auto &city_data = g_city;
26
- int city_resource_count (e_resource resource) {
27
+ int city_resource_warehouse_stored (e_resource resource) {
27
28
return city_data.resource .stored_in_warehouses [resource];
28
29
}
29
30
31
+ int city_resource_granary_stored (e_resource resource) {
32
+ if (!resource_is_food (resource)) {
33
+ return 0 ;
34
+ }
35
+ return city_data.resource .granary_food_stored [resource];
36
+ }
37
+
38
+ int city_resource_storages_stored (e_resource resource) {
39
+ return city_resource_warehouse_stored (resource)
40
+ + city_resource_granary_stored (resource);
41
+ }
42
+
30
43
const resource_list &city_resource_get_available () {
31
44
return g_available_data.resources ;
32
45
}
@@ -183,15 +196,60 @@ void city_resource_add_produced_to_granary(int amount) {
183
196
void city_resource_remove_from_granary (int food, int amount) {
184
197
city_data.resource .granary_food_stored [food] -= amount;
185
198
}
199
+
186
200
void city_resource_add_to_storageyard (e_resource resource, int amount) {
187
201
city_data.resource .space_in_warehouses [resource] -= amount;
188
202
city_data.resource .stored_in_warehouses [resource] += amount;
189
203
}
204
+
190
205
void city_resource_remove_from_storageyard (e_resource resource, int amount) {
191
206
city_data.resource .space_in_warehouses [resource] += amount;
192
207
city_data.resource .stored_in_warehouses [resource] -= amount;
193
208
}
194
209
210
+ int city_storageyards_remove_resource (e_resource resource, int amount) {
211
+ int amount_left = amount;
212
+
213
+ // first go for non-getting warehouses
214
+ buildings_valid_do ([&] (building &b) {
215
+ building_storage_yard *warehouse = b.dcast_storage_yard ();
216
+ if (warehouse && warehouse->is_valid () && !warehouse->is_getting (resource)) {
217
+ amount_left = warehouse->remove_resource (resource, amount_left);
218
+ }
219
+ });
220
+ // if that doesn't work, take it anyway
221
+ buildings_valid_do ([&] (building &b) {
222
+ building_storage_yard *warehouse = b.dcast_storage_yard ();
223
+ if (warehouse && warehouse->is_valid ()) {
224
+ amount_left = warehouse->remove_resource (resource, amount_left);
225
+ }
226
+ });
227
+
228
+ return amount - amount_left;
229
+ }
230
+
231
+ int city_granaries_remove_resource (e_resource resource, int amount) {
232
+ int amount_left = amount;
233
+
234
+ // first go for non-getting warehouses
235
+ buildings_valid_do ([&] (building &b) {
236
+ building_granary *granary = b.dcast_granary ();
237
+ if (granary && granary->is_valid () && !granary->is_getting (resource)) {
238
+ amount_left = granary->remove_resource (resource, amount_left);
239
+ }
240
+ });
241
+ // if that doesn't work, take it anyway
242
+ buildings_valid_do ([&] (building &b) {
243
+ building_granary *granary = b.dcast_granary ();
244
+ if (granary && granary->is_valid ()) {
245
+ amount_left = granary->remove_resource (resource, amount_left);
246
+ }
247
+ });
248
+
249
+ return amount - amount_left;
250
+ }
251
+
252
+
195
253
void city_resource_calculate_storageyard_stocks () {
196
254
OZZY_PROFILER_SECTION (" Game/Run/Tick/Warehouse Stocks Update" );
197
255
for (int i = 0 ; i < RESOURCES_MAX; i++) {
0 commit comments