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/bwapi4/UnitCommand.java

116 lines
3.6 KiB
Java
Raw Normal View History

package bwapi4;
2015-02-09 13:16:11 -05:00
import bwapi.UnitCommandType;
2015-02-09 13:16:11 -05:00
import java.lang.Override;
public class UnitCommand {
2015-02-09 13:16:11 -05:00
private Unit unit;
private UnitCommandType unitCommandType;
private Unit target;
private int x, y;
private int extra;
public UnitCommand(Unit unit, UnitCommandType unitCommandType, Unit target, int x, int y, int extra) {
this.unit = unit;
this.unitCommandType = unitCommandType;
this.target = target;
this.x = x;
this.y = y;
this.extra = extra;
}
public Unit getUnit() {
return unit;
}
public UnitCommandType getUnitCommandType() {
return unitCommandType;
}
public Unit getTarget() {
return target;
}
2015-02-09 13:16:11 -05:00
public int getSlot() {
if (unitCommandType == UnitCommandType.None) {
return extra;
}
return -1;
}
public Position getTargetPosition() {
if (unitCommandType == UnitCommandType.Build ||
unitCommandType == UnitCommandType.Land ||
unitCommandType == UnitCommandType.Place_COP) {
return new Position(x * 32, y * 32);
}
return new Position(x, y);
}
2015-02-09 13:16:11 -05:00
public TilePosition getTargetTilePosition() {
if (unitCommandType == UnitCommandType.Build ||
unitCommandType == UnitCommandType.Land ||
unitCommandType == UnitCommandType.Place_COP) {
return new TilePosition(x, y);
2015-02-07 12:16:07 -05:00
}
2015-02-09 13:16:11 -05:00
return new TilePosition(x / 32, y / 32);
}
public boolean isQueued() {
if (unitCommandType == UnitCommandType.Attack_Move ||
unitCommandType == UnitCommandType.Attack_Unit ||
unitCommandType == UnitCommandType.Move ||
unitCommandType == UnitCommandType.Patrol ||
unitCommandType == UnitCommandType.Hold_Position ||
unitCommandType == UnitCommandType.Stop ||
unitCommandType == UnitCommandType.Follow ||
unitCommandType == UnitCommandType.Gather ||
unitCommandType == UnitCommandType.Return_Cargo ||
unitCommandType == UnitCommandType.Repair ||
unitCommandType == UnitCommandType.Load ||
unitCommandType == UnitCommandType.Unload_All ||
unitCommandType == UnitCommandType.Unload_All_Position ||
unitCommandType == UnitCommandType.Right_Click_Position ||
unitCommandType == UnitCommandType.Right_Click_Unit) {
return extra != 0;
}
2015-02-09 13:16:11 -05:00
return false;
}
2015-02-09 13:16:11 -05:00
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof UnitCommand)) return false;
2015-02-09 13:16:11 -05:00
UnitCommand that = (UnitCommand) o;
2015-02-09 13:16:11 -05:00
if (extra != that.extra) return false;
if (x != that.x) return false;
if (y != that.y) return false;
if (target != null ? !target.equals(that.target) : that.target != null) return false;
if (unit != null ? !unit.equals(that.unit) : that.unit != null) return false;
if (unitCommandType != null ? !unitCommandType.equals(that.unitCommandType) : that.unitCommandType != null)
return false;
2015-02-09 13:16:11 -05:00
return true;
}
@Override
public int hashCode() {
int result = unit != null ? unit.hashCode() : 0;
result = 31 * result + (unitCommandType != null ? unitCommandType.hashCode() : 0);
result = 31 * result + (target != null ? target.hashCode() : 0);
result = 31 * result + x;
result = 31 * result + y;
result = 31 * result + extra;
return result;
}
}