summaryrefslogtreecommitdiff
path: root/src/world.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/world.c b/src/world.c
index a27d468..6d62b09 100644
--- a/src/world.c
+++ b/src/world.c
@@ -568,6 +568,11 @@ world* world_create_new()
new_world->log.events = array_create(sizeof(event));
new_world->log.write_cursor = 0;
new_world->log.has_unread_messages = false;
+ new_world->bank_info = (bank){0};
+ new_world->bank_info.loan1 = (bank_loan){10000, 3, 12, 846.94, 0};
+ new_world->bank_info.loan2 = (bank_loan){50000, 5, 12, 4280.38, 0};
+ new_world->bank_info.loan3 = (bank_loan){150000, 8, 12, 13048.27, 0};
+
array_reserve(&new_world->log.events, LOG_HISTORY_LENGTH);
new_world->insights = array_create(sizeof(money_data_collection));
array_reserve(&new_world->insights, 10);
@@ -1267,7 +1272,7 @@ static void give_random_fine(world* world)
case 1: snprintf(error_msg, MAX_EVENT_MESSAGE_LENGTH, "You were fined $%d because %s did not secure their load correctly.", fine, emp->name); break;
case 2: snprintf(error_msg, MAX_EVENT_MESSAGE_LENGTH, "You were fined $%d because %s had the incorrect shipping papers on their trip.", fine, emp->name); break;
}
- world->money -= fine;
+
ADD_EXPENSE(world, location, expenses_from_utility, fine);
world_report_event(world, error_msg, EVENT_TYPE_FINED, emp);
}
@@ -1285,7 +1290,6 @@ static void brake_down_random_truck(world* world)
char error_msg[MAX_EVENT_MESSAGE_LENGTH];
snprintf(error_msg, MAX_EVENT_MESSAGE_LENGTH, "%s's truck broke down and was repaired for $%d", emp->name, fine);
- world->money -= fine;
ADD_EXPENSE(world, location, expenses_from_repairs, fine);
world_report_event(world, error_msg, EVENT_TYPE_FINED, emp);
}
@@ -1313,7 +1317,6 @@ static void do_random_inspection(world* world)
char error_msg[MAX_EVENT_MESSAGE_LENGTH];
snprintf(error_msg, MAX_EVENT_MESSAGE_LENGTH, "A random inspection was performed in %s and %d employees were found to be working more hours than allowed. Fine: $%d.", location->name, total_employees_overworking, fine);
- world->money -= fine;
ADD_EXPENSE(world, location, expenses_from_utility, fine);
world_report_event(world, error_msg, EVENT_TYPE_FINED, 0);
}
@@ -1462,6 +1465,22 @@ static void world_age_employee(world* world)
}
}
+#define UPDATE_LOAN(_loan)\
+if (_loan.is_active) {\
+ _loan.days_left--;\
+ ADD_EXPENSE(world, 0, expenses_from_loans, _loan.monthly_payment/28.0f);\
+ if (_loan.days_left <= 0) {\
+ _loan.is_active = false;\
+ }\
+}
+
+static void world_update_loans(world* world)
+{
+ UPDATE_LOAN(world->bank_info.loan1);
+ UPDATE_LOAN(world->bank_info.loan2);
+ UPDATE_LOAN(world->bank_info.loan3);
+}
+
static void world_run_simulation_tick(world* world)
{
s32 elapsed_sec = MINUTES(world->simulation_speed);
@@ -1491,6 +1510,7 @@ static void world_run_simulation_tick(world* world)
if (curr_time->tm_mday <= 28) {
world_payout_salaries(world); // Pay salary first 28 days of month.
world_pay_investments(world);
+ world_update_loans(world);
}
}