-
Notifications
You must be signed in to change notification settings - Fork 0
/
DesireManager.nut
135 lines (111 loc) · 3.56 KB
/
DesireManager.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
class DesireManager {
Desires = {};
constructor () {
Desires.rawset(Desire.FEED_STATION, Desire(Desire.FEED_STATION));
Desires.rawget(Desire.FEED_STATION).active = false;
Desires.rawset(Desire.ECONOMICALLY_RESPONSIBLE, Desire(Desire.ECONOMICALLY_RESPONSIBLE));
Desires.rawget(Desire.ECONOMICALLY_RESPONSIBLE).active = false;
Desires.rawset(Desire.EXTEND_FEEDER_NETWORK, Desire(Desire.EXTEND_FEEDER_NETWORK));
Desires.rawget(Desire.EXTEND_FEEDER_NETWORK).active = false;
Desires.rawset(Desire.ADD_VEHICLE, Desire(Desire.ADD_VEHICLE));
Desires.rawget(Desire.ADD_VEHICLE).active = false;
}
/**
* Activate Desires.
* @param BeliefManager bm Instance of a BeliefManager.
*/
function ActivateDesires(bm);
/**
* Activate FeedStation Desire for stations it makes sense in.
* @param BeliefManager bm Instance of a BeliefManager
*/
function ActivateFSDesire(bm);
/**
* Activate global Economically Responsible Desire.
* @param BeliefManager bm Instance of BeliefManager
*/
function ActivateERDesire(bm);
/**
* Activate Extend Feeder Network Desire.
* @param BeliefManager bm Instance of BeliefManager
*/
function ActivateEFNDesire(bm);
/**
* Activate Add Vehicle Desire.
* @param BeliefManager bm Instance of BeliefManager
*/
function ActivateAVDesire(bm);
}
function DesireManager::ActivateDesires(bm) {
DesireManager.ActivateFSDesire(bm);
DesireManager.ActivateERDesire(bm);
DesireManager.ActivateEFNDesire(bm);
DesireManager.ActivateAVDesire(bm);
}
function DesireManager::ActivateAVDesire(bm) {
local des = Desire.ADD_VEHICLE;
local activateDes = false;
foreach (townid, sw7town in bm.AllTownsList.towns) {
local pax = bm.getPaxCargoId();
local waitingCargo = 0;
local cargoCapacity = 0;
foreach (station, _ in sw7town.Stations) {
waitingCargo += AIStation.GetCargoWaiting(station, pax);
}
foreach (vehicle, _ in sw7town.Vehicles) {
cargoCapacity += AIVehicle.GetCapacity(vehicle, pax);
}
if (waitingCargo > (cargoCapacity * 3)) {
//local cTick = AIController.GetTick();
//if (bm.LastVehicleCheck == null || (bm.LastVehicleCheck + 200) < cTick) {
//bm.LastVehicleCheck = cTick;
sw7town.setDesire(des, true);
activateDes = true;
//} else {
//}
} else {
sw7town.setDesire(des, false);
}
}
DesireManager.Desires.rawget(Desire.ADD_VEHICLE).active = activateDes;
}
function DesireManager::ActivateFSDesire(bm) {
local des = (Desire.FEED_STATION);
if (bm.StationsToFeed.Count() == 0) {
DesireManager.Desires.rawget(des).active = false;
} else {
DesireManager.Desires.rawget(des).active = true;
foreach (id, town in bm.AllTownsList.towns) {
if (town.active) {
if (!bm.CurrentServicedTownsList.rawin(id)) {
town.setDesire(des, (town.GetPopulation() > 400));
} else {
town.setDesire(des, false);
}
}
}
}
}
function DesireManager::ActivateERDesire(bm) {
local des = Desire.ECONOMICALLY_RESPONSIBLE;
if (bm.CurrentMoney > bm.LoanInterval) {
DesireManager.Desires.rawget(des).active = true;
} else {
DesireManager.Desires.rawget(des).active = false;
}
}
function DesireManager::ActivateEFNDesire(bm) {
local townsToExtend = false;
local des = Desire.EXTEND_FEEDER_NETWORK;
foreach (sTown in bm.CurrentServicedTownsList) {
local popl = sTown.GetPopulation();
local stMax = (0.00000001 * popl * popl + 0.001 * popl + 2.25)*2/3;
if (stMax >= (sTown.Stations.Count() + 1)) {
sTown.setDesire(des, true);
townsToExtend = true;
} else {
sTown.setDesire(des, false);
}
}
DesireManager.Desires.rawget(des).active = townsToExtend;
}