summaryrefslogtreecommitdiff
path: root/src/world.c
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-11-25 14:52:56 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-11-25 14:52:56 +0100
commit82419840618418daa9020029a5347fc0f6e5edc5 (patch)
treea571a917c081abb1bb2fc2db3d55066518dd3141 /src/world.c
parent269be26f06ff9506cf33da603342bb0963a3339c (diff)
location score. close #1, close #7, close #6
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c58
1 files changed, 56 insertions, 2 deletions
diff --git a/src/world.c b/src/world.c
index db8ce7d..3226937 100644
--- a/src/world.c
+++ b/src/world.c
@@ -692,7 +692,7 @@ static void world_assign_new_job_offers(world* world)
total_dist += distance_between_location(source, dest);
}
new_offer.total_distance = total_dist;
- new_offer.reward = (u32)(new_offer.total_distance * 2.1); // -1 because source is is connection list.
+ new_offer.reward = (u32)(new_offer.total_distance * 2.1);
// lets assume most experienced drivers drive at 90km/h
double min_duration_hours = (new_offer.total_distance/90.0);
@@ -976,7 +976,12 @@ static void world_update_active_jobs(world* world)
i--;
}
else { // Job is done, return to original location if not staying.
- if (sc_job) sc_job->trust += (0.1f / sc_job->trust); // If job is still available, update trust.
+ if (sc_job) { // If job is still available, update trust.
+ sc_job->trust += (0.01f / sc_job->trust);
+ if (sc_job->trust > 1.0f) {
+ sc_job->trust = 1.0f;
+ }
+ }
ADD_INCOME(world, endpoints.source, income_from_trips, job->offer.reward);
float gasprice = ((job->offer.total_distance/100.0f) * job->assigned_truck.fuelusage) * DIESEL_PRICE_PER_LITER;
@@ -1151,6 +1156,54 @@ static void end_contract_with_employee(world* world, employee* emp)
if (curr_loc) array_remove_by(&curr_loc->employees, &emp);
}
+static void world_update_location_scores(world* world)
+{
+ for (s32 i = 0; i < world->locations.length; i++)
+ {
+ world_location* location = array_at(&world->locations, i);
+ if (!location->is_owned) continue;
+
+ s32 total_scheduled_slots = 0;
+ for (int x = 0; x < location->schedule.jobs.length; x++)
+ {
+ scheduled_job* job = array_at(&location->schedule.jobs, x);
+ total_scheduled_slots += job->offer.shipday_count;
+ }
+
+ float total_happiness = 0.0f;
+ int total_employees_counted = 0;
+ for (s32 x = 0; x < location->employees.length; x++)
+ {
+ employee* em = *(employee**)array_at(&location->employees, x);
+ if (em->original_location_id != location->id) continue;
+
+ total_employees_counted++;
+ total_happiness += em->happiness;
+ }
+ if (total_employees_counted == 0) total_employees_counted = 1;
+
+ float total_trust = 0.0f;
+ int total_trust_counted = 0;
+ for (s32 x = 0; x < location->schedule.jobs.length; x++)
+ {
+ scheduled_job* scheduled_job = array_at(&location->schedule.jobs, x);
+ total_trust += scheduled_job->trust;
+ total_trust_counted++;
+ }
+ if (total_trust_counted == 0) total_trust_counted = 1;
+
+ float fill = total_scheduled_slots / ((float)TIME_SLOTS_PER_WEEK / 3);
+ if (fill > 1.0f) fill = 1.0f;
+
+ float happiness = total_happiness / total_employees_counted;
+ float trust = total_trust / total_trust_counted;
+ location->score = ((fill*3.0f)+(happiness*0.5f)+(trust*1.5f)) / 5.0f;
+
+ //printf("Score for location %s: (Schedule: %f Happiness: %f Trust: %f) = %f%% stars: %d\n",
+ // location->name, fill, happiness, trust, location->score*100.0f, (int)round(location->score * 5));
+ }
+}
+
static void world_run_simulation_tick(world* world)
{
s32 elapsed_sec = MINUTES(world->simulation_speed);
@@ -1195,6 +1248,7 @@ static void world_run_simulation_tick(world* world)
}
world_update_active_jobs(world);
+ world_update_location_scores(world);
}
void world_update(platform_window* window, world* world)