From bab229ec3d48cc1bddef1b94e58188770be37735 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 24 Apr 2020 23:53:54 -0400 Subject: [PATCH] v0.8.0a: improved logic for spreading water to tiles, fixes bugs --- .../actors/blobs/StormCloud.java | 13 +---- .../items/spells/AquaBlast.java | 9 +--- .../shatteredpixeldungeon/levels/Level.java | 35 ++++++++++++++ .../levels/NewCavesBossLevel.java | 48 ++++++++++++------- .../levels/NewHallsBossLevel.java | 2 +- 5 files changed, 69 insertions(+), 38 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/StormCloud.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/StormCloud.java index 16a96bb3f..3512bac5f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/StormCloud.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/StormCloud.java @@ -41,18 +41,7 @@ public class StormCloud extends Blob { for (int j = area.top; j < area.bottom; j++){ cell = i + j*Dungeon.level.width(); if (cur[cell] > 0) { - int terr = Dungeon.level.map[cell]; - if (terr == Terrain.EMPTY || terr == Terrain.GRASS || - terr == Terrain.EMBERS || terr == Terrain.EMPTY_SP || - terr == Terrain.HIGH_GRASS || terr == Terrain.FURROWED_GRASS - || terr == Terrain.EMPTY_DECO) { - Level.set(cell, Terrain.WATER); - GameScene.updateMap(cell); - } else if (terr == Terrain.SECRET_TRAP || terr == Terrain.TRAP || terr == Terrain.INACTIVE_TRAP) { - Level.set(cell, Terrain.WATER); - Dungeon.level.traps.remove(cell); - GameScene.updateMap(cell); - } + Dungeon.level.setCellToWater(true, cell); } } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/spells/AquaBlast.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/spells/AquaBlast.java index 6f7bc7d78..435932350 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/spells/AquaBlast.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/spells/AquaBlast.java @@ -51,14 +51,7 @@ public class AquaBlast extends TargetedSpell { for (int i : PathFinder.NEIGHBOURS9){ if (i == 0 || Random.Int(5) != 0){ - int terr = Dungeon.level.map[cell + i]; - if (terr == Terrain.EMPTY || terr == Terrain.GRASS || - terr == Terrain.EMBERS || terr == Terrain.EMPTY_SP || - terr == Terrain.HIGH_GRASS || terr == Terrain.FURROWED_GRASS || - terr == Terrain.EMPTY_DECO) { - Level.set(cell + i, Terrain.WATER); - GameScene.updateMap(cell + i); - } + Dungeon.level.setCellToWater(false, cell+i); } } 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 3fa8d479f..ab0c6fcb8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java @@ -822,6 +822,41 @@ public abstract class Level implements Bundlable { trap.reveal(); GameScene.updateMap( cell ); } + + public boolean setCellToWater( boolean includeTraps, int cell ){ + Point p = cellToPoint(cell); + + //if a custom tilemap is over that cell, don't put water there + for (CustomTilemap cust : customTiles){ + Point custPoint = new Point(p); + custPoint.x -= cust.tileX; + custPoint.y -= cust.tileY; + if (custPoint.x >= 0 && custPoint.y >= 0 + && custPoint.x < cust.tileW && custPoint.y < cust.tileH){ + if (cust.image(custPoint.x, custPoint.y) != null){ + return false; + } + } + } + + int terr = map[cell]; + if (terr == Terrain.EMPTY || terr == Terrain.GRASS || + terr == Terrain.EMBERS || terr == Terrain.EMPTY_SP || + terr == Terrain.HIGH_GRASS || terr == Terrain.FURROWED_GRASS + || terr == Terrain.EMPTY_DECO){ + set(cell, Terrain.WATER); + GameScene.updateMap(cell); + return true; + } else if (includeTraps && (terr == Terrain.SECRET_TRAP || + terr == Terrain.TRAP || terr == Terrain.INACTIVE_TRAP)){ + set(cell, Terrain.WATER); + Dungeon.level.traps.remove(cell); + GameScene.updateMap(cell); + return true; + } + + return false; + } public int fallCell( boolean fallIntoPit ) { int result; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/NewCavesBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/NewCavesBossLevel.java index bdff64279..e77cbe7f8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/NewCavesBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/NewCavesBossLevel.java @@ -192,6 +192,17 @@ public class NewCavesBossLevel extends Level { return cell; } + @Override + public boolean setCellToWater(boolean includeTraps, int cell) { + for (int i : pylonPositions){ + if (Dungeon.level.distance(cell, i) <= 1){ + return false; + } + } + + return super.setCellToWater(includeTraps, cell); + } + @Override public void occupyCell(Char ch) { super.occupyCell(ch); @@ -707,25 +718,28 @@ public class NewCavesBossLevel extends Level { @Override protected void evolve() { - int cell; - for (int i=area.top-1; i <= area.bottom; i++) { - for (int j = area.left-1; j <= area.right; j++) { - cell = j + i* Dungeon.level.width(); - if (Dungeon.level.insideMap(cell)) { - off[cell] = cur[cell]; - volume += off[cell]; - if (off[cell] > 0){ + for (int cell = 0; cell < Dungeon.level.length(); cell++) { + if (Dungeon.level.insideMap(cell)) { + off[cell] = cur[cell]; - Char ch = Actor.findChar(cell); - if (ch != null && !(ch instanceof NewDM300)) { - Sample.INSTANCE.play( Assets.SND_LIGHTNING ); - ch.damage( Random.NormalIntRange(6, 12), Electricity.class); - ch.sprite.flash(); + //instantly spreads to water cells + if (off[cell] == 0 && Dungeon.level.water[cell]){ + off[cell]++; + } - if (ch == Dungeon.hero && !ch.isAlive()) { - Dungeon.fail(NewDM300.class); - GLog.n( Messages.get(Electricity.class, "ondeath") ); - } + volume += off[cell]; + + if (off[cell] > 0){ + + Char ch = Actor.findChar(cell); + if (ch != null && !(ch instanceof NewDM300)) { + Sample.INSTANCE.play( Assets.SND_LIGHTNING ); + ch.damage( Random.NormalIntRange(6, 12), Electricity.class); + ch.sprite.flash(); + + if (ch == Dungeon.hero && !ch.isAlive()) { + Dungeon.fail(NewDM300.class); + GLog.n( Messages.get(Electricity.class, "ondeath") ); } } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/NewHallsBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/NewHallsBossLevel.java index 181b9e397..c415891f6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/NewHallsBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/NewHallsBossLevel.java @@ -283,7 +283,7 @@ public class NewHallsBossLevel extends Level { 24, 25, 26, 19, 19, 19, 28, 29, 30, 24, 25, 26, 19, 19, 19, 28, 29, 30, 24, 25, 26, 19, 19, 19, 28, 29, 30, - 24, 25, 34, 35, 35, 35, -1, 29, 30, + 24, 25, 34, 35, 35, 35, 34, 29, 30, 40, 41, 36, 36, 36, 36, 36, 40, 41, 48, 49, 36, 36, 36, 36, 36, 48, 49 };