com.watabou.utils.PathFinder Java Examples

The following examples show how to use com.watabou.utils.PathFinder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EtherealChains.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSelect(Integer target) {
	if (target != null && (Dungeon.level.visited[target] || Dungeon.level.mapped[target])){

		//chains cannot be used to go where it is impossible to walk to
		PathFinder.buildDistanceMap(target, BArray.or(Dungeon.level.passable, Dungeon.level.avoid, null));
		if (PathFinder.distance[curUser.pos] == Integer.MAX_VALUE){
			GLog.w( Messages.get(EtherealChains.class, "cant_reach") );
			return;
		}
		
		final Ballistica chain = new Ballistica(curUser.pos, target, Ballistica.STOP_TARGET);
		
		if (Actor.findChar( chain.collisionPos ) != null){
			chainEnemy( chain, curUser, Actor.findChar( chain.collisionPos ));
		} else {
			chainLocation( chain, curUser );
		}

	}

}
 
Example #2
Source File: AquaBlast.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void affectTarget(Ballistica bolt, Hero hero) {
	int cell = bolt.collisionPos;
	
	Splash.at(cell, 0x00AAFF, 10);
	
	for (int i : PathFinder.NEIGHBOURS9){
		if (i == 0 || Random.Int(5) != 0){
			Dungeon.level.setCellToWater(false, cell+i);
		}
	}
	
	Char target = Actor.findChar(cell);
	
	if (target != null && target != hero){
		//just enough to skip their current turn
		Buff.affect(target, Paralysis.class, 0f);
	}
}
 
Example #3
Source File: Goo.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int damageRoll() {
	int min = 1;
	int max = (HP*2 <= HT) ? 12 : 8;
	if (pumpedUp > 0) {
		pumpedUp = 0;
		PathFinder.buildDistanceMap( pos, BArray.not( Dungeon.level.solid, null ), 2 );
		for (int i = 0; i < PathFinder.distance.length; i++) {
			if (PathFinder.distance[i] < Integer.MAX_VALUE)
				CellEmitter.get(i).burst(ElmoParticle.FACTORY, 10);
		}
		Sample.INSTANCE.play( Assets.SND_BURNING );
		return Random.NormalIntRange( min*3, max*3 );
	} else {
		return Random.NormalIntRange( min, max );
	}
}
 
Example #4
Source File: Goo.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void die( Object cause ) {
	
	super.die( cause );
	
	Dungeon.level.unseal();
	
	GameScene.bossSlain();
	Dungeon.level.drop( new SkeletonKey( Dungeon.depth ), pos ).sprite.drop();
	
	//60% chance of 2 blobs, 30% chance of 3, 10% chance for 4. Average of 2.5
	int blobs = Random.chances(new float[]{0, 0, 6, 3, 1});
	for (int i = 0; i < blobs; i++){
		int ofs;
		do {
			ofs = PathFinder.NEIGHBOURS8[Random.Int(8)];
		} while (!Dungeon.level.passable[pos + ofs]);
		Dungeon.level.drop( new GooBlob(), pos + ofs ).sprite.drop( pos );
	}
	
	Badges.validateBossSlain();
	
	yell( Messages.get(this, "defeated") );
}
 
Example #5
Source File: Dungeon.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public static int flee( Char ch, int cur, int from, boolean pass[], boolean[] visible ) {
	
	if (ch.flying) {
		BArray.or( pass, Level.avoid, passable );
	} else {
		System.arraycopy( pass, 0, passable, 0, Level.LENGTH );
	}
	
	for (Actor actor : Actor.all()) {
		if (actor instanceof Char) {
			int pos = ((Char)actor).pos;
			if (visible[pos]) {
				passable[pos] = false;
			}
		}
	}
	passable[cur] = true;
	
	return PathFinder.getStepBack( cur, from, passable );
	
}
 
