From 806217e20947172accab5120c721dc642982b067 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Wed, 17 Aug 2016 21:04:58 -0400 Subject: [PATCH] v0.4.2: added support for variable map sizes --- .../java/com/watabou/utils/PathFinder.java | 24 +- .../shatteredpixeldungeon/Dungeon.java | 32 +- .../shatteredpixeldungeon/DungeonTilemap.java | 15 +- .../shatteredpixeldungeon/actors/Char.java | 7 +- .../actors/blobs/Alchemy.java | 10 +- .../actors/blobs/Blob.java | 66 ++-- .../actors/blobs/ConfusionGas.java | 3 +- .../actors/blobs/Fire.java | 14 +- .../actors/blobs/Foliage.java | 4 +- .../actors/blobs/GooWarn.java | 8 +- .../actors/blobs/ParalyticGas.java | 3 +- .../actors/blobs/Regrowth.java | 2 +- .../actors/blobs/StenchGas.java | 3 +- .../actors/blobs/ToxicGas.java | 2 +- .../actors/blobs/VenomGas.java | 3 +- .../actors/blobs/WaterOfAwareness.java | 2 +- .../actors/blobs/Web.java | 8 +- .../actors/blobs/WellWater.java | 11 +- .../actors/buffs/Combo.java | 5 +- .../actors/hero/Hero.java | 36 +-- .../actors/mobs/Bee.java | 8 +- .../actors/mobs/DM300.java | 10 +- .../actors/mobs/GnollTrickster.java | 3 +- .../actors/mobs/Goo.java | 24 +- .../actors/mobs/Guard.java | 3 +- .../actors/mobs/King.java | 14 +- .../actors/mobs/Mimic.java | 3 +- .../actors/mobs/Mob.java | 4 +- .../actors/mobs/RotLasher.java | 3 +- .../actors/mobs/Scorpio.java | 2 +- .../actors/mobs/Shaman.java | 2 +- .../actors/mobs/Skeleton.java | 5 +- .../actors/mobs/Statue.java | 2 +- .../actors/mobs/Succubus.java | 6 +- .../actors/mobs/Swarm.java | 2 +- .../actors/mobs/Tengu.java | 10 +- .../actors/mobs/Thief.java | 2 +- .../actors/mobs/Warlock.java | 2 +- .../actors/mobs/Wraith.java | 3 +- .../actors/mobs/Yog.java | 15 +- .../actors/mobs/npcs/NPC.java | 3 +- .../actors/mobs/npcs/Wandmaker.java | 2 +- .../effects/BlobEmitter.java | 9 +- .../shatteredpixeldungeon/effects/Ripple.java | 5 +- .../effects/Surprise.java | 4 +- .../shatteredpixeldungeon/effects/Swap.java | 2 +- .../shatteredpixeldungeon/effects/Wound.java | 6 +- .../shatteredpixeldungeon/items/Bomb.java | 7 +- .../shatteredpixeldungeon/items/Honeypot.java | 3 +- .../items/armor/WarriorArmor.java | 6 +- .../items/armor/curses/AntiEntropy.java | 3 +- .../items/armor/curses/Corrosion.java | 3 +- .../items/armor/curses/Multiplicity.java | 5 +- .../items/armor/glyphs/Multiplicity.java | 5 +- .../items/artifacts/CapeOfThorns.java | 2 +- .../items/artifacts/DriedRose.java | 11 +- .../items/artifacts/EtherealChains.java | 4 +- .../items/artifacts/LloydsBeacon.java | 5 +- .../items/artifacts/TalismanOfForesight.java | 16 +- .../items/potions/PotionOfFrost.java | 2 +- .../items/potions/PotionOfLiquidFlame.java | 3 +- .../items/potions/PotionOfPurity.java | 2 +- .../items/quest/CeremonialCandle.java | 9 +- .../items/quest/CorpseDust.java | 2 +- .../items/quest/Pickaxe.java | 5 +- .../items/scrolls/ScrollOfMagicMapping.java | 2 +- .../items/scrolls/ScrollOfMirrorImage.java | 5 +- .../items/wands/CursedWand.java | 2 +- .../items/wands/WandOfBlastWave.java | 9 +- .../items/wands/WandOfFireblast.java | 17 +- .../items/wands/WandOfLightning.java | 38 ++- .../items/wands/WandOfPrismaticLight.java | 6 +- .../items/wands/WandOfRegrowth.java | 21 +- .../items/wands/WandOfVenom.java | 3 +- .../items/weapon/enchantments/Shocking.java | 5 +- .../items/weapon/missiles/MissileWeapon.java | 2 +- .../levels/CavesBossLevel.java | 44 +-- .../levels/CavesLevel.java | 30 +- .../levels/CityBossLevel.java | 33 +- .../levels/CityLevel.java | 8 +- .../levels/DeadEndLevel.java | 18 +- .../levels/HallsBossLevel.java | 34 +- .../levels/HallsLevel.java | 15 +- .../levels/LastLevel.java | 25 +- .../levels/LastShopLevel.java | 10 +- .../shatteredpixeldungeon/levels/Level.java | 300 +++++++++--------- .../shatteredpixeldungeon/levels/Patch.java | 15 +- .../levels/PrisonBossLevel.java | 21 +- .../levels/PrisonLevel.java | 26 +- .../levels/RegularLevel.java | 39 +-- .../shatteredpixeldungeon/levels/Room.java | 24 +- .../levels/SewerBossLevel.java | 21 +- .../levels/SewerLevel.java | 26 +- .../levels/painters/ArmoryPainter.java | 2 +- .../levels/painters/BlacksmithPainter.java | 8 +- .../levels/painters/BossExitPainter.java | 2 +- .../levels/painters/CryptPainter.java | 2 +- .../levels/painters/EntrancePainter.java | 2 +- .../levels/painters/ExitPainter.java | 2 +- .../levels/painters/GardenPainter.java | 12 +- .../levels/painters/LaboratoryPainter.java | 4 +- .../levels/painters/LibraryPainter.java | 6 +- .../levels/painters/MagicWellPainter.java | 2 +- .../levels/painters/MassGravePainter.java | 4 +- .../levels/painters/Painter.java | 4 +- .../levels/painters/PitPainter.java | 4 +- .../levels/painters/PoolPainter.java | 4 +- .../levels/painters/RatKingPainter.java | 16 +- .../levels/painters/RitualSitePainter.java | 2 +- .../levels/painters/RotGardenPainter.java | 9 +- .../levels/painters/ShopPainter.java | 11 +- .../levels/painters/StandardPainter.java | 10 +- .../levels/painters/StatuePainter.java | 2 +- .../levels/painters/StoragePainter.java | 2 +- .../levels/painters/TrapsPainter.java | 8 +- .../levels/painters/TreasuryPainter.java | 4 +- .../levels/painters/VaultPainter.java | 5 +- .../levels/traps/BlazingTrap.java | 17 +- .../levels/traps/DisarmingTrap.java | 5 +- .../levels/traps/DisintegrationTrap.java | 4 +- .../levels/traps/FlockTrap.java | 14 +- .../levels/traps/GrimTrap.java | 2 +- .../levels/traps/LightningTrap.java | 2 +- .../levels/traps/PitfallTrap.java | 4 +- .../levels/traps/RockfallTrap.java | 5 +- .../levels/traps/SummoningTrap.java | 5 +- .../mechanics/Ballistica.java | 5 +- .../mechanics/ShadowCaster.java | 10 +- .../shatteredpixeldungeon/plants/Icecap.java | 2 +- .../scenes/GameScene.java | 14 +- .../scenes/InterlevelScene.java | 4 +- .../sprites/BlacksmithSprite.java | 2 +- .../sprites/CharSprite.java | 13 +- .../sprites/GnollTricksterSprite.java | 3 +- .../sprites/ItemSprite.java | 4 +- .../sprites/PlantSprite.java | 5 +- .../sprites/ScorpioSprite.java | 3 +- .../sprites/TenguSprite.java | 3 +- .../sprites/TrapSprite.java | 5 +- .../ui/CustomTileVisual.java | 3 +- .../ui/QuickSlotButton.java | 11 +- .../windows/WndInfoCell.java | 4 +- 142 files changed, 821 insertions(+), 759 deletions(-) diff --git a/SPD-classes/src/main/java/com/watabou/utils/PathFinder.java b/SPD-classes/src/main/java/com/watabou/utils/PathFinder.java index 4474ae440..50e0e173c 100644 --- a/SPD-classes/src/main/java/com/watabou/utils/PathFinder.java +++ b/SPD-classes/src/main/java/com/watabou/utils/PathFinder.java @@ -34,20 +34,26 @@ public class PathFinder { private static int size = 0; private static int[] dir; + + //performance-light shortcuts for some common pathfinder cases + public static int[] NEIGHBOURS4; + public static int[] NEIGHBOURS8; + public static int[] NEIGHBOURS9; public static void setMapSize( int width, int height ) { int size = width * height; - - if (PathFinder.size != size) { - PathFinder.size = size; - distance = new int[size]; - goals = new boolean[size]; - queue = new int[size]; - - dir = new int[]{-1, +1, -width, +width, -width-1, -width+1, +width-1, +width+1}; - } + PathFinder.size = size; + distance = new int[size]; + goals = new boolean[size]; + queue = new int[size]; + + dir = new int[]{-1, +1, -width, +width, -width-1, -width+1, +width-1, +width+1}; + + NEIGHBOURS4 = new int[]{-width, +1, +width, -1}; + NEIGHBOURS8 = new int[]{-width, +1-width, +1, +1+width, +width, -1+width, -1, -1-width}; + NEIGHBOURS9 = new int[]{0, -width, +1-width, +1, +1+width, +width, -1+width, -1, -1-width}; } public static Path find( int from, int to, boolean[] passable ) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java index 5d1eac3d6..3b4bea439 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/Dungeon.java @@ -129,7 +129,7 @@ public class Dungeon { public static HashSet chapters; // Hero's field of view - public static boolean[] visible = new boolean[Level.LENGTH]; + public static boolean[] visible; public static SparseArray> droppedItems; @@ -143,8 +143,6 @@ public class Dungeon { Actor.clear(); Actor.resetNextID(); - PathFinder.setMapSize( Level.WIDTH, Level.HEIGHT ); - Scroll.initLabels(); Potion.initColors(); Ring.initGems(); @@ -203,8 +201,6 @@ public class Dungeon { } } - Arrays.fill( visible, false ); - Level level; switch (depth) { case 1: @@ -261,7 +257,8 @@ public class Dungeon { level = new DeadEndLevel(); Statistics.deepestFloor--; } - + + visible = new boolean[level.length()]; level.create(); Statistics.qualifiedForNoKilling = !bossLevel(); @@ -273,8 +270,6 @@ public class Dungeon { Actor.clear(); - Arrays.fill( visible, false ); - level.reset(); switchLevel( level, level.entrance ); } @@ -296,6 +291,9 @@ public class Dungeon { Dungeon.level = level; Actor.init(); + + PathFinder.setMapSize(level.width(), level.height()); + visible = new boolean[level.length()]; Actor respawner = level.respawner(); if (respawner != null) { @@ -531,10 +529,6 @@ public class Dungeon { Dungeon.level = null; Dungeon.depth = -1; - if (fullLoad) { - PathFinder.setMapSize( Level.WIDTH, Level.HEIGHT ); - } - Scroll.restore( bundle ); Potion.restore( bundle ); Ring.restore( bundle ); @@ -677,18 +671,17 @@ public class Dungeon { GameScene.afterObserve(); } - private static boolean[] passable = new boolean[Level.LENGTH]; - public static int findPath( Char ch, int from, int to, boolean pass[], boolean[] visible ) { - if (Level.adjacent( from, to )) { + if (level.adjacent( from, to )) { return Actor.findChar( to ) == null && (pass[to] || Level.avoid[to]) ? to : -1; } - + + boolean[] passable = new boolean[Dungeon.level.length()]; if (ch.flying || ch.buff( Amok.class ) != null) { BArray.or( pass, Level.avoid, passable ); } else { - System.arraycopy( pass, 0, passable, 0, Level.LENGTH ); + System.arraycopy( pass, 0, passable, 0, Dungeon.level.length() ); } for (Char c : Actor.chars()) { @@ -702,11 +695,12 @@ public class Dungeon { } public static int flee( Char ch, int cur, int from, boolean pass[], boolean[] visible ) { - + + boolean[] passable = new boolean[Dungeon.level.length()]; if (ch.flying) { BArray.or( pass, Level.avoid, passable ); } else { - System.arraycopy( pass, 0, passable, 0, Level.LENGTH ); + System.arraycopy( pass, 0, passable, 0, Dungeon.level.length() ); } for (Char c : Actor.chars()) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/DungeonTilemap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/DungeonTilemap.java index ea5e27bcf..41349c0f9 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/DungeonTilemap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/DungeonTilemap.java @@ -38,7 +38,7 @@ public class DungeonTilemap extends Tilemap { super( Dungeon.level.tilesTex(), new TextureFilm( Dungeon.level.tilesTex(), SIZE, SIZE ) ); - map( Dungeon.level.map, Level.WIDTH ); + map( Dungeon.level.map, Dungeon.level.width() ); instance = this; } @@ -48,7 +48,12 @@ public class DungeonTilemap extends Tilemap { offset( this.point().negate() ). invScale( SIZE ). floor(); - return p.x >= 0 && p.x < Level.WIDTH && p.y >= 0 && p.y < Level.HEIGHT ? p.x + p.y * Level.WIDTH : -1; + return p.x >= 0 + && p.x < Dungeon.level.width() + && p.y >= 0 + && p.y < Dungeon.level.height() ? + p.x + p.y * Dungeon.level.width() + : -1; } @Override @@ -75,13 +80,13 @@ public class DungeonTilemap extends Tilemap { } public static PointF tileToWorld( int pos ) { - return new PointF( pos % Level.WIDTH, pos / Level.WIDTH ).scale( SIZE ); + return new PointF( pos % Dungeon.level.width(), pos / Dungeon.level.width() ).scale( SIZE ); } public static PointF tileCenterToWorld( int pos ) { return new PointF( - (pos % Level.WIDTH + 0.5f) * SIZE, - (pos / Level.WIDTH + 0.5f) * SIZE ); + (pos % Dungeon.level.width() + 0.5f) * SIZE, + (pos / Dungeon.level.width() + 0.5f) * SIZE ); } public static Image tile( int index ) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java index 42ff725a4..ba6f3e573 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/Char.java @@ -49,6 +49,7 @@ import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundlable; import com.watabou.utils.Bundle; import com.watabou.utils.GameMath; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.HashSet; @@ -399,9 +400,9 @@ public abstract class Char extends Actor { public void move( int step ) { - if (Level.adjacent( step, pos ) && buff( Vertigo.class ) != null) { + if (Dungeon.level.adjacent( step, pos ) && buff( Vertigo.class ) != null) { sprite.interruptMotion(); - int newPos = pos + Level.NEIGHBOURS8[Random.Int( 8 )]; + int newPos = pos + PathFinder.NEIGHBOURS8[Random.Int( 8 )]; if (!(Level.passable[newPos] || Level.avoid[newPos]) || Actor.findChar( newPos ) != null) return; else { @@ -426,7 +427,7 @@ public abstract class Char extends Actor { } public int distance( Char other ) { - return Level.distance( pos, other.pos ); + return Dungeon.level.distance( pos, other.pos ); } public void onMotionComplete() { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Alchemy.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Alchemy.java index 25bccabae..21ea2e84e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Alchemy.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Alchemy.java @@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.BlobEmitter; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.items.Heap; import com.shatteredpixel.shatteredpixeldungeon.items.Item; +import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.watabou.utils.Bundle; public class Alchemy extends Blob { @@ -35,8 +36,8 @@ public class Alchemy extends Blob { @Override public void restoreFromBundle( Bundle bundle ) { super.restoreFromBundle( bundle ); - - for (int i=0; i < LENGTH; i++) { + + for (int i=0; i < cur.length; i++) { if (cur[i] > 0) { pos = i; break; @@ -54,7 +55,10 @@ public class Alchemy extends Blob { } @Override - public void seed( int cell, int amount ) { + public void seed( Level level, int cell, int amount ) { + if (cur == null) cur = new int[level.length()]; + if (off == null) off = new int[cur.length]; + cur[pos] = 0; pos = cell; volume = cur[pos] = amount; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Blob.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Blob.java index a5c46705d..51afa1c12 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Blob.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Blob.java @@ -33,13 +33,9 @@ import java.util.Arrays; public class Blob extends Actor { { - actPriority = 1; //take prioerity over mobs, but not the hero + actPriority = 1; //take priority over mobs, but not the hero } - public static final int WIDTH = Level.WIDTH; - public static final int HEIGHT = Level.HEIGHT; - public static final int LENGTH = Level.LENGTH; - public int volume = 0; public int[] cur; @@ -47,16 +43,9 @@ public class Blob extends Actor { public BlobEmitter emitter; - protected Blob() { - - cur = new int[LENGTH]; - off = new int[LENGTH]; - - volume = 0; - } - private static final String CUR = "cur"; private static final String START = "start"; + private static final String LENGTH = "length"; @Override public void storeInBundle( Bundle bundle ) { @@ -65,19 +54,20 @@ public class Blob extends Actor { if (volume > 0) { int start; - for (start=0; start < LENGTH; start++) { + for (start=0; start < Dungeon.level.length(); start++) { if (cur[start] > 0) { break; } } int end; - for (end=LENGTH-1; end > start; end--) { + for (end=Dungeon.level.length()-1; end > start; end--) { if (cur[end] > 0) { break; } } bundle.put( START, start ); + bundle.put( LENGTH, cur.length ); bundle.put( CUR, trim( start, end + 1 ) ); } @@ -94,6 +84,13 @@ public class Blob extends Actor { public void restoreFromBundle( Bundle bundle ) { super.restoreFromBundle( bundle ); + + if (bundle.contains(LENGTH)) { + cur = new int[bundle.getInt(LENGTH)]; + } else { + //compatability with pre-0.4.2 + cur = new int[1024]; + } int[] data = bundle.getIntArray( CUR ); if (data != null) { @@ -103,18 +100,6 @@ public class Blob extends Actor { volume += data[i]; } } - - if (Level.resizingNeeded) { - int[] cur = new int[Level.LENGTH]; - Arrays.fill( cur, 0 ); - - int loadedMapSize = Level.loadedMapSize; - for (int i=0; i < loadedMapSize; i++) { - System.arraycopy( this.cur, i * loadedMapSize, cur, i * Level.WIDTH, loadedMapSize ); - } - - this.cur = cur; - } } @Override @@ -144,10 +129,10 @@ public class Blob extends Actor { boolean[] notBlocking = BArray.not( Level.solid, null ); - for (int i=1; i < HEIGHT-1; i++) { + for (int i=1; i < Dungeon.level.height()-1; i++) { - int from = i * WIDTH + 1; - int to = from + WIDTH - 2; + int from = i * Dungeon.level.width() + 1; + int to = from + Dungeon.level.width() - 2; for (int pos=from; pos < to; pos++) { if (notBlocking[pos]) { @@ -163,12 +148,12 @@ public class Blob extends Actor { sum += cur[pos+1]; count++; } - if (notBlocking[pos-WIDTH]) { - sum += cur[pos-WIDTH]; + if (notBlocking[pos-Dungeon.level.width()]) { + sum += cur[pos-Dungeon.level.width()]; count++; } - if (notBlocking[pos+WIDTH]) { - sum += cur[pos+WIDTH]; + if (notBlocking[pos+Dungeon.level.width()]) { + sum += cur[pos+Dungeon.level.width()]; count++; } @@ -182,8 +167,11 @@ public class Blob extends Actor { } } } - - public void seed( int cell, int amount ) { + + public void seed( Level level, int cell, int amount ) { + if (cur == null) cur = new int[level.length()]; + if (off == null) off = new int[cur.length]; + cur[cell] += amount; volume += amount; } @@ -195,8 +183,8 @@ public class Blob extends Actor { public void fullyClear(){ volume = 0; - cur = new int[LENGTH]; - off = new int[LENGTH]; + cur = new int[Dungeon.level.length()]; + off = new int[Dungeon.level.length()]; } public String tileDesc() { @@ -213,7 +201,7 @@ public class Blob extends Actor { Dungeon.level.blobs.put( type, gas ); } - gas.seed( cell, amount ); + gas.seed( Dungeon.level, cell, amount ); return gas; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/ConfusionGas.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/ConfusionGas.java index 0b7ca4294..8e8a5f55f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/ConfusionGas.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/ConfusionGas.java @@ -20,6 +20,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.actors.blobs; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; @@ -35,7 +36,7 @@ public class ConfusionGas extends Blob { super.evolve(); Char ch; - for (int i=0; i < LENGTH; i++) { + for (int i = 0; i < Dungeon.level.length(); i++) { if (cur[i] > 0 && (ch = Actor.findChar( i )) != null) { if (!ch.immunities().contains(this.getClass())) Buff.prolong( ch, Vertigo.class, 2 ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Fire.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Fire.java index 7d0f7b27e..b182af4fd 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Fire.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Fire.java @@ -40,8 +40,8 @@ public class Fire extends Blob { boolean[] flamable = Level.flamable; - int from = WIDTH + 1; - int to = Level.LENGTH - WIDTH - 1; + int from = Dungeon.level.width() + 1; + int to = Dungeon.level.length() - Dungeon.level.width() - 1; boolean observe = false; @@ -68,7 +68,11 @@ public class Fire extends Blob { } else { - if (flamable[pos] && (cur[pos-1] > 0 || cur[pos+1] > 0 || cur[pos-WIDTH] > 0 || cur[pos+WIDTH] > 0)) { + if (flamable[pos] + && (cur[pos-1] > 0 + || cur[pos+1] > 0 + || cur[pos-Dungeon.level.width()] > 0 + || cur[pos+Dungeon.level.width()] > 0)) { fire = 4; burn( pos ); } else { @@ -103,7 +107,9 @@ public class Fire extends Blob { } } - public void seed( int cell, int amount ) { + public void seed( Level level, int cell, int amount ) { + if (cur == null) cur = new int[level.length()]; + if (off == null) off = new int[cur.length]; if (cur[cell] == 0) { volume += amount; cur[cell] = amount; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Foliage.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Foliage.java index e1d0193c0..92f1e1d6a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Foliage.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Foliage.java @@ -37,8 +37,8 @@ public class Foliage extends Blob { @Override protected void evolve() { - int from = WIDTH + 1; - int to = Level.LENGTH - WIDTH - 1; + int from = Dungeon.level.width() + 1; + int to = Dungeon.level.length() - Dungeon.level.width() - 1; int[] map = Dungeon.level.map; boolean regrowth = false; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/GooWarn.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/GooWarn.java index 5d7bcc660..28cf92520 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/GooWarn.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/GooWarn.java @@ -22,7 +22,9 @@ package com.shatteredpixel.shatteredpixeldungeon.actors.blobs; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.effects.BlobEmitter; +import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.sprites.GooSprite; @@ -39,7 +41,7 @@ public class GooWarn extends Blob { @Override protected void evolve() { - for (int i=0; i < LENGTH; i++) { + for (int i = 0; i < Dungeon.level.length(); i++) { int offv = cur[i] > 0 ? cur[i] - 1 : 0; off[i] = offv; @@ -52,7 +54,9 @@ public class GooWarn extends Blob { } - public void seed( int cell, int amount ) { + public void seed(Level level, int cell, int amount ) { + if (cur == null) cur = new int[level.length()]; + if (off == null) off = new int[cur.length]; int diff = amount - cur[cell]; if (diff > 0) { cur[cell] = amount; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/ParalyticGas.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/ParalyticGas.java index 89e3691bb..ede24b4ba 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/ParalyticGas.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/ParalyticGas.java @@ -20,6 +20,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.actors.blobs; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; @@ -35,7 +36,7 @@ public class ParalyticGas extends Blob { super.evolve(); Char ch; - for (int i=0; i < LENGTH; i++) { + for (int i = 0; i < Dungeon.level.length(); i++) { if (cur[i] > 0 && (ch = Actor.findChar( i )) != null) { if (!ch.immunities().contains(this.getClass())) Buff.prolong( ch, Paralysis.class, Paralysis.duration( ch ) ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Regrowth.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Regrowth.java index d6adcdce5..ade68b064 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Regrowth.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Regrowth.java @@ -39,7 +39,7 @@ public class Regrowth extends Blob { if (volume > 0) { - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < Dungeon.level.length(); i++) { if (off[i] > 0) { int c = Dungeon.level.map[i]; int c1 = c; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/StenchGas.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/StenchGas.java index 7b6572249..6aeafea34 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/StenchGas.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/StenchGas.java @@ -20,6 +20,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.actors.blobs; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; @@ -35,7 +36,7 @@ public class StenchGas extends Blob { super.evolve(); Char ch; - for (int i=0; i < LENGTH; i++) { + for (int i = 0; i < Dungeon.level.length(); i++) { if (cur[i] > 0 && (ch = Actor.findChar(i)) != null) { if (!ch.immunities().contains(this.getClass())) Buff.prolong( ch, Paralysis.class, Paralysis.duration( ch )/5 ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/ToxicGas.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/ToxicGas.java index 7f3f175d8..475b531a3 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/ToxicGas.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/ToxicGas.java @@ -40,7 +40,7 @@ public class ToxicGas extends Blob implements Hero.Doom { int levelDamage = 5 + Dungeon.depth * 5; Char ch; - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < Dungeon.level.length(); i++) { if (cur[i] > 0 && (ch = Actor.findChar( i )) != null) { int damage = (ch.HT + levelDamage) / 40; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/VenomGas.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/VenomGas.java index e62425916..865b2aa28 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/VenomGas.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/VenomGas.java @@ -20,6 +20,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.actors.blobs; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; @@ -41,7 +42,7 @@ public class VenomGas extends Blob { strength = 0; } else { Char ch; - for (int i = 0; i < LENGTH; i++) { + for (int i = 0; i < Dungeon.level.length(); i++) { if (cur[i] > 0 && (ch = Actor.findChar(i)) != null) { if (!ch.immunities().contains(this.getClass())) Buff.affect(ch, Venom.class).set(2f, strength); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WaterOfAwareness.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WaterOfAwareness.java index 854b3f302..112c75f73 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WaterOfAwareness.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WaterOfAwareness.java @@ -50,7 +50,7 @@ public class WaterOfAwareness extends WellWater { hero.belongings.observe(); - for (int i=0; i < Level.LENGTH; i++) { + for (int i=0; i < Dungeon.level.length(); i++) { int terr = Dungeon.level.map[i]; if ((Terrain.flags[terr] & Terrain.SECRET) != 0) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Web.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Web.java index b71f29435..4f77b7345 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Web.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/Web.java @@ -20,12 +20,14 @@ */ package com.shatteredpixel.shatteredpixeldungeon.actors.blobs; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Roots; import com.shatteredpixel.shatteredpixeldungeon.effects.BlobEmitter; import com.shatteredpixel.shatteredpixeldungeon.effects.particles.WebParticle; +import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; public class Web extends Blob { @@ -33,7 +35,7 @@ public class Web extends Blob { @Override protected void evolve() { - for (int i=0; i < LENGTH; i++) { + for (int i = 0; i < Dungeon.level.length(); i++) { int offv = cur[i] > 0 ? cur[i] - 1 : 0; off[i] = offv; @@ -57,7 +59,9 @@ public class Web extends Blob { emitter.pour( WebParticle.FACTORY, 0.4f ); } - public void seed( int cell, int amount ) { + public void seed(Level level, int cell, int amount ) { + if (cur == null) cur = new int[level.length()]; + if (off == null) off = new int[cur.length]; int diff = amount - cur[cell]; if (diff > 0) { cur[cell] = amount; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WellWater.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WellWater.java index 2ab76ef66..50db45632 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WellWater.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/blobs/WellWater.java @@ -30,6 +30,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.watabou.utils.Bundle; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; public class WellWater extends Blob { @@ -39,8 +40,8 @@ public class WellWater extends Blob { @Override public void restoreFromBundle( Bundle bundle ) { super.restoreFromBundle( bundle ); - - for (int i=0; i < LENGTH; i++) { + + for (int i=0; i < cur.length; i++) { if (cur[i] > 0) { pos = i; break; @@ -99,7 +100,7 @@ public class WellWater extends Blob { int newPlace; do { - newPlace = pos + Level.NEIGHBOURS8[Random.Int( 8 )]; + newPlace = pos + PathFinder.NEIGHBOURS8[Random.Int( 8 )]; } while (!Level.passable[newPlace] && !Level.avoid[newPlace]); Dungeon.level.drop( heap.pickUp(), newPlace ).sprite.drop( pos ); @@ -123,7 +124,9 @@ public class WellWater extends Blob { } @Override - public void seed( int cell, int amount ) { + public void seed( Level level, int cell, int amount ) { + if (cur == null) cur = new int[level.length()]; + if (off == null) off = new int[cur.length]; cur[pos] = 0; pos = cell; volume = cur[pos] = amount; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Combo.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Combo.java index 946994537..2aab3043a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Combo.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/buffs/Combo.java @@ -43,6 +43,7 @@ import com.watabou.noosa.Image; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundle; import com.watabou.utils.Callback; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; public class Combo extends Buff implements ActionIndicator.Action { @@ -231,8 +232,8 @@ public class Combo extends Buff implements ActionIndicator.Action { case CLOBBER: if (enemy.isAlive()){ if (!enemy.properties().contains(Char.Property.IMMOVABLE)){ - for (int i=0; i < Level.NEIGHBOURS8.length; i++) { - int ofs = Level.NEIGHBOURS8[i]; + for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) { + int ofs = PathFinder.NEIGHBOURS8[i]; if (enemy.pos - target.pos == ofs) { int newPos = enemy.pos + ofs; if ((Level.passable[newPos] || Level.avoid[newPos]) && Actor.findChar( newPos ) == null) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index 14b65dc23..1d06b6c04 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -258,7 +258,7 @@ public class Hero extends Char { @Override public int attackSkill( Char target ) { float accuracy = 1; - if (rangedWeapon != null && Level.distance( pos, target.pos ) == 1) { + if (rangedWeapon != null && Dungeon.level.distance( pos, target.pos ) == 1) { accuracy *= 0.5f; } @@ -391,12 +391,12 @@ public class Hero extends Char { return false; //can always attack adjacent enemies - if (Level.adjacent(pos, enemy.pos)) + if (Dungeon.level.adjacent(pos, enemy.pos)) return true; KindOfWeapon wep = Dungeon.hero.belongings.weapon; - if (wep != null && Level.distance( pos, enemy.pos ) <= wep.reachFactor(this)){ + if (wep != null && Dungeon.level.distance( pos, enemy.pos ) <= wep.reachFactor(this)){ boolean[] passable = BArray.not(Level.solid, null); for (Mob m : Dungeon.level.mobs) @@ -575,7 +575,7 @@ public class Hero extends Char { NPC npc = action.npc; - if (Level.adjacent( pos, npc.pos )) { + if (Dungeon.level.adjacent( pos, npc.pos )) { ready(); sprite.turnTo( pos, npc.pos ); @@ -598,7 +598,7 @@ public class Hero extends Char { private boolean actBuy( HeroAction.Buy action ) { int dst = action.dst; - if (pos == dst || Level.adjacent( pos, dst )) { + if (pos == dst || Dungeon.level.adjacent( pos, dst )) { ready(); @@ -690,7 +690,7 @@ public class Hero extends Char { private boolean actOpenChest( HeroAction.OpenChest action ) { int dst = action.dst; - if (Level.adjacent( pos, dst ) || pos == dst) { + if (Dungeon.level.adjacent( pos, dst ) || pos == dst) { Heap heap = Dungeon.level.heaps.get( dst ); if (heap != null && (heap.type != Type.HEAP && heap.type != Type.FOR_SALE)) { @@ -737,7 +737,7 @@ public class Hero extends Char { private boolean actUnlock( HeroAction.Unlock action ) { int doorCell = action.dst; - if (Level.adjacent( pos, doorCell )) { + if (Dungeon.level.adjacent( pos, doorCell )) { boolean hasKey = false; int door = Dungeon.level.map[doorCell]; @@ -1015,7 +1015,7 @@ public class Hero extends Char { int step = -1; - if (Level.adjacent( pos, target )) { + if (Dungeon.level.adjacent( pos, target )) { if (Actor.findChar( target ) == null) { if (Level.pit[target] && !flying && !Level.solid[target]) { @@ -1034,7 +1034,7 @@ public class Hero extends Char { } else { - int len = Level.LENGTH; + int len = Dungeon.level.length(); boolean[] p = Level.passable; boolean[] v = Dungeon.level.visited; boolean[] m = Dungeon.level.mapped; @@ -1281,7 +1281,7 @@ public class Hero extends Char { public static void reallyDie( Object cause ) { - int length = Level.LENGTH; + int length = Dungeon.level.length(); int[] map = Dungeon.level.map; boolean[] visited = Dungeon.level.visited; boolean[] discoverable = Level.discoverable; @@ -1308,7 +1308,7 @@ public class Hero extends Char { int pos = Dungeon.hero.pos; ArrayList passable = new ArrayList(); - for (Integer ofs : Level.NEIGHBOURS8) { + for (Integer ofs : PathFinder.NEIGHBOURS8) { int cell = pos + ofs; if ((Level.passable[cell] || Level.avoid[cell]) && Dungeon.level.heaps.get( cell ) == null) { passable.add( cell ); @@ -1440,23 +1440,23 @@ public class Hero extends Char { distance = 1; } - int cx = pos % Level.WIDTH; - int cy = pos / Level.WIDTH; + int cx = pos % Dungeon.level.width(); + int cy = pos / Dungeon.level.width(); int ax = cx - distance; if (ax < 0) { ax = 0; } int bx = cx + distance; - if (bx >= Level.WIDTH) { - bx = Level.WIDTH - 1; + if (bx >= Dungeon.level.width()) { + bx = Dungeon.level.width() - 1; } int ay = cy - distance; if (ay < 0) { ay = 0; } int by = cy + distance; - if (by >= Level.HEIGHT) { - by = Level.HEIGHT - 1; + if (by >= Dungeon.level.height()) { + by = Dungeon.level.height() - 1; } TalismanOfForesight.Foresight foresight = buff( TalismanOfForesight.Foresight.class ); @@ -1467,7 +1467,7 @@ public class Hero extends Char { } for (int y = ay; y <= by; y++) { - for (int x = ax, p = ax + y * Level.WIDTH; x <= bx; x++, p++) { + for (int x = ax, p = ax + y * Dungeon.level.width(); x <= bx; x++, p++) { if (Dungeon.visible[p]) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Bee.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Bee.java index 0401223f4..5aa76bd3c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Bee.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Bee.java @@ -121,18 +121,18 @@ public class Bee extends Mob { //if already targeting something, and that thing is still alive and near the pot, keeping targeting it. if (enemy != null && enemy.isAlive() && Dungeon.level.mobs.contains(enemy) && Level.fieldOfView[enemy.pos] && enemy.invisible == 0 - && Level.distance(enemy.pos, potPos) <= 3) + && Dungeon.level.distance(enemy.pos, potPos) <= 3) return enemy; //find all mobs near the pot HashSet enemies = new HashSet<>(); for (Mob mob : Dungeon.level.mobs) - if (!(mob instanceof Bee) && Level.distance(mob.pos, potPos) <= 3 && (mob.hostile || mob.ally)) + if (!(mob instanceof Bee) && Dungeon.level.distance(mob.pos, potPos) <= 3 && (mob.hostile || mob.ally)) enemies.add(mob); //pick one, if there are none, check if the hero is near the pot, go for them, otherwise go for nothing. if (enemies.size() > 0) return Random.element(enemies); - else return (Level.distance(Dungeon.hero.pos, potPos) <= 3) ? Dungeon.hero : null ; + else return (Dungeon.level.distance(Dungeon.hero.pos, potPos) <= 3) ? Dungeon.hero : null ; } } @@ -140,7 +140,7 @@ public class Bee extends Mob { protected boolean getCloser(int target) { if (enemy != null && Actor.findById(potHolder) == enemy) { target = enemy.pos; - } else if (potPos != -1 && (state == WANDERING || Level.distance(target, potPos) > 3)) + } else if (potPos != -1 && (state == WANDERING || Dungeon.level.distance(target, potPos) > 3)) this.target = target = potPos; return super.getCloser( target ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/DM300.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/DM300.java index 600b02111..85bb1bbc7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/DM300.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/DM300.java @@ -106,11 +106,11 @@ public class DM300 extends Mob { } int[] cells = { - step-1, step+1, step-Level.WIDTH, step+Level.WIDTH, - step-1-Level.WIDTH, - step-1+Level.WIDTH, - step+1-Level.WIDTH, - step+1+Level.WIDTH + step-1, step+1, step-Dungeon.level.width(), step+Dungeon.level.width(), + step-1-Dungeon.level.width(), + step-1+Dungeon.level.width(), + step+1-Dungeon.level.width(), + step+1+Dungeon.level.width() }; int cell = cells[Random.Int( cells.length )]; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/GnollTrickster.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/GnollTrickster.java index ff93ad2d8..8e168db6b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/GnollTrickster.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/GnollTrickster.java @@ -20,6 +20,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.actors.mobs; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Fire; @@ -64,7 +65,7 @@ public class GnollTrickster extends Gnoll { @Override protected boolean canAttack( Char enemy ) { Ballistica attack = new Ballistica( pos, enemy.pos, Ballistica.PROJECTILE); - return !Level.adjacent(pos, enemy.pos) && attack.collisionPos == enemy.pos; + return !Dungeon.level.adjacent(pos, enemy.pos) && attack.collisionPos == enemy.pos; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Goo.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Goo.java index cd7ce9b7b..33e5e0bfd 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Goo.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Goo.java @@ -43,10 +43,12 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.GooSprite; import com.shatteredpixel.shatteredpixeldungeon.ui.BossHealthBar; +import com.shatteredpixel.shatteredpixeldungeon.utils.BArray; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.watabou.noosa.Camera; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundle; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.HashSet; @@ -74,10 +76,10 @@ public class Goo extends Mob { int max = (HP*2 <= HT) ? 15 : 10; if (pumpedUp > 0) { pumpedUp = 0; - for (int i = 0; i < Level.NEIGHBOURS9DIST2.length; i++) { - int j = pos + Level.NEIGHBOURS9DIST2[i]; - if (Level.insideMap(j) && Level.passable[j]) - CellEmitter.get(j).burst(ElmoParticle.FACTORY, 10); + PathFinder.buildDistanceMap( pos, BArray.not( Level.solid, null ), 2 ); + for (int i = 0; i < PathFinder.distance.length; i++) { + if (PathFinder.distance[i] < Integer.MAX_VALUE) + CellEmitter.get(i).burst(ElmoParticle.FACTORY, 10); } Sample.INSTANCE.play( Assets.SND_BURNING ); return Random.NormalIntRange( min*3, max*3 ); @@ -142,10 +144,10 @@ public class Goo extends Mob { protected boolean doAttack( Char enemy ) { if (pumpedUp == 1) { ((GooSprite)sprite).pumpUp(); - for (int i = 0; i < Level.NEIGHBOURS9DIST2.length; i++) { - int j = pos + Level.NEIGHBOURS9DIST2[i]; - if (Level.insideMap(j) && Level.passable[j]) - GameScene.add(Blob.seed(j, 2, GooWarn.class)); + PathFinder.buildDistanceMap( pos, BArray.not( Level.solid, null ), 2 ); + for (int i = 0; i < PathFinder.distance.length; i++) { + if (PathFinder.distance[i] < Integer.MAX_VALUE) + GameScene.add(Blob.seed(i, 2, GooWarn.class)); } pumpedUp++; @@ -176,9 +178,9 @@ public class Goo extends Mob { ((GooSprite)sprite).pumpUp(); - for (int i=0; i < Level.NEIGHBOURS9.length; i++) { - int j = pos + Level.NEIGHBOURS9[i]; - if (Level.passable[j]) { + for (int i=0; i < PathFinder.NEIGHBOURS9.length; i++) { + int j = pos + PathFinder.NEIGHBOURS9[i]; + if (!Level.solid[j]) { GameScene.add(Blob.seed(j, 2, GooWarn.class)); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Guard.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Guard.java index 9ea19b5a5..4cadcb25f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Guard.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Guard.java @@ -72,7 +72,8 @@ public class Guard extends Mob { enemy != null && enemy.invisible == 0 && Level.fieldOfView[enemy.pos] && - Level.distance( pos, enemy.pos ) < 5 && !Level.adjacent( pos, enemy.pos ) && + Dungeon.level.distance( pos, enemy.pos ) < 5 && + !Dungeon.level.adjacent( pos, enemy.pos ) && Random.Int(3) == 0 && chain(enemy.pos)) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/King.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/King.java index ea93e9b53..8da821b6e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/King.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/King.java @@ -105,20 +105,20 @@ public class King extends Mob { @Override protected boolean getCloser( int target ) { return canTryToSummon() ? - super.getCloser( CityBossLevel.pedestal( nextPedestal ) ) : + super.getCloser( ((CityBossLevel)Dungeon.level).pedestal( nextPedestal ) ) : super.getCloser( target ); } @Override protected boolean canAttack( Char enemy ) { return canTryToSummon() ? - pos == CityBossLevel.pedestal( nextPedestal ) : - Level.adjacent( pos, enemy.pos ); + pos == ((CityBossLevel)Dungeon.level).pedestal( nextPedestal ) : + Dungeon.level.adjacent( pos, enemy.pos ); } private boolean canTryToSummon() { if (Undead.count < maxArmySize()) { - Char ch = Actor.findChar( CityBossLevel.pedestal( nextPedestal ) ); + Char ch = Actor.findChar( ((CityBossLevel)Dungeon.level).pedestal( nextPedestal ) ); return ch == this || ch == null; } else { return false; @@ -127,11 +127,11 @@ public class King extends Mob { @Override public boolean attack( Char enemy ) { - if (canTryToSummon() && pos == CityBossLevel.pedestal( nextPedestal )) { + if (canTryToSummon() && pos == ((CityBossLevel)Dungeon.level).pedestal( nextPedestal )) { summon(); return true; } else { - if (Actor.findChar( CityBossLevel.pedestal( nextPedestal ) ) == enemy) { + if (Actor.findChar( ((CityBossLevel)Dungeon.level).pedestal( nextPedestal ) ) == enemy) { nextPedestal = !nextPedestal; } return super.attack(enemy); @@ -199,7 +199,7 @@ public class King extends Mob { undeadLabel: for (int i=0; i < undeadsToSummon; i++) { do { - for (int j=0; j < Level.LENGTH; j++) { + for (int j=0; j < Dungeon.level.length(); j++) { if (PathFinder.distance[j] == dist) { Undead undead = new Undead(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mimic.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mimic.java index acf1317cb..ce0ab7618 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mimic.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mimic.java @@ -36,6 +36,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.MimicSprite; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundle; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.ArrayList; @@ -115,7 +116,7 @@ public class Mimic extends Mob { Char ch = Actor.findChar( pos ); if (ch != null) { ArrayList candidates = new ArrayList<>(); - for (int n : Level.NEIGHBOURS8) { + for (int n : PathFinder.NEIGHBOURS8) { int cell = pos + n; if ((Level.passable[cell] || Level.avoid[cell]) && Actor.findChar( cell ) == null) { candidates.add( cell ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java index 088df1439..666cd3baf 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java @@ -285,7 +285,7 @@ public abstract class Mob extends Char { } protected boolean canAttack( Char enemy ) { - return Level.adjacent( pos, enemy.pos ); + return Dungeon.level.adjacent( pos, enemy.pos ); } protected boolean getCloser( int target ) { @@ -662,7 +662,7 @@ public abstract class Mob extends Char { public boolean act( boolean enemyInFOV, boolean justAlerted ) { enemySeen = enemyInFOV; //loses target when 0-dist rolls a 6 or greater. - if (enemy == null || !enemyInFOV && 1 + Random.Int(Level.distance(pos, target)) >= 6){ + if (enemy == null || !enemyInFOV && 1 + Random.Int(Dungeon.level.distance(pos, target)) >= 6){ target = -1; } else { target = enemy.pos; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/RotLasher.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/RotLasher.java index aa67429f3..4813b84ab 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/RotLasher.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/RotLasher.java @@ -20,6 +20,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.actors.mobs; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.ToxicGas; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; @@ -52,7 +53,7 @@ public class RotLasher extends Mob { @Override protected boolean act() { - if (enemy == null || !Level.adjacent(pos, enemy.pos)) { + if (enemy == null || !Dungeon.level.adjacent(pos, enemy.pos)) { HP = Math.min(HT, HP + 3); } return super.act(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Scorpio.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Scorpio.java index c4489cd1b..e0dbb8c97 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Scorpio.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Scorpio.java @@ -73,7 +73,7 @@ public class Scorpio extends Mob { @Override protected boolean canAttack( Char enemy ) { Ballistica attack = new Ballistica( pos, enemy.pos, Ballistica.PROJECTILE); - return !Level.adjacent( pos, enemy.pos ) && attack.collisionPos == enemy.pos; + return !Dungeon.level.adjacent( pos, enemy.pos ) && attack.collisionPos == enemy.pos; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Shaman.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Shaman.java index 9891d27c6..cf78a30b1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Shaman.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Shaman.java @@ -77,7 +77,7 @@ public class Shaman extends Mob implements Callback { @Override protected boolean doAttack( Char enemy ) { - if (Level.distance( pos, enemy.pos ) <= 1) { + if (Dungeon.level.distance( pos, enemy.pos ) <= 1) { return super.doAttack( enemy ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Skeleton.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Skeleton.java index 4a69f272b..182c37941 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Skeleton.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Skeleton.java @@ -32,6 +32,7 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.sprites.SkeletonSprite; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.watabou.noosa.audio.Sample; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.HashSet; @@ -66,8 +67,8 @@ public class Skeleton extends Mob { super.die( cause ); boolean heroKilled = false; - for (int i=0; i < Level.NEIGHBOURS8.length; i++) { - Char ch = findChar( pos + Level.NEIGHBOURS8[i] ); + for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) { + Char ch = findChar( pos + PathFinder.NEIGHBOURS8[i] ); if (ch != null && ch.isAlive()) { int damage = Math.max( 0, damageRoll() - (ch.drRoll() / 2) ); ch.damage( damage, this ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Statue.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Statue.java index d2a274b43..c0770e42a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Statue.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Statue.java @@ -103,7 +103,7 @@ public class Statue extends Mob { @Override protected boolean canAttack(Char enemy) { - return Level.distance( pos, enemy.pos ) <= weapon.RCH; + return Dungeon.level.distance( pos, enemy.pos ) <= weapon.RCH; } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Succubus.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Succubus.java index bd94a4386..6a096c974 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Succubus.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Succubus.java @@ -21,6 +21,7 @@ package com.shatteredpixel.shatteredpixeldungeon.actors.mobs; import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; @@ -35,6 +36,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica; import com.shatteredpixel.shatteredpixeldungeon.sprites.SuccubusSprite; import com.watabou.noosa.audio.Sample; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.ArrayList; @@ -81,7 +83,7 @@ public class Succubus extends Mob { @Override protected boolean getCloser( int target ) { - if (Level.fieldOfView[target] && Level.distance( pos, target ) > 2 && delay <= 0) { + if (Level.fieldOfView[target] && Dungeon.level.distance( pos, target ) > 2 && delay <= 0) { blink( target ); spend( -1 / speed() ); @@ -106,7 +108,7 @@ public class Succubus extends Mob { if (Level.avoid[ cell ]){ ArrayList candidates = new ArrayList<>(); - for (int n : Level.NEIGHBOURS8) { + for (int n : PathFinder.NEIGHBOURS8) { cell = route.collisionPos + n; if (Level.passable[cell] && Actor.findChar( cell ) == null) { candidates.add( cell ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Swarm.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Swarm.java index ee8205395..51786acbb 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Swarm.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Swarm.java @@ -88,7 +88,7 @@ public class Swarm extends Mob { ArrayList candidates = new ArrayList<>(); boolean[] passable = Level.passable; - int[] neighbours = {pos + 1, pos - 1, pos + Level.WIDTH, pos - Level.WIDTH}; + int[] neighbours = {pos + 1, pos - 1, pos + Dungeon.level.width(), pos - Dungeon.level.width()}; for (int n : neighbours) { if (passable[n] && Actor.findChar( n ) == null) { candidates.add( n ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Tengu.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Tengu.java index a23867fd4..212c71d0f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Tengu.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Tengu.java @@ -166,7 +166,7 @@ public class Tengu extends Mob { for (int i=0; i < 4; i++) { int trapPos; do { - trapPos = Random.Int( Level.LENGTH ); + trapPos = Random.Int( Dungeon.level.length() ); } while (!Level.fieldOfView[trapPos] || Level.solid[trapPos]); if (Dungeon.level.map[trapPos] == Terrain.INACTIVE_TRAP) { @@ -182,20 +182,20 @@ public class Tengu extends Mob { //if we're in phase 1, want to warp around within the room if (HP > HT/2) { do { - newPos = Random.Int(Level.LENGTH); + newPos = Random.Int(Dungeon.level.length()); } while ( !(Dungeon.level.map[newPos] == Terrain.INACTIVE_TRAP || Dungeon.level.map[newPos] == Terrain.TRAP)|| Level.solid[newPos] || - Level.adjacent(newPos, enemy.pos) || + Dungeon.level.adjacent(newPos, enemy.pos) || Actor.findChar(newPos) != null); //otherwise go wherever, as long as it's a little bit away } else { do { - newPos = Random.Int(Level.LENGTH); + newPos = Random.Int(Dungeon.level.length()); } while ( Level.solid[newPos] || - Level.distance(newPos, enemy.pos) < 8 || + Dungeon.level.distance(newPos, enemy.pos) < 8 || Actor.findChar(newPos) != null); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Thief.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Thief.java index 37fa52da8..8945e4891 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Thief.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Thief.java @@ -191,7 +191,7 @@ public class Thief extends Mob { if (count-- <= 0) { break; } - } while (newPos == -1 || Dungeon.visible[newPos] || Level.distance(newPos, pos) < (count/3)); + } while (newPos == -1 || Dungeon.visible[newPos] || Dungeon.level.distance(newPos, pos) < (count/3)); if (newPos != -1) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Warlock.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Warlock.java index ff84eb1d4..bc1a87b65 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Warlock.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Warlock.java @@ -80,7 +80,7 @@ public class Warlock extends Mob implements Callback { protected boolean doAttack( Char enemy ) { - if (Level.adjacent( pos, enemy.pos )) { + if (Dungeon.level.adjacent( pos, enemy.pos )) { return super.doAttack( enemy ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Wraith.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Wraith.java index b47f761cb..3b02727a4 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Wraith.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Wraith.java @@ -31,6 +31,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.WraithSprite; import com.watabou.noosa.tweeners.AlphaTweener; import com.watabou.utils.Bundle; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.HashSet; @@ -90,7 +91,7 @@ public class Wraith extends Mob { } public static void spawnAround( int pos ) { - for (int n : Level.NEIGHBOURS4) { + for (int n : PathFinder.NEIGHBOURS4) { int cell = pos + n; if (Level.passable[cell] && Actor.findChar( cell ) == null) { spawnAt( cell ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Yog.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Yog.java index aaf5eac85..6a6df7732 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Yog.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Yog.java @@ -53,6 +53,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.YogSprite; import com.shatteredpixel.shatteredpixeldungeon.ui.BossHealthBar; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.watabou.utils.Bundle; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.ArrayList; @@ -83,8 +84,8 @@ public class Yog extends Mob { BurningFist fist2 = new BurningFist(); do { - fist1.pos = pos + Level.NEIGHBOURS8[Random.Int( 8 )]; - fist2.pos = pos + Level.NEIGHBOURS8[Random.Int( 8 )]; + fist1.pos = pos + PathFinder.NEIGHBOURS8[Random.Int( 8 )]; + fist2.pos = pos + PathFinder.NEIGHBOURS8[Random.Int( 8 )]; } while (!Level.passable[fist1.pos] || !Level.passable[fist2.pos] || fist1.pos == fist2.pos); GameScene.add( fist1 ); @@ -128,8 +129,8 @@ public class Yog extends Mob { ArrayList spawnPoints = new ArrayList<>(); - for (int i=0; i < Level.NEIGHBOURS8.length; i++) { - int p = pos + Level.NEIGHBOURS8[i]; + for (int i=0; i < PathFinder.NEIGHBOURS8.length; i++) { + int p = pos + PathFinder.NEIGHBOURS8[i]; if (Actor.findChar( p ) == null && (Level.passable[p] || Level.avoid[p])) { spawnPoints.add( p ); } @@ -332,7 +333,7 @@ public class Yog extends Mob { @Override public boolean attack( Char enemy ) { - if (!Level.adjacent( pos, enemy.pos )) { + if (!Dungeon.level.adjacent( pos, enemy.pos )) { spend( attackDelay() ); if (hit( this, enemy, true )) { @@ -362,8 +363,8 @@ public class Yog extends Mob { @Override public boolean act() { - for (int i=0; i < Level.NEIGHBOURS9.length; i++) { - GameScene.add( Blob.seed( pos + Level.NEIGHBOURS9[i], 2, Fire.class ) ); + for (int i=0; i < PathFinder.NEIGHBOURS9.length; i++) { + GameScene.add( Blob.seed( pos + PathFinder.NEIGHBOURS9[i], 2, Fire.class ) ); } return super.act(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/NPC.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/NPC.java index fb67b3bc3..d9f1b29c4 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/NPC.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/NPC.java @@ -24,6 +24,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.items.Heap; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; public abstract class NPC extends Mob { @@ -41,7 +42,7 @@ public abstract class NPC extends Mob { if (heap != null) { int n; do { - n = pos + Level.NEIGHBOURS8[Random.Int( 8 )]; + n = pos + PathFinder.NEIGHBOURS8[Random.Int( 8 )]; } while (!Level.passable[n] && !Level.avoid[n]); Dungeon.level.drop( heap.pickUp(), n ).sprite.drop( pos ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Wandmaker.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Wandmaker.java index 61a86ab6a..ac1e37678 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Wandmaker.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/npcs/Wandmaker.java @@ -259,7 +259,7 @@ public class Wandmaker extends NPC { if (setRoom( rooms )){ Wandmaker npc = new Wandmaker(); do { - npc.pos = room.random(); + npc.pos = Dungeon.level.pointToCell(room.random()); } while (level.map[npc.pos] == Terrain.ENTRANCE || level.map[npc.pos] == Terrain.SIGN); level.mobs.add( npc ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/BlobEmitter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/BlobEmitter.java index 352f4f115..7cdb376ce 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/BlobEmitter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/BlobEmitter.java @@ -27,9 +27,6 @@ import com.watabou.noosa.particles.Emitter; import com.watabou.utils.Random; public class BlobEmitter extends Emitter { - - private static final int WIDTH = Blob.WIDTH; - private static final int LENGTH = Blob.LENGTH; private Blob blob; @@ -51,10 +48,10 @@ public class BlobEmitter extends Emitter { int[] map = blob.cur; float size = DungeonTilemap.SIZE; - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < Dungeon.level.length(); i++) { if (map[i] > 0 && Dungeon.visible[i]) { - float x = ((i % WIDTH) + Random.Float()) * size; - float y = ((i / WIDTH) + Random.Float()) * size; + float x = ((i % Dungeon.level.width()) + Random.Float()) * size; + float y = ((i / Dungeon.level.width()) + Random.Float()) * size; factory.emit( this, index, x, y ); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Ripple.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Ripple.java index 0158f0637..a77107917 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Ripple.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Ripple.java @@ -20,6 +20,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.effects; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.DungeonTilemap; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.watabou.noosa.Game; @@ -38,8 +39,8 @@ public class Ripple extends Image { public void reset( int p ) { revive(); - x = (p % Level.WIDTH) * DungeonTilemap.SIZE; - y = (p / Level.WIDTH) * DungeonTilemap.SIZE; + x = (p % Dungeon.level.width()) * DungeonTilemap.SIZE; + y = (p / Dungeon.level.width()) * DungeonTilemap.SIZE; origin.set( width / 2, height / 2 ); scale.set( 0 ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Surprise.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Surprise.java index 61464b0f8..62922158d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Surprise.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Surprise.java @@ -42,8 +42,8 @@ public class Surprise extends Image { public void reset(int p) { revive(); - x = (p % Level.WIDTH) * DungeonTilemap.SIZE + (DungeonTilemap.SIZE - width) / 2; - y = (p / Level.WIDTH) * DungeonTilemap.SIZE + (DungeonTilemap.SIZE - height) / 2; + x = (p % Dungeon.level.width()) * DungeonTilemap.SIZE + (DungeonTilemap.SIZE - width) / 2; + y = (p / Dungeon.level.width()) * DungeonTilemap.SIZE + (DungeonTilemap.SIZE - height) / 2; time = TIME_TO_FADE; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Swap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Swap.java index a731b4fcc..461b8723c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Swap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Swap.java @@ -47,7 +47,7 @@ public class Swap extends Actor { this.ch1 = ch1; this.ch2 = ch2; - delay = Level.distance( ch1.pos, ch2.pos ) * 0.1f; + delay = Dungeon.level.distance( ch1.pos, ch2.pos ) * 0.1f; eff1 = new Effect( ch1.sprite, ch1.pos, ch2.pos ); eff2 = new Effect( ch2.sprite, ch2.pos, ch1.pos ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Wound.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Wound.java index 841646574..97d932345 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Wound.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/effects/Wound.java @@ -41,9 +41,9 @@ public class Wound extends Image { public void reset( int p ) { revive(); - - x = (p % Level.WIDTH) * DungeonTilemap.SIZE + (DungeonTilemap.SIZE - width) / 2; - y = (p / Level.WIDTH) * DungeonTilemap.SIZE + (DungeonTilemap.SIZE - height) / 2; + + x = (p % Dungeon.level.width()) * DungeonTilemap.SIZE + (DungeonTilemap.SIZE - width) / 2; + y = (p / Dungeon.level.width()) * DungeonTilemap.SIZE + (DungeonTilemap.SIZE - height) / 2; time = TIME_TO_FADE; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Bomb.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Bomb.java index ca8cb992c..9822a7c1a 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Bomb.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Bomb.java @@ -37,6 +37,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundle; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.ArrayList; @@ -90,7 +91,7 @@ public class Bomb extends Item { } if (Actor.findChar( cell ) != null && !(Actor.findChar( cell ) instanceof Hero) ){ ArrayList candidates = new ArrayList<>(); - for (int i : Level.NEIGHBOURS8) + for (int i : PathFinder.NEIGHBOURS8) if (Level.passable[cell + i]) candidates.add(cell + i); int newCell = candidates.isEmpty() ? cell : Random.element(candidates); @@ -119,9 +120,9 @@ public class Bomb extends Item { } boolean terrainAffected = false; - for (int n : Level.NEIGHBOURS9) { + for (int n : PathFinder.NEIGHBOURS9) { int c = cell + n; - if (c >= 0 && c < Level.LENGTH) { + if (c >= 0 && c < Dungeon.level.length()) { if (Dungeon.visible[c]) { CellEmitter.get( c ).burst( SmokeParticle.FACTORY, 4 ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Honeypot.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Honeypot.java index 7d759537a..7be0cce4b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Honeypot.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/Honeypot.java @@ -34,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.watabou.noosa.audio.Sample; import com.watabou.noosa.tweeners.AlphaTweener; import com.watabou.utils.Bundle; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.ArrayList; @@ -97,7 +98,7 @@ public class Honeypot extends Item { ArrayList candidates = new ArrayList(); boolean[] passable = Level.passable; - for (int n : Level.NEIGHBOURS4) { + for (int n : PathFinder.NEIGHBOURS4) { int c = pos + n; if (passable[c] && Actor.findChar( c ) == null) { candidates.add( c ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/WarriorArmor.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/WarriorArmor.java index 8bf9a7e21..83f161234 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/WarriorArmor.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/WarriorArmor.java @@ -35,6 +35,8 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.watabou.noosa.Camera; import com.watabou.utils.Callback; +import com.watabou.utils.PathFinder; + public class WarriorArmor extends ClassArmor { private static int LEAP_TIME = 1; @@ -74,8 +76,8 @@ public class WarriorArmor extends ClassArmor { Dungeon.level.press(dest, curUser); Dungeon.observe(); - for (int i = 0; i < Level.NEIGHBOURS8.length; i++) { - Char mob = Actor.findChar(curUser.pos + Level.NEIGHBOURS8[i]); + for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) { + Char mob = Actor.findChar(curUser.pos + PathFinder.NEIGHBOURS8[i]); if (mob != null && mob != curUser) { Buff.prolong(mob, Paralysis.class, SHOCK_TIME); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/AntiEntropy.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/AntiEntropy.java index 58bcd630f..9c5e6bd88 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/AntiEntropy.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/AntiEntropy.java @@ -20,6 +20,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.items.armor.curses; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Burning; @@ -43,7 +44,7 @@ public class AntiEntropy extends Glyph { if (Random.Int( 8 ) == 0) { - if (Level.adjacent( attacker.pos, defender.pos )) { + if (Dungeon.level.adjacent( attacker.pos, defender.pos )) { Buff.prolong(attacker, Frost.class, Frost.duration(attacker) * Random.Float(0.5f, 1f)); CellEmitter.get(attacker.pos).start(SnowParticle.FACTORY, 0.2f, 6); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/Corrosion.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/Corrosion.java index 7d548068c..1b1ecbc09 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/Corrosion.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/Corrosion.java @@ -28,6 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.Splash; import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; public class Corrosion extends Armor.Glyph { @@ -39,7 +40,7 @@ public class Corrosion extends Armor.Glyph { if (Random.Int(10) == 0){ int pos = defender.pos; - for (int i : Level.NEIGHBOURS9){ + for (int i : PathFinder.NEIGHBOURS9){ Splash.at(pos+i, 0x000000, 5); if (Actor.findChar(pos+i) != null) Buff.affect(Actor.findChar(pos+i), Ooze.class); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/Multiplicity.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/Multiplicity.java index fd3c35f4b..a62ebdb02 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/Multiplicity.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/curses/Multiplicity.java @@ -34,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; import com.watabou.utils.Bundle; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.ArrayList; @@ -48,8 +49,8 @@ public class Multiplicity extends Armor.Glyph { if (Random.Int(20) == 0){ ArrayList spawnPoints = new ArrayList<>(); - for (int i = 0; i < Level.NEIGHBOURS8.length; i++) { - int p = defender.pos + Level.NEIGHBOURS8[i]; + for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) { + int p = defender.pos + PathFinder.NEIGHBOURS8[i]; if (Actor.findChar( p ) == null && (Level.passable[p] || Level.avoid[p])) { spawnPoints.add( p ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/glyphs/Multiplicity.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/glyphs/Multiplicity.java index 6d09a4a7b..13eda08a1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/glyphs/Multiplicity.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/armor/glyphs/Multiplicity.java @@ -31,6 +31,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite.Glowing; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.ArrayList; @@ -48,8 +49,8 @@ public class Multiplicity extends Glyph { ArrayList respawnPoints = new ArrayList(); - for (int i=0; i < Level.NEIGHBOURS8.length; i++) { - int p = defender.pos + Level.NEIGHBOURS8[i]; + for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) { + int p = defender.pos + PathFinder.NEIGHBOURS8[i]; if (Actor.findChar( p ) == null && (Level.passable[p] || Level.avoid[p])) { respawnPoints.add( p ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CapeOfThorns.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CapeOfThorns.java index 4cc215d66..ce4cc6ac7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CapeOfThorns.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CapeOfThorns.java @@ -93,7 +93,7 @@ public class CapeOfThorns extends Artifact { int deflected = Random.NormalIntRange(0, damage); damage -= deflected; - if (attacker != null && Level.adjacent(attacker.pos, defender.pos)) { + if (attacker != null && Dungeon.level.adjacent(attacker.pos, defender.pos)) { attacker.damage(deflected, this); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java index edb488a98..83fff070f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/DriedRose.java @@ -48,6 +48,7 @@ import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.windows.WndQuest; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundle; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.ArrayList; @@ -100,8 +101,8 @@ public class DriedRose extends Artifact { else if (cursed) GLog.i( Messages.get(this, "cursed") ); else { ArrayList spawnPoints = new ArrayList(); - for (int i = 0; i < Level.NEIGHBOURS8.length; i++) { - int p = hero.pos + Level.NEIGHBOURS8[i]; + for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) { + int p = hero.pos + PathFinder.NEIGHBOURS8[i]; if (Actor.findChar(p) == null && (Level.passable[p] || Level.avoid[p])) { spawnPoints.add(p); } @@ -217,8 +218,8 @@ public class DriedRose extends Artifact { ArrayList spawnPoints = new ArrayList(); - for (int i = 0; i < Level.NEIGHBOURS8.length; i++) { - int p = target.pos + Level.NEIGHBOURS8[i]; + for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) { + int p = target.pos + PathFinder.NEIGHBOURS8[i]; if (Actor.findChar(p) == null && (Level.passable[p] || Level.avoid[p])) { spawnPoints.add(p); } @@ -347,7 +348,7 @@ public class DriedRose extends Artifact { @Override protected boolean getCloser( int target ) { - if (state == WANDERING || Level.distance(target, Dungeon.hero.pos) > 6) + if (state == WANDERING || Dungeon.level.distance(target, Dungeon.hero.pos) > 6) this.target = target = Dungeon.hero.pos; return super.getCloser( target ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/EtherealChains.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/EtherealChains.java index 98a6929bc..d309a551c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/EtherealChains.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/EtherealChains.java @@ -120,7 +120,7 @@ public class EtherealChains extends Artifact { } else { final int newMobPos = newPos; final Char affected = Actor.findChar( chain.collisionPos ); - int chargeUse = Level.distance(affected.pos, newMobPos); + int chargeUse = Dungeon.level.distance(affected.pos, newMobPos); if (chargeUse > charge) { GLog.w( Messages.get(EtherealChains.class, "no_charge") ); return; @@ -159,7 +159,7 @@ public class EtherealChains extends Artifact { GLog.w( Messages.get(EtherealChains.class, "does_nothing") ); } else { final int newHeroPos = newPos; - int chargeUse = Level.distance(curUser.pos, newHeroPos); + int chargeUse = Dungeon.level.distance(curUser.pos, newHeroPos); if (chargeUse > charge){ GLog.w( Messages.get(EtherealChains.class, "no_charge") ); return; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/LloydsBeacon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/LloydsBeacon.java index 82cfee5a7..5bd09478d 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/LloydsBeacon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/LloydsBeacon.java @@ -46,6 +46,7 @@ import com.watabou.noosa.Game; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundle; import com.watabou.utils.Callback; +import com.watabou.utils.PathFinder; import java.util.ArrayList; @@ -115,8 +116,8 @@ public class LloydsBeacon extends Artifact { return; } - for (int i=0; i < Level.NEIGHBOURS8.length; i++) { - if (Actor.findChar( hero.pos + Level.NEIGHBOURS8[i] ) != null) { + for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) { + if (Actor.findChar( hero.pos + PathFinder.NEIGHBOURS8[i] ) != null) { GLog.w( Messages.get(this, "creatures") ); return; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TalismanOfForesight.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TalismanOfForesight.java index 36a716c9d..b898a6bad 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TalismanOfForesight.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TalismanOfForesight.java @@ -75,7 +75,7 @@ public class TalismanOfForesight extends Artifact { hero.busy(); Sample.INSTANCE.play(Assets.SND_BEACON); charge = 0; - for (int i = 0; i < Level.LENGTH; i++) { + for (int i = 0; i < Dungeon.level.length(); i++) { int terr = Dungeon.level.map[i]; if ((Terrain.flags[terr] & Terrain.SECRET) != 0) { @@ -130,27 +130,27 @@ public class TalismanOfForesight extends Artifact { int distance = 3; - int cx = target.pos % Level.WIDTH; - int cy = target.pos / Level.WIDTH; + int cx = target.pos % Dungeon.level.width(); + int cy = target.pos / Dungeon.level.width(); int ax = cx - distance; if (ax < 0) { ax = 0; } int bx = cx + distance; - if (bx >= Level.WIDTH) { - bx = Level.WIDTH - 1; + if (bx >= Dungeon.level.width()) { + bx = Dungeon.level.width() - 1; } int ay = cy - distance; if (ay < 0) { ay = 0; } int by = cy + distance; - if (by >= Level.HEIGHT) { - by = Level.HEIGHT - 1; + if (by >= Dungeon.level.height()) { + by = Dungeon.level.height() - 1; } for (int y = ay; y <= by; y++) { - for (int x = ax, p = ax + y * Level.WIDTH; x <= bx; x++, p++) { + for (int x = ax, p = ax + y * Dungeon.level.width(); x <= bx; x++, p++) { if (Dungeon.visible[p] && Level.secret[p] && Dungeon.level.map[p] != Terrain.SECRET_DOOR) smthFound = true; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfFrost.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfFrost.java index 0fbe8144e..f9ac81cec 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfFrost.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfFrost.java @@ -45,7 +45,7 @@ public class PotionOfFrost extends Potion { Fire fire = (Fire)Dungeon.level.blobs.get( Fire.class ); boolean visible = false; - for (int i=0; i < Level.LENGTH; i++) { + for (int i=0; i < Dungeon.level.length(); i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE) { visible = Freezing.affect( i, fire ) || visible; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfLiquidFlame.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfLiquidFlame.java index 7e05c994e..645fa2533 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfLiquidFlame.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfLiquidFlame.java @@ -30,6 +30,7 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.particles.FlameParticle; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.watabou.noosa.audio.Sample; +import com.watabou.utils.PathFinder; public class PotionOfLiquidFlame extends Potion { @@ -47,7 +48,7 @@ public class PotionOfLiquidFlame extends Potion { Sample.INSTANCE.play( Assets.SND_SHATTER ); } - for (int offset : Level.NEIGHBOURS9){ + for (int offset : PathFinder.NEIGHBOURS9){ if (Level.flamable[cell+offset] || Actor.findChar(cell+offset) != null || Dungeon.level.heaps.get(cell+offset) != null) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfPurity.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfPurity.java index 7db006bcc..11da1dead 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfPurity.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/potions/PotionOfPurity.java @@ -70,7 +70,7 @@ public class PotionOfPurity extends Potion { continue; } - for (int i=0; i < Level.LENGTH; i++) { + for (int i=0; i < Dungeon.level.length(); i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE) { int value = blob.cur[i]; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/quest/CeremonialCandle.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/quest/CeremonialCandle.java index 229f3b92f..478cb87c9 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/quest/CeremonialCandle.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/quest/CeremonialCandle.java @@ -34,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.watabou.noosa.audio.Sample; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.ArrayList; @@ -76,9 +77,9 @@ public class CeremonialCandle extends Item { } private static void checkCandles(){ - Heap heapTop = Dungeon.level.heaps.get(ritualPos - Level.WIDTH); + Heap heapTop = Dungeon.level.heaps.get(ritualPos - Dungeon.level.width()); Heap heapRight = Dungeon.level.heaps.get(ritualPos + 1); - Heap heapBottom = Dungeon.level.heaps.get(ritualPos + Level.WIDTH); + Heap heapBottom = Dungeon.level.heaps.get(ritualPos + Dungeon.level.width()); Heap heapLeft = Dungeon.level.heaps.get(ritualPos - 1); if (heapTop != null && @@ -100,7 +101,7 @@ public class CeremonialCandle extends Item { Char ch = Actor.findChar( ritualPos ); if (ch != null) { ArrayList candidates = new ArrayList<>(); - for (int n : Level.NEIGHBOURS8) { + for (int n : PathFinder.NEIGHBOURS8) { int cell = ritualPos + n; if ((Level.passable[cell] || Level.avoid[cell]) && Actor.findChar( cell ) == null) { candidates.add( cell ); @@ -117,7 +118,7 @@ public class CeremonialCandle extends Item { elemental.state = elemental.HUNTING; GameScene.add(elemental, 1); - for (int i : Level.NEIGHBOURS9){ + for (int i : PathFinder.NEIGHBOURS9){ CellEmitter.get(ritualPos+i).burst(ElmoParticle.FACTORY, 10); } Sample.INSTANCE.play(Assets.SND_BURNING); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/quest/CorpseDust.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/quest/CorpseDust.java index 5ed8eb07b..a2d83ae83 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/quest/CorpseDust.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/quest/CorpseDust.java @@ -101,7 +101,7 @@ public class CorpseDust extends Item { spawnPower -= powerNeeded; int pos = 0; do{ - pos = Random.Int(Level.LENGTH); + pos = Random.Int(Dungeon.level.length()); } while (!Dungeon.visible[pos] || !Level.passable[pos] || Actor.findChar( pos ) != null); Wraith.spawnAt(pos); Sample.INSTANCE.play(Assets.SND_CURSED); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/quest/Pickaxe.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/quest/Pickaxe.java index 5a99979a3..64b86f496 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/quest/Pickaxe.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/quest/Pickaxe.java @@ -40,6 +40,7 @@ import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundle; import com.watabou.utils.Callback; +import com.watabou.utils.PathFinder; import java.util.ArrayList; @@ -96,9 +97,9 @@ public class Pickaxe extends Weapon { return; } - for (int i=0; i < Level.NEIGHBOURS8.length; i++) { + for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) { - final int pos = hero.pos + Level.NEIGHBOURS8[i]; + final int pos = hero.pos + PathFinder.NEIGHBOURS8[i]; if (Dungeon.level.map[pos] == Terrain.WALL_DECO) { hero.spend( TIME_TO_MINE ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfMagicMapping.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfMagicMapping.java index f7d784393..8eef0c1ec 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfMagicMapping.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfMagicMapping.java @@ -42,7 +42,7 @@ public class ScrollOfMagicMapping extends Scroll { @Override protected void doRead() { - int length = Level.LENGTH; + int length = Dungeon.level.length(); int[] map = Dungeon.level.map; boolean[] mapped = Dungeon.level.mapped; boolean[] discoverable = Level.discoverable; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfMirrorImage.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfMirrorImage.java index 6fa666655..b2f0b9216 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfMirrorImage.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfMirrorImage.java @@ -27,6 +27,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.MirrorImage; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.watabou.noosa.audio.Sample; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.ArrayList; @@ -44,8 +45,8 @@ public class ScrollOfMirrorImage extends Scroll { ArrayList respawnPoints = new ArrayList(); - for (int i=0; i < Level.NEIGHBOURS8.length; i++) { - int p = curUser.pos + Level.NEIGHBOURS8[i]; + for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) { + int p = curUser.pos + PathFinder.NEIGHBOURS8[i]; if (Actor.findChar( p ) == null && (Level.passable[p] || Level.avoid[p])) { respawnPoints.add( p ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java index 11ad72e5b..d1a54d4d6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java @@ -356,7 +356,7 @@ public class CursedWand { //great forest fire! case 0: - for (int i = 0; i < Level.LENGTH; i++){ + for (int i = 0; i < Dungeon.level.length(); i++){ int c = Dungeon.level.map[i]; if (c == Terrain.EMPTY || c == Terrain.EMBERS || diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfBlastWave.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfBlastWave.java index b328fd6be..58a5b34b7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfBlastWave.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfBlastWave.java @@ -40,6 +40,7 @@ import com.watabou.noosa.Group; import com.watabou.noosa.Image; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Callback; +import com.watabou.utils.PathFinder; import com.watabou.utils.PointF; import com.watabou.utils.Random; @@ -67,12 +68,12 @@ public class WandOfBlastWave extends DamageWand { int damage = damageRoll(); //presses all tiles in the AOE first - for (int i : Level.NEIGHBOURS9){ + for (int i : PathFinder.NEIGHBOURS9){ Dungeon.level.press(bolt.collisionPos+i, Actor.findChar(bolt.collisionPos+i)); } //throws other chars around the center. - for (int i : Level.NEIGHBOURS8){ + for (int i : PathFinder.NEIGHBOURS8){ Char ch = Actor.findChar(bolt.collisionPos + i); if (ch != null){ @@ -186,8 +187,8 @@ public class WandOfBlastWave extends DamageWand { public void reset(int pos) { revive(); - x = (pos % Level.WIDTH) * DungeonTilemap.SIZE + (DungeonTilemap.SIZE - width) / 2; - y = (pos / Level.WIDTH) * DungeonTilemap.SIZE + (DungeonTilemap.SIZE - height) / 2; + x = (pos % Dungeon.level.width()) * DungeonTilemap.SIZE + (DungeonTilemap.SIZE - width) / 2; + y = (pos / Dungeon.level.width()) * DungeonTilemap.SIZE + (DungeonTilemap.SIZE - height) / 2; time = TIME_TO_FADE; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFireblast.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFireblast.java index 610eb0dcb..206b73c89 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFireblast.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFireblast.java @@ -39,6 +39,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Callback; +import com.watabou.utils.PathFinder; import java.util.HashSet; @@ -100,9 +101,9 @@ public class WandOfFireblast extends DamageWand { affectedCells.add(cell); if (strength >= 1.5f) { visualCells.remove(cell); - spreadFlames(cell + Level.NEIGHBOURS8[left(direction)], strength - 1.5f); - spreadFlames(cell + Level.NEIGHBOURS8[direction], strength - 1.5f); - spreadFlames(cell + Level.NEIGHBOURS8[right(direction)], strength - 1.5f); + spreadFlames(cell + PathFinder.NEIGHBOURS8[left(direction)], strength - 1.5f); + spreadFlames(cell + PathFinder.NEIGHBOURS8[direction], strength - 1.5f); + spreadFlames(cell + PathFinder.NEIGHBOURS8[right(direction)], strength - 1.5f); } else { visualCells.add(cell); } @@ -134,8 +135,8 @@ public class WandOfFireblast extends DamageWand { int maxDist = (int)(4 * Math.pow(1.5,(chargesPerCast()-1))); int dist = Math.min(bolt.dist, maxDist); - for (int i = 0; i < Level.NEIGHBOURS8.length; i++){ - if (bolt.sourcePos+Level.NEIGHBOURS8[i] == bolt.path.get(1)){ + for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++){ + if (bolt.sourcePos+PathFinder.NEIGHBOURS8[i] == bolt.path.get(1)){ direction = i; break; } @@ -146,9 +147,9 @@ public class WandOfFireblast extends DamageWand { strength--; //as we start at dist 1, not 0. affectedCells.add(c); if (strength > 1) { - spreadFlames(c + Level.NEIGHBOURS8[left(direction)], strength - 1); - spreadFlames(c + Level.NEIGHBOURS8[direction], strength - 1); - spreadFlames(c + Level.NEIGHBOURS8[right(direction)], strength - 1); + spreadFlames(c + PathFinder.NEIGHBOURS8[left(direction)], strength - 1); + spreadFlames(c + PathFinder.NEIGHBOURS8[direction], strength - 1); + spreadFlames(c + PathFinder.NEIGHBOURS8[right(direction)], strength - 1); } else { visualCells.add(c); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfLightning.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfLightning.java index a02cbfcf5..c4be349e7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfLightning.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfLightning.java @@ -33,9 +33,11 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.traps.LightningTrap; import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; +import com.shatteredpixel.shatteredpixeldungeon.utils.BArray; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.watabou.noosa.Camera; import com.watabou.utils.Callback; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.ArrayList; @@ -94,28 +96,24 @@ public class WandOfLightning extends DamageWand { affected.add( ch ); - for (int i : Level.NEIGHBOURS8) { - int cell = ch.pos + i; + int dist; + if (Level.water[ch.pos] && !ch.flying) + dist = 2; + else + dist = 1; - Char n = Actor.findChar( cell ); - if (n != null && !affected.contains( n )) { - arcs.add(new Lightning.Arc(ch.pos, n.pos)); - arc(n); - } - } - - if (Level.water[ch.pos] && !ch.flying){ - for (int i : Level.NEIGHBOURS8DIST2) { - int cell = ch.pos + i; - //player can only be hit by lightning from an adjacent enemy. - if (!Level.insideMap(cell) || Actor.findChar(cell) == Dungeon.hero) continue; - - Char n = Actor.findChar( ch.pos + i ); - if (n != null && !affected.contains( n )) { - arcs.add(new Lightning.Arc(ch.pos, n.pos)); - arc(n); + PathFinder.buildDistanceMap( ch.pos, BArray.not( Level.solid, null ), dist ); + for (int i = 0; i < PathFinder.distance.length; i++) { + if (PathFinder.distance[i] < Integer.MAX_VALUE){ + Char n = Actor.findChar( i ); + if (n == Dungeon.hero && PathFinder.distance[i] > 1) + //the hero is only zapped if they are adjacent + continue; + else if (n != null && !affected.contains( n )) { + arcs.add(new Lightning.Arc(ch.pos, n.pos)); + arc(n); + } } - } } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfPrismaticLight.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfPrismaticLight.java index ff9722856..08348a2c7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfPrismaticLight.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfPrismaticLight.java @@ -41,8 +41,10 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; +import com.shatteredpixel.shatteredpixeldungeon.utils.BArray; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Callback; +import com.watabou.utils.PathFinder; import com.watabou.utils.PointF; import com.watabou.utils.Random; @@ -100,10 +102,8 @@ public class WandOfPrismaticLight extends DamageWand { private void affectMap(Ballistica beam){ boolean noticed = false; for (int c: beam.subPath(0, beam.dist)){ - for (int n : Level.NEIGHBOURS9DIST2){ + for (int n : PathFinder.NEIGHBOURS9){ int cell = c+n; - if (!Level.insideMap(cell)) - continue; if (Level.discoverable[cell]) Dungeon.level.mapped[cell] = true; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfRegrowth.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfRegrowth.java index 89b610ca6..aabbde414 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfRegrowth.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfRegrowth.java @@ -43,6 +43,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Callback; import com.watabou.utils.ColorMath; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.ArrayList; @@ -110,9 +111,9 @@ public class WandOfRegrowth extends Wand { if (strength >= 0 && Level.passable[cell] && !Level.losBlocking[cell]){ affectedCells.add(cell); if (strength >= 1.5f) { - spreadRegrowth(cell + Level.NEIGHBOURS8[left(direction)], strength - 1.5f); - spreadRegrowth(cell + Level.NEIGHBOURS8[direction], strength - 1.5f); - spreadRegrowth(cell + Level.NEIGHBOURS8[right(direction)], strength-1.5f); + spreadRegrowth(cell + PathFinder.NEIGHBOURS8[left(direction)], strength - 1.5f); + spreadRegrowth(cell + PathFinder.NEIGHBOURS8[direction], strength - 1.5f); + spreadRegrowth(cell + PathFinder.NEIGHBOURS8[right(direction)], strength-1.5f); } else { visualCells.add(cell); } @@ -187,8 +188,8 @@ public class WandOfRegrowth extends Wand { int maxDist = Math.round(1.2f + chargesPerCast()*.8f); int dist = Math.min(bolt.dist, maxDist); - for (int i = 0; i < Level.NEIGHBOURS8.length; i++){ - if (bolt.sourcePos+Level.NEIGHBOURS8[i] == bolt.path.get(1)){ + for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++){ + if (bolt.sourcePos+PathFinder.NEIGHBOURS8[i] == bolt.path.get(1)){ direction = i; break; } @@ -199,9 +200,9 @@ public class WandOfRegrowth extends Wand { strength--; //as we start at dist 1, not 0. if (!Level.losBlocking[c]) { affectedCells.add(c); - spreadRegrowth(c + Level.NEIGHBOURS8[left(direction)], strength - 1); - spreadRegrowth(c + Level.NEIGHBOURS8[direction], strength - 1); - spreadRegrowth(c + Level.NEIGHBOURS8[right(direction)], strength - 1); + spreadRegrowth(c + PathFinder.NEIGHBOURS8[left(direction)], strength - 1); + spreadRegrowth(c + PathFinder.NEIGHBOURS8[direction], strength - 1); + spreadRegrowth(c + PathFinder.NEIGHBOURS8[right(direction)], strength - 1); } else { visualCells.add(c); } @@ -254,7 +255,7 @@ public class WandOfRegrowth extends Wand { int nDrops = Random.NormalIntRange(2, 8); ArrayList candidates = new ArrayList(); - for (int i : Level.NEIGHBOURS8){ + for (int i : PathFinder.NEIGHBOURS8){ if (Level.passable[pos+i]){ candidates.add(pos+i); } @@ -288,7 +289,7 @@ public class WandOfRegrowth extends Wand { int nSeeds = Random.NormalIntRange(1, 5); ArrayList candidates = new ArrayList(); - for (int i : Level.NEIGHBOURS8){ + for (int i : PathFinder.NEIGHBOURS8){ if (Level.passable[pos+i]){ candidates.add(pos+i); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfVenom.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfVenom.java index 179c6ef49..ee2a3a086 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfVenom.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfVenom.java @@ -34,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Callback; +import com.watabou.utils.PathFinder; public class WandOfVenom extends Wand { @@ -49,7 +50,7 @@ public class WandOfVenom extends Wand { ((VenomGas)venomGas).setStrength(level()+1); GameScene.add(venomGas); - for (int i : Level.NEIGHBOURS9) { + for (int i : PathFinder.NEIGHBOURS9) { Char ch = Actor.findChar(bolt.collisionPos + i); if (ch != null) { processSoulMark(ch, chargesPerCast()); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/enchantments/Shocking.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/enchantments/Shocking.java index 2b26a6708..732a05e3c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/enchantments/Shocking.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/enchantments/Shocking.java @@ -28,6 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.traps.LightningTrap; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.ArrayList; @@ -83,8 +84,8 @@ public class Shocking extends Weapon.Enchantment { ch.sprite.flash(); HashSet ns = new HashSet(); - for (int i=0; i < Level.NEIGHBOURS8.length; i++) { - Char n = Actor.findChar( ch.pos + Level.NEIGHBOURS8[i] ); + for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) { + Char n = Actor.findChar( ch.pos + PathFinder.NEIGHBOURS8[i] ); if (n != null && !affected.contains( n )) { arcs.add(new Lightning.Arc(ch.pos, n.pos)); hit(n, Random.Int(damage / 2, damage)); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java index eee4ae9b1..921eae75c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/weapon/missiles/MissileWeapon.java @@ -57,7 +57,7 @@ abstract public class MissileWeapon extends Weapon { @Override public int throwPos(Hero user, int dst) { if (hasEnchant(Projecting.class) - && !Level.solid[dst] && Level.distance(user.pos, dst) <= 4){ + && !Level.solid[dst] && Dungeon.level.distance(user.pos, dst) <= 4){ return dst; } else { return super.throwPos(user, dst); 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 7322e0806..5a52fa293 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesBossLevel.java @@ -41,6 +41,7 @@ import com.watabou.noosa.Camera; import com.watabou.noosa.Group; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundle; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; public class CavesBossLevel extends Level { @@ -51,7 +52,10 @@ public class CavesBossLevel extends Level { viewDistance = 6; } - + + private static final int WIDTH = 32; + private static final int HEIGHT = 32; + private static final int ROOM_LEFT = WIDTH / 2 - 2; private static final int ROOM_RIGHT = WIDTH / 2 + 2; private static final int ROOM_TOP = HEIGHT / 2 - 2; @@ -103,21 +107,21 @@ public class CavesBossLevel extends Level { right = ROOM_RIGHT + 3; } else { left = ROOM_LEFT - 3; - right = Random.Int( ROOM_RIGHT + 3, WIDTH - 1 ); + right = Random.Int( ROOM_RIGHT + 3, width() - 1 ); } if (Random.Int( 2 ) == 0) { top = Random.Int( 2, ROOM_TOP - 3 ); bottom = ROOM_BOTTOM + 3; } else { top = ROOM_LEFT - 3; - bottom = Random.Int( ROOM_TOP + 3, HEIGHT - 1 ); + bottom = Random.Int( ROOM_TOP + 3, height() - 1 ); } Painter.fill( this, left, top, right - left + 1, bottom - top + 1, Terrain.EMPTY ); if (top < topMost) { topMost = top; - exit = Random.Int( left, right ) + (top - 1) * WIDTH; + exit = Random.Int( left, right ) + (top - 1) * width(); } } @@ -131,21 +135,21 @@ public class CavesBossLevel extends Level { Painter.fill( this, ROOM_LEFT, ROOM_TOP, ROOM_RIGHT - ROOM_LEFT + 1, 1, Terrain.EMPTY_DECO ); - arenaDoor = Random.Int( ROOM_LEFT, ROOM_RIGHT ) + (ROOM_BOTTOM + 1) * WIDTH; + arenaDoor = Random.Int( ROOM_LEFT, ROOM_RIGHT ) + (ROOM_BOTTOM + 1) * width(); map[arenaDoor] = Terrain.DOOR; entrance = Random.Int( ROOM_LEFT + 1, ROOM_RIGHT - 1 ) + - Random.Int( ROOM_TOP + 1, ROOM_BOTTOM - 1 ) * WIDTH; + Random.Int( ROOM_TOP + 1, ROOM_BOTTOM - 1 ) * width(); map[entrance] = Terrain.ENTRANCE; - boolean[] patch = Patch.generate( 0.45f, 6 ); - for (int i=0; i < LENGTH; i++) { + boolean[] patch = Patch.generate( this, 0.45f, 6 ); + for (int i=0; i < length(); i++) { if (map[i] == Terrain.EMPTY && patch[i]) { map[i] = Terrain.WATER; } } - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < length(); i++) { if (map[i] == Terrain.EMPTY && Random.Int( 6 ) == 0) { map[i] = Terrain.INACTIVE_TRAP; Trap t = new ToxicTrap().reveal(); @@ -160,7 +164,7 @@ public class CavesBossLevel extends Level { @Override protected void decorate() { - for (int i=WIDTH + 1; i < LENGTH - WIDTH; i++) { + for (int i=width() + 1; i < length() - width(); i++) { if (map[i] == Terrain.EMPTY) { int n = 0; if (map[i+1] == Terrain.WALL) { @@ -169,10 +173,10 @@ public class CavesBossLevel extends Level { if (map[i-1] == Terrain.WALL) { n++; } - if (map[i+WIDTH] == Terrain.WALL) { + if (map[i+width()] == Terrain.WALL) { n++; } - if (map[i-WIDTH] == Terrain.WALL) { + if (map[i-width()] == Terrain.WALL) { n++; } if (Random.Int( 8 ) <= n) { @@ -181,7 +185,7 @@ public class CavesBossLevel extends Level { } } - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < length(); i++) { if (map[i] == Terrain.WALL && Random.Int( 8 ) == 0) { map[i] = Terrain.WALL_DECO; } @@ -189,7 +193,7 @@ public class CavesBossLevel extends Level { int sign; do { - sign = Random.Int( ROOM_LEFT, ROOM_RIGHT ) + Random.Int( ROOM_TOP, ROOM_BOTTOM ) * WIDTH; + sign = Random.Int( ROOM_LEFT, ROOM_RIGHT ) + Random.Int( ROOM_TOP, ROOM_BOTTOM ) * width(); } while (sign == entrance || map[sign] == Terrain.INACTIVE_TRAP); map[sign] = Terrain.SIGN; } @@ -208,7 +212,7 @@ public class CavesBossLevel extends Level { if (item != null) { int pos; do { - pos = Random.IntRange( ROOM_LEFT, ROOM_RIGHT ) + Random.IntRange( ROOM_TOP + 1, ROOM_BOTTOM ) * WIDTH; + pos = Random.IntRange( ROOM_LEFT, ROOM_RIGHT ) + Random.IntRange( ROOM_TOP + 1, ROOM_BOTTOM ) * width(); } while (pos == entrance || map[pos] == Terrain.SIGN); drop( item, pos ).type = Heap.Type.REMAINS; } @@ -216,9 +220,9 @@ public class CavesBossLevel extends Level { @Override public int randomRespawnCell() { - int cell = entrance + NEIGHBOURS8[Random.Int(8)]; + int cell = entrance + PathFinder.NEIGHBOURS8[Random.Int(8)]; while (!passable[cell]){ - cell = entrance + NEIGHBOURS8[Random.Int(8)]; + cell = entrance + PathFinder.NEIGHBOURS8[Random.Int(8)]; } return cell; } @@ -236,7 +240,7 @@ public class CavesBossLevel extends Level { Mob boss = Bestiary.mob( Dungeon.depth ); boss.state = boss.WANDERING; do { - boss.pos = Random.Int( LENGTH ); + boss.pos = Random.Int( length() ); } while ( !passable[boss.pos] || !outsideEntraceRoom( boss.pos ) || @@ -272,8 +276,8 @@ public class CavesBossLevel extends Level { } private boolean outsideEntraceRoom( int cell ) { - int cx = cell % WIDTH; - int cy = cell / WIDTH; + int cx = cell % width(); + int cy = cell / width(); return cx < ROOM_LEFT-1 || cx > ROOM_RIGHT+1 || cy < ROOM_TOP-1 || cy > ROOM_BOTTOM+1; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesLevel.java index 922b9b4fa..6157e8841 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CavesLevel.java @@ -73,11 +73,11 @@ public class CavesLevel extends RegularLevel { } protected boolean[] water() { - return Patch.generate( feeling == Feeling.WATER ? 0.60f : 0.45f, 6 ); + return Patch.generate( this, feeling == Feeling.WATER ? 0.60f : 0.45f, 6 ); } protected boolean[] grass() { - return Patch.generate( feeling == Feeling.GRASS ? 0.55f : 0.35f, 3 ); + return Patch.generate( this, feeling == Feeling.GRASS ? 0.55f : 0.35f, 3 ); } @Override @@ -121,32 +121,32 @@ public class CavesLevel extends RegularLevel { int s = room.square(); if (Random.Int( s ) > 8) { - int corner = (room.left + 1) + (room.top + 1) * WIDTH; - if (map[corner - 1] == Terrain.WALL && map[corner - WIDTH] == Terrain.WALL) { + int corner = (room.left + 1) + (room.top + 1) * width(); + if (map[corner - 1] == Terrain.WALL && map[corner - width()] == Terrain.WALL) { map[corner] = Terrain.WALL; traps.remove(corner); } } if (Random.Int( s ) > 8) { - int corner = (room.right - 1) + (room.top + 1) * WIDTH; - if (map[corner + 1] == Terrain.WALL && map[corner - WIDTH] == Terrain.WALL) { + int corner = (room.right - 1) + (room.top + 1) * width(); + if (map[corner + 1] == Terrain.WALL && map[corner - width()] == Terrain.WALL) { map[corner] = Terrain.WALL; traps.remove(corner); } } if (Random.Int( s ) > 8) { - int corner = (room.left + 1) + (room.bottom - 1) * WIDTH; - if (map[corner - 1] == Terrain.WALL && map[corner + WIDTH] == Terrain.WALL) { + int corner = (room.left + 1) + (room.bottom - 1) * width(); + if (map[corner - 1] == Terrain.WALL && map[corner + width()] == Terrain.WALL) { map[corner] = Terrain.WALL; traps.remove(corner); } } if (Random.Int( s ) > 8) { - int corner = (room.right - 1) + (room.bottom - 1) * WIDTH; - if (map[corner + 1] == Terrain.WALL && map[corner + WIDTH] == Terrain.WALL) { + int corner = (room.right - 1) + (room.bottom - 1) * width(); + if (map[corner + 1] == Terrain.WALL && map[corner + width()] == Terrain.WALL) { map[corner] = Terrain.WALL; traps.remove(corner); } @@ -159,7 +159,7 @@ public class CavesLevel extends RegularLevel { } } - for (int i=WIDTH + 1; i < LENGTH - WIDTH; i++) { + for (int i=width() + 1; i < length() - width(); i++) { if (map[i] == Terrain.EMPTY) { int n = 0; if (map[i+1] == Terrain.WALL) { @@ -168,10 +168,10 @@ public class CavesLevel extends RegularLevel { if (map[i-1] == Terrain.WALL) { n++; } - if (map[i+WIDTH] == Terrain.WALL) { + if (map[i+width()] == Terrain.WALL) { n++; } - if (map[i-WIDTH] == Terrain.WALL) { + if (map[i-width()] == Terrain.WALL) { n++; } if (Random.Int( 6 ) <= n) { @@ -180,7 +180,7 @@ public class CavesLevel extends RegularLevel { } } - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < length(); i++) { if (map[i] == Terrain.WALL && Random.Int( 12 ) == 0) { map[i] = Terrain.WALL_DECO; } @@ -261,7 +261,7 @@ public class CavesLevel extends RegularLevel { } public static void addCavesVisuals( Level level, Group group ) { - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < level.length(); i++) { if (level.map[i] == Terrain.WALL_DECO) { group.add( new Vein( i ) ); } 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 29611cd52..f92715be3 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityBossLevel.java @@ -36,6 +36,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.watabou.noosa.Group; import com.watabou.noosa.tweeners.AlphaTweener; import com.watabou.utils.Bundle; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; public class CityBossLevel extends Level { @@ -49,6 +50,8 @@ public class CityBossLevel extends Level { private static final int HALL_WIDTH = 7; private static final int HALL_HEIGHT = 15; private static final int CHAMBER_HEIGHT = 3; + + private static final int WIDTH = 32; private static final int LEFT = (WIDTH - HALL_WIDTH) / 2; private static final int CENTER = LEFT + HALL_WIDTH / 2; @@ -95,8 +98,8 @@ public class CityBossLevel extends Level { int y = TOP + 1; while (y < TOP + HALL_HEIGHT) { - map[y * WIDTH + CENTER - 2] = Terrain.STATUE_SP; - map[y * WIDTH + CENTER + 2] = Terrain.STATUE_SP; + map[y * width() + CENTER - 2] = Terrain.STATUE_SP; + map[y * width() + CENTER + 2] = Terrain.STATUE_SP; y += 2; } @@ -107,17 +110,17 @@ public class CityBossLevel extends Level { map[i] = Terrain.EMPTY_SP; } - exit = (TOP - 1) * WIDTH + CENTER; + exit = (TOP - 1) * width() + CENTER; map[exit] = Terrain.LOCKED_EXIT; - arenaDoor = (TOP + HALL_HEIGHT) * WIDTH + CENTER; + arenaDoor = (TOP + HALL_HEIGHT) * width() + CENTER; map[arenaDoor] = Terrain.DOOR; Painter.fill( this, LEFT, TOP + HALL_HEIGHT + 1, HALL_WIDTH, CHAMBER_HEIGHT, Terrain.EMPTY ); Painter.fill( this, LEFT, TOP + HALL_HEIGHT + 1, 1, CHAMBER_HEIGHT, Terrain.BOOKSHELF ); Painter.fill( this, LEFT + HALL_WIDTH - 1, TOP + HALL_HEIGHT + 1, 1, CHAMBER_HEIGHT, Terrain.BOOKSHELF ); - entrance = (TOP + HALL_HEIGHT + 2 + Random.Int( CHAMBER_HEIGHT - 1 )) * WIDTH + LEFT + (/*1 +*/ Random.Int( HALL_WIDTH-2 )); + entrance = (TOP + HALL_HEIGHT + 2 + Random.Int( CHAMBER_HEIGHT - 1 )) * width() + LEFT + (/*1 +*/ Random.Int( HALL_WIDTH-2 )); map[entrance] = Terrain.ENTRANCE; return true; @@ -126,7 +129,7 @@ public class CityBossLevel extends Level { @Override protected void decorate() { - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < length(); i++) { if (map[i] == Terrain.EMPTY && Random.Int( 10 ) == 0) { map[i] = Terrain.EMPTY_DECO; } else if (map[i] == Terrain.WALL && Random.Int( 8 ) == 0) { @@ -134,15 +137,15 @@ public class CityBossLevel extends Level { } } - int sign = arenaDoor + WIDTH + 1; + int sign = arenaDoor + width() + 1; map[sign] = Terrain.SIGN; } - public static int pedestal( boolean left ) { + public int pedestal( boolean left ) { if (left) { - return (TOP + HALL_HEIGHT / 2) * WIDTH + CENTER - 2; + return (TOP + HALL_HEIGHT / 2) * width() + CENTER - 2; } else { - return (TOP + HALL_HEIGHT / 2) * WIDTH + CENTER + 2; + return (TOP + HALL_HEIGHT / 2) * width() + CENTER + 2; } } @@ -162,7 +165,7 @@ public class CityBossLevel extends Level { do { pos = Random.IntRange( LEFT + 1, LEFT + HALL_WIDTH - 2 ) + - Random.IntRange( TOP + HALL_HEIGHT + 1, TOP + HALL_HEIGHT + CHAMBER_HEIGHT ) * WIDTH; + Random.IntRange( TOP + HALL_HEIGHT + 1, TOP + HALL_HEIGHT + CHAMBER_HEIGHT ) * width(); } while (pos == entrance || map[pos] == Terrain.SIGN); drop( item, pos ).type = Heap.Type.REMAINS; } @@ -170,9 +173,9 @@ public class CityBossLevel extends Level { @Override public int randomRespawnCell() { - int cell = entrance + NEIGHBOURS8[Random.Int(8)]; + int cell = entrance + PathFinder.NEIGHBOURS8[Random.Int(8)]; while (!passable[cell]){ - cell = entrance + NEIGHBOURS8[Random.Int(8)]; + cell = entrance + PathFinder.NEIGHBOURS8[Random.Int(8)]; } return cell; } @@ -191,7 +194,7 @@ public class CityBossLevel extends Level { boss.state = boss.WANDERING; int count = 0; do { - boss.pos = Random.Int( LENGTH ); + boss.pos = Random.Int( length() ); } while ( !passable[boss.pos] || !outsideEntraceRoom( boss.pos ) || @@ -227,7 +230,7 @@ public class CityBossLevel extends Level { } private boolean outsideEntraceRoom( int cell ) { - return cell / WIDTH < arenaDoor / WIDTH; + return cell / width() < arenaDoor / width(); } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityLevel.java index 8154f42e6..29ae81674 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/CityLevel.java @@ -68,11 +68,11 @@ public class CityLevel extends RegularLevel { } protected boolean[] water() { - return Patch.generate( feeling == Feeling.WATER ? 0.65f : 0.45f, 4 ); + return Patch.generate( this, feeling == Feeling.WATER ? 0.65f : 0.45f, 4 ); } protected boolean[] grass() { - return Patch.generate( feeling == Feeling.GRASS ? 0.60f : 0.40f, 3 ); + return Patch.generate( this, feeling == Feeling.GRASS ? 0.60f : 0.40f, 3 ); } @Override @@ -107,7 +107,7 @@ public class CityLevel extends RegularLevel { @Override protected void decorate() { - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < length(); i++) { if (map[i] == Terrain.EMPTY && Random.Int( 10 ) == 0) { map[i] = Terrain.EMPTY_DECO; } else if (map[i] == Terrain.WALL && Random.Int( 8 ) == 0) { @@ -167,7 +167,7 @@ public class CityLevel extends RegularLevel { } public static void addCityVisuals( Level level, Group group ) { - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < level.length(); i++) { if (level.map[i] == Terrain.WALL_DECO) { group.add( new Smoke( i ) ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/DeadEndLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/DeadEndLevel.java index 3b58b238e..13e511d93 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/DeadEndLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/DeadEndLevel.java @@ -52,22 +52,22 @@ public class DeadEndLevel extends Level { for (int i=2; i < SIZE; i++) { for (int j=2; j < SIZE; j++) { - map[i * WIDTH + j] = Terrain.EMPTY; + map[i * width() + j] = Terrain.EMPTY; } } for (int i=1; i <= SIZE; i++) { - map[WIDTH + i] = - map[WIDTH * SIZE + i] = - map[WIDTH * i + 1] = - map[WIDTH * i + SIZE] = + map[width() + i] = + map[width() * SIZE + i] = + map[width() * i + 1] = + map[width() * i + SIZE] = Terrain.WATER; } - entrance = SIZE * WIDTH + SIZE / 2 + 1; + entrance = SIZE * width() + SIZE / 2 + 1; map[entrance] = Terrain.ENTRANCE; - map[(SIZE / 2 + 1) * (WIDTH + 1)] = Terrain.SIGN; + map[(SIZE / 2 + 1) * (width() + 1)] = Terrain.SIGN; exit = 0; @@ -76,7 +76,7 @@ public class DeadEndLevel extends Level { @Override protected void decorate() { - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < length(); i++) { if (map[i] == Terrain.EMPTY && Random.Int( 10 ) == 0) { map[i] = Terrain.EMPTY_DECO; } else if (map[i] == Terrain.WALL && Random.Int( 8 ) == 0) { @@ -99,7 +99,7 @@ public class DeadEndLevel extends Level { @Override public int randomRespawnCell() { - return entrance-WIDTH; + return entrance-width(); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/HallsBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/HallsBossLevel.java index 4d87b40d5..76c548c9e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/HallsBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/HallsBossLevel.java @@ -36,6 +36,7 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.watabou.noosa.Group; import com.watabou.utils.Bundle; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; public class HallsBossLevel extends Level { @@ -46,7 +47,10 @@ public class HallsBossLevel extends Level { viewDistance = 3; } - + + private static final int WIDTH = 32; + private static final int HEIGHT = 32; + private static final int ROOM_LEFT = WIDTH / 2 - 1; private static final int ROOM_RIGHT = WIDTH / 2 + 1; private static final int ROOM_TOP = HEIGHT / 2 - 1; @@ -96,13 +100,13 @@ public class HallsBossLevel extends Level { Painter.fill( this, 2 + i * 4, top, 4, bottom - top + 1, Terrain.EMPTY ); if (i == 2) { - exit = (i * 4 + 3) + (top - 1) * WIDTH ; + exit = (i * 4 + 3) + (top - 1) * width() ; } for (int j=0; j < 4; j++) { if (Random.Int( 2 ) == 0) { int y = Random.IntRange( top + 1, bottom - 1 ); - map[i*4+j + y*WIDTH] = Terrain.WALL_DECO; + map[i*4+j + y*width()] = Terrain.WALL_DECO; } } } @@ -115,11 +119,11 @@ public class HallsBossLevel extends Level { ROOM_RIGHT - ROOM_LEFT + 1, ROOM_BOTTOM - ROOM_TOP + 1, Terrain.EMPTY ); entrance = Random.Int( ROOM_LEFT + 1, ROOM_RIGHT - 1 ) + - Random.Int( ROOM_TOP + 1, ROOM_BOTTOM - 1 ) * WIDTH; + Random.Int( ROOM_TOP + 1, ROOM_BOTTOM - 1 ) * width(); map[entrance] = Terrain.ENTRANCE; - boolean[] patch = Patch.generate( 0.45f, 6 ); - for (int i=0; i < LENGTH; i++) { + boolean[] patch = Patch.generate( this, 0.45f, 6 ); + for (int i=0; i < length(); i++) { if (map[i] == Terrain.EMPTY && patch[i]) { map[i] = Terrain.WATER; } @@ -131,7 +135,7 @@ public class HallsBossLevel extends Level { @Override protected void decorate() { - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < length(); i++) { if (map[i] == Terrain.EMPTY && Random.Int( 10 ) == 0) { map[i] = Terrain.EMPTY_DECO; } @@ -152,7 +156,7 @@ public class HallsBossLevel extends Level { if (item != null) { int pos; do { - pos = Random.IntRange( ROOM_LEFT, ROOM_RIGHT ) + Random.IntRange( ROOM_TOP + 1, ROOM_BOTTOM ) * WIDTH; + pos = Random.IntRange( ROOM_LEFT, ROOM_RIGHT ) + Random.IntRange( ROOM_TOP + 1, ROOM_BOTTOM ) * width(); } while (pos == entrance || map[pos] == Terrain.SIGN); drop( item, pos ).type = Heap.Type.REMAINS; } @@ -161,9 +165,9 @@ public class HallsBossLevel extends Level { @Override public int randomRespawnCell() { if (entrance == -1) return entrance; - int cell = entrance + NEIGHBOURS8[Random.Int(8)]; + int cell = entrance + PathFinder.NEIGHBOURS8[Random.Int(8)]; while (!passable[cell]){ - cell = entrance + NEIGHBOURS8[Random.Int(8)]; + cell = entrance + PathFinder.NEIGHBOURS8[Random.Int(8)]; } return cell; } @@ -179,12 +183,12 @@ public class HallsBossLevel extends Level { seal(); for (int i=ROOM_LEFT-1; i <= ROOM_RIGHT + 1; i++) { - doMagic( (ROOM_TOP - 1) * WIDTH + i ); - doMagic( (ROOM_BOTTOM + 1) * WIDTH + i ); + doMagic( (ROOM_TOP - 1) * width() + i ); + doMagic( (ROOM_BOTTOM + 1) * width() + i ); } for (int i=ROOM_TOP; i < ROOM_BOTTOM + 1; i++) { - doMagic( i * WIDTH + ROOM_LEFT - 1 ); - doMagic( i * WIDTH + ROOM_RIGHT + 1 ); + doMagic( i * width() + ROOM_LEFT - 1 ); + doMagic( i * width() + ROOM_RIGHT + 1 ); } doMagic( entrance ); GameScene.updateMap(); @@ -193,7 +197,7 @@ public class HallsBossLevel extends Level { Yog boss = new Yog(); do { - boss.pos = Random.Int( LENGTH ); + boss.pos = Random.Int( length() ); } while ( !passable[boss.pos] || Dungeon.visible[boss.pos]); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/HallsLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/HallsLevel.java index 379bb67ca..8eb72e301 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/HallsLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/HallsLevel.java @@ -48,6 +48,7 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.watabou.noosa.Game; import com.watabou.noosa.Group; import com.watabou.noosa.particles.PixelParticle; +import com.watabou.utils.PathFinder; import com.watabou.utils.PointF; import com.watabou.utils.Random; @@ -81,11 +82,11 @@ public class HallsLevel extends RegularLevel { } protected boolean[] water() { - return Patch.generate( feeling == Feeling.WATER ? 0.55f : 0.40f, 6 ); + return Patch.generate( this, feeling == Feeling.WATER ? 0.55f : 0.40f, 6 ); } protected boolean[] grass() { - return Patch.generate( feeling == Feeling.GRASS ? 0.55f : 0.30f, 3 ); + return Patch.generate( this, feeling == Feeling.GRASS ? 0.55f : 0.30f, 3 ); } @Override @@ -107,12 +108,12 @@ public class HallsLevel extends RegularLevel { @Override protected void decorate() { - for (int i=WIDTH + 1; i < LENGTH - WIDTH - 1; i++) { + for (int i=width() + 1; i < length() - width() - 1; i++) { if (map[i] == Terrain.EMPTY) { int count = 0; - for (int j=0; j < NEIGHBOURS8.length; j++) { - if ((Terrain.flags[map[i + NEIGHBOURS8[j]]] & Terrain.PASSABLE) > 0) { + for (int j=0; j < PathFinder.NEIGHBOURS8.length; j++) { + if ((Terrain.flags[map[i + PathFinder.NEIGHBOURS8[j]]] & Terrain.PASSABLE) > 0) { count++; } } @@ -123,7 +124,7 @@ public class HallsLevel extends RegularLevel { } else if (map[i] == Terrain.WALL && - map[i-1] != Terrain.WALL_DECO && map[i-WIDTH] != Terrain.WALL_DECO && + map[i-1] != Terrain.WALL_DECO && map[i-width()] != Terrain.WALL_DECO && Random.Int( 20 ) == 0) { map[i] = Terrain.WALL_DECO; @@ -174,7 +175,7 @@ public class HallsLevel extends RegularLevel { } public static void addHallsVisuals( Level level, Group group ) { - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < level.length(); i++) { if (level.map[i] == Terrain.WATER) { group.add( new Stream( i ) ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastLevel.java index 70ac2545f..b4ef5a0a7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastLevel.java @@ -27,6 +27,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.watabou.noosa.Group; import com.watabou.utils.Bundle; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.Arrays; @@ -57,7 +58,7 @@ public class LastLevel extends Level { @Override public void create() { super.create(); - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < length(); i++) { int flags = Terrain.flags[map[i]]; if ((flags & Terrain.PIT) != 0){ passable[i] = avoid[i] = false; @@ -82,23 +83,23 @@ public class LastLevel extends Level { //Painter.fill( this, 2, 2, SIZE-2, SIZE-2, Terrain.EMPTY ); //Painter.fill( this, SIZE/2, SIZE/2, 3, 3, Terrain.EMPTY_SP ); - entrance = SIZE * WIDTH + SIZE / 2 + 1; + entrance = SIZE * width() + SIZE / 2 + 1; map[entrance] = Terrain.ENTRANCE; - pedestal = (SIZE / 2 + 1) * (WIDTH + 1) - 4*WIDTH; + pedestal = (SIZE / 2 + 1) * (width() + 1) - 4*width(); map[pedestal] = Terrain.PEDESTAL; - map[pedestal-1-WIDTH] = map[pedestal+1-WIDTH] = map[pedestal-1+WIDTH] = map[pedestal+1+WIDTH] = Terrain.STATUE_SP; + map[pedestal-1-width()] = map[pedestal+1-width()] = map[pedestal-1+width()] = map[pedestal+1+width()] = Terrain.STATUE_SP; exit = pedestal; int pos = pedestal; - map[pos-WIDTH] = map[pos-1] = map[pos+1] = map[pos-2] = map[pos+2] = Terrain.WATER; - pos+=WIDTH; + map[pos-width()] = map[pos-1] = map[pos+1] = map[pos-2] = map[pos+2] = Terrain.WATER; + pos+=width(); map[pos] = map[pos-2] = map[pos+2] = map[pos-3] = map[pos+3] = Terrain.WATER; - pos+=WIDTH; + pos+=width(); map[pos-3] = map[pos-2] = map[pos-1] = map[pos] = map[pos+1] = map[pos+2] = map[pos+3] = Terrain.WATER; - pos+=WIDTH; + pos+=width(); map[pos-2] = map[pos+2] = Terrain.WATER; @@ -110,7 +111,7 @@ public class LastLevel extends Level { @Override protected void decorate() { - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < length(); i++) { if (map[i] == Terrain.EMPTY && Random.Int( 10 ) == 0) { map[i] = Terrain.EMPTY_DECO; } @@ -132,9 +133,9 @@ public class LastLevel extends Level { @Override public int randomRespawnCell() { - int cell = entrance + NEIGHBOURS8[Random.Int(8)]; + int cell = entrance + PathFinder.NEIGHBOURS8[Random.Int(8)]; while (!passable[cell]){ - cell = entrance + NEIGHBOURS8[Random.Int(8)]; + cell = entrance + PathFinder.NEIGHBOURS8[Random.Int(8)]; } return cell; } @@ -181,7 +182,7 @@ public class LastLevel extends Level { @Override public void restoreFromBundle(Bundle bundle) { super.restoreFromBundle(bundle); - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < length(); i++) { int flags = Terrain.flags[map[i]]; if ((flags & Terrain.PIT) != 0){ passable[i] = avoid[i] = false; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastShopLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastShopLevel.java index ccdd672a3..c3f31a132 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastShopLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/LastShopLevel.java @@ -134,7 +134,7 @@ public class LastShopLevel extends RegularLevel { @Override protected void decorate() { - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < length(); i++) { if (map[i] == Terrain.EMPTY && Random.Int( 10 ) == 0) { map[i] = Terrain.EMPTY_DECO; @@ -169,7 +169,7 @@ public class LastShopLevel extends RegularLevel { if (item != null) { int pos; do { - pos = roomEntrance.random(); + pos = pointToCell(roomEntrance.random()); } while (pos == entrance || map[pos] == Terrain.SIGN); drop( item, pos ).type = Heap.Type.REMAINS; } @@ -177,7 +177,7 @@ public class LastShopLevel extends RegularLevel { @Override public int randomRespawnCell() { - return roomEntrance.random(); + return pointToCell( roomEntrance.random() ); } @Override @@ -216,12 +216,12 @@ public class LastShopLevel extends RegularLevel { @Override protected boolean[] water() { - return Patch.generate( 0.35f, 4 ); + return Patch.generate( this, 0.35f, 4 ); } @Override protected boolean[] grass() { - return Patch.generate( 0.30f, 3 ); + return Patch.generate( this, 0.30f, 3 ); } @Override 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 7a6904841..aa78868fb 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Level.java @@ -80,6 +80,9 @@ import com.watabou.noosa.Group; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundlable; import com.watabou.utils.Bundle; +import com.watabou.utils.PathFinder; +import com.watabou.utils.Point; +import com.watabou.utils.PointF; import com.watabou.utils.Random; import com.watabou.utils.SparseArray; @@ -98,32 +101,11 @@ public abstract class Level implements Bundlable { GRASS, DARK } - - public static final int WIDTH = 32; - public static final int HEIGHT = 32; - public static final int LENGTH = WIDTH * HEIGHT; - - public static final int[] NEIGHBOURS4 = {-WIDTH, +1, +WIDTH, -1}; - public static final int[] NEIGHBOURS8 = {-WIDTH, +1-WIDTH, +1, +1+WIDTH, +WIDTH, -1+WIDTH, -1, -1-WIDTH}; - public static final int[] NEIGHBOURS9 = {0, -WIDTH, +1-WIDTH, +1, +1+WIDTH, +WIDTH, -1+WIDTH, -1, -1-WIDTH}; - - //make sure to check insideMap() when using these, as there's a risk something may be outside the map - public static final int[] NEIGHBOURS8DIST2 = {+2+2*WIDTH, +1+2*WIDTH, 2*WIDTH, -1+2*WIDTH, -2+2*WIDTH, - +2+WIDTH, +1+WIDTH, +WIDTH, -1+WIDTH, -2+WIDTH, - +2, +1, -1, -2, - +2-WIDTH, +1-WIDTH, -WIDTH, -1-WIDTH, -2-WIDTH, - +2-2*WIDTH, +1-2*WIDTH, -2*WIDTH, -1-2*WIDTH, -2-2*WIDTH}; - public static final int[] NEIGHBOURS9DIST2 = {+2+2*WIDTH, +1+2*WIDTH, 2*WIDTH, -1+2*WIDTH, -2+2*WIDTH, - +2+WIDTH, +1+WIDTH, +WIDTH, -1+WIDTH, -2+WIDTH, - +2, +1, 0, -1, -2, - +2-WIDTH, +1-WIDTH, -WIDTH, -1-WIDTH, -2-WIDTH, - +2-2*WIDTH, +1-2*WIDTH, -2*WIDTH, -1-2*WIDTH, -2-2*WIDTH}; + protected int width; + protected int height; protected static final float TIME_TO_RESPAWN = 50; - - public static boolean resizingNeeded; - public static int loadedMapSize; public int version; public int[] map; @@ -131,19 +113,20 @@ public abstract class Level implements Bundlable { public boolean[] mapped; public int viewDistance = Dungeon.isChallenged( Challenges.DARKNESS ) ? 3: 8; + + //FIXME should not be static! + public static boolean[] fieldOfView; - public static boolean[] fieldOfView = new boolean[LENGTH]; + public static boolean[] passable; + public static boolean[] losBlocking; + public static boolean[] flamable; + public static boolean[] secret; + public static boolean[] solid; + public static boolean[] avoid; + public static boolean[] water; + public static boolean[] pit; - public static boolean[] passable = new boolean[LENGTH]; - public static boolean[] losBlocking = new boolean[LENGTH]; - public static boolean[] flamable = new boolean[LENGTH]; - public static boolean[] secret = new boolean[LENGTH]; - public static boolean[] solid = new boolean[LENGTH]; - public static boolean[] avoid = new boolean[LENGTH]; - public static boolean[] water = new boolean[LENGTH]; - public static boolean[] pit = new boolean[LENGTH]; - - public static boolean[] discoverable = new boolean[LENGTH]; + public static boolean[] discoverable; public Feeling feeling = Feeling.NONE; @@ -187,13 +170,22 @@ public abstract class Level implements Bundlable { private static final String FEELING = "feeling"; public void create() { + + setupSize(); + PathFinder.setMapSize(width(), height()); + passable = new boolean[length()]; + losBlocking = new boolean[length()]; + flamable = new boolean[length()]; + secret = new boolean[length()]; + solid = new boolean[length()]; + avoid = new boolean[length()]; + water = new boolean[length()]; + pit = new boolean[length()]; - resizingNeeded = false; - - map = new int[LENGTH]; - visited = new boolean[LENGTH]; + map = new int[length()]; + visited = new boolean[length()]; Arrays.fill( visited, false ); - mapped = new boolean[LENGTH]; + mapped = new boolean[length()]; Arrays.fill( mapped, false ); if (!(Dungeon.bossLevel() || Dungeon.depth == 21) /*final shop floor*/) { @@ -282,6 +274,10 @@ public abstract class Level implements Bundlable { createMobs(); createItems(); } + + protected void setupSize(){ + width = height = 32; + } public void reset() { @@ -297,6 +293,13 @@ public abstract class Level implements Bundlable { public void restoreFromBundle( Bundle bundle ) { version = bundle.getInt( VERSION ); + + if (bundle.contains("width") && bundle.contains("height")){ + width = bundle.getInt("width"); + height = bundle.getInt("height"); + } else + width = height = 32; //default sizes + PathFinder.setMapSize(width(), height()); mobs = new HashSet<>(); heaps = new SparseArray<>(); @@ -316,8 +319,6 @@ public abstract class Level implements Bundlable { locked = bundle.getBoolean( LOCKED ); weakFloorCreated = false; - - adjustMapSize(); //for pre-0.3.0c saves if (version < 44){ @@ -327,9 +328,6 @@ public abstract class Level implements Bundlable { Collection collection = bundle.getCollection( HEAPS ); for (Bundlable h : collection) { Heap heap = (Heap)h; - if (resizingNeeded) { - heap.pos = adjustPos( heap.pos ); - } if (!heap.isEmpty()) heaps.put( heap.pos, heap ); } @@ -337,27 +335,18 @@ public abstract class Level implements Bundlable { collection = bundle.getCollection( PLANTS ); for (Bundlable p : collection) { Plant plant = (Plant)p; - if (resizingNeeded) { - plant.pos = adjustPos( plant.pos ); - } plants.put( plant.pos, plant ); } collection = bundle.getCollection( TRAPS ); for (Bundlable p : collection) { Trap trap = (Trap)p; - if (resizingNeeded) { - trap.pos = adjustPos( trap.pos ); - } traps.put( trap.pos, trap ); } collection = bundle.getCollection( CUSTOM_TILES ); for (Bundlable p : collection) { CustomTileVisual vis = (CustomTileVisual)p; - if (resizingNeeded) { - //TODO: add proper resizing logic here - } customTiles.add( vis ); } @@ -365,9 +354,6 @@ public abstract class Level implements Bundlable { for (Bundlable m : collection) { Mob mob = (Mob)m; if (mob != null) { - if (resizingNeeded) { - mob.pos = adjustPos( mob.pos ); - } mobs.add( mob ); } } @@ -389,6 +375,8 @@ public abstract class Level implements Bundlable { @Override public void storeInBundle( Bundle bundle ) { bundle.put( VERSION, Game.versionCode ); + bundle.put( "width", width ); + bundle.put( "height", height ); bundle.put( MAP, map ); bundle.put( VISITED, visited ); bundle.put( MAPPED, mapped ); @@ -407,43 +395,21 @@ public abstract class Level implements Bundlable { public int tunnelTile() { return feeling == Feeling.CHASM ? Terrain.EMPTY_SP : Terrain.EMPTY; } - - private void adjustMapSize() { - // For levels saved before 1.6.3 - // Seeing as shattered started on 1.7.1 this is never used, but the code may be resused in future. - if (map.length < LENGTH) { - - resizingNeeded = true; - loadedMapSize = (int)Math.sqrt( map.length ); - - int[] map = new int[LENGTH]; - Arrays.fill( map, Terrain.WALL ); - - boolean[] visited = new boolean[LENGTH]; - Arrays.fill( visited, false ); - - boolean[] mapped = new boolean[LENGTH]; - Arrays.fill( mapped, false ); - - for (int i=0; i < loadedMapSize; i++) { - System.arraycopy( this.map, i * loadedMapSize, map, i * WIDTH, loadedMapSize ); - System.arraycopy( this.visited, i * loadedMapSize, visited, i * WIDTH, loadedMapSize ); - System.arraycopy( this.mapped, i * loadedMapSize, mapped, i * WIDTH, loadedMapSize ); - } - - this.map = map; - this.visited = visited; - this.mapped = mapped; - - entrance = adjustPos( entrance ); - exit = adjustPos( exit ); - } else { - resizingNeeded = false; - } + + public int width() { + if (width == 0) + setupSize(); + return width; } - - public int adjustPos( int pos ) { - return (pos / loadedMapSize) * WIDTH + (pos % loadedMapSize); + + public int height() { + if (height == 0) + setupSize(); + return height; + } + + public int length() { + return width() * height(); } public String tilesTex() { @@ -481,11 +447,11 @@ public abstract class Level implements Bundlable { } else { visuals.clear(); } - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < length(); i++) { if (pit[i]) { visuals.add( new WindParticle.Wind( i ) ); - if (i >= WIDTH && water[i-WIDTH]) { - visuals.add( new FlowParticle.Flow( i - WIDTH ) ); + if (i >= width() && water[i-width()]) { + visuals.add( new FlowParticle.Flow( i - width() ) ); } } } @@ -535,7 +501,7 @@ public abstract class Level implements Bundlable { public int randomRespawnCell() { int cell; do { - cell = Random.Int( LENGTH ); + cell = Random.Int( length() ); } while (!passable[cell] || Dungeon.visible[cell] || Actor.findChar( cell ) != null); return cell; } @@ -543,7 +509,7 @@ public abstract class Level implements Bundlable { public int randomDestination() { int cell; do { - cell = Random.Int( LENGTH ); + cell = Random.Int( length() ); } while (!passable[cell]); return cell; } @@ -577,8 +543,17 @@ public abstract class Level implements Bundlable { } protected void buildFlagMaps() { + + passable = new boolean[length()]; + losBlocking = new boolean[length()]; + flamable = new boolean[length()]; + secret = new boolean[length()]; + solid = new boolean[length()]; + avoid = new boolean[length()]; + water = new boolean[length()]; + pit = new boolean[length()]; - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < length(); i++) { int flags = Terrain.flags[map[i]]; passable[i] = (flags & Terrain.PASSABLE) != 0; losBlocking[i] = (flags & Terrain.LOS_BLOCKING) != 0; @@ -590,28 +565,28 @@ public abstract class Level implements Bundlable { pit[i] = (flags & Terrain.PIT) != 0; } - int lastRow = LENGTH - WIDTH; - for (int i=0; i < WIDTH; i++) { + int lastRow = length() - width(); + for (int i=0; i < width(); i++) { passable[i] = avoid[i] = false; passable[lastRow + i] = avoid[lastRow + i] = false; } - for (int i=WIDTH; i < lastRow; i += WIDTH) { + for (int i=width(); i < lastRow; i += width()) { passable[i] = avoid[i] = false; - passable[i + WIDTH-1] = avoid[i + WIDTH-1] = false; + passable[i + width()-1] = avoid[i + width()-1] = false; } - for (int i=WIDTH; i < LENGTH - WIDTH; i++) { + for (int i=width(); i < length() - width(); i++) { if (water[i]) { map[i] = getWaterTile( i ); } if (pit[i]) { - if (!pit[i - WIDTH]) { - int c = map[i - WIDTH]; + if (!pit[i - width()]) { + int c = map[i - width()]; if (c == Terrain.EMPTY_SP || c == Terrain.STATUE_SP) { map[i] = Terrain.CHASM_FLOOR_SP; - } else if (water[i - WIDTH]) { + } else if (water[i - width()]) { map[i] = Terrain.CHASM_WATER; } else if ((Terrain.flags[c] & Terrain.UNSTITCHABLE) != 0) { map[i] = Terrain.CHASM_WALL; @@ -625,8 +600,8 @@ public abstract class Level implements Bundlable { private int getWaterTile( int pos ) { int t = Terrain.WATER_TILES; - for (int j=0; j < NEIGHBOURS4.length; j++) { - if ((Terrain.flags[map[pos + NEIGHBOURS4[j]]] & Terrain.UNSTITCHABLE) != 0) { + for (int j=0; j < PathFinder.NEIGHBOURS4.length; j++) { + if ((Terrain.flags[map[pos + PathFinder.NEIGHBOURS4[j]]] & Terrain.UNSTITCHABLE) != 0) { t += 1 << j; } } @@ -640,8 +615,8 @@ public abstract class Level implements Bundlable { } else { boolean flood = false; - for (int j=0; j < NEIGHBOURS4.length; j++) { - if (water[pos + NEIGHBOURS4[j]]) { + for (int j = 0; j < PathFinder.NEIGHBOURS4.length; j++) { + if (water[pos + PathFinder.NEIGHBOURS4[j]]) { flood = true; break; } @@ -655,13 +630,15 @@ public abstract class Level implements Bundlable { } protected void cleanWalls() { - for (int i=0; i < LENGTH; i++) { + discoverable = new boolean[length()]; + + for (int i=0; i < length(); i++) { boolean d = false; - for (int j=0; j < NEIGHBOURS9.length; j++) { - int n = i + NEIGHBOURS9[j]; - if (n >= 0 && n < LENGTH && map[n] != Terrain.WALL && map[n] != Terrain.WALL_DECO) { + for (int j=0; j < PathFinder.NEIGHBOURS9.length; j++) { + int n = i + PathFinder.NEIGHBOURS9[j]; + if (n >= 0 && n < length() && map[n] != Terrain.WALL && map[n] != Terrain.WALL_DECO) { d = true; break; } @@ -670,9 +647,9 @@ public abstract class Level implements Bundlable { if (d) { d = false; - for (int j=0; j < NEIGHBOURS9.length; j++) { - int n = i + NEIGHBOURS9[j]; - if (n >= 0 && n < LENGTH && !pit[n]) { + for (int j=0; j < PathFinder.NEIGHBOURS9.length; j++) { + int n = i + PathFinder.NEIGHBOURS9[j]; + if (n >= 0 && n < length() && !pit[n]) { d = true; break; } @@ -727,7 +704,7 @@ public abstract class Level implements Bundlable { Dungeon.hero.buff(AlchemistsToolkit.alchemy.class) != null && Dungeon.hero.buff(AlchemistsToolkit.alchemy.class).isCursed())) { int n; do { - n = cell + NEIGHBOURS8[Random.Int( 8 )]; + n = cell + PathFinder.NEIGHBOURS8[Random.Int( 8 )]; } while (map[n] != Terrain.EMPTY_SP); cell = n; } @@ -750,7 +727,7 @@ public abstract class Level implements Bundlable { int n; do { - n = cell + Level.NEIGHBOURS8[Random.Int( 8 )]; + n = cell + PathFinder.NEIGHBOURS8[Random.Int( 8 )]; } while (!Level.passable[n] && !Level.avoid[n]); return drop( item, n ); @@ -920,16 +897,16 @@ public abstract class Level implements Bundlable { } public boolean[] updateFieldOfView( Char c ) { + + fieldOfView = new boolean[length()]; - int cx = c.pos % WIDTH; - int cy = c.pos / WIDTH; + int cx = c.pos % width(); + int cy = c.pos / width(); boolean sighted = c.buff( Blindness.class ) == null && c.buff( Shadows.class ) == null && c.buff( TimekeepersHourglass.timeStasis.class ) == null && c.isAlive(); if (sighted) { ShadowCaster.castShadow( cx, cy, fieldOfView, c.viewDistance ); - } else { - Arrays.fill( fieldOfView, false ); } int sense = 1; @@ -942,17 +919,17 @@ public abstract class Level implements Bundlable { if ((sighted && sense > 1) || !sighted) { int ax = Math.max( 0, cx - sense ); - int bx = Math.min( cx + sense, WIDTH - 1 ); + int bx = Math.min( cx + sense, width() - 1 ); int ay = Math.max( 0, cy - sense ); - int by = Math.min( cy + sense, HEIGHT - 1 ); + int by = Math.min( cy + sense, height() - 1 ); int len = bx - ax + 1; - int pos = ax + ay * WIDTH; - for (int y = ay; y <= by; y++, pos+=WIDTH) { + int pos = ax + ay * width(); + for (int y = ay; y <= by; y++, pos+=width()) { Arrays.fill( fieldOfView, pos, pos + len, true ); } - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < length(); i++) { fieldOfView[i] &= discoverable[i]; } } @@ -964,12 +941,12 @@ public abstract class Level implements Bundlable { fieldOfView[p] = true; fieldOfView[p + 1] = true; fieldOfView[p - 1] = true; - fieldOfView[p + WIDTH + 1] = true; - fieldOfView[p + WIDTH - 1] = true; - fieldOfView[p - WIDTH + 1] = true; - fieldOfView[p - WIDTH - 1] = true; - fieldOfView[p + WIDTH] = true; - fieldOfView[p - WIDTH] = true; + fieldOfView[p + width() + 1] = true; + fieldOfView[p + width() - 1] = true; + fieldOfView[p - width() + 1] = true; + fieldOfView[p - width() - 1] = true; + fieldOfView[p + width()] = true; + fieldOfView[p - width()] = true; } } else if (c == Dungeon.hero && ((Hero)c).heroClass == HeroClass.HUNTRESS) { for (Mob mob : mobs) { @@ -978,12 +955,12 @@ public abstract class Level implements Bundlable { fieldOfView[p] = true; fieldOfView[p + 1] = true; fieldOfView[p - 1] = true; - fieldOfView[p + WIDTH + 1] = true; - fieldOfView[p + WIDTH - 1] = true; - fieldOfView[p - WIDTH + 1] = true; - fieldOfView[p - WIDTH - 1] = true; - fieldOfView[p + WIDTH] = true; - fieldOfView[p - WIDTH] = true; + fieldOfView[p + width() + 1] = true; + fieldOfView[p + width() - 1] = true; + fieldOfView[p - width() + 1] = true; + fieldOfView[p - width() - 1] = true; + fieldOfView[p + width()] = true; + fieldOfView[p - width()] = true; } } } @@ -993,12 +970,12 @@ public abstract class Level implements Bundlable { fieldOfView[p] = true; fieldOfView[p + 1] = true; fieldOfView[p - 1] = true; - fieldOfView[p + WIDTH + 1] = true; - fieldOfView[p + WIDTH - 1] = true; - fieldOfView[p - WIDTH + 1] = true; - fieldOfView[p - WIDTH - 1] = true; - fieldOfView[p + WIDTH] = true; - fieldOfView[p - WIDTH] = true; + fieldOfView[p + width() + 1] = true; + fieldOfView[p + width() - 1] = true; + fieldOfView[p - width() + 1] = true; + fieldOfView[p - width() - 1] = true; + fieldOfView[p + width()] = true; + fieldOfView[p - width()] = true; } } } @@ -1010,27 +987,34 @@ public abstract class Level implements Bundlable { return fieldOfView; } - public static int distance( int a, int b ) { - int ax = a % WIDTH; - int ay = a / WIDTH; - int bx = b % WIDTH; - int by = b / WIDTH; + public int distance( int a, int b ) { + int ax = a % width(); + int ay = a / width(); + int bx = b % width(); + int by = b / width(); return Math.max( Math.abs( ax - bx ), Math.abs( ay - by ) ); } - public static boolean adjacent( int a, int b ) { - int diff = Math.abs( a - b ); - return diff == 1 || diff == WIDTH || diff == WIDTH + 1 || diff == WIDTH - 1; + public boolean adjacent( int a, int b ) { + return distance( a, b ) == 1; } //returns true if the input is a valid tile within the level - public static boolean insideMap( int tile ){ + public boolean insideMap( int tile ){ //outside map array - return !((tile <= -1 || tile >= LENGTH) || + return !((tile < 0 || tile >= length()) || //top and bottom row - (tile <= 31 || tile >= LENGTH - WIDTH) || + (tile < width() || tile >= length() - width()) || //left and right column - (tile % WIDTH == 0 || tile % WIDTH == 31)); + (tile % width() == 0 || tile % width() == width()-1)); + } + + public Point cellToPoint( int cell ){ + return new Point(cell % width(), cell / width()); + } + + public int pointToCell( Point p ){ + return p.x + p.y*width(); } public String tileName( int tile ) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Patch.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Patch.java index 636819e6b..10cebcf9c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Patch.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Patch.java @@ -20,19 +20,20 @@ */ package com.shatteredpixel.shatteredpixeldungeon.levels; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.watabou.utils.Random; public class Patch { - private static boolean[] cur = new boolean[Level.LENGTH]; - private static boolean[] off = new boolean[Level.LENGTH]; - - public static boolean[] generate( float seed, int nGen ) { + public static boolean[] generate( Level level, float seed, int nGen ) { - int w = Level.WIDTH; - int h = Level.HEIGHT; + int w = level.width(); + int h = level.width(); + + boolean[] cur = new boolean[level.length()]; + boolean[] off = new boolean[level.length()]; - for (int i=0; i < Level.LENGTH; i++) { + for (int i=0; i < level.length(); i++) { off[i] = Random.Float() < seed; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java index 23fc6b0f0..aa988fba7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonBossLevel.java @@ -44,6 +44,7 @@ import com.watabou.noosa.Group; import com.watabou.noosa.audio.Sample; import com.watabou.utils.Bundlable; import com.watabou.utils.Bundle; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.ArrayList; @@ -175,13 +176,13 @@ public class PrisonBossLevel extends Level { if (ch == Dungeon.hero){ //hero enters tengu's chamber if (state == State.START - && ((Room)new Room().set(2, 25, 8, 32)).inside(cell)){ + && ((Room)new Room().set(2, 25, 8, 32)).inside(cellToPoint(cell))){ progress(); } //hero finishes the maze else if (state == State.MAZE - && ((Room)new Room().set(4, 0, 7, 4)).inside(cell)){ + && ((Room)new Room().set(4, 0, 7, 4)).inside(cellToPoint(cell))){ progress(); } } @@ -189,7 +190,7 @@ public class PrisonBossLevel extends Level { @Override public int randomRespawnCell() { - return 5+2*32 + NEIGHBOURS8[Random.Int(8)]; //random cell adjacent to the entrance. + return 5+2*32 + PathFinder.NEIGHBOURS8[Random.Int(8)]; //random cell adjacent to the entrance. } @Override @@ -220,7 +221,7 @@ public class PrisonBossLevel extends Level { } traps.clear(); - for (int i = 0; i < Level.LENGTH; i++){ + for (int i = 0; i < Dungeon.level.length(); i++){ if (map[i] == Terrain.INACTIVE_TRAP) { Trap t = new SpearTrap().reveal(); t.active = false; @@ -237,13 +238,13 @@ public class PrisonBossLevel extends Level { cleanWalls(); exit = entrance = 0; - for (int i = 0; i < LENGTH; i ++) + for (int i = 0; i < length(); i ++) if (map[i] == Terrain.ENTRANCE) entrance = i; else if (map[i] == Terrain.EXIT) exit = i; - visited = mapped = new boolean[LENGTH]; + visited = mapped = new boolean[length()]; for (Blob blob: blobs.values()){ blob.fullyClear(); } @@ -255,19 +256,19 @@ public class PrisonBossLevel extends Level { private void clearEntities(Room safeArea){ for (Heap heap : heaps.values()){ - if (safeArea == null || !safeArea.inside(heap.pos)){ + if (safeArea == null || !safeArea.inside(cellToPoint(heap.pos))){ for (Item item : heap.items) storedItems.add(item); heap.destroy(); } } for (Mob mob : Dungeon.level.mobs.toArray(new Mob[Dungeon.level.mobs.size()])){ - if (mob != tengu && (safeArea == null || !safeArea.inside(mob.pos))){ + if (mob != tengu && (safeArea == null || !safeArea.inside(cellToPoint(mob.pos)))){ mob.destroy(); } } for (Plant plant : plants.values()){ - if (safeArea == null || !safeArea.inside(plant.pos)){ + if (safeArea == null || !safeArea.inside(cellToPoint(plant.pos))){ plants.remove(plant.pos); plant.sprite.kill(); } @@ -328,7 +329,7 @@ public class PrisonBossLevel extends Level { tengu.state = tengu.HUNTING; do { - tengu.pos = Random.Int(LENGTH); + tengu.pos = Random.Int(length()); } while (solid[tengu.pos] || distance(tengu.pos, Dungeon.hero.pos) < 8); GameScene.add(tengu); tengu.notice(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonLevel.java index d59ba2eae..3ba57d7d6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/PrisonLevel.java @@ -66,11 +66,11 @@ public class PrisonLevel extends RegularLevel { } protected boolean[] water() { - return Patch.generate( feeling == Feeling.WATER ? 0.65f : 0.45f, 4 ); + return Patch.generate( this, feeling == Feeling.WATER ? 0.65f : 0.45f, 4 ); } protected boolean[] grass() { - return Patch.generate( feeling == Feeling.GRASS ? 0.60f : 0.40f, 3 ); + return Patch.generate( this, feeling == Feeling.GRASS ? 0.60f : 0.40f, 3 ); } @Override @@ -103,20 +103,20 @@ public class PrisonLevel extends RegularLevel { @Override protected void decorate() { - for (int i=WIDTH + 1; i < LENGTH - WIDTH - 1; i++) { + for (int i=width() + 1; i < length() - width() - 1; i++) { if (map[i] == Terrain.EMPTY) { float c = 0.05f; - if (map[i + 1] == Terrain.WALL && map[i + WIDTH] == Terrain.WALL) { + if (map[i + 1] == Terrain.WALL && map[i + width()] == Terrain.WALL) { c += 0.2f; } - if (map[i - 1] == Terrain.WALL && map[i + WIDTH] == Terrain.WALL) { + if (map[i - 1] == Terrain.WALL && map[i + width()] == Terrain.WALL) { c += 0.2f; } - if (map[i + 1] == Terrain.WALL && map[i - WIDTH] == Terrain.WALL) { + if (map[i + 1] == Terrain.WALL && map[i - width()] == Terrain.WALL) { c += 0.2f; } - if (map[i - 1] == Terrain.WALL && map[i - WIDTH] == Terrain.WALL) { + if (map[i - 1] == Terrain.WALL && map[i - width()] == Terrain.WALL) { c += 0.2f; } @@ -126,19 +126,19 @@ public class PrisonLevel extends RegularLevel { } } - for (int i=0; i < WIDTH; i++) { + for (int i=0; i < width(); i++) { if (map[i] == Terrain.WALL && - (map[i + WIDTH] == Terrain.EMPTY || map[i + WIDTH] == Terrain.EMPTY_SP) && + (map[i + width()] == Terrain.EMPTY || map[i + width()] == Terrain.EMPTY_SP) && Random.Int( 6 ) == 0) { map[i] = Terrain.WALL_DECO; } } - for (int i=WIDTH; i < LENGTH - WIDTH; i++) { + for (int i=width(); i < length() - width(); i++) { if (map[i] == Terrain.WALL && - map[i - WIDTH] == Terrain.WALL && - (map[i + WIDTH] == Terrain.EMPTY || map[i + WIDTH] == Terrain.EMPTY_SP) && + map[i - width()] == Terrain.WALL && + (map[i + width()] == Terrain.EMPTY || map[i + width()] == Terrain.EMPTY_SP) && Random.Int( 3 ) == 0) { map[i] = Terrain.WALL_DECO; @@ -178,7 +178,7 @@ public class PrisonLevel extends RegularLevel { } public static void addPrisonVisuals(Level level, Group group){ - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < level.length(); i++) { if (level.map[i] == Terrain.WALL_DECO) { group.add( new Torch( i ) ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java index a90fd8fd8..29180eaf8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/RegularLevel.java @@ -40,6 +40,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap; import com.shatteredpixel.shatteredpixeldungeon.levels.traps.WornTrap; import com.watabou.utils.Bundle; import com.watabou.utils.Graph; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import com.watabou.utils.Rect; @@ -172,7 +173,7 @@ public abstract class RegularLevel extends Level { protected void placeSign(){ while (true) { - int pos = roomEntrance.random(); + int pos = pointToCell(roomEntrance.random()); if (pos != entrance && traps.get(pos) == null && findMob(pos) == null) { map[pos] = Terrain.SIGN; break; @@ -182,8 +183,8 @@ public abstract class RegularLevel extends Level { protected boolean initRooms() { - rooms = new HashSet(); - split( new Rect( 0, 0, WIDTH - 1, HEIGHT - 1 ) ); + rooms = new HashSet<>(); + split( new Rect( 0, 0, width() - 1, height() - 1 ) ); if (rooms.size() < 8) { return false; @@ -296,7 +297,7 @@ public abstract class RegularLevel extends Level { protected void paintWater() { boolean[] lake = water(); - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < length(); i++) { if (map[i] == Terrain.EMPTY && lake[i]) { map[i] = Terrain.WATER; } @@ -310,18 +311,18 @@ public abstract class RegularLevel extends Level { for (Room room : rooms) { if (room.type != Type.NULL && room.type != Type.PASSAGE && room.type != Type.TUNNEL) { - grass[(room.left + 1) + (room.top + 1) * WIDTH] = true; - grass[(room.right - 1) + (room.top + 1) * WIDTH] = true; - grass[(room.left + 1) + (room.bottom - 1) * WIDTH] = true; - grass[(room.right - 1) + (room.bottom - 1) * WIDTH] = true; + grass[(room.left + 1) + (room.top + 1) * width()] = true; + grass[(room.right - 1) + (room.top + 1) * width()] = true; + grass[(room.left + 1) + (room.bottom - 1) * width()] = true; + grass[(room.right - 1) + (room.bottom - 1) * width()] = true; } } } - for (int i=WIDTH+1; i < LENGTH-WIDTH-1; i++) { + for (int i=width()+1; i < length()-width()-1; i++) { if (map[i] == Terrain.EMPTY && grass[i]) { int count = 1; - for (int n : NEIGHBOURS8) { + for (int n : PathFinder.NEIGHBOURS8) { if (grass[i + n]) { count++; } @@ -342,7 +343,7 @@ public abstract class RegularLevel extends Level { LinkedList validCells = new LinkedList(); - for (int i = 0; i < LENGTH; i ++) { + for (int i = 0; i < length(); i ++) { if (map[i] == Terrain.EMPTY){ if(Dungeon.depth == 1){ @@ -477,7 +478,7 @@ public abstract class RegularLevel extends Level { } Room.Door d = r.connected.get( n ); - int door = d.x + d.y * WIDTH; + int door = d.x + d.y * width(); switch (d.type) { case EMPTY: @@ -595,7 +596,7 @@ public abstract class RegularLevel extends Level { Room roomToSpawn = stdRoomIter.next(); Mob mob = Bestiary.mob( Dungeon.depth ); - mob.pos = roomToSpawn.random(); + mob.pos = pointToCell(roomToSpawn.random()); if (findMob(mob.pos) == null && Level.passable[mob.pos]) { mobsToSpawn--; @@ -604,7 +605,7 @@ public abstract class RegularLevel extends Level { //TODO: perhaps externalize this logic into a method. Do I want to make mobs more likely to clump deeper down? if (mobsToSpawn > 0 && Random.Int(4) == 0){ mob = Bestiary.mob( Dungeon.depth ); - mob.pos = roomToSpawn.random(); + mob.pos = pointToCell(roomToSpawn.random()); if (findMob(mob.pos) == null && Level.passable[mob.pos]) { mobsToSpawn--; @@ -631,7 +632,7 @@ public abstract class RegularLevel extends Level { continue; } - cell = room.random(); + cell = pointToCell(room.random()); if (!Dungeon.visible[cell] && Actor.findChar( cell ) == null && Level.passable[cell]) { return cell; } @@ -651,7 +652,7 @@ public abstract class RegularLevel extends Level { continue; } - cell = room.random(); + cell = pointToCell(room.random()); if (Level.passable[cell]) { return cell; } @@ -721,7 +722,7 @@ public abstract class RegularLevel extends Level { public Room room( int pos ) { for (Room room : rooms) { - if (room.type != Type.NULL && room.inside( pos )) { + if (room.type != Type.NULL && room.inside( cellToPoint(pos) )) { return room; } } @@ -733,7 +734,7 @@ public abstract class RegularLevel extends Level { while (true) { Room room = randomRoom( Room.Type.STANDARD, 1 ); if (room != null) { - int pos = room.random(); + int pos = pointToCell(room.random()); if (passable[pos]) { return pos; } @@ -745,7 +746,7 @@ public abstract class RegularLevel extends Level { public int pitCell() { for (Room room : rooms) { if (room.type == Type.PIT) { - return room.random(); + return pointToCell(room.random()); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Room.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Room.java index b0e3e0758..42a21d85c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Room.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/Room.java @@ -20,6 +20,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.levels; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.levels.painters.AltarPainter; import com.shatteredpixel.shatteredpixeldungeon.levels.painters.ArmoryPainter; @@ -133,14 +134,13 @@ public class Room extends Rect implements Graph.Node, Bundlable { public Type type = Type.NULL; - public int random() { + public Point random() { return random( 0 ); } - public int random( int m ) { - int x = Random.Int( left + 1 + m, right - m ); - int y = Random.Int( top + 1 + m, bottom - m ); - return x + y * Level.WIDTH; + public Point random( int m ) { + return new Point( Random.Int( left + 1 + m, right - m ), + Random.Int( top + 1 + m, bottom - m )); } public void addNeigbour( Room other ) { @@ -165,10 +165,8 @@ public class Room extends Rect implements Graph.Node, Bundlable { return connected.values().iterator().next(); } - public boolean inside( int p ) { - int x = p % Level.WIDTH; - int y = p / Level.WIDTH; - return x > left && y > top && x < right && y < bottom; + public boolean inside( Point p ) { + return p.x > left && p.y > top && p.x < right && p.y < bottom; } public Point center() { @@ -176,14 +174,6 @@ public class Room extends Rect implements Graph.Node, Bundlable { (left + right) / 2 + (((right - left) & 1) == 1 ? Random.Int( 2 ) : 0), (top + bottom) / 2 + (((bottom - top) & 1) == 1 ? Random.Int( 2 ) : 0) ); } - - public HashSet getCells(){ - HashSet points = getPoints(); - HashSet cells = new HashSet<>(); - for( Point point : points) - cells.add(point.x + point.y*Level.WIDTH); - return cells; - } // **** Graph.Node interface **** diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/SewerBossLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/SewerBossLevel.java index 819afc5cf..f8795ab0b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/SewerBossLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/SewerBossLevel.java @@ -34,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.watabou.noosa.Group; import com.watabou.utils.Bundle; import com.watabou.utils.Graph; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.ArrayList; @@ -159,12 +160,12 @@ public class SewerBossLevel extends RegularLevel { paint(); //sticks the exit in the room entrance. - exit = roomEntrance.top * Level.WIDTH + (roomEntrance.left + roomEntrance.right) / 2; + exit = roomEntrance.top * width() + (roomEntrance.left + roomEntrance.right) / 2; map[exit] = Terrain.LOCKED_EXIT; //make sure the exit is only visible in the entrance room. int count = 0; - for (int i : NEIGHBOURS8){ + for (int i : PathFinder.NEIGHBOURS8){ //exit must have exactly 3 non-wall tiles around it. if (map[exit+i] != Terrain.WALL) count++; @@ -180,23 +181,23 @@ public class SewerBossLevel extends RegularLevel { } protected boolean[] water() { - return Patch.generate( 0.5f, 5 ); + return Patch.generate( this, 0.5f, 5 ); } protected boolean[] grass() { - return Patch.generate( 0.40f, 4 ); + return Patch.generate( this, 0.40f, 4 ); } @Override protected void decorate() { - int start = roomExit.top * WIDTH + roomExit.left + 1; + int start = roomExit.top * width() + roomExit.left + 1; int end = start + roomExit.width() - 1; for (int i=start; i < end; i++) { if (i != exit && map[i] == Terrain.WALL) { map[i] = Terrain.WALL_DECO; - map[i + WIDTH] = Terrain.WATER; + map[i + width()] = Terrain.WATER; } else { - map[i + WIDTH] = Terrain.EMPTY; + map[i + width()] = Terrain.EMPTY; } } @@ -217,7 +218,7 @@ public class SewerBossLevel extends RegularLevel { do { room = Random.element(rooms); } while (room.type != Type.STANDARD); - mob.pos = room.random(); + mob.pos = pointToCell(room.random()); mobs.add( mob ); } @@ -231,7 +232,7 @@ public class SewerBossLevel extends RegularLevel { if (item != null) { int pos; do { - pos = roomEntrance.random(); + pos = pointToCell(roomEntrance.random()); } while (pos == entrance || map[pos] == Terrain.SIGN); drop( item, pos ).type = Heap.Type.REMAINS; } @@ -239,7 +240,7 @@ public class SewerBossLevel extends RegularLevel { @Override public int randomRespawnCell() { - return roomEntrance.random(); + return pointToCell(roomEntrance.random()); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/SewerLevel.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/SewerLevel.java index a95efc644..ac33fff76 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/SewerLevel.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/SewerLevel.java @@ -62,11 +62,11 @@ public class SewerLevel extends RegularLevel { } protected boolean[] water() { - return Patch.generate( feeling == Feeling.WATER ? 0.60f : 0.45f, 5 ); + return Patch.generate( this, feeling == Feeling.WATER ? 0.60f : 0.45f, 5 ); } protected boolean[] grass() { - return Patch.generate( feeling == Feeling.GRASS ? 0.60f : 0.40f, 4 ); + return Patch.generate( this, feeling == Feeling.GRASS ? 0.60f : 0.40f, 4 ); } @Override @@ -90,33 +90,33 @@ public class SewerLevel extends RegularLevel { @Override protected void decorate() { - for (int i=0; i < WIDTH; i++) { + for (int i=0; i < width(); i++) { if (map[i] == Terrain.WALL && - map[i + WIDTH] == Terrain.WATER && + map[i + width()] == Terrain.WATER && Random.Int( 4 ) == 0) { map[i] = Terrain.WALL_DECO; } } - for (int i=WIDTH; i < LENGTH - WIDTH; i++) { + for (int i=width(); i < length() - width(); i++) { if (map[i] == Terrain.WALL && - map[i - WIDTH] == Terrain.WALL && - map[i + WIDTH] == Terrain.WATER && + map[i - width()] == Terrain.WALL && + map[i + width()] == Terrain.WATER && Random.Int( 2 ) == 0) { map[i] = Terrain.WALL_DECO; } } - for (int i=WIDTH + 1; i < LENGTH - WIDTH - 1; i++) { + for (int i=width() + 1; i < length() - width() - 1; i++) { if (map[i] == Terrain.EMPTY) { int count = (map[i + 1] == Terrain.WALL ? 1 : 0) + (map[i - 1] == Terrain.WALL ? 1 : 0) + - (map[i + WIDTH] == Terrain.WALL ? 1 : 0) + - (map[i - WIDTH] == Terrain.WALL ? 1 : 0); + (map[i + width()] == Terrain.WALL ? 1 : 0) + + (map[i - width()] == Terrain.WALL ? 1 : 0); if (Random.Int( 16 ) < count * count) { map[i] = Terrain.EMPTY_DECO; @@ -129,7 +129,7 @@ public class SewerLevel extends RegularLevel { for (Room r : roomEntrance.connected.keySet()){ Room.Door d = roomEntrance.connected.get(r); if (d.type == Room.Door.Type.REGULAR) - map[d.x + d.y * WIDTH] = Terrain.SECRET_DOOR; + map[d.x + d.y * width()] = Terrain.SECRET_DOOR; } placeSign(); @@ -155,7 +155,7 @@ public class SewerLevel extends RegularLevel { } public static void addSewerVisuals( Level level, Group group ) { - for (int i=0; i < LENGTH; i++) { + for (int i=0; i < level.length(); i++) { if (level.map[i] == Terrain.WALL_DECO) { group.add( new Sink( i ) ); } @@ -216,7 +216,7 @@ public class SewerLevel extends RegularLevel { super.update(); if ((rippleDelay -= Game.elapsed) <= 0) { - Ripple ripple = GameScene.ripple( pos + WIDTH ); + Ripple ripple = GameScene.ripple( pos + Dungeon.level.width() ); if (ripple != null) { ripple.y -= DungeonTilemap.SIZE / 2; rippleDelay = Random.Float(0.2f, 0.3f); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/ArmoryPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/ArmoryPainter.java index b95002fb0..1f83d7ac1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/ArmoryPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/ArmoryPainter.java @@ -57,7 +57,7 @@ public class ArmoryPainter extends Painter { for (int i=0; i < n; i++) { int pos; do { - pos = room.random(); + pos = level.pointToCell(room.random()); } while (level.map[pos] != Terrain.EMPTY || level.heaps.get( pos ) != null); level.drop( prize( level ), pos ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/BlacksmithPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/BlacksmithPainter.java index 2a31aedbb..b010cdb15 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/BlacksmithPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/BlacksmithPainter.java @@ -26,6 +26,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.Room; import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.levels.traps.FireTrap; +import com.watabou.utils.Point; import com.watabou.utils.Random; public class BlacksmithPainter extends Painter { @@ -39,7 +40,7 @@ public class BlacksmithPainter extends Painter { for (int i=0; i < 2; i++) { int pos; do { - pos = room.random(); + pos = level.pointToCell(room.random()); } while (level.map[pos] != Terrain.EMPTY_SP); level.drop( Generator.random( Random.oneOf( @@ -55,11 +56,12 @@ public class BlacksmithPainter extends Painter { Blacksmith npc = new Blacksmith(); do { - npc.pos = room.random( 1 ); + npc.pos = level.pointToCell(room.random( 1 )); } while (level.heaps.get( npc.pos ) != null); level.mobs.add( npc ); - for(int cell : room.getCells()) { + for(Point p : room.getPoints()) { + int cell = level.pointToCell(p); if (level.map[cell] == Terrain.TRAP){ level.setTrap(new FireTrap().reveal(), cell); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/BossExitPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/BossExitPainter.java index 047734fea..153b6f100 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/BossExitPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/BossExitPainter.java @@ -35,7 +35,7 @@ public class BossExitPainter extends Painter { door.set( Room.Door.Type.REGULAR ); } - level.exit = room.top * Level.WIDTH + (room.left + room.right) / 2; + level.exit = room.top * level.width() + (room.left + room.right) / 2; set( level, level.exit, Terrain.LOCKED_EXIT ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/CryptPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/CryptPainter.java index 9ca8a7b10..6eb6ce96c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/CryptPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/CryptPainter.java @@ -65,7 +65,7 @@ public class CryptPainter extends Painter { cy = room.top + 2; } - level.drop( prize( level ), cx + cy * Level.WIDTH ).type = Type.TOMB; + level.drop( prize( level ), cx + cy * level.width() ).type = Type.TOMB; } private static Item prize( Level level ) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/EntrancePainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/EntrancePainter.java index fcfd3d7aa..f36950513 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/EntrancePainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/EntrancePainter.java @@ -36,7 +36,7 @@ public class EntrancePainter extends Painter { } do { - level.entrance = room.random(1); + level.entrance = level.pointToCell(room.random(1)); } while (level.findMob(level.entrance) != null); set( level, level.entrance, Terrain.ENTRANCE ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/ExitPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/ExitPainter.java index ca629a81e..87ca5e29c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/ExitPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/ExitPainter.java @@ -35,7 +35,7 @@ public class ExitPainter extends Painter { door.set( Room.Door.Type.REGULAR ); } - level.exit = room.random( 1 ); + level.exit = level.pointToCell(room.random( 1 )); set( level, level.exit, Terrain.EXIT ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/GardenPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/GardenPainter.java index 1f7ccac17..3a072aabd 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/GardenPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/GardenPainter.java @@ -42,17 +42,17 @@ public class GardenPainter extends Painter { if (Dungeon.isChallenged(Challenges.NO_FOOD)) { if (Random.Int(2) == 0){ - level.plant(new Sungrass.Seed(), room.random()); + level.plant(new Sungrass.Seed(), level.pointToCell(room.random())); } } else { int bushes = Random.Int(3); if (bushes == 0) { - level.plant(new Sungrass.Seed(), room.random()); + level.plant(new Sungrass.Seed(), level.pointToCell(room.random())); } else if (bushes == 1) { - level.plant(new BlandfruitBush.Seed(), room.random()); + level.plant(new BlandfruitBush.Seed(), level.pointToCell(room.random())); } else if (Random.Int(5) == 0) { - level.plant(new Sungrass.Seed(), room.random()); - level.plant(new BlandfruitBush.Seed(), room.random()); + level.plant(new Sungrass.Seed(), level.pointToCell(room.random())); + level.plant(new BlandfruitBush.Seed(), level.pointToCell(room.random())); } } @@ -62,7 +62,7 @@ public class GardenPainter extends Painter { } for (int i=room.top + 1; i < room.bottom; i++) { for (int j=room.left + 1; j < room.right; j++) { - light.seed( j + Level.WIDTH * i, 1 ); + light.seed( level, j + level.width() * i, 1 ); } } level.blobs.put( Foliage.class, light ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/LaboratoryPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/LaboratoryPainter.java index f777d3463..e0fbae929 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/LaboratoryPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/LaboratoryPainter.java @@ -54,14 +54,14 @@ public class LaboratoryPainter extends Painter { set( level, pot, Terrain.ALCHEMY ); Alchemy alchemy = new Alchemy(); - alchemy.seed( pot.x + Level.WIDTH * pot.y, 1 ); + alchemy.seed( level, pot.x + level.width() * pot.y, 1 ); level.blobs.put( Alchemy.class, alchemy ); int n = Random.IntRange( 2, 3 ); for (int i=0; i < n; i++) { int pos; do { - pos = room.random(); + pos = level.pointToCell(room.random()); } while ( level.map[pos] != Terrain.EMPTY_SP || level.heaps.get( pos ) != null); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/LibraryPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/LibraryPainter.java index 9f84b6322..760c70b31 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/LibraryPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/LibraryPainter.java @@ -61,10 +61,10 @@ public class LibraryPainter extends Painter { b = new Point( entrance.x-1, room.bottom-1 ); fill( level, room.left + 1, room.top+1, room.width() - 1, 1 , Terrain.BOOKSHELF ); } - if (a != null && level.map[a.x + a.y * Level.WIDTH] == Terrain.EMPTY) { + if (a != null && level.map[a.x + a.y * level.width()] == Terrain.EMPTY) { set( level, a, Terrain.STATUE ); } - if (b != null && level.map[b.x + b.y * Level.WIDTH] == Terrain.EMPTY) { + if (b != null && level.map[b.x + b.y * level.width()] == Terrain.EMPTY) { set( level, b, Terrain.STATUE ); } @@ -72,7 +72,7 @@ public class LibraryPainter extends Painter { for (int i=0; i < n; i++) { int pos; do { - pos = room.random(); + pos = level.pointToCell(room.random()); } while (level.map[pos] != Terrain.EMPTY || level.heaps.get( pos ) != null); Item item; if (i == 0) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/MagicWellPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/MagicWellPainter.java index 2e629bd10..bebfeb4f1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/MagicWellPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/MagicWellPainter.java @@ -64,7 +64,7 @@ public class MagicWellPainter extends Painter { return; } } - water.seed( c.x + Level.WIDTH * c.y, 1 ); + water.seed( level, c.x + level.width() * c.y, 1 ); level.blobs.put( waterClass, water ); room.entrance().set( Room.Door.Type.REGULAR ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/MassGravePainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/MassGravePainter.java index 9b229e65e..8f6462026 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/MassGravePainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/MassGravePainter.java @@ -56,7 +56,7 @@ public class MassGravePainter extends Painter { int pos; do { - pos = room.random(); + pos = level.pointToCell(room.random()); } while (level.map[pos] != Terrain.EMPTY_SP || level.findMob(pos) != null); skele.pos = pos; level.mobs.add( skele ); @@ -75,7 +75,7 @@ public class MassGravePainter extends Painter { for (Item item : items){ int pos; do { - pos = room.random(); + pos = level.pointToCell(room.random()); } while (level.map[pos] != Terrain.EMPTY_SP || level.heaps.get(pos) != null); Heap h = level.drop(item, pos); h.type = Heap.Type.SKELETON; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/Painter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/Painter.java index 245fd1976..2bd3d30e8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/Painter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/Painter.java @@ -34,7 +34,7 @@ public class Painter { } public static void set( Level level, int x, int y, int value ) { - set( level, x + y * Level.WIDTH, value ); + set( level, x + y * level.width(), value ); } public static void set( Level level, Point p, int value ) { @@ -43,7 +43,7 @@ public class Painter { public static void fill( Level level, int x, int y, int w, int h, int value ) { - int width = Level.WIDTH; + int width = level.width(); int pos = y * width + x; for (int i=y; i < y + h; i++, pos += width) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/PitPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/PitPainter.java index ac58f4113..9170e6776 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/PitPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/PitPainter.java @@ -53,9 +53,9 @@ public class PitPainter extends Painter { } set( level, well, Terrain.EMPTY_WELL ); - int remains = room.random(); + int remains = level.pointToCell(room.random()); while (level.map[remains] == Terrain.EMPTY_WELL) { - remains = room.random(); + remains = level.pointToCell(room.random()); } level.drop( new IronKey( Dungeon.depth ), remains ).type = Type.SKELETON; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/PoolPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/PoolPainter.java index daec26105..5213dd618 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/PoolPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/PoolPainter.java @@ -68,7 +68,7 @@ public class PoolPainter extends Painter { } - int pos = x + y * Level.WIDTH; + int pos = x + y * level.width(); level.drop( prize( level ), pos ).type = Random.Int( 3 ) == 0 ? Heap.Type.CHEST : Heap.Type.HEAP; set( level, pos, Terrain.PEDESTAL ); @@ -78,7 +78,7 @@ public class PoolPainter extends Painter { for (int i=0; i < NPIRANHAS; i++) { Piranha piranha = new Piranha(); do { - piranha.pos = room.random(); + piranha.pos = level.pointToCell(room.random()); } while (level.map[piranha.pos] != Terrain.WATER|| level.findMob( piranha.pos ) != null); level.mobs.add( piranha ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RatKingPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RatKingPainter.java index c8779ce92..b73565c21 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RatKingPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RatKingPainter.java @@ -38,20 +38,20 @@ public class RatKingPainter extends Painter { Room.Door entrance = room.entrance(); entrance.set( Room.Door.Type.HIDDEN ); - int door = entrance.x + entrance.y * Level.WIDTH; + int door = entrance.x + entrance.y * level.width(); for (int i=room.left + 1; i < room.right; i++) { - addChest( level, (room.top + 1) * Level.WIDTH + i, door ); - addChest( level, (room.bottom - 1) * Level.WIDTH + i, door ); + addChest( level, (room.top + 1) * level.width() + i, door ); + addChest( level, (room.bottom - 1) * level.width() + i, door ); } for (int i=room.top + 2; i < room.bottom - 1; i++) { - addChest( level, i * Level.WIDTH + room.left + 1, door ); - addChest( level, i * Level.WIDTH + room.right - 1, door ); + addChest( level, i * level.width() + room.left + 1, door ); + addChest( level, i * level.width() + room.right - 1, door ); } RatKing king = new RatKing(); - king.pos = room.random( 1 ); + king.pos = level.pointToCell(room.random( 1 )); level.mobs.add( king ); } @@ -59,8 +59,8 @@ public class RatKingPainter extends Painter { if (pos == door - 1 || pos == door + 1 || - pos == door - Level.WIDTH || - pos == door + Level.WIDTH) { + pos == door - level.width() || + pos == door + level.width()) { return; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RitualSitePainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RitualSitePainter.java index 6da3d6cab..6e359f8b0 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RitualSitePainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RitualSitePainter.java @@ -53,7 +53,7 @@ public class RitualSitePainter extends Painter { level.addItemToSpawn(new CeremonialCandle()); level.addItemToSpawn(new CeremonialCandle()); - CeremonialCandle.ritualPos = c.x + (Level.WIDTH * c.y); + CeremonialCandle.ritualPos = c.x + (level.width() * c.y); } public static class RitualMarker extends CustomTileVisual{ diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RotGardenPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RotGardenPainter.java index 265790718..5eb07e104 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RotGardenPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/RotGardenPainter.java @@ -28,6 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.Room; import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; public class RotGardenPainter extends Painter { @@ -55,14 +56,14 @@ public class RotGardenPainter extends Painter { heartY = room.top + 1; } - placePlant(level, heartX + heartY * Level.WIDTH, new RotHeart()); + placePlant(level, heartX + heartY * level.width(), new RotHeart()); int lashers = ((room.right-room.left-1)*(room.bottom-room.top-1))/8; for (int i = 1; i <= lashers; i++){ int pos; do { - pos = room.random(); + pos = level.pointToCell(room.random()); } while (!validPlantPos(level, pos)); placePlant(level, pos, new RotLasher()); } @@ -73,7 +74,7 @@ public class RotGardenPainter extends Painter { return false; } - for (int i : Level.NEIGHBOURS9){ + for (int i : PathFinder.NEIGHBOURS9){ if (level.findMob(pos+i) != null){ return false; } @@ -86,7 +87,7 @@ public class RotGardenPainter extends Painter { plant.pos = pos; level.mobs.add( plant ); - for(int i : Level.NEIGHBOURS8) { + for(int i : PathFinder.NEIGHBOURS8) { if (level.map[pos + i] == Terrain.GRASS){ set(level, pos + i, Terrain.HIGH_GRASS); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/ShopPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/ShopPainter.java index 8826d33cc..c209384a3 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/ShopPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/ShopPainter.java @@ -70,6 +70,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.Room; import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.plants.Plant; +import com.watabou.utils.PathFinder; import com.watabou.utils.Point; import com.watabou.utils.Random; @@ -99,11 +100,11 @@ public class ShopPainter extends Painter { for (Item item : itemsToSpawn) { Point xy = p2xy( room, (pos + per) % per ); - int cell = xy.x + xy.y * Level.WIDTH; + int cell = xy.x + xy.y * level.width(); if (level.heaps.get( cell ) != null) { do { - cell = room.random(); + cell = level.pointToCell(room.random()); } while (level.heaps.get( cell ) != null); } @@ -304,7 +305,7 @@ public class ShopPainter extends Painter { int pos; do { - pos = room.random(); + pos = level.pointToCell(room.random()); } while (level.heaps.get( pos ) != null); Mob shopkeeper = level instanceof LastShopLevel ? new ImpShopkeeper() : new Shopkeeper(); @@ -312,8 +313,8 @@ public class ShopPainter extends Painter { level.mobs.add( shopkeeper ); if (level instanceof LastShopLevel) { - for (int i=0; i < Level.NEIGHBOURS9.length; i++) { - int p = shopkeeper.pos + Level.NEIGHBOURS9[i]; + for (int i = 0; i < PathFinder.NEIGHBOURS9.length; i++) { + int p = shopkeeper.pos + PathFinder.NEIGHBOURS9[i]; if (level.map[p] == Terrain.EMPTY_SP) { level.map[p] = Terrain.WATER; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/StandardPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/StandardPainter.java index cb6393718..a6f6f52d6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/StandardPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/StandardPainter.java @@ -97,7 +97,7 @@ public class StandardPainter extends Painter { private static void paintBurned( Level level, Room room ) { for (int i=room.top + 1; i < room.bottom; i++) { for (int j=room.left + 1; j < room.right; j++) { - int cell = i * Level.WIDTH + j; + int cell = i * level.width() + j; int t = Terrain.EMBERS; switch (Random.Int( 5 )) { case 0: @@ -135,8 +135,8 @@ public class StandardPainter extends Painter { int shift = Random.Int( 2 ); for (int i=0; i < nGraves; i++) { int pos = w > h ? - room.left + 1 + shift + i * 2 + (room.top + 2 + Random.Int( h-2 )) * Level.WIDTH : - (room.left + 2 + Random.Int( w-2 )) + (room.top + 1 + shift + i * 2) * Level.WIDTH; + room.left + 1 + shift + i * 2 + (room.top + 2 + Random.Int( h-2 )) * level.width() : + (room.left + 2 + Random.Int( w-2 )) + (room.top + 1 + shift + i * 2) * level.width(); level.drop( i == index ? Generator.random() : new Gold().random(), pos ).type = Heap.Type.TOMB; } } @@ -176,14 +176,14 @@ public class StandardPainter extends Painter { if (Random.Int(2) != 0){ Item prize = level.findPrizeItem(); if (prize != null) { - level.drop(prize, (room.center().x + center.y * level.WIDTH)); + level.drop(prize, (room.center().x + center.y * level.width())); return; } } level.drop(Generator.random( Random.oneOf( Generator.Category.POTION, - Generator.Category.SCROLL)), (room.center().x + center.y * level.WIDTH)); + Generator.Category.SCROLL)), (room.center().x + center.y * level.width())); } private static void paintBridge( Level level, Room room ) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/StatuePainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/StatuePainter.java index ed8e2e800..9b16c2522 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/StatuePainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/StatuePainter.java @@ -67,7 +67,7 @@ public class StatuePainter extends Painter { } Statue statue = new Statue(); - statue.pos = cx + cy * Level.WIDTH; + statue.pos = cx + cy * level.width(); level.mobs.add( statue ); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/StoragePainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/StoragePainter.java index 77fc9344e..b121442ba 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/StoragePainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/StoragePainter.java @@ -44,7 +44,7 @@ public class StoragePainter extends Painter { for (int i=0; i < n; i++) { int pos; do { - pos = room.random(); + pos = level.pointToCell(room.random()); } while (level.map[pos] != floor); if (honeyPot){ level.drop( new Honeypot(), pos); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/TrapsPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/TrapsPainter.java index 54b14d37c..e73cbb064 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/TrapsPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/TrapsPainter.java @@ -43,6 +43,7 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.traps.ToxicTrap; import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap; import com.shatteredpixel.shatteredpixeldungeon.levels.traps.VenomTrap; import com.shatteredpixel.shatteredpixeldungeon.levels.traps.WarpingTrap; +import com.watabou.utils.Point; import com.watabou.utils.Random; public class TrapsPainter extends Painter { @@ -73,7 +74,7 @@ public class TrapsPainter extends Painter { Room.Door door = room.entrance(); door.set( Room.Door.Type.REGULAR ); - int lastRow = level.map[room.left + 1 + (room.top + 1) * Level.WIDTH] == Terrain.CHASM ? Terrain.CHASM : Terrain.EMPTY; + int lastRow = level.map[room.left + 1 + (room.top + 1) * level.width()] == Terrain.CHASM ? Terrain.CHASM : Terrain.EMPTY; int x = -1; int y = -1; @@ -95,7 +96,8 @@ public class TrapsPainter extends Painter { fill( level, room.left + 1, y, room.width() - 1, 1 , lastRow ); } - for(int cell : room.getCells()) { + for(Point p : room.getPoints()) { + int cell = level.pointToCell(p); if (level.map[cell] == Terrain.TRAP){ try { level.setTrap(((Trap) trapClass.newInstance()).reveal(), cell); @@ -105,7 +107,7 @@ public class TrapsPainter extends Painter { } } - int pos = x + y * Level.WIDTH; + int pos = x + y * level.width(); if (Random.Int( 3 ) == 0) { if (lastRow == Terrain.CHASM) { set( level, pos, Terrain.EMPTY ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/TreasuryPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/TreasuryPainter.java index 48a588fcc..c1b5007a3 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/TreasuryPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/TreasuryPainter.java @@ -44,7 +44,7 @@ public class TreasuryPainter extends Painter { for (int i=0; i < n; i++) { int pos; do { - pos = room.random(); + pos = level.pointToCell(room.random()); } while (level.map[pos] != Terrain.EMPTY || level.heaps.get( pos ) != null); level.drop( new Gold().random(), pos ).type = (Random.Int(20) == 0 && heapType == Heap.Type.CHEST ? Heap.Type.MIMIC : heapType); } @@ -53,7 +53,7 @@ public class TreasuryPainter extends Painter { for (int i=0; i < 6; i++) { int pos; do { - pos = room.random(); + pos = level.pointToCell(room.random()); } while (level.map[pos] != Terrain.EMPTY); level.drop( new Gold( Random.IntRange( 5, 12 ) ), pos ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/VaultPainter.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/VaultPainter.java index 698988014..f5000af64 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/VaultPainter.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/painters/VaultPainter.java @@ -29,6 +29,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.Room; import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; public class VaultPainter extends Painter { @@ -41,7 +42,7 @@ public class VaultPainter extends Painter { int cx = (room.left + room.right) / 2; int cy = (room.top + room.bottom) / 2; - int c = cx + cy * Level.WIDTH; + int c = cx + cy * level.width(); switch (Random.Int( 3 )) { @@ -57,7 +58,7 @@ public class VaultPainter extends Painter { i2 = prize( level ); } while (i1.getClass() == i2.getClass()); level.drop( i1, c ).type = Type.CRYSTAL_CHEST; - level.drop( i2, c + Level.NEIGHBOURS8[Random.Int( 8 )]).type = Type.CRYSTAL_CHEST; + level.drop( i2, c + PathFinder.NEIGHBOURS8[Random.Int( 8 )]).type = Type.CRYSTAL_CHEST; level.addItemToSpawn( new GoldenKey( Dungeon.depth ) ); break; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/BlazingTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/BlazingTrap.java index 5f493bb9b..46f447ba7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/BlazingTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/BlazingTrap.java @@ -21,6 +21,7 @@ package com.shatteredpixel.shatteredpixeldungeon.levels.traps; import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Fire; import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter; @@ -28,7 +29,9 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.particles.FlameParticle; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.TrapSprite; +import com.shatteredpixel.shatteredpixeldungeon.utils.BArray; import com.watabou.noosa.audio.Sample; +import com.watabou.utils.PathFinder; public class BlazingTrap extends Trap { @@ -40,14 +43,14 @@ public class BlazingTrap extends Trap { @Override public void activate() { - for (int i : Level.NEIGHBOURS9DIST2){ - if (Level.insideMap(pos+i) && !Level.solid[pos+i]) { - if (Level.pit[pos+i] || Level.water[pos+i]) - GameScene.add(Blob.seed(pos + i, 1, Fire.class)); + PathFinder.buildDistanceMap( pos, BArray.not( Level.solid, null ), 2 ); + for (int i = 0; i < PathFinder.distance.length; i++) { + if (PathFinder.distance[i] < Integer.MAX_VALUE) + if (Level.pit[i] || Level.water[i]) + GameScene.add(Blob.seed( i, 1, Fire.class)); else - GameScene.add(Blob.seed(pos + i, 5, Fire.class)); - CellEmitter.get(pos + i).burst(FlameParticle.FACTORY, 5); - } + GameScene.add(Blob.seed( i, 5, Fire.class)); + CellEmitter.get(i).burst(FlameParticle.FACTORY, 5); } Sample.INSTANCE.play(Assets.SND_BURNING); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DisarmingTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DisarmingTrap.java index a02b6cd36..851e34ecb 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DisarmingTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DisarmingTrap.java @@ -34,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.sprites.TrapSprite; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.watabou.noosa.audio.Sample; +import com.watabou.utils.PathFinder; public class DisarmingTrap extends Trap{ @@ -52,7 +53,7 @@ public class DisarmingTrap extends Trap{ if (cell != -1) { Item item = heap.pickUp(); Dungeon.level.drop( item, cell ).seen = true; - for (int i : Level.NEIGHBOURS9) + for (int i : PathFinder.NEIGHBOURS9) Dungeon.level.visited[cell+i] = true; Dungeon.observe(); @@ -74,7 +75,7 @@ public class DisarmingTrap extends Trap{ weapon.updateQuickslot(); Dungeon.level.drop(weapon, cell).seen = true; - for (int i : Level.NEIGHBOURS9) + for (int i : PathFinder.NEIGHBOURS9) Dungeon.level.visited[cell+i] = true; Dungeon.observe(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DisintegrationTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DisintegrationTrap.java index dcbe524c6..75c17944f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DisintegrationTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/DisintegrationTrap.java @@ -50,8 +50,8 @@ public class DisintegrationTrap extends Trap { if (Dungeon.visible[ pos ]) { sprite.parent.add( new Beam.DeathRay( DungeonTilemap.tileCenterToWorld(pos-1), DungeonTilemap.tileCenterToWorld(pos+1))); - sprite.parent.add(new Beam.DeathRay(DungeonTilemap.tileCenterToWorld(pos - Level.WIDTH), - DungeonTilemap.tileCenterToWorld(pos + Level.WIDTH))); + sprite.parent.add(new Beam.DeathRay(DungeonTilemap.tileCenterToWorld(pos - Dungeon.level.width()), + DungeonTilemap.tileCenterToWorld(pos + Dungeon.level.width()))); Sample.INSTANCE.play( Assets.SND_RAY ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/FlockTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/FlockTrap.java index 04d434f29..44e99c145 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/FlockTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/FlockTrap.java @@ -29,7 +29,9 @@ import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.TrapSprite; +import com.shatteredpixel.shatteredpixeldungeon.utils.BArray; import com.watabou.noosa.audio.Sample; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; public class FlockTrap extends Trap { @@ -48,16 +50,16 @@ public class FlockTrap extends Trap { { actPriority = 3; } protected boolean act() { - int cell; - for (int i : Level.NEIGHBOURS9DIST2) { - cell = pos + i; - if (Level.insideMap(cell) && Actor.findChar(cell) == null && !(Level.solid[cell] || Level.pit[cell])) { + PathFinder.buildDistanceMap( pos, BArray.not( Level.solid, null ), 2 ); + for (int i = 0; i < PathFinder.distance.length; i++) { + if (PathFinder.distance[i] < Integer.MAX_VALUE) + if (Dungeon.level.insideMap(i) && Actor.findChar(i) == null && !(Level.pit[i])) { Sheep sheep = new Sheep(); sheep.lifespan = 2 + Random.Int(Dungeon.depth + 10); - sheep.pos = cell; + sheep.pos = i; GameScene.add(sheep); } - CellEmitter.get(cell).burst(Speck.factory(Speck.WOOL), 4); + CellEmitter.get(i).burst(Speck.factory(Speck.WOOL), 4); } Sample.INSTANCE.play(Assets.SND_PUFF); Actor.remove(this); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/GrimTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/GrimTrap.java index 2d99e5b33..4937e65ae 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/GrimTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/GrimTrap.java @@ -57,7 +57,7 @@ public class GrimTrap extends Trap { for (Char ch : Actor.chars()){ Ballistica bolt = new Ballistica(pos, ch.pos, Ballistica.PROJECTILE); if (bolt.collisionPos == ch.pos && - (target == null || Level.distance(pos, ch.pos) < Level.distance(pos, target.pos))){ + (target == null || Dungeon.level.distance(pos, ch.pos) < Dungeon.level.distance(pos, target.pos))){ target = ch; } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/LightningTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/LightningTrap.java index cfe3b5c5f..093a1db26 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/LightningTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/LightningTrap.java @@ -63,7 +63,7 @@ public class LightningTrap extends Trap { } ArrayList arcs = new ArrayList<>(); - arcs.add(new Lightning.Arc(pos - Level.WIDTH, pos + Level.WIDTH)); + arcs.add(new Lightning.Arc(pos - Dungeon.level.width(), pos + Dungeon.level.width())); arcs.add(new Lightning.Arc(pos - 1, pos + 1)); ch.sprite.parent.add( new Lightning( arcs, null ) ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/PitfallTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/PitfallTrap.java index 8c36bd3db..92a5b39e1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/PitfallTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/PitfallTrap.java @@ -67,10 +67,10 @@ public class PitfallTrap extends Trap { super.disarm(); //if making a pit here wouldn't block any paths, make a pit tile instead of a disarmed trap tile. - if (!(Dungeon.level.solid[pos - Level.WIDTH] && Dungeon.level.solid[pos + Level.WIDTH]) + if (!(Dungeon.level.solid[pos - Dungeon.level.width()] && Dungeon.level.solid[pos + Dungeon.level.width()]) && !(Dungeon.level.solid[pos - 1]&& Dungeon.level.solid[pos + 1])){ - int c = Dungeon.level.map[pos - Level.WIDTH]; + int c = Dungeon.level.map[pos - Dungeon.level.width()]; if (c == Terrain.WALL || c == Terrain.WALL_DECO) { Level.set(pos, Terrain.CHASM_WALL); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/RockfallTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/RockfallTrap.java index 3ab31b369..d2c807fcf 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/RockfallTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/RockfallTrap.java @@ -34,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.TrapSprite; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.watabou.noosa.Camera; import com.watabou.noosa.audio.Sample; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; public class RockfallTrap extends Trap { @@ -48,13 +49,13 @@ public class RockfallTrap extends Trap { boolean seen = false; - for (int i : Level.NEIGHBOURS9){ + for (int i : PathFinder.NEIGHBOURS9){ if (Level.solid[pos+i]) continue; if (Dungeon.visible[ pos+i ]){ - CellEmitter.get( pos + i - Level.WIDTH ).start(Speck.factory(Speck.ROCK), 0.07f, 10); + CellEmitter.get( pos + i - Dungeon.level.width() ).start(Speck.factory(Speck.ROCK), 0.07f, 10); if (!seen) { Camera.main.shake(3, 0.7f); Sample.INSTANCE.play(Assets.SND_ROCKS); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/SummoningTrap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/SummoningTrap.java index 0b098cbe6..ffd9a3dfe 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/SummoningTrap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/levels/traps/SummoningTrap.java @@ -28,6 +28,7 @@ import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportat import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.sprites.TrapSprite; +import com.watabou.utils.PathFinder; import com.watabou.utils.Random; import java.util.ArrayList; @@ -58,8 +59,8 @@ public class SummoningTrap extends Trap { ArrayList candidates = new ArrayList<>(); - for (int i=0; i < Level.NEIGHBOURS8.length; i++) { - int p = pos + Level.NEIGHBOURS8[i]; + for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) { + int p = pos + PathFinder.NEIGHBOURS8[i]; if (Actor.findChar( p ) == null && (Level.passable[p] || Level.avoid[p])) { candidates.add( p ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/mechanics/Ballistica.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/mechanics/Ballistica.java index 0dbde3b20..3eaa39789 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/mechanics/Ballistica.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/mechanics/Ballistica.java @@ -20,6 +20,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.mechanics; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; @@ -58,7 +59,7 @@ public class Ballistica { } private void build( int from, int to, boolean stopTarget, boolean stopChars, boolean stopTerrain ) { - int w = Level.WIDTH; + int w = Dungeon.level.width(); int x0 = from % w; int x1 = to % w; @@ -98,7 +99,7 @@ public class Ballistica { int cell = from; int err = dA / 2; - while (Level.insideMap(cell)) { + while (Dungeon.level.insideMap(cell)) { //if we're in a wall, collide with the previous cell along the path. if (stopTerrain && cell != sourcePos && !Level.passable[cell] && !Level.avoid[cell]) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/mechanics/ShadowCaster.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/mechanics/ShadowCaster.java index 9943055e3..fc6a7b7a6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/mechanics/ShadowCaster.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/mechanics/ShadowCaster.java @@ -20,6 +20,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.mechanics; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import java.util.Arrays; @@ -28,9 +29,6 @@ public final class ShadowCaster { private static final int MAX_DISTANCE = 8; - private static final int WIDTH = Level.WIDTH; - private static final int HEIGHT = Level.HEIGHT; - private static int distance; private static int limits[]; @@ -59,7 +57,7 @@ public final class ShadowCaster { ShadowCaster.fieldOfView = fieldOfView; Arrays.fill( fieldOfView, false ); - fieldOfView[y * WIDTH + x] = true; + fieldOfView[y * Dungeon.level.width() + x] = true; scanSector( x, y, +1, +1, 0, 0 ); scanSector( x, y, -1, +1, 0, 0 ); @@ -85,13 +83,13 @@ public final class ShadowCaster { int x = cx + q * m1 + p * m3; int y = cy + p * m2 + q * m4; - if (y >= 0 && y < HEIGHT && x >= 0 && x < WIDTH) { + if (y >= 0 && y < Dungeon.level.height() && x >= 0 && x < Dungeon.level.width()) { float a0 = (float)q / p; float a1 = a0 - dq2; float a2 = a0 + dq2; - int pos = y * WIDTH + x; + int pos = y * Dungeon.level.width() + x; if (obs.isBlocked( a0 ) && obs.isBlocked( a1 ) && obs.isBlocked( a2 )) { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/plants/Icecap.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/plants/Icecap.java index 56a136db8..dca67437e 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/plants/Icecap.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/plants/Icecap.java @@ -42,7 +42,7 @@ public class Icecap extends Plant { Fire fire = (Fire)Dungeon.level.blobs.get( Fire.class ); - for (int i=0; i < Level.LENGTH; i++) { + for (int i=0; i < PathFinder.distance.length; i++) { if (PathFinder.distance[i] < Integer.MAX_VALUE) { Freezing.affect( i, fire ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java index 40afdd33b..fc59dc874 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java @@ -158,8 +158,8 @@ public class GameScene extends PixelScene { add( terrain ); water = new SkinnedBlock( - Level.WIDTH * DungeonTilemap.SIZE, - Level.HEIGHT * DungeonTilemap.SIZE, + Dungeon.level.width() * DungeonTilemap.SIZE, + Dungeon.level.height() * DungeonTilemap.SIZE, Dungeon.level.waterTex() ); terrain.add( water ); @@ -228,7 +228,7 @@ public class GameScene extends PixelScene { addBlobSprite( blob ); } - fog = new FogOfWar( Level.WIDTH, Level.HEIGHT ); + fog = new FogOfWar( Dungeon.level.width(), Dungeon.level.height() ); fog.updateVisibility( Dungeon.visible, Dungeon.level.visited, Dungeon.level.mapped ); add( fog ); @@ -664,20 +664,20 @@ public class GameScene extends PixelScene { public static void resetMap() { if (scene != null) { - scene.tiles.map(Dungeon.level.map, Level.WIDTH ); + scene.tiles.map(Dungeon.level.map, Dungeon.level.width() ); } } public static void updateMap() { if (scene != null) { - scene.tiles.updated.set( 0, 0, Level.WIDTH, Level.HEIGHT ); + scene.tiles.updated.set( 0, 0, Dungeon.level.width(), Dungeon.level.height() ); } } public static void updateMap( int cell ) { if (scene != null) { - scene.tiles.updated.union( cell % Level.WIDTH, cell / Level.WIDTH ); + scene.tiles.updated.union( cell % Dungeon.level.width(), cell / Dungeon.level.width() ); } } @@ -785,7 +785,7 @@ public class GameScene extends PixelScene { return; } - if (cell < 0 || cell > Level.LENGTH || (!Dungeon.level.visited[cell] && !Dungeon.level.mapped[cell])) { + if (cell < 0 || cell > Dungeon.level.length() || (!Dungeon.level.visited[cell] && !Dungeon.level.mapped[cell])) { GameScene.show( new WndMessage( Messages.get(GameScene.class, "dont_know") ) ) ; return; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java index aa3ea76fd..7f066e210 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java @@ -240,7 +240,7 @@ public class InterlevelScene extends PixelScene { Dungeon.saveAll(); Dungeon.depth = returnDepth; Level level = Dungeon.loadLevel( Dungeon.hero.heroClass ); - Dungeon.switchLevel( level, Level.resizingNeeded ? level.adjustPos( returnPos ) : returnPos ); + Dungeon.switchLevel( level, returnPos ); } private void restore() throws IOException { @@ -255,7 +255,7 @@ public class InterlevelScene extends PixelScene { Dungeon.switchLevel( Dungeon.loadLevel( StartScene.curClass ), -1 ); } else { Level level = Dungeon.loadLevel( StartScene.curClass ); - Dungeon.switchLevel( level, Level.resizingNeeded ? level.adjustPos( Dungeon.hero.pos ) : Dungeon.hero.pos ); + Dungeon.switchLevel( level, Dungeon.hero.pos ); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/BlacksmithSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/BlacksmithSprite.java index 61926d38a..391f50c18 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/BlacksmithSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/BlacksmithSprite.java @@ -77,7 +77,7 @@ public class BlacksmithSprite extends MobSprite { if (visible && emitter != null && anim == idle) { emitter.burst( Speck.factory( Speck.FORGE ), 3 ); - float volume = 0.2f / (Level.distance( ch.pos, Dungeon.hero.pos )); + float volume = 0.2f / (Dungeon.level.distance( ch.pos, Dungeon.hero.pos )); Sample.INSTANCE.play( Assets.SND_EVOKE, volume, volume, 0.8f ); } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java index 23a85ea2f..55d83c3f1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java @@ -21,6 +21,7 @@ package com.shatteredpixel.shatteredpixeldungeon.sprites; import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.DungeonTilemap; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.effects.DarkBlock; @@ -109,7 +110,7 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip ch.sprite = this; place( ch.pos ); - turnTo( ch.pos, Random.Int( Level.LENGTH ) ); + turnTo( ch.pos, Random.Int( Dungeon.level.length() ) ); ch.updateSpriteState(); } @@ -119,8 +120,8 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip final int csize = DungeonTilemap.SIZE; return new PointF( - PixelScene.align(Camera.main, ((cell % Level.WIDTH) + 0.5f) * csize - width * 0.5f), - PixelScene.align(Camera.main, ((cell / Level.WIDTH) + 1.0f) * csize - height) + PixelScene.align(Camera.main, ((cell % Dungeon.level.width()) + 0.5f) * csize - width * 0.5f), + PixelScene.align(Camera.main, ((cell / Dungeon.level.width()) + 1.0f) * csize - height) ); } @@ -191,8 +192,8 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip } public void turnTo( int from, int to ) { - int fx = from % Level.WIDTH; - int tx = to % Level.WIDTH; + int fx = from % Dungeon.level.width(); + int tx = to % Dungeon.level.width(); if (tx > fx) { flipHorizontal = false; } else if (tx < fx) { @@ -203,7 +204,7 @@ public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip public void jump( int from, int to, Callback callback ) { jumpCallback = callback; - int distance = Level.distance( from, to ); + int distance = Dungeon.level.distance( from, to ); jumpTweener = new JumpTweener( this, worldToCamera( to ), distance * 4, distance * 0.1f ); jumpTweener.listener = this; parent.add( jumpTweener ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/GnollTricksterSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/GnollTricksterSprite.java index ee5fd7d91..af580804f 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/GnollTricksterSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/GnollTricksterSprite.java @@ -21,6 +21,7 @@ package com.shatteredpixel.shatteredpixeldungeon.sprites; import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.CurareDart; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.watabou.noosa.MovieClip; @@ -57,7 +58,7 @@ public class GnollTricksterSprite extends MobSprite { @Override public void attack( int cell ) { - if (!Level.adjacent(cell, ch.pos)) { + if (!Dungeon.level.adjacent(cell, ch.pos)) { ((MissileSprite)parent.recycle( MissileSprite.class )). reset( ch.pos, cell, new CurareDart(), new Callback() { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/ItemSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/ItemSprite.java index bec6e7711..ab41ab8a4 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/ItemSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/ItemSprite.java @@ -125,8 +125,8 @@ public class ItemSprite extends MovieClip { final int csize = DungeonTilemap.SIZE; return new PointF( - cell % Level.WIDTH * csize + (csize - SIZE) * 0.5f, - cell / Level.WIDTH * csize + (csize - SIZE) * 0.5f + cell % Dungeon.level.width() * csize + (csize - SIZE) * 0.5f, + cell / Dungeon.level.width() * csize + (csize - SIZE) * 0.5f ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/PlantSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/PlantSprite.java index 2988b6693..1128f0b8c 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/PlantSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/PlantSprite.java @@ -21,6 +21,7 @@ package com.shatteredpixel.shatteredpixeldungeon.sprites; import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.DungeonTilemap; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.plants.Plant; @@ -65,8 +66,8 @@ public class PlantSprite extends Image { alpha( 1f ); pos = plant.pos; - x = (pos % Level.WIDTH) * DungeonTilemap.SIZE; - y = (pos / Level.WIDTH) * DungeonTilemap.SIZE; + x = (pos % Dungeon.level.width()) * DungeonTilemap.SIZE; + y = (pos / Dungeon.level.width()) * DungeonTilemap.SIZE; state = State.GROWING; time = DELAY; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/ScorpioSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/ScorpioSprite.java index 830b0d296..ae6771bc6 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/ScorpioSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/ScorpioSprite.java @@ -21,6 +21,7 @@ package com.shatteredpixel.shatteredpixeldungeon.sprites; import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.Dart; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.watabou.noosa.TextureFilm; @@ -61,7 +62,7 @@ public class ScorpioSprite extends MobSprite { @Override public void attack( int cell ) { - if (!Level.adjacent( cell, ch.pos )) { + if (!Dungeon.level.adjacent( cell, ch.pos )) { cellToAttack = cell; turnTo( ch.pos , cell ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/TenguSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/TenguSprite.java index de8fc3bb2..b016d64a8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/TenguSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/TenguSprite.java @@ -21,6 +21,7 @@ package com.shatteredpixel.shatteredpixeldungeon.sprites; import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.Actor; import com.shatteredpixel.shatteredpixeldungeon.actors.Char; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.Shuriken; @@ -75,7 +76,7 @@ public class TenguSprite extends MobSprite { @Override public void attack( int cell ) { - if (!Level.adjacent( cell, ch.pos )) { + if (!Dungeon.level.adjacent( cell, ch.pos )) { final Char enemy = Actor.findChar(cell); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/TrapSprite.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/TrapSprite.java index bcac8a498..72295d197 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/TrapSprite.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/sprites/TrapSprite.java @@ -21,6 +21,7 @@ package com.shatteredpixel.shatteredpixeldungeon.sprites; import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.DungeonTilemap; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap; @@ -77,8 +78,8 @@ public class TrapSprite extends Image { alpha( 1f ); pos = trap.pos; - x = (pos % Level.WIDTH) * DungeonTilemap.SIZE; - y = (pos / Level.WIDTH) * DungeonTilemap.SIZE; + x = (pos % Dungeon.level.width()) * DungeonTilemap.SIZE; + y = (pos / Dungeon.level.width()) * DungeonTilemap.SIZE; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/CustomTileVisual.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/CustomTileVisual.java index 848ae0fe2..e72b852f9 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/CustomTileVisual.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/CustomTileVisual.java @@ -20,6 +20,7 @@ */ package com.shatteredpixel.shatteredpixeldungeon.ui; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.Room; import com.watabou.noosa.Image; @@ -44,7 +45,7 @@ public abstract class CustomTileVisual extends Image implements Bundlable { public int tileW = 1, tileH = 1; //width and height in tiles public void pos(int pos) { - pos( pos%Level.WIDTH, pos/Level.WIDTH ); + pos( pos% Dungeon.level.width(), pos/Dungeon.level.width() ); } public void pos(int tileX, int tileY){ diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java index f7866d433..20e8b40c9 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java @@ -29,9 +29,11 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; +import com.shatteredpixel.shatteredpixeldungeon.utils.BArray; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.watabou.noosa.Image; import com.watabou.noosa.ui.Button; +import com.watabou.utils.PathFinder; public class QuickSlotButton extends Button implements WndBag.Listener { @@ -202,10 +204,11 @@ public class QuickSlotButton extends Button implements WndBag.Listener { } //Otherwise pick nearby tiles to try and 'angle' the shot, auto-aim basically. - for (int i : Level.NEIGHBOURS9DIST2) { - if (item.throwPos(Dungeon.hero, target.pos+i) == target.pos){ - return target.pos+i; - } + PathFinder.buildDistanceMap( target.pos, BArray.not( new boolean[Dungeon.level.length()], null ), 2 ); + for (int i = 0; i < PathFinder.distance.length; i++) { + if (PathFinder.distance[i] < Integer.MAX_VALUE + && item.throwPos(Dungeon.hero, i) == target.pos) + return i; } //couldn't find a cell, give up. diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoCell.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoCell.java index 136cdd8b5..d5fd5c642 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoCell.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndInfoCell.java @@ -49,8 +49,8 @@ public class WndInfoCell extends Window { } CustomTileVisual vis = null; - int x = cell % Level.WIDTH; - int y = cell / Level.WIDTH; + int x = cell % Dungeon.level.width(); + int y = cell / Dungeon.level.width(); for (CustomTileVisual i : Dungeon.level.customTiles){ if ((x >= i.tileX && x < i.tileX+i.tileW) && (y >= i.tileY && y < i.tileY+i.tileH)){