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

The following examples show how to use com.watabou.utils.Graph#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: RegularLevel.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
protected boolean placeEntranceAndExit() {
	int distance;
	int retry = 0;
	int minDistance = (int) Math.sqrt(rooms.size());

	Room roomExit;

	do {
		do {
			roomEntrance = Random.element(rooms);
		} while (roomEntrance.width() < 4 || roomEntrance.height() < 4);

		do {
			roomExit = Random.element(rooms);
		} while (roomExit == roomEntrance || roomExit.width() < 4 || roomExit.height() < 4);

		Graph.buildDistanceMap(rooms, roomExit);
		distance = roomEntrance.distance();

		if (retry++ > 10) {
			return false;
		}

	} while (distance < minDistance);

	roomEntrance.type = Type.ENTRANCE;
	roomExit.type = Type.EXIT;

	setRoomExit(roomExit);

	return true;
}
 
Example 2
Source File: RegularLevel.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
protected void buildPath(Room from, Room to) {
	Graph.buildDistanceMap(rooms, to);
	List<Room> path = Graph.buildPath(from, to);
	if(path!=null) {
		Room room = from;
		for (Room next : path) {
			if (!room.isRoomIsolatedFrom(to)) {
				break;
			}
			room.price(room.price()*2);
			room.connect(next);
			room = next;
		}
	}
}
 
Example 3
Source File: LastShopLevel.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean build() {

	feeling = Feeling.CHASM;
	viewDistance = 4;
	
	initRooms();
	
	int distance;
	int retry = 0;
	int minDistance = (int)Math.sqrt( rooms.size() );
	do {
		int innerRetry = 0;
		do {
			if (innerRetry++ > 10) {
				return false;
			}
			roomEntrance = Random.element( rooms );
		} while (roomEntrance.width() < 4 || roomEntrance.height() < 4);
		
		innerRetry = 0;
		do {
			if (innerRetry++ > 10) {
				return false;
			}
			roomExit = Random.element( rooms );
		} while (roomExit == roomEntrance || roomExit.width() < 6 || roomExit.height() < 6 || roomExit.top == 0);

		Graph.buildDistanceMap( rooms, roomExit );
		distance = Graph.buildPath( rooms, roomEntrance, roomExit ).size();
		
		if (retry++ > 10) {
			return false;
		}
		
	} while (distance < minDistance);
	
	roomEntrance.type = Type.ENTRANCE;
	roomExit.type = Type.EXIT;
	
	Graph.buildDistanceMap( rooms, roomExit );
	List<Room> path = Graph.buildPath( rooms, roomEntrance, roomExit );
	
	Graph.setPrice( path, roomEntrance.distance );
	
	Graph.buildDistanceMap( rooms, roomExit );
	path = Graph.buildPath( rooms, roomEntrance, roomExit );
	
	Room room = roomEntrance;
	for (Room next : path) {
		room.connect( next );
		room = next;
	}
	
	Room roomShop = null;
	int shopSquare = 0;
	for (Room r : rooms) {
		if (r.type == Type.NULL && r.connected.size() > 0) {
			r.type = Type.PASSAGE;
			if (r.square() > shopSquare) {
				roomShop = r;
				shopSquare = r.square();
			}
		}
	}
	
	if (roomShop == null || shopSquare < 54) {
		return false;
	} else {
		roomShop.type = Imp.Quest.isCompleted() ? Room.Type.SHOP : Room.Type.STANDARD;
	}
	
	paint();
	
	paintWater();
	paintGrass();
	
	return true;
}
 
