-
Notifications
You must be signed in to change notification settings - Fork 0
/
building.pde
116 lines (95 loc) · 3.24 KB
/
building.pde
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
abstract class Building extends WorldlyObject implements Comparable<Building> {
int[] c = new int[3];
String name;
ArrayList<Human> assignedHumans;
int assignmentLimit;
Building(Cell location, String name) {
super(location);
this.c = new int[]{20, 20, 20};
this.name = name;
this.assignedHumans = new ArrayList<Human>();
this.assignmentLimit = Integer.MAX_VALUE;
location.addBuilding(this);
}
boolean removeAssignee(Human h) {
return this.assignedHumans.remove(h);
}
boolean addAssignee(Human h) {
if (this.numFreeAssignments() > 0) {
this.assignedHumans.add(h);
return true;
}
return false;
}
int numFreeAssignments() {
return this.assignmentLimit - this.assignedHumans.size();
}
// buildings sortable by how many available assignee spaces they have left
@Override public int compareTo(Building b) {
int ourFreeAssign = this.numFreeAssignments();
int theirFreeAssign = b.numFreeAssignments();
if (ourFreeAssign > theirFreeAssign) {
return -1;
} else if (ourFreeAssign < theirFreeAssign) {
return 1;
}
return 0;
}
void draw() {
fill(c[0], c[1], c[2]);
rect(this.loc.x + 1, this.loc.y + 1, this.w, this.h);
}
String getName() {
return this.name;
}
}
enum BuildingCode {
NONE, FARM, CROP, HOVEL, SAWMILL, STOCKPILE, TOWNSQUARE, FOUNDRY, BARRACKS;
@Override
public String toString() {
return name().toLowerCase();
}
}
enum ResourceCode {
LUMBER, METAL;
@Override
public String toString() {
return name().toLowerCase();
}
}
class BuildingCosts {
HashMap<BuildingCode, HashMap<ResourceCode, Integer>> costs;
BuildingCosts() {
HashMap<ResourceCode, Integer> free = new HashMap<ResourceCode, Integer>();
free.put(ResourceCode.LUMBER, 0);
free.put(ResourceCode.METAL, 0);
HashMap<ResourceCode, Integer> farm = new HashMap<ResourceCode, Integer>();
farm.put(ResourceCode.LUMBER, 12);
farm.put(ResourceCode.METAL, 0);
HashMap<ResourceCode, Integer> sawmill = new HashMap<ResourceCode, Integer>();
sawmill.put(ResourceCode.LUMBER, 16);
sawmill.put(ResourceCode.METAL, 4);
HashMap<ResourceCode, Integer> hovel = new HashMap<ResourceCode, Integer>();
hovel.put(ResourceCode.LUMBER, 4);
hovel.put(ResourceCode.METAL, 0);
HashMap<ResourceCode, Integer> stockpile = new HashMap<ResourceCode, Integer>();
stockpile.put(ResourceCode.LUMBER, 4);
stockpile.put(ResourceCode.METAL, 0);
HashMap<ResourceCode, Integer> barracks = new HashMap<ResourceCode, Integer>();
barracks.put(ResourceCode.LUMBER, 32);
barracks.put(ResourceCode.METAL, 32);
HashMap<ResourceCode, Integer> foundry = new HashMap<ResourceCode, Integer>();
foundry.put(ResourceCode.LUMBER, 24);
foundry.put(ResourceCode.METAL, 0);
costs = new HashMap<BuildingCode, HashMap<ResourceCode, Integer>>();
for (BuildingCode buildingCode : BuildingCode.values()) {
costs.put(buildingCode, free);
}
costs.put(BuildingCode.FARM, farm);
costs.put(BuildingCode.SAWMILL, sawmill);
costs.put(BuildingCode.HOVEL, hovel);
costs.put(BuildingCode.STOCKPILE, stockpile);
costs.put(BuildingCode.BARRACKS, barracks);
costs.put(BuildingCode.FOUNDRY, foundry);
}
}