@@ -44,7 +44,7 @@ void building_dock::static_params::planer_setup_preview_graphics(build_planner &
44
44
45
45
void building_dock::on_create (int orientation) {
46
46
base.orientation = orientation;
47
- data. dock .trading_goods .one ();
47
+ runtime_data () .trading_goods .one ();
48
48
}
49
49
50
50
void building_dock::on_place (int orientation, int variant) {
@@ -58,7 +58,7 @@ void building_dock::on_destroy() {
58
58
}
59
59
60
60
bool building_dock::can_play_animation () const {
61
- if (data. dock .num_ships > 0 ) {
61
+ if (runtime_data () .num_ships > 0 ) {
62
62
return true ;
63
63
}
64
64
@@ -108,21 +108,22 @@ void building_dock::spawn_figure() {
108
108
}
109
109
// count existing dockers
110
110
int existing_dockers = 0 ;
111
+ auto &d = runtime_data ();
111
112
for (int i = 0 ; i < 3 ; i++) {
112
- if (data. dock .docker_ids [i]) {
113
- if (figure_get (data. dock .docker_ids [i])->type == FIGURE_DOCKER) {
113
+ if (d .docker_ids [i]) {
114
+ if (figure_get (d .docker_ids [i])->type == FIGURE_DOCKER) {
114
115
existing_dockers++;
115
116
} else {
116
- data. dock .docker_ids [i] = 0 ;
117
+ d .docker_ids [i] = 0 ;
117
118
}
118
119
}
119
120
}
120
121
121
122
if (existing_dockers > max_dockers) {
122
123
// too many dockers, poof one of them
123
124
for (int i = 2 ; i >= 0 ; i--) {
124
- if (data. dock .docker_ids [i]) {
125
- figure_get (data. dock .docker_ids [i])->poof ();
125
+ if (d .docker_ids [i]) {
126
+ figure_get (d .docker_ids [i])->poof ();
126
127
return ;
127
128
}
128
129
}
@@ -133,8 +134,8 @@ void building_dock::spawn_figure() {
133
134
f->action_state = FIGURE_ACTION_132_DOCKER_IDLING;
134
135
f->set_home (&base);
135
136
for (int i = 0 ; i < 3 ; i++) {
136
- if (!data. dock .docker_ids [i]) {
137
- data. dock .docker_ids [i] = f->id ;
137
+ if (!d .docker_ids [i]) {
138
+ d .docker_ids [i] = f->id ;
138
139
return ;
139
140
}
140
141
}
@@ -143,9 +144,10 @@ void building_dock::spawn_figure() {
143
144
144
145
void building_dock::on_tick (bool refresh_only) {
145
146
auto &anim_wharf = base.anim ;
147
+ auto &d = runtime_data ();
146
148
if (anim_wharf.valid ()) {
147
- data. dock .docker_anim_frame ++;
148
- data. dock .docker_anim_frame %= (anim_wharf.max_frames * anim_wharf.frame_duration );
149
+ d .docker_anim_frame ++;
150
+ d .docker_anim_frame %= (anim_wharf.max_frames * anim_wharf.frame_duration );
149
151
}
150
152
}
151
153
@@ -169,37 +171,39 @@ void building_dock::update_graphic() {
169
171
170
172
bool building_dock::draw_ornaments_and_animations_height (painter &ctx, vec2i point, tile2i t, color color_mask) {
171
173
auto &anim_dockers = base.anim ;
172
-
174
+ auto &d = runtime_data ();
173
175
if (anim_dockers.valid ()) {
174
- int img_id = anim_dockers.start () + (data. dock .docker_anim_frame / anim_dockers.frame_duration ) * 4 ;
176
+ int img_id = anim_dockers.start () + (d .docker_anim_frame / anim_dockers.frame_duration ) * 4 ;
175
177
ImageDraw::img_generic (ctx, img_id, point + anim_dockers.pos , color_mask, 1 .f , ImgFlag_InternalOffset);
176
178
}
177
179
return false ;
178
180
}
179
181
180
182
void building_dock::bind_dynamic (io_buffer *iob, size_t version) {
181
- iob->bind (BIND_SIGNATURE_INT16, &data.dock .queued_docker_id );
182
- iob->bind (BIND_SIGNATURE_INT32, &data.dock .dock_tiles [0 ]);
183
- iob->bind (BIND_SIGNATURE_INT32, &data.dock .dock_tiles [1 ]);
184
- iob->bind (BIND_SIGNATURE_UINT64, data.dock .trading_goods .data_ptr ());
183
+ auto &d = runtime_data ();
184
+ iob->bind (BIND_SIGNATURE_INT16, &d.queued_docker_id );
185
+ iob->bind (BIND_SIGNATURE_INT32, &d.dock_tiles [0 ]);
186
+ iob->bind (BIND_SIGNATURE_INT32, &d.dock_tiles [1 ]);
187
+ iob->bind (BIND_SIGNATURE_UINT64, d.trading_goods .data_ptr ());
185
188
iob->bind____skip (9 );
186
- iob->bind (BIND_SIGNATURE_UINT8, &data. dock .num_ships );
189
+ iob->bind (BIND_SIGNATURE_UINT8, &d .num_ships );
187
190
iob->bind____skip (2 );
188
191
iob->bind (BIND_SIGNATURE_INT8, &base.orientation );
189
192
iob->bind____skip (3 );
190
193
191
- iob->bind (BIND_SIGNATURE_INT16, &data. dock .docker_ids [0 ]);
192
- iob->bind (BIND_SIGNATURE_INT16, &data. dock .docker_ids [1 ]);
193
- iob->bind (BIND_SIGNATURE_INT16, &data. dock .docker_ids [2 ]);
194
-
195
- iob->bind (BIND_SIGNATURE_INT16, &data. dock .trade_ship_id );
194
+ iob->bind (BIND_SIGNATURE_INT16, &d .docker_ids [0 ]);
195
+ iob->bind (BIND_SIGNATURE_INT16, &d .docker_ids [1 ]);
196
+ iob->bind (BIND_SIGNATURE_INT16, &d .docker_ids [2 ]);
197
+
198
+ iob->bind (BIND_SIGNATURE_INT16, &d .trade_ship_id );
196
199
}
197
200
198
201
int building_dock::count_idle_dockers () const {
199
202
int num_idle = 0 ;
203
+ auto &d = runtime_data ();
200
204
for (int i = 0 ; i < 3 ; i++) {
201
- if (data. dock .docker_ids [i]) {
202
- figure* f = figure_get (data. dock .docker_ids [i]);
205
+ if (d .docker_ids [i]) {
206
+ figure* f = figure_get (d .docker_ids [i]);
203
207
if (f->action_state == FIGURE_ACTION_132_DOCKER_IDLING
204
208
|| f->action_state == FIGURE_ACTION_133_DOCKER_IMPORT_QUEUE) {
205
209
num_idle++;
@@ -216,25 +220,26 @@ bool map_tile_is_connected_to_open_water(tile2i tile) {
216
220
}
217
221
218
222
void building_dock::unaccept_all_goods () {
219
- data. dock .trading_goods .zeroes (64 );
223
+ runtime_data () .trading_goods .zeroes (64 );
220
224
}
221
225
222
226
int building_dock::trader_id () {
223
- return figure_get (data. dock .trade_ship_id )->trader_id ;
227
+ return figure_get (runtime_data () .trade_ship_id )->trader_id ;
224
228
}
225
229
226
230
int building_dock::trader_city_id () {
227
- return data.dock .trade_ship_id
228
- ? figure_get (data.dock .trade_ship_id )->empire_city_id
231
+ auto &d = runtime_data ();
232
+ return d.trade_ship_id
233
+ ? figure_get (d.trade_ship_id )->empire_city_id
229
234
: 0 ;
230
235
}
231
236
232
237
bool building_dock::is_trade_accepted (e_resource r) {
233
- return data. dock .trading_goods .is_set (r);
238
+ return runtime_data () .trading_goods .is_set (r);
234
239
}
235
240
236
241
void building_dock::toggle_good_accepted (e_resource r) {
237
- data. dock .trading_goods .flip (r);
242
+ runtime_data () .trading_goods .flip (r);
238
243
}
239
244
240
245
bool building_dock::accepts_ship (int ship_id) {
@@ -255,10 +260,16 @@ bool building_dock::accepts_ship(int ship_id) {
255
260
void building_dock::highlight_waypoints () {
256
261
building_impl::highlight_waypoints ();
257
262
258
- map_highlight_set (data.dock .dock_tiles [0 ], ehighligth_green);
259
- map_highlight_set (data.dock .dock_tiles [1 ], ehighligth_green);
263
+ auto &d = runtime_data ();
264
+ map_highlight_set (d.dock_tiles [0 ], ehighligth_green);
265
+ map_highlight_set (d.dock_tiles [1 ], ehighligth_green);
260
266
}
261
267
268
+ void building_dock::set_water_access_tiles (const water_access_tiles &tiles) {
269
+ auto &d = runtime_data ();
270
+ d.dock_tiles [0 ] = tiles.point_a .grid_offset ();
271
+ d.dock_tiles [1 ] = tiles.point_b .grid_offset ();
272
+ }
262
273
263
274
tile2i building_dock::moor_tile () const {
264
275
vec2i offset;
@@ -315,7 +326,8 @@ building_dest map_get_free_destination_dock(int ship_id) {
315
326
}
316
327
317
328
better_dock = dock;
318
- if (!dock->data .dock .trade_ship_id || dock->data .dock .trade_ship_id == ship_id) {
329
+ auto &d = dock->runtime_data ();
330
+ if (!d.trade_ship_id || d.trade_ship_id == ship_id) {
319
331
break ;
320
332
}
321
333
}
@@ -326,7 +338,7 @@ building_dest map_get_free_destination_dock(int ship_id) {
326
338
}
327
339
328
340
tile2i moor_tile = better_dock->moor_tile ();
329
- better_dock->data . dock .trade_ship_id = ship_id;
341
+ better_dock->runtime_data () .trade_ship_id = ship_id;
330
342
return {better_dock->id (), moor_tile };
331
343
}
332
344
0 commit comments