summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/src/ch/asynk/rustanddust/engine/Board.java49
-rw-r--r--core/src/ch/asynk/rustanddust/engine/Objective.java54
-rw-r--r--core/src/ch/asynk/rustanddust/engine/ObjectiveSet.java89
-rw-r--r--core/src/ch/asynk/rustanddust/engine/PathBuilder.java2
-rw-r--r--core/src/ch/asynk/rustanddust/engine/Tile.java105
-rw-r--r--core/src/ch/asynk/rustanddust/game/Factory.java2
-rw-r--r--core/src/ch/asynk/rustanddust/game/Hex.java4
-rw-r--r--core/src/ch/asynk/rustanddust/game/Map.java4
-rw-r--r--core/src/ch/asynk/rustanddust/game/map/Map0Hex.java34
-rw-r--r--core/src/ch/asynk/rustanddust/game/map/Map3Animations.java4
-rw-r--r--core/src/ch/asynk/rustanddust/game/map/Map4Commands.java12
11 files changed, 161 insertions, 198 deletions
diff --git a/core/src/ch/asynk/rustanddust/engine/Board.java b/core/src/ch/asynk/rustanddust/engine/Board.java
index 83dbd86..6664d47 100644
--- a/core/src/ch/asynk/rustanddust/engine/Board.java
+++ b/core/src/ch/asynk/rustanddust/engine/Board.java
@@ -16,6 +16,7 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Matrix4;
+import ch.asynk.rustanddust.engine.gfx.Moveable;
import ch.asynk.rustanddust.engine.gfx.Animation;
import ch.asynk.rustanddust.engine.gfx.animations.AnimationSequence;
import ch.asynk.rustanddust.engine.gfx.animations.RunnableAnimation;
@@ -66,7 +67,6 @@ public abstract class Board implements Disposable, Animation
protected SelectedTile selectedTile;
abstract protected Config getConfig();
- abstract protected boolean isObjectiveFor(Tile tile, Pawn pawn);
protected Board(int cols, int rows)
{
@@ -392,6 +392,46 @@ public abstract class Board implements Disposable, Animation
return entry.opposite();
}
+ public int objectivesCount(Faction faction)
+ {
+ int n = 0;
+ for (Tile tile : tiles) {
+ if (tile.isOwnedObjective(faction))
+ n += 1;
+ }
+ return n;
+ }
+
+ public void claim(Moveable moveable, Tile tile)
+ {
+ int o = tile.belongsTo().overlay();
+ if (tile.claim(moveable.getFaction())) {
+ if (tile.isObjective()) {
+ tile.enableOverlay(o, false);
+ tile.enableOverlay(moveable.getFaction().overlay(), true);
+ tilesToDraw.add(tile);
+ }
+ }
+ }
+
+ public void unclaim(Moveable moveable, Tile tile)
+ {
+ if (tile.unclaim()) {
+ if (tile.isObjective()) {
+ tile.enableOverlay(moveable.getFaction().overlay(), false);
+ tile.enableOverlay(tile.belongsTo().overlay(), true);
+ tilesToDraw.add(tile);
+ }
+ }
+ }
+
+ public void revertclaim(Pawn pawn, Tile tile)
+ {
+ int o = pawn.getTile().revertClaim().overlay();
+ tile.enableOverlay(pawn.getFaction().overlay(), false);
+ enableOverlayOn(tile ,o, true);
+ }
+
public void enableOverlayOn(Tile tile, int i, boolean enable)
{
if(tile.enableOverlay(i, enable))
@@ -467,10 +507,15 @@ public abstract class Board implements Disposable, Animation
setPawnOnto(pawn, move.to, move.orientation);
}
- protected void revertLastPawnMove(final Pawn pawn)
+ protected void revertLastPawnMove(final Pawn pawn, final Move move)
{
removePawn(pawn);
+ revertclaim(pawn, move.to);
+ for (Tile tile : move.tiles)
+ revertclaim(pawn, tile);
+ claim(pawn, move.from);
+
addAnimation(RunnableAnimation.get(pawn, new Runnable() {
@Override
public void run() {
diff --git a/core/src/ch/asynk/rustanddust/engine/Objective.java b/core/src/ch/asynk/rustanddust/engine/Objective.java
deleted file mode 100644
index d10f446..0000000
--- a/core/src/ch/asynk/rustanddust/engine/Objective.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package ch.asynk.rustanddust.engine;
-
-public class Objective
-{
- protected Faction curFaction;
- protected Faction prevFaction;
- private boolean persistent;
-
- public Objective(Faction faction, boolean persistent)
- {
- this.curFaction = faction;
- this.prevFaction = faction;
- this.persistent = persistent;
- }
-
- public boolean is(Faction faction)
- {
- return (curFaction == faction);
- }
-
- public Faction faction()
- {
- return curFaction;
- }
-
- public boolean persistent()
- {
- return persistent;
- }
-
- public boolean set(Faction faction)
- {
- if (faction == curFaction)
- return false;
-
- prevFaction = curFaction;
- curFaction = faction;
- return true;
- }
-
- public boolean unset()
- {
- if (persistent)
- return false;
- revert();
- return true;
- }
-
- public Faction revert()
- {
- curFaction = prevFaction;
- return curFaction;
- }
-}
diff --git a/core/src/ch/asynk/rustanddust/engine/ObjectiveSet.java b/core/src/ch/asynk/rustanddust/engine/ObjectiveSet.java
deleted file mode 100644
index 61feba6..0000000
--- a/core/src/ch/asynk/rustanddust/engine/ObjectiveSet.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package ch.asynk.rustanddust.engine;
-
-import java.util.HashMap;
-
-public class ObjectiveSet extends HashMap<Tile, Objective>
-{
- public interface ObjectiveCb
- {
- public void showObjective(Tile tile, Faction faction);
- }
-
- private final Board board;
- private final HashMap<Objective, Tile> modified;
-
- public ObjectiveSet(Board board, int n)
- {
- super(n);
- this.board = board;
- this.modified = new HashMap<Objective, Tile>(10);
- }
-
- public void add(Tile tile, Faction faction, boolean persistent)
- {
- put(tile, new Objective(faction, persistent));
- }
-
- public int count(Faction faction)
- {
- int n = 0;
- for (Objective objective : values()) {
- if (objective.is(faction))
- n += 1;
- }
- return n;
- }
-
- public boolean isObjectiveFor(Tile tile, Pawn pawn)
- {
- Objective objective = get(tile);
- if (objective == null)
- return false;
-
- if (objective.faction() == pawn.getFaction())
- return false;
-
- return (objective.persistent());
- }
-
- public Faction claim(Tile tile, Faction faction)
- {
- Objective objective = get(tile);
- if (objective == null)
- return null;
-
- if (objective.set(faction))
- modified.put(objective, tile);
- return objective.faction();
- }
-
- public Faction unclaim(Tile tile)
- {
- Objective objective = get(tile);
- if (objective == null)
- return null;
-
- if (objective.unset())
- modified.remove(objective);
- return objective.faction();
- }
-
- public void forget()
- {
- modified.clear();
- }
-
- public int modifiedCount()
- {
- return modified.size();
- }
-
- public void revert(ObjectiveCb cb)
- {
- for (Objective objective : modified.keySet()) {
- objective.revert();
- cb.showObjective(modified.get(objective), objective.faction());
- }
- modified.clear();
- }
-}
diff --git a/core/src/ch/asynk/rustanddust/engine/PathBuilder.java b/core/src/ch/asynk/rustanddust/engine/PathBuilder.java
index 0f18ae0..6097d87 100644
--- a/core/src/ch/asynk/rustanddust/engine/PathBuilder.java
+++ b/core/src/ch/asynk/rustanddust/engine/PathBuilder.java
@@ -157,7 +157,7 @@ public class PathBuilder implements Disposable
int n = next.costFrom(pawn, o);
boolean r = next.road(o);
int f = (fitness + 1 + (r ? 0 : 1));
- if (board.isObjectiveFor(next, pawn)) f -= 4;
+ if (next.isObjectiveFor(pawn)) f -= 4;
int m = (mvtLeft - n);
r &= roadMarch;
diff --git a/core/src/ch/asynk/rustanddust/engine/Tile.java b/core/src/ch/asynk/rustanddust/engine/Tile.java
index c865b31..4bf1e29 100644
--- a/core/src/ch/asynk/rustanddust/engine/Tile.java
+++ b/core/src/ch/asynk/rustanddust/engine/Tile.java
@@ -18,6 +18,14 @@ public abstract class Tile implements Drawable, Disposable, Iterable<Pawn>
{
}
+ public enum Objective
+ {
+ NONE,
+ PERSISTENT,
+ VERSATILE,
+ FINAL
+ }
+
protected int col;
protected int row;
protected float x;
@@ -25,6 +33,10 @@ public abstract class Tile implements Drawable, Disposable, Iterable<Pawn>
private StackedImages overlays;
protected ArrayDeque<Pawn> stack;
+ protected Faction curFaction;
+ protected Faction prevFaction;
+ protected Objective objective;
+
public abstract int defense();
public abstract int exitCost();
public abstract int costFrom(Pawn pawn, Orientation side);
@@ -35,20 +47,21 @@ public abstract class Tile implements Drawable, Disposable, Iterable<Pawn>
public abstract boolean atLeastOneMove(Pawn pawn);
public abstract boolean blockLineOfSight(Tile from, Tile to);
- protected Tile(int col, int row)
+ protected Tile(int col, int row, Faction defaultFaction)
{
this.col = col;
this.row = row;
this.stack = new ArrayDeque<Pawn>();
+ this.curFaction = defaultFaction;
+ this.prevFaction = defaultFaction;
+ this.objective = Objective.NONE;
}
- public Tile(float x, float y, int col, int row, TextureAtlas atlas)
+ public Tile(float x, float y, int col, int row, TextureAtlas atlas, Faction defaultFaction)
{
- this.stack = new ArrayDeque<Pawn>();
+ this(col, row, defaultFaction);
this.x = x;
this.y = y;
- this.col = col;
- this.row = row;
this.overlays = new StackedImages(atlas);
this.overlays.centerOn(x, y);
}
@@ -76,6 +89,8 @@ public abstract class Tile implements Drawable, Disposable, Iterable<Pawn>
overlays.dispose();
}
+ // STACK
+
public boolean isEmpty()
{
return stack.isEmpty();
@@ -116,6 +131,86 @@ public abstract class Tile implements Drawable, Disposable, Iterable<Pawn>
return false;
}
+ // OBJECTIVE
+
+ public void setObjective(Faction faction, Objective objective)
+ {
+ this.curFaction = faction;
+ this.prevFaction = faction;
+ this.objective = objective;
+ }
+
+ public boolean isPersistent()
+ {
+ return ((objective == Objective.PERSISTENT) || (objective == Objective.FINAL));
+ }
+
+ public boolean isFinal()
+ {
+ return (objective == Objective.FINAL);
+ }
+
+ public Faction belongsTo()
+ {
+ return curFaction;
+ }
+
+ public boolean belongsTo(Faction faction)
+ {
+ return (faction == curFaction);
+ }
+
+ public boolean isObjective()
+ {
+ return (objective != Objective.NONE);
+ }
+
+ public boolean isOwnedObjective(Faction faction)
+ {
+ return (isObjective() && belongsTo(faction));
+ }
+
+ public boolean isObjectiveFor(Pawn pawn)
+ {
+ if (!isObjective())
+ return false;
+
+ if (belongsTo(pawn.getFaction()))
+ return false;
+
+ return isPersistent();
+ }
+
+
+ public boolean claim(Faction faction)
+ {
+ if (belongsTo(faction))
+ return false;
+
+ if (isFinal() && (curFaction != prevFaction))
+ return false;
+
+ prevFaction = curFaction;
+ curFaction = faction;
+ return true;
+ }
+
+ public boolean unclaim()
+ {
+ if (isPersistent())
+ return false;
+ revertClaim();
+ return true;
+ }
+
+ public Faction revertClaim()
+ {
+ curFaction = prevFaction;
+ return curFaction;
+ }
+
+ // OVERLAYS
+
public boolean mustBeDrawn()
{
if (!isEmpty()) return true;
diff --git a/core/src/ch/asynk/rustanddust/game/Factory.java b/core/src/ch/asynk/rustanddust/game/Factory.java
index 6f5b731..d65edd9 100644
--- a/core/src/ch/asynk/rustanddust/game/Factory.java
+++ b/core/src/ch/asynk/rustanddust/game/Factory.java
@@ -187,7 +187,7 @@ public class Factory implements Board.TileBuilder, Disposable
public Hex getNewTile(float x, float y, int col, int row, boolean offmap)
{
- Hex hex = new Hex(x, y, col, row, hexOverlaysAtlas);
+ Hex hex = new Hex(x, y, col, row, hexOverlaysAtlas, Army.NONE);
if (offmap) hex.terrain = Hex.Terrain.OFFMAP;
return hex;
}
diff --git a/core/src/ch/asynk/rustanddust/game/Hex.java b/core/src/ch/asynk/rustanddust/game/Hex.java
index 5f970ba..2bfbc94 100644
--- a/core/src/ch/asynk/rustanddust/game/Hex.java
+++ b/core/src/ch/asynk/rustanddust/game/Hex.java
@@ -43,9 +43,9 @@ public class Hex extends Tile
return String.format("(%d;%d)", col, row);
}
- public Hex(float x, float y, int col, int row, TextureAtlas atlas)
+ public Hex(float x, float y, int col, int row, TextureAtlas atlas, Army defaultArmy)
{
- super(x, y, col, row, atlas);
+ super(x, y, col, row, atlas, defaultArmy);
this.terrain = Terrain.CLEAR;
this.roads = 0;
}
diff --git a/core/src/ch/asynk/rustanddust/game/Map.java b/core/src/ch/asynk/rustanddust/game/Map.java
index 99f1011..d3daf1c 100644
--- a/core/src/ch/asynk/rustanddust/game/Map.java
+++ b/core/src/ch/asynk/rustanddust/game/Map.java
@@ -32,16 +32,12 @@ public abstract class Map extends Map4Commands
public void actionDone()
{
- objectives.forget();
}
public void turnDone()
{
RustAndDust.debug("TurnDone", String.format(" Processed Commands : %d", commandsSize()));
- if (objectives.modifiedCount() > 0)
- throw new RuntimeException("objectives not cleared");
-
// FIXME do something with these Commands
commandsClear();
}
diff --git a/core/src/ch/asynk/rustanddust/game/map/Map0Hex.java b/core/src/ch/asynk/rustanddust/game/map/Map0Hex.java
index 77780cd..1472d6b 100644
--- a/core/src/ch/asynk/rustanddust/game/map/Map0Hex.java
+++ b/core/src/ch/asynk/rustanddust/game/map/Map0Hex.java
@@ -8,21 +8,18 @@ import ch.asynk.rustanddust.engine.Pawn;
import ch.asynk.rustanddust.engine.Board;
import ch.asynk.rustanddust.engine.Faction;
import ch.asynk.rustanddust.engine.SelectedTile;
-import ch.asynk.rustanddust.engine.ObjectiveSet;
import ch.asynk.rustanddust.game.Hex;
import ch.asynk.rustanddust.game.Army;
-public abstract class Map0Hex extends Board implements ObjectiveSet.ObjectiveCb
+public abstract class Map0Hex extends Board
{
protected final RustAndDust game;
- protected final ObjectiveSet objectives;
public Map0Hex(final RustAndDust game, Texture map, SelectedTile hex)
{
super(game.factory, map, hex);
this.game = game;
- objectives = new ObjectiveSet(this, 4);
}
public Hex getHexAt(float x, float y)
@@ -48,25 +45,10 @@ public abstract class Map0Hex extends Board implements ObjectiveSet.ObjectiveCb
private void addObjective(int col, int row, Army army, boolean persistent)
{
Hex hex = getHex(col, row);
- objectives.add(hex, army, persistent);
+ hex.setObjective(army, (persistent ? Tile.Objective.PERSISTENT : Tile.Objective.VERSATILE));
showObjective(hex, army, !persistent);
}
- protected void claim(Hex hex, Army army)
- {
- showObjective(hex, objectives.claim(hex, army));
- }
-
- protected void unclaim(Hex hex)
- {
- showObjective(hex, objectives.unclaim(hex));
- }
-
- public int objectivesCount(Army army)
- {
- return objectives.count(army);
- }
-
public void hexSelect(Hex hex) { selectedTile.set(hex); }
public void hexUnselect(Hex hex) { selectedTile.hide(); }
public void hexMoveShow(Hex hex) { enableOverlayOn(hex, Hex.MOVE, true); }
@@ -76,18 +58,6 @@ public abstract class Map0Hex extends Board implements ObjectiveSet.ObjectiveCb
public void hexExitShow(Hex hex) { enableOverlayOn(hex, Hex.EXIT, true); }
public void hexExitHide(Hex hex) { enableOverlayOn(hex, Hex.EXIT, false); }
- @Override
- public boolean isObjectiveFor(Tile tile, Pawn pawn)
- {
- return objectives.isObjectiveFor(tile, pawn);
- }
-
- @Override
- public void showObjective(Tile tile, Faction faction)
- {
- showObjective((Hex) tile, (Army) faction);
- }
-
private void showObjective(Hex hex, Army army, boolean hold)
{
if (hold)
diff --git a/core/src/ch/asynk/rustanddust/game/map/Map3Animations.java b/core/src/ch/asynk/rustanddust/game/map/Map3Animations.java
index ee114f7..68bb441 100644
--- a/core/src/ch/asynk/rustanddust/game/map/Map3Animations.java
+++ b/core/src/ch/asynk/rustanddust/game/map/Map3Animations.java
@@ -74,13 +74,13 @@ public abstract class Map3Animations extends Map2Moves implements MoveToAnimatio
@Override
public void moveToAnimationEnter(Moveable moveable, float x, float y, float r)
{
- claim(getHexAt(x, y), (Army) moveable.getFaction());
+ claim(moveable, getHexAt(x, y));
}
@Override
public void moveToAnimationLeave(Moveable moveable, float x, float y, float r)
{
- unclaim(getHexAt(x, y));
+ unclaim(moveable, getHexAt(x, y));
}
@Override
diff --git a/core/src/ch/asynk/rustanddust/game/map/Map4Commands.java b/core/src/ch/asynk/rustanddust/game/map/Map4Commands.java
index 7bb6293..8cde4fc 100644
--- a/core/src/ch/asynk/rustanddust/game/map/Map4Commands.java
+++ b/core/src/ch/asynk/rustanddust/game/map/Map4Commands.java
@@ -78,18 +78,18 @@ public abstract class Map4Commands extends Map3Animations
{
for (Unit unit: activatedUnits) {
RustAndDust.debug(" revertMove() " + unit);
- revertLastPawnMove(unit);
+ revertLastPawnMove(unit, ((Command) commands.get(unit, Command.CommandType.MOVE)).move);
commands.dispose(unit, Command.CommandType.MOVE);
}
activatedUnits.clear();
- objectives.revert(this);
}
public void revertEnter(final Unit unit)
{
RustAndDust.debug(" revertEnter() "+ unit);
+
+ revertclaim(unit, unit.getHex());
removePawn(unit);
- objectives.revert(this);
battle.getPlayer().revertUnitEntry(unit);
commands.dispose(unit);
unit.reset();
@@ -188,12 +188,12 @@ public abstract class Map4Commands extends Map3Animations
case SET:
setPawnOnto(unit, move);
battle.getPlayer().unitEntry(unit);
- claim((Hex) move.to, unit.getArmy());
+ claim(unit, move.to);
break;
case ENTER:
enterPawn(unit, move);
battle.getPlayer().unitEntry(unit);
- claim((Hex) move.to, unit.getArmy());
+ claim(unit, move.to);
break;
default:
System.err.println(String.format("process wrong Move type %s", move.type));
@@ -222,7 +222,7 @@ public abstract class Map4Commands extends Map3Animations
}
if (e.success) {
- unclaim(e.defender.getHex());
+ unclaim(e.defender, e.defender.getHex());
removePawn(e.defender);
addDestroyAnimation(e.defender);
}