diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-29 00:59:33 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-29 00:59:33 +0100 |
commit | 6487955b187a469186a8348eeaac070d1543f2a7 (patch) | |
tree | 9fb6e1f1b31ee48c6f30e6740dc8d11cc626b293 /core/src/ch/asynk | |
parent | c9d131e5fb4d4cb5b1147d53e7dbe5baa9767eee (diff) | |
download | RustAndDust-6487955b187a469186a8348eeaac070d1543f2a7.zip RustAndDust-6487955b187a469186a8348eeaac070d1543f2a7.tar.gz |
Map: possibleTargets and attackAssists are Board.PawnCollection, activablePawns is no more
Diffstat (limited to 'core/src/ch/asynk')
4 files changed, 38 insertions, 38 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 88a63ec..402a8e0 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -267,14 +267,14 @@ public abstract class Board implements Disposable return moves.fromNodes(nodes); } - protected int buildPossibleTargets(Pawn pawn, TileCollection targets) + protected int collectPossibleTargets(Pawn pawn, PawnCollection targets) { Tile from = pawn.getTile(); List<SearchBoard.Node> nodes = searchBoard.possibleTargetsFrom(pawn, from.getCol(), from.getRow()); return targets.fromNodes(nodes); } - protected int buildPossibleTargets(Pawn pawn, Iterator<Pawn> units, TileCollection targets) + protected int collectPossibleTargets(Pawn pawn, Iterator<Pawn> units, PawnCollection targets) { Tile from = pawn.getTile(); targets.clear(); @@ -282,7 +282,7 @@ public abstract class Board implements Disposable Pawn target = units.next(); Tile to = target.getTile(); if (searchBoard.buildAttack(pawn, true, target, from.getCol(), from.getRow(), to.getCol(), to.getRow())) - targets.add(to); + targets.add(target); } return targets.size(); @@ -306,7 +306,7 @@ public abstract class Board implements Disposable return assists.size(); } - protected int buildAttackAssists(Pawn pawn, Pawn target, Iterator<Pawn> units, TileCollection assists) + protected int collectAttackAssists(Pawn pawn, Pawn target, Iterator<Pawn> units, PawnCollection assists) { assists.clear(); Tile to = target.getTile(); @@ -316,7 +316,7 @@ public abstract class Board implements Disposable Tile from = p.getTile(); if (searchBoard.buildAttack(p, !p.canAssistAttackWithoutLos(), target, from.getCol(), from.getRow(), to.getCol(), to.getRow())) { if (p != pawn) - assists.add(from); + assists.add(p); } } diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index 5cd9848..0bdd46b 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -40,12 +40,11 @@ public abstract class Map extends Board private final Ctrl ctrl; public final Board.TileCollection possibleMoves; - public final Board.TileCollection possibleTargets; public final Board.TileCollection possiblePaths; public final Board.PawnCollection moveablePawns; - public final Board.TileCollection attackAssists; - public final ArrayList<Pawn> activablePawns = new ArrayList<Pawn>(7); // PawnSet - public final ArrayList<Pawn> activatedPawns = new ArrayList<Pawn>(7); // PawnSet + public final Board.PawnCollection possibleTargets; + public final Board.PawnCollection attackAssists; + public final ArrayList<Pawn> activatedPawns = new ArrayList<Pawn>(7); private final SpriteAnimation explosion; private final SpriteAnimation explosions; @@ -64,8 +63,8 @@ public abstract class Map extends Board possiblePaths = new HexSet(this, Hex.MOVE1, 10); // Hex.MOVE2 moveablePawns = new UnitSet(this, Unit.MOVE, 6); - possibleTargets = new HexSet(this, Hex.TARGET, 10); // UnitSet - use Unit overlays - attackAssists = new HexSet(this, Hex.ASSIST, 6); // UnitSet - use Unit overlays + possibleTargets = new UnitSet(this, Unit.TARGET, 10); + attackAssists = new UnitSet(this, Unit.ATTACK_ASSIST, 6); } @Override @@ -82,7 +81,6 @@ public abstract class Map extends Board possiblePaths.clear(); moveablePawns.clear(); attackAssists.clear(); - activablePawns.clear(); activatedPawns.clear(); } @@ -176,22 +174,19 @@ public abstract class Map extends Board public int buildAttackAssists(Pawn pawn, Pawn target, Iterator<Pawn> units) { - int s = buildAttackAssists(pawn, target, units, attackAssists); + int s = collectAttackAssists(pawn, target, units, attackAssists); activatedPawns.add(pawn); - attackAssists.getPawns(activablePawns); return s; } public boolean toggleAttackAssist(Pawn pawn) { - if (activablePawns.contains(pawn)) { - activablePawns.remove(pawn); - activatedPawns.add(pawn); - return true; - } else { + if (activatedPawns.contains(pawn)) { activatedPawns.remove(pawn); - activablePawns.add(pawn); return false; + } else { + activatedPawns.add(pawn); + return true; } } diff --git a/core/src/ch/asynk/tankontank/game/states/StateAttack.java b/core/src/ch/asynk/tankontank/game/states/StateAttack.java index 359e9dd..0e637fd 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateAttack.java +++ b/core/src/ch/asynk/tankontank/game/states/StateAttack.java @@ -13,10 +13,10 @@ public class StateAttack extends StateCommon ctrl.hud.show(false, false, false, true, false, ctrl.cfg.canCancel); ctrl.hud.attackBtn.setOn(); + // activeUnit is the target if (fromSelect) { activeUnit = null; // use selectedHex and selectedUnit - from = selectedHex; map.possibleTargets.hide(); map.buildPossibleTargets(selectedUnit, ctrl.opponent.unitIterator()); map.possibleTargets.show(); @@ -25,17 +25,20 @@ public class StateAttack extends StateCommon upHex = to; touchUp(); } - map.selectHex(from, true); - } + selectedUnit.showAttack(true); + map.selectHex(selectedHex, true); + } else + System.err.println("should not happen"); } @Override public void leave(StateType nextState) { - map.attackAssists.hide(); - map.attackAssists.enable(Hex.TARGET, false); // disable selected assists + selectedUnit.showAttack(false); + map.attackAssists.enable(Unit.ATTACK, false); + map.attackAssists.enable(Unit.ATTACK_ASSIST, false); map.possibleTargets.hide(); - map.selectHex(from, false); + map.selectHex(selectedHex, false); if (to != null) map.selectHex(to, false); } @@ -48,24 +51,26 @@ public class StateAttack extends StateCommon @Override public void touchUp() { + Unit unit = upHex.getUnit(); + // activeUnit is the target - if ((activeUnit == null) && map.possibleTargets.contains(upHex)) { + if ((activeUnit == null) && map.possibleTargets.contains(unit)) { map.possibleTargets.hide(); to = upHex; - activeUnit = to.getUnit(); - map.showTarget(to, true); + activeUnit = unit; + activeUnit.showTarget(true); map.buildAttackAssists(selectedUnit, activeUnit, ctrl.player.unitIterator()); map.attackAssists.show(); ctrl.hud.show(false, false, false, true, true, ctrl.cfg.canCancel); } - if ((activeUnit != null) && map.attackAssists.contains(upHex)) { - if (map.toggleAttackAssist(upHex.getUnit())) { - map.showAssist(upHex, false); - map.showTarget(upHex, true); + if ((activeUnit != null) && map.attackAssists.contains(unit)) { + if (map.toggleAttackAssist(unit)) { + unit.showAttack(true); + unit.showAttackAssist(false); } else { - map.showAssist(upHex, true); - map.showTarget(upHex, false); + unit.showAttack(false); + unit.showAttackAssist(true); } } } @@ -82,10 +87,10 @@ public class StateAttack extends StateCommon { int d1 = ctrl.player.d6(); int d2 = ctrl.player.d6(); - System.err.print(" attack (" + from.getCol() + ";" + from.getRow() + ") -> (" + to.getCol() + ";" + to.getRow() + ") : 2D6 -> (" + d1 + " + " + d2 + ")"); + System.err.print(" attack (" + selectedHex.getCol() + ";" + selectedHex.getRow() + ") -> (" + to.getCol() + ";" + to.getRow() + ") : 2D6 -> (" + d1 + " + " + d2 + ")"); if (map.attackPawn(selectedUnit, activeUnit, d1 + d2)) ctrl.player.casualty(activeUnit); - map.showTarget(to, false); + activeUnit.showTarget(true); ctrl.setState(StateType.ANIMATION); super.done(); diff --git a/core/src/ch/asynk/tankontank/game/states/StateSelect.java b/core/src/ch/asynk/tankontank/game/states/StateSelect.java index ddddf6f..d4d010c 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateSelect.java +++ b/core/src/ch/asynk/tankontank/game/states/StateSelect.java @@ -40,7 +40,7 @@ public class StateSelect extends StateCommon ctrl.setState(StateType.MOVE); return; } - if (map.possibleTargets.contains(upHex)) { + if (map.possibleTargets.contains(upHex.getUnit())) { // quick fire to = upHex; ctrl.setState(StateType.ATTACK); |