Skip to content

Commit 54dcf21

Browse files
committed
tutorial: tut1 add event after filling granary with 400 meat
1 parent 4f31c5f commit 54dcf21

File tree

4 files changed

+57
-21
lines changed

4 files changed

+57
-21
lines changed

src/building/building_granary.h

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ struct granary_getting_result {
2121
tile2i tile;
2222
};
2323

24+
struct event_granary_filled { building_id bid; int amount; };
25+
2426
class building_granary : public building_storage {
2527
public:
2628
BUILDING_METAINFO_RT(BUILDING_GRANARY, building_granary)

src/city/city_resource.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,9 @@ static void calculate_available_food() {
365365
for (int r = 0; r < RESOURCES_FOODS_MAX; r++)
366366
city_data.resource.granary_food_stored[r] += granary.resource_stored[r];
367367

368-
if (amount_stored >= 100)
369-
tutorial_on_filled_granary(amount_stored);
368+
if (amount_stored >= 100) {
369+
g_city_events.enqueue(event_granary_filled{b.id, amount_stored});
370+
}
370371
}
371372
}, BUILDING_GRANARY);
372373

src/game/tutorial.cpp

+51-18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "building/building_menu.h"
44
#include "building/maintenance.h"
5+
#include "building/building_granary.h"
56
#include "city/buildings.h"
67
#include "city/city.h"
78
#include "city/message.h"
@@ -181,12 +182,12 @@ void tutorial1_handle_fire(event_fire_damage) {
181182
post_message(MESSAGE_TUTORIAL_FIRE_IN_THE_VILLAGE);
182183
}
183184

