Java Code Examples for com.watabou.utils.PathFinder#buildDistanceMap()

The following examples show how to use com.watabou.utils.PathFinder#buildDistanceMap() . 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: PotionOfFrost.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void shatter( int cell ) {
	
	if( !canShatter() ) {
		return;
	}
	
	PathFinder.buildDistanceMap( cell, BArray.not( Dungeon.level.losBlocking, null ), (int) (DISTANCE * qualityFactor()));

	for (int i=0; i < Dungeon.level.getLength(); i++) {
		if (PathFinder.distance[i] < Integer.MAX_VALUE) {
			Freezing.affect( i );
		}
	}
	
	splash( cell );
	Sample.INSTANCE.play( Assets.SND_SHATTER );
	
	setKnown();
}
 
Example 2
Source File: Icecap.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 ) {
	
	if (ch instanceof Hero && ((Hero) ch).subClass == HeroSubClass.WARDEN){
		Buff.affect(ch, FrostImbue.class, 15f);
	}
	
	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 3
Source File: Firebomb.java    From shattered-pixel-dungeon 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.pit[i])
				GameScene.add(Blob.seed(i, 2, Fire.class));
			else
				GameScene.add(Blob.seed(i, 10, Fire.class));
			CellEmitter.get(i).burst(FlameParticle.FACTORY, 5);
		}
	}
	Sample.INSTANCE.play(Assets.Sounds.BURNING);
}
 
Example 4
Source File: Shocking.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public static void arc( Char attacker, Char defender, int dist, ArrayList<Char> affected, ArrayList<Lightning.Arc> arcs ) {
	
	affected.add(defender);
	
	defender.sprite.centerEmitter().burst(SparkParticle.FACTORY, 3);
	defender.sprite.flash();
	
	PathFinder.buildDistanceMap( defender.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 != null && n != attacker && !affected.contains(n)) {
				arcs.add(new Lightning.Arc(defender.sprite.center(), n.sprite.center()));
				arc(attacker, n, (Dungeon.level.water[n.pos] && !n.flying) ? 2 : 1, affected, arcs);
			}
		}
	}
}
 
Example 5
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 6
Source File: Firebomb.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.pit[i])
				GameScene.add(Blob.seed(i, 2, Fire.class));
			else
				GameScene.add(Blob.seed(i, 10, Fire.class));
			CellEmitter.get(i).burst(FlameParticle.FACTORY, 5);
		}
	}
	Sample.INSTANCE.play(Assets.SND_BURNING);
}
 
Example 7
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 8
Source File: Piranha.java    From shattered-pixel-dungeon-gdx 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 9
Source File: RogueArmor.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onSelect( Integer target ) {
	if (target != null) {
		
		PathFinder.buildDistanceMap(curUser.pos, BArray.not(Dungeon.level.solid,null), 8);
		
		if ( PathFinder.distance[target] == Integer.MAX_VALUE ||
			!Dungeon.level.heroFOV[target] ||
			Actor.findChar( target ) != null) {
			
			GLog.w( Messages.get(RogueArmor.class, "fov") );
			return;
		}

		charge -= 35;
		updateQuickslot();
		
		for (Mob mob : Dungeon.level.mobs.toArray(new Mob[0])) {
			if (Dungeon.level.adjacent(mob.pos, curUser.pos) && mob.alignment != Char.Alignment.ALLY) {
				Buff.prolong( mob, Blindness.class, Blindness.DURATION/2f );
				if (mob.state == mob.HUNTING) mob.state = mob.WANDERING;
				mob.sprite.emitter().burst( Speck.factory( Speck.LIGHT ), 4 );
			}
		}
		Buff.affect(curUser, Invisibility.class, Invisibility.DURATION/2f);

		CellEmitter.get( curUser.pos ).burst( Speck.factory( Speck.WOOL ), 10 );
		ScrollOfTeleportation.appear( curUser, target );
		Sample.INSTANCE.play( Assets.Sounds.PUFF );
		Dungeon.level.occupyCell(curUser );
		Dungeon.observe();
		GameScene.updateFog();
		
		curUser.spendAndNext( Actor.TICK );
	}
}
 
Example 10
Source File: Piranha.java    From shattered-pixel-dungeon-gdx 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 11
Source File: StormTrap.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]){
		Sample.INSTANCE.play( Assets.SND_LIGHTNING );
	}
	
	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, Electricity.class));
		}
	}
}
 
Example 12
Source File: StoneOfShock.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void activate(int cell) {
	
	Sample.INSTANCE.play( Assets.Sounds.LIGHTNING );
	
	ArrayList<Lightning.Arc> arcs = new ArrayList<>();
	int hits = 0;
	
	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) {
			Char n = Actor.findChar(i);
			if (n != null) {
				arcs.add(new Lightning.Arc(cell, n.sprite.center()));
				Buff.prolong(n, Paralysis.class, 1f);
				hits++;
			}
		}
	}
	
	CellEmitter.center( cell ).burst( SparkParticle.FACTORY, 3 );
	
	if (hits > 0) {
		curUser.sprite.parent.addToFront( new Lightning( arcs, null ) );
		curUser.sprite.centerEmitter().burst(EnergyParticle.FACTORY, 10);
		Sample.INSTANCE.play( Assets.Sounds.LIGHTNING );
		
		curUser.belongings.charge(1f + hits);
	}

}
 
