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 float now = 0;
|
||||||
|
|
||||||
private static Char[] chars = new Char[Level.LENGTH];
|
|
||||||
|
|
||||||
public static void clear() {
|
public static void clear() {
|
||||||
|
|
||||||
now = 0;
|
now = 0;
|
||||||
|
|
||||||
Arrays.fill( chars, null );
|
|
||||||
all.clear();
|
all.clear();
|
||||||
|
|
||||||
ids.clear();
|
ids.clear();
|
||||||
|
@ -160,14 +157,6 @@ public abstract class Actor implements Bundlable {
|
||||||
public static void resetNextID(){
|
public static void resetNextID(){
|
||||||
nextID = 1;
|
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() {
|
/*protected*/public void next() {
|
||||||
if (current == this) {
|
if (current == this) {
|
||||||
|
@ -186,8 +175,7 @@ public abstract class Actor implements Bundlable {
|
||||||
do {
|
do {
|
||||||
now = Float.MAX_VALUE;
|
now = Float.MAX_VALUE;
|
||||||
current = null;
|
current = null;
|
||||||
|
|
||||||
Arrays.fill( chars, null );
|
|
||||||
|
|
||||||
for (Actor actor : all) {
|
for (Actor actor : all) {
|
||||||
|
|
||||||
|
@ -197,11 +185,7 @@ public abstract class Actor implements Bundlable {
|
||||||
now = actor.time;
|
now = actor.time;
|
||||||
current = actor;
|
current = actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actor instanceof Char) {
|
|
||||||
Char ch = (Char)actor;
|
|
||||||
chars[ch.pos] = ch;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
|
@ -247,7 +231,6 @@ public abstract class Actor implements Bundlable {
|
||||||
|
|
||||||
if (actor instanceof Char) {
|
if (actor instanceof Char) {
|
||||||
Char ch = (Char)actor;
|
Char ch = (Char)actor;
|
||||||
chars[ch.pos] = ch;
|
|
||||||
for (Buff buff : ch.buffs()) {
|
for (Buff buff : ch.buffs()) {
|
||||||
all.add( buff );
|
all.add( buff );
|
||||||
buff.onAdd();
|
buff.onAdd();
|
||||||
|
@ -268,7 +251,11 @@ public abstract class Actor implements Bundlable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Char findChar( int pos ) {
|
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 ) {
|
public static Actor findById( int id ) {
|
||||||
|
|
|
@ -279,7 +279,6 @@ public abstract class Char extends Actor {
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
HP = 0;
|
HP = 0;
|
||||||
Actor.remove( this );
|
Actor.remove( this );
|
||||||
Actor.freeCell( pos );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void die( Object src ) {
|
public void die( Object src ) {
|
||||||
|
@ -404,10 +403,7 @@ public abstract class Char extends Actor {
|
||||||
Door.leave( pos );
|
Door.leave( pos );
|
||||||
}
|
}
|
||||||
|
|
||||||
Actor.freeCell(pos);
|
|
||||||
pos = step;
|
pos = step;
|
||||||
Actor.occupyCell( this );
|
|
||||||
|
|
||||||
|
|
||||||
if (flying && Dungeon.level.map[pos] == Terrain.DOOR) {
|
if (flying && Dungeon.level.map[pos] == Terrain.DOOR) {
|
||||||
Door.enter( pos );
|
Door.enter( pos );
|
||||||
|
|
|
@ -181,8 +181,6 @@ public class Ghost extends NPC {
|
||||||
}
|
}
|
||||||
if (newPos != -1) {
|
if (newPos != -1) {
|
||||||
|
|
||||||
Actor.freeCell(pos);
|
|
||||||
|
|
||||||
CellEmitter.get(pos).start(Speck.factory(Speck.LIGHT), 0.2f, 3);
|
CellEmitter.get(pos).start(Speck.factory(Speck.LIGHT), 0.2f, 3);
|
||||||
pos = newPos;
|
pos = newPos;
|
||||||
sprite.place(pos);
|
sprite.place(pos);
|
||||||
|
@ -317,7 +315,6 @@ public class Ghost extends NPC {
|
||||||
ghost.pos = level.randomRespawnCell();
|
ghost.pos = level.randomRespawnCell();
|
||||||
} while (ghost.pos == -1);
|
} while (ghost.pos == -1);
|
||||||
level.mobs.add( ghost );
|
level.mobs.add( ghost );
|
||||||
Actor.occupyCell( ghost );
|
|
||||||
|
|
||||||
spawned = true;
|
spawned = true;
|
||||||
//dungeon depth determines type of quest.
|
//dungeon depth determines type of quest.
|
||||||
|
|
|
@ -217,9 +217,8 @@ public class Imp extends NPC {
|
||||||
npc.pos = level.randomRespawnCell();
|
npc.pos = level.randomRespawnCell();
|
||||||
} while (npc.pos == -1 || level.heaps.get( npc.pos ) != null);
|
} while (npc.pos == -1 || level.heaps.get( npc.pos ) != null);
|
||||||
level.mobs.add( npc );
|
level.mobs.add( npc );
|
||||||
Actor.occupyCell( npc );
|
|
||||||
|
|
||||||
spawned = true;
|
spawned = true;
|
||||||
alternative = Random.Int( 2 ) == 0;
|
alternative = Random.Int( 2 ) == 0;
|
||||||
|
|
||||||
given = false;
|
given = false;
|
||||||
|
|
|
@ -214,7 +214,6 @@ public class Wandmaker extends NPC {
|
||||||
npc.pos = room.random();
|
npc.pos = room.random();
|
||||||
} while (level.map[npc.pos] == Terrain.ENTRANCE || level.map[npc.pos] == Terrain.SIGN);
|
} while (level.map[npc.pos] == Terrain.ENTRANCE || level.map[npc.pos] == Terrain.SIGN);
|
||||||
level.mobs.add( npc );
|
level.mobs.add( npc );
|
||||||
Actor.occupyCell( npc );
|
|
||||||
|
|
||||||
spawned = true;
|
spawned = true;
|
||||||
alternative = Random.Int( 2 ) == 0;
|
alternative = Random.Int( 2 ) == 0;
|
||||||
|
|
|
@ -271,7 +271,6 @@ public class CursedWand {
|
||||||
sheep.pos = ch.pos;
|
sheep.pos = ch.pos;
|
||||||
ch.sprite.killAndErase();
|
ch.sprite.killAndErase();
|
||||||
Actor.remove(ch);
|
Actor.remove(ch);
|
||||||
Actor.freeCell(ch.pos);
|
|
||||||
Dungeon.level.mobs.remove(ch);
|
Dungeon.level.mobs.remove(ch);
|
||||||
HealthIndicator.instance.target(null);
|
HealthIndicator.instance.target(null);
|
||||||
GameScene.add(sheep);
|
GameScene.add(sheep);
|
||||||
|
|
|
@ -591,7 +591,6 @@ public abstract class RegularLevel extends Level {
|
||||||
if (Actor.findChar(mob.pos) == null && Level.passable[mob.pos]) {
|
if (Actor.findChar(mob.pos) == null && Level.passable[mob.pos]) {
|
||||||
mobsToSpawn--;
|
mobsToSpawn--;
|
||||||
mobs.add(mob);
|
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?
|
//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){
|
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]) {
|
if (Actor.findChar(mob.pos) == null && Level.passable[mob.pos]) {
|
||||||
mobsToSpawn--;
|
mobsToSpawn--;
|
||||||
mobs.add(mob);
|
mobs.add(mob);
|
||||||
Actor.occupyCell(mob);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,5 @@ public class BlacksmithPainter extends Painter {
|
||||||
npc.pos = room.random( 1 );
|
npc.pos = room.random( 1 );
|
||||||
} while (level.heaps.get( npc.pos ) != null);
|
} while (level.heaps.get( npc.pos ) != null);
|
||||||
level.mobs.add( npc );
|
level.mobs.add( npc );
|
||||||
Actor.occupyCell( npc );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,6 @@ public class PoolPainter extends Painter {
|
||||||
piranha.pos = room.random();
|
piranha.pos = room.random();
|
||||||
} while (level.map[piranha.pos] != Terrain.WATER|| Actor.findChar( piranha.pos ) != null);
|
} while (level.map[piranha.pos] != Terrain.WATER|| Actor.findChar( piranha.pos ) != null);
|
||||||
level.mobs.add( piranha );
|
level.mobs.add( piranha );
|
||||||
Actor.occupyCell( piranha );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,5 @@ public class StatuePainter extends Painter {
|
||||||
Statue statue = new Statue();
|
Statue statue = new Statue();
|
||||||
statue.pos = cx + cy * Level.WIDTH;
|
statue.pos = cx + cy * Level.WIDTH;
|
||||||
level.mobs.add( statue );
|
level.mobs.add( statue );
|
||||||
Actor.occupyCell( statue );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,12 +48,6 @@ public class SummoningTrap extends Trap {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Char c = Actor.findChar( pos );
|
|
||||||
|
|
||||||
if (c != null) {
|
|
||||||
Actor.occupyCell( c );
|
|
||||||
}
|
|
||||||
|
|
||||||
int nMobs = 1;
|
int nMobs = 1;
|
||||||
if (Random.Int( 2 ) == 0) {
|
if (Random.Int( 2 ) == 0) {
|
||||||
nMobs++;
|
nMobs++;
|
||||||
|
@ -79,7 +73,6 @@ public class SummoningTrap extends Trap {
|
||||||
int index = Random.index( candidates );
|
int index = Random.index( candidates );
|
||||||
|
|
||||||
DUMMY.pos = candidates.get( index );
|
DUMMY.pos = candidates.get( index );
|
||||||
Actor.occupyCell( DUMMY );
|
|
||||||
|
|
||||||
respawnPoints.add( candidates.remove( index ) );
|
respawnPoints.add( candidates.remove( index ) );
|
||||||
nMobs--;
|
nMobs--;
|
||||||
|
|
|
@ -546,14 +546,12 @@ public class GameScene extends PixelScene {
|
||||||
public static void add( Mob mob ) {
|
public static void add( Mob mob ) {
|
||||||
Dungeon.level.mobs.add( mob );
|
Dungeon.level.mobs.add( mob );
|
||||||
Actor.add( mob );
|
Actor.add( mob );
|
||||||
Actor.occupyCell( mob );
|
|
||||||
scene.addMobSprite( mob );
|
scene.addMobSprite( mob );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void add( Mob mob, float delay ) {
|
public static void add( Mob mob, float delay ) {
|
||||||
Dungeon.level.mobs.add( mob );
|
Dungeon.level.mobs.add( mob );
|
||||||
Actor.addDelayed( mob, delay );
|
Actor.addDelayed( mob, delay );
|
||||||
Actor.occupyCell( mob );
|
|
||||||
scene.addMobSprite( mob );
|
scene.addMobSprite( mob );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user