summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/game/map
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-05-03 15:31:32 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2016-05-03 15:31:32 +0200
commit79793cf2dd5cad2af5fa513a7213292d2ee53f86 (patch)
tree306e849be86d992a543e42c8e8ddec80d24795a6 /core/src/ch/asynk/rustanddust/game/map
parentcff800a98e8aec4e454c5dc84fd4249b7127a1fd (diff)
downloadRustAndDust-79793cf2dd5cad2af5fa513a7213292d2ee53f86.zip
RustAndDust-79793cf2dd5cad2af5fa513a7213292d2ee53f86.tar.gz
OMG: add event queue, messages, replay, bounce animation, complete states rewrite ...
Diffstat (limited to 'core/src/ch/asynk/rustanddust/game/map')
-rw-r--r--core/src/ch/asynk/rustanddust/game/map/Map1Units.java8
-rw-r--r--core/src/ch/asynk/rustanddust/game/map/Map2Moves.java13
-rw-r--r--core/src/ch/asynk/rustanddust/game/map/Map3Animations.java53
-rw-r--r--core/src/ch/asynk/rustanddust/game/map/Map4Orders.java350
-rw-r--r--core/src/ch/asynk/rustanddust/game/map/Map5Marshal.java79
5 files changed, 276 insertions, 227 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/map/Map1Units.java b/core/src/ch/asynk/rustanddust/game/map/Map1Units.java
index 3aa0c8d..b490042 100644
--- a/core/src/ch/asynk/rustanddust/game/map/Map1Units.java
+++ b/core/src/ch/asynk/rustanddust/game/map/Map1Units.java
@@ -79,13 +79,13 @@ public abstract class Map1Units extends Map0Hex
}
}
- public Unit unitsMoveableGet(int i) { return activableUnits.get(i); }
+ public Unit getFirstActivable() { return activableUnits.get(0); }
public void unitsTargetClear() { targetUnits.clear(); }
public void unitsActivatedClear() { activatedUnits.clear(); }
public int unitsActivatedSize() { return activatedUnits.size(); }
- public int unitsActivableSize() { return activableUnits.size(); }
+ public int unitsActivableSize() { return activableUnits.size(); }
public boolean unitsTargetContains(Unit unit) { return targetUnits.contains(unit); }
public boolean unitsActivableContains(Unit unit) { return activableUnits.contains(unit); }
@@ -94,8 +94,8 @@ public abstract class Map1Units extends Map0Hex
public void unitsTargetHide() { unitsShowOverlay(targetUnits, Unit.TARGET, false); }
public void unitsAssistShow() { unitsShowOverlay(activableUnits, Unit.MAY_FIRE, true); }
public void unitsAssistHide() { unitsShowOverlay(activableUnits, Unit.MAY_FIRE, false); unitsShowOverlay(activableUnits, Unit.FIRE, false); }
- public void unitsActivableShow() { unitsShowOverlay(activableUnits, Unit.ACTIVEABLE, true); }
- public void unitsActivableHide() { unitsShowOverlay(activableUnits, Unit.ACTIVEABLE, false); }
+ public void unitsActivableShow() { unitsShowOverlay(activableUnits, Unit.ACTIVEABLE, true); }
+ public void unitsActivableHide() { unitsShowOverlay(activableUnits, Unit.ACTIVEABLE, false); }
private void unitsShowOverlay(UnitList units, int overlay, boolean on)
{
diff --git a/core/src/ch/asynk/rustanddust/game/map/Map2Moves.java b/core/src/ch/asynk/rustanddust/game/map/Map2Moves.java
index e7ba8ce..e092fea 100644
--- a/core/src/ch/asynk/rustanddust/game/map/Map2Moves.java
+++ b/core/src/ch/asynk/rustanddust/game/map/Map2Moves.java
@@ -51,21 +51,10 @@ public abstract class Map2Moves extends Map1Units
return 0;
}
- public void collectUpdate(Unit unit)
- {
- movesHide();
- unitsActivableHide();
- movesCollect(unit);
- collectMoveable(unit);
- movesShow();
- unitsActivableShow();
- activatedUnits.clear();
- }
-
public int pathsSize() { return paths.size(); }
public void pathsClear() { paths.clear(); }
public void pathsInit(Unit unit) { paths.init(unit); }
- public void pathsInit(Unit unit, Hex hex) { paths.init(unit, hex); }
+ public void pathsInit(Unit unit, Hex from) { paths.init(unit, from); }
public int pathsBuild(Hex hex) { return paths.build(hex); }
public Hex pathsTo() { return (Hex) paths.to; }
public void pathsSetOrientation(Orientation o) { paths.orientation = o; }
diff --git a/core/src/ch/asynk/rustanddust/game/map/Map3Animations.java b/core/src/ch/asynk/rustanddust/game/map/Map3Animations.java
index eba741b..d109366 100644
--- a/core/src/ch/asynk/rustanddust/game/map/Map3Animations.java
+++ b/core/src/ch/asynk/rustanddust/game/map/Map3Animations.java
@@ -4,6 +4,7 @@ import com.badlogic.gdx.audio.Sound;
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.gfx.Moveable;
import ch.asynk.rustanddust.engine.gfx.animations.AnimationSequence;
@@ -21,7 +22,7 @@ import ch.asynk.rustanddust.game.Hex;
import ch.asynk.rustanddust.game.Unit;
import ch.asynk.rustanddust.game.Army;
import ch.asynk.rustanddust.game.Player;
-import ch.asynk.rustanddust.game.Ctrl.EventType;
+import ch.asynk.rustanddust.game.Ctrl.MsgType;
public abstract class Map3Animations extends Map2Moves implements MoveToAnimationCb
{
@@ -31,6 +32,8 @@ public abstract class Map3Animations extends Map2Moves implements MoveToAnimatio
private Sound sound;
private long soundId = -1;
+ protected static final float BOUNCE_DURATION = 0.3f;
+
public Map3Animations(final RustAndDust game, Texture map, SelectedTile hex)
{
super(game, map, hex);
@@ -92,18 +95,50 @@ public abstract class Map3Animations extends Map2Moves implements MoveToAnimatio
// <- implement MoveToAnimationCb
- protected void addBounceAnimation(final Unit unit, float duration)
+ protected void moveUnit(final Unit unit, final Move move, MoveToAnimationCb cb, boolean bounce)
{
- addAnimation(BounceAnimation.get(unit, duration));
+ removePawn(unit);
+
+ AnimationSequence seq = AnimationSequence.get(move.steps() + (bounce ? 2 : 1));
+ if (bounce) seq.addAnimation(BounceAnimation.get(unit, BOUNCE_DURATION));
+ unit.getMoveAnimation(move.iterator(), seq, cb);
+ seq.addAnimation(RunnableAnimation.get(unit, new Runnable() {
+ @Override
+ public void run() {
+ unit.move(move);
+ if (!move.to.isOffMap())
+ setPawnOnto(unit, move.to, move.orientation);
+ }
+ }));
+ addAnimation(seq);
}
- protected void addPromoteAnimation(final Unit unit, final Player player, final Runnable after)
+ protected void revertLastUnitMove(final Unit unit, final Move move)
{
- Hex hex = unit.getHex();
- AnimationSequence seq = AnimationSequence.get(2);
- seq.addAnimation(PromoteAnimation.get((unit.getArmy() == Army.US), hex.getX(), hex.getY(), game.config.fxVolume));
- seq.addAnimation(RunnableAnimation.get(unit, after));
+ removePawn(unit);
+ revertClaim(unit, move);
+
+ AnimationSequence seq = AnimationSequence.get(1);
+ unit.getRevertLastMoveAnimation(seq);
+ seq.addAnimation(RunnableAnimation.get(unit, new Runnable() {
+ @Override
+ public void run() {
+ setPawnOnto(unit, move.to, move.orientation);
+ }
+ }));
addAnimation(seq);
+ unit.revertLastMove();
+ }
+
+ protected void addBounceAnimation(final Unit unit)
+ {
+ addAnimation(BounceAnimation.get(unit, BOUNCE_DURATION));
+ }
+
+ protected void addPromoteAnimation(final Unit unit, final Player player)
+ {
+ Hex hex = unit.getHex();
+ addAnimation(PromoteAnimation.get((unit.getArmy() == Army.US), hex.getX(), hex.getY(), game.config.fxVolume));
}
protected void addDestroyAnimation(Unit unit)
@@ -142,6 +177,6 @@ public abstract class Map3Animations extends Map2Moves implements MoveToAnimatio
addAnimation( SoundAnimation.get(SoundAnimation.Action.FADE_OUT, sound, soundId, game.config.fxVolume, 0.5f));
soundId = -1;
} else
- game.ctrl.postEvent(EventType.ANIMATIONS_DONE);
+ game.ctrl.sendMsg(MsgType.ANIMATIONS_DONE);
}
}
diff --git a/core/src/ch/asynk/rustanddust/game/map/Map4Orders.java b/core/src/ch/asynk/rustanddust/game/map/Map4Orders.java
index e3662e2..05cc569 100644
--- a/core/src/ch/asynk/rustanddust/game/map/Map4Orders.java
+++ b/core/src/ch/asynk/rustanddust/game/map/Map4Orders.java
@@ -6,8 +6,10 @@ import ch.asynk.rustanddust.RustAndDust;
import ch.asynk.rustanddust.engine.Move;
import ch.asynk.rustanddust.engine.SelectedTile;
import ch.asynk.rustanddust.engine.Orientation;
-import ch.asynk.rustanddust.game.Hex;
+import ch.asynk.rustanddust.game.Ctrl.MsgType;
import ch.asynk.rustanddust.game.Unit;
+import ch.asynk.rustanddust.game.Hex;
+import ch.asynk.rustanddust.game.Zone;
import ch.asynk.rustanddust.game.Order;
import ch.asynk.rustanddust.game.OrderList;
import ch.asynk.rustanddust.game.Engagement;
@@ -17,15 +19,12 @@ public abstract class Map4Orders extends Map3Animations
protected final OrderList orders;
protected final OrderList replayOrders;
- protected int orderId;
- protected abstract int engagementCost(Engagement e);
protected abstract void resolveEngagement(Engagement e);
public Map4Orders(final RustAndDust game, Texture map, SelectedTile hex)
{
super(game, map, hex);
- this.orderId = 0;
this.orders = new OrderList(10);
this.replayOrders = new OrderList(10);
}
@@ -39,78 +38,126 @@ public abstract class Map4Orders extends Map3Animations
Engagement.clearPool();
}
- protected void incOrderId() { orderId += 1; }
protected int ordersSize() { return orders.size(); }
protected void ordersClear() { orders.dispose(); }
// STATES ENTRY ->
- public void showOnBoard(final Unit unit, Hex to, Orientation o)
+ public void setOnBoard(final Unit unit, Move move)
{
- setPawnOnto(unit, to, o);
+ setPawnOnto(unit, move);
+ addBounceAnimation(unit);
}
- public boolean setOnBoard(final Unit unit, Hex to, Orientation entry)
+ public void setOnBoard(final Unit unit, Hex to, Orientation o)
{
- orders.dispose(unit);
- return process(getMoveOrder(unit, Move.getSet(unit, to, entry)));
+ setPawnOnto(unit, to, o);
+ addBounceAnimation(unit);
}
- public boolean enterBoard(final Unit unit, Hex to, int allowedMoves)
+ public boolean enterBoard(final Unit unit, Hex to, Zone entryZone)
{
- Orientation entry = findBestEntry(unit, to, allowedMoves);
+ Orientation entry = findBestEntry(unit, to, entryZone.allowedMoves);
if (entry == Orientation.KEEP)
return false;
-
- return process(getMoveOrder(unit, Move.getEnter(unit, to, entry)));
+ unit.spendMovementPoints(to.costFrom(unit, entry));
+ setOnBoard(unit, to, entry.opposite());
+ return true;
}
- public boolean exitBoard(final Unit unit)
+ public void revertEnter(final Unit unit)
{
- return process(getMoveOrder(unit, paths.getExitMove()));
+ removePawn(unit);
+ unit.reset();
}
- public boolean moveUnit(final Unit unit)
+ public Order getSetOrder(final Unit unit, final Hex to, final Orientation o)
{
- return process(getMoveOrder(unit, paths.getMove()));
+ Order order = getMoveOrder(unit, Move.getSet(unit, to, o), false);
+ order.cost = 0;
+
+ return order;
}
- public void revertMoves()
+ public Order getRevertSetOrder(Unit unit)
{
- for (Unit unit: activatedUnits) {
- RustAndDust.debug(" revertMove() " + unit);
- revertLastPawnMove(unit, ((Order) orders.get(unit, Order.OrderType.MOVE)).move);
- orders.dispose(unit, Order.OrderType.MOVE);
+ Order o = orders.get(unit, Order.OrderType.MOVE);
+ if (o == null) {
+ RustAndDust.error(String.format("can't revert order : %s %s", Order.OrderType.MOVE, unit));
+ return null;
}
- activatedUnits.clear();
+ Order order = Order.REVERT;
+ order.setRevert(o.id);
+
+ return order;
}
- public void revertEnter(final Unit unit)
+ public Order getExitOrder(final Unit unit, boolean hqMode)
{
- RustAndDust.debug(" revertEnter() "+ unit);
+ Order order = getMoveOrder(unit, paths.getExitMove(), hqMode);
- revertclaim(unit, unit.getHex());
- removePawn(unit);
- game.ctrl.battle.getPlayer().revertUnitEntry(unit);
- orders.dispose(unit);
- unit.reset();
+ return order;
}
- public boolean engageUnit(final Unit unit, final Unit target)
+ public Order getEnterOrder(final Unit unit, boolean hqMode)
{
- attack(unit, target, true);
+ Order order = getMoveOrder(unit, paths.getEnterMove(unit, getAdjTileAt(unit.getTile(), unit.getOrientation().opposite())), hqMode);
+
+ return order;
+ }
+
+ public Order getMoveOrder(final Unit unit, boolean hqMode)
+ {
+ Order order = getMoveOrder(unit, paths.getMove(), hqMode);
+ return order;
+ }
+
+ // FIXME revertMoves(...)
+ // public void revertMoves()
+ // {
+ // for (Unit unit: activatedUnits) {
+ // RustAndDust.debug(" revertMove() " + unit);
+ // revertLastPawnMove(unit, ((Order) orders.get(unit, Order.OrderType.MOVE)).move);
+ // orders.dispose(unit, Order.OrderType.MOVE);
+ // }
+ // activatedUnits.clear();
+ // }
+
+ public Order getEngageOrder(final Unit unit, final Unit target)
+ {
+ attack(unit, target, true);
Order order = Order.get();
order.setEngage(unit, target);
- process(order);
- return order.engagement.success;
+
+ Engagement e = order.engagement;
+ resolveEngagement(e);
+ order.setActivables(activableUnits);
+ if ((e.cost > 0) && order.activables.size() > 0)
+ order.cost = 0;
+
+ return order;
}
- public boolean promoteUnit(final Unit unit)
+ public Order getPromoteOrder(final Unit unit)
{
Order order = Order.get();
order.setPromote(unit);
- return process(order);
+
+ return order;
+ }
+
+ private Order getMoveOrder(Unit leader, Move move, boolean hqMode)
+ {
+ Order order = Order.get();
+ order.setMove(leader, move);
+ activableUnits.remove((Unit) move.pawn);
+ activatedUnits.add((Unit) move.pawn);
+ order.setActivables(activableUnits);
+ if (hqMode && order.activables.size() > 0)
+ order.cost = 0;
+
+ return order;
}
// STATES ENTRY <-
@@ -120,22 +167,36 @@ public abstract class Map4Orders extends Map3Animations
public void prepareReplayLastAction()
{
int s = orders.size();
- int a = orders.get(s - 1).id;
- while (s > 0) {
+ if (s == 0) return;
+
+ boolean more = true;
+ // int a = orders.get(s - 1).id;
+ while (more) {
s -= 1;
Order o = orders.get(s);
- if (o.id != a)
- break;
+ o.replay = true;
replayOrders.add(o);
+ if (s == 0) {
+ more = false;
+ } else {
+ Order prev = orders.get(s - 1);
+ // first order cost=1 part of a group action
+ if ((o.cost > 0) && (s > 0) && replayOrders.size() == 1)
+ more = ((prev.cost == 0) && (prev.type == o.type));
+ else // part of a group action
+ more = ((o.cost == 0) && (prev.cost == 0) && (prev.type == o.type));
+ }
}
}
- public void prepareReplayLastTurn()
+ public void prepareReplayCurrentTurn()
{
int s = orders.size();
while (s > 0) {
s -= 1;
- replayOrders.add(orders.get(s));
+ Order o = orders.get(s);
+ o.replay = true;
+ replayOrders.add(o);
}
}
@@ -147,154 +208,129 @@ public abstract class Map4Orders extends Map3Animations
return replayOrders.remove(s - 1);
}
- public boolean replay(Order order)
- {
- return process(order, true);
- }
-
// REPLAY <-
- private Order getMoveOrder(Unit unit, Move move)
+ // EXECUTE ->
+
+ public void execute(final Order order)
{
- Order order = Order.get();
- order.setMove(unit, move);
- return order;
+ RustAndDust.debug(" Order", order.toString());
+
+ switch(order.type)
+ {
+ case MOVE: executeMove(order); break;
+ case ENGAGE: executeEngage(order); break;
+ case PROMOTE: executePromote(order); break;
+ case END: executeEnd(order); return;
+ case REVERT: executeRevert(order); return;
+ default:
+ RustAndDust.error(String.format("Unhandled Order Type %s", order.type));
+ break;
+ }
+
+ if (order.replay) {
+ activableUnits.clear();
+ for (Unit u : order.activables)
+ activableUnits.add(u);
+ } else
+ orders.add(order);
}
- private boolean process(Order order)
+ private void executePromote(final Order order)
{
- return process(order, false);
+ addPromoteAnimation(order.leader, game.ctrl.battle.getPlayer());
}
- private boolean process(Order order, boolean replay)
+ private void executeEngage(final Order order)
{
- RustAndDust.debug("Order", order.toString());
+ Engagement e = order.engagement;
- boolean r = false;
+ e.attacker.engage();
+ for (Unit u : e.assists)
+ u.engage();
- switch(order.type) {
- case MOVE:
- r = doMove(order.unit, order.move, replay);
- break;
- case PROMOTE:
- r = doPromote(order.unit, replay);
- break;
- case ENGAGE:
- r = doEngagement(order.engagement, replay);
- break;
- default:
- RustAndDust.error(String.format("Unhandled Order Type %s", order.type));
- break;
- }
-
- if (r && !replay) {
- order.id = orderId;
- order.setActivable(activableUnits);
- order.cost = ((activatedUnits.size() > 0) ? ((activableUnits.size() > 0) ? 0 : 1) : 0);
- orders.add(order);
- game.ctrl.orderProcessedCb();
+ if (order.replay) {
+ activatedUnits.clear();
+ activatedUnits.add(e.attacker);
+ addBounceAnimation(e.attacker);
+ for (Unit u : e.assists) {
+ activatedUnits.add(u);
+ addBounceAnimation(u);
+ }
}
- if (replay) {
- activableUnits.clear();
- for (Unit u : order.activable)
- activableUnits.add(u);
- orderId = order.id;
+ if (e.success) {
+ unclaim(e.defender, e.defender.getHex());
+ removePawn(e.defender);
+ addDestroyAnimation(e.defender);
}
-
- return r;
+ addEngagementAnimation(e.defender);
}
- private boolean doMove(Unit unit, Move move, boolean replay)
+ private void executeMove(final Order order)
{
- RustAndDust.debug(" Move", String.format("%s %s", move.type, move.toString()));
+ final Unit leader = order.leader;
+ final Unit unit = (Unit) order.move.pawn;
+ final Move move = order.move;
- switch(move.type) {
+ switch(move.type)
+ {
case REGULAR:
- initMove(unit);
- movePawn(unit, move, this);
- break;
- case EXIT:
- initMove(unit);
- movePawn(unit, move, this);
- game.ctrl.battle.getPlayer().unitWithdraw(unit);
+ playMoveSound(unit);
+ moveUnit(unit, move, this, order.replay);
break;
case SET:
- setPawnOnto(unit, move);
- game.ctrl.battle.getPlayer().unitEntry(unit);
claim(unit, move.to);
- addBounceAnimation(unit, 0.3f);
+ if (!order.replay)
+ orders.dispose(unit, Order.OrderType.MOVE);
+ setOnBoard(unit, move);
break;
case ENTER:
- enterPawn(unit, move);
- game.ctrl.battle.getPlayer().unitEntry(unit);
- claim(unit, move.to);
- addBounceAnimation(unit, 0.3f);
+ claim(unit, move.from);
+ if (order.replay)
+ unit.setOnTile(move.from, Orientation.NORTH.r());
+ playMoveSound(unit);
+ moveUnit(unit, move, this, order.replay);
+ break;
+ case EXIT:
+ playMoveSound(unit);
+ moveUnit(unit, move, this, order.replay);
break;
default:
- RustAndDust.error(String.format("Unhandled Move Type %s", move.type));
- return false;
+ RustAndDust.error(String.format("Unhandled Move Type %s", order.move.type));
}
-
- return true;
- }
-
- private void initMove(Unit unit)
- {
- activableUnits.remove(unit);
- activatedUnits.add(unit);
- playMoveSound(unit);
}
- private boolean doPromote(final Unit unit, boolean replay)
+ private void executeRevert(Order order)
{
- activableUnits.remove(unit);
- activatedUnits.add(unit);
- addPromoteAnimation(unit, game.ctrl.battle.getPlayer(), new Runnable() {
- @Override
- public void run() {
- game.ctrl.battle.getPlayer().promote(unit);
- }
- });
- return true;
- }
+ int id = order.id;
+ order = orders.getId(id);
+ orders.remove(order);
- private boolean doEngagement(Engagement e, boolean replay)
- {
- if (replay) {
- activatedUnits.clear();
- for (Unit u : e.assists) {
- u.engage();
- activatedUnits.add(u);
- }
- e.attacker.engage();
- activatedUnits.add(e.attacker);
- } else {
- resolveEngagement(e);
- activableUnits.clear();
- if (e.success) {
- for (Unit u : activatedUnits) {
- u.engage();
- if (u.canBreak())
- activableUnits.add(u);
- }
- }
+ if (order.type != Order.OrderType.MOVE) {
+ RustAndDust.error(String.format("Unhandled Revert for Order Type %s", order.type));
+ return;
}
- if (e.success) {
- unclaim(e.defender, e.defender.getHex());
- removePawn(e.defender);
- addDestroyAnimation(e.defender);
+ Unit unit = (Unit) order.move.pawn;
+ switch(order.move.type)
+ {
+ case SET:
+ removePawn(unit);
+ unclaim(unit, order.move.to);
+ game.ctrl.sendMsg(MsgType.UNIT_UNDEPLOYED, unit);
+ break;
+ case REGULAR:
+ case EXIT:
+ case ENTER:
+ default:
+ RustAndDust.error(String.format("Unhandled Move Type %s", order.move.type));
}
-
- if (!replay)
- game.ctrl.hud.engagementSummary(e);
- addEngagementAnimation(e.defender);
-
- if (engagementCost(e) == 0)
- activatedUnits.clear();
-
- return true;
+ order.dispose();
}
+ private void executeEnd(Order order)
+ {
+ orders.get(orders.size() - 1).cost = 1;
+ }
}
diff --git a/core/src/ch/asynk/rustanddust/game/map/Map5Marshal.java b/core/src/ch/asynk/rustanddust/game/map/Map5Marshal.java
index 9447c38..b291062 100644
--- a/core/src/ch/asynk/rustanddust/game/map/Map5Marshal.java
+++ b/core/src/ch/asynk/rustanddust/game/map/Map5Marshal.java
@@ -37,10 +37,11 @@ public abstract class Map5Marshal extends Map4Orders implements Marshal
@Override
public void unload(Marshal.Mode mode, Json json)
{
- if((mode == Marshal.Mode.FULL) || (mode == Marshal.Mode.STATE))
- unloadMap(json);
- else if(mode == Marshal.Mode.ORDERS)
- unloadOrders(json, orders);
+ switch(mode)
+ {
+ case MAP: unloadMap(json); break;
+ case ORDERS: unloadOrders(json, orders); break;
+ }
}
public void unloadPlayers(Json json, Player a, Player b)
@@ -160,20 +161,15 @@ public abstract class Map5Marshal extends Map4Orders implements Marshal
json.writeValue("id", o.id);
json.writeValue("type", o.type);
json.writeValue("cost", o.cost);
- switch(o.type) {
- case MOVE:
- unloadMoveOrder(json, o.move);
- break;
- case ENGAGE:
- unloadEngageOrder(json, o.engagement);
- break;
- case PROMOTE:
- unloadPromoteOrder(json, o.unit);
- break;
+ switch(o.type)
+ {
+ case MOVE: unloadMoveOrder(json, o.leader, o.move); break;
+ case ENGAGE: unloadEngageOrder(json, o.engagement); break;
+ case PROMOTE: unloadPromoteOrder(json, o.leader); break;
}
- if (o.activable.size() > 0) {
+ if (o.activables.size() > 0) {
json.writeArrayStart("a");
- for(Unit u : o.activable)
+ for(Unit u : o.activables)
json.writeValue(u.id());
json.writeArrayEnd();
}
@@ -182,9 +178,11 @@ public abstract class Map5Marshal extends Map4Orders implements Marshal
json.writeArrayEnd();
}
- private void unloadMoveOrder(Json json, Move m)
+ private void unloadMoveOrder(Json json, Unit leader, Move m)
{
json.writeValue("mType", m.type);
+ json.writeValue("mCost", m.cost);
+ json.writeValue("l", leader.id());
json.writeValue("u", ((Unit) m.pawn).id());
if (m.from != null) {
json.writeArrayStart("from");
@@ -267,10 +265,10 @@ public abstract class Map5Marshal extends Map4Orders implements Marshal
@Override
public void load(Marshal.Mode mode, JsonValue v)
{
- if((mode == Marshal.Mode.FULL) || (mode == Marshal.Mode.STATE))
- loadMap(v.get("map"));
- else if(mode == Marshal.Mode.ORDERS)
- loadOrders(v.get("orders"));
+ switch(mode) {
+ case MAP: loadMap(v.get("map")); break;
+ case ORDERS: loadOrders(v.get("orders")); break;
+ }
}
public void loadPlayers(JsonValue v, Player[] players)
@@ -323,8 +321,7 @@ public abstract class Map5Marshal extends Map4Orders implements Marshal
if (pos) {
a = v.get("p");
Hex h = getHex(a.getInt(0), a.getInt(1));
- u.setRotation(a.getInt(2));
- showOnBoard(u, h, Orientation.fromRotation(a.getInt(2)));
+ setOnBoard(u, h, Orientation.fromRotation(a.getInt(2)));
}
units.add(u);
return u;
@@ -366,23 +363,18 @@ public abstract class Map5Marshal extends Map4Orders implements Marshal
for (int i = 0; i < v.size; i++) {
JsonValue o = v.get(i);
Order order = null;
- switch(Order.OrderType.valueOf(o.getString("type"))) {
- case MOVE:
- order = loadMoveOrder(o);
- break;
- case ENGAGE:
- order = loadEngageOrder(o);
- break;
- case PROMOTE:
- order = loadPromoteOrder(o);
- break;
+ switch(Order.OrderType.valueOf(o.getString("type")))
+ {
+ case MOVE: order = loadMoveOrder(o); break;
+ case ENGAGE: order = loadEngageOrder(o); break;
+ case PROMOTE: order = loadPromoteOrder(o); break;
}
order.id = o.getInt("id");
order.cost = o.getInt("cost");
JsonValue a = o.get("a");
if (a != null) {
for (int j = 0; j < a.size; j++) {
- order.activable.add(findById(a.getInt(j)));
+ order.activables.add(findById(a.getInt(j)));
}
}
orders.add(order);
@@ -391,6 +383,7 @@ public abstract class Map5Marshal extends Map4Orders implements Marshal
private Order loadMoveOrder(JsonValue v)
{
+ Unit leader = findById(v.getInt("l"));
Unit unit = findById(v.getInt("u"));
if (unit == null) return null;
Hex from = loadHex(v, "from");
@@ -408,24 +401,20 @@ public abstract class Map5Marshal extends Map4Orders implements Marshal
}
Move m = null;
- switch(Move.MoveType.valueOf(v.getString("mType"))) {
- case REGULAR:
- m = Move.get(unit, from, to, orientation, path);
- break;
- case ENTER:
- m = Move.getEnter(unit, to, orientation);
- break;
- case SET:
- m = Move.getSet(unit, to, orientation);
- break;
+ switch(Move.MoveType.valueOf(v.getString("mType")))
+ {
+ case REGULAR: m = Move.get(unit, from, to, orientation, path); break;
+ case ENTER: m = Move.getEnter(unit, from, to, orientation, path); break;
+ case SET: m = Move.getSet(unit, to, orientation); break;
case EXIT:
m = Move.get(unit, from, to, orientation, path);
m.type = Move.MoveType.EXIT;
break;
}
+ m.cost = v.getInt("mCost");
Order o = Order.get();
- o.setMove(unit, m);
+ o.setMove(leader, m);
return o;
}