Example 13
Source File: FrostBomb.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 5 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) {
			GameScene.add(Blob.seed(i, 10, Freezing.class));
			Char ch = Actor.findChar(i);
			if (ch != null){
				Buff.affect(ch, Frost.class, 2f);
			}
		}
	}
}
 
Example 14
Source File: Icecap.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void activate() {
	
	PathFinder.buildDistanceMap( pos, BArray.not( Level.losBlocking, null ), 1 );
	
	Fire fire = (Fire)Dungeon.level.blobs.get( Fire.class );
	
	for (int i=0; i < Level.LENGTH; i++) {
		if (PathFinder.distance[i] < Integer.MAX_VALUE) {
			Freezing.affect( i, fire );
		}
	}
}
 
Example 15
Source File: StormTrap.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void activate() {
	
	if (Dungeon.level.heroFOV[pos]){
		Sample.INSTANCE.play( Assets.Sounds.LIGHTNING );
	}
	
	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, Electricity.class));
		}
	}
}
 
Example 16
Source File: SecretMazeRoom.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void paint(Level level) {
	Painter.fill(level, this, Terrain.WALL);
	Painter.fill(level, this, 1, Terrain.EMPTY);
	
	//true = space, false = wall
	Maze.allowDiagonals = false;
	boolean[][] maze = Maze.generate(this);
	boolean[] passable = new boolean[width()*height()];
	
	Painter.fill(level, this, 1, Terrain.EMPTY);
	for (int x = 0; x < maze.length; x++) {
		for (int y = 0; y < maze[0].length; y++) {
			if (maze[x][y] == Maze.FILLED) {
				Painter.fill(level, x + left, y + top, 1, 1, Terrain.WALL);
			}
			passable[x + width()*y] = maze[x][y] == Maze.EMPTY;
		}
	}
	
	PathFinder.setMapSize(width(), height());
	Point entrance = entrance();
	int entrancePos = (entrance.x - left) + width()*(entrance.y - top);
	
	PathFinder.buildDistanceMap( entrancePos, passable );
	
	int bestDist = 0;
	Point bestDistP = new Point();
	for (int i = 0; i < PathFinder.distance.length; i++){
		if (PathFinder.distance[i] != Integer.MAX_VALUE
				&& PathFinder.distance[i] > bestDist){
			bestDist = PathFinder.distance[i];
			bestDistP.x = (i % width()) + left;
			bestDistP.y = (i / width()) + top;
		}
	}
	
	Item prize;
	//1 floor set higher in probability, never cursed
	do {
		if (Random.Int(2) == 0) {
			prize = Generator.randomWeapon((Dungeon.depth / 5) + 1);
		} else {
			prize = Generator.randomArmor((Dungeon.depth / 5) + 1);
		}
	} while (prize.cursed || Challenges.isItemBlocked(prize));
	
	//33% chance for an extra update.
	if (Random.Int(3) == 0){
		prize.upgrade();
	}
	
	level.drop(prize, level.pointToCell(bestDistP)).type = Heap.Type.CHEST;
	
	PathFinder.setMapSize(level.width(), level.height());
	
	entrance().set(Door.Type.HIDDEN);
}
 
Example 17
Source File: Goo.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean doAttack( Char enemy ) {
	if (pumpedUp == 1) {
		((GooSprite)sprite).pumpUp();
		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, 1, GooWarn.class));
		}
		pumpedUp++;
		Sample.INSTANCE.play( Assets.Sounds.CHARGEUP );

		spend( attackDelay() );

		return true;
	} else if (pumpedUp >= 2 || Random.Int( (HP*2 <= HT) ? 2 : 5 ) > 0) {

		boolean visible = Dungeon.level.heroFOV[pos];

		if (visible) {
			if (pumpedUp >= 2) {
				((GooSprite) sprite).pumpAttack();
			}
			else
				sprite.attack( enemy.pos );
		} else {
			attack( enemy );
		}

		spend( attackDelay() );

		return !visible;

	} else {

		pumpedUp++;

		((GooSprite)sprite).pumpUp();

		for (int i=0; i < PathFinder.NEIGHBOURS9.length; i++) {
			int j = pos + PathFinder.NEIGHBOURS9[i];
			if (!Dungeon.level.solid[j]) {
				GameScene.add(Blob.seed(j, 1, GooWarn.class));
			}
		}

		if (Dungeon.level.heroFOV[pos]) {
			sprite.showStatus( CharSprite.NEGATIVE, Messages.get(this, "!!!") );
			GLog.n( Messages.get(this, "pumpup") );
			Sample.INSTANCE.play( Assets.Sounds.CHARGEUP, 1f, 0.8f );
		}

		spend( attackDelay() );

		return true;
	}
}
 
