summaryrefslogtreecommitdiff
path: root/src/world.c
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-11-25 15:20:50 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-11-25 15:20:50 +0100
commiteba92835cee8e4c5564ce0e23db15db5b04ad279 (patch)
tree51d518cb02de45dfa33a21e196afaaae061baff0 /src/world.c
parent82419840618418daa9020029a5347fc0f6e5edc5 (diff)
close #5, close #4
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c24
1 files changed, 21 insertions, 3 deletions
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);