Example #6
Source File: WandOfRegrowth.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void activate( Char ch ) {

	int nSeeds = Random.NormalIntRange(2, 4);

	ArrayList<Integer> candidates = new ArrayList<>();
	for (int i : PathFinder.NEIGHBOURS8){
		if (Dungeon.level.passable[pos+i]
				&& pos+i != Dungeon.level.entrance
				&& pos+i != Dungeon.level.exit){
			candidates.add(pos+i);
		}
	}

	for (int i = 0; i < nSeeds && !candidates.isEmpty(); i++){
		Integer c = Random.element(candidates);
		Dungeon.level.drop(Generator.random(Generator.Category.SEED), c).sprite.drop(pos);
		candidates.remove(c);
	}

}
 
Example #7
Source File: PotionOfLiquidFlame.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void shatter( int cell ) {

	if (Dungeon.level.heroFOV[cell]) {
		setKnown();

		splash( cell );
		Sample.INSTANCE.play( Assets.SND_SHATTER );
	}

	for (int offset : PathFinder.NEIGHBOURS9){
		if (!Dungeon.level.solid[cell+offset]) {

			GameScene.add(Blob.seed(cell + offset, 2, Fire.class));

		}
	}
}
 
Example #8
Source File: StoneOfFlock.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void activate(int cell) {

	for (int i : PathFinder.NEIGHBOURS9){
		
		if (!Dungeon.level.solid[cell + i]
				&& !Dungeon.level.pit[cell + i]
				&& Actor.findChar(cell + i) == null) {
			
			Sheep sheep = new Sheep();
			sheep.lifespan = Random.IntRange(5, 8);
			sheep.pos = cell + i;
			GameScene.add(sheep);
			Dungeon.level.occupyCell(sheep);
			
			CellEmitter.get(sheep.pos).burst(Speck.factory(Speck.WOOL), 4);
		}
	}
	CellEmitter.get(cell).burst(Speck.factory(Speck.WOOL), 4);
	Sample.INSTANCE.play(Assets.Sounds.PUFF);
	
}
 
Example #9
Source File: Mob.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
public static void restoreAllies( Level level, int pos ){
	if (!heldAllies.isEmpty()){
		
		ArrayList<Integer> candidatePositions = new ArrayList<>();
		for (int i : PathFinder.NEIGHBOURS8) {
			if (!Dungeon.level.solid[i+pos] && level.findMob(i+pos) == null){
				candidatePositions.add(i+pos);
			}
		}
		Collections.shuffle(candidatePositions);
		
		for (Mob ally : heldAllies) {
			level.mobs.add(ally);
			ally.state = ally.WANDERING;
			
			if (!candidatePositions.isEmpty()){
				ally.pos = candidatePositions.remove(0);
			} else {
				ally.pos = pos;
			}
			
		}
	}
	heldAllies.clear();
}
 
Example #10
Source File: EtherealChains.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSelect(Integer target) {
	if (target != null && (Dungeon.level.visited[target] || Dungeon.level.mapped[target])){

		//chains cannot be used to go where it is impossible to walk to
		PathFinder.buildDistanceMap(target, BArray.or(Dungeon.level.passable, Dungeon.level.avoid, null));
		if (PathFinder.distance[curUser.pos] == Integer.MAX_VALUE){
			GLog.w( Messages.get(EtherealChains.class, "cant_reach") );
			return;
		}
		
		final Ballistica chain = new Ballistica(curUser.pos, target, Ballistica.STOP_TARGET);
		
		if (Actor.findChar( chain.collisionPos ) != null){
			chainEnemy( chain, curUser, Actor.findChar( chain.collisionPos ));
		} else {
			chainLocation( chain, curUser );
		}
		throwSound();
		Sample.INSTANCE.play( Assets.Sounds.CHAINS );

	}

}
 
Example #11
Source File: Icecap.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void activate( Char ch ) {
	
	if (ch instanceof Hero && ((Hero) ch).subClass == HeroSubClass.WARDEN){
		Buff.affect(ch, FrostImbue.class, FrostImbue.DURATION*0.3f);
	}
	
	PathFinder.buildDistanceMap( pos, BArray.not( Dungeon.level.losBlocking, null ), 1 );
	
	Fire fire = (Fire)Dungeon.level.blobs.get( Fire.class );
	
	for (int i=0; i < PathFinder.distance.length; i++) {
		if (PathFinder.distance[i] < Integer.MAX_VALUE) {
			Freezing.affect( i, fire );
		}
	}
}
 
