From 8b645e30dc0430e1a333a4f770ae2ac3723bee5e Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sun, 24 Nov 2024 09:59:45 +0100 Subject: more locations --- build.bat | 1 + data/world/locations.json | 111 +++++++++++++++++++++++++++++++++++++++++++++- src/include/world.h | 2 +- src/world.c | 37 +++++++++++----- 4 files changed, 138 insertions(+), 13 deletions(-) diff --git a/build.bat b/build.bat index 5a407c9..adc4518 100644 --- a/build.bat +++ b/build.bat @@ -1,2 +1,3 @@ +robocopy "data/" "build/data" /s /e gcc.exe -m64 -w -g -DMODE_DEBUG src/main.c -o build/truckerx2.exe -Llibs/ -lSDL2 -lSDL2_mixer call build\truckerx2.exe \ No newline at end of file diff --git a/data/world/locations.json b/data/world/locations.json index 90ed8a3..7c256e1 100644 --- a/data/world/locations.json +++ b/data/world/locations.json @@ -1,4 +1,5 @@ -[{ +[ + { "latitude": 50.8577758, "longitude": 5.6308645, "name": "Maastricht", @@ -10,6 +11,30 @@ "name": "Paris", "size": 1 }, + { + "latitude": 47.0780862, + "longitude": 2.3570985, + "name": "Bourges", + "size": 1 + }, + { + "latitude": 43.6100709, + "longitude": 3.83297, + "name": "Montpellier", + "size": 1 + }, + { + "latitude": 43.600798, + "longitude": 1.3504423, + "name": "Toulouse", + "size": 1 + }, + { + "latitude": 49.1048739, + "longitude": 6.1550344, + "name": "Metz", + "size": 1 + }, { "latitude": 51.5285582, "longitude": -0.2416796, @@ -27,5 +52,89 @@ "longitude": -2.2935019, "name": "Manchester", "size": 1 + }, + { + "latitude": 50.1213155, + "longitude": 8.4717595, + "name": "Frankfurt", + "size": 1 + }, + { + "latitude": 52.5069386, + "longitude": 12.2599279, + "name": "Berlin", + "size": 1 + }, + { + "latitude": 48.1549958, + "longitude": 11.4594358, + "name": "München", + "size": 1 + }, + { + "latitude": 47.3775284, + "longitude": 8.4543356, + "name": "Zürich", + "size": 1 + }, + { + "latitude": 46.2048579, + "longitude": 6.1224393, + "name": "Genève", + "size": 1 + }, + { + "latitude": 41.3927673, + "longitude": 2.0577889, + "name": "Barcelona", + "size": 1 + }, + { + "latitude": 43.2633529, + "longitude": -2.9541639, + "name": "Bilbao", + "size": 1 + }, + { + "latitude": 40.4380986, + "longitude": -3.8443426, + "name": "Madrid", + "size": 1 + }, + { + "latitude": 39.4078888, + "longitude": -0.4439116, + "name": "Valencia", + "size": 1 + }, + { + "latitude": 36.1295421, + "longitude": -5.3738995, + "name": "Gibraltar", + "size": 1 + }, + { + "latitude": 37.3754318, + "longitude": -5.9962577, + "name": "Sevilla", + "size": 1 + }, + { + "latitude": 42.6036354, + "longitude": -5.5979908, + "name": "León", + "size": 1 + }, + { + "latitude": 38.7441392, + "longitude": -9.2009352, + "name": "Lissabon", + "size": 1 + }, + { + "latitude": 40.9656382, + "longitude": -8.6800902, + "name": "Porto", + "size": 1 } ] \ No newline at end of file diff --git a/src/include/world.h b/src/include/world.h index 11c8ab3..11ac92e 100644 --- a/src/include/world.h +++ b/src/include/world.h @@ -263,7 +263,7 @@ typedef enum t_event_type EVENT_TYPE_EMPLOYEE_QUIT, // go to schedule } event_type; -#define MAX_EVENT_MESSAGE_LENGTH 150 +#define MAX_EVENT_MESSAGE_LENGTH 200 typedef struct t_event { 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 + 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; } -- cgit v1.2.3-70-g09d2