diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-14 11:16:06 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-14 11:16:06 +0200 |
commit | a34c377e53061db4d2affe8bda13d12fb1038911 (patch) | |
tree | 624816bfb9dd5bcf27e1190aa48b5cbc6f2ad4ec /core/src/ch/asynk/tankontank | |
parent | 9108226756b227265be365d40efa4b3942aa712a (diff) | |
download | RustAndDust-a34c377e53061db4d2affe8bda13d12fb1038911.zip RustAndDust-a34c377e53061db4d2affe8bda13d12fb1038911.tar.gz |
Board: add simpler buildPossibleTargetsFrom() based on enemy units
Diffstat (limited to 'core/src/ch/asynk/tankontank')
4 files changed, 26 insertions, 4 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 8ad214b..91a88f5 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -329,6 +329,27 @@ public abstract class Board implements Disposable return targets.size(); } + protected int buildPossibleTargetsFrom(Pawn pawn, GridPoint2 coords, Iterator<Pawn> units, ArrayList<GridPoint2> targets) + { + clearPointVector(targets); + + GridPoint2 to = gridPoint2Pool.obtain(); + while (units.hasNext()) { + Pawn target = units.next(); + getHexUnder(target, to); + if (searchBoard.buildAttack(pawn, target, coords.x, coords.y, to.x, to.y)) { + targets.add(to); + to = gridPoint2Pool.obtain(); + } + } + + int s = targets.size(); + if ((s > 0) && (to != targets.get(s - 1))) + gridPoint2Pool.free(to); + + return s; + } + protected int buildMoveAssists(Pawn pawn, GridPoint2 coords, List<GridPoint2> assists) { assists.clear(); diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index d1dfcb4..fdf7e8b 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -208,9 +208,10 @@ public abstract class Map extends Board return buildPossibleMovesFrom(pawn, hex, possibleMoves); } - public int buildPossibleTargets(Pawn pawn, GridPoint2 hex) + public int buildPossibleTargets(Pawn pawn, GridPoint2 hex, Iterator<Pawn> foes) { - return buildPossibleTargetsFrom(pawn, hex, possibleTargets); + // return buildPossibleTargetsFrom(pawn, hex, possibleTargets); + return buildPossibleTargetsFrom(pawn, hex, foes, possibleTargets); } public int buildMoveAssists(Pawn pawn, GridPoint2 hex) diff --git a/core/src/ch/asynk/tankontank/game/states/StateAttack.java b/core/src/ch/asynk/tankontank/game/states/StateAttack.java index 7c4d6b2..bbf54d1 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateAttack.java +++ b/core/src/ch/asynk/tankontank/game/states/StateAttack.java @@ -19,7 +19,7 @@ public class StateAttack extends StateCommon // use selectedHex and selectedPawn from.set(selectedHex); map.showPossibleTargets(false); - map.buildPossibleTargets(selectedPawn, from); + map.buildPossibleTargets(selectedPawn, from, ctrl.otherPlayer().unitIterator()); map.showPossibleTargets(true); if (to.x != -1) { // quick fire -> replay touchUp diff --git a/core/src/ch/asynk/tankontank/game/states/StateSelect.java b/core/src/ch/asynk/tankontank/game/states/StateSelect.java index 0ae3465..5dc5e68 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateSelect.java +++ b/core/src/ch/asynk/tankontank/game/states/StateSelect.java @@ -53,7 +53,7 @@ public class StateSelect extends StateCommon if (hasPawn() && (!isEnemy || ctrl.cfg.showEnemyPossibilities)) { int moves = map.buildPossibleMoves(selectedPawn, selectedHex); - int targets = map.buildPossibleTargets(selectedPawn, selectedHex); + int targets = map.buildPossibleTargets(selectedPawn, selectedHex, ctrl.otherPlayer().unitIterator()); int assists = map.buildMoveAssists(selectedPawn, selectedHex); showPossibleTargetsMovesAssists(selectedPawn); ctrl.hud.show( |