1 #include "festival.h"
2 
3 #include "building/warehouse.h"
4 #include "building/monument.h"
5 #include "core/calc.h"
6 #include "city/constants.h"
7 #include "city/data_private.h"
8 #include "city/emperor.h"
9 #include "city/finance.h"
10 #include "city/message.h"
11 #include "city/sentiment.h"
12 #include "core/config.h"
13 #include "game/time.h"
14 
15 auto_festival autofestivals[5] = {
16     {0, 3}, // ceres, april
17     {1, 6}, // neptune, july
18     {2, 4}, // mercury, may
19     {3, 2}, // mars, march
20     {4, 3}, // venus, april
21 };
22 
city_festival_is_planned(void)23 int city_festival_is_planned(void)
24 {
25     return city_data.festival.planned.size != FESTIVAL_NONE;
26 }
27 
city_festival_months_since_last(void)28 int city_festival_months_since_last(void)
29 {
30     return city_data.festival.months_since_festival;
31 }
32 
city_festival_small_cost(void)33 int city_festival_small_cost(void)
34 {
35     return city_data.festival.small_cost;
36 }
37 
city_festival_large_cost(void)38 int city_festival_large_cost(void)
39 {
40     return city_data.festival.large_cost;
41 }
42 
city_festival_grand_cost(void)43 int city_festival_grand_cost(void)
44 {
45     return city_data.festival.grand_cost;
46 }
47 
city_festival_grand_wine(void)48 int city_festival_grand_wine(void)
49 {
50     return city_data.festival.grand_wine;
51 }
52 
city_festival_out_of_wine(void)53 int city_festival_out_of_wine(void)
54 {
55     return city_data.festival.not_enough_wine;
56 }
57 
city_festival_selected_god(void)58 int city_festival_selected_god(void)
59 {
60     return city_data.festival.selected.god;
61 }
62 
city_festival_select_god(int god_id)63 void city_festival_select_god(int god_id)
64 {
65     city_data.festival.selected.god = god_id;
66 }
67 
city_festival_selected_size(void)68 int city_festival_selected_size(void)
69 {
70     return city_data.festival.selected.size;
71 }
72 
city_festival_selected_game_id(void)73 int city_festival_selected_game_id(void)
74 {
75     return city_data.games.selected_games_id;
76 }
77 
city_festival_games_active(void)78 int city_festival_games_active(void)
79 {
80     if (city_data.games.games_is_active) {
81         return city_data.games.selected_games_id;
82     }
83     return 0;
84 }
85 
city_festival_games_active_venue_type(void)86 int city_festival_games_active_venue_type(void)
87 {
88     if (city_data.games.games_is_active) {
89         return city_data.games.selected_games_id <= 3 ? BUILDING_COLOSSEUM : BUILDING_HIPPODROME;
90     }
91     return 0;
92 }
93 
city_festival_games_bonus_active(int game_id)94 int city_festival_games_bonus_active(int game_id)
95 {
96     switch (game_id) {
97         case 1:
98             return city_data.games.naval_battle_bonus_months;
99         case 2:
100             return city_data.games.executions_bonus_months;
101         case 3:
102             return city_data.games.imperial_games_bonus_months;
103         case 4:
104             return city_data.games.games_4_bonus_months;
105         default:
106             return 0;
107     }
108 }
109 
city_festival_games_remaining_duration(void)110 int city_festival_games_remaining_duration(void)
111 {
112     return city_data.games.remaining_duration;
113 }
114 
city_festival_games_planning_time(void)115 int city_festival_games_planning_time(void)
116 {
117     return city_data.games.months_to_go;
118 }
119 
city_festival_games_cooldown(void)120 int city_festival_games_cooldown(void)
121 {
122     return 0; //calc_bound(36 - city_data.games.months_since_last, 0, 36);
123 }
124 
city_festival_select_size(int size)125 int city_festival_select_size(int size)
126 {
127     if (size == FESTIVAL_GRAND && city_data.festival.not_enough_wine) {
128         return 0;
129     }
130     city_data.festival.selected.size = size;
131     return 1;
132 }
133 
city_festival_schedule(void)134 void city_festival_schedule(void)
135 {
136     city_data.festival.planned.god = city_data.festival.selected.god;
137     city_data.festival.planned.size = city_data.festival.selected.size;
138     int cost;
139     if (city_data.festival.selected.size == FESTIVAL_SMALL) {
140         city_data.festival.planned.months_to_go = 2;
141         cost = city_data.festival.small_cost;
142     } else if (city_data.festival.selected.size == FESTIVAL_LARGE) {
143         city_data.festival.planned.months_to_go = 3;
144         cost = city_data.festival.large_cost;
145     } else {
146         city_data.festival.planned.months_to_go = 4;
147         cost = city_data.festival.grand_cost;
148     }
149 
150     city_finance_process_sundry(cost);
151 
152     if (city_data.festival.selected.size == FESTIVAL_GRAND) {
153         int wine_needed = city_data.festival.grand_wine;
154         if (building_monument_gt_module_is_active(VENUS_MODULE_1_DISTRIBUTE_WINE)) {
155             building *venus_gt = building_get(building_monument_get_venus_gt());
156             if (wine_needed <= venus_gt->loads_stored) {
157                 venus_gt->loads_stored -= wine_needed;
158                 wine_needed = 0;
159             } else {
160                 wine_needed -= venus_gt->loads_stored;
161                 venus_gt->loads_stored = 0;
162             }
163         }
164         building_warehouses_remove_resource(RESOURCE_WINE, wine_needed);
165     }
166 }
167 
festival_sentiment_and_deity(int size,int god_id)168 void festival_sentiment_and_deity(int size, int god_id)
169 {
170     if (city_data.festival.first_festival_effect_months <= 0) {
171         city_data.festival.first_festival_effect_months = 12;
172         switch (size) {
173             case FESTIVAL_SMALL: city_data.sentiment.blessing_festival_boost += 6; break;
174             case FESTIVAL_LARGE: city_data.sentiment.blessing_festival_boost += 9; break;
175             case FESTIVAL_GRAND: city_data.sentiment.blessing_festival_boost += 18; break;
176         }
177     } else if (city_data.festival.second_festival_effect_months <= 0) {
178         city_data.festival.second_festival_effect_months = 12;
179         switch (size) {
180             case FESTIVAL_SMALL: city_data.sentiment.blessing_festival_boost += 2; break;
181             case FESTIVAL_LARGE: city_data.sentiment.blessing_festival_boost += 3; break;
182             case FESTIVAL_GRAND: city_data.sentiment.blessing_festival_boost += 9; break;
183         }
184     }
185     city_data.festival.months_since_festival = 1;
186     city_data.religion.gods[god_id].months_since_festival = 0;
187 }
188 
throw_auto_festival(int god_id)189 static void throw_auto_festival(int god_id)
190 {
191     festival_sentiment_and_deity(1, god_id);
192     city_message_post(0, MESSAGE_AUTO_FESTIVAL_CERES + god_id, 0, 0);
193 }
194 
throw_party(void)195 static void throw_party(void)
196 {
197     festival_sentiment_and_deity(city_data.festival.planned.size, city_data.festival.planned.god);
198     switch (city_data.festival.planned.size) {
199         case FESTIVAL_SMALL: city_message_post(1, MESSAGE_SMALL_FESTIVAL, 0, 0); break;
200         case FESTIVAL_LARGE: city_message_post(1, MESSAGE_LARGE_FESTIVAL, 0, 0); break;
201         case FESTIVAL_GRAND: city_message_post(1, MESSAGE_GRAND_FESTIVAL, 0, 0); break;
202     }
203     city_data.festival.planned.size = FESTIVAL_NONE;
204     city_data.festival.planned.months_to_go = 0;
205 }
206 
city_festival_update(void)207 void city_festival_update(void)
208 {
209     city_data.festival.months_since_festival++;
210     if (city_data.festival.first_festival_effect_months) {
211         --city_data.festival.first_festival_effect_months;
212     }
213     if (city_data.festival.second_festival_effect_months) {
214         --city_data.festival.second_festival_effect_months;
215     }
216     if (city_festival_is_planned()) {
217         city_data.festival.planned.months_to_go--;
218         if (city_data.festival.planned.months_to_go <= 0) {
219             throw_party();
220         }
221     }
222 
223     if (building_monument_working(BUILDING_PANTHEON)) {
224         for (int god = 0; god <= 4; ++god) {
225             if (game_time_total_years() % 5 == god && game_time_month() == autofestivals[god].month) {
226                 throw_auto_festival(god);
227             }
228         }
229     }
230 }
231 
city_festival_calculate_costs(void)232 void city_festival_calculate_costs(void)
233 {
234     int wine_available = city_data.resource.stored_in_warehouses[RESOURCE_WINE];
235     if (building_monument_gt_module_is_active(VENUS_MODULE_1_DISTRIBUTE_WINE)) {
236         building *venus_gt = building_get(building_monument_get_venus_gt());
237         wine_available += venus_gt->loads_stored;
238     }
239 
240     city_data.festival.small_cost = city_data.population.population / 20 + 10;
241     city_data.festival.large_cost = city_data.population.population / 10 + 20;
242     city_data.festival.grand_cost = city_data.population.population / 5 + 40;
243     city_data.festival.grand_wine = city_data.population.population / 500 + 1;
244     city_data.festival.not_enough_wine = 0;
245     if (wine_available < city_data.festival.grand_wine) {
246         city_data.festival.not_enough_wine = 1;
247         if (city_data.festival.selected.size == FESTIVAL_GRAND) {
248             city_data.festival.selected.size = FESTIVAL_LARGE;
249         }
250     }
251 }