From eba92835cee8e4c5564ce0e23db15db5b04ad279 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Mon, 25 Nov 2024 15:20:50 +0100 Subject: close #5, close #4 --- src/world.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/world.c') diff --git a/src/world.c b/src/world.c index 3226937..ab90371 100644 --- a/src/world.c +++ b/src/world.c @@ -12,8 +12,9 @@ float dotsize = 5; static s32 get_random_number(s32 min, s32 max) { - log_assert(min < max, "Min cannot be larger than max"); + log_assert(min <= max, "Min cannot be larger than max"); // it is assumed srand has been initialized at world load. + if (min == max) return min; return min + rand() % (max-min); } @@ -652,6 +653,21 @@ static void world_find_location_deep(s32 depth, world_location* source, array* b } } +static s32 world_get_max_ship_days_for_location(world_location* location) +{ + s32 shipdays = (int)round(MAX_SHIPDAYS*location->score); + if (shipdays < MIN_POSSIBLE_SHIPDAYS) shipdays = MIN_POSSIBLE_SHIPDAYS; + return shipdays; +} + +static s32 world_get_max_depth_for_location(world_location* location) +{ + s32 max_depth = 6; + s32 location_depth = (int)round(max_depth*location->score); + if (location_depth < 1) location_depth = 1; + return location_depth; +} + static void world_assign_new_job_offers(world* world) { for (s32 i = 0; i < world->locations.length; i++) @@ -668,7 +684,8 @@ static void world_assign_new_job_offers(world* world) job_offer new_offer = (job_offer){world->next_id++, world->simulation_time+DAYS(10), company, product, 0, {DAY_INVALID,DAY_INVALID,DAY_INVALID,DAY_INVALID}, 0}; new_offer.connections = array_create(sizeof(world_location*)); - s32 amount_of_shipdays = get_random_number(1, MAX_SHIPDAYS+1); + s32 max_shipdays = world_get_max_ship_days_for_location(location); + s32 amount_of_shipdays = get_random_number(1, max_shipdays+1); for (s32 s = 0; s < amount_of_shipdays; s++) { s32 random_day = get_random_number(0, NUM_DAYS); if (!job_offer_has_ship_day(&new_offer, random_day)) { @@ -679,7 +696,8 @@ static void world_assign_new_job_offers(world* world) } } - s32 amount_of_connections = get_random_number(1, 5) + 1; // +1 because we add original location to connection list. + s32 max_depth = world_get_max_depth_for_location(location); + s32 amount_of_connections = get_random_number(1, max_depth + 1) + 1; // +1 because we add original location to connection list. array_push(&new_offer.connections, &location); world_find_location_deep(amount_of_connections, location, &new_offer.connections); -- cgit v1.2.3-70-g09d2