-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpMoney.nut
121 lines (98 loc) · 3.11 KB
/
OpMoney.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
/* OperationMoney v.1, r.53a, [2011-03-31]
* part of WmDOT v.5
* Copyright © 2011 by William Minchin. For more info,
* please visit https://github.com/MinchinWeb/openttd-wmdot
*
* Permission is granted to you to use, copy, modify, merge, publish,
* distribute, sublincense, and/or sell this software, and provide these
* rights to others, provided:
*
* + The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the software.
* + Attribution is provided in the normal place for recognition of 3rd party
* contributions.
* + You accept that this software is provided to you "as is", without warranty.
*/
// Requires SuperLib v6 or better
class OpMoney {
function GetVersion() { return 1; }
function GetRevision() { return "53a"; }
function GetDate() { return "2011-03-31"; }
function GetName() { return "Operation Money"; }
_SleepLength = null;
// Controls how many ticks the AI sleeps between iterations.
_MinBalance = null;
// Minimum Bank balance (in GBP - £) to have on hand
_NextRun = null;
Log = null;
constructor()
{
this._SleepLength = 50;
this._MinBalance = 100;
this.Settings = this.Settings(this);
this.State = this.State(this);
Log = OpLog;
}
};
class OpMoney.Settings {
_main = null;
function _set(idx, val)
{
switch (idx) {
case "SleepLength": this._main._SleepLength = val; break;
case "MinBalance": this._main._MinBalance = val; break;
default: throw("the index '" + idx + "' does not exist");
}
return val;
}
function _get(idx)
{
switch (idx) {
case "SleepLength": return this._main._SleepLength; break;
case "MinBalance": return this._main._MinBalance; break;
default: throw("the index '" + idx + "' does not exist");
}
}
constructor(main)
{
this._main = main;
}
}
class OpMoney.State {
_main = null;
function _get(idx)
{
switch (idx) {
case "NextRun": return this._main._NextRun; break;
default: throw("the index '" + idx + "' does not exist");
}
}
constructor(main)
{
this._main = main;
}
}
function OpMoney::LinkUp()
{
this.Log = WmDOT.Log;
Log.Note(this.GetName() + " linked up!",3);
}
function OpMoney::Run() {
// Repays the loan and keeps a small balance on hand
this._NextRun = AIController.GetTick();
Log.Note("OpMoney running at tick " + this._NextRun + ".",1);
this._NextRun += this._SleepLength;
SLMoney.MakeMaximumPayback();
SLMoney.MakeSureToHaveAmount(this._MinBalance);
Log.Note("Bank Balance: " + AICompany.GetBankBalance(AICompany.ResolveCompanyID(AICompany.COMPANY_SELF)) + "£, Loan: " + AICompany.GetLoanAmount() + "£, Keep Minimum Balance of " + this._MinBalance + "£.",2)
}
function OpMoney::FundsRequest(Amount) {
// Makes sure the requested amount is available, taking a loan if available
Amount = Amount.tointeger();
Log.Note("Funds Request for " + Amount + "£ received.",3);
SLMoney.MakeSureToHaveAmount(Amount);
}
function OpMoney::GreaseMoney(Amount = 100) {
// Designed to keep just enough money onhand to keep from being sold off
SLMoney.MakeSureToHaveAmount(Amount);
}