v2.2.0: substantially improved mining level gold generation

This commit is contained in:
Evan Debenham
2023-09-21 16:05:16 -04:00
parent fac4c58515
commit 5c59b3e777
2 changed files with 43 additions and 50 deletions
@@ -22,12 +22,12 @@
package com.shatteredpixel.shatteredpixeldungeon.levels.painters; package com.shatteredpixel.shatteredpixeldungeon.levels.painters;
import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
import com.shatteredpixel.shatteredpixeldungeon.levels.Patch;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain; import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTileSheet; import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.quest.MineSecretRoom;
import com.watabou.utils.Graph; import com.watabou.utils.Graph;
import com.watabou.utils.PathFinder; import com.watabou.utils.PathFinder;
import com.watabou.utils.Point;
import com.watabou.utils.Random; import com.watabou.utils.Random;
import java.util.ArrayList; import java.util.ArrayList;
@@ -35,9 +35,10 @@ import java.util.HashMap;
public class MiningLevelPainter extends CavesPainter { public class MiningLevelPainter extends CavesPainter {
//TODO currently this does an acceptable job of generating veins/clusters of gold @Override
// and an excellent job of ensuring that the total gold amount is consistent protected int padding(Level level) {
// but it doesn't ensure anything about gold distribution. Gold can often be overly clumped in certain areas return 3;
}
private int goldToAdd = 0; private int goldToAdd = 0;
@@ -56,63 +57,51 @@ public class MiningLevelPainter extends CavesPainter {
} }
int[] map = level.map; int[] map = level.map;
do { do {
//use the patch system to generate a random smattering of gold with some grouping Random.shuffle(rooms);
boolean[] gold = Patch.generate( level.width(), level.height(), 0.05f, 2, true ); for (Room r : rooms) {
ArrayList<Integer> goldPosCandidates = new ArrayList<>();
//find all potential gold cells that are exposed if (r instanceof MineSecretRoom) continue;
for (int i = 0; i < level.length(); i++){
if (level.insideMap(i) && goldToAdd > 0 && map[i] == Terrain.WALL && gold[i]){
for (int j : PathFinder.NEIGHBOURS4){ ArrayList<Integer> goldPosCandidates = new ArrayList<>();
if (level.insideMap(i+j) && DungeonTileSheet.floorTile(map[i+j])){ for (Point p : r.getPoints()){
goldPosCandidates.add(i); int i = level.pointToCell(p);
break;
if (level.insideMap(i) && goldToAdd > 0 && map[i] == Terrain.WALL){
for (int j : PathFinder.NEIGHBOURS4){
if (level.insideMap(i+j) && map[i+j] != Terrain.WALL){
goldPosCandidates.add(i);
break;
}
} }
} }
} }
}
Random.shuffle(goldPosCandidates); if (goldToAdd > 0 && !goldPosCandidates.isEmpty()){
int pos = Random.element(goldPosCandidates);
//fill in only the exposed potential gold cells... map[pos] = Terrain.WALL_DECO;
for (int i : goldPosCandidates){
if (map[i] == Terrain.WALL) {
map[i] = Terrain.WALL_DECO;
goldToAdd--; goldToAdd--;
}
//...with some preference to fill in neighbours if (goldToAdd > 0){
for (int k : PathFinder.NEIGHBOURS4){ int i = PathFinder.NEIGHBOURS4[Random.Int(4)];
if (!level.insideMap(i+k)) continue; if (level.insideMap(pos+i) && map[pos+i] == Terrain.WALL){
if (goldToAdd > 0 && goldPosCandidates.contains(i+k) && map[i+k] == Terrain.WALL){ map[pos+i] = Terrain.WALL_DECO;
map[i+k] = Terrain.WALL_DECO;
goldToAdd--;
}
};
if (goldToAdd <= 0) break;
}
//if we have more gold to add, also look into filling in some non-exposed potential gold cells
// that are adjacent to exposed cells
if (goldToAdd > 0){
for (int i : goldPosCandidates){
for (int k : PathFinder.NEIGHBOURS4){
if (!level.insideMap(i+k)) continue;
if (goldToAdd > 0 && gold[i+k] && map[i+k] == Terrain.WALL){
map[i+k] = Terrain.WALL_DECO;
goldToAdd--; goldToAdd--;
} }
}; if (Random.Int(2) == 0){
if (goldToAdd <= 0) break; i = PathFinder.NEIGHBOURS4[Random.Int(4)];
} if (level.insideMap(pos+i) && map[pos+i] == Terrain.WALL){
} map[pos+i] = Terrain.WALL_DECO;
goldToAdd--;
}
}
}
//if we don't have enough gold yet, loop }
}
} while (goldToAdd > 0); } while (goldToAdd > 0);
} }
@@ -75,6 +75,10 @@ public abstract class RegularPainter extends Painter {
trapChances = chances; trapChances = chances;
return this; return this;
} }
protected int padding(Level level){
return level.feeling == Level.Feeling.CHASM ? 2 : 1;
}
@Override @Override
public boolean paint(Level level, ArrayList<Room> rooms) { public boolean paint(Level level, ArrayList<Room> rooms) {
@@ -82,7 +86,7 @@ public abstract class RegularPainter extends Painter {
//painter can be used without rooms //painter can be used without rooms
if (rooms != null) { if (rooms != null) {
int padding = level.feeling == Level.Feeling.CHASM ? 2 : 1; int padding = padding(level);
int leftMost = Integer.MAX_VALUE, topMost = Integer.MAX_VALUE; int leftMost = Integer.MAX_VALUE, topMost = Integer.MAX_VALUE;