From e8a2004345d65e25f0af759973f16710a7eb0c33 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 14 May 2015 19:47:25 -0400 Subject: [PATCH] v0.3.0: reworked acting order, now uses a proper priority system with owned properties --- .../shatteredpixeldungeon/actors/Actor.java | 14 ++++++++------ .../shatteredpixeldungeon/actors/blobs/Blob.java | 4 ++++ .../shatteredpixeldungeon/actors/buffs/Buff.java | 4 ++++ .../shatteredpixeldungeon/actors/hero/Hero.java | 4 ++++ .../shatteredpixeldungeon/actors/mobs/Mob.java | 4 ++++ .../shatteredpixeldungeon/effects/Pushing.java | 4 ++++ .../shatteredpixeldungeon/items/Bomb.java | 4 ++++ .../shatteredpixeldungeon/levels/Level.java | 7 ++++++- 8 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java index 281ae7dc6..36dd26c79 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java @@ -40,6 +40,10 @@ public abstract class Actor implements Bundlable { private int id = 0; + //used to determine what order actors act in. + //hero should always act on 0, therefore negative is before hero, positive is after hero + protected int actPriority = Integer.MAX_VALUE; + protected abstract boolean act(); protected void spend( float time ) { @@ -186,12 +190,10 @@ public abstract class Actor implements Bundlable { Arrays.fill( chars, null ); for (Actor actor : all) { - //Order of actions when time is equal: - //1. Hero - //2. Other Chars - //3. Other Actors (e.g. blobs) - if (actor.time < now || (actor instanceof Hero && actor.time == now) - || (actor instanceof Char && actor.time == now && !(current instanceof Hero))) { + + //some actors will always go before others if time is equal. + if (actor.time < now || + actor.time == now && actor.actPriority < current.actPriority) { now = actor.time; current = actor; } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Blob.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Blob.java index a3d225fe6..2a2d7a15c 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Blob.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Blob.java @@ -28,6 +28,10 @@ import com.shatteredpixel.shatteredpixeldungeon.utils.BArray; import com.watabou.utils.Bundle; public class Blob extends Actor { + + { + actPriority = 1; //take prioerity over mobs, but not the hero + } public static final int WIDTH = Level.WIDTH; public static final int HEIGHT = Level.HEIGHT; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Buff.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Buff.java index d0000b0a1..967015246 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Buff.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Buff.java @@ -28,6 +28,10 @@ public class Buff extends Actor { public Char target; + { + actPriority = 3; //low priority, at the end of a turn + } + //determines how the buff is announced when it is shown. //buffs that work behind the scenes, or have other visual indicators can usually be silent. public enum buffType {POSITIVE, NEGATIVE, NEUTRAL, SILENT}; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index ccd69b044..63db3c9fe 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -118,6 +118,10 @@ import java.util.Collections; import java.util.HashSet; public class Hero extends Char { + + { + actPriority = 0; //acts at priority 0, baseline for the rest of behaviour. + } private static final String TXT_LEAVE = "One does not simply leave Pixel Dungeon."; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java index e61711b20..fa6563211 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java @@ -47,6 +47,10 @@ import com.watabou.utils.Random; import java.util.HashSet; public abstract class Mob extends Char { + + { + actPriority = 2; //hero gets priority over mobs. + } private static final String TXT_DIED = "You hear something died in the distance"; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/effects/Pushing.java b/src/com/shatteredpixel/shatteredpixeldungeon/effects/Pushing.java index 9e504d938..88b3222fc 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/effects/Pushing.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/effects/Pushing.java @@ -31,6 +31,10 @@ public class Pushing extends Actor { private int to; private Effect effect; + + { + actPriority = Integer.MIN_VALUE; //it's a visual effect, gets priority no matter what + } public Pushing( Char ch, int from, int to ) { sprite = ch.sprite; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/items/Bomb.java b/src/com/shatteredpixel/shatteredpixeldungeon/items/Bomb.java index fb0a425c9..bf00dfb75 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/items/Bomb.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/items/Bomb.java @@ -215,6 +215,10 @@ public class Bomb extends Item { public static class Fuse extends Actor{ + { + actPriority = 3; //as if it were a buff + } + private Bomb bomb; public Fuse ignite(Bomb bomb){ diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java b/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java index a92b308d3..f647332ee 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java @@ -445,7 +445,12 @@ public abstract class Level implements Bundlable { } public Actor respawner() { - return new Actor() { + return new Actor() { + + { + actPriority = 1; //as if it were a buff. + } + @Override protected boolean act() { if (mobs.size() < nMobs()) {