Skip to content

Commit 5871640

Browse files
committed
add new helper function building_get_ex
1 parent b892185 commit 5871640

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

src/city/city_buildings.cpp

+5-28
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
building g_all_buildings[5000];
1515
custom_span<building> g_city_buildings = make_span(g_all_buildings);
1616

17-
building *building_get(int id) {
17+
building *building_get(building_id id) {
1818
return &g_all_buildings[id];
1919
}
2020

2121
custom_span<building> &city_buildings() {
2222
return g_city_buildings;
2323
}
2424

25-
building *building_next(int i, e_building_type type) {
26-
for (; i < MAX_BUILDINGS; ++i) {
27-
building *b = building_get(i);
25+
building *building_next(building_id bid, e_building_type type) {
26+
for (; bid < MAX_BUILDINGS; ++bid) {
27+
building *b = building_get(bid);
2828
if (b->state == BUILDING_STATE_VALID && b->type == type)
2929
return b;
3030
}
@@ -222,29 +222,6 @@ void building_update_state(void) {
222222
}
223223
}
224224

225-
static void io_type_data(io_buffer *iob, building *b, size_t version) {
226-
auto &data = b->data;
227-
228-
b->dcast()->bind_dynamic(iob, version);
229-
if (building_is_temple_complex(b->type) || building_is_monument(b->type)) {
230-
iob->bind____skip(38);
231-
iob->bind(BIND_SIGNATURE_UINT8, &data.monuments.orientation);
232-
for (int i = 0; i < 5; i++) {
233-
iob->bind(BIND_SIGNATURE_UINT16, &data.monuments.workers[i]);
234-
}
235-
iob->bind(BIND_SIGNATURE_UINT8, &data.monuments.phase);
236-
iob->bind(BIND_SIGNATURE_UINT8, &data.monuments.statue_offset);
237-
iob->bind(BIND_SIGNATURE_UINT8, &data.monuments.temple_complex_attachments);
238-
iob->bind(BIND_SIGNATURE_UINT8, &data.monuments.variant);
239-
240-
for (int i = 0; i < RESOURCES_MAX; i++) {
241-
iob->bind(BIND_SIGNATURE_UINT8, &data.monuments.resources_pct[i]);
242-
}
243-
} else {
244-
; // nothing
245-
}
246-
}
247-
248225
io_buffer *iob_buildings = new io_buffer([] (io_buffer *iob, size_t version) {
249226
for (int i = 0; i < MAX_BUILDINGS; i++) {
250227
// building_state_load_from_buffer(buf, &all_buildings[i]);
@@ -308,7 +285,7 @@ io_buffer *iob_buildings = new io_buffer([] (io_buffer *iob, size_t version) {
308285
iob->bind(BIND_SIGNATURE_UINT8, &b->health_proof);
309286
iob->bind(BIND_SIGNATURE_INT16, &b->formation_id);
310287

311-
io_type_data(iob, b, version); // 102 for PH
288+
b->dcast()->bind_dynamic(iob, version); // 102 for PH
312289

313290
int currind = iob->get_offset() - sind;
314291
assert(currind > 0);

src/city/city_buildings.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ inline building *building_end() { return building_get(MAX_BUILDINGS); }
88

99
custom_span<building> &city_buildings();
1010

11-
building *building_next(int id, e_building_type type);
11+
building *building_next(building_id id, e_building_type type);
1212

1313
int building_id_first(e_building_type type);
1414
building *building_first(e_building_type type);
@@ -20,7 +20,6 @@ building *building_at(int x, int y);
2020
building *building_at(tile2i tile);
2121

2222
bool building_exists_at(int grid_offset, building *b);
23-
2423
bool building_exists_at(tile2i point, building *b);
2524

2625
void building_clear_all();
@@ -34,6 +33,12 @@ T* building_at_ex(tile2i tile) {
3433
return smart_cast<T>(b);
3534
}
3635

36+
template<typename T>
37+
T *building_get_ex(building_id bid) {
38+
building *b = building_get(bid);
39+
return smart_cast<T>(b);
40+
}
41+
3742
template<typename T>
3843
void buildings_valid_do(T func) {
3944
for (auto &b : city_buildings()) {

0 commit comments

Comments
 (0)