forked from F1rrel/RenewedVillageGrowth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneration_cargo.nut
94 lines (80 loc) · 3.15 KB
/
generation_cargo.nut
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import("util.superlib", "SuperLib", 40);
Log <- SuperLib.Log;
class GenerationCargo {
base_1900 = null;
time_rates = null;
// trace current hour
current_hour = null;
current_year = null;
constructor(){
this.base_1900 = GSController.GetSetting("town_cargo_generation_base");
this.GetPassengerTimeRates();
this.current_hour = this.GetHourSafe();
this.current_year = this.GetYear();
}
}
function GenerationCargo::GetPassengerTimeRates()
{
local preset_setting = GSController.GetSetting("passenger_preset");
switch(preset_setting)
{
case 1:
Log.Info("Extended: Preset: Hyper peak", Log.LVL_INFO);
this.time_rates = [-1.69, -2.80, -5.32, -5.32, -5.32, -2.42, -0.97, 0.00, 1.70, 0.64, 0.15, 0.00, 0.00, 0.00, 0.00, 0.20, 0.68, 1.14, 1.32, 1.14, 0.38, 0.00, -1.00, -1.30];
// this.time_rates = [0.30, 0.14, 0.02, 0.02, 0.02, 0.18, 0.49, 0.96, 3.12, 1.50, 1.06, 0.96, 0.96, 0.96, 0.96, 1.1, 1.54, 2.12, 2.4, 2.12, 1.25, 0.96, 0.48, 0.39];
break;
case 2:
Log.Info("Extended: Preset: Equal peaks", Log.LVL_INFO);
this.time_rates = [-1.44, -2.58, -5.39, -5.39, -5.39, -2.59, -1.15, 0.79, 1.52, 0.52, 0.07, -0.07, -0.07, -0.07, -0.07, 0.16, 0.37, 0.97, 1.39, 1.21, 0.49, 0.14, -0.75, -1.05];
break;
case 3:
Log.Info("Extended: Preset: Japan", Log.LVL_INFO);
this.time_rates = [-0.83, -2.07, -5.63, -5.63, -5.63, -2.32, -0.43, 1.13, 1.86, 0.30, -0.31, -0.31, -0.31, -0.31, -0.31, -0.31, 0.07, 0.61, 1.01, 0.87, 0.64, 0.42, 0.15, -0.17];
break;
default:
Log.Error("Extended: Failed to recognise preset");
}
}
function GenerationCargo::GetHourSafe()
{
local tick_scale = GSDate.GetCurrentScaledDateTicks();
local hour = GSDate.GetHour(tick_scale);
if (hour >= 24) {
Log.Warning("Extended: GetHour returned "+current_time+". Hours set to 0");
hour = 0;
}
return hour;
}
function GenerationCargo::GetYear()
{
local date = GSDate.GetCurrentDate();
return GSDate.GetYear(date);
}
function GenerationCargo::Manage()
{
local hour = this.GetHourSafe();
local year = this.GetYear();
local diff_hour = hour - this.current_hour;
if (diff_hour != 0) {
Log.Info("Extended: Starting Hourly Updates...", Log.LVL_DEBUG);
/* TODO: add base rate profile */
/* TODO: prod_rate change to new settings */
// local base_rate = (year - 1900 - 4) / 10 + this.base_1900;
local base_rate = this.base_1900;
local prod_rate = this.time_rates[hour] * 10 + base_rate;
if (prod_rate > 80) {
prod_rate = 80;
}
if (prod_rate < -120) {
prod_rate = -120;
}
Log.Info("Extended: Town Cargo Prod Rate: " + prod_rate, Log.LVL_DEBUG);
GSGameSettings.SetValue("economy.town_cargo_scale_factor", prod_rate.tointeger());
this.current_hour = hour;
}
local diff_year = year - this.current_year;
if (diff_year != 0) {
Log.Info("Extended: Starting Yearly Updates...", Log.LVL_DEBUG);
this.current_year = year;
}
}