This repository has been archived on 2023-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
BWMirror-Generator/manual-bwapi/TilePosition.java

93 lines
2.1 KiB
Java
Raw Normal View History

2014-08-05 04:43:14 -04:00
package bwapi;
2017-04-11 10:48:21 -04:00
import bwapi.Position;
2014-08-05 04:43:14 -04:00
import java.lang.Override;
import java.util.HashMap;
import java.util.Map;
/**
* Build Tiles - each build tile is a 4x4 square of walk tiles, or a 32x32 square of pixels.
* These are called build tiles because buildability data is available at this resolution, and correspond to the tiles seen in game.
* For example, a Command Center occupies an area of 4x3 build tiles.
*/
2014-12-13 12:33:26 -05:00
public class TilePosition extends AbstractPoint<TilePosition>{
2014-08-05 04:43:14 -04:00
private int x, y;
2017-04-11 10:48:21 -04:00
public static final int SIZE_IN_PIXELS = 32;
2014-08-05 04:43:14 -04:00
public TilePosition(int x, int y) {
this.x = x;
this.y = y;
}
public String toString() {
return "[" + x + ", " + y + "]";
}
public native boolean isValid();
public native TilePosition makeValid();
public native double getLength();
public int getX() {
return x;
}
public int getY() {
return y;
}
public static TilePosition Invalid;
public static TilePosition None;
public static TilePosition Unknown;
private static Map<Long, TilePosition> instances = new HashMap<Long, TilePosition>();
private TilePosition(long pointer) {
this.pointer = pointer;
}
private static TilePosition get(long pointer) {
TilePosition instance = instances.get(pointer);
if (instance == null) {
instance = new TilePosition(pointer);
instances.put(pointer, instance);
}
return instance;
}
private long pointer;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof TilePosition)) return false;
TilePosition that = (TilePosition) o;
if (x != that.x) return false;
if (y != that.y) return false;
return true;
}
@Override
public int hashCode() {
int result = x;
result = 31 * result + y;
return result;
}
2014-12-13 12:33:26 -05:00
public TilePosition getPoint(){
return this;
}
2017-04-11 10:48:21 -04:00
public Position toPosition(){
return new Position(x * SIZE_IN_PIXELS, y * SIZE_IN_PIXELS);
}
2014-08-05 04:43:14 -04:00
}