|
| 1 | +// Original work Copyright (c) 2015, 2017, Igor Dimitrijevic |
| 2 | +// Modified work Copyright (c) 2017-2018 OpenBW Team |
| 3 | + |
| 4 | +////////////////////////////////////////////////////////////////////////// |
| 5 | +// |
| 6 | +// This file is part of the BWEM Library. |
| 7 | +// BWEM is free software, licensed under the MIT/X11 License. |
| 8 | +// A copy of the license is provided with the library in the LICENSE file. |
| 9 | +// Copyright (c) 2015, 2017, Igor Dimitrijevic |
| 10 | +// |
| 11 | +////////////////////////////////////////////////////////////////////////// |
| 12 | + |
| 13 | +package bwem; |
| 14 | + |
| 15 | +import bwapi.point.Position; |
| 16 | +import bwapi.point.TilePosition; |
| 17 | +import bwapi.types.UnitType; |
| 18 | +import bwem.area.Area; |
| 19 | +import bwem.unit.Geyser; |
| 20 | +import bwem.unit.Mineral; |
| 21 | +import bwem.unit.Resource; |
| 22 | +import bwem.util.BwemExt; |
| 23 | +import java.util.ArrayList; |
| 24 | +import java.util.List; |
| 25 | +import java.util.Objects; |
| 26 | +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(); |
| 48 | + } |
| 49 | + |
| 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 | + } |
| 58 | + } |
| 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(); |
| 107 | + } |
| 108 | + |
| 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())); |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public int hashCode() { |
| 129 | + return Objects.hash(this.area, this.location, this.center); |
| 130 | + } |
| 131 | +} |
0 commit comments