From 7c889d5a80a59d3281775c3ea731f4e640295353 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Tue, 3 Dec 2024 18:56:44 +0100 Subject: working on save load --- src/world.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'src/world.c') diff --git a/src/world.c b/src/world.c index b95e0d9..9130160 100644 --- a/src/world.c +++ b/src/world.c @@ -268,6 +268,21 @@ world_location* get_world_location_by_name(world* world, char* str) return 0; } +truck* world_get_truck_by_type(world* world, s32 type) +{ + for (s32 i = 0; i < world->truck_dealers.length; i++) + { + truck_dealer* td = array_at(&world->truck_dealers, i); + + for (s32 x = 0; x < td->trucks.length; x++) + { + truck* tr = array_at(&td->trucks, x); + if (tr->type == type) return tr; + } + } + return 0; +} + void add_truck_to_world_location(world* world, world_location* location, truck* tr) { log_assert(location->trucks.length < MAX_TRUCK_COUNT, "Too many trucks"); @@ -390,6 +405,33 @@ static bool world_load_boat_routes_from_file(world* world) return true; } +company* world_get_product_by_name(world* world, char* str) +{ + for (int i = 0; i < world->companies.length; i++) + { + company* c = array_at(&world->companies, i); + + for (int x = 0; x < c->products.length; x++) + { + product* p = array_at(&c->products, x); + + if (strcmp(p->name, str) == 0) return c; + } + } + return 0; +} + +company* world_get_company_by_name(world* world, char* str) +{ + for (int i = 0; i < world->companies.length; i++) + { + company* c = array_at(&world->companies, i); + + if (strcmp(c->name, str) == 0) return c; + } + return 0; +} + static bool world_load_companies_from_file(world* world) { world->companies = array_create(sizeof(company)); @@ -629,7 +671,7 @@ static money_data_collection* get_current_insights_data(world* world) return (money_data_collection*)array_at(&world->insights, index); } -world* world_create_new() +world* world_create_new(bool create_default_state) { world* new_world = mem_alloc(sizeof(world)); new_world->simulation_time = time(NULL); @@ -692,7 +734,7 @@ world* world_create_new() return 0; } - if (!world_create_default_state(new_world)) { + if (create_default_state && !world_create_default_state(new_world)) { log_info("Could not create world"); mem_free(new_world); return 0; -- cgit v1.2.3-70-g09d2