v0.6.0: improvements to finding a random room in regularlevel
This commit is contained in:
parent
c15316baa2
commit
0e0554f324
|
@ -51,6 +51,7 @@ import com.watabou.utils.Random;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public abstract class RegularLevel extends Level {
|
public abstract class RegularLevel extends Level {
|
||||||
|
@ -207,7 +208,7 @@ public abstract class RegularLevel extends Level {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Room room = randomRoom( StandardRoom.class, 10 );
|
Room room = randomRoom( StandardRoom.class );
|
||||||
if (room == null) {
|
if (room == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -311,11 +312,13 @@ public abstract class RegularLevel extends Level {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Room randomRoom( Class<?extends Room> type, int tries ) {
|
protected Room randomRoom( Class<?extends Room> type ) {
|
||||||
for (int i=0; i < tries; i++) {
|
Collections.shuffle( rooms );
|
||||||
Room room = Random.element( rooms );
|
for (Room r : rooms) {
|
||||||
if (room.getClass().equals(type)) {
|
if (type.isInstance(r)
|
||||||
return room;
|
//compatibility with pre-0.6.0 saves
|
||||||
|
|| (type == StandardRoom.class && r.legacyType.equals("STANDARD"))) {
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -333,7 +336,7 @@ public abstract class RegularLevel extends Level {
|
||||||
|
|
||||||
protected int randomDropCell() {
|
protected int randomDropCell() {
|
||||||
while (true) {
|
while (true) {
|
||||||
Room room = randomRoom( StandardRoom.class, 1 );
|
Room room = randomRoom( StandardRoom.class );
|
||||||
if (room != null) {
|
if (room != null) {
|
||||||
int pos = pointToCell(room.random());
|
int pos = pointToCell(room.random());
|
||||||
if (passable[pos]) {
|
if (passable[pos]) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user