summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/engine/Tile.java
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-12-28 18:38:37 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2015-12-28 18:38:37 +0100
commitec8d22ee6a21b8aaf56b051600e7d9bb94a1d788 (patch)
treefed0f439885aeb333ffe5dfddf491248d206dd49 /core/src/ch/asynk/rustanddust/engine/Tile.java
parentd76dd1fa80df0f89e33c3d3c5ab40e48c4f82d77 (diff)
downloadRustAndDust-ec8d22ee6a21b8aaf56b051600e7d9bb94a1d788.zip
RustAndDust-ec8d22ee6a21b8aaf56b051600e7d9bb94a1d788.tar.gz
Objective: Tile swallows Objective, ObjectiveSet is destroyed, Board does the trick
Diffstat (limited to 'core/src/ch/asynk/rustanddust/engine/Tile.java')
-rw-r--r--core/src/ch/asynk/rustanddust/engine/Tile.java105
1 files changed, 100 insertions, 5 deletions
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;