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

The following examples show how to use com.watabou.utils.PathFinder#getStep() . 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: Dungeon.java    From unleashed-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) {
		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 2
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 3
Source File: YogFist.java    From shattered-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void damage(int dmg, Object src) {
	int beforeHP = HP;
	super.damage(dmg, src);
	if (isAlive() && beforeHP > HT/2 && HP < HT/2){
		HP = HT/2;
		Buff.prolong( Dungeon.hero, Blindness.class, Blindness.DURATION*1.5f );
		int i;
		do {
			i = Random.Int(Dungeon.level.length());
		} while (Dungeon.level.heroFOV[i]
				|| Dungeon.level.solid[i]
				|| Actor.findChar(i) != null
				|| PathFinder.getStep(i, Dungeon.level.exit, Dungeon.level.passable) == -1);
		ScrollOfTeleportation.appear(this, i);
		state = WANDERING;
		GameScene.flash(0xFFFFFF);
		GLog.w( Messages.get( this, "teleport" ));
	} else if (!isAlive()){
		Buff.prolong( Dungeon.hero, Blindness.class, Blindness.DURATION*3f );
		GameScene.flash(0xFFFFFF);
	}
}
 
Example 4
Source File: Dungeon.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 6 votes vote down vote up
public static int findStep(Char ch, int from, int to, boolean pass[], boolean[] visible ) {

		if (Dungeon.level.adjacent( from, to )) {
			return Actor.findChar( to ) == null && (pass[to] || Dungeon.level.avoid[to]) ? to : -1;
		}

		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() );
		}
		
		for (Char c : Actor.chars()) {
			if (visible[c.pos]) {
				passable[c.pos] = false;
			}
		}
		
		return PathFinder.getStep( from, to, passable );

	}
 
Example 5
Source File: Dungeon.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 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] && !(ch instanceof Piranha)) ? to : -1;
		}

		if (ch.flying || ch.buff( Tormented.class ) != null ||
            ch.buff( Blinded.class ) != null || ch.buff( Vertigo.class ) != null
        ) {
			BArray.or( pass, Level.avoid, passable );
		} else {
			System.arraycopy( pass, 0, passable, 0, Level.LENGTH );
		}

        if (ch instanceof Mob && !(ch instanceof Piranha)) {
            BArray.or( passable, Level.illusory, passable );
        }

		for (Actor actor : Actor.all()) {
			if (actor instanceof Char) {
				int pos = ((Char)actor).pos;
				if (visible[pos] && ((Char) actor).invisible == 0) {
					passable[pos] = false;
				}
			}
		}
		
		return PathFinder.getStep( from, to, passable );
		
	}
 
Example 6
Source File: Dungeon.java    From shattered-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static int findStep(Char ch, int to, boolean[] pass, boolean[] visible, boolean chars ) {

		if (Dungeon.level.adjacent( ch.pos, to )) {
			return Actor.findChar( to ) == null && (pass[to] || Dungeon.level.avoid[to]) ? to : -1;
		}

		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 (visible[c.pos]) {
					passable[c.pos] = false;
				}
			}
		}
		
		return PathFinder.getStep( ch.pos, to, passable );

	}
 
Example 7
Source File: Dungeon.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static int findPath(Hero ch, int from, int to, boolean pass[], boolean[] visible) {

        if (level.adjacent(from, to)) {
            if (!(pass[to] || level.avoid[to])) {
                return -1;
            }

            Char chr = Actor.findChar(to);

            if (chr instanceof Mob) {
                Mob mob = (Mob) chr;
                if (mob.isPet()) {
                    return to;
                }
            }
            return chr == null ? to : -1;
        }

        if (ch.isFlying() || ch.hasBuff(Amok.class)) {
            BArray.or(pass, level.avoid, passable);
        } else {
            System.arraycopy(pass, 0, passable, 0, level.getLength());
        }

        markActorsAsUnpassable(ch, visible);

        markObjects(ch);

        return PathFinder.getStep(from, to, passable);
    }
 
