From d793093925608448104454ff91fbac4b757cbb5e Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Wed, 4 Dec 2024 15:41:36 +0100 Subject: load save file --- src/world.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'src/world.c') diff --git a/src/world.c b/src/world.c index 9130160..83ca6d9 100644 --- a/src/world.c +++ b/src/world.c @@ -6,6 +6,8 @@ static void world_payout_salaries(world* world); static void enable_insights_for_current_month(world* world); static vec2f get_world_location_for_job(platform_window* window, world* world, active_job* job); static employee* get_employee_by_id(world_location* location, u32 id); +static employee* get_employee_by_id_global(world* world, u32 id); +static truck* get_truck_by_id(world* world, u32 id); static void end_contract_with_employee(world* world, employee* emp); vec2f px_to_coords(platform_window* window, double x, double y); static bool world_check_location_accessibility(world_location* orig, world_location* source, int depth, double dist); @@ -405,7 +407,7 @@ static bool world_load_boat_routes_from_file(world* world) return true; } -company* world_get_product_by_name(world* world, char* str) +product* world_get_product_by_name(world* world, char* str) { for (int i = 0; i < world->companies.length; i++) { @@ -415,7 +417,7 @@ company* world_get_product_by_name(world* world, char* str) { product* p = array_at(&c->products, x); - if (strcmp(p->name, str) == 0) return c; + if (strcmp(p->name, str) == 0) return p; } } return 0; @@ -1114,6 +1116,35 @@ static employee* get_global_employee_by_id(world* world, u32 id) return 0; } +static employee* get_employee_by_id_global(world* world, u32 id) +{ + for (s32 x = 0; x < world->locations.length; x++) + { + world_location* location = array_at(&world->locations, x); + if (!location->is_owned) continue; + for (s32 i = 0; i < location->employees.length; i++) + { + employee* em = *(employee**)array_at(&location->employees, i); + if (em->id == id) return em; + } + } + return 0; +} + +static truck* get_truck_by_id(world* world, u32 id) +{ + for (s32 x = 0; x < world->locations.length; x++) + { + world_location* location = array_at(&world->locations, x); + if (!location->is_owned) continue; + for (s32 i = 0; i < location->trucks.length; i++) { + truck* emp = array_at(&location->trucks, i); + if (emp->id == id) return emp; + } + } + return 0; +} + static employee* get_employee_by_id(world_location* location, u32 id) { for (s32 i = 0; i < location->employees.length; i++) -- cgit v1.2.3-70-g09d2