Example #12
Source File: Dungeon.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public static PathFinder.Path findPath(Char ch, int to, boolean[] pass, boolean[] vis, boolean chars) {

		setupPassable();
		if (ch.flying || ch.buff( Amok.class ) != null) {
			BArray.or( pass, Dungeon.level.avoid, passable );
		} else {
			System.arraycopy( pass, 0, passable, 0, Dungeon.level.length() );
		}

		if (Char.hasProp(ch, Char.Property.LARGE)){
			BArray.and( pass, Dungeon.level.openSpace, passable );
		}

		if (chars) {
			for (Char c : Actor.chars()) {
				if (vis[c.pos]) {
					passable[c.pos] = false;
				}
			}
		}

		return PathFinder.find( ch.pos, to, passable );

	}
 
Example #13
Source File: Dungeon.java    From pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public static int findPath( Char ch, int from, int to, boolean pass[], boolean[] visible ) {
	
	if (Level.adjacent( from, to )) {
		return Actor.findChar( to ) == null && (pass[to] || Level.avoid[to]) ? to : -1;
	}
	
	if (ch.flying || ch.buff( Amok.class ) != null || ch.buff( Rage.class ) != null) {
		BArray.or( pass, Level.avoid, passable );
	} else {
		System.arraycopy( pass, 0, passable, 0, Level.LENGTH );
	}
	
	for (Actor actor : Actor.all()) {
		if (actor instanceof Char) {
			int pos = ((Char)actor).pos;
			if (visible[pos]) {
				passable[pos] = false;
			}
		}
	}
	
	return PathFinder.getStep( from, to, passable );
	
}
 
Example #14
Source File: WoollyBomb.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void explode(int cell) {
	super.explode(cell);
	
	PathFinder.buildDistanceMap( cell, BArray.not( Dungeon.level.solid, null ), 2 );
	for (int i = 0; i < PathFinder.distance.length; i++) {
		if (PathFinder.distance[i] < Integer.MAX_VALUE) {
			if (Dungeon.level.insideMap(i)
					&& Actor.findChar(i) == null
					&& !(Dungeon.level.pit[i])) {
				Sheep sheep = new Sheep();
				sheep.lifespan = Random.NormalIntRange( 8, 16 );
				sheep.pos = i;
				Dungeon.level.occupyCell(sheep);
				GameScene.add(sheep);
				CellEmitter.get(i).burst(Speck.factory(Speck.WOOL), 4);
			}
		}
	}
	
	Sample.INSTANCE.play(Assets.SND_PUFF);
	
	
}
 
Example #15
Source File: WandOfRegrowth.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void activate( Char ch ) {

	int nSeeds = Random.NormalIntRange(2, 4);

	ArrayList<Integer> candidates = new ArrayList<>();
	for (int i : PathFinder.NEIGHBOURS8){
		if (Dungeon.level.passable[pos+i]
				&& pos+i != Dungeon.level.entrance
				&& pos+i != Dungeon.level.exit){
			candidates.add(pos+i);
		}
	}

	for (int i = 0; i < nSeeds && !candidates.isEmpty(); i++){
		Integer c = Random.element(candidates);
		Dungeon.level.drop(Generator.random(Generator.Category.SEED), c).sprite.drop(pos);
		candidates.remove(c);
	}

}
 
