-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompany.java
More file actions
187 lines (155 loc) · 4.69 KB
/
Company.java
File metadata and controls
187 lines (155 loc) · 4.69 KB
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
import java.util.*;
public class Company {
Country country; // owner country
Economy economy;
int id; // assigned company id
// Employee information
int technology; // 0 - 100 score for innovation
double techVal; // calculated technology score
int education; // 0 - 5 score for education
int employees; // number of employees
double multiplier; // multiplier calculated from education 1/2 < x < 3
double cumulativeConfidence = 1;
int wage;
// Money
long value; // total value of company
long assets; // illiquid assets of company, earns interest
long capital; // liquid assets of company
long debt; // liabilities
double debtPayment; // interest on liabilities
double interest; // interest on capital
double maintenance; // cost of assets
// Money - flow
int reach; // people this business reached in last tick
long revenue;
long expenses;
long ebitda;
long profit;
long lqRevenue;
long lqExpenses;
long lqProfit;
// Equity
int stocksOutstanding;
double stockPrice;
public Company(Economy eco, int numEmp, int newId) {
id = newId;
economy = eco;
country = eco.country;
stocksOutstanding = 100;
stockPrice = 1;
assets = 10000;
capital = 25000;
debt = 0;
interest = 0.02;
maintenance = 0.1;
employees = numEmp;
education = 2;
technology = 20;
wage = 15000;
}
public void tick(long tick) {
if(tick%100 == 0) {
// One year
} if(tick%25 == 0) {
// One quarter
// investCapital();
if(id == 0 && MacSim.SUPPRESS == 1)
quarterlyReport();
lqRevenue = 0;
lqExpenses = 0;
lqProfit = 0;
}
revenue = calculateRevenue();
expenses = calculateExpenses();
// revenue += assetRevenue();
ebitda = revenue - expenses;
debtPayment = 0.04 * (debt * interest);
ebitda -= debtPayment;
capital += ebitda;
lqRevenue += revenue;
lqExpenses += expenses;
lqProfit += profit;
value = capital + assets - debt;
}
void quarterlyReport() {
MacSim.log(2, " ");
MacSim.log(2, "Quarterly report: " + id);
MacSim.log(2, "Assets: " + assets);
MacSim.log(2, "Capital: " + capital);
MacSim.log(2, "Employees: " + employees);
MacSim.log(2, "Profit: " + lqProfit);
MacSim.p(2, " Revenue: " + lqRevenue);
MacSim.p(2, " Expenses: " + lqExpenses);
MacSim.log(2, " ");
}
long tax(double amount) {
long amtTaxable = (long)((amount * 0.01) * ebitda);
if(amtTaxable < 0) return 0;
profit = ebitda - amtTaxable;
// log("Amt taxable: " + amtTaxable);
capital -= amtTaxable;
return amtTaxable;
}
// inject capital in company
void invest(long investAmt) {
capital += investAmt;
}
// improves company by spending capital
void investCapital() {
if(capital > 10000000)
majorInvestment();
if(capital > 250000)
minorInvestment();
}
void majorInvestment() {
if(country.pop.unemployed > 20) {
hire(20);
convertCapital(5000000);
} else {
convertCapital(10000000);
}
}
void minorInvestment() {
if(country.pop.unemployed > 5) {
hire(5);
convertCapital(175000);
} else {
convertCapital(250000);
}
}
void convertCapital(long amount) {
assets += amount;
capital -= amount;
}
long calculateRevenue() {
// multiplier (education + 1) / 2.0;
// reach
reach = updateReach();
multiplier = updateMultiplier();
return (long)(reach * multiplier * 0.027);
}
long calculateExpenses() {
return (long)(((employees * wage * multiplier) + chargeForAssets()) * 0.01 * (MacSim.rand.nextDouble() * 0.2 + 0.9));
}
long chargeForAssets() {
return (long)(assets * maintenance);
}
long assetRevenue() {
long assetRevenue = (long)(assets * interest);
if(id==0)
MacSim.log(1, "Asset revenue: " + assetRevenue);
return assetRevenue;
}
void hire(int numToHire) {
country.pop.hire(numToHire);
employees += numToHire;
}
int updateReach() {
techVal = 1.0 - (technology * 0.002 + 0.01);
double empTech = (employees) / techVal;
return (int)(country.pop.totalPop * (int)empTech);
}
double updateMultiplier() {
return (education + 1) / 2.0;
}
}