v0.3.0c: refactored finding a character, no longer need to maintain chars[] array
This commit is contained in:
parent
3cf7979a4c
commit
dbeff25d2c
|
@ -102,13 +102,10 @@ public abstract class Actor implements Bundlable {
|
|||
|
||||
private static float now = 0;
|
||||
|
||||
private static Char[] chars = new Char[Level.LENGTH];
|
||||
|
||||
public static void clear() {
|
||||
|
||||
now = 0;
|
||||
|
||||
Arrays.fill( chars, null );
|
||||
all.clear();
|
||||
|
||||
ids.clear();
|
||||
|
@ -161,14 +158,6 @@ public abstract class Actor implements Bundlable {
|
|||
nextID = 1;
|
||||
}
|
||||
|
||||
public static void occupyCell( Char ch ) {
|
||||
chars[ch.pos] = ch;
|
||||
}
|
||||
|
||||
public static void freeCell( int pos ) {
|
||||
chars[pos] = null;
|
||||
}
|
||||
|
||||
/*protected*/public void next() {
|
||||
if (current == this) {
|
||||
current = null;
|
||||
|
@ -187,7 +176,6 @@ public abstract class Actor implements Bundlable {
|
|||
now = Float.MAX_VALUE;
|
||||
current = null;
|
||||
|
||||
Arrays.fill( chars, null );
|
||||
|
||||
for (Actor actor : all) {
|
||||
|
||||
|
@ -198,10 +186,6 @@ public abstract class Actor implements Bundlable {
|
|||
current = actor;
|
||||
}
|
||||
|
||||
if (actor instanceof Char) {
|
||||
Char ch = (Char)actor;
|
||||
chars[ch.pos] = ch;
|
||||
}
|
||||
}
|
||||
|
||||
if (current != null) {
|
||||
|
@ -247,7 +231,6 @@ public abstract class Actor implements Bundlable {
|
|||
|
||||
if (actor instanceof Char) {
|
||||
Char ch = (Char)actor;
|
||||
chars[ch.pos] = ch;
|
||||
for (Buff buff : ch.buffs()) {
|
||||
all.add( buff );
|
||||
buff.onAdd();
|
||||
|
@ -268,7 +251,11 @@ public abstract class Actor implements Bundlable {
|
|||
}
|
||||
|
||||
public static Char findChar( int pos ) {
|
||||
return chars[pos];
|
||||
for (Actor actor : all){
|
||||
if (actor instanceof Char && ((Char)actor).pos == pos)
|
||||
return (Char)actor;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Actor findById( int id ) {
|
||||
|
|
|
@ -279,7 +279,6 @@ public abstract class Char extends Actor {
|
|||
public void destroy() {
|
||||
HP = 0;
|
||||
Actor.remove( this );
|
||||
Actor.freeCell( pos );
|
||||
}
|
||||
|
||||
public void die( Object src ) {
|
||||
|
@ -404,10 +403,7 @@ public abstract class Char extends Actor {
|
|||
Door.leave( pos );
|
||||
}
|
||||
|
||||
Actor.freeCell(pos);
|
||||
pos = step;
|
||||
Actor.occupyCell( this );
|
||||
|
||||
|
||||
if (flying && Dungeon.level.map[pos] == Terrain.DOOR) {
|
||||
Door.enter( pos );
|
||||
|
|
|
@ -181,8 +181,6 @@ public class Ghost extends NPC {
|
|||
}
|
||||
if (newPos != -1) {
|
||||
|
||||
Actor.freeCell(pos);
|
||||
|
||||
CellEmitter.get(pos).start(Speck.factory(Speck.LIGHT), 0.2f, 3);
|
||||
pos = newPos;
|
||||
sprite.place(pos);
|
||||
|
@ -317,7 +315,6 @@ public class Ghost extends NPC {
|
|||
ghost.pos = level.randomRespawnCell();
|
||||
} while (ghost.pos == -1);
|
||||
level.mobs.add( ghost );
|
||||
Actor.occupyCell( ghost );
|
||||
|
||||
spawned = true;
|
||||
//dungeon depth determines type of quest.
|
||||
|
|
|
@ -217,7 +217,6 @@ public class Imp extends NPC {
|
|||
npc.pos = level.randomRespawnCell();
|
||||
} while (npc.pos == -1 || level.heaps.get( npc.pos ) != null);
|
||||
level.mobs.add( npc );
|
||||
Actor.occupyCell( npc );
|
||||
|
||||
spawned = true;
|
||||
alternative = Random.Int( 2 ) == 0;
|
||||
|
|
|
@ -214,7 +214,6 @@ public class Wandmaker extends NPC {
|
|||
npc.pos = room.random();
|
||||
} while (level.map[npc.pos] == Terrain.ENTRANCE || level.map[npc.pos] == Terrain.SIGN);
|
||||
level.mobs.add( npc );
|
||||
Actor.occupyCell( npc );
|
||||
|
||||
spawned = true;
|
||||
alternative = Random.Int( 2 ) == 0;
|
||||
|
|
|
@ -271,7 +271,6 @@ public class CursedWand {
|
|||
sheep.pos = ch.pos;
|
||||
ch.sprite.killAndErase();
|
||||
Actor.remove(ch);
|
||||
Actor.freeCell(ch.pos);
|
||||
Dungeon.level.mobs.remove(ch);
|
||||
HealthIndicator.instance.target(null);
|
||||
GameScene.add(sheep);
|
||||
|
|
|
@ -591,7 +591,6 @@ public abstract class RegularLevel extends Level {
|
|||
if (Actor.findChar(mob.pos) == null && Level.passable[mob.pos]) {
|
||||
mobsToSpawn--;
|
||||
mobs.add(mob);
|
||||
Actor.occupyCell(mob);
|
||||
|
||||
//TODO: perhaps externalize this logic into a method. Do I want to make mobs more likely to clump deeper down?
|
||||
if (mobsToSpawn > 0 && Random.Int(4) == 0){
|
||||
|
@ -601,7 +600,6 @@ public abstract class RegularLevel extends Level {
|
|||
if (Actor.findChar(mob.pos) == null && Level.passable[mob.pos]) {
|
||||
mobsToSpawn--;
|
||||
mobs.add(mob);
|
||||
Actor.occupyCell(mob);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,5 @@ public class BlacksmithPainter extends Painter {
|
|||
npc.pos = room.random( 1 );
|
||||
} while (level.heaps.get( npc.pos ) != null);
|
||||
level.mobs.add( npc );
|
||||
Actor.occupyCell( npc );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,6 @@ public class PoolPainter extends Painter {
|
|||
piranha.pos = room.random();
|
||||
} while (level.map[piranha.pos] != Terrain.WATER|| Actor.findChar( piranha.pos ) != null);
|
||||
level.mobs.add( piranha );
|
||||
Actor.occupyCell( piranha );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,6 +67,5 @@ public class StatuePainter extends Painter {
|
|||
Statue statue = new Statue();
|
||||
statue.pos = cx + cy * Level.WIDTH;
|
||||
level.mobs.add( statue );
|
||||
Actor.occupyCell( statue );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,12 +48,6 @@ public class SummoningTrap extends Trap {
|
|||
return;
|
||||
}
|
||||
|
||||
Char c = Actor.findChar( pos );
|
||||
|
||||
if (c != null) {
|
||||
Actor.occupyCell( c );
|
||||
}
|
||||
|
||||
int nMobs = 1;
|
||||
if (Random.Int( 2 ) == 0) {
|
||||
nMobs++;
|
||||
|
@ -79,7 +73,6 @@ public class SummoningTrap extends Trap {
|
|||
int index = Random.index( candidates );
|
||||
|
||||
DUMMY.pos = candidates.get( index );
|
||||
Actor.occupyCell( DUMMY );
|
||||
|
||||
respawnPoints.add( candidates.remove( index ) );
|
||||
nMobs--;
|
||||
|
|
|
@ -546,14 +546,12 @@ public class GameScene extends PixelScene {
|
|||
public static void add( Mob mob ) {
|
||||
Dungeon.level.mobs.add( mob );
|
||||
Actor.add( mob );
|
||||
Actor.occupyCell( mob );
|
||||
scene.addMobSprite( mob );
|
||||
}
|
||||
|
||||
public static void add( Mob mob, float delay ) {
|
||||
Dungeon.level.mobs.add( mob );
|
||||
Actor.addDelayed( mob, delay );
|
||||
Actor.occupyCell( mob );
|
||||
scene.addMobSprite( mob );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user