summaryrefslogtreecommitdiffstats
path: root/core/src/ch
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch')
-rw-r--r--core/src/ch/asynk/rustanddust/engine/Order.java16
-rw-r--r--core/src/ch/asynk/rustanddust/game/Map.java6
-rw-r--r--core/src/ch/asynk/rustanddust/game/Order.java (renamed from core/src/ch/asynk/rustanddust/game/Command.java)64
-rw-r--r--core/src/ch/asynk/rustanddust/game/OrderList.java (renamed from core/src/ch/asynk/rustanddust/engine/OrderList.java)14
-rw-r--r--core/src/ch/asynk/rustanddust/game/map/Map4Orders.java (renamed from core/src/ch/asynk/rustanddust/game/map/Map4Commands.java)52
5 files changed, 65 insertions, 87 deletions
diff --git a/core/src/ch/asynk/rustanddust/engine/Order.java b/core/src/ch/asynk/rustanddust/engine/Order.java
deleted file mode 100644
index 960b126..0000000
--- a/core/src/ch/asynk/rustanddust/engine/Order.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package ch.asynk.rustanddust.engine;
-
-import java.lang.Comparable;
-
-import com.badlogic.gdx.utils.Disposable;
-import com.badlogic.gdx.utils.Pool;
-import com.badlogic.gdx.utils.Json;
-
-public abstract class Order implements Disposable, Pool.Poolable, Json.Serializable, Comparable<Pawn>
-{
- public interface OrderType
- {
- }
-
- public abstract boolean isA(OrderType type);
-}
diff --git a/core/src/ch/asynk/rustanddust/game/Map.java b/core/src/ch/asynk/rustanddust/game/Map.java
index 4484327..2386f5d 100644
--- a/core/src/ch/asynk/rustanddust/game/Map.java
+++ b/core/src/ch/asynk/rustanddust/game/Map.java
@@ -8,9 +8,9 @@ import ch.asynk.rustanddust.engine.SelectedTile;
import ch.asynk.rustanddust.engine.Meteorology;
import ch.asynk.rustanddust.game.Unit;
import ch.asynk.rustanddust.game.Engagement;
-import ch.asynk.rustanddust.game.map.Map4Commands;
+import ch.asynk.rustanddust.game.map.Map4Orders;
-public abstract class Map extends Map4Commands
+public abstract class Map extends Map4Orders
{
protected final Meteorology meteorology;
@@ -39,7 +39,7 @@ public abstract class Map extends Map4Commands
RustAndDust.debug("TurnDone", String.format(" Processed Commands : %d", commandsSize()));
// FIXME must emit the turn commands
- commandsClear();
+ ordersClear();
}
@Override
diff --git a/core/src/ch/asynk/rustanddust/game/Command.java b/core/src/ch/asynk/rustanddust/game/Order.java
index a146257..07fa19c 100644
--- a/core/src/ch/asynk/rustanddust/game/Command.java
+++ b/core/src/ch/asynk/rustanddust/game/Order.java
@@ -1,18 +1,17 @@
package ch.asynk.rustanddust.game;
import com.badlogic.gdx.utils.Pool;
+import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.JsonValue;
-import ch.asynk.rustanddust.engine.Order;
import ch.asynk.rustanddust.engine.Move;
-import ch.asynk.rustanddust.engine.Pawn;
import ch.asynk.rustanddust.engine.Tile;
import ch.asynk.rustanddust.engine.util.Collection;
-public class Command extends Order
+public class Order implements Disposable, Pool.Poolable, Json.Serializable, Comparable<Unit>
{
- public enum CommandType implements Order.OrderType
+ public enum OrderType
{
NONE,
MOVE,
@@ -21,40 +20,36 @@ public class Command extends Order
END_OF_TURN;
}
- private static final Pool<Command> commandPool = new Pool<Command>()
+ private static final Pool<Order> orderPool = new Pool<Order>()
{
@Override
- protected Command newObject() {
- return new Command();
+ protected Order newObject() {
+ return new Order();
}
};
public static void clearPool()
{
- commandPool.clear();
+ orderPool.clear();
}
- public static Command get(Player player)
+ public static Order get(Player player)
{
- Command c = commandPool.obtain();
+ Order c = orderPool.obtain();
c.player = player;
- c.ap = player.getAp();
- c.turn = player.getCurrentTurn();
return c;
}
- public CommandType type;
+ public OrderType type;
public Player player;
- public int ap;
- public int turn;
public Unit unit;
public Unit.UnitId unitId;
public Unit.UnitType unitType;
- public Tile unitTile;
+ public Hex unitHex;
public Move move;
public Engagement engagement;
- private Command()
+ private Order()
{
reset();
}
@@ -62,13 +57,13 @@ public class Command extends Order
@Override
public void dispose()
{
- commandPool.free(this);
+ orderPool.free(this);
}
@Override
public void reset()
{
- this.type = CommandType.NONE;
+ this.type = OrderType.NONE;
this.player = null;
this.unit = null;
if (this.move != null) {
@@ -82,14 +77,13 @@ public class Command extends Order
}
@Override
- public int compareTo(Pawn pawn)
+ public int compareTo(Unit other)
{
- if (pawn == unit)
+ if (unit == other)
return 0;
return 1;
}
- @Override
public boolean isA(OrderType type)
{
return (type == this.type);
@@ -103,20 +97,20 @@ public class Command extends Order
public void setMove(Unit unit, Move move)
{
- this.type = CommandType.MOVE;
+ this.type = OrderType.MOVE;
this.move = move;
setUnit(unit);
}
public void setPromote(Unit unit)
{
- this.type = CommandType.PROMOTE;
+ this.type = OrderType.PROMOTE;
setUnit(unit);
}
public void setEngage(Unit unit, Unit target)
{
- this.type = CommandType.ENGAGE;
+ this.type = OrderType.ENGAGE;
this.engagement = Engagement.get(unit, target);
setUnit(unit);
}
@@ -126,7 +120,7 @@ public class Command extends Order
this.unit = unit;
this.unitId = unit.id;
this.unitType = unit.type;
- this.unitTile = unit.getTile();
+ this.unitHex = unit.getHex();
}
@Override
@@ -135,15 +129,15 @@ public class Command extends Order
json.writeValue("type", type);
json.writeObjectStart("player");
json.writeValue("army", player.getName());
- json.writeValue("turn", turn);
- json.writeValue("aps", ap);
+ json.writeValue("turn", player.getCurrentTurn());
+ json.writeValue("aps", player.getAp());
json.writeObjectEnd();
json.writeObjectStart("unit");
json.writeValue("id", unitId);
json.writeValue("type", unitType);
json.writeValue("hq", unit.hq);
json.writeValue("ace", unit.ace);
- writeTile(json, "tile", unitTile);
+ writeHex(json, "tile", unitHex);
json.writeObjectEnd();
if (move != null) writeMove(json, "move", move);
if (engagement != null) writeEngagement(json, "engagement", engagement);
@@ -153,8 +147,8 @@ public class Command extends Order
{
json.writeObjectStart(key);
json.writeValue("type", move.type);
- writeTile(json, "from", move.from);
- writeTile(json, "to", move.to);
+ writeHex(json, "from", (Hex) move.from);
+ writeHex(json, "to", (Hex) move.to);
json.writeValue("orientation", move.orientation.r());
writeTiles(json, "path", move.tiles);
json.writeObjectEnd();
@@ -187,7 +181,7 @@ public class Command extends Order
json.writeValue("id", u.id);
json.writeValue("ace", u.ace);
json.writeValue("army", u.getArmy());
- writeTile(json, "tile", u.getTile());
+ writeHex(json, "tile", u.getHex());
json.writeObjectEnd();
}
@@ -199,7 +193,7 @@ public class Command extends Order
json.writeArrayEnd();
}
- private void writeTile(Json json, String key, Tile t)
+ private void writeHex(Json json, String key, Hex t)
{
if (t == null) return;
if (key != null) json.writeObjectStart(key);
@@ -213,13 +207,13 @@ public class Command extends Order
{
json.writeArrayStart(key);
for (Tile t : tiles)
- writeTile(json, null, t);
+ writeHex(json, null, (Hex) t);
json.writeArrayEnd();
}
@Override
public void read(Json json, JsonValue jsonMap)
{
- // FIXME Command.read(Json, JsonValue);
+ // FIXME Order.read(Json, JsonValue);
}
}
diff --git a/core/src/ch/asynk/rustanddust/engine/OrderList.java b/core/src/ch/asynk/rustanddust/game/OrderList.java
index 9e4fe6c..d6c5b5f 100644
--- a/core/src/ch/asynk/rustanddust/engine/OrderList.java
+++ b/core/src/ch/asynk/rustanddust/game/OrderList.java
@@ -1,4 +1,4 @@
-package ch.asynk.rustanddust.engine;
+package ch.asynk.rustanddust.game;
import java.util.Iterator;
@@ -15,33 +15,33 @@ public class OrderList extends IterableArray<Order> implements Json.Serializable
super(capacity);
}
- public Order get(Pawn pawn, Order.OrderType type)
+ public Order get(Unit unit, Order.OrderType type)
{
for (Order o : this) {
- if ((o.compareTo(pawn) == 0) && (o.isA(type)))
+ if ((o.compareTo(unit) == 0) && (o.isA(type)))
return o;
}
return null;
}
- public void dispose(Pawn pawn)
+ public void dispose(Unit unit)
{
Iterator<Order> it = iterator();
while (it.hasNext()) {
Order order = it.next();
- if (order.compareTo(pawn) == 0) {
+ if (order.compareTo(unit) == 0) {
it.remove();
order.dispose();
}
}
}
- public void dispose(Pawn pawn, Order.OrderType type)
+ public void dispose(Unit unit, Order.OrderType type)
{
Iterator<Order> it = iterator();
while (it.hasNext()) {
Order order = it.next();
- if ((order.compareTo(pawn) == 0) && (order.isA(type))) {
+ if ((order.compareTo(unit) == 0) && (order.isA(type))) {
it.remove();
order.dispose();
}
diff --git a/core/src/ch/asynk/rustanddust/game/map/Map4Commands.java b/core/src/ch/asynk/rustanddust/game/map/Map4Orders.java
index 2335475..3aa0bbf 100644
--- a/core/src/ch/asynk/rustanddust/game/map/Map4Commands.java
+++ b/core/src/ch/asynk/rustanddust/game/map/Map4Orders.java
@@ -5,42 +5,42 @@ import com.badlogic.gdx.graphics.Texture;
import ch.asynk.rustanddust.RustAndDust;
import ch.asynk.rustanddust.engine.Move;
import ch.asynk.rustanddust.engine.SelectedTile;
-import ch.asynk.rustanddust.engine.OrderList;
import ch.asynk.rustanddust.engine.Orientation;
import ch.asynk.rustanddust.game.Hex;
import ch.asynk.rustanddust.game.Unit;
import ch.asynk.rustanddust.game.Player;
-import ch.asynk.rustanddust.game.Command;
+import ch.asynk.rustanddust.game.Order;
+import ch.asynk.rustanddust.game.OrderList;
import ch.asynk.rustanddust.game.Engagement;
import ch.asynk.rustanddust.game.Battle;
-public abstract class Map4Commands extends Map3Animations
+public abstract class Map4Orders extends Map3Animations
{
private final Battle battle;
- private final OrderList commands;
+ private final OrderList orders;
protected abstract int engagementCost(Engagement e);
protected abstract void resolveEngagement(Engagement e);
- public Map4Commands(final RustAndDust game, Texture map, SelectedTile hex)
+ public Map4Orders(final RustAndDust game, Texture map, SelectedTile hex)
{
super(game, map, hex);
this.battle = game.ctrl.battle;
- this.commands = new OrderList(10);
+ this.orders = new OrderList(10);
}
@Override
public void dispose()
{
super.dispose();
- commands.dispose();
- Command.clearPool();
+ orders.dispose();
+ Order.clearPool();
Engagement.clearPool();
}
- protected int commandsSize() { return commands.size(); }
- protected void commandsClear() { commands.dispose(); }
+ protected int ordersSize() { return orders.size(); }
+ protected void ordersClear() { orders.dispose(); }
// STATES ENTRY ->
@@ -51,8 +51,8 @@ public abstract class Map4Commands extends Map3Animations
public boolean setOnBoard(final Unit unit, Hex to, Orientation entry)
{
- commands.dispose(unit);
- return (process(getMoveCommand(unit, Move.getSet(unit, to, entry))) == 1);
+ orders.dispose(unit);
+ return (process(getMoveOrder(unit, Move.getSet(unit, to, entry))) == 1);
}
public boolean enterBoard(final Unit unit, Hex to, int allowedMoves)
@@ -61,25 +61,25 @@ public abstract class Map4Commands extends Map3Animations
if (entry == Orientation.KEEP)
return false;
- return (process(getMoveCommand(unit, Move.getEnter(unit, to, entry))) == 1);
+ return (process(getMoveOrder(unit, Move.getEnter(unit, to, entry))) == 1);
}
public int exitBoard(final Unit unit)
{
- return process(getMoveCommand(unit, paths.getExitMove()));
+ return process(getMoveOrder(unit, paths.getExitMove()));
}
public int moveUnit(final Unit unit)
{
- return process(getMoveCommand(unit, paths.getMove()));
+ return process(getMoveOrder(unit, paths.getMove()));
}
public void revertMoves()
{
for (Unit unit: activatedUnits) {
RustAndDust.debug(" revertMove() " + unit);
- revertLastPawnMove(unit, ((Command) commands.get(unit, Command.CommandType.MOVE)).move);
- commands.dispose(unit, Command.CommandType.MOVE);
+ revertLastPawnMove(unit, ((Order) orders.get(unit, Order.OrderType.MOVE)).move);
+ orders.dispose(unit, Order.OrderType.MOVE);
}
activatedUnits.clear();
}
@@ -91,7 +91,7 @@ public abstract class Map4Commands extends Map3Animations
revertclaim(unit, unit.getHex());
removePawn(unit);
battle.getPlayer().revertUnitEntry(unit);
- commands.dispose(unit);
+ orders.dispose(unit);
unit.reset();
}
@@ -99,23 +99,23 @@ public abstract class Map4Commands extends Map3Animations
{
attack(unit, target, true);
- Command cmd = Command.get(battle.getPlayer());
+ Order cmd = Order.get(battle.getPlayer());
cmd.setEngage(unit, target);
return (process(cmd) == 1);
}
public void promoteUnit(final Unit unit)
{
- Command cmd = Command.get(battle.getPlayer());
+ Order cmd = Order.get(battle.getPlayer());
cmd.setPromote(unit);
process(cmd);
}
// STATES ENTRY <-
- private Command getMoveCommand(Unit unit, Move move)
+ private Order getMoveOrder(Unit unit, Move move)
{
- Command cmd = Command.get(battle.getPlayer());
+ Order cmd = Order.get(battle.getPlayer());
cmd.setMove(unit, move);
return cmd;
}
@@ -139,9 +139,9 @@ public abstract class Map4Commands extends Map3Animations
return 1;
}
- private int process(Command cmd)
+ private int process(Order cmd)
{
- RustAndDust.debug("Command", cmd.toString());
+ RustAndDust.debug("Order", cmd.toString());
int r = 1;
@@ -156,13 +156,13 @@ public abstract class Map4Commands extends Map3Animations
r = doEngagement(cmd.engagement);
break;
default:
- System.err.println(String.format("process wrong Command type %s", cmd.type));
+ System.err.println(String.format("process wrong Order type %s", cmd.type));
r = -1;
break;
}
if (r != -1)
- commands.add(cmd);
+ orders.add(cmd);
return r;
}