1 #include "gladiator_revolt.h"
2
3 #include "building/count.h"
4 #include "city/games.h"
5 #include "city/message.h"
6 #include "core/random.h"
7 #include "game/time.h"
8 #include "scenario/data.h"
9
10 static struct {
11 int game_year;
12 int month;
13 int end_month;
14 int state;
15 } data;
16
scenario_gladiator_revolt_init(void)17 void scenario_gladiator_revolt_init(void)
18 {
19 data.game_year = scenario.start_year + scenario.gladiator_revolt.year;
20 data.month = 3 + (random_byte() & 3);
21 data.end_month = 3 + data.month;
22 data.state = EVENT_NOT_STARTED;
23 }
24
scenario_gladiator_revolt_process(void)25 void scenario_gladiator_revolt_process(void)
26 {
27 if (!scenario.gladiator_revolt.enabled) {
28 return;
29 }
30
31 if (data.state == EVENT_NOT_STARTED) {
32 if (game_time_year() == data.game_year && game_time_month() == data.month) {
33 if (building_count_active(BUILDING_GLADIATOR_SCHOOL) > 0 && !city_games_executions_active()) {
34 data.state = EVENT_IN_PROGRESS;
35 city_message_post(1, MESSAGE_GLADIATOR_REVOLT, 0, 0);
36 } else {
37 data.state = EVENT_FINISHED;
38 }
39 }
40 } else if (data.state == EVENT_IN_PROGRESS) {
41 if (data.end_month == game_time_month()) {
42 data.state = EVENT_FINISHED;
43 city_message_post(1, MESSAGE_GLADIATOR_REVOLT_FINISHED, 0, 0);
44 }
45 }
46 }
47
scenario_gladiator_revolt_is_in_progress(void)48 int scenario_gladiator_revolt_is_in_progress(void)
49 {
50 return data.state == EVENT_IN_PROGRESS;
51 }
52
scenario_gladiator_revolt_is_finished(void)53 int scenario_gladiator_revolt_is_finished(void)
54 {
55 return data.state == EVENT_FINISHED;
56 }
57
scenario_gladiator_revolt_save_state(buffer * buf)58 void scenario_gladiator_revolt_save_state(buffer *buf)
59 {
60 buffer_write_i32(buf, data.game_year);
61 buffer_write_i32(buf, data.month);
62 buffer_write_i32(buf, data.end_month);
63 buffer_write_i32(buf, data.state);
64 }
65
scenario_gladiator_revolt_load_state(buffer * buf)66 void scenario_gladiator_revolt_load_state(buffer *buf)
67 {
68 data.game_year = buffer_read_i32(buf);
69 data.month = buffer_read_i32(buf);
70 data.end_month = buffer_read_i32(buf);
71 data.state = buffer_read_i32(buf);
72 }
73