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/world.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src/world.c') 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