-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmpire.java
More file actions
598 lines (487 loc) · 11 KB
/
Copy pathEmpire.java
File metadata and controls
598 lines (487 loc) · 11 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
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
import java.util.ArrayList;
public class Empire {
// This Empire's name.
private String name;
// This empire's position on war. Positive is pacifist, negative is warmonger.
// 3 : Peaceful, 2 : Accepting, 1 : Welcoming, 0 : Neutral, -1 : Unfriendly, -2 : Warlike, -3 : Destructive
private int pacWar;
// This empire's position on other empires. Positive is involved, negative is isolationist.
// 3 : Interventionist, 2 : Interfering, 1 : Upstanding, 0 : Neutral, -1 : Lonely, -2: Closed, -3 : Nationalist
private int invIso;
// Action levels.
private int armyLv, scienceLv, productionLv, diplomacyLv, growthLv, developmentLv;
// Quantities of all resources.
// Resources : {S} Soldiers, [D] Data, (G) Goods, #A# Accord, !P! Power, >P> Progress, =T= Territory
private int soldiers, data, goods, accord, power, progress, territory;
// Maximum storages of each resource, the actual number (for convenience, later maybe change to a level and method)
private int soldiersMax, dataMax, goodsMax, accordMax, powerMax, progressMax;
// All of this player's actions.
private ArrayList<String> myActions;
// All actions against this player.
private ArrayList<String> enemyActions;
// New actions against this player.
private ArrayList<String> recent;
// The age of this Empire.
private int age;
// How many turns this empire is under treaty (cannot use Fight)
private int treatied;
// Empty constructor.
public Empire() {}
// Standard constructor.
public Empire(String n) {
name = n;
pacWar = 0;
invIso = 0;
armyLv = 1;
scienceLv = 1;
productionLv = 1;
diplomacyLv = 1;
growthLv = 1;
developmentLv = 1;
soldiers = 0;
data = 0;
goods = 0;
accord = 0;
power = 0;
progress = 0;
territory = 0;
soldiersMax = 10;
dataMax = 10;
goodsMax = 10;
accordMax = 10;
powerMax = 10;
progressMax = 10;
myActions = new ArrayList<String>();
enemyActions = new ArrayList<String>();
recent = new ArrayList<String>();
age = 0;
treatied = 0;
}
// Territory bonus. Log(terr) = bonus
public int getTerrBonus()
{
return (int) Math.log(territory * 1.0);
}
// Attempts to treaty this player. If accord >= territory, it succeeds.
public boolean treaty(int accord)
{
if (accord >= territory)
{
treatied += 2;
return true;
}
return false;
}
// The actual words of this player's alignment.
public String getAlignText() {
String out = "";
switch (pacWar) {
case 3:
out += "Peaceful";
break;
case 2:
out += "Accepting";
break;
case 1:
out += "Welcoming";
break;
case -1:
out += "Unfriendly";
break;
case -2:
out += "Warlike";
break;
case -3:
out += "Destructive";
break;
}
switch (invIso) {
case 3:
out += " Interventionist";
break;
case 2:
out += " Interfering";
break;
case 1:
out += " Upstanding";
break;
case -1:
out += " Lonely";
break;
case -2:
out += " Closed";
break;
case -3:
out += " Nationalist";
break;
}
if (out.equals(""))
out = "Neutral";
return out;
}
// Text representation of pacWar and invIso, i.e. this empire's alignment.
public String getAlign() {
String out = "";
String adder = "";
if (pacWar > 0) // Pacifist
adder = "+";
else if (pacWar < 0) // Warmonger
adder = "-";
for (int i = 0; i < Math.abs(pacWar); i++)
out += adder;
adder = "";
if (invIso > 0) // Involved
adder = "=";
else if (invIso < 0) // Isolationist
adder = "~";
for (int i = 0; i < Math.abs(invIso); i++)
out += adder;
return out;
}
// Easy comparison method for battles.
public boolean canDefeat(Empire e) {
return e.getSoldiers() < soldiers; // i.e. This empire wins
}
// Gets the assosciated cost for something of the given level (1: 10, 2 : 50, 3 : 250, 4: 1250, 5: 6050, 6: 30250)
public int ascCost(int lv)
{
return (int) (10 * Math.pow(5, lv - 1));
}
// Indexes : 0 - Army, 1 - Science, 2 - Production, 3 - Diplomacy, 4 - Growth, 5 - Development
// Levels : 1: 10, 2 : 50, 3 : 250, 4: 1250, 5: 6050, 6: 30250
// Returns the cost array for this empire.
public int[] costArray()
{
int[] out = new int[6];
out[0] = ascCost(armyLv);
out[1] = ascCost(scienceLv);
out[2] = ascCost(productionLv);
out[3] = ascCost(diplomacyLv);
out[4] = ascCost(growthLv);
out[5] = ascCost(developmentLv);
return out;
}
// Method that upgrades an action if the player can pay, returns false if they can't.
// 0 - Army, 1 - Science, 2 - Production, 3 - Diplomacy, 4 - Growth, 5 - Development
public boolean upgrade(int index)
{
int[] out = costArray();
if (data >= out[index])
{
data -= out[index];
switch (index) {
case 0:
armyLv++;
break;
case 1:
scienceLv++;
break;
case 2:
productionLv++;
break;
case 3:
diplomacyLv++;
break;
case 4:
growthLv++;
break;
case 5:
developmentLv++;
break;
}
return true;
}
else
return false;
}
// Returns the total level of this empire's upgrades, i.e. the sum of all levels past one. 1 2 3 3 5 4 = 12. Maximum is thus 30.
public int empireLv()
{
return (int) (armyLv + scienceLv + productionLv + diplomacyLv + growthLv + developmentLv) - 6;
}
// Increases age by 1
public void countAge()
{
age++;
}
// Bonus getters. +0, +1, +2, or +3.
public int warmonger()
{
switch (pacWar) {
case -1:
return 1;
case -2:
return 2;
case -3:
return 3;
default:
return 0;
}
}
public int pacifist()
{
switch (pacWar) {
case 1:
return 1;
case 2:
return 2;
case 3:
return 3;
default:
return 0;
}
}
public int isolationist()
{
switch (invIso) {
case -1:
return 1;
case -2:
return 2;
case -3:
return 3;
default:
return 0;
}
}
public int involved()
{
switch (invIso) {
case 1:
return 1;
case 2:
return 2;
case 3:
return 3;
default:
return 0;
}
}
// Getters, adders, and setters.
public void addEnemyAction(String plus)
{
enemyActions.add(plus);
recent.add(plus);
}
public void addMyAction(String plus)
{
myActions.add(plus);
}
// Returns recent and then wipes it.
public ArrayList<String> getClearRecents()
{
ArrayList<String> out = recent;
recent = new ArrayList<String>();
return out;
}
public int getSoldiersMax() {
return soldiersMax;
}
public void setSoldiersMax(int soldiersMax) {
this.soldiersMax = soldiersMax;
}
public void addSoldiers(int plus)
{
soldiers += plus;
if (soldiers > soldiersMax)
soldiers = soldiersMax;
if (soldiers < 0)
soldiers = 0;
}
public int getGoodsMax() {
return goodsMax;
}
public void setGoodsMax(int goodsMax) {
this.goodsMax = goodsMax;
}
public void addGoods(int plus)
{
goods += plus;
if (goods > goodsMax)
goods = goodsMax;
if (goods < 0)
goods = 0;
}
public int getAccordMax() {
return accordMax;
}
public void setAccordMax(int accordMax) {
this.accordMax = accordMax;
}
public void addAccord(int plus)
{
accord += plus;
if (accord > accordMax)
accord = accordMax;
if (accord < 0)
accord = 0;
}
public int getPowerMax() {
return powerMax;
}
public void setPowerMax(int powerMax) {
this.powerMax = powerMax;
}
public void addPower(int plus)
{
power += plus;
if (power > powerMax)
power = powerMax;
if (power < 0)
power = 0;
}
public int getProgressMax() {
return progressMax;
}
public void setProgressMax(int progressMax) {
this.progressMax = progressMax;
}
public void addProgress(int plus)
{
progress += plus;
if (progress > progressMax)
progress = progressMax;
if (progress < 0)
progress = 0;
}
public int getDataMax() {
return dataMax;
}
public void setDataMax(int dataMax) {
this.dataMax = dataMax;
}
public void addData(int plus)
{
data += plus;
if (data > dataMax)
data = dataMax;
if (data < 0)
data = 0;
}
public int getData() {
return data;
}
public void setData(int data) {
this.data = data;
}
public int getProgress() {
return progress;
}
public void setProgress(int progress) {
this.progress = progress;
}
public int getAccord() {
return accord;
}
public void setAccord(int accord) {
this.accord = accord;
}
public int getTerritory() {
return territory;
}
public void setTerritory(int territory) {
this.territory = territory;
}
public void addTerritory(int plus)
{
territory += plus;
if (territory < 0)
territory = 0;
}
public int getPower() {
return power;
}
public void setPower(int power) {
this.power = power;
}
public int getGoods() {
return goods;
}
public void setGoods(int goods) {
this.goods = goods;
}
public int getSoldiers() {
return soldiers;
}
public void setSoldiers(int soldiers) {
this.soldiers = soldiers;
}
public int getProductionLv() {
return productionLv;
}
public void setProductionLv(int productionLv) {
this.productionLv = productionLv;
}
public int getArmyLv() {
return armyLv;
}
public void setArmyLv(int armyLv) {
this.armyLv = armyLv;
}
public int getScienceLv() {
return scienceLv;
}
public void setScienceLv(int scienceLv) {
this.scienceLv = scienceLv;
}
public int getDiplomacyLv() {
return diplomacyLv;
}
public void setDiplomacyLv(int diplomacyLv) {
this.diplomacyLv = diplomacyLv;
}
public int getGrowthLv() {
return growthLv;
}
public void setGrowthLv(int growthLv) {
this.growthLv = growthLv;
}
public int getDevelopmentLv() {
return developmentLv;
}
public void setDevelopmentLv(int developmentLv) {
this.developmentLv = developmentLv;
}
public int getInvIso() {
return invIso;
}
public void setInvIso(int invIso) {
this.invIso = invIso;
}
public int getPacWar() {
return pacWar;
}
public void setPacWar(int pacWar) {
this.pacWar = pacWar;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList<String> getActions() {
return myActions;
}
public void setActions(ArrayList<String> actions) {
this.myActions = actions;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getTreatied() {
return treatied;
}
public void setTreatied(int treatied) {
this.treatied = treatied;
}
public ArrayList<String> getRecent() {
return recent;
}
public void setRecent(ArrayList<String> recent) {
this.recent = recent;
}
}