184-
void tutorial1_handle_population_changed(event_population_changed ev) {
185+
void tutorial1_handle_population_150(event_population_changed ev) {
185186
if (g_tutorials_flags.tutorial_1.population_150_reached || ev.value < 150) {
186187
return;
187188
}
188189

189-
g_city_events.removeListener(typeid(event_population_changed), &tutorial1_handle_population_changed);
190+
g_city_events.removeListener(typeid(event_population_changed), &tutorial1_handle_population_150);
190191

191192
g_tutorials_flags.tutorial_1.population_150_reached = true;
192193
building_menu_update(tutorial_stage.tutorial_food);
@@ -205,6 +206,45 @@ void tutorial1_handle_collapse(event_collase_damage) {
205206
post_message(MESSAGE_TUTORIAL_COLLAPSED_BUILDING);
206207
}
207208

209+
void tutorial1_on_filled_granary(event_granary_filled ev) {
210+
if (g_tutorials_flags.tutorial_1.gamemeat_400_stored) {
211+
return;
212+
}
213+
214+
if (ev.amount <= 400) {
215+
return;
216+
}
217+
218+
g_city_events.removeListener(typeid(event_granary_filled), &tutorial1_on_filled_granary);
219+
220+
g_tutorials_flags.tutorial_1.gamemeat_400_stored = true;
221+
building_menu_update(tutorial_stage.tutorial_water);
222+
post_message(MESSAGE_TUTORIAL_CLEAN_WATER);
223+
}
224+
225+
void tutorial3_on_filled_granary(event_granary_filled ev) {
226+
if (g_tutorials_flags.tutorial_3.figs_800_stored) {
227+
return;
228+
}
229+
230+
if (ev.amount < 800) {
231+
return;
232+
}
233+
234+
auto granary = building_get(ev.bid)->dcast_granary();
235+
const int figs_stored = granary ? granary->amount(RESOURCE_FIGS) : 0;
236+
237+
if (figs_stored < 800) {
238+
return;
239+
}
240+
241+
g_city_events.removeListener(typeid(event_granary_filled), &tutorial3_on_filled_granary);
242+
243+
g_tutorials_flags.tutorial_3.figs_800_stored = true;
244+
building_menu_update(tutorial_stage.tutorial_industry);
245+
post_message(MESSAGE_TUTORIAL_INDUSTRY);
246+
}
247+
208248
bool tutorial1_is_success() {
209249
auto &tut = g_tutorials_flags.tutorial_1;
210250
return tut.fire && tut.collapse && tut.population_150_reached && tut.gamemeat_400_stored;
@@ -216,12 +256,17 @@ bool tutorial_menu_update(int tut) {
216256
else g_city_events.appendListener(typeid(event_fire_damage), &tutorial1_handle_fire);
217257

218258
if (g_tutorials_flags.tutorial_1.population_150_reached) building_menu_update(tutorial_stage.tutorial_food);
219-
else g_city_events.appendListener(typeid(event_population_changed), &tutorial1_handle_population_changed);
259+
else g_city_events.appendListener(typeid(event_population_changed), &tutorial1_handle_population_150);
260+
261+
//if (!g_tutorials_flags.tutorial_1.architector_built) {
262+
// g_city_events.appendListener(typeid(event_building_create), &tutorial1_handle_building_create);
263+
//}
220264

221265
if (g_tutorials_flags.tutorial_1.collapse) building_menu_update(tutorial_stage.tutorial_collapse);
222266
else g_city_events.appendListener(typeid(event_collase_damage), &tutorial1_handle_collapse);
223267

224268
if (g_tutorials_flags.tutorial_1.gamemeat_400_stored) building_menu_update(tutorial_stage.tutorial_water);
269+
else g_city_events.appendListener(typeid(event_granary_filled), &tutorial1_on_filled_granary);
225270

226271
g_city.victory_state.add_condition(&tutorial1_is_success);
227272

@@ -237,6 +282,8 @@ bool tutorial_menu_update(int tut) {
237282

238283
if (tut == 3) {
239284
if (g_tutorials_flags.tutorial_3.figs_800_stored) building_menu_update(tutorial_stage.tutorial_industry);
285+
else g_city_events.appendListener(typeid(event_granary_filled), &tutorial3_on_filled_granary);
286+
240287
if (g_tutorials_flags.tutorial_3.pottery_made) building_menu_update(tutorial_stage.tutorial_industry);
241288
if (g_tutorials_flags.tutorial_3.disease) building_menu_update(tutorial_stage.tutorial_health);
242289
if (g_tutorials_flags.tutorial_3.pottery_made) building_menu_update(tutorial_stage.tutorial_gardens);
@@ -370,20 +417,6 @@ void tutorial_on_disease() {
370417
}
371418
}
372419

373-
void tutorial_on_filled_granary(int quantity) {
374-
if (scenario_is_mission_rank(1) && !g_tutorials_flags.tutorial_1.gamemeat_400_stored && quantity >= 400) {
375-
g_tutorials_flags.tutorial_1.gamemeat_400_stored = 1;
376-
building_menu_update(tutorial_stage.tutorial_water);
377-
post_message(MESSAGE_TUTORIAL_CLEAN_WATER);
378-
}
379-
380-
if (scenario_is_mission_rank(3) && !g_tutorials_flags.tutorial_3.figs_800_stored && quantity >= 800) {
381-
g_tutorials_flags.tutorial_3.figs_800_stored = 1;
382-
building_menu_update(tutorial_stage.tutorial_industry);
383-
post_message(MESSAGE_TUTORIAL_INDUSTRY);
384-
}
385-
}
386-
387420
void tutorial_check_resources_on_storageyard() {
388421
if (!g_tutorials_flags.tutorial_3.pottery_made && city_resource_warehouse_stored(RESOURCE_POTTERY) >= 1) {
389422
g_tutorials_flags.tutorial_3.pottery_made = true;
@@ -535,6 +568,7 @@ io_buffer* iob_tutorial_flags = new io_buffer([](io_buffer* iob, size_t version)
535568
iob->bind(BIND_SIGNATURE_UINT8, &g_tutorials_flags.tutorial_1.population_150_reached);
536569
iob->bind(BIND_SIGNATURE_UINT8, &g_tutorials_flags.tutorial_1.gamemeat_400_stored);
537570
iob->bind(BIND_SIGNATURE_UINT8, &g_tutorials_flags.tutorial_1.collapse);
571+
iob->bind(BIND_SIGNATURE_UINT8, &g_tutorials_flags.tutorial_1.architector_built);
538572
// tut 2
539573
iob->bind(BIND_SIGNATURE_UINT8, &g_tutorials_flags.tutorial_2.gold_mined_500);
540574
iob->bind(BIND_SIGNATURE_UINT8, &g_tutorials_flags.tutorial_2.temples_built);
@@ -577,5 +611,4 @@ io_buffer* iob_tutorial_flags = new io_buffer([](io_buffer* iob, size_t version)
577611
iob->bind(BIND_SIGNATURE_UINT8, &g_tutorials_flags.pharaoh.flags[37]); // goal: temples
578612
iob->bind(BIND_SIGNATURE_UINT8, &g_tutorials_flags.pharaoh.flags[38]);
579613
iob->bind(BIND_SIGNATURE_UINT8, &g_tutorials_flags.pharaoh.flags[39]);
580-
iob->bind(BIND_SIGNATURE_UINT8, &g_tutorials_flags.pharaoh.flags[40]);
581614
});

src/game/tutorial.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct tutorial_flags_t {
3232
bool population_150_reached;
3333
bool gamemeat_400_stored;
3434
bool collapse;
35+
bool architector_built;
3536
} tutorial_1;
3637

3738
struct {
@@ -102,7 +103,6 @@ int tutorial_adjust_request_year(int* year);
102103
int tutorial_extra_damage_risk();
103104

104105
void tutorial_on_disease();
105-
void tutorial_on_filled_granary(int quantity);
106106
void tutorial_on_gold_extracted();
107107
void tutorial_on_religion();
108108
void tutorial_on_house_evolve(e_house_level level);

0 commit comments

Comments
 (0)