summaryrefslogtreecommitdiff
path: root/src/world.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/world.c b/src/world.c
index fbb2ec2..02563ec 100644
--- a/src/world.c
+++ b/src/world.c
@@ -1,3 +1,5 @@
+#include <float.h>
+
static void world_assign_new_job_offers(world* world);
static double distance_between_location(world_location* location1, world_location* location2);
static void world_payout_salaries(world* world);
@@ -99,20 +101,36 @@ static world_location world_create_location(u8 size, double latitude, double lon
static void world_create_connections(world* world)
{
- const double max_distance = 2.5; // about 155km
+ const double max_distance = 410;
for (s32 i = 0; i < world->locations.length; i++)
{
world_location* source = array_at(&world->locations, i);
+
+ double closest = FLT_MAX;
+ world_location* closest_loc = 0;
for (s32 d = 0; d < world->locations.length; d++)
{
world_location* destination = array_at(&world->locations, d);
if (destination == source) continue;
- if (fabs(source->latitude - destination->latitude) < max_distance ||
- fabs(source->longitude - destination->longitude) < max_distance) {
+ double total_dist = distance_between_location(source, destination);
+ #if 0
+ printf("%s %s -> %f\n", source->name, destination->name, distance_between_location(source, destination));
+ #endif
+
+ if (total_dist < closest) {
+ closest = total_dist;
+ closest_loc = destination;
+ }
+
+ if (total_dist < max_distance) {
array_push(&source->connections, &destination);
}
}
+
+ if (source->connections.length == 0 && closest_loc != 0) {
+ array_push(&source->connections, &closest_loc);
+ }
}
}
@@ -325,8 +343,6 @@ static bool world_load_lastnames_from_file(world* world)
cJSON_Delete(json_object);
platform_destroy_file_content(&firstname_file);
- world_create_connections(world);
-
return true;
}
@@ -403,8 +419,6 @@ static bool world_load_trucks_from_file(world* world)
cJSON_Delete(json_object);
platform_destroy_file_content(&firstname_file);
- world_create_connections(world);
-
return true;
}
@@ -430,8 +444,6 @@ static bool world_load_firstnames_from_file(world* world)
cJSON_Delete(json_object);
platform_destroy_file_content(&firstname_file);
- world_create_connections(world);
-
return true;
}
@@ -633,7 +645,7 @@ static void world_find_location_deep(s32 depth, world_location* source, array* b
}
best_match = already_in_path ? 0 : connection;
- #if 0
+ #if 1
double best_match_distance = 0;
for (s32 i = 0; i < current_source->connections.length; i++) {
@@ -821,7 +833,10 @@ static void world_start_scheduled_job(world* world, scheduled_job* scheduled_job
if (scheduled_time.assignee->current_location_id != orig->id) {
scheduled_job->trust -= MISSED_DELIVERY_TRUST_PENALTY;
char error_msg[MAX_EVENT_MESSAGE_LENGTH];
- snprintf(error_msg, MAX_EVENT_MESSAGE_LENGTH, "%s missed a shipment because they are not at the right location.", scheduled_time.assignee->name);
+
+ snprintf(error_msg, MAX_EVENT_MESSAGE_LENGTH,
+ "%s missed a shipment because they are not at the right location. (Expected location: %s)",
+ scheduled_time.assignee->name, orig->name);
world_report_event_ex(world, error_msg, EVENT_TYPE_MISSED_SHIPMENT_NOT_AT_LOCATION, scheduled_job, scheduled_time);
return;
}