v0.6.0: moved special room management into the special room class

This commit is contained in:
Evan Debenham 2017-03-29 19:49:04 -04:00
parent 0d366be632
commit a9e6eb8108
4 changed files with 59 additions and 72 deletions

View File

@ -53,7 +53,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.PrisonBossLevel;
import com.shatteredpixel.shatteredpixeldungeon.levels.PrisonLevel;
import com.shatteredpixel.shatteredpixeldungeon.levels.SewerBossLevel;
import com.shatteredpixel.shatteredpixeldungeon.levels.SewerLevel;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.StartScene;
@ -158,7 +158,7 @@ public class Dungeon {
transmutation = Random.IntRange( 6, 14 );
Room.shuffleTypes();
SpecialRoom.shuffleTypes();
Random.seed();
@ -476,7 +476,7 @@ public class Dungeon {
Imp .Quest.storeInBundle( quests );
bundle.put( QUESTS, quests );
Room.storeRoomsInBundle( bundle );
SpecialRoom.storeRoomsInBundle( bundle );
Statistics.storeInBundle( bundle );
Journal.storeInBundle( bundle );
@ -592,7 +592,7 @@ public class Dungeon {
Imp.Quest.reset();
}
Room.restoreRoomsFromBundle(bundle);
SpecialRoom.restoreRoomsFromBundle(bundle);
}
Bundle badges = bundle.getBundle(BADGES);

View File

@ -17,6 +17,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.MagicWellRo
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.PitRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.RatKingRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ShopRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.StatueRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.TreasuryRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.VaultRoom;
@ -168,7 +169,7 @@ public class LegacyBuilder extends Builder {
}
}
specials = new ArrayList<Class<? extends Room>>( Room.SPECIALS );
specials = new ArrayList<>( SpecialRoom.SPECIALS );
if (Dungeon.bossLevel( Dungeon.depth + 1 )) {
specials.remove( WeakFloorRoom.class );
}
@ -510,7 +511,7 @@ public class LegacyBuilder extends Builder {
}
Room.useType( r.getClass() );
SpecialRoom.useType( r.getClass() );
specials.remove( r.getClass() );
specialRooms++;
@ -519,7 +520,7 @@ public class LegacyBuilder extends Builder {
ArrayList<Room> neigbours = new ArrayList<>();
for (Room n : r.neigbours) {
if (!r.connected.containsKey( n ) &&
!Room.SPECIALS.contains( n.getClass() ) &&
!SpecialRoom.SPECIALS.contains( n.getClass() ) &&
!(n instanceof PitRoom)) {
neigbours.add( n );

View File

@ -22,20 +22,6 @@
package com.shatteredpixel.shatteredpixeldungeon.levels.rooms;
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.ArmoryRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.CryptRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.GardenRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.LaboratoryRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.LibraryRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.MagicWellRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.PoolRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.StatueRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.StorageRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.TrapsRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.TreasuryRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.VaultRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.WeakFloorRoom;
import com.watabou.utils.Bundlable;
import com.watabou.utils.Bundle;
import com.watabou.utils.Graph;
@ -44,7 +30,6 @@ import com.watabou.utils.Random;
import com.watabou.utils.Rect;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
@ -108,19 +93,6 @@ public class Room extends Rect implements Graph.Node, Bundlable {
public void paint(Level level){ }
public void paint(Level level, Room room){
}
private static final ArrayList<Class<? extends SpecialRoom>> ALL_SPEC = new ArrayList<>( Arrays.asList(
WeakFloorRoom.class, MagicWellRoom.class, CryptRoom.class, PoolRoom.class, GardenRoom.class, LibraryRoom.class, ArmoryRoom.class,
TreasuryRoom.class, TrapsRoom.class, StorageRoom.class, StatueRoom.class, LaboratoryRoom.class, VaultRoom.class
) );
public static ArrayList<Class<? extends Room>> SPECIALS = new ArrayList<>();
public String legacyType = "NULL";
public Point random() {
return random( 0 );
}
@ -185,6 +157,8 @@ public class Room extends Rect implements Graph.Node, Bundlable {
return neigbours;
}
public String legacyType = "NULL";
@Override
public void storeInBundle( Bundle bundle ) {
bundle.put( "left", left );
@ -205,45 +179,9 @@ public class Room extends Rect implements Graph.Node, Bundlable {
legacyType = bundle.getString( "type" );
}
public static void shuffleTypes() {
SPECIALS = (ArrayList<Class<?extends Room>>)ALL_SPEC.clone();
int size = SPECIALS.size();
for (int i=0; i < size - 1; i++) {
int j = Random.Int( i, size );
if (j != i) {
Class<?extends Room> c = SPECIALS.get( i );
SPECIALS.set( i, SPECIALS.get( j ) );
SPECIALS.set( j, c );
}
}
}
public static void useType( Class<?extends Room> type ) {
if (SPECIALS.remove( type )) {
SPECIALS.add( type );
}
}
private static final String ROOMS = "special_rooms";
public static void restoreRoomsFromBundle( Bundle bundle ) {
if (bundle.contains( ROOMS )) {
SPECIALS.clear();
for (Class<?extends Room> type : bundle.getClassArray( ROOMS )) {
SPECIALS.add( type );
}
} else {
shuffleTypes();
}
}
public static void storeRoomsInBundle( Bundle bundle ) {
bundle.put( ROOMS, SPECIALS.toArray(new Class[0]) );
}
public static class Door extends Point {
public static enum Type {
public enum Type {
EMPTY, TUNNEL, REGULAR, UNLOCKED, HIDDEN, BARRICADE, LOCKED
}
public Type type = Type.EMPTY;

View File

@ -1,6 +1,11 @@
package com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
import com.watabou.utils.Bundle;
import com.watabou.utils.Random;
import java.util.ArrayList;
import java.util.Arrays;
public class SpecialRoom extends Room {
@ -17,4 +22,47 @@ public class SpecialRoom extends Room {
public Door entrance() {
return connected.values().iterator().next();
}
private static final ArrayList<Class<? extends SpecialRoom>> ALL_SPEC = new ArrayList<>( Arrays.asList(
WeakFloorRoom.class, MagicWellRoom.class, CryptRoom.class, PoolRoom.class, GardenRoom.class, LibraryRoom.class, ArmoryRoom.class,
TreasuryRoom.class, TrapsRoom.class, StorageRoom.class, StatueRoom.class, LaboratoryRoom.class, VaultRoom.class
) );
public static ArrayList<Class<? extends Room>> SPECIALS = new ArrayList<>();
public static void shuffleTypes() {
SPECIALS = (ArrayList<Class<?extends Room>>)ALL_SPEC.clone();
int size = SPECIALS.size();
for (int i=0; i < size - 1; i++) {
int j = Random.Int( i, size );
if (j != i) {
Class<?extends Room> c = SPECIALS.get( i );
SPECIALS.set( i, SPECIALS.get( j ) );
SPECIALS.set( j, c );
}
}
}
public static void useType( Class<?extends Room> type ) {
if (SPECIALS.remove( type )) {
SPECIALS.add( type );
}
}
private static final String ROOMS = "special_rooms";
public static void restoreRoomsFromBundle( Bundle bundle ) {
if (bundle.contains( ROOMS )) {
SPECIALS.clear();
for (Class<?extends Room> type : bundle.getClassArray( ROOMS )) {
SPECIALS.add( type );
}
} else {
shuffleTypes();
}
}
public static void storeRoomsInBundle( Bundle bundle ) {
bundle.put( ROOMS, SPECIALS.toArray(new Class[0]) );
}
}