|
20 | 20 | import bwem.unit.Mineral; |
21 | 21 | import bwem.unit.Resource; |
22 | 22 | import bwem.util.BwemExt; |
| 23 | + |
23 | 24 | import java.util.ArrayList; |
24 | 25 | import java.util.List; |
25 | 26 | import java.util.Objects; |
| 27 | + |
26 | 28 | public class BaseImpl implements Base { |
27 | | - private final Area area; |
28 | | - private TilePosition location; |
29 | | - private Position center; |
30 | | - private final List<Mineral> minerals = new ArrayList<>(); |
31 | | - private final List<Geyser> geysers = new ArrayList<>(); |
32 | | - private final List<Mineral> blockingMinerals; |
33 | | - private boolean isStartingLocation = false; |
34 | | - |
35 | | - public BaseImpl( |
36 | | - final Area area, |
37 | | - final TilePosition location, |
38 | | - final List<Resource> assignedResources, |
39 | | - final List<Mineral> blockingMinerals) { |
40 | | - this.area = area; |
41 | | - this.location = location; |
42 | | - this.center = BwemExt.centerOfBuilding(location, UnitType.Terran_Command_Center.tileSize()); |
43 | | - this.blockingMinerals = blockingMinerals; |
44 | | - |
45 | | - // bwem_assert(!AssignedResources.empty()); |
46 | | - if (assignedResources.isEmpty()) { |
47 | | - throw new IllegalArgumentException(); |
| 29 | + private final Area area; |
| 30 | + private final List<Mineral> minerals = new ArrayList<>(); |
| 31 | + private final List<Geyser> geysers = new ArrayList<>(); |
| 32 | + private final List<Mineral> blockingMinerals; |
| 33 | + private TilePosition location; |
| 34 | + private Position center; |
| 35 | + private boolean isStartingLocation = false; |
| 36 | + |
| 37 | + public BaseImpl( |
| 38 | + final Area area, |
| 39 | + final TilePosition location, |
| 40 | + final List<Resource> assignedResources, |
| 41 | + final List<Mineral> blockingMinerals) { |
| 42 | + this.area = area; |
| 43 | + this.location = location; |
| 44 | + this.center = BwemExt.centerOfBuilding(location, UnitType.Terran_Command_Center.tileSize()); |
| 45 | + this.blockingMinerals = blockingMinerals; |
| 46 | + |
| 47 | + // bwem_assert(!AssignedResources.empty()); |
| 48 | + if (assignedResources.isEmpty()) { |
| 49 | + throw new IllegalArgumentException(); |
| 50 | + } |
| 51 | + |
| 52 | + for (final Resource assignedResource : assignedResources) { |
| 53 | + if (assignedResource instanceof Mineral) { |
| 54 | + final Mineral assignedMineral = (Mineral) assignedResource; |
| 55 | + this.minerals.add(assignedMineral); |
| 56 | + } else if (assignedResource instanceof Geyser) { |
| 57 | + final Geyser assignedGeyser = (Geyser) assignedResource; |
| 58 | + this.geysers.add(assignedGeyser); |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public boolean isStartingLocation() { |
| 65 | + return this.isStartingLocation; |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public Area getArea() { |
| 70 | + return this.area; |
48 | 71 | } |
49 | 72 |
|
50 | | - for (final Resource assignedResource : assignedResources) { |
51 | | - if (assignedResource instanceof Mineral) { |
52 | | - final Mineral assignedMineral = (Mineral) assignedResource; |
53 | | - this.minerals.add(assignedMineral); |
54 | | - } else if (assignedResource instanceof Geyser) { |
55 | | - final Geyser assignedGeyser = (Geyser) assignedResource; |
56 | | - this.geysers.add(assignedGeyser); |
57 | | - } |
| 73 | + @Override |
| 74 | + public TilePosition getLocation() { |
| 75 | + return this.location; |
58 | 76 | } |
59 | | - } |
60 | | - |
61 | | - @Override |
62 | | - public boolean isStartingLocation() { |
63 | | - return this.isStartingLocation; |
64 | | - } |
65 | | - |
66 | | - @Override |
67 | | - public Area getArea() { |
68 | | - return this.area; |
69 | | - } |
70 | | - |
71 | | - @Override |
72 | | - public TilePosition getLocation() { |
73 | | - return this.location; |
74 | | - } |
75 | | - |
76 | | - @Override |
77 | | - public Position getCenter() { |
78 | | - return this.center; |
79 | | - } |
80 | | - |
81 | | - @Override |
82 | | - public List<Mineral> getMinerals() { |
83 | | - return this.minerals; |
84 | | - } |
85 | | - |
86 | | - @Override |
87 | | - public List<Geyser> getGeysers() { |
88 | | - return this.geysers; |
89 | | - } |
90 | | - |
91 | | - @Override |
92 | | - public List<Mineral> getBlockingMinerals() { |
93 | | - return this.blockingMinerals; |
94 | | - } |
95 | | - |
96 | | - public void assignStartingLocation(final TilePosition actualLocation) { |
97 | | - this.isStartingLocation = true; |
98 | | - this.location = actualLocation; |
99 | | - this.center = |
100 | | - BwemExt.centerOfBuilding(actualLocation, UnitType.Terran_Command_Center.tileSize()); |
101 | | - } |
102 | | - |
103 | | - public void onMineralDestroyed(final Mineral mineral) { |
104 | | - // bwem_assert(pMineral); |
105 | | - if (mineral == null) { |
106 | | - throw new IllegalArgumentException(); |
| 77 | + |
| 78 | + @Override |
| 79 | + public Position getCenter() { |
| 80 | + return this.center; |
107 | 81 | } |
108 | 82 |
|
109 | | - this.minerals.remove(mineral); |
110 | | - this.blockingMinerals.remove(mineral); |
111 | | - } |
112 | | - |
113 | | - @Override |
114 | | - public boolean equals(final Object object) { |
115 | | - if (this == object) { |
116 | | - return true; |
117 | | - } else if (!(object instanceof Base)) { |
118 | | - return false; |
119 | | - } else { |
120 | | - final Base that = (Base) object; |
121 | | - return (getArea().equals(that.getArea()) |
122 | | - && getLocation().equals(that.getLocation()) |
123 | | - && getCenter().equals(that.getCenter())); |
| 83 | + @Override |
| 84 | + public List<Mineral> getMinerals() { |
| 85 | + return this.minerals; |
124 | 86 | } |
125 | | - } |
126 | 87 |
|
127 | | - @Override |
128 | | - public int hashCode() { |
129 | | - return Objects.hash(this.area, this.location, this.center); |
130 | | - } |
| 88 | + @Override |
| 89 | + public List<Geyser> getGeysers() { |
| 90 | + return this.geysers; |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + public List<Mineral> getBlockingMinerals() { |
| 95 | + return this.blockingMinerals; |
| 96 | + } |
| 97 | + |
| 98 | + public void assignStartingLocation(final TilePosition actualLocation) { |
| 99 | + this.isStartingLocation = true; |
| 100 | + this.location = actualLocation; |
| 101 | + this.center = |
| 102 | + BwemExt.centerOfBuilding(actualLocation, UnitType.Terran_Command_Center.tileSize()); |
| 103 | + } |
| 104 | + |
| 105 | + public void onMineralDestroyed(final Mineral mineral) { |
| 106 | + // bwem_assert(pMineral); |
| 107 | + if (mineral == null) { |
| 108 | + throw new IllegalArgumentException(); |
| 109 | + } |
| 110 | + |
| 111 | + this.minerals.remove(mineral); |
| 112 | + this.blockingMinerals.remove(mineral); |
| 113 | + } |
| 114 | + |
| 115 | + @Override |
| 116 | + public boolean equals(final Object object) { |
| 117 | + if (this == object) { |
| 118 | + return true; |
| 119 | + } else if (!(object instanceof Base)) { |
| 120 | + return false; |
| 121 | + } else { |
| 122 | + final Base that = (Base) object; |
| 123 | + return (getArea().equals(that.getArea()) |
| 124 | + && getLocation().equals(that.getLocation()) |
| 125 | + && getCenter().equals(that.getCenter())); |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + @Override |
| 130 | + public int hashCode() { |
| 131 | + return Objects.hash(this.area, this.location, this.center); |
| 132 | + } |
131 | 133 | } |
0 commit comments