From 9508c6e65c7ff25da8848ca7e17e2220acb5ee5c Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Mon, 2 Dec 2024 15:46:15 +0100 Subject: exclude boat time from work time --- src/include/world.h | 3 +++ src/ui/selectors.c | 2 +- src/world.c | 58 +++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 51 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/include/world.h b/src/include/world.h index 06a6d11..458478b 100644 --- a/src/include/world.h +++ b/src/include/world.h @@ -135,8 +135,10 @@ typedef struct t_job_offer u32 reward; array connections; // Should not be freed if offer has been accepted. double total_distance; // in KM + double boat_distance; // in KM, included in trip time but not worked time. reward for these KM's are 10% of normal price. time_t duration_sec_min; // experienced drivers time_t duration_sec_max; // inexperienced drivers + time_t duration_sec_min_excluding_boat; // used to calculate scheduled hours. hours on boat are only counted for 10% } job_offer; typedef struct t_employee @@ -227,6 +229,7 @@ typedef struct t_schedule typedef struct t_world_location { // Static + s32 index; u8 size; double latitude; double longitude; diff --git a/src/ui/selectors.c b/src/ui/selectors.c index dc5a6bc..7d55b98 100644 --- a/src/ui/selectors.c +++ b/src/ui/selectors.c @@ -109,7 +109,7 @@ employee* employee_selector_render(platform_window* window, float scale, bool en tb_y += fnt->px_h + (12*scale); } - float hours_for_this_job = (offer->offer.duration_sec_min * get_shiptime_factor(result)) / 3600.0f; + float hours_for_this_job = (offer->offer.duration_sec_min_excluding_boat * get_shiptime_factor(result)) / 3600.0f; float total_hours = get_worked_hours_per_week_for_employee(_active_world, result, (_active_schedule_state == RESCHEDULING_JOB ? _active_selected_scheduled_job : 0)); // If being scheduled, also add timeslots that are currently being scheduled. diff --git a/src/world.c b/src/world.c index 31ba752..88c3dac 100644 --- a/src/world.c +++ b/src/world.c @@ -583,6 +583,7 @@ static bool world_load_locations_from_file(world* world) if (!longitude) return false; world_location location = world_create_location(size->valueint, latitude->valuedouble, longitude->valuedouble, name->valuestring, false); + location.index = world->locations.length; array_push(&world->locations, &location); } @@ -859,13 +860,14 @@ static void world_assign_new_job_offers(world* world, bool force) world_location* source = *(world_location**)array_at(&new_offer.connections, d); world_location* dest = *(world_location**)array_at(&new_offer.connections, d+1); - //if (!connection_is_sea_route(source, dest)) + if (!connection_is_sea_route(source, dest)) total_dist += distance_between_location(source, dest); - //else - // boat_distance += distance_between_location(source, dest); + else + boat_distance += distance_between_location(source, dest); } - new_offer.total_distance = total_dist; - new_offer.reward = (u32)((new_offer.total_distance * 2.1) * + new_offer.total_distance = total_dist + boat_distance; + new_offer.boat_distance = boat_distance; + new_offer.reward = (u32)((((new_offer.total_distance-boat_distance) + (new_offer.boat_distance*0.1f)) * 2.1) * (1 + (0.2f * (location->score))) * (1 + (get_random_number(0, 10) / 100.0f))); @@ -875,6 +877,7 @@ static void world_assign_new_job_offers(world* world, bool force) new_offer.duration_sec_min = (time_t)(min_duration_hours * 60 * 60); new_offer.duration_sec_max = (time_t)(max_diration_hours * 60 * 60); + new_offer.duration_sec_min_excluding_boat = (time_t)(((new_offer.total_distance-(new_offer.boat_distance*0.9f))/90.0) * 60 * 60); // printf("Distance: %.0f, duration between %.2f and %.2f hours.", total_dist, min_duration_hours, max_diration_hours); @@ -1022,7 +1025,7 @@ static void world_start_scheduled_job(world* world, scheduled_job* scheduled_job new_job.done_at = new_job.left_at + new_job.duration_sec; new_job.reversed = false; - float gasprice = ((new_job.offer.total_distance/100.0f) * new_job.assigned_truck.fuelusage) * DIESEL_PRICE_PER_LITER; + float gasprice = (((new_job.offer.total_distance-new_job.offer.boat_distance)/100.0f) * new_job.assigned_truck.fuelusage) * DIESEL_PRICE_PER_LITER; ADD_EXPENSE(world, orig, expenses_from_fuel, gasprice); array_push(&world->active_jobs, &new_job); @@ -1157,7 +1160,7 @@ static void world_update_active_jobs(world* world) } ADD_INCOME(world, endpoints.source, income_from_trips, job->offer.reward); - float gasprice = ((job->offer.total_distance/100.0f) * job->assigned_truck.fuelusage) * DIESEL_PRICE_PER_LITER; + float gasprice = (((job->offer.total_distance-job->offer.boat_distance)/100.0f) * job->assigned_truck.fuelusage) * DIESEL_PRICE_PER_LITER; ADD_EXPENSE(world, endpoints.source, expenses_from_fuel, gasprice); job->left_at = job->done_at; @@ -1192,7 +1195,7 @@ static float get_worked_hours_per_week_for_employee(world* world, employee* emp, for (s32 s = 0; s < MAX_SHIPDAYS; s++) { scheduled_job_time slot = job->timeslots[s]; if (slot.assignee == emp) { - float hworked = job->offer.duration_sec_min * get_shiptime_factor(emp); + float hworked = job->offer.duration_sec_min_excluding_boat * get_shiptime_factor(emp); if (!slot.stay_at_destination) hworked *= 2; total += hworked; } @@ -1691,6 +1694,31 @@ static bool world_check_location_accessibility(world_location* orig, world_locat bool world_map_location_is_in_sun(vec2f px_pos); +static void draw_dotted_line(float x1, float y1, float x2, float y2, color line_clr) +{ + s32 divisions = 50; + + for (int i = 0; i < divisions; i+=2) + { + if (i%4 == 0) continue; + if (i%4 == 1) continue; + + float percentage = (1.0f / divisions) * i; + float px1 = x1 + (x2-x1) * percentage; + float py1 = y1 + (y2-y1) * percentage; + + percentage = (1.0f / divisions) * (i+1); + float px2 = x1 + (x2-x1) * percentage; + float py2 = y1 + (y2-y1) * percentage; + + if (!world_map_location_is_in_sun((vec2f){px1, py1})) { + line_clr = rgba(255,255,0, 50); + } + + renderer->render_line(px1, py1, px2, py2, 2, line_clr); + } +} + world_update_result world_render(platform_window* window, world* world) { world_update_result result = {0,0}; @@ -1769,15 +1797,23 @@ world_update_result world_render(platform_window* window, world* world) { world_location* destination = *(world_location**)array_at(&source->connections, d); if (destination == source) continue; + if (destination->index < source->index) continue; color line_clr = COLOR_CONNECTION_BETWEEN_LOCATION_ACCESSIBLE; if (!source->is_accessible) line_clr = COLOR_CONNECTION_BETWEEN_LOCATION_INACCESSIBLE; if (!destination->is_accessible) line_clr = COLOR_CONNECTION_BETWEEN_LOCATION_INACCESSIBLE; line_clr.a = 100; - if (!world_map_location_is_in_sun((vec2f){source->map_position_x, source->map_position_y})) { - line_clr = rgba(255,255,0, 50); + + if (connection_is_sea_route(destination, source)) { + draw_dotted_line(source->map_position_x, source->map_position_y, destination->map_position_x, destination->map_position_y,line_clr); + } + else { + if (!world_map_location_is_in_sun((vec2f){source->map_position_x, source->map_position_y})) { + line_clr = rgba(255,255,0, 50); + } + + renderer->render_line(source->map_position_x, source->map_position_y, destination->map_position_x, destination->map_position_y, 2, line_clr); } - renderer->render_line(source->map_position_x, source->map_position_y, destination->map_position_x, destination->map_position_y, 2, line_clr); } } -- cgit v1.2.3-70-g09d2