1
1
#include " building_statue.h"
2
2
3
3
#include " building/building.h"
4
+ #include " building/rotation.h"
4
5
#include " city/object_info.h"
5
6
#include " game/resource.h"
6
7
#include " graphics/elements/panel.h"
15
16
16
17
#include " js/js_game.h"
17
18
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) {
19
56
c.help_id = 79 ;
20
57
window_building_play_sound (&c, snd::get_building_info_sound (" statue" ));
21
58
outer_panel_draw (c.offset , c.width_blocks , c.height_blocks );
22
59
lang_text_draw_centered (80 , 0 , c.offset .x , c.offset .y + 10 , 16 * c.width_blocks , FONT_LARGE_BLACK_ON_LIGHT);
23
60
window_building_draw_description_at (c, 16 * c.height_blocks - 158 , 80 , 1 );
24
61
}
25
62
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);
44
64
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);
47
69
}
48
70
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
+ }
52
77
53
- void config_load_big_statue_images () {
54
- config_load_statue_images_t (" big_statue_images" , big_statues_img);
78
+ return 0 ;
55
79
}
56
80
57
81
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);
65
83
return rand () % size;
66
84
}
67
85
@@ -70,13 +88,7 @@ int building_statue_next_variant(int type, int variant) {
70
88
return 0 ;
71
89
}
72
90
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);
80
92
if (!size) {
81
93
return variant;
82
94
}
@@ -88,27 +100,28 @@ int building_statue_next_variant(int type, int variant) {
88
100
int building_statue_get_image (int type, int orientation, int variant) {
89
101
int image_id = 0 ;
90
102
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; }
99
112
100
113
switch (type) {
101
114
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]);
104
117
105
118
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]);
108
121
109
122
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]);
112
125
}
113
126
114
127
return image_id;
0 commit comments