Skip to content

Commit 53f1750

Browse files
committed
buildings: cleanup pavillion logic
1 parent 6605a42 commit 53f1750

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

src/building/building_pavilion.cpp

+24-25
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,17 @@ struct pavilion_model : public buildings::model_t<building_pavilion> {
6969
for (auto &pdir : place_dir) {
7070
pdir.load(arch, bstring32().printf("place_dir_%d", std::distance(place_dir, &pdir)).c_str());
7171
}
72+
73+
dancer_tile = anim[animkeys().base].first_img();
74+
booth_tile = anim[animkeys().booth].first_img();
75+
musician_tile_s = anim[animkeys().stand_sn_s].first_img();
76+
musician_tile_e = anim[animkeys().stand_sn_e].first_img();
7277
}
7378

7479
preview_offset preview_dir[8];
7580
place_offset place_dir[8];
7681
} pavilion_m;
7782

78-
ANK_REGISTER_CONFIG_ITERATOR(config_load_building_pavilion);
79-
void config_load_building_pavilion() {
80-
pavilion_m.load();
81-
pavilion_m.dancer_tile = pavilion_m.anim["base"].first_img();
82-
pavilion_m.booth_tile = pavilion_m.anim["booth"].first_img();
83-
pavilion_m.musician_tile_s = pavilion_m.anim["stand_sn_s"].first_img();
84-
pavilion_m.musician_tile_e = pavilion_m.anim["stand_sn_e"].first_img();
85-
}
86-
8783
void building_pavilion::on_create(int orientation) {
8884

8985
}
@@ -109,7 +105,7 @@ void building_pavilion::on_place_update_tiles(int orientation, int variant) {
109105
data.entertainment.orientation = orientation;
110106

111107
int size = pavilion_m.building_size;
112-
int image_id = pavilion_m.anim["square"].first_img();
108+
int image_id = anim(animkeys().square).first_img();
113109

114110
int basic_orientation;
115111
map_orientation_for_venue_with_map_orientation(tile(), e_venue_mode_pavilion, &basic_orientation);
@@ -130,23 +126,23 @@ void building_pavilion::on_place_checks() {
130126

131127
bool building_pavilion::draw_ornaments_and_animations_height(painter &ctx, vec2i point, tile2i tile, color color_mask) {
132128
if (data.entertainment.dancer_visited && map_image_at(tile) == pavilion_m.dancer_tile) {
133-
const animation_t &anim = pavilion_m.anim["dancer"];
134-
building_draw_normal_anim(ctx, point, &base, tile, anim, color_mask);
129+
const animation_t &ranim = anim(animkeys().dancer);
130+
building_draw_normal_anim(ctx, point, &base, tile, ranim, color_mask);
135131
}
136132

137133
if (data.entertainment.musician_visited) {
138134
if (map_image_at(tile) == pavilion_m.musician_tile_s) {
139-
const animation_t &anim = pavilion_m.anim["musician_sn"];
140-
building_draw_normal_anim(ctx, point, &base, tile, anim, color_mask);
135+
const animation_t &ranim = anim(animkeys().musician_sn);
136+
building_draw_normal_anim(ctx, point, &base, tile, ranim, color_mask);
141137
} else if (map_image_at(tile) == pavilion_m.musician_tile_e) {
142-
const animation_t &anim = pavilion_m.anim["musician_we"];
143-
building_draw_normal_anim(ctx, point, &base, tile, anim, color_mask);
138+
const animation_t &ranim = anim(animkeys().musician_we);
139+
building_draw_normal_anim(ctx, point, &base, tile, ranim, color_mask);
144140
}
145141
}
146142

147143
if (data.entertainment.juggler_visited && map_image_at(tile) == pavilion_m.booth_tile) {
148-
const animation_t &anim = pavilion_m.anim["juggler"];
149-
building_draw_normal_anim(ctx, point, &base, tile, anim, color_mask);
144+
const animation_t &ranim = anim(animkeys().juggler);
145+
building_draw_normal_anim(ctx, point, &base, tile, ranim, color_mask);
150146
}
151147

152148
return true;
@@ -181,15 +177,17 @@ void building_pavilion::spawn_figure() {
181177

182178
void building_pavilion::ghost_preview(painter &ctx, tile2i tile, vec2i pixel, int orientation) {
183179
int size = pavilion_m.building_size;
184-
int square_id = building_impl::params(BUILDING_PAVILLION).anim["square"].first_img();
180+
const auto &params = building_impl::params(BUILDING_PAVILLION);
181+
int square_id = params.anim[animkeys().square].first_img();
185182
for (int i = 0; i < size * size; i++) {
186183
ImageDraw::isometric(ctx, square_id + i, pixel + vec2i{((i % size) - (i / size)) * 30, ((i % size) + (i / size)) * 15}, COLOR_MASK_GREEN);
187184
}
188-
int stand_sn_n = pavilion_m.anim["stand_sn_n"].first_img();
189-
int stand_sn_s = pavilion_m.anim["stand_sn_s"].first_img();
190-
int booth = pavilion_m.anim["booth"].first_img();
191-
int stand = pavilion_m.anim["base"].first_img();
185+
int stand_sn_n = params.anim[animkeys().stand_sn_n].first_img();
186+
int stand_sn_s = params.anim[animkeys().stand_sn_s].first_img();
187+
int booth = params.anim[animkeys().booth].first_img();
188+
int stand = params.anim[animkeys().base].first_img();
192189
const auto &preview_conf = pavilion_m.preview_dir[orientation];
190+
193191
draw_building_ghost(ctx, stand, pixel + preview_conf.stand, COLOR_MASK_GREEN);
194192
draw_building_ghost(ctx, stand_sn_n + preview_conf.stand_b_img, pixel + preview_conf.stand_b, COLOR_MASK_GREEN);
195193
draw_building_ghost(ctx, stand_sn_s + preview_conf.stand_e_img, pixel + preview_conf.stand_e, COLOR_MASK_GREEN);
@@ -199,8 +197,9 @@ void building_pavilion::ghost_preview(painter &ctx, tile2i tile, vec2i pixel, in
199197
void building_pavilion::on_undo() {
200198
for (int dy = 0; dy < 4; dy++) {
201199
for (int dx = 0; dx < 4; dx++) {
202-
if (map_building_at(data.entertainment.booth_corner_grid_offset + GRID_OFFSET(dx, dy)) == 0)
203-
map_building_set(data.entertainment.booth_corner_grid_offset + GRID_OFFSET(dx, dy), id());
200+
const uint32_t offset = data.entertainment.booth_corner_grid_offset + GRID_OFFSET(dx, dy);
201+
if (map_building_at(offset) == 0)
202+
map_building_set(offset, id());
204203
}
205204
}
206205
}

src/graphics/animkeys.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ const xstring id_anim_t::wait_s = "wait_s";
3131
const xstring id_anim_t::wait_e = "wait_e";
3232
const xstring id_anim_t::eating = "eating";
3333
const xstring id_anim_t::idle = "idle";
34+
const xstring id_anim_t::booth = "booth";
35+
const xstring id_anim_t::stand_sn_s = "stand_sn_s";
36+
const xstring id_anim_t::stand_sn_n = "stand_sn_n";
37+
const xstring id_anim_t::stand_sn_e = "stand_sn_e";
38+
const xstring id_anim_t::dancer = "dancer";
39+
const xstring id_anim_t::musician_sn = "musician_sn";
40+
const xstring id_anim_t::musician_we = "musician_we";
3441
const xstring id_anim_t::attack = "attack";
3542
const xstring id_anim_t::farmland = "farmland";
3643
const xstring id_anim_t::square = "square";

src/graphics/animkeys.h

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ struct id_anim_t {
3333
static const xstring wait_e;
3434
static const xstring eating;
3535
static const xstring idle;
36+
static const xstring booth;
37+
static const xstring stand_sn_s;
38+
static const xstring stand_sn_n;
39+
static const xstring stand_sn_e;
40+
static const xstring dancer;
41+
static const xstring musician_sn;
42+
static const xstring musician_we;
3643
static const xstring attack;
3744
static const xstring farmland;
3845
static const xstring square;

0 commit comments

Comments
 (0)