-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactory.java
More file actions
executable file
·116 lines (98 loc) · 3.63 KB
/
Factory.java
File metadata and controls
executable file
·116 lines (98 loc) · 3.63 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
import bc.*;
public class Factory extends UnitInstance {
private boolean isBuilt;
public Factory(int id, boolean isBuilt) {
super(id);
this.isBuilt = isBuilt;
}
/**
* Emergency build worker
*/
public void emergencyRun() {
if (isBuilt) {
if (Player.gc.canProduceRobot(this.getId(), UnitType.Worker)) {
Player.gc.produceRobot(this.getId(), UnitType.Worker);
}
}
unload();
}
/**
* Method that will run code for the factory
*/
@Override
public void run() {
if (isBuilt) {
UnitType unitToProduce = findUnitToProduce();
if (Player.gc.canProduceRobot(this.getId(), unitToProduce)) {
Player.gc.produceRobot(this.getId(), unitToProduce);
switch (unitToProduce) {
case Knight:
Earth.knightCount++;
//System.out.println("Knight count " + Earth.knightCount);
break;
case Ranger:
Earth.rangerCount++;
//System.out.println("Ranger count " + Earth.rangerCount);
break;
case Healer:
Earth.healerCount++;
//System.out.println("Healer count " + Earth.healerCount);
break;
case Mage:
Earth.mageCount++;
//System.out.println("Mage count " + Earth.mageCount);
break;
}
}
}
unload();
}
/**
* Method that will unload units inside its garrison when it can
*/
public void unload() {
for (int i = 0; i < 8; i++) {
Direction direction = Direction.swigToEnum(i);
if (Player.gc.canUnload(this.getId(), direction)) {
Player.gc.unload(this.getId(), direction);
MapLocation unloadLocation = this.getLocation().add(direction);
int unitId = Player.gc.senseUnitAtLocation(unloadLocation).id();
UnitType unitType = Player.gc.unit(unitId).unitType();
UnitInstance unitInstance = null;
switch (unitType) {
case Knight:
unitInstance = new Knight(unitId);
break;
case Ranger:
unitInstance = new Ranger(unitId);
break;
case Healer:
unitInstance = new Healer(unitId);
break;
case Mage:
unitInstance = new Mage(unitId);
break;
case Worker:
unitInstance = new Worker(unitId);
Earth.earthStagingWorkerMap.put(unitId, unitInstance);
return;
default:
unitInstance = new Knight(unitId);
System.out.println("ERROR in UNLOAD, unit type: " + unitType);
}
Earth.earthStagingAttackerMap.put(unitId, unitInstance);
}
}
}
/**
* Method that will tell the factory produce a specific unit given the current unit counts.
* @return The unit to produce
*/
private UnitType findUnitToProduce() {
if (Earth.healerCount < (Earth.knightCount) * (.5) && Earth.knightCount > 5) {
return UnitType.Healer;
} else {
return UnitType.Knight;
}
}
}