@@ -67,7 +67,7 @@ int building_granary::amount(e_resource resource) const {
67
67
return 0 ;
68
68
}
69
69
70
- return data. granary .resource_stored [resource];
70
+ return runtime_data () .resource_stored [resource];
71
71
}
72
72
73
73
bool building_granary::is_accepting (e_resource resource) {
@@ -105,7 +105,8 @@ int building_granary::add_resource(e_resource resource, bool is_produced, int am
105
105
return -1 ;
106
106
}
107
107
108
- if (data.granary .resource_stored [RESOURCE_NONE] <= 0 ) {
108
+ auto &d = runtime_data ();
109
+ if (d.resource_stored [RESOURCE_NONE] <= 0 ) {
109
110
return -1 ; // no space
110
111
}
111
112
@@ -117,9 +118,9 @@ int building_granary::add_resource(e_resource resource, bool is_produced, int am
117
118
city_resource_add_produced_to_granary (amount);
118
119
}
119
120
120
- int deliverable_amount = std::min<int >(data. granary .resource_stored [RESOURCE_NONE], amount);
121
- data. granary .resource_stored [resource] += deliverable_amount;
122
- data. granary .resource_stored [RESOURCE_NONE] -= deliverable_amount;
121
+ int deliverable_amount = std::min<int >(d .resource_stored [RESOURCE_NONE], amount);
122
+ d .resource_stored [resource] += deliverable_amount;
123
+ d .resource_stored [RESOURCE_NONE] -= deliverable_amount;
123
124
return amount - deliverable_amount;
124
125
}
125
126
@@ -133,19 +134,20 @@ int building_granary::total_stored() const {
133
134
}
134
135
135
136
int building_granary::freespace () const {
136
- return data. granary .resource_stored [RESOURCE_NONE];
137
+ return runtime_data () .resource_stored [RESOURCE_NONE];
137
138
}
138
139
139
140
int building_granary::remove_resource (e_resource resource, int amount) {
140
141
if (amount <= 0 ) {
141
142
return 0 ;
142
143
}
143
144
144
- int removed = std::min<int >(data.granary .resource_stored [resource], amount);
145
+ auto &d = runtime_data ();
146
+ int removed = std::min<int >(d.resource_stored [resource], amount);
145
147
146
148
city_resource_remove_from_granary (resource, removed);
147
- data. granary .resource_stored [resource] -= removed;
148
- data. granary .resource_stored [RESOURCE_NONE] += removed;
149
+ d .resource_stored [resource] -= removed;
150
+ d .resource_stored [RESOURCE_NONE] += removed;
149
151
150
152
return amount - removed;
151
153
}
@@ -252,7 +254,8 @@ int building_granary_for_storing(tile2i tile, e_resource resource, int distance_
252
254
continue ;
253
255
}
254
256
255
- if (granary->data .granary .resource_stored [RESOURCE_NONE] >= ONE_LOAD) {
257
+ const auto &d = granary->runtime_data ();
258
+ if (d.resource_stored [RESOURCE_NONE] >= ONE_LOAD) {
256
259
// there is room
257
260
int dist = calc_distance_with_penalty (vec2i (granary->tilex () + 1 , granary->tiley () + 1 ), tile, distance_from_entry, granary->distance_from_entry ());
258
261
if (dist < min_dist) {
@@ -295,7 +298,8 @@ int building_getting_granary_for_storing(tile2i tile, e_resource resource, int d
295
298
if (granary->is_getting (resource) || granary->is_empty_all ())
296
299
continue ;
297
300
298
- if (granary->data .granary .resource_stored [RESOURCE_NONE] > ONE_LOAD) {
301
+ const auto &d = granary->runtime_data ();
302
+ if (d.resource_stored [RESOURCE_NONE] > ONE_LOAD) {
299
303
// there is room
300
304
int dist = calc_distance_with_penalty (vec2i (granary->tilex () + 1 , granary->tiley () + 1 ), tile, distance_from_entry, granary->distance_from_entry ());
301
305
if (dist < min_dist) {
@@ -481,21 +485,22 @@ void building_granary_draw_anim(building &b, vec2i point, tile2i tile, color mas
481
485
}
482
486
483
487
void building_granary::on_create (int orientation) {
484
- data. granary .resource_stored [RESOURCE_NONE] = capacity_stored ();
488
+ runtime_data () .resource_stored [RESOURCE_NONE] = capacity_stored ();
485
489
base.storage_id = building_storage_create (BUILDING_GRANARY);
486
490
}
487
491
488
492
void building_granary::update_day () {
489
493
building_impl::update_day ();
490
- data. granary .resource_stored [RESOURCE_NONE] = capacity_stored () - total_stored ();
494
+ runtime_data () .resource_stored [RESOURCE_NONE] = capacity_stored () - total_stored ();
491
495
}
492
496
493
497
void building_granary::bind_dynamic (io_buffer *iob, size_t version) {
494
498
iob->bind____skip (2 );
495
499
iob->bind____skip (2 );
496
500
501
+ auto &d = runtime_data ();
497
502
for (int i = 0 ; i < RESOURCES_MAX; i++) {
498
- iob->bind (BIND_SIGNATURE_INT16, &data. granary .resource_stored [i]);
503
+ iob->bind (BIND_SIGNATURE_INT16, &d .resource_stored [i]);
499
504
}
500
505
}
501
506
@@ -553,10 +558,12 @@ textid building_granary::get_tooltip() const {
553
558
void building_granary::draw_stores (vec2i point, color color_mask, painter &ctx) {
554
559
int last_spot_filled = 0 ;
555
560
int resources_id = granary_m.anim [" resources" ].first_img ();
561
+
562
+ const auto &d = runtime_data ();
556
563
for (int r = 1 ; r < 9 ; r++) {
557
- if (data. granary .resource_stored [r] > 0 ) {
558
- int spots_filled = ceil ((float )(data. granary .resource_stored [r] - 199 ) / (float )400 ); // number of "spots" occupied by food
559
- if (spots_filled == 0 && data. granary .resource_stored [r] > 0 )
564
+ if (d .resource_stored [r] > 0 ) {
565
+ int spots_filled = ceil ((float )(d .resource_stored [r] - 199 ) / (float )400 ); // number of "spots" occupied by food
566
+ if (spots_filled == 0 && d .resource_stored [r] > 0 )
560
567
spots_filled = 1 ;
561
568
562
569
for (int spot = last_spot_filled; spot < last_spot_filled + spots_filled; spot++) {
0 commit comments