Example #16
Source File: Plant.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onThrow( int cell ) {
	if (Dungeon.level.map[cell] == Terrain.ALCHEMY
			|| Dungeon.level.pit[cell]
			|| Dungeon.level.traps.get(cell) != null
			|| Dungeon.isChallenged(Challenges.NO_HERBALISM)) {
		super.onThrow( cell );
	} else {
		Dungeon.level.plant( this, cell );
		if (Dungeon.hero.subClass == HeroSubClass.WARDEN) {
			for (int i : PathFinder.NEIGHBOURS8) {
				int c = Dungeon.level.map[cell + i];
				if ( c == Terrain.EMPTY || c == Terrain.EMPTY_DECO
						|| c == Terrain.EMBERS || c == Terrain.GRASS){
					Level.set(cell + i, Terrain.FURROWED_GRASS);
					GameScene.updateMap(cell + i);
					CellEmitter.get( cell + i ).burst( LeafParticle.LEVEL_SPECIFIC, 4 );
				}
			}
		}
	}
}
 
Example #17
Source File: Golem.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public void teleportEnemy(){
	spend(TICK);

	int bestPos = enemy.pos;
	for (int i : PathFinder.NEIGHBOURS8){
		if (Dungeon.level.passable[pos + i]
			&& Actor.findChar(pos+i) == null
			&& Dungeon.level.trueDistance(pos+i, enemy.pos) > Dungeon.level.trueDistance(bestPos, enemy.pos)){
			bestPos = pos+i;
		}
	}

	if (enemy.buff(MagicImmune.class) != null){
		bestPos = enemy.pos;
	}

	if (bestPos != enemy.pos){
		ScrollOfTeleportation.appear(enemy, bestPos);
		if (enemy instanceof Hero){
			((Hero) enemy).interrupt();
			Dungeon.observe();
		}
	}

	enemyTeleCooldown = 20;
}
 
Example #18
Source File: StoneOfFlock.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void activate(int cell) {

	for (int i : PathFinder.NEIGHBOURS9){
		
		if (!Dungeon.level.solid[cell + i]
				&& !Dungeon.level.pit[cell + i]
				&& Actor.findChar(cell + i) == null) {
			
			Sheep sheep = new Sheep();
			sheep.lifespan = Random.IntRange(5, 8);
			sheep.pos = cell + i;
			GameScene.add(sheep);
			Dungeon.level.occupyCell(sheep);
			
			CellEmitter.get(sheep.pos).burst(Speck.factory(Speck.WOOL), 4);
		}
	}
	CellEmitter.get(cell).burst(Speck.factory(Speck.WOOL), 4);
	Sample.INSTANCE.play(Assets.SND_PUFF);
	
}
 
Example #19
Source File: QuickSlotButton.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
public static int autoAim(Char target, Item item){

		//first try to directly target
		if (item.throwPos(Dungeon.hero, target.pos) == target.pos) {
			return target.pos;
		}

		//Otherwise pick nearby tiles to try and 'angle' the shot, auto-aim basically.
		PathFinder.buildDistanceMap( target.pos, BArray.not( new boolean[Dungeon.level.length()], null ), 2 );
		for (int i = 0; i < PathFinder.distance.length; i++) {
			if (PathFinder.distance[i] < Integer.MAX_VALUE
					&& item.throwPos(Dungeon.hero, i) == target.pos)
				return i;
		}

		//couldn't find a cell, give up.
		return -1;
	}
 
Example #20
Source File: WandOfLightning.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
private void arc( Char ch ) {

		int dist = (Dungeon.level.water[ch.pos] && !ch.flying) ? 2 : 1;

		ArrayList<Char> hitThisArc = new ArrayList<>();
		PathFinder.buildDistanceMap( ch.pos, BArray.not( Dungeon.level.solid, null ), dist );
		for (int i = 0; i < PathFinder.distance.length; i++) {
			if (PathFinder.distance[i] < Integer.MAX_VALUE){
				Char n = Actor.findChar( i );
				if (n == Dungeon.hero && PathFinder.distance[i] > 1)
					//the hero is only zapped if they are adjacent
					continue;
				else if (n != null && !affected.contains( n )) {
					hitThisArc.add(n);
				}
			}
		}
		
		affected.addAll(hitThisArc);
		for (Char hit : hitThisArc){
			arcs.add(new Lightning.Arc(ch.sprite.center(), hit.sprite.center()));
			arc(hit);
		}
	}
 