Example 4
Source File: LastShopLevel.java    From pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean build() {
	
	initRooms();
	
	int distance;
	int retry = 0;
	int minDistance = (int)Math.sqrt( rooms.size() );
	do {
		int innerRetry = 0;
		do {
			if (innerRetry++ > 10) {
				return false;
			}
			roomEntrance = Random.element( rooms );
		} while (roomEntrance.width() < 4 || roomEntrance.height() < 4);
		
		innerRetry = 0;
		do {
			if (innerRetry++ > 10) {
				return false;
			}
			roomExit = Random.element( rooms );
		} while (roomExit == roomEntrance || roomExit.width() < 6 || roomExit.height() < 6 || roomExit.top == 0);

		Graph.buildDistanceMap( rooms, roomExit );
		distance = Graph.buildPath( rooms, roomEntrance, roomExit ).size();
		
		if (retry++ > 10) {
			return false;
		}
		
	} while (distance < minDistance);
	
	roomEntrance.type = Type.ENTRANCE;
	roomExit.type = Type.EXIT;
	
	Graph.buildDistanceMap( rooms, roomExit );
	List<Room> path = Graph.buildPath( rooms, roomEntrance, roomExit );
	
	Graph.setPrice( path, roomEntrance.distance );
	
	Graph.buildDistanceMap( rooms, roomExit );
	path = Graph.buildPath( rooms, roomEntrance, roomExit );
	
	Room room = roomEntrance;
	for (Room next : path) {
		room.connect( next );
		room = next;
	}
	
	Room roomShop = null;
	int shopSquare = 0;
	for (Room r : rooms) {
		if (r.type == Type.NULL && r.connected.size() > 0) {
			r.type = Type.PASSAGE; 
			if (r.square() > shopSquare) {
				roomShop = r;
				shopSquare = r.square();
			}
		}
	}
	
	if (roomShop == null || shopSquare < 30) {
		return false;
	} else {
		roomShop.type = Imp.Quest.isCompleted() ? Room.Type.SHOP : Room.Type.STANDARD;
	}
	
	paint();
	
	paintWater();
	paintGrass();
	
	return true;
}
 
Example 5
Source File: RegularPainter.java    From shattered-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
protected void paintDoors( Level l, ArrayList<Room> rooms ) {
	for (Room r : rooms) {
		for (Room n : r.connected.keySet()) {
			
			if (joinRooms(l, r, n)) {
				continue;
			}
			
			Room.Door d = r.connected.get(n);
			int door = d.x + d.y * l.width();
			
			if (d.type == Room.Door.Type.REGULAR){
				//chance for a hidden door scales from 3/21 on floor 2 to 3/3 on floor 20
				if (Dungeon.depth > 1 &&
						(Dungeon.depth >= 20 || Random.Int(23 - Dungeon.depth) < Dungeon.depth)) {
					d.type = Room.Door.Type.HIDDEN;
					Graph.buildDistanceMap(rooms, r);
					//don't hide if it would make this room only accessible by hidden doors
					if (n.distance == Integer.MAX_VALUE){
						d.type = Room.Door.Type.UNLOCKED;
					}
				} else {
					d.type = Room.Door.Type.UNLOCKED;
				}

				//entrance doors on floor 2 are hidden if the player hasn't beaten the first boss
				if (Dungeon.depth == 2
						&& !Badges.isUnlocked(Badges.Badge.BOSS_SLAIN_1)
						&& r instanceof EntranceRoom){
					d.type = Room.Door.Type.HIDDEN;
				}
			}
			
			switch (d.type) {
				case EMPTY:
					l.map[door] = Terrain.EMPTY;
					break;
				case TUNNEL:
					l.map[door] = l.tunnelTile();
					break;
				case UNLOCKED:
					l.map[door] = Terrain.DOOR;
					break;
				case HIDDEN:
					l.map[door] = Terrain.SECRET_DOOR;
					break;
				case BARRICADE:
					l.map[door] = Terrain.BARRICADE;
					break;
				case LOCKED:
					l.map[door] = Terrain.LOCKED_DOOR;
					break;
			}
		}
	}
}
 
Example 6
Source File: LastShopLevel.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean build() {
	
	initRooms();
	
	int distance;
	int retry = 0;
	int minDistance = (int)Math.sqrt( rooms.size() );
	do {
		int innerRetry = 0;
		do {
			if (innerRetry++ > 10) {
				return false;
			}
			roomEntrance = Random.element( rooms );
		} while (roomEntrance.width() < 4 || roomEntrance.height() < 4);
		
		innerRetry = 0;
		do {
			if (innerRetry++ > 10) {
				return false;
			}
			setRoomExit(Random.element( rooms ));
		} while (getRoomExit() == roomEntrance || getRoomExit().width() < 6 || getRoomExit().height() < 6 || getRoomExit().top == 0);

		Graph.buildDistanceMap( rooms, getRoomExit());
		distance = Graph.buildPath(roomEntrance, getRoomExit()).size();
		
		if (retry++ > 10) {
			return false;
		}
		
	} while (distance < minDistance);
	
	roomEntrance.type = Type.ENTRANCE;
	getRoomExit().type = Type.EXIT;
	
	Graph.buildDistanceMap( rooms, getRoomExit());
	List<Room> path = Graph.buildPath(roomEntrance, getRoomExit());
	
	Graph.setPrice( path, roomEntrance.distance );
	
	Graph.buildDistanceMap( rooms, getRoomExit());
	path = Graph.buildPath(roomEntrance, getRoomExit());
	
	Room room = roomEntrance;
	for (Room next : path) {
		room.connect( next );
		room = next;
	}
	
	Room roomShop = null;
	int shopSquare = 0;
	for (Room r : rooms) {
		if (r.type == Type.NULL && r.connected.size() > 0) {
			r.type = Type.PASSAGE; 
			if (r.square() > shopSquare) {
				roomShop = r;
				shopSquare = r.square();
			}
		}
	}
	
	if (roomShop == null || shopSquare < 30) {
		return false;
	} else {
		roomShop.type = Imp.Quest.isCompleted() ? Room.Type.SHOP : Room.Type.STANDARD;
	}
	
	paint();
	
	paintWater();
	paintGrass();
	
	return true;
}
 
