Skip to content

Commit 4f31c5f

Browse files
committed
tutorial: collapse handler moved to event
1 parent a74cc11 commit 4f31c5f

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

src/building/maintenance.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,17 @@ std::pair<int, tile2i> building_maintenance_get_closest_burning_ruin(tile2i tile
9898

9999
static void collapse_building(building* b) {
100100
city_message_apply_sound_interval(MESSAGE_CAT_COLLAPSE);
101-
if (!tutorial_handle_collapse()) {
102-
city_message_post_with_popup_delay(MESSAGE_CAT_COLLAPSE, false, MESSAGE_COLLAPSED_BUILDING, b->type, b->tile.grid_offset());
103-
}
101+
102+
g_city_events.enqueue(event_collase_damage{ b->id });
103+
city_message_post_with_popup_delay(MESSAGE_CAT_COLLAPSE, false, MESSAGE_COLLAPSED_BUILDING, b->type, b->tile.grid_offset());
104104

105105
game_undo_disable();
106106
building_destroy_by_collapse(b);
107107
}
108108

109109
static void fire_building(building* b) {
110110
city_message_apply_sound_interval(MESSAGE_CAT_FIRE);
111+
city_message_post_with_popup_delay(MESSAGE_CAT_FIRE, false, MESSAGE_FIRE, b->type, b->tile.grid_offset());
111112

112113
g_city_events.enqueue(event_fire_damage{ b->id });
113114

@@ -172,6 +173,7 @@ void building_maintenance_check_fire_collapse() {
172173
}
173174

174175
void building_maintenance_init() {
176+
175177
}
176178

177179
void building_maintenance_check_kingdome_access() {

src/building/maintenance.h

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <functional>
77

88
struct event_fire_damage { building_id bid; };
9+
struct event_collase_damage { building_id id; };
910

1011
void building_maintenance_update_fire_direction();
1112
int building_maintenance_fire_direction();

src/game/tutorial.cpp

+17-13
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,18 @@ void tutorial1_handle_population_changed(event_population_changed ev) {
193193
post_message(MESSAGE_TUTORIAL_FOOD_OR_FAMINE);
194194
}
195195

196+
void tutorial1_handle_collapse(event_collase_damage) {
197+
if (g_tutorials_flags.tutorial_1.collapse) {
198+
return;
199+
}
200+
201+
g_city_events.removeListener(typeid(event_collase_damage), &tutorial1_handle_collapse);
202+
203+
g_tutorials_flags.tutorial_1.collapse = true;
204+
building_menu_update(tutorial_stage.tutorial_collapse);
205+
post_message(MESSAGE_TUTORIAL_COLLAPSED_BUILDING);
206+
}
207+
196208
bool tutorial1_is_success() {
197209
auto &tut = g_tutorials_flags.tutorial_1;
198210
return tut.fire && tut.collapse && tut.population_150_reached && tut.gamemeat_400_stored;
@@ -207,6 +219,8 @@ bool tutorial_menu_update(int tut) {
207219
else g_city_events.appendListener(typeid(event_population_changed), &tutorial1_handle_population_changed);
208220

209221
if (g_tutorials_flags.tutorial_1.collapse) building_menu_update(tutorial_stage.tutorial_collapse);
222+
else g_city_events.appendListener(typeid(event_collase_damage), &tutorial1_handle_collapse);
223+
210224
if (g_tutorials_flags.tutorial_1.gamemeat_400_stored) building_menu_update(tutorial_stage.tutorial_water);
211225

212226
g_city.victory_state.add_condition(&tutorial1_is_success);
@@ -336,21 +350,11 @@ int tutorial_extra_fire_risk(void) {
336350
&& scenario_is_mission_rank(1); // Fix for extra fire risk in late tutorials
337351
}
338352

339-
int tutorial_extra_damage_risk(void) {
353+
int tutorial_extra_damage_risk() {
340354
return g_tutorials_flags.tutorial_1.fire && !g_tutorials_flags.tutorial_1.collapse
341355
&& scenario_is_mission_rank(1); // Fix for extra damage risk in late tutorials
342356
}
343357

344-
int tutorial_handle_collapse(void) {
345-
if (g_tutorials_flags.tutorial_1.collapse)
346-
return 0;
347-
348-
g_tutorials_flags.tutorial_1.collapse = 1;
349-
building_menu_update(tutorial_stage.tutorial_collapse);
350-
post_message(MESSAGE_TUTORIAL_COLLAPSED_BUILDING);
351-
return 1;
352-
}
353-
354358
void tutorial_flags_t::on_crime() {
355359
if (!g_tutorials_flags.pharaoh.crime) {
356360
g_tutorials_flags.pharaoh.crime = 1;
@@ -439,7 +443,7 @@ void tutorial_update_step(pcstr s) {
439443
const xstring step(s);
440444
if (step == tutorial_stage.tutorial_fire) {
441445
g_tutorials_flags.tutorial_1.fire = false;
442-
tutorial1_handle_fire(event_fire_damage{0});
446+
tutorial1_handle_fire({0});
443447
} else if (step == tutorial_stage.tutorial_food) {
444448
building_menu_update(step);
445449
post_message(MESSAGE_TUTORIAL_FOOD_OR_FAMINE);
@@ -448,7 +452,7 @@ void tutorial_update_step(pcstr s) {
448452
post_message(MESSAGE_TUTORIAL_CLEAN_WATER);
449453
} else if (step == tutorial_stage.tutorial_collapse) {
450454
g_tutorials_flags.tutorial_1.collapse = false;
451-
tutorial_handle_collapse();
455+
tutorial1_handle_collapse({0});
452456
} else if (step == tutorial_stage.tutorial_gods) {
453457
building_menu_update(step);
454458
post_message(MESSAGE_TUTORIAL_GODS_OF_EGYPT);

src/game/tutorial.h

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ int tutorial_get_immediate_goal_text();
100100
int tutorial_adjust_request_year(int* year);
101101

102102
int tutorial_extra_damage_risk();
103-
int tutorial_handle_collapse();
104103

105104
void tutorial_on_disease();
106105
void tutorial_on_filled_granary(int quantity);

0 commit comments

Comments
 (0)