Example 18
Source File: King.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
private void summon() {

		nextPedestal = !nextPedestal;
		
		sprite.centerEmitter().start( Speck.factory( Speck.SCREAM ), 0.4f, 2 );
		Sample.INSTANCE.play( Assets.SND_CHALLENGE );
		
		boolean[] passable = Dungeon.level.passable.clone();
		for (Char c : Actor.chars()) {
			passable[c.pos] = false;
		}
		
		int undeadsToSummon = maxArmySize() - Undead.count;

		PathFinder.buildDistanceMap( pos, passable, undeadsToSummon );
		PathFinder.distance[pos] = Integer.MAX_VALUE;
		int dist = 1;
		
	undeadLabel:
		for (int i=0; i < undeadsToSummon; i++) {
			do {
				for (int j=0; j < Dungeon.level.length(); j++) {
					if (PathFinder.distance[j] == dist) {
						
						Undead undead = new Undead();
						undead.pos = j;
						GameScene.add( undead );
						
						ScrollOfTeleportation.appear( undead, j );
						new Flare( 3, 32 ).color( 0x000000, false ).show( undead.sprite, 2f ) ;
						
						PathFinder.distance[j] = Integer.MAX_VALUE;
						
						continue undeadLabel;
					}
				}
				dist++;
			} while (dist < undeadsToSummon);
		}
		
		yell( Messages.get(this, "arise") );
		spend( TICK );
	}
 
Example 19
Source File: SecretMazeRoom.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void paint(Level level) {
	Painter.fill(level, this, Terrain.WALL);
	Painter.fill(level, this, 1, Terrain.EMPTY);
	
	//true = space, false = wall
	Maze.allowDiagonals = false;
	boolean[][] maze = Maze.generate(this);
	boolean[] passable = new boolean[width()*height()];
	
	Painter.fill(level, this, 1, Terrain.EMPTY);
	for (int x = 0; x < maze.length; x++) {
		for (int y = 0; y < maze[0].length; y++) {
			if (maze[x][y] == Maze.FILLED) {
				Painter.fill(level, x + left, y + top, 1, 1, Terrain.WALL);
			}
			passable[x + width()*y] = maze[x][y] == Maze.EMPTY;
		}
	}
	
	PathFinder.setMapSize(width(), height());
	Point entrance = entrance();
	int entrancePos = (entrance.x - left) + width()*(entrance.y - top);
	
	PathFinder.buildDistanceMap( entrancePos, passable );
	
	int bestDist = 0;
	Point bestDistP = new Point();
	for (int i = 0; i < PathFinder.distance.length; i++){
		if (PathFinder.distance[i] != Integer.MAX_VALUE
				&& PathFinder.distance[i] > bestDist){
			bestDist = PathFinder.distance[i];
			bestDistP.x = (i % width()) + left;
			bestDistP.y = (i / width()) + top;
		}
	}
	
	Item prize;
	//1 floor set higher in probability, never cursed
	do {
		if (Random.Int(2) == 0) {
			prize = Generator.randomWeapon((Dungeon.depth / 5) + 1);
		} else {
			prize = Generator.randomArmor((Dungeon.depth / 5) + 1);
		}
	} while (prize.cursed || Challenges.isItemBlocked(prize));
	
	//33% chance for an extra update.
	if (Random.Int(3) == 0){
		prize.upgrade();
	}
	
	level.drop(prize, level.pointToCell(bestDistP)).type = Heap.Type.CHEST;
	
	PathFinder.setMapSize(level.width(), level.height());
	
	entrance().set(Door.Type.HIDDEN);
}
 
Example 20
Source File: WandOfFlock.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onZap( int cell ) {
	int level = effectiveLevel();
	
	int n = level + 2;
	
	if (Actor.findChar( cell ) != null && Ballistica.distance > 2) {
		cell = Ballistica.trace[Ballistica.distance - 2];
	}
	
	boolean[] passable = BArray.or( Dungeon.level.passable, Dungeon.level.avoid, null );
	for (Actor actor : Actor.all()) {
		if (actor instanceof Char) {
			passable[((Char)actor).getPos()] = false;
		}
	}
	
	PathFinder.buildDistanceMap( cell, passable, n );
	int dist = 0;
	
	if (Actor.findChar( cell ) != null) {
		PathFinder.distance[cell] = Integer.MAX_VALUE;
		dist = 1;
	}
	
	float lifespan = level + 3;
	
sheepLabel:
	for (int i=0; i < n; i++) {
		do {
			for (int j=0; j < Dungeon.level.getLength(); j++) {
				if (PathFinder.distance[j] == dist) {
					
					Sheep sheep = new Sheep();
					sheep.lifespan = lifespan;
					sheep.setPos(j);
					Dungeon.level.spawnMob(sheep);
					Dungeon.level.press(sheep.getPos(), sheep );
					
					CellEmitter.get( j ).burst( Speck.factory( Speck.WOOL ), 4 );
					
					PathFinder.distance[j] = Integer.MAX_VALUE;
					
					continue sheepLabel;
				}
			}
			dist++;
		} while (dist < n);
	}
}