diff options
Diffstat (limited to 'core/src/ch/asynk/rustanddust/game/map')
3 files changed, 273 insertions, 132 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/map/Map2Moves.java b/core/src/ch/asynk/rustanddust/game/map/Map2Moves.java index e7ba8ce..c447da3 100644 --- a/core/src/ch/asynk/rustanddust/game/map/Map2Moves.java +++ b/core/src/ch/asynk/rustanddust/game/map/Map2Moves.java @@ -51,21 +51,9 @@ 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 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..63b3391 100644 --- a/core/src/ch/asynk/rustanddust/game/map/Map3Animations.java +++ b/core/src/ch/asynk/rustanddust/game/map/Map3Animations.java @@ -21,7 +21,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 { @@ -142,6 +142,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..10684cb 100644 --- a/core/src/ch/asynk/rustanddust/game/map/Map4Orders.java +++ b/core/src/ch/asynk/rustanddust/game/map/Map4Orders.java @@ -17,7 +17,6 @@ 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); @@ -25,7 +24,6 @@ public abstract class Map4Orders extends Map3Animations { super(game, map, hex); - this.orderId = 0; this.orders = new OrderList(10); this.replayOrders = new OrderList(10); } @@ -39,7 +37,6 @@ public abstract class Map4Orders extends Map3Animations Engagement.clearPool(); } - protected void incOrderId() { orderId += 1; } protected int ordersSize() { return orders.size(); } protected void ordersClear() { orders.dispose(); } @@ -50,33 +47,59 @@ public abstract class Map4Orders extends Map3Animations setPawnOnto(unit, to, o); } - public boolean setOnBoard(final Unit unit, Hex to, Orientation entry) + public Order getSetOrder(final Unit unit, final Hex to, final Orientation o) { - orders.dispose(unit); - return process(getMoveOrder(unit, Move.getSet(unit, to, entry))); + Order order = getMoveOrder(unit, Move.getSet(unit, to, o), false); + order.cost = 0; + + return order; } + // public boolean setOnBoard(final Unit unit, Hex to, Orientation entry) + // { + // // need to remove orders first when changing orientation + // orders.dispose(unit); + // return process(getMoveOrder(unit, Move.getSet(unit, to, entry))); + // } + public boolean enterBoard(final Unit unit, Hex to, int allowedMoves) { - Orientation entry = findBestEntry(unit, to, allowedMoves); - if (entry == Orientation.KEEP) - return false; + // FIXME enterBoard(...) + // Orientation entry = findBestEntry(unit, to, allowedMoves); + // if (entry == Orientation.KEEP) + // return false; - return process(getMoveOrder(unit, Move.getEnter(unit, to, entry))); + // return process(getMoveOrder(unit, Move.getEnter(unit, to, entry))); + return false; } - public boolean exitBoard(final Unit unit) + public Order getExitOrder(final Unit unit, boolean hqMode) { - return process(getMoveOrder(unit, paths.getExitMove())); + Order order = getMoveOrder(unit, paths.getExitMove(), hqMode); + + return order; } - public boolean moveUnit(final Unit unit) + // public boolean exitBoard(final Unit unit) + // { + // return process(getMoveOrder(unit, paths.getExitMove())); + // } + + public Order getMoveOrder(final Unit unit, boolean hqMode) { - return process(getMoveOrder(unit, paths.getMove())); + Order order = getMoveOrder(unit, paths.getMove(), hqMode); + + return order; } + // public boolean moveUnit(final Unit unit) + // { + // return process(getMoveOrder(unit, paths.getMove())); + // } + public void revertMoves() { + // FIXME for (Unit unit: activatedUnits) { RustAndDust.debug(" revertMove() " + unit); revertLastPawnMove(unit, ((Order) orders.get(unit, Order.OrderType.MOVE)).move); @@ -87,8 +110,10 @@ public abstract class Map4Orders extends Map3Animations public void revertEnter(final Unit unit) { + // FIXME RustAndDust.debug(" revertEnter() "+ unit); + orders.dispose(unit); revertclaim(unit, unit.getHex()); removePawn(unit); game.ctrl.battle.getPlayer().revertUnitEntry(unit); @@ -96,25 +121,68 @@ public abstract class Map4Orders extends Map3Animations unit.reset(); } - public boolean engageUnit(final Unit unit, final Unit target) + 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.cost = engagementCost(e); + activableUnits.clear(); + for (Unit u : activatedUnits) { + // FIXME in ctrl at order resolution + u.engage(); + if (e.success && u.canBreak()) + activableUnits.add(u); + } + order.setActivable(activableUnits); + if (order.activable.size() > 0) + order.cost = 0; + + return order; } - public boolean promoteUnit(final Unit unit) + // public boolean engageUnit(final Unit unit, final Unit target) + // { + // attack(unit, target, true); + + // Order order = Order.get(); + // order.setEngage(unit, target); + // process(order); + // return order.engagement.success; + // } + + public Order getPromoteOrder(final Unit unit) { Order order = Order.get(); order.setPromote(unit); - return process(order); + // order.cost = 1; + + return order; } + // public boolean promoteUnit(final Unit unit) + // { + // Order order = Order.get(); + // order.setPromote(unit); + // return process(order); + // } + // STATES ENTRY <- + private Order getMoveOrder(Unit unit, Move move, boolean hqMode) + { + Order order = Order.get(); + order.setMove(unit, move); + if (hqMode && activableUnits.size() > 0) { + order.setActivable(activableUnits); + order.cost = 0; + } + return order; + } + // REPLAY -> public void prepareReplayLastAction() @@ -149,66 +217,112 @@ public abstract class Map4Orders extends Map3Animations public boolean replay(Order order) { - return process(order, true); + // FIMXE replay(Order) + // return process(order, true); + return true; } // REPLAY <- - private Order getMoveOrder(Unit unit, Move move) - { - Order order = Order.get(); - order.setMove(unit, move); - return order; - } - - private boolean process(Order order) - { - return process(order, false); - } - - private boolean process(Order order, boolean replay) + // private boolean process(Order order) + // { + // return process(order, false); + // } + + // private boolean process(Order order, boolean replay) + // { + // boolean r = false; + + // switch(order.type) { + // case MOVE: + // r = doMove(order, replay); + // break; + // case PROMOTE: + // r = doPromote(order, replay); + // break; + // case ENGAGE: + // r = doEngagement(order, replay); + // break; + // default: + // RustAndDust.error(String.format("Unhandled Order Type %s", order.type)); + // break; + // } + + // if (!r) + // throw new RuntimeException(String.format("Exectution failure : %s", order)); + + // if (replay) { + // activableUnits.clear(); + // for (Unit u : order.activable) + // activableUnits.add(u); + // orderId = order.id + 1; + // } else { + // if (order.cost > 0) + // orderId += 1; + // order.id = orderId; + // order.setActivable(activableUnits); + // orders.add(order); + // game.ctrl.orderProcessedCb(); + // } + + // RustAndDust.debug("Order", order.toString()); + + // return true; + // } + + public void execute(final Order order) { RustAndDust.debug("Order", order.toString()); - boolean r = false; - switch(order.type) { - case MOVE: - r = doMove(order.unit, order.move, replay); - break; case PROMOTE: - r = doPromote(order.unit, replay); + executePromote(order); break; case ENGAGE: - r = doEngagement(order.engagement, replay); + executeEngage(order); break; + case MOVE: + executeMove(order); + break; + case END: + orders.get(orders.size() - 1).cost = 1; + return; default: RustAndDust.error(String.format("Unhandled Order Type %s", order.type)); break; } + // FIXME not all + orders.add(order); + } - 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(); - } + private void executePromote(final Order order) + { + addPromoteAnimation(order.unit, game.ctrl.battle.getPlayer(), new Runnable() { + @Override + public void run() { + // FIXME Ctrl should do that !!! + game.ctrl.battle.getPlayer().promote(order.unit); + } + }); + } - if (replay) { - activableUnits.clear(); - for (Unit u : order.activable) - activableUnits.add(u); - orderId = order.id; + private void executeEngage(final Order order) + { + Engagement e = order.engagement; + if (!order.replay) + game.ctrl.hud.engagementSummary(e); + 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 unit = order.unit; + final Move move = order.move; switch(move.type) { case REGULAR: initMove(unit); @@ -220,25 +334,60 @@ public abstract class Map4Orders extends Map3Animations game.ctrl.battle.getPlayer().unitWithdraw(unit); break; case SET: + orders.dispose(unit); setPawnOnto(unit, move); - game.ctrl.battle.getPlayer().unitEntry(unit); + game.ctrl.battle.getPlayer().unitEntry(order.unit); claim(unit, move.to); addBounceAnimation(unit, 0.3f); break; case ENTER: - enterPawn(unit, move); - game.ctrl.battle.getPlayer().unitEntry(unit); - claim(unit, move.to); - addBounceAnimation(unit, 0.3f); - break; + // FIXME 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 boolean doMove(Order order, boolean replay) + // { + // Unit unit = order.unit; + // Move move = order.move; + + // RustAndDust.debug(" Move", String.format("%s %s", move.type, move.toString())); + + // switch(move.type) { + // case REGULAR: + // initMove(unit); + // movePawn(unit, move, this); + // order.cost = ((activableUnits.size() > 0) ? 0 : 1); + // break; + // case EXIT: + // initMove(unit); + // movePawn(unit, move, this); + // game.ctrl.battle.getPlayer().unitWithdraw(unit); + // order.cost = 1; + // break; + // case SET: + // setPawnOnto(unit, move); + // game.ctrl.battle.getPlayer().unitEntry(unit); + // claim(unit, move.to); + // addBounceAnimation(unit, 0.3f); + // order.cost = 1; + // break; + // case ENTER: + // enterPawn(unit, move); + // game.ctrl.battle.getPlayer().unitEntry(unit); + // claim(unit, move.to); + // addBounceAnimation(unit, 0.3f); + // // FIXME : ENTER : order.cost = 1; + // break; + // default: + // RustAndDust.error(String.format("Unhandled Move Type %s", move.type)); + // return false; + // } + + // return true; + // } + private void initMove(Unit unit) { activableUnits.remove(unit); @@ -246,55 +395,59 @@ public abstract class Map4Orders extends Map3Animations playMoveSound(unit); } - private boolean doPromote(final Unit unit, boolean replay) - { - 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; - } - - 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 (e.success) { - unclaim(e.defender, e.defender.getHex()); - removePawn(e.defender); - addDestroyAnimation(e.defender); - } - - if (!replay) - game.ctrl.hud.engagementSummary(e); - addEngagementAnimation(e.defender); - - if (engagementCost(e) == 0) - activatedUnits.clear(); - - return true; - } + // private boolean doPromote(Order order, boolean replay) + // { + // final Unit unit = order.unit; + // order.cost = 1; + // 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; + // } + + // private boolean doEngagement(Order order, boolean replay) + // { + // Engagement e = order.engagement; + // 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 (e.success) { + // unclaim(e.defender, e.defender.getHex()); + // removePawn(e.defender); + // addDestroyAnimation(e.defender); + // } + + // if (!replay) + // game.ctrl.hud.engagementSummary(e); + // addEngagementAnimation(e.defender); + + // order.cost = engagementCost(e); + // if (order.cost == 0) + // activatedUnits.clear(); + + // return true; + // } } |