summaryrefslogtreecommitdiff
path: root/src/world.c
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-12-02 15:46:15 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-12-02 15:46:15 +0100
commit9508c6e65c7ff25da8848ca7e17e2220acb5ee5c (patch)
treee7e85174dcbf13e83f8d2ccb506ad8d237db069d /src/world.c
parent1b85aeaf9882e29c15b116b683acdab41bb3e94a (diff)
exclude boat time from work time
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c58
1 files changed, 47 insertions, 11 deletions
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);
}
}