1 #include "religion.h"
2
3 #include "assets/assets.h"
4 #include "building/count.h"
5 #include "city/festival.h"
6 #include "city/gods.h"
7 #include "city/houses.h"
8 #include "game/settings.h"
9 #include "graphics/generic_button.h"
10 #include "graphics/image.h"
11 #include "graphics/lang_text.h"
12 #include "graphics/panel.h"
13 #include "graphics/text.h"
14 #include "window/hold_festival.h"
15
16 static void button_hold_festival(int param1, int param2);
17
18 static generic_button hold_festival_button[] = {
19 {102, 340, 300, 20, button_hold_festival, button_none, 0, 0},
20 };
21
22 static int focus_button_id;
23
get_religion_advice(void)24 static int get_religion_advice(void)
25 {
26 int least_happy = city_god_least_happy();
27 const house_demands *demands = city_houses_demands();
28 if (least_happy >= 0 && city_god_wrath_bolts(least_happy) > 4) {
29 return 6 + least_happy;
30 } else if (demands->religion == 1) {
31 return demands->requiring.religion ? 1 : 0;
32 } else if (demands->religion == 2) {
33 return 2;
34 } else if (demands->religion == 3) {
35 return 3;
36 } else if (!demands->requiring.religion) {
37 return 4;
38 } else if (least_happy >= 0) {
39 return 6 + least_happy;
40 } else {
41 return 5;
42 }
43 }
44
draw_god_row(god_type god,int y_offset,building_type small_temple,building_type large_temple,building_type grand_temple)45 static void draw_god_row(god_type god, int y_offset, building_type small_temple,
46 building_type large_temple, building_type grand_temple)
47 {
48 lang_text_draw(59, 11 + god, 40, y_offset, FONT_NORMAL_WHITE);
49 lang_text_draw(59, 16 + god, 120, y_offset + 1, FONT_SMALL_PLAIN);
50 text_draw_number_centered(building_count_active(small_temple), 230, y_offset, 50, FONT_NORMAL_WHITE);
51 if (building_count_active(grand_temple)) {
52 text_draw_number_centered(building_count_active(large_temple) + building_count_active(grand_temple),
53 290, y_offset, 50, FONT_NORMAL_GREEN);
54 } else {
55 text_draw_number_centered(building_count_active(large_temple), 290, y_offset, 50, FONT_NORMAL_WHITE);
56 }
57 text_draw_number_centered(city_god_months_since_festival(god), 360, y_offset, 50, FONT_NORMAL_WHITE);
58 int width = lang_text_draw(59, 32 + city_god_happiness(god) / 10, 460, y_offset, FONT_NORMAL_WHITE);
59 int bolts = city_god_wrath_bolts(god);
60 for (int i = 0; i < bolts / 10; i++) {
61 image_draw(image_group(GROUP_GOD_BOLT), 10 * i + width + 460, y_offset - 4);
62 }
63 int happy_bolts = city_god_happy_bolts(god);
64 for (int i = 0; i < happy_bolts; i++) {
65 image_draw(assets_get_image_id("UI_Elements", "Happy God Icon"),
66 10 * i + width + 460, y_offset - 4);
67 }
68 }
69
draw_oracle_row(void)70 static void draw_oracle_row(void)
71 {
72 int oracle_count = building_count_active(BUILDING_ORACLE) + building_count_active(BUILDING_SMALL_MAUSOLEUM);
73 int large_oracle_count = building_count_active(BUILDING_NYMPHAEUM) +
74 building_count_active(BUILDING_PANTHEON) + building_count_active(BUILDING_LARGE_MAUSOLEUM);
75 lang_text_draw(59, 8, 40, 166, FONT_NORMAL_WHITE);
76 text_draw_number_centered(oracle_count, 230, 166, 50, FONT_NORMAL_WHITE);
77 if (building_count_active(BUILDING_PANTHEON)) {
78 text_draw_number_centered(large_oracle_count, 290, 166, 50, FONT_NORMAL_GREEN);
79 } else {
80 text_draw_number_centered(large_oracle_count, 290, 166, 50, FONT_NORMAL_WHITE);
81 }
82 }
83
draw_lararium_row(void)84 static void draw_lararium_row(void)
85 {
86 text_draw(translation_for(TR_WINDOW_ADVISOR_RELIGION_LARARIUMS), 40, 186, FONT_NORMAL_WHITE, 0);
87 text_draw_number_centered(building_count_total(BUILDING_LARARIUM), 230, 186, 50, FONT_NORMAL_WHITE);
88 }
89
get_festival_advice(void)90 static int get_festival_advice(void)
91 {
92 int months_since_festival = city_festival_months_since_last();
93 if (months_since_festival <= 1) {
94 return 0;
95 } else if (months_since_festival <= 6) {
96 return 1;
97 } else if (months_since_festival <= 12) {
98 return 2;
99 } else if (months_since_festival <= 18) {
100 return 3;
101 } else if (months_since_festival <= 24) {
102 return 4;
103 } else if (months_since_festival <= 30) {
104 return 5;
105 } else {
106 return 6;
107 }
108 }
109
draw_festival_info(void)110 static void draw_festival_info(void)
111 {
112 inner_panel_draw(48, 302, 34, 6);
113 image_draw(image_group(GROUP_PANEL_WINDOWS) + 15, 460, 305);
114 lang_text_draw(58, 17, 52, 274, FONT_LARGE_BLACK);
115
116 int width = lang_text_draw_amount(8, 4, city_festival_months_since_last(), 112, 315, FONT_NORMAL_WHITE);
117 lang_text_draw(58, 15, 112 + width, 315, FONT_NORMAL_WHITE);
118 if (city_festival_is_planned()) {
119 lang_text_draw_centered(58, 34, 102, 339, 300, FONT_NORMAL_WHITE);
120 } else {
121 lang_text_draw_centered(58, 16, 102, 339, 300, FONT_NORMAL_WHITE);
122 }
123 lang_text_draw_multiline(58, 18 + get_festival_advice(), 56, 360, 400, FONT_NORMAL_WHITE);
124 }
125
draw_background(void)126 static int draw_background(void)
127 {
128 int height_blocks;
129 height_blocks = 27;
130 outer_panel_draw(0, 0, 40, height_blocks);
131
132 image_draw(image_group(GROUP_ADVISOR_ICONS) + 9, 10, 10);
133
134 lang_text_draw(59, 0, 60, 12, FONT_LARGE_BLACK);
135
136 // table header
137 lang_text_draw(59, 5, 270, 32, FONT_SMALL_PLAIN);
138 lang_text_draw(59, 1, 240, 46, FONT_SMALL_PLAIN);
139 lang_text_draw(59, 2, 300, 46, FONT_SMALL_PLAIN);
140 lang_text_draw(59, 3, 450, 46, FONT_SMALL_PLAIN);
141 lang_text_draw(59, 6, 370, 18, FONT_SMALL_PLAIN);
142 lang_text_draw(59, 9, 370, 32, FONT_SMALL_PLAIN);
143 lang_text_draw(59, 7, 370, 46, FONT_SMALL_PLAIN);
144
145 inner_panel_draw(32, 60, 36, 9);
146
147 // god rows
148 draw_god_row(GOD_CERES, 66, BUILDING_SMALL_TEMPLE_CERES,
149 BUILDING_LARGE_TEMPLE_CERES, BUILDING_GRAND_TEMPLE_CERES);
150 draw_god_row(GOD_NEPTUNE, 86, BUILDING_SMALL_TEMPLE_NEPTUNE,
151 BUILDING_LARGE_TEMPLE_NEPTUNE, BUILDING_GRAND_TEMPLE_NEPTUNE);
152 draw_god_row(GOD_MERCURY, 106, BUILDING_SMALL_TEMPLE_MERCURY,
153 BUILDING_LARGE_TEMPLE_MERCURY, BUILDING_GRAND_TEMPLE_MERCURY);
154 draw_god_row(GOD_MARS, 126, BUILDING_SMALL_TEMPLE_MARS,
155 BUILDING_LARGE_TEMPLE_MARS, BUILDING_GRAND_TEMPLE_MARS);
156 draw_god_row(GOD_VENUS, 146, BUILDING_SMALL_TEMPLE_VENUS,
157 BUILDING_LARGE_TEMPLE_VENUS, BUILDING_GRAND_TEMPLE_VENUS);
158
159 // oracles
160 draw_oracle_row();
161
162 // larariums
163 draw_lararium_row();
164
165 city_gods_calculate_least_happy();
166
167 lang_text_draw_multiline(59, 21 + get_religion_advice(), 60, 216, 512, FONT_NORMAL_BLACK);
168
169 draw_festival_info();
170
171 return height_blocks;
172 }
173
draw_foreground(void)174 static void draw_foreground(void)
175 {
176 if (!city_festival_is_planned()) {
177 button_border_draw(102, 335, 300, 20, focus_button_id == 1);
178 }
179 }
180
handle_mouse(const mouse * m)181 static int handle_mouse(const mouse *m)
182 {
183 return generic_buttons_handle_mouse(m, 0, 0, hold_festival_button, 1, &focus_button_id);
184 }
185
button_hold_festival(int param1,int param2)186 static void button_hold_festival(int param1, int param2)
187 {
188 if (!city_festival_is_planned()) {
189 window_hold_festival_show();
190 }
191 }
192
get_tooltip_text(advisor_tooltip_result * r)193 static void get_tooltip_text(advisor_tooltip_result *r)
194 {
195 if (focus_button_id) {
196 r->text_id = 112;
197 }
198 }
199
window_advisor_religion(void)200 const advisor_window_type *window_advisor_religion(void)
201 {
202 static const advisor_window_type window = {
203 draw_background,
204 draw_foreground,
205 handle_mouse,
206 get_tooltip_text
207 };
208 focus_button_id = 0;
209 return &window;
210 }
211