-
Notifications
You must be signed in to change notification settings - Fork 0
/
guides.nut
153 lines (136 loc) · 2.97 KB
/
guides.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
class GuidingStrategy {
static desc = "base guiding strategy";
strategies = [];
condition = false;
// condition must return true to activate this guiding strategy
function Condition() {
return condition;
}
function DoAction(action, arg=null) {
local ret = Condition();
if (ret == false) { return }
local strat;
//Debug("number of strategies are ", strategies.len());
foreach (strat in strategies) {
//Debug("strategy: action ", action, " on ", strat.desc);
try {
if (action == "Start") {
strat.Start();
strat.RunTasks();
} else if (action == "Stop") {
strat.Stop();
} else if (action == "Uninit") {
strat.Uninit();
} else if (action == "Wake") {
strat.Wake();
strat.RunTasks();
} else if (action == "Quarterly") {
strat.Quarterly();
strat.RunTasks();
} else if (action == "Event") {
strat.Event(arg);
strat.RunTasks();
}
} catch (e) {
Error("exception thrown:", e);
}
}
}
function Start() {
DoAction("Start");
}
function Stop() {
DoAction("Stop");
}
function Uninit() {
DoAction("Uninit");
}
function Wake() {
DoAction("Wake");
}
function Quarterly() {
DoAction("Quarterly");
}
function Event(e) {
DoAction("Event", e);
}
}
class VerySmallMapGuide extends GuidingStrategy {
desc = "strategies for 64x64 maps";
constructor() {
//local cargos = GenCargos();
//local fruit = cargos.GRAI;
strategies = [
//ExpandTowns(1, 1000, 30),
BusesToPopularTowns(1),
SubStrategy(),
/* COMMENTED OUT
SimpleSuppliesStrategy({
maxroutes = 10,
delay = 365,
interval = 365,
mindistance = 5,
maxdistance = 30,
}),
AuxSuppliesStrategy({
maxroutes = 5,
delay = 730,
interval = 100,
mindistance = 5,
maxdistance = 30,
}),
*/
];
}
function Condition() {
local x = AIMap.GetMapSizeX();
local y = AIMap.GetMapSizeY();
if (x == 64 && y == 64) {
return true;
}
return false;
}
function Wake() {
local m = MaxLoanStrategy();
m.Start();
GuidingStrategy.Wake();
local z = ZeroLoanStrategy();
z.Start();
}
}
class BigCityRoutes extends GuidingStrategy {
desc = "build routes in the largest city";
townID = null;
constructor(minpopulation=7000) {
townID = null;
local towns = AITownList();
towns.Valuate(AITown.GetPopulation);
towns.KeepAboveValue(minpopulation);
towns.Sort(AIList.SORT_BY_VALUE, AIList.SORT_DESCENDING);
if (towns.IsEmpty()) { return }
townID = towns.Begin();
local name = AITown.GetName(townID);
local pop = AITown.GetPopulation(townID);
Debug("biggest town is ", name, "with a population of ", pop);
strategies = [
LocalTownStations(townID),
];
}
function Condition() {
if (this.townID != null) {
return true;
}
return false;
}
function Wake() {
local m = MaxLoanStrategy();
m.Start();
GuidingStrategy.Wake();
local z = ZeroLoanStrategy();
z.Start();
}
}
// other ideas:
// very urban maps
// lots of water
// long maps (like 64x512)