Skip to content

Commit 1d2d85b

Browse files
author
s.kushnirenko
committed
buildings: statue config variants redesigned, make it with model paradigm
1 parent 76fa837 commit 1d2d85b

13 files changed

+121
-99
lines changed

src/building/building.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,6 @@ static void building_new_fill_in_data_for_type(building* b, e_building_type type
245245
b->subtype.market_goods = 0x0000;
246246
break;
247247

248-
case BUILDING_SMALL_STATUE:
249-
case BUILDING_MEDIUM_STATUE:
250-
case BUILDING_LARGE_STATUE: {
251-
int orientation = (4 + building_rotation_global_rotation() + city_view_orientation() / 2) % 4;
252-
b->data.monuments.variant = building_rotation_get_building_variant();
253-
b->data.monuments.statue_offset = rand() % 4;
254-
}
255-
break;
256-
257248
case BUILDING_TEMPLE_COMPLEX_OSIRIS:
258249
case BUILDING_TEMPLE_COMPLEX_RA:
259250
case BUILDING_TEMPLE_COMPLEX_PTAH:
@@ -346,6 +337,12 @@ building_impl *building::dcast() {
346337
_ptr = new building_tax_collector(*this);
347338
break;
348339

340+
case BUILDING_SMALL_STATUE:
341+
case BUILDING_MEDIUM_STATUE:
342+
case BUILDING_LARGE_STATUE:
343+
_ptr = new building_statue(*this);
344+
break;
345+
349346
case BUILDING_SHRINE_OSIRIS:
350347
case BUILDING_SHRINE_RA:
351348
case BUILDING_SHRINE_PTAH:

src/building/building_pottery.h

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class building_pottery : public building_impl {
66
public:
77
building_pottery(building &b) : building_impl(b) {}
88
virtual void on_create() override;
9+
virtual bool is_workshop() const override { return true; }
910
virtual void window_info_background(object_info &c) override;
1011
virtual bool draw_ornaments_and_animations_height(painter &ctx, vec2i point, tile2i tile, color color_mask) override;
1112
};

src/building/building_statue.cpp

+67-54
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "building_statue.h"
22

33
#include "building/building.h"
4+
#include "building/rotation.h"
45
#include "city/object_info.h"
56
#include "game/resource.h"
67
#include "graphics/elements/panel.h"
@@ -15,53 +16,70 @@
1516

1617
#include "js/js_game.h"
1718

18-
void building_statue_draw_info(object_info &c) {
19+
namespace model {
20+
struct small_statue_t {
21+
std::vector<image_desc> var;
22+
};
23+
small_statue_t small_statue;
24+
25+
struct medium_statue_t {
26+
std::vector<image_desc> var;
27+
};
28+
medium_statue_t medium_statue;
29+
30+
struct big_statue_t {
31+
std::vector<image_desc> var;
32+
};
33+
big_statue_t big_statue;
34+
35+
template<typename T>
36+
void config_load_statue(pcstr key, T& model) {
37+
model.var.clear();
38+
g_config_arch.r_section(key, [&model] (archive model_arch) {
39+
model_arch.r_array("variants", [&model] (archive arch) {
40+
int pack = arch.r_int("pack");
41+
int id = arch.r_int("id");
42+
int offset = arch.r_int("offset");
43+
model.var.push_back({pack, id, offset});
44+
});
45+
});
46+
}
47+
}
48+
49+
void building_statue::on_create() {
50+
int orientation = (4 + building_rotation_global_rotation() + city_view_orientation() / 2) % 4;
51+
data.monuments.variant = building_rotation_get_building_variant();
52+
data.monuments.statue_offset = rand() % 4;
53+
}
54+
55+
void building_statue::window_info_background(object_info &c) {
1956
c.help_id = 79;
2057
window_building_play_sound(&c, snd::get_building_info_sound("statue"));
2158
outer_panel_draw(c.offset, c.width_blocks, c.height_blocks);
2259
lang_text_draw_centered(80, 0, c.offset.x, c.offset.y + 10, 16 * c.width_blocks, FONT_LARGE_BLACK_ON_LIGHT);
2360
window_building_draw_description_at(c, 16 * c.height_blocks - 158, 80, 1);
2461
}
2562

26-
svector<image_desc, 10> small_statues_img;
27-
svector<image_desc, 10> medium_statue_images;
28-
svector<image_desc, 10> big_statues_img;
29-
30-
ANK_REGISTER_CONFIG_ITERATOR(config_load_small_statue_images);
31-
ANK_REGISTER_CONFIG_ITERATOR(config_load_medium_statue_images);
32-
ANK_REGISTER_CONFIG_ITERATOR(config_load_big_statue_images);
33-
34-
template<typename T>
35-
void config_load_statue_images_t(pcstr key, T& config) {
36-
config.clear();
37-
g_config_arch.r_array(key, [&] (archive arch) {
38-
int pack = arch.r_int("pack");
39-
int id = arch.r_int("id");
40-
int offset = arch.r_int("offset");
41-
config.push_back({pack, id, offset});
42-
});
43-
}
63+
ANK_REGISTER_CONFIG_ITERATOR(config_load_statue_models);
4464

45-
void config_load_small_statue_images() {
46-
config_load_statue_images_t("small_statue_images", small_statues_img);
65+
void config_load_statue_models() {
66+
model::config_load_statue("building_small_statue", model::small_statue);
67+
model::config_load_statue("building_medium_statue", model::medium_statue);
68+
model::config_load_statue("building_big_statue", model::big_statue);
4769
}
4870

49-
void config_load_medium_statue_images() {
50-
config_load_statue_images_t("medium_statue_images", medium_statue_images);
51-
}
71+
int building_statue_get_variant_size(int type) {
72+
switch (type) {
73+
case BUILDING_SMALL_STATUE: return model::small_statue.var.size(); break;
74+
case BUILDING_MEDIUM_STATUE: return model::medium_statue.var.size(); break;
75+
case BUILDING_LARGE_STATUE: return model::big_statue.var.size(); break;
76+
}
5277

53-
void config_load_big_statue_images() {
54-
config_load_statue_images_t("big_statue_images", big_statues_img);
78+
return 0;
5579
}
5680

5781
int building_statue_random_variant(int type, int variant) {
58-
int size = 1;
59-
switch (type) {
60-
case BUILDING_SMALL_STATUE: size = small_statues_img.size(); break;
61-
case BUILDING_MEDIUM_STATUE: size = medium_statue_images.size(); break;
62-
case BUILDING_LARGE_STATUE: size = big_statues_img.size(); break;
63-
}
64-
82+
int size = building_statue_get_variant_size(type);
6583
return rand() % size;
6684
}
6785

@@ -70,13 +88,7 @@ int building_statue_next_variant(int type, int variant) {
7088
return 0;
7189
}
7290

73-
int size = 0;
74-
switch (type) {
75-
case BUILDING_SMALL_STATUE: size = small_statues_img.size(); break;
76-
case BUILDING_MEDIUM_STATUE: size = medium_statue_images.size(); break;
77-
case BUILDING_LARGE_STATUE: size = big_statues_img.size(); break;
78-
}
79-
91+
int size = building_statue_get_variant_size(type);
8092
if (!size) {
8193
return variant;
8294
}
@@ -88,27 +100,28 @@ int building_statue_next_variant(int type, int variant) {
88100
int building_statue_get_image(int type, int orientation, int variant) {
89101
int image_id = 0;
90102

91-
while (orientation < 0)
92-
orientation += 4;
93-
while (orientation > 3)
94-
orientation -= 4;
95-
while (variant < 0)
96-
variant += 4;
97-
while (variant > 3)
98-
variant -= 4;
103+
int size = building_statue_get_variant_size(type);
104+
//
105+
while (orientation < 0) { orientation += 4; }
106+
//
107+
while (orientation > 3) { orientation -= 4; }
108+
109+
while (variant < 0) { variant += 4; }
110+
111+
while (variant > (size - 1)) { variant -= size; }
99112

100113
switch (type) {
101114
case BUILDING_SMALL_STATUE:
102-
variant %= small_statues_img.size();
103-
return image_group(small_statues_img[variant]);
115+
variant %= size;
116+
return image_group(model::small_statue.var[variant]);
104117

105118
case BUILDING_MEDIUM_STATUE:
106-
variant %= medium_statue_images.size();
107-
return image_group(medium_statue_images[variant]);
119+
variant %= size;
120+
return image_group(model::medium_statue.var[variant]);
108121

109122
case BUILDING_LARGE_STATUE:
110-
variant %= big_statues_img.size();
111-
return image_group(big_statues_img[variant]);
123+
variant %= size;
124+
return image_group(model::big_statue.var[variant]);
112125
}
113126

114127
return image_id;

src/building/building_statue.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
#pragma once
22

3-
struct object_info;
3+
#include "building/building.h"
44

5-
void building_statue_draw_info(object_info &c);
5+
class building_statue : public building_impl {
6+
public:
7+
building_statue(building &b) : building_impl(b) {}
8+
virtual void on_create() override;
9+
virtual bool is_workshop() const override { return true; }
10+
virtual void window_info_background(object_info &c) override;
11+
virtual e_sound_channel_city sound_channel() const { return SOUND_CHANNEL_CITY_STATUE; }
12+
};
613

714
int building_statue_random_variant(int type, int variant);
815
int building_statue_next_variant(int type, int variant);

src/building/building_tax_collector.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class building_tax_collector : public building_impl {
66
public:
77
building_tax_collector(building &b) : building_impl(b) {}
8-
virtual bool is_workshop() const override { return true; }
8+
virtual bool is_workshop() const override { return false; }
99
virtual void window_info_background(object_info &c) override;
1010
virtual e_overlay get_overlay() const override { return OVERLAY_TAX_INCOME; }
1111
virtual void update_month() override;

src/building/construction/build_planner.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,9 @@ void BuildPlanner::update_orientations(bool check_if_changed) {
17261726
relative_orientation = global_rotation + 1;
17271727
variant = 0;
17281728
break;
1729+
1730+
default:
1731+
break;
17291732
}
17301733
relative_orientation = relative_orientation % 4;
17311734
absolute_orientation = city_view_absolute_orientation(relative_orientation);

src/scripts/building_info.js

+28
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,34 @@ building_info = [
2525
{ help_id:92, type:"bricklayers_guild", text_id:172},
2626
]
2727

28+
building_small_statue = {
29+
variants : [
30+
{pack: PACK_GENERAL, id: 61, offset:1},
31+
{pack: PACK_GENERAL, id: 61, offset:5},
32+
{pack: PACK_EXPANSION, id: 37, offset:1},
33+
{pack: PACK_EXPANSION, id: 37, offset:5},
34+
{pack: PACK_TEMPLE_RA, id: 1, offset:27},
35+
]
36+
}
37+
38+
building_medium_statue = {
39+
variants : [
40+
{pack: PACK_GENERAL, id: 8, offset:1},
41+
{pack: PACK_GENERAL, id: 8, offset:5},
42+
{pack: PACK_EXPANSION, id: 36, offset:1},
43+
{pack: PACK_EXPANSION, id: 36, offset:5},
44+
]
45+
}
46+
47+
building_big_statue = {
48+
variants : [
49+
{pack: PACK_GENERAL, id: 7, offset:1},
50+
{pack: PACK_GENERAL, id: 7, offset:5},
51+
{pack: PACK_EXPANSION, id: 35, offset:1},
52+
{pack: PACK_EXPANSION, id: 35, offset:5},
53+
]
54+
}
55+
2856
building_personal_mansion = {
2957
animations : {
3058
work : { pos : [-1, -1], anim_id: IMG_PERSONAL_MANSION }

src/scripts/common.js

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ var medium_statue_images = []
2222
var big_statue_images = []
2323
var top_menu_bar = {}
2424
var main_menu_window = {}
25+
var building_small_statue = {}
26+
var building_medium_statue = {}
27+
var building_big_statue = {}
2528
var building_booth = {}
2629
var building_conservatory = {}
2730
var building_pottery = {}

src/scripts/images.js

-22
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
11
log_info("akhenaten: images started")
22

3-
small_statue_images = [
4-
{pack: PACK_GENERAL, id: 61, offset:1},
5-
{pack: PACK_GENERAL, id: 61, offset:5},
6-
{pack: PACK_EXPANSION, id: 37, offset:1},
7-
{pack: PACK_EXPANSION, id: 37, offset:5},
8-
{pack: PACK_TEMPLE_RA, id: 1, offset:27},
9-
]
10-
11-
medium_statue_images = [
12-
{pack: PACK_GENERAL, id: 8, offset:1},
13-
{pack: PACK_GENERAL, id: 8, offset:5},
14-
{pack: PACK_EXPANSION, id: 36, offset:1},
15-
{pack: PACK_EXPANSION, id: 36, offset:5},
16-
]
17-
18-
big_statue_images = [
19-
{pack: PACK_GENERAL, id: 7, offset:1},
20-
{pack: PACK_GENERAL, id: 7, offset:5},
21-
{pack: PACK_EXPANSION, id: 35, offset:1},
22-
{pack: PACK_EXPANSION, id: 35, offset:5},
23-
]
24-
253
images = [
264
{img: IMG_IMMIGRANT, pack: PACK_SPR_MAIN, id: 14},// 886
275
//{img: IMG_IMMIGRANT_DEATH, pack: PACK_SPR_MAIN, id: 15} // 982

src/sound/city.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,6 @@ int building_type_to_channel(building *b) {
8989
case BUILDING_DANCE_SCHOOL: return SOUND_CHANNEL_CITY_DANCE_SCHOOL;
9090
case BUILDING_GARDENS: return SOUND_CHANNEL_CITY_GARDEN;
9191

92-
case BUILDING_SMALL_STATUE:
93-
case BUILDING_MEDIUM_STATUE:
94-
case BUILDING_LARGE_STATUE:
95-
return SOUND_CHANNEL_CITY_STATUE;
96-
9792
case BUILDING_APOTHECARY: return SOUND_CHANNEL_CITY_APOTHECARY;
9893
case BUILDING_MORTUARY: return SOUND_CHANNEL_CITY_MORTUARY;
9994
case BUILDING_DENTIST: return SOUND_CHANNEL_CITY_DENTIST;

src/widget/debug_console.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "imgui/backends/imgui_impl_sdlrenderer.h"
1616
#include "imgui/backends/imgui_impl_sdl.h"
1717

18+
#include <iostream>
19+
1820
dev::imgui_qconsole *_debug_console = nullptr;
1921

2022
dev::imgui_qconsole &debug_console() {

src/widget/debug_console.h

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "core/string.h"
44

55
#include <functional>
6+
#include <iosfwd>
67

78
void game_debug_cli_draw();
89
void game_debug_cli_message(pcstr msg);

src/window/window_building_info.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -616,12 +616,6 @@ static void draw_refresh_background() {
616616
case BUILDING_WATER_LIFT: window_building_draw_water_lift(&context); break;
617617
case BUILDING_MENU_BEAUTIFICATION: window_building_draw_fountain(&context); break;
618618

619-
case BUILDING_SMALL_STATUE:
620-
case BUILDING_MEDIUM_STATUE:
621-
case BUILDING_LARGE_STATUE:
622-
building_statue_draw_info(context);
623-
break;
624-
625619
case BUILDING_RESERVED_TRIUMPHAL_ARCH_56: window_building_draw_triumphal_arch(&context); break;
626620
case BUILDING_POLICE_STATION: window_building_draw_prefect(&context); break;
627621

0 commit comments

Comments
 (0)