Example #21
Source File: WandOfCorrosion.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onZap(Ballistica bolt) {
	CorrosiveGas gas = Blob.seed(bolt.collisionPos, 50 + 10 * buffedLvl(), CorrosiveGas.class);
	CellEmitter.get(bolt.collisionPos).burst(Speck.factory(Speck.CORROSION), 10 );
	gas.setStrength(2 + buffedLvl());
	GameScene.add(gas);
	Sample.INSTANCE.play(Assets.Sounds.GAS);

	for (int i : PathFinder.NEIGHBOURS9) {
		Char ch = Actor.findChar(bolt.collisionPos + i);
		if (ch != null) {
			processSoulMark(ch, chargesPerCast());
		}
	}
	
	if (Actor.findChar(bolt.collisionPos) == null){
		Dungeon.level.pressCell(bolt.collisionPos);
	}
}
 
Example #22
Source File: FrostTrap.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void activate() {
	
	if (Dungeon.level.heroFOV[ pos ]){
		Splash.at( pos, 0xFFB2D6FF, 5);
		Sample.INSTANCE.play( Assets.SND_SHATTER );
	}
	
	PathFinder.buildDistanceMap( pos, BArray.not( Dungeon.level.solid, null ), 2 );
	for (int i = 0; i < PathFinder.distance.length; i++) {
		if (PathFinder.distance[i] < Integer.MAX_VALUE) {
			GameScene.add(Blob.seed(i, 20, Freezing.class));
		}
	}
}
 
Example #23
Source File: Pylon.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean act() {
	spend(TICK);

	Heap heap = Dungeon.level.heaps.get( pos );
	if (heap != null) {
		int n;
		do {
			n = pos + PathFinder.NEIGHBOURS8[Random.Int( 8 )];
		} while (!Dungeon.level.passable[n] && !Dungeon.level.avoid[n]);
		Dungeon.level.drop( heap.pickUp(), n ).sprite.drop( pos );
	}

	if (alignment == Alignment.NEUTRAL){
		return true;
	}

	int cell1 = pos + PathFinder.CIRCLE8[targetNeighbor];
	int cell2 = pos + PathFinder.CIRCLE8[(targetNeighbor+4)%8];

	sprite.flash();
	if (Dungeon.level.heroFOV[pos] || Dungeon.level.heroFOV[cell1] || Dungeon.level.heroFOV[cell2]) {
		sprite.parent.add(new Lightning(DungeonTilemap.raisedTileCenterToWorld(cell1),
				DungeonTilemap.raisedTileCenterToWorld(cell2), null));
		CellEmitter.get(cell1).burst(SparkParticle.FACTORY, 3);
		CellEmitter.get(cell2).burst(SparkParticle.FACTORY, 3);
		Sample.INSTANCE.play( Assets.Sounds.LIGHTNING );
	}

	shockChar(Actor.findChar(cell1));
	shockChar(Actor.findChar(cell2));

	targetNeighbor = (targetNeighbor+1)%8;

	return true;
}
 
Example #24
Source File: DM201.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void rollToDropLoot() {
	if (Dungeon.hero.lvl > maxLvl + 2) return;

	super.rollToDropLoot();

	int ofs;
	do {
		ofs = PathFinder.NEIGHBOURS8[Random.Int(8)];
	} while (!Dungeon.level.passable[pos + ofs]);
	Dungeon.level.drop( new MetalShard(), pos + ofs ).sprite.drop( pos );
}
 
