From 63bb02e5c6c10ebdf0eabec0c20d7e8993cb5ee7 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sun, 1 Dec 2024 10:26:15 +0100 Subject: close #34 --- src/include/world.h | 2 ++ src/scenes/world_map.c | 4 +++- src/world.c | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/include/world.h b/src/include/world.h index dc11460..250e235 100644 --- a/src/include/world.h +++ b/src/include/world.h @@ -264,6 +264,8 @@ typedef enum t_event_type EVENT_TYPE_MISSED_SHIPMENT_NO_ASSIGNEE, // go to schedule EVENT_TYPE_EMPLOYEE_QUIT, // go to schedule EVENT_TYPE_FINED, // go to employee detail + + EVENT_TYPE_INFO, // not clickable } event_type; #define MAX_EVENT_MESSAGE_LENGTH 200 diff --git a/src/scenes/world_map.c b/src/scenes/world_map.c index 2642bdb..1053420 100644 --- a/src/scenes/world_map.c +++ b/src/scenes/world_map.c @@ -668,7 +668,7 @@ static void world_map_draw_event_log(platform_window* window) s32 highlight_w = text_w; s32 highlight_h = texth+(inner_pad); - if (mouse_interacts(text_x, text_y, highlight_w, highlight_h)) { + if (e->type != EVENT_TYPE_INFO && mouse_interacts(text_x, text_y, highlight_w, highlight_h)) { platform_set_cursor(window, CURSOR_POINTER); renderer->render_rectangle(text_x, text_y, text_w, highlight_h, rgba(255,255,255,20)); @@ -688,6 +688,8 @@ static void world_map_draw_event_log(platform_window* window) place_detail_show_schedule_with_highlighted_job((world_location*)e->data, 0, e->job_time); break; + case EVENT_TYPE_INFO: break; + default: log_assert(0, "Invalid event type."); break; diff --git a/src/world.c b/src/world.c index 4b478e9..7da1d2d 100644 --- a/src/world.c +++ b/src/world.c @@ -49,7 +49,7 @@ void world_report_event_ex(world* world, char* msg, event_type type, void* data, world->log.has_unread_messages = true; } - audio_play_sound(snd_event, AUDIO_CHANNEL_SFX_2); + if (type != EVENT_TYPE_INFO) audio_play_sound(snd_event, AUDIO_CHANNEL_SFX_2); } void world_report_event(world* world, char* msg, event_type type, void* data) @@ -1272,6 +1272,35 @@ static void brake_down_random_truck(world* world) world_report_event(world, error_msg, EVENT_TYPE_FINED, emp); } +static void do_random_inspection(world* world) +{ + world_location* location = get_random_owned_location(world); + + int total_employees_overworking = 0; + for (s32 x = 0; x < location->employees.length; x++) + { + employee* em = *(employee**)array_at(&location->employees, x); + float total_hours = get_worked_hours_per_week_for_employee(world, em, 0); + if (total_hours > MAX_WORKED_HOURS_WEEKLY) total_employees_overworking++; + } + + if (total_employees_overworking == 0) { + char error_msg[MAX_EVENT_MESSAGE_LENGTH]; + snprintf(error_msg, MAX_EVENT_MESSAGE_LENGTH, "A random inspection was performed in %s and no issues were found.", location->name); + world_report_event(world, error_msg, EVENT_TYPE_INFO,location); + } + else { + s32 fine = total_employees_overworking * 1000; + + char error_msg[MAX_EVENT_MESSAGE_LENGTH]; + snprintf(error_msg, MAX_EVENT_MESSAGE_LENGTH, "A random inspection was performed in %s and %d employees were found to be working more hours than allowed. Fine: $%d.", location->name, total_employees_overworking, fine); + + world->money -= fine; + ADD_EXPENSE(world, location, expenses_from_utility, fine); + world_report_event(world, error_msg, EVENT_TYPE_FINED, 0); + } +} + static void world_start_random_events(world* world) { world->days_since_last_random_event++; @@ -1287,12 +1316,13 @@ static void world_start_random_events(world* world) bool run_event = chance_of_random_event >= (get_random_number(0, 100)/100.0f); if (run_event) { - s32 rand_event = get_random_number(0, 4); + s32 rand_event = get_random_number(0, 5); switch(rand_event) { case 0: end_contract_with_random_employee(world); break; case 1: end_contract_with_random_job(world); break; case 2: give_random_fine(world); break; case 3: brake_down_random_truck(world); break; + case 4: do_random_inspection(world); break; } world->days_since_last_random_event = 0; -- cgit v1.2.3-70-g09d2