-
Notifications
You must be signed in to change notification settings - Fork 17
/
strings.nut
397 lines (351 loc) · 13.7 KB
/
strings.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
function GoalTown::TownBoxText(growth_enabled, text_mode, redraw=false)
{
local text_townbox = null;
// If the function is called with false, town is not growing. Give a help message.
local display_cargo = ::SettingsTable.randomization == Randomization.NONE ? false : ::SettingsTable.display_cargo;
if (!growth_enabled || 0 == text_mode) {
if (display_cargo) {
text_townbox = GSText(GSText["STR_TOWNBOX_CARGO_"+(::CargoCatNum-1)]);
text_townbox = this.TownTextContributor(text_townbox);
local cargo_mask = 0;
foreach (cargo in ::CargoLimiter) {
cargo_mask = cargo_mask | 1 << cargo;
}
text_townbox.AddParam(GSText(GSText.STR_TOWNBOX_NOGROWTH, cargo_mask));
foreach (index, category in this.town_cargo_cat) {
cargo_mask = 0;
foreach (cargo in category) {
cargo_mask = cargo_mask | 1 << cargo;
}
text_townbox.AddParam(GSText(GSText["STR_CARGOCAT_LABEL_"+::CargoCatList[index]]));
text_townbox.AddParam(cargo_mask);
}
} else {
local cargo_mask = 0;
foreach (cargo in ::CargoLimiter) {
cargo_mask = cargo_mask | 1 << cargo;
}
text_townbox = GSText(GSText.STR_TOWNBOX_NOGROWTH, cargo_mask);
}
return text_townbox;
}
switch (text_mode) {
case 1: // automatic
if (::SettingsTable.randomization == Randomization.NONE) {
text_townbox = this.TownTextCategories();
break;
} else if (::SettingsTable.randomization == Randomization.INDUSTRY_DESC
|| ::SettingsTable.randomization == Randomization.INDUSTRY_ASC) {
text_townbox = this.TownTextCategoriesCombined(display_cargo);
break;
}
if (!redraw) {
this.town_text_scroll = (this.town_text_scroll < 1) ? this.town_text_scroll + 1 : 0;
}
if (this.town_text_scroll > 0) {
text_townbox = this.TownTextCargos(display_cargo);
} else {
text_townbox = this.TownTextCategories();
}
break;
case 2: // categories
text_townbox = this.TownTextCategories();
break;
case 3: // cargos
text_townbox = this.TownTextCargos(display_cargo);
break;
case 4: // combined
text_townbox = this.TownTextCategoriesCombined(display_cargo);
break;
case 5: // all cargos
text_townbox = this.TownTextCargos(true);
break;
}
return text_townbox;
}
function GoalTown::TownTextLimiter(text_townbox, category)
{
local str = category ? "CATEGORY" : "CARGO";
if (this.allowGrowth && this.limit_delay > 0 && this.limit_transported != 0) {
text_townbox.AddParam(GSText(GSText["STR_TOWNBOX_" + str + "_DELAYED"], this.limit_transported));
}
else if (this.allowGrowth && this.limit_transported != 0) {
text_townbox.AddParam(GSText(GSText["STR_TOWNBOX_" + str + "_LOW"], this.limit_transported));
}
else if (!this.allowGrowth) {
text_townbox.AddParam(GSText(GSText["STR_TOWNBOX_" + str + "_STOP"], this.limit_transported));
}
else {
text_townbox.AddParam(GSText(GSText["STR_TOWNBOX_" + str], GSText(GSText.STR_EMPTY)));
}
return text_townbox;
}
function GoalTown::TownTextContributor(text_townbox)
{
if (this.contributor < 0) {
text_townbox.AddParam(GSText(GSText.STR_TOWNBOX_NO_CONTRIBUTOR, this.max_population, GSText(GSText.STR_EMPTY)));
}
else {
text_townbox.AddParam(GSText(GSText.STR_TOWNBOX_CONTRIBUTOR, this.max_population, this.contributor));
}
return text_townbox;
}
/* Function which builds town texts.
* Town text will look like below:
* Cargocat label: required/last supplied/stockpiled
*/
function GoalTown::TownTextCategories()
{
local max_cat = 0;
while (max_cat <::CargoCatNum - 1) {
if (this.town_goals_cat[max_cat + 1] == 0) break;
max_cat++;
}
local text_townbox = GSText(GSText["STR_TOWNBOX_CATEGORY_" + max_cat]);
text_townbox = this.TownTextContributor(text_townbox);
text_townbox = this.TownTextLimiter(text_townbox, true);
for (local i = 0; i <= max_cat; i++) {
text_townbox.AddParam(GSText(GSText["STR_CARGOCAT_LABEL_" + ::CargoCatList[i]]));
text_townbox.AddParam(this.town_supplied_cat[i] + " / " + this.town_goals_cat[i]);
}
return text_townbox;
}
function GoalTown::TownTextCategoriesCombined(display_all)
{
local max_cat = 0;
if (display_all) {
max_cat = ::CargoCatNum-1;
} else {
while (max_cat < ::CargoCatNum-1) {
if (this.town_goals_cat[max_cat + 1] == 0) break;
max_cat++;
}
}
local text_townbox = GSText(GSText["STR_TOWNBOX_COMBINED_" + max_cat]);
text_townbox = this.TownTextContributor(text_townbox);
text_townbox = this.TownTextLimiter(text_townbox, true);
for (local index = 0; index <= max_cat; ++index) {
local cargo_mask = 0;
foreach (cargo in this.town_cargo_cat[index]) {
cargo_mask += 1 << cargo;
}
text_townbox.AddParam(cargo_mask);
text_townbox.AddParam(this.town_supplied_cat[index] + " / " + this.town_goals_cat[index]);
}
return text_townbox;
}
function GoalTown::TownTextCargos(display_all)
{
local max_cat = 0;
if (display_all) {
max_cat = ::CargoCatNum-1;
} else {
while (max_cat < ::CargoCatNum-1) {
if (this.town_goals_cat[max_cat+1] == 0) break;
max_cat++;
}
}
local text_townbox = GSText(GSText["STR_TOWNBOX_CARGO_" + max_cat]);
text_townbox = this.TownTextContributor(text_townbox);
text_townbox = this.TownTextLimiter(text_townbox, false);
for (local index = 0; index <= max_cat; ++index) {
local cargo_mask = 0;
foreach (cargo in this.town_cargo_cat[index]) {
cargo_mask += 1 << cargo;
}
text_townbox.AddParam(GSText(GSText["STR_CARGOCAT_LABEL_" + ::CargoCatList[index]]));
text_townbox.AddParam(cargo_mask);
}
return text_townbox;
}
/* Building the text for towns' signtexts. */
function GoalTown::TownSignText()
{
local text_townsign = null;
if (GSTown.GetGrowthRate(this.id) > 880) {
text_townsign = GSText(GSText.STR_TOWNSIGN_NOTGROWING);
} else {
local growth_rate = GSTown.GetGrowthRate(this.id);
if (::SettingsTable.wallclock_timekeeping == 1) { // Wallclock Timekeeping
if (growth_rate > 300)
text_townsign = GSText(GSText.STR_TOWNSIGN_GROWTHRATE, GSTown.GetGrowthRate(this.id) / 30, GSText(GSText.STR_TOWNSIGN_MINUTES));
else
text_townsign = GSText(GSText.STR_TOWNSIGN_GROWTHRATE, GSTown.GetGrowthRate(this.id) * 2, GSText(GSText.STR_TOWNSIGN_SECONDS));
} else {
if (growth_rate > 360)
text_townsign = GSText(GSText.STR_TOWNSIGN_GROWTHRATE, GSTown.GetGrowthRate(this.id) / 30, GSText(GSText.STR_TOWNSIGN_MONTHS));
else
text_townsign = GSText(GSText.STR_TOWNSIGN_GROWTHRATE, GSTown.GetGrowthRate(this.id), GSText(GSText.STR_TOWNSIGN_DAYS));
}
}
return text_townsign;
}
/* Helper function: get a list of currently used cargo labels/ID. */
function DebugCargoLabels()
{
foreach (index, cargo_label in ::CargoIDList) {
Log.Info("Cargo " + index + ": " + cargo_label, Log.LVL_SUB_DECISIONS);
}
}
/* Debug function: print supplied cargo. */
function GoalTown::DebugCargoSupplied(i, supplied)
{
Log.Info(GSTown.GetName(this.id)+": supplied "+GSCargo.GetCargoLabel(i)+"="
+supplied, Log.LVL_DEBUG);
}
/* Debug function: print supplied cargo towards category for the company. */
function GoalTown::DebugCompanyCategorySupplied(cid, cat, supplied)
{
Log.Info(GSCompany.GetName(cid) + " cat " + cat + ": supplied " + supplied, Log.LVL_DEBUG);
}
/* Debug function: print stockpiled/supplied/goal per cargo category. */
function GoalTown::DebugCargoCatInfo(i)
{
Log.Info(GSTown.GetName(this.id)+": Cat. "+(i+1)
+" - Goal="+this.town_goals_cat[i]
+" Supplied="+this.town_supplied_cat[i]
+" Stockpiled="+this.town_stockpiled_cat[i], Log.LVL_DEBUG);
}
/* Debug function: print the general goals achievement before calculating the new TGR. */
function GoalTown::DebugGoalsResult(sum_goals, goal_diff, goal_diff_percent)
{
Log.Info(GSTown.GetName(this.id)+": sum_goals="+sum_goals+" goal_diff="+goal_diff+" goal_diff_percent="
+goal_diff_percent, Log.LVL_DEBUG);
}
/* Debug function: print the content of the TGR array. */
function GoalTown::DebugTgrArray()
{
local array_text = " ";
foreach (i, val in this.tgr_array) {
array_text = array_text+"i"+i+"="+val+" ";
}
Log.Info(GSTown.GetName(this.id)+": "+array_text+"Average="+this.tgr_average, Log.LVL_DEBUG);
}
function GoalTown::DebugCargoHash(hash)
{
local cargo_text = "";
for (local i = 0; i < 64; i++)
{
if (hash & (1 << i)) {
cargo_text += GSCargo.GetCargoLabel(i) + ",";
}
}
Log.Info(GSTown.GetName(this.id) + ": " + cargo_text, Log.LVL_DEBUG);
}
function GoalTown::DebugCargoTable(cargo_table)
{
local cargo_text = "";
foreach (index, cat in cargo_table) {
cargo_text += " " + (index + 1) + ": ";
foreach (cargo in cat) {
cargo_text += GSCargo.GetCargoLabel(cargo) + ",";
}
}
Log.Info(GSTown.GetName(this.id) + ": " + cargo_text, Log.LVL_SUB_DECISIONS);
}
function DebugIndustryLists()
{
local str = ::industries_raw.len() + " Raw industries: | ";
foreach (industry in ::industries_raw) {
str += industry + " " + GSIndustryType.GetName(industry) + " | ";
}
Log.Info(str, Log.LVL_DEBUG);
str = ::industries_1.len() + " Accepting 1 cargos: | ";
foreach (industry in ::industries_1) {
str += industry + " " + GSIndustryType.GetName(industry) + " | ";
}
Log.Info(str, Log.LVL_DEBUG);
str = ::industries_2.len() + " Accepting 2 cargos: | ";
foreach (industry in ::industries_2) {
str += industry + " " + GSIndustryType.GetName(industry) + " | ";
}
Log.Info(str, Log.LVL_DEBUG);
str = ::industries_3.len() + " Accepting 3 cargos: | ";
foreach (industry in ::industries_3) {
str += industry + " " + GSIndustryType.GetName(industry) + " | ";
}
Log.Info(str, Log.LVL_DEBUG);
str = ::industries_4.len() + " Accepting 4 and more cargos: | ";
foreach (industry in ::industries_4) {
str += industry + " " + GSIndustryType.GetName(industry) + " | ";
}
Log.Info(str, Log.LVL_DEBUG);
}
function GoalTown::DebugRandomizationIndustry(categories)
{
local str = "";
foreach (index, category in categories) {
str += " " + (index + 1) + ": ";
foreach (industry in category) {
str += GSIndustryType.GetName(industry) + ",";
}
}
Log.Info(GSTown.GetName(this.id) + ": " + str, Log.LVL_SUB_DECISIONS);
}
function DebugTownIndustries(town_industries)
{
foreach (town, industry_list in town_industries) {
local industries_text = "";
foreach (industry in industry_list) {
industries_text += " " + GSIndustry.GetName(industry) + ", ";
}
Log.Info(GSTown.GetName(town) + ": " + industries_text, Log.LVL_DEBUG);
}
}
function DebugSortedTowns(sorted_towns, towns)
{
Log.Info("Not monitored towns:", Log.LVL_SUB_DECISIONS);
local text = "";
foreach (town in sorted_towns.not_monitored) {
text += " \"" + GSTown.GetName(town) + "\"";
}
Log.Info(text, Log.LVL_SUB_DECISIONS);
Log.Info("Contributed towns:", Log.LVL_SUB_DECISIONS);
foreach (company, town_list in sorted_towns.contributed) {
text = GSCompany.GetName(company) + ":";
foreach (town_index in town_list) {
text += " \"" + GSTown.GetName(towns[town_index].id) + "\"";
}
Log.Info(text, Log.LVL_SUB_DECISIONS);
}
}
function DebugSubsidies(subsidies)
{
Log.Info("Subsidies:", Log.LVL_SUB_DECISIONS);
foreach (company, subs in subsidies) {
local text = GSCompany.GetName(company) + ": ";
if (subs.town_subsidy != null)
text += "[ Town subsidy: " + GSTown.GetName(subs.town_subsidy.town_1) + " -> " + GSTown.GetName(subs.town_subsidy.town_2) + " ]";
if (subs.cargo_subsidy != null)
text += " [ Cargo subsidy: \"" + GSCargo.GetName(subs.cargo_subsidy.cargo_id) + "\" " + GSIndustry.GetName(subs.cargo_subsidy.providing_industry_id) + " -> " + GSIndustry.GetName(subs.cargo_subsidy.accepting_industry_id) + " ]";
Log.Info(text, Log.LVL_SUB_DECISIONS);
}
}
function DebugNearTownCargos(near_town_cargos)
{
foreach (town, categories in near_town_cargos) {
local cargos_text = "";
foreach (cat_idx, cargos in categories) {
cargos_text += cat_idx + " [";
foreach (cargo in cargos) {
cargos_text += GSCargo.GetCargoLabel(cargo) + ", ";
}
cargos_text += "] ";
}
Log.Info(GSTown.GetName(town) + ": " + cargos_text, Log.LVL_DEBUG);
}
}
function DebugNearTownIndustryTypes(near_town_industry_types)
{
foreach (town, categories in near_town_industry_types) {
local industry_text = "";
foreach (cat_idx, industry_types in categories) {
industry_text += cat_idx + " [";
foreach (industry in industry_types) {
industry_text += GSIndustryType.GetName(industry) + ", ";
}
industry_text += "] ";
}
Log.Info(GSTown.GetName(town) + ": " + industry_text, Log.LVL_DEBUG);
}
}