Example 8
Source File: NewHallsBossLevel.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean build() {

	setSize(WIDTH, HEIGHT);

	for (int i = 0; i < 5; i++) {

		int top;
		int bottom;

		if (i == 0 || i == 4){
			top = Random.IntRange(ROOM_TOP-1, ROOM_TOP+3);
			bottom = Random.IntRange(ROOM_BOTTOM+2, ROOM_BOTTOM+6);
		} else if (i == 1 || i == 3){
			top = Random.IntRange(ROOM_TOP-5, ROOM_TOP-1);
			bottom = Random.IntRange(ROOM_BOTTOM+6, ROOM_BOTTOM+10);
		} else {
			top = Random.IntRange(ROOM_TOP-6, ROOM_TOP-3);
			bottom = Random.IntRange(ROOM_BOTTOM+8, ROOM_BOTTOM+12);
		}

		Painter.fill(this, 4 + i * 5, top, 5, bottom - top + 1, Terrain.EMPTY);

		if (i == 2) {
			entrance = (6 + i * 5) + (bottom - 1) * width();
		}

	}

	boolean[] patch = Patch.generate(width, height, 0.20f, 0, true);
	for (int i = 0; i < length(); i++) {
		if (map[i] == Terrain.EMPTY && patch[i]) {
			map[i] = Terrain.STATUE;
		}
	}

	map[entrance] = Terrain.ENTRANCE;

	Painter.fill(this, ROOM_LEFT-1, ROOM_TOP-1, 11, 11, Terrain.EMPTY );

	patch = Patch.generate(width, height, 0.30f, 3, true);
	for (int i = 0; i < length(); i++) {
		if ((map[i] == Terrain.EMPTY || map[i] == Terrain.STATUE) && patch[i]) {
			map[i] = Terrain.WATER;
		}
	}

	for (int i = 0; i < length(); i++) {
		if (map[i] == Terrain.EMPTY && Random.Int(4) == 0) {
			map[i] = Terrain.EMPTY_DECO;
		}
	}

	Painter.fill(this, ROOM_LEFT, ROOM_TOP, 9, 9, Terrain.EMPTY_SP );

	Painter.fill(this, ROOM_LEFT, ROOM_TOP, 9, 2, Terrain.WALL_DECO );
	Painter.fill(this, ROOM_LEFT, ROOM_BOTTOM-1, 2, 2, Terrain.WALL_DECO );
	Painter.fill(this, ROOM_RIGHT-1, ROOM_BOTTOM-1, 2, 2, Terrain.WALL_DECO );

	Painter.fill(this, ROOM_LEFT+3, ROOM_TOP+2, 3, 4, Terrain.EMPTY );

	exit = width/2 + ((ROOM_TOP+1) * width);

	CustomTilemap vis = new CenterPieceVisuals();
	vis.pos(ROOM_LEFT, ROOM_TOP+1);
	customTiles.add(vis);

	vis = new CenterPieceWalls();
	vis.pos(ROOM_LEFT, ROOM_TOP);
	customWalls.add(vis);

	//basic version of building flag maps for the pathfinder test
	for (int i = 0; i < length; i++){
		passable[i]	= ( Terrain.flags[map[i]] & Terrain.PASSABLE) != 0;
	}

	//ensures a path to the exit exists
	return (PathFinder.getStep(entrance, exit, passable) != -1);
}
 
Example 9
Source File: Dungeon.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public static int findPath(Char ch, int from, int to, boolean pass[]) {

        if (level.adjacent(from, to)) {

            if (!(pass[to] || level.avoid[to])) {
                return -1;
            }

            Char chr = Actor.findChar(to);

            return chr == null ? to : -1;
        }

        if (ch.isFlying() || ch.hasBuff(Amok.class)) {
            BArray.or(pass, level.avoid, passable);
        } else {
            System.arraycopy(pass, 0, passable, 0, level.getLength());
        }

        markActorsAsUnpassableIgnoreFov();

        markObjects(ch);

        return PathFinder.getStep(from, to, passable);

    }