Skip to content

Commit 5f3341a

Browse files
author
s.kushnirenko
committed
feat: add city message when monument mastaba is finished
1 parent 3f549c0 commit 5f3341a

File tree

5 files changed

+61
-33
lines changed

5 files changed

+61
-33
lines changed

src/building/building.h

+2
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ class building_impl {
392392
inline figure *create_roaming_figure(e_figure_type _type, e_figure_action created_action, e_building_slot slot) { return base.create_roaming_figure(_type, created_action, slot); }
393393
inline bool common_spawn_figure_trigger(int min_houses) { return base.common_spawn_figure_trigger(min_houses); }
394394
inline bool common_spawn_roamer(e_figure_type type, int min_houses, e_figure_action created_action) { return base.common_spawn_roamer(type, min_houses, created_action); }
395+
inline tile2i tile() const { return base.tile; }
396+
inline e_building_type type() const { return base.type; }
395397

396398
building &base;
397399
building::impl_data_t &data;

src/building/monument_mastaba.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "building/count.h"
1010
#include "game/game.h"
1111
#include "city/resource.h"
12+
#include "city/message.h"
1213
#include "grid/random.h"
1314
#include "grid/tiles.h"
1415
#include "grid/grid.h"
@@ -127,6 +128,12 @@ void building_small_mastaba::update_day() {
127128

128129
if (data.monuments.phase >= 8) {
129130
building_small_mastabe_finalize(&base);
131+
if (is_main()) {
132+
city_message_options message;
133+
message.force_popup = true;
134+
message.hide_img = true;
135+
city_message_post_with_popup_delay(MESSAGE_CAT_MONUMENTS, MESSAGE_MASTABA_FINISHED, type(), tile().grid_offset(), &message);
136+
}
130137
return;
131138
}
132139

src/city/message.cpp

+24-20
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#define MAX_MESSAGES 1000
1919
#define MAX_QUEUE 20
20-
#define MAX_MESSAGE_CATEGORIES 20
2120

2221
struct message_data_t {
2322
city_message messages[MAX_MESSAGES];
@@ -49,8 +48,8 @@ struct message_data_t {
4948
uint16_t pop25000 : 1;
5049
} population_shown;
5150

52-
int message_count[MAX_MESSAGE_CATEGORIES];
53-
int message_delay[MAX_MESSAGE_CATEGORIES];
51+
int message_count[MESSAGE_CAT_SIZE];
52+
int message_delay[MESSAGE_CAT_SIZE];
5453

5554
time_millis last_sound_time[MESSAGE_CAT_RIOT_COLLAPSE + 1];
5655

@@ -79,7 +78,7 @@ void city_message_init_scenario(void) {
7978
data.total_messages = 0;
8079
data.current_message_id = 0;
8180

82-
for (int i = 0; i < MAX_MESSAGE_CATEGORIES; i++) {
81+
for (int i = 0; i < MESSAGE_CAT_SIZE; i++) {
8382
data.message_count[i] = 0;
8483
data.message_delay[i] = 0;
8584
}
@@ -225,7 +224,7 @@ void city_message_post_full(bool use_popup, int template_id, int event_id, int p
225224
should_play_sound = true;
226225
}
227226

228-
static void city_message_post_common(bool use_popup, int message_id, int param1, int param2, int god, int bg_img) {
227+
static void city_message_post_common(bool use_popup, int message_id, int param1, int param2, int god, int bg_img, city_message_options *opts) {
229228
auto &data = g_message_data;
230229

231230
int id = new_message_id();
@@ -249,7 +248,8 @@ static void city_message_post_common(bool use_popup, int message_id, int param1,
249248
msg->param2 = param2;
250249
msg->sequence = data.next_message_sequence++;
251250
msg->god = god;
252-
msg->background_img = bg_img;
251+
msg->hide_img = (opts && opts->hide_img);
252+
msg->background_img = (opts && (opts->force_img >= 0)) ? opts->force_img : bg_img;
253253

254254
int text_id = city_message_get_text_id(message_id);
255255
int lang_msg_type = lang_get_message(text_id)->message_type;
@@ -271,30 +271,33 @@ static void city_message_post_common(bool use_popup, int message_id, int param1,
271271
}
272272

273273
void city_message_god_post(int god, bool use_popup, int message_id, int param1, int param2) {
274-
city_message_post_common(use_popup, message_id, param1, param2, god, 0);
274+
city_message_post_common(use_popup, message_id, param1, param2, god, 0, nullptr);
275275
}
276276

277277
void city_message_population_post(bool use_popup, int message_id, int param1, int param2) {
278278
int img_id = image_id_from_group(GROUP_PANEL_GODS_DIALOGDRAW) + 16;
279-
city_message_post_common(use_popup, message_id, param1, param2, GOD_UNKNOWN, img_id);
279+
city_message_post_common(use_popup, message_id, param1, param2, GOD_UNKNOWN, img_id, nullptr);
280280
}
281281

282-
void city_message_post(bool use_popup, int message_id, int param1, int param2) {
283-
city_message_post_common(use_popup, message_id, param1, param2, GOD_UNKNOWN, 0);
282+
void city_message_post(bool use_popup, int message_id, int param1, int param2, city_message_options *opts) {
283+
city_message_post_common(use_popup, message_id, param1, param2, GOD_UNKNOWN, 0, opts);
284284
}
285285

286-
void city_message_post_with_popup_delay(int category, int message_type, int param1, short param2) {
286+
void city_message_post_with_popup_delay(e_mesage_category category, int message_type, int param1, short param2, city_message_options *opts) {
287287
auto& data = g_message_data;
288288
int use_popup = false;
289+
289290
if (data.message_delay[category] <= 0) {
290291
use_popup = true;
291292
data.message_delay[category] = 12;
292293
}
293-
city_message_post(use_popup, message_type, param1, param2);
294+
use_popup |= (opts && opts->force_popup);
295+
296+
city_message_post(use_popup, message_type, param1, param2, opts);
294297
data.message_count[category]++;
295298
}
296299

297-
void city_message_post_with_message_delay(int category, int use_popup, int message_type, int delay) {
300+
void city_message_post_with_message_delay(e_mesage_category category, int use_popup, int message_type, int delay) {
298301
auto& data = g_message_data;
299302
if (category == MESSAGE_CAT_FISHING_BLOCKED || category == MESSAGE_CAT_NO_WORKING_DOCK) {
300303
// bug in the original game: delays for 'fishing blocked' and 'no working dock'
@@ -414,22 +417,22 @@ int city_message_get_advisor(int message_type) {
414417
}
415418
}
416419

417-
void city_message_reset_category_count(int category) {
420+
void city_message_reset_category_count(e_mesage_category category) {
418421
auto& data = g_message_data;
419422
data.message_count[category] = 0;
420423
}
421-
void city_message_increase_category_count(int category) {
424+
void city_message_increase_category_count(e_mesage_category category) {
422425
auto& data = g_message_data;
423426
data.message_count[category]++;
424427
}
425-
int city_message_get_category_count(int category) {
428+
int city_message_get_category_count(e_mesage_category category) {
426429
auto& data = g_message_data;
427430
return data.message_count[category];
428431
}
429432

430433
void city_message_decrease_delays(void) {
431434
auto& data = g_message_data;
432-
for (int i = 0; i < MAX_MESSAGE_CATEGORIES; i++) {
435+
for (int i = 0; i < MESSAGE_CAT_SIZE; i++) {
433436
if (data.message_delay[i] > 0)
434437
data.message_delay[i]--;
435438
}
@@ -587,7 +590,8 @@ io_buffer* iob_messages = new io_buffer([](io_buffer* iob, size_t version) {
587590
iob->bind(BIND_SIGNATURE_INT16, &msg->eventmsg_phrase_id);
588591
iob->bind(BIND_SIGNATURE_INT16, &msg->req_city_past); // enum?
589592
iob->bind(BIND_SIGNATURE_INT16, &msg->unk_09); // 00 00
590-
iob->bind(BIND_SIGNATURE_INT16, &msg->unk_10); // 00 00
593+
iob->bind(BIND_SIGNATURE_UINT8, &msg->unk_10); // 00 00
594+
iob->bind(BIND_SIGNATURE_UINT8, &msg->hide_img); // 00 00
591595

592596
iob->bind(BIND_SIGNATURE_INT16, &msg->req_amount_past);
593597
iob->bind(BIND_SIGNATURE_INT16, &msg->req_resource_past);
@@ -613,11 +617,11 @@ io_buffer* iob_message_extra = new io_buffer([](io_buffer* iob, size_t version)
613617
iob->bind(BIND_SIGNATURE_UINT16, &data.reserved_5);
614618
iob->bind(BIND_SIGNATURE_UINT8, &data.reserved_6);
615619

616-
for (int i = 0; i < MAX_MESSAGE_CATEGORIES; i++) {
620+
for (int i = 0; i < MESSAGE_CAT_SIZE; i++) {
617621
iob->bind(BIND_SIGNATURE_INT32, &data.message_count[i]);
618622
}
619623

620-
for (int i = 0; i < MAX_MESSAGE_CATEGORIES; i++) {
624+
for (int i = 0; i < MESSAGE_CAT_SIZE; i++) {
621625
iob->bind(BIND_SIGNATURE_INT32, &data.message_delay[i]);
622626
}
623627
});

src/city/message.h

+20-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ enum e_mesage_category {
1313
MESSAGE_CAT_NO_WORKING_DOCK = 10,
1414
MESSAGE_CAT_FISHING_BLOCKED = 11,
1515
MESSAGE_CAT_HEALTH_PROBLEM = 12,
16+
MESSAGE_CAT_MONUMENTS = 13,
17+
18+
MESSAGE_CAT_SIZE = 20,
1619
};
1720

1821
enum e_message_advisor {
@@ -128,6 +131,7 @@ enum e_message_type {
128131
MESSAGE_HEALTH_DISEASE = 325 - 99,
129132
MESSAGE_HEALTH_PLAGUE = 326 - 99,
130133
MESSAGE_HEALTH_MALARIA_PROBLEM = 327 - 99,
134+
MESSAGE_MASTABA_FINISHED = 394 - 99,
131135
MESSAGE_SPIRIT_OF_MARS = 105,
132136
MESSAGE_CAESAR_RESPECT_1 = 106,
133137
MESSAGE_CAESAR_RESPECT_2 = 107,
@@ -288,26 +292,33 @@ struct city_message {
288292
int eventmsg_phrase_id;
289293
int req_city_past;
290294
int unk_09;
291-
int unk_10;
295+
uint8_t unk_10;
296+
bool hide_img;
292297

293298
int req_amount_past;
294299
int req_resource_past;
295300
int unk_11a_i8;
296-
int god;
301+
uint8_t god;
297302
uint16_t background_img;
298303
};
299304

305+
struct city_message_options {
306+
bool force_popup = false;
307+
int force_img = -1;
308+
bool hide_img = false;
309+
};
310+
300311
void city_message_init_scenario();
301312
void city_message_init_problem_areas();
302313

303314
void city_message_disable_sound_for_next_message(void);
304315
void city_message_apply_sound_interval(int category);
305316

306317
void city_message_post_full(bool use_popup, int template_id, int event_id, int parent_event_id, int title_id, int body_id, int phrase_id, int param1, int param2);
307-
void city_message_post(bool use_popup, int message_id, int param1, int param2);
318+
void city_message_post(bool use_popup, int message_id, int param1, int param2, city_message_options *opts = nullptr);
308319
void city_message_god_post(int god, bool use_popup, int message_id, int param1, int param2);
309-
void city_message_post_with_popup_delay(int category, int message_type, int param1, short param2);
310-
void city_message_post_with_message_delay(int category, int use_popup, int message_type, int delay);
320+
void city_message_post_with_popup_delay(e_mesage_category category, int message_type, int param1, short param2, city_message_options *opts = nullptr);
321+
void city_message_post_with_message_delay(e_mesage_category category, int use_popup, int message_type, int delay);
311322
void city_message_population_post(bool use_popup, int message_id, int param1, int param2);
312323

313324
void city_message_process_queue(void);
@@ -316,10 +327,10 @@ void city_message_sort_and_compact(void);
316327
int city_message_get_text_id(int message_id);
317328
int city_message_get_advisor(int message_type);
318329

319-
void city_message_reset_category_count(int category);
320-
void city_message_increase_category_count(int category);
321-
int city_message_get_category_count(int category);
322-
void city_message_decrease_delays(void);
330+
void city_message_reset_category_count(e_mesage_category category);
331+
void city_message_increase_category_count(e_mesage_category category);
332+
int city_message_get_category_count(e_mesage_category category);
333+
void city_message_decrease_delays();
323334

324335
bool city_message_mark_population_shown(int population);
325336

src/window/message_dialog.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,19 @@ static void draw_city_message_text(const lang_message* msg) {
338338
}
339339

340340
static void draw_title(const lang_message* msg) {
341-
painter ctx = game.painter();
342341
auto &data = g_message_dialog_data;
342+
343+
painter ctx = game.painter();
343344
uint8_t* text = msg->title.text;
345+
const city_message *city_msg = city_message_get(data.message_id);
344346

345347
if (data.is_eventmsg)
346348
text = data.title_text;
347349

348-
if (!text)
350+
if (!text) {
349351
return;
352+
}
353+
350354
int image_id = get_message_image_id(msg);
351355
const image_t* img = image_id ? image_get(image_id) : 0;
352356
// title
@@ -361,7 +365,7 @@ static void draw_title(const lang_message* msg) {
361365
data.y_text = data.y + 48;
362366

363367
// picture
364-
if (img) {
368+
if (img && !city_msg->hide_img) {
365369
int image_x = msg->image.x;
366370
int image_y = msg->image.y;
367371
ImageDraw::img_generic(ctx, image_id, vec2i{data.x + image_x, data.y + image_y});
@@ -409,7 +413,7 @@ static void draw_content(const lang_message* msg) {
409413
graphics_reset_clip_rectangle();
410414
}
411415

412-
static void draw_background_normal(void) {
416+
static void draw_background_normal() {
413417
auto &data = g_message_dialog_data;
414418
rich_text_set_fonts(FONT_NORMAL_WHITE_ON_DARK, FONT_NORMAL_YELLOW);
415419
const lang_message* msg = lang_get_message(data.text_id);

0 commit comments

Comments
 (0)