package ch.asynk.rustanddust.game; import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.utils.Disposable; import ch.asynk.rustanddust.engine.Move; public class Order implements Disposable, Pool.Poolable, Comparable { public static int orderId = 1; public static final Order END = new Order(OrderType.END); public enum OrderType { NONE, MOVE, ENGAGE, PROMOTE, END, } private static final Pool orderPool = new Pool() { @Override protected Order newObject() { return new Order(); } }; public static void clearPool() { orderPool.clear(); } public static Order get() { Order c = orderPool.obtain(); return c; } public int id; public int cost; public boolean replay; public Unit unit; public OrderType type; public Move move; public Engagement engagement; public UnitList activable = new UnitList(4); private Order() { reset(); } private Order(OrderType type) { this(); this.type = type; } @Override public void dispose() { orderPool.free(this); } @Override public void reset() { this.id = orderId; orderId += 1; this.cost = 1; this.replay = false; this.unit = null; this.type = OrderType.NONE; this.activable.clear(); if (this.move != null) { this.move.dispose(); this.move = null; } if (this.engagement != null) { this.engagement.dispose(); this.engagement = null; } } @Override public int compareTo(Unit other) { if (unit == other) return 0; return 1; } public boolean isA(OrderType type) { return (type == this.type); } @Override public String toString() { if (type == OrderType.END) return String.format("[00] END"); else return String.format("[%d] %s(%d) : %s", id, type, cost, unit.code); } public void setMove(Unit unit, Move move) { this.unit = unit; this.type = OrderType.MOVE; this.move = move; } public void setPromote(Unit unit) { this.unit = unit; this.type = OrderType.PROMOTE; } public void setEngage(Unit unit, Unit target) { this.unit = unit; this.type = OrderType.ENGAGE; this.engagement = Engagement.get(unit, target); } public void setActivable(UnitList l) { for(Unit u : l) activable.add(u); } }