v2.1.1: added lots of new code to support actually using depth branches
This commit is contained in:
@@ -179,9 +179,12 @@ public class Dungeon {
|
|||||||
public static int depth;
|
public static int depth;
|
||||||
//determines path the hero is on. Current uses:
|
//determines path the hero is on. Current uses:
|
||||||
// 0 is the default path
|
// 0 is the default path
|
||||||
// Other numbers are currently unused
|
// 1 is for quest sub-floors
|
||||||
public static int branch;
|
public static int branch;
|
||||||
|
|
||||||
|
//keeps track of what levels the game should try to load instead of creating fresh
|
||||||
|
public static ArrayList<Integer> generatedLevels = new ArrayList<>();
|
||||||
|
|
||||||
public static int gold;
|
public static int gold;
|
||||||
public static int energy;
|
public static int energy;
|
||||||
|
|
||||||
@@ -244,6 +247,7 @@ public class Dungeon {
|
|||||||
|
|
||||||
depth = 1;
|
depth = 1;
|
||||||
branch = 0;
|
branch = 0;
|
||||||
|
generatedLevels.clear();
|
||||||
|
|
||||||
gold = 0;
|
gold = 0;
|
||||||
energy = 0;
|
energy = 0;
|
||||||
@@ -271,21 +275,15 @@ public class Dungeon {
|
|||||||
return (challenges & mask) != 0;
|
return (challenges & mask) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean levelHasBeenGenerated(int depth, int branch){
|
||||||
|
return generatedLevels.contains(depth + 1000*branch);
|
||||||
|
}
|
||||||
|
|
||||||
public static Level newLevel() {
|
public static Level newLevel() {
|
||||||
|
|
||||||
Dungeon.level = null;
|
Dungeon.level = null;
|
||||||
Actor.clear();
|
Actor.clear();
|
||||||
|
|
||||||
if (depth > Statistics.deepestFloor) {
|
|
||||||
Statistics.deepestFloor = depth;
|
|
||||||
|
|
||||||
if (Statistics.qualifiedForNoKilling) {
|
|
||||||
Statistics.completedWithNoKilling = true;
|
|
||||||
} else {
|
|
||||||
Statistics.completedWithNoKilling = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Level level;
|
Level level;
|
||||||
if (branch == 0) {
|
if (branch == 0) {
|
||||||
switch (depth) {
|
switch (depth) {
|
||||||
@@ -339,16 +337,33 @@ public class Dungeon {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
level = new DeadEndLevel();
|
level = new DeadEndLevel();
|
||||||
Statistics.deepestFloor--;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
level = new DeadEndLevel();
|
level = new DeadEndLevel();
|
||||||
Statistics.deepestFloor--;
|
}
|
||||||
|
|
||||||
|
//dead end levels get cleared, don't count as generated
|
||||||
|
if (!(level instanceof DeadEndLevel)){
|
||||||
|
//this assumes that we will never have a depth value outside the range 0 to 999
|
||||||
|
// or -500 to 499, etc.
|
||||||
|
if (!generatedLevels.contains(depth + 1000*branch)) {
|
||||||
|
generatedLevels.add(depth + 1000 * branch);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (depth > Statistics.deepestFloor && branch == 0) {
|
||||||
|
Statistics.deepestFloor = depth;
|
||||||
|
|
||||||
|
if (Statistics.qualifiedForNoKilling) {
|
||||||
|
Statistics.completedWithNoKilling = true;
|
||||||
|
} else {
|
||||||
|
Statistics.completedWithNoKilling = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
level.create();
|
level.create();
|
||||||
|
|
||||||
Statistics.qualifiedForNoKilling = !bossLevel();
|
if (branch == 0) Statistics.qualifiedForNoKilling = !bossLevel();
|
||||||
Statistics.qualifiedForBossChallengeBadge = false;
|
Statistics.qualifiedForBossChallengeBadge = false;
|
||||||
|
|
||||||
return level;
|
return level;
|
||||||
@@ -524,6 +539,7 @@ public class Dungeon {
|
|||||||
private static final String HERO = "hero";
|
private static final String HERO = "hero";
|
||||||
private static final String DEPTH = "depth";
|
private static final String DEPTH = "depth";
|
||||||
private static final String BRANCH = "branch";
|
private static final String BRANCH = "branch";
|
||||||
|
private static final String GENERATED_LEVELS = "generated_levels";
|
||||||
private static final String GOLD = "gold";
|
private static final String GOLD = "gold";
|
||||||
private static final String ENERGY = "energy";
|
private static final String ENERGY = "energy";
|
||||||
private static final String DROPPED = "dropped%d";
|
private static final String DROPPED = "dropped%d";
|
||||||
@@ -584,6 +600,12 @@ public class Dungeon {
|
|||||||
Notes.storeInBundle( bundle );
|
Notes.storeInBundle( bundle );
|
||||||
Generator.storeInBundle( bundle );
|
Generator.storeInBundle( bundle );
|
||||||
|
|
||||||
|
int[] bundleArr = new int[generatedLevels.size()];
|
||||||
|
for (int i = 0; i < generatedLevels.size(); i++){
|
||||||
|
bundleArr[i] = generatedLevels.get(i);
|
||||||
|
}
|
||||||
|
bundle.put( GENERATED_LEVELS, bundleArr);
|
||||||
|
|
||||||
Scroll.save( bundle );
|
Scroll.save( bundle );
|
||||||
Potion.save( bundle );
|
Potion.save( bundle );
|
||||||
Ring.save( bundle );
|
Ring.save( bundle );
|
||||||
@@ -713,6 +735,18 @@ public class Dungeon {
|
|||||||
Statistics.restoreFromBundle( bundle );
|
Statistics.restoreFromBundle( bundle );
|
||||||
Generator.restoreFromBundle( bundle );
|
Generator.restoreFromBundle( bundle );
|
||||||
|
|
||||||
|
generatedLevels.clear();
|
||||||
|
if (bundle.contains(GENERATED_LEVELS)){
|
||||||
|
for (int i : bundle.getIntArray(GENERATED_LEVELS)){
|
||||||
|
generatedLevels.add(i);
|
||||||
|
}
|
||||||
|
//pre-v2.1.1 saves
|
||||||
|
} else {
|
||||||
|
for (int i = 1; i <= Statistics.deepestFloor; i++){
|
||||||
|
generatedLevels.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
droppedItems = new SparseArray<>();
|
droppedItems = new SparseArray<>();
|
||||||
for (int i=1; i <= 26; i++) {
|
for (int i=1; i <= 26; i++) {
|
||||||
|
|
||||||
|
|||||||
@@ -1194,8 +1194,8 @@ public class Hero extends Char {
|
|||||||
|
|
||||||
Level.beforeTransition();
|
Level.beforeTransition();
|
||||||
InterlevelScene.curTransition = transition;
|
InterlevelScene.curTransition = transition;
|
||||||
//TODO probably want to make this more flexible when more types exist
|
if (transition.type == LevelTransition.Type.REGULAR_EXIT
|
||||||
if (transition.type == LevelTransition.Type.REGULAR_EXIT) {
|
|| transition.type == LevelTransition.Type.BRANCH_EXIT) {
|
||||||
InterlevelScene.mode = InterlevelScene.Mode.DESCEND;
|
InterlevelScene.mode = InterlevelScene.Mode.DESCEND;
|
||||||
} else {
|
} else {
|
||||||
InterlevelScene.mode = InterlevelScene.Mode.ASCEND;
|
InterlevelScene.mode = InterlevelScene.Mode.ASCEND;
|
||||||
|
|||||||
+13
-1
@@ -22,6 +22,7 @@
|
|||||||
package com.shatteredpixel.shatteredpixeldungeon.levels;
|
package com.shatteredpixel.shatteredpixeldungeon.levels;
|
||||||
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
|
||||||
@@ -66,7 +67,18 @@ public class DeadEndLevel extends Level {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int entrance = SIZE * width() + SIZE / 2 + 1;
|
int entrance = SIZE * width() + SIZE / 2 + 1;
|
||||||
transitions.add(new LevelTransition(this, entrance, LevelTransition.Type.REGULAR_ENTRANCE));
|
|
||||||
|
//different exit behaviour depending on main branch or side one
|
||||||
|
if (Dungeon.branch == 0) {
|
||||||
|
transitions.add(new LevelTransition(this, entrance, LevelTransition.Type.REGULAR_ENTRANCE));
|
||||||
|
} else {
|
||||||
|
transitions.add(new LevelTransition(this,
|
||||||
|
entrance,
|
||||||
|
LevelTransition.Type.BRANCH_ENTRANCE,
|
||||||
|
Dungeon.depth,
|
||||||
|
0,
|
||||||
|
LevelTransition.Type.BRANCH_EXIT));
|
||||||
|
}
|
||||||
map[entrance] = Terrain.ENTRANCE;
|
map[entrance] = Terrain.ENTRANCE;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -187,7 +187,8 @@ public abstract class Level implements Bundlable {
|
|||||||
|
|
||||||
Random.pushGenerator( Dungeon.seedCurDepth() );
|
Random.pushGenerator( Dungeon.seedCurDepth() );
|
||||||
|
|
||||||
if (!(Dungeon.bossLevel())) {
|
//TODO maybe just make this part of RegularLevel?
|
||||||
|
if (!Dungeon.bossLevel() && Dungeon.branch == 0) {
|
||||||
|
|
||||||
addItemToSpawn(Generator.random(Generator.Category.FOOD));
|
addItemToSpawn(Generator.random(Generator.Category.FOOD));
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -34,7 +34,9 @@ public class LevelTransition extends Rect implements Bundlable {
|
|||||||
public enum Type {
|
public enum Type {
|
||||||
SURFACE,
|
SURFACE,
|
||||||
REGULAR_ENTRANCE,
|
REGULAR_ENTRANCE,
|
||||||
REGULAR_EXIT;
|
REGULAR_EXIT,
|
||||||
|
BRANCH_ENTRANCE,
|
||||||
|
BRANCH_EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type type;
|
public Type type;
|
||||||
|
|||||||
+23
-13
@@ -384,11 +384,11 @@ public class InterlevelScene extends PixelScene {
|
|||||||
Level level;
|
Level level;
|
||||||
Dungeon.depth = curTransition.destDepth;
|
Dungeon.depth = curTransition.destDepth;
|
||||||
Dungeon.branch = curTransition.destBranch;
|
Dungeon.branch = curTransition.destBranch;
|
||||||
//TODO this is brittle atm, assumes we're always going down in depth 1 at a time
|
|
||||||
if (curTransition.destDepth > Statistics.deepestFloor) {
|
if (Dungeon.levelHasBeenGenerated(Dungeon.depth, Dungeon.branch)) {
|
||||||
level = Dungeon.newLevel();
|
|
||||||
} else {
|
|
||||||
level = Dungeon.loadLevel( GamesInProgress.curSlot );
|
level = Dungeon.loadLevel( GamesInProgress.curSlot );
|
||||||
|
} else {
|
||||||
|
level = Dungeon.newLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
LevelTransition destTransition = level.getTransition(curTransition.destType);
|
LevelTransition destTransition = level.getTransition(curTransition.destType);
|
||||||
@@ -408,22 +408,27 @@ public class InterlevelScene extends PixelScene {
|
|||||||
|
|
||||||
Level level;
|
Level level;
|
||||||
Dungeon.depth++;
|
Dungeon.depth++;
|
||||||
if (Dungeon.depth > Statistics.deepestFloor) {
|
if (Dungeon.levelHasBeenGenerated(Dungeon.depth, Dungeon.branch)) {
|
||||||
level = Dungeon.newLevel();
|
|
||||||
} else {
|
|
||||||
level = Dungeon.loadLevel( GamesInProgress.curSlot );
|
level = Dungeon.loadLevel( GamesInProgress.curSlot );
|
||||||
|
} else {
|
||||||
|
level = Dungeon.newLevel();
|
||||||
}
|
}
|
||||||
Dungeon.switchLevel( level, level.fallCell( fallIntoPit ));
|
Dungeon.switchLevel( level, level.fallCell( fallIntoPit ));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ascend() throws IOException {
|
private void ascend() throws IOException {
|
||||||
|
|
||||||
Mob.holdAllies( Dungeon.level );
|
Mob.holdAllies( Dungeon.level );
|
||||||
|
|
||||||
Dungeon.saveAll();
|
Dungeon.saveAll();
|
||||||
|
|
||||||
|
Level level;
|
||||||
Dungeon.depth = curTransition.destDepth;
|
Dungeon.depth = curTransition.destDepth;
|
||||||
Dungeon.branch = curTransition.destBranch;
|
Dungeon.branch = curTransition.destBranch;
|
||||||
Level level = Dungeon.loadLevel( GamesInProgress.curSlot );
|
|
||||||
|
if (Dungeon.levelHasBeenGenerated(Dungeon.depth, Dungeon.branch)) {
|
||||||
|
level = Dungeon.loadLevel( GamesInProgress.curSlot );
|
||||||
|
} else {
|
||||||
|
level = Dungeon.newLevel();
|
||||||
|
}
|
||||||
|
|
||||||
LevelTransition destTransition = level.getTransition(curTransition.destType);
|
LevelTransition destTransition = level.getTransition(curTransition.destType);
|
||||||
curTransition = null;
|
curTransition = null;
|
||||||
@@ -431,13 +436,18 @@ public class InterlevelScene extends PixelScene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void returnTo() throws IOException {
|
private void returnTo() throws IOException {
|
||||||
|
|
||||||
Mob.holdAllies( Dungeon.level );
|
Mob.holdAllies( Dungeon.level );
|
||||||
|
|
||||||
Dungeon.saveAll();
|
Dungeon.saveAll();
|
||||||
|
|
||||||
|
Level level;
|
||||||
Dungeon.depth = returnDepth;
|
Dungeon.depth = returnDepth;
|
||||||
Dungeon.branch = returnBranch;
|
Dungeon.branch = returnBranch;
|
||||||
Level level = Dungeon.loadLevel( GamesInProgress.curSlot );
|
if (Dungeon.levelHasBeenGenerated(Dungeon.depth, Dungeon.branch)) {
|
||||||
|
level = Dungeon.loadLevel( GamesInProgress.curSlot );
|
||||||
|
} else {
|
||||||
|
level = Dungeon.newLevel();
|
||||||
|
}
|
||||||
|
|
||||||
Dungeon.switchLevel( level, returnPos );
|
Dungeon.switchLevel( level, returnPos );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user