Example 7
Source File: SewerBossLevel.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean build() {

	if(!initRooms()){
		return false;
	}

	int distance;
	int retry = 0;
	int minDistance = (int)Math.sqrt( rooms.size() );
	do {
		int innerRetry = 0;
		do {
			if (innerRetry++ > 10) {
				return false;
			}
			roomEntrance = Random.element( rooms );
		} while (roomEntrance.width() < 4 || roomEntrance.height() < 4);
		
		innerRetry = 0;
		do {
			if (innerRetry++ > 10) {
				return false;
			}
			setRoomExit(Random.element( rooms ));
		} while (getRoomExit() == roomEntrance || getRoomExit().width() < 6 || getRoomExit().height() < 6 || getRoomExit().top == 0);

		Graph.buildDistanceMap( rooms, getRoomExit());
		distance = roomEntrance.distance();
		
		if (retry++ > 10) {
			return false;
		}
		
	} while (distance < minDistance);
	
	roomEntrance.type = Type.ENTRANCE;
	getRoomExit().type = Type.SEWER_BOSS_EXIT;

	placeSecondaryExits();

	buildPath(roomEntrance, getRoomExit());

	var ignoredRooms = new HashSet<Room.Type>();
	ignoredRooms.add(Type.NULL);

	connectRooms(ignoredRooms);

	for (Room r : rooms) {
		if (r.type == Type.NULL && r.connected.size() > 0) {
			r.type = Type.TUNNEL;
		}
	}

	placeKingRoom();

	paint();
	
	paintWater();
	
	paintGrass();
	
	placeTraps();
	
	return true;
}
 
Example 8
Source File: RegularPainter.java    From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 4 votes vote down vote up
protected void paintDoors( Level l, ArrayList<Room> rooms ) {
	for (Room r : rooms) {
		for (Room n : r.connected.keySet()) {
			
			if (joinRooms(l, r, n)) {
				continue;
			}
			
			Room.Door d = r.connected.get(n);
			int door = d.x + d.y * l.width();
			
			if (d.type == Room.Door.Type.REGULAR){
				//chance for a hidden door scales from 3/21 on floor 2 to 3/3 on floor 20
				if (Dungeon.depth > 1 &&
						(Dungeon.depth >= 20 || Random.Int(23 - Dungeon.depth) < Dungeon.depth)) {
					d.type = Room.Door.Type.HIDDEN;
					Graph.buildDistanceMap(rooms, r);
					//don't hide if it would make this room only accessible by hidden doors
					if (n.distance == Integer.MAX_VALUE){
						d.type = Room.Door.Type.UNLOCKED;
					}
				} else {
					d.type = Room.Door.Type.UNLOCKED;
				}
			}
			
			switch (d.type) {
				case EMPTY:
					l.map[door] = Terrain.EMPTY;
					break;
				case TUNNEL:
					l.map[door] = l.tunnelTile();
					break;
				case UNLOCKED:
					l.map[door] = Terrain.DOOR;
					break;
				case HIDDEN:
					l.map[door] = Terrain.SECRET_DOOR;
					break;
				case BARRICADE:
					l.map[door] = Terrain.BARRICADE;
					break;
				case LOCKED:
					l.map[door] = Terrain.LOCKED_DOOR;
					break;
			}
		}
	}
}