Example #25
Source File: NewTengu.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
public static boolean throwBomb(final Char thrower, final Char target){
	
	int targetCell = -1;
	
	//Targets closest cell which is adjacent to target, and at least 3 tiles away
	for (int i : PathFinder.NEIGHBOURS8){
		int cell = target.pos + i;
		if (Dungeon.level.distance(cell, thrower.pos) >= 3){
			if (targetCell == -1 ||
					Dungeon.level.trueDistance(cell, thrower.pos) < Dungeon.level.trueDistance(targetCell, thrower.pos)){
				targetCell = cell;
			}
		}
	}
	
	if (targetCell == -1){
		return false;
	}
	
	final int finalTargetCell = targetCell;
	throwingChar = thrower;
	final BombAbility.BombItem item = new BombAbility.BombItem();
	thrower.sprite.zap(finalTargetCell);
	((MissileSprite) thrower.sprite.parent.recycle(MissileSprite.class)).
			reset(thrower.sprite,
					finalTargetCell,
					item,
					new Callback() {
						@Override
						public void call() {
							item.onThrow(finalTargetCell);
							thrower.next();
						}
					});
	return true;
}
 
Example #26
Source File: Piranha.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean act(boolean enemyInFOV, boolean justAlerted) {
	if (enemyInFOV) {
		PathFinder.buildDistanceMap(enemy.pos, Dungeon.level.water, viewDistance);
		enemyInFOV = PathFinder.distance[pos] != Integer.MAX_VALUE;
	}
	
	return super.act(enemyInFOV, justAlerted);
}
 
Example #27
Source File: Skeleton.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void die( Object cause ) {
	
	super.die( cause );
	
	if (cause == Chasm.class) return;
	
	boolean heroKilled = false;
	for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) {
		Char ch = findChar( pos + PathFinder.NEIGHBOURS8[i] );
		if (ch != null && ch.isAlive()) {
			int damage = Random.NormalIntRange(6, 12);
			damage = Math.max( 0,  damage - (ch.drRoll() + ch.drRoll()) );
			ch.damage( damage, this );
			if (ch == Dungeon.hero && !ch.isAlive()) {
				heroKilled = true;
			}
		}
	}
	
	if (Dungeon.level.heroFOV[pos]) {
		Sample.INSTANCE.play( Assets.SND_BONES );
	}
	
	if (heroKilled) {
		Dungeon.fail( getClass() );
		GLog.n( Messages.get(this, "explo_kill") );
	}
}
 
Example #28
Source File: OldPrisonBossLevel.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int randomRespawnCell() {
	int pos = 5+2*32; //random cell adjacent to the entrance.
	int cell;
	do {
		cell = pos + PathFinder.NEIGHBOURS8[Random.Int(8)];
	} while (!passable[cell] || Actor.findChar(cell) != null);
	return cell;
}
 
Example #29
Source File: Imp.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static void spawn( CityLevel level ) {
	if (!spawned && Dungeon.depth > 16 && Random.Int( 20 - Dungeon.depth ) == 0) {
		
		Imp npc = new Imp();
		do {
			npc.pos = level.randomRespawnCell( npc );
		} while (
				npc.pos == -1 ||
				level.heaps.get( npc.pos ) != null ||
				level.traps.get( npc.pos) != null ||
				level.findMob( npc.pos ) != null ||
				//The imp doesn't move, so he cannot obstruct a passageway
				!(level.passable[npc.pos + PathFinder.CIRCLE4[0]] && level.passable[npc.pos + PathFinder.CIRCLE4[2]]) ||
				!(level.passable[npc.pos + PathFinder.CIRCLE4[1]] && level.passable[npc.pos + PathFinder.CIRCLE4[3]]));
		level.mobs.add( npc );
		
		spawned = true;

		//always assigns monks on floor 17, golems on floor 19, and 50/50 between either on 18
		switch (Dungeon.depth){
			case 17: default:
				alternative = true;
				break;
			case 18:
				alternative = Random.Int(2) == 0;
				break;
			case 19:
				alternative = false;
				break;
		}
		
		given = false;
		
		do {
			reward = (Ring)Generator.random( Generator.Category.RING );
		} while (reward.cursed);
		reward.upgrade( 2 );
		reward.cursed = true;
	}
}
 
Example #30
Source File: Wraith.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static void spawnAround( int pos ) {
	for (int n : PathFinder.NEIGHBOURS4) {
		int cell = pos + n;
		if (Dungeon.level.passable[cell] && Actor.findChar( cell ) == null) {
			spawnAt( cell );
		}
	}
}