Skip to content

Commit 1ebe7eb

Browse files
committed
refactor: build_planner_latch_on_venue() function moved to building_entertainment class
1 parent 3286296 commit 1ebe7eb

10 files changed

+149
-143
lines changed

src/building/building_bandstand.cpp

+27-17
Original file line numberDiff line numberDiff line change
@@ -123,40 +123,50 @@ void building_bandstand::on_place_update_tiles(int orientation, int variant) {
123123
// add additional building parts, update graphics accordingly
124124
switch (absolute_orientation) {
125125
case 0:
126-
build_planner_latch_on_venue(BUILDING_GARDENS, &base, 2, 1, 0);
127-
build_planner_latch_on_venue(BUILDING_BOOTH, &base, 2, 0, 0);
128-
build_planner_latch_on_venue(BUILDING_BANDSTAND, &base, 0, 0, 0, true);
129-
build_planner_latch_on_venue(BUILDING_BANDSTAND, &base, 0, 1, 0, false);
126+
place_latch_on_venue(BUILDING_GARDENS, 2, 1, 0);
127+
place_latch_on_venue(BUILDING_BOOTH, 2, 0, 0);
128+
place_latch_on_venue(BUILDING_BANDSTAND, 0, 0, 0, true);
129+
place_latch_on_venue(BUILDING_BANDSTAND, 0, 1, 0, false);
130130
break;
131131

132132
case 1:
133-
build_planner_latch_on_venue(BUILDING_GARDENS, &base, 1, 2, 0);
134-
build_planner_latch_on_venue(BUILDING_BOOTH, &base, 2, 2, 0);
135-
build_planner_latch_on_venue(BUILDING_BANDSTAND, &base, 1, 0, 1, true);
136-
build_planner_latch_on_venue(BUILDING_BANDSTAND, &base, 2, 0, 1, false);
133+
place_latch_on_venue(BUILDING_GARDENS, 1, 2, 0);
134+
place_latch_on_venue(BUILDING_BOOTH, 2, 2, 0);
135+
place_latch_on_venue(BUILDING_BANDSTAND, 1, 0, 1, true);
136+
place_latch_on_venue(BUILDING_BANDSTAND, 2, 0, 1, false);
137137
break;
138138

139139
case 2:
140-
build_planner_latch_on_venue(BUILDING_GARDENS, &base, 2, 1, 0);
141-
build_planner_latch_on_venue(BUILDING_BOOTH, &base, 2, 2, 0);
142-
build_planner_latch_on_venue(BUILDING_BANDSTAND, &base, 0, 1, 2, true);
143-
build_planner_latch_on_venue(BUILDING_BANDSTAND, &base, 0, 2, 2, false);
140+
place_latch_on_venue(BUILDING_GARDENS, 2, 1, 0);
141+
place_latch_on_venue(BUILDING_BOOTH, 2, 2, 0);
142+
place_latch_on_venue(BUILDING_BANDSTAND, 0, 1, 2, true);
143+
place_latch_on_venue(BUILDING_BANDSTAND, 0, 2, 2, false);
144144
break;
145145

146146
case 3:
147-
build_planner_latch_on_venue(BUILDING_GARDENS, &base, 1, 2, 0);
148-
build_planner_latch_on_venue(BUILDING_BOOTH, &base, 0, 2, 0);
149-
build_planner_latch_on_venue(BUILDING_BANDSTAND, &base, 1, 0, 3, true);
150-
build_planner_latch_on_venue(BUILDING_BANDSTAND, &base, 0, 0, 3, false);
147+
place_latch_on_venue(BUILDING_GARDENS, 1, 2, 0);
148+
place_latch_on_venue(BUILDING_BOOTH, 0, 2, 0);
149+
place_latch_on_venue(BUILDING_BANDSTAND, 1, 0, 3, true);
150+
place_latch_on_venue(BUILDING_BANDSTAND, 0, 0, 3, false);
151151
break;
152152
}
153153
}
154154

155+
void building_bandstand::map_add_bandstand_tiles() {
156+
int offset = bandstand_main_img_offset(data.entertainment.orientation);
157+
int offset_add = bandstand_add_img_offset(data.entertainment.orientation);
158+
159+
int stand_sn_s = building_impl::params(BUILDING_BANDSTAND).anim["stand_sn_s"].first_img();
160+
map_image_set(data.entertainment.latched_venue_main_grid_offset, stand_sn_s + offset);
161+
map_image_set(data.entertainment.latched_venue_add_grid_offset, stand_sn_s + offset_add);
162+
}
163+
164+
155165
void building_bandstand::update_map_orientation(int map_orientation) {
156166
int plaza_image_id = anim(animkeys().square).first_img();
157167
tile2i btile(data.entertainment.booth_corner_grid_offset);
158168
map_add_venue_plaza_tiles(id(), base.size, btile, plaza_image_id, true);
159-
map_add_bandstand_tiles(&base);
169+
map_add_bandstand_tiles();
160170
}
161171

