From 5373b1388ddace7f799638525e5189fe658100ee Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 8 Aug 2024 14:19:36 -0400 Subject: [PATCH] v2.5.0: added checks for load into invalid cells in caves & city boss --- .../shatteredpixeldungeon/Dungeon.java | 7 +++---- .../levels/CavesBossLevel.java | 18 ++++++++++++++++-- .../levels/CityBossLevel.java | 9 +++++++++ .../shatteredpixeldungeon/levels/Level.java | 5 +++++ .../levels/MiningLevel.java | 5 +++++ 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index aeab6eede..2e2c7d57e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -464,10 +464,9 @@ public class Dungeon { if (t != null) pos = t.cell(); } - //Place hero at the entrance if they are out of the map (often used for pox = -1) - // or if they are in solid terrain (except in the mining level, where that happens normally) - if (pos < 0 || pos >= level.length() - || (!(level instanceof MiningLevel) && !level.passable[pos] && !level.avoid[pos])){ + //Place hero at the entrance if they are out of the map (often used for pos = -1) + // or if they are in invalid terrain terrain (except in the mining level, where that happens normally) + if (pos < 0 || pos >= level.length() || level.invalidHeroPos(pos)){ pos = level.getTransition(null).cell(); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java index a6ef78264..80185ffb2 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java @@ -256,6 +256,20 @@ public class CavesBossLevel extends Level { return super.setCellToWater(includeTraps, cell); } + @Override + public boolean invalidHeroPos(int tile) { + //hero cannot be above gate, or above arena, when gate is closed + if (map[gate.left + gate.top*width()] == Terrain.CUSTOM_DECO){ + Point p = cellToPoint(tile); + if (p.y < diggableArea.top){ + return true; + } else if (p.y < gate.bottom && p.x >= gate.left && p.x < gate.right){ + return true; + } + } + return super.invalidHeroPos(tile); + } + @Override public void occupyCell(Char ch) { //seal the level when the hero moves near to a pylon, the level isn't already sealed, and the gate hasn't been destroyed @@ -330,8 +344,8 @@ public class CavesBossLevel extends Level { blobs.get(PylonEnergy.class).fullyClear(); set( entrance(), Terrain.ENTRANCE ); - int i = 14 + 13*width(); - for (int j = 0; j < 5; j++){ + int i = gate.top*width(); + for (int j = gate.left; j < gate.right; j++){ set( i+j, Terrain.EMPTY ); if (Dungeon.level.heroFOV[i+j]){ CellEmitter.get(i+j).burst(BlastParticle.FACTORY, 10); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java index 1b5674b32..65a5d7838 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java @@ -293,6 +293,15 @@ public class CityBossLevel extends Level { } } + @Override + public boolean invalidHeroPos(int tile) { + //hero cannot be above top door if it is locked + if (map[topDoor] == Terrain.LOCKED_DOOR && tile <= topDoor){ + return true; + } + return super.invalidHeroPos(tile); + } + @Override public void occupyCell( Char ch ) { if (map[bottomDoor] != Terrain.LOCKED_DOOR && map[topDoor] == Terrain.LOCKED_DOOR diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java index be2274b1b..569d722a8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java @@ -1467,6 +1467,11 @@ public abstract class Level implements Bundlable { return (float)Math.sqrt(Math.pow(Math.abs( ax - bx ), 2) + Math.pow(Math.abs( ay - by ), 2)); } + //usually just if a cell is solid, but other cases exist too + public boolean invalidHeroPos( int tile ){ + return !passable[tile] && !avoid[tile]; + } + //returns true if the input is a valid tile within the level public boolean insideMap( int tile ){ //top and bottom row and beyond diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/MiningLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/MiningLevel.java index f3f0a2901..17514d98e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/MiningLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/MiningLevel.java @@ -333,6 +333,11 @@ public class MiningLevel extends CavesLevel { return wallVisuals; } + @Override + public boolean invalidHeroPos(int tile) { + return false; //solid tiles are fine for hero to be in here + } + public static class BorderTopDarken extends CustomTilemap { {