162172
void building_bandstand::spawn_figure() {

src/building/building_bandstand.h

+1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ class building_bandstand : public building_entertainment {
4141
void draw_shows_musicians(painter &ctx, vec2i pixel, int direction, color color_mask);
4242

4343
static const static_params &current_params() { return (const static_params &)params(TYPE); }
44+
void map_add_bandstand_tiles();
4445
};

src/building/building_booth.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ void building_booth::on_place_update_tiles(int orientation, int variant) {
9393

9494
// add additional building parts, update graphics accordingly
9595
switch (absolute_orientation) {
96-
case 0: build_planner_latch_on_venue(BUILDING_BOOTH, &base, 0, 0, orientation, true); break;
97-
case 1: build_planner_latch_on_venue(BUILDING_BOOTH, &base, 1, 0, orientation, true); break;
98-
case 2: build_planner_latch_on_venue(BUILDING_BOOTH, &base, 1, 1, orientation, true); break;
99-
case 3: build_planner_latch_on_venue(BUILDING_BOOTH, &base, 0, 1, orientation, true); break;
96+
case 0: place_latch_on_venue(BUILDING_BOOTH, 0, 0, orientation, true); break;
97+
case 1: place_latch_on_venue(BUILDING_BOOTH, 1, 0, orientation, true); break;
98+
case 2: place_latch_on_venue(BUILDING_BOOTH, 1, 1, orientation, true); break;
99+
case 3: place_latch_on_venue(BUILDING_BOOTH, 0, 1, orientation, true); break;
100100
}
101101
}
102102

src/building/building_entertainment.cpp

+113
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,119 @@
11
#include "building_entertainment.h"
22

33
#include "io/io_buffer.h"
4+
#include "grid/terrain.h"
5+
#include "grid/tiles.h"
6+
#include "grid/image.h"
7+
#include "grid/building_tiles.h"
8+
#include "graphics/view/view.h"
9+
10+
int building_entertainment::bandstand_main_img_offset(int orientation) {
11+
int offset = 0;
12+
if (orientation == 2) {
13+
switch (city_view_orientation() / 2) {
14+
case 0: offset = 1; break;
15+
case 1: offset = 2; break;
16+
case 2: offset = 0; break;
17+
case 3: offset = 3; break;
18+
}
19+
} else if (orientation == 3) {
20+
switch (city_view_orientation() / 2) {
21+
case 0: offset = 3; break;
22+
case 1: offset = 1; break;
23+
case 2: offset = 2; break;
24+
case 3: offset = 0; break;
25+
}
26+
} else if (orientation == 0) {
27+
switch (city_view_orientation() / 2) {
28+
case 0: offset = 1; break;
29+
case 1: offset = 2; break;
30+
case 2: offset = 0; break;
31+
case 3: offset = 3; break;
32+
}
33+
} else if (orientation == 1) {
34+
switch (city_view_orientation() / 2) {
35+
case 0: offset = 2; break;
36+
case 1: offset = 0; break;
37+
case 2: offset = 3; break;
38+
case 3: offset = 1; break;
39+
}
40+
}
41+
return offset;
42+
}
43+
44+
int building_entertainment::bandstand_add_img_offset(int orientation) {
45+
int offset = 0;
46+
if (orientation == 2) {
47+
switch (city_view_orientation() / 2) {
48+
case 0: offset = 0; break;
49+
case 1: offset = 3; break;
50+
case 2: offset = 1; break;
51+
case 3: offset = 2; break;
52+
}
53+
} else if (orientation == 3) {
54+
switch (city_view_orientation() / 2) {
55+
case 0: offset = 2; break;
56+
case 1: offset = 0; break;
57+
case 2: offset = 3; break;
58+
case 3: offset = 1; break;
59+
}
60+
} else if (orientation == 0) {
61+
switch (city_view_orientation() / 2) {
62+
case 0: offset = 0; break;
63+
case 1: offset = 3; break;
64+
case 2: offset = 1; break;
65+
case 3: offset = 2; break;
66+
}
67+
} else if (orientation == 1) {
68+
switch (city_view_orientation() / 2) {
69+
case 0: offset = 3; break;
70+
case 1: offset = 1; break;
71+
case 2: offset = 2; break;
72+
case 3: offset = 0; break;
73+
}
74+
}
75+
return offset;
76+
}
77+
78+
void building_entertainment::place_latch_on_venue(e_building_type type, int dx, int dy, int orientation, bool main_venue) {
79+
tile2i point = base.tile.shifted(dx, dy);
80+
// set map graphics accordingly
81+
82+
switch (type) {
83+
case BUILDING_GARDENS:
84+
map_terrain_add(point, TERRAIN_GARDEN);
85+
map_tiles_update_all_gardens();
86+
break;
87+
88+
case BUILDING_BOOTH:
89+
{
90+
int booth = anim(animkeys().booth).first_img();
91+
map_image_set(point, booth);
92+
}
93+
break;
94+
95+
case BUILDING_BANDSTAND:
96+
if (main_venue) {
97+
int stand_sn_s = anim("stand_sn_s").first_img();
98+
data.entertainment.latched_venue_main_grid_offset = point.grid_offset();
99+
int offset = bandstand_main_img_offset(orientation);
100+
map_image_set(point, stand_sn_s + offset);
101+
} else {
102+
int stand_sn_s = anim("stand_sn_s").first_img();
103+
data.entertainment.latched_venue_add_grid_offset = point.grid_offset();
104+
int offset = bandstand_add_img_offset(orientation);
105+
map_image_set(point, stand_sn_s + offset);
106+
}
107+
break;
108+
109+
case BUILDING_PAVILLION:
110+
{
111+
int base_id = anim(animkeys().base).first_img();
112+
map_building_tiles_add(id(), point, 2, base_id, TERRAIN_BUILDING);
113+
}
114+
break;
115+
}
116+
}
4117

5118
void building_entertainment::bind_dynamic(io_buffer *iob, size_t version) {
6119
iob->bind____skip(26);

src/building/building_entertainment.h

+3
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ class building_entertainment : public building_impl {
88
virtual building_entertainment *dcast_entertainment() override { return this; }
99

1010
virtual void bind_dynamic(io_buffer *iob, size_t version) override;
11+
void place_latch_on_venue(e_building_type type, int dx, int dy, int orientation, bool main_venue = false);
12+
int bandstand_main_img_offset(int orientation);
13+
int bandstand_add_img_offset(int orientation);
1114
};

src/building/building_pavilion.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void building_pavilion::on_place_update_tiles(int orientation, int variant) {
130130
map_add_venue_plaza_tiles(id(), size, tile(), image_id, false);
131131
int absolute_orientation = abs(basic_orientation + (8 - city_view_orientation())) % 8;
132132
for (const auto &item: pavilion_m.place_dir[absolute_orientation].items) {
133-
build_planner_latch_on_venue(item.type, &base, item.offset.x, item.offset.y, orientation, item.main);
133+
place_latch_on_venue(item.type, item.offset.x, item.offset.y, orientation, item.main);
134134
}
135135
}
136136

src/building/construction/build_planner.cpp

-39
Original file line numberDiff line numberDiff line change
@@ -145,45 +145,6 @@ bool build_planner::ghost_mark_deleting(tile2i tile) {
145145
return true;
146146
}
147147

148-
void build_planner_latch_on_venue(e_building_type type, building *b, int dx, int dy, int orientation, bool main_venue) {
149-
tile2i point = b->tile.shifted(dx, dy);
150-
// set map graphics accordingly
151-
152-
const auto &params = b->dcast()->params();
153-
switch (type) {
154-
case BUILDING_GARDENS:
155-
map_terrain_add(point, TERRAIN_GARDEN);
156-
map_tiles_update_all_gardens();
157-
break;
158-
159-
case BUILDING_BOOTH: {
160-
int booth = params.anim["booth"].first_img();
161-
map_image_set(point, booth);
162-
}
163-
break;
164-
165-
case BUILDING_BANDSTAND:
166-
if (main_venue) {
167-
int stand_sn_s = params.anim["stand_sn_s"].first_img();
168-
b->data.entertainment.latched_venue_main_grid_offset = point.grid_offset();
169-
int offset = map_bandstand_main_img_offset(orientation);
170-
map_image_set(point, stand_sn_s + offset);
171-
} else {
172-
int stand_sn_s = params.anim["stand_sn_s"].first_img();
173-
b->data.entertainment.latched_venue_add_grid_offset = point.grid_offset();
174-
int offset = map_bandstand_add_img_offset(orientation);
175-
map_image_set(point, stand_sn_s + offset);
176-
}
177-
break;
178-
179-
case BUILDING_PAVILLION: {
180-
int base_id = params.anim["base"].first_img();
181-
map_building_tiles_add(b->id, point, 2, base_id, TERRAIN_BUILDING);
182-
}
183-
break;
184-
}
185-
}
186-
187148
void build_planner::mark_construction(tile2i tile, vec2i size, int terrain, bool absolute_xy) {
188149
if (g_city_planner.can_be_placed() == CAN_PLACE
189150
&& map_building_tiles_mark_construction(tile, size.x, size.y, terrain, absolute_xy)) {

src/building/construction/build_planner.h

-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,5 @@ class build_planner {
145145
void draw_tile_graphics_array(painter &ctx, tile2i start, tile2i end, vec2i pixel);
146146
};
147147

148-
void build_planner_latch_on_venue(e_building_type type, building *b, int dx, int dy, int orientation, bool main_venue = false);
149-
150148
extern build_planner g_city_planner;
151149
extern const vec2i VIEW_OFFSETS[];

src/grid/building_tiles.cpp

-77
Original file line numberDiff line numberDiff line change
@@ -101,83 +101,6 @@ void map_building_tiles_add(int building_id, tile2i tile, int size, int image_id
101101
map_property_mark_draw_tile(draw_tile.grid_offset());
102102
}
103103

104-
int map_bandstand_main_img_offset(int orientation) {
105-
int offset = 0;
106-
if (orientation == 2) {
107-
switch (city_view_orientation() / 2) {
108-
case 0: offset = 1; break;
109-
case 1: offset = 2; break;
110-
case 2: offset = 0; break;
111-
case 3: offset = 3; break;
112-
}
113-
} else if (orientation == 3) {
114-
switch (city_view_orientation() / 2) {
115-
case 0: offset = 3; break;
116-
case 1: offset = 1; break;
117-
case 2: offset = 2; break;
118-
case 3: offset = 0; break;
119-
}
120-
} else if (orientation == 0) {
121-
switch (city_view_orientation() / 2) {
122-
case 0: offset = 1; break;
123-
case 1: offset = 2; break;
124-
case 2: offset = 0; break;
125-
case 3: offset = 3; break;
126-
}
127-
} else if (orientation == 1) {
128-
switch (city_view_orientation() / 2) {
129-
case 0: offset = 2; break;
130-
case 1: offset = 0; break;
131-
case 2: offset = 3; break;
132-
case 3: offset = 1; break;
133-
}
134-
}
135-
return offset;
136-
}
137-
138-
int map_bandstand_add_img_offset(int orientation) {
139-
int offset = 0;
140-
if (orientation == 2) {
141-
switch (city_view_orientation() / 2) {
142-
case 0: offset = 0; break;
143-
case 1: offset = 3; break;
144-
case 2: offset = 1; break;
145-
case 3: offset = 2; break;
146-
}
147-
} else if (orientation == 3) {
148-
switch (city_view_orientation() / 2) {
149-
case 0: offset = 2; break;
150-
case 1: offset = 0; break;
151-
case 2: offset = 3; break;
152-
case 3: offset = 1; break;
153-
}
154-
} else if (orientation == 0) {
155-
switch (city_view_orientation() / 2) {
156-
case 0: offset = 0; break;
157-
case 1: offset = 3; break;
158-
case 2: offset = 1; break;
159-
case 3: offset = 2; break;
160-
}
161-
} else if (orientation == 1) {
162-
switch (city_view_orientation() / 2) {
163-
case 0: offset = 3; break;
164-
case 1: offset = 1; break;
165-
case 2: offset = 2; break;
166-
case 3: offset = 0; break;
167-
}
168-
}
169-
return offset;
170-
}
171-
172-
void map_add_bandstand_tiles(building* b) {
173-
int offset = map_bandstand_main_img_offset(b->data.entertainment.orientation);
174-
int offset_add = map_bandstand_add_img_offset(b->data.entertainment.orientation);
175-
176-
int stand_sn_s = building_impl::params(BUILDING_BANDSTAND).anim["stand_sn_s"].first_img();
177-
map_image_set(b->data.entertainment.latched_venue_main_grid_offset, stand_sn_s + offset);
178-
map_image_set(b->data.entertainment.latched_venue_add_grid_offset, stand_sn_s + offset_add);
179-
}
180-
181104
static void set_underlying_venue_plaza_tile(int grid_offset, int building_id, int image_id, bool update_only) {
182105
if (!update_only) {
183106
map_image_set(grid_offset, image_id);

src/grid/building_tiles.h

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
void map_building_tiles_add(int building_id, tile2i tile, int size, int image_id, int terrain);
88

9-
void map_add_bandstand_tiles(building* b);
10-
int map_bandstand_main_img_offset(int orientation);
11-
int map_bandstand_add_img_offset(int orientation);
129
void map_add_venue_plaza_tiles(int building_id, int size, tile2i tile, int image_id, bool update_only);
1310

1411
void map_add_temple_complex_base_tiles(e_building_type type, int x, int y, int orientation);

0 commit comments

Comments
 (0)