v2.2.0: added a basic first gold generator for mining levels

This commit is contained in:
Evan Debenham
2023-07-13 17:51:51 -04:00
parent aec4b0089c
commit d6fa0b82dd
3 changed files with 146 additions and 3 deletions

View File

@@ -30,7 +30,7 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.levels.features.LevelTransition;
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.CavesPainter;
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.MiningLevelPainter;
import com.shatteredpixel.shatteredpixeldungeon.levels.painters.Painter;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.standard.CaveRoom;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
@@ -39,6 +39,7 @@ import com.watabou.noosa.Group;
import com.watabou.noosa.Image;
import com.watabou.noosa.Tilemap;
import com.watabou.noosa.audio.Music;
import com.watabou.utils.Random;
import java.util.Arrays;
@@ -88,7 +89,8 @@ public class MiningLevel extends Level {
map[entrance] = Terrain.ENTRANCE;
Painter painter = new CavesPainter()
Painter painter = new MiningLevelPainter()
.setGold(Random.NormalIntRange(42, 46))
.setWater(0.35f, 6)
.setGrass(0.10f, 3);

View File

@@ -113,6 +113,15 @@ public class CavesPainter extends RegularPainter {
}
}
generateGold(level, rooms);
}
protected void generateGold(Level level, ArrayList<Room> rooms){
int w = level.width();
int l = level.length();
int[] map = level.map;
for (int i=0; i < l - w; i++) {
if (map[i] == Terrain.WALL &&
DungeonTileSheet.floorTile(map[i + w])
@@ -120,6 +129,5 @@ public class CavesPainter extends RegularPainter {
map[i] = Terrain.WALL_DECO;
}
}
}
}

View File

@@ -0,0 +1,133 @@
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2023 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.levels.painters;
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
import com.shatteredpixel.shatteredpixeldungeon.levels.Patch;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTileSheet;
import com.watabou.utils.PathFinder;
import com.watabou.utils.Random;
import java.util.ArrayList;
public class MiningLevelPainter extends CavesPainter {
//TODO currently this does an acceptable job of generating veins/clusters of gold
// and an excellent job of ensuring that the total gold amount is consistent
// but it doesn't ensure anything about gold distribution. Gold can often be overly clumped in certain areas
//TODO gold on left/right/below walls is also super hard to see atm
private int goldToAdd = 0;
public RegularPainter setGold(int amount){
goldToAdd = amount;
return this;
}
@Override
protected void generateGold(Level level, ArrayList<Room> rooms) {
//we start by counting all the gold purposefully made by rooms
for (int i = 0; i < level.length(); i++){
if (level.map[i] == Terrain.WALL_DECO) {
goldToAdd--;
}
}
int[] map = level.map;
do {
//use the patch system to generate a random smattering of gold with some grouping
boolean[] gold = Patch.generate( level.width(), level.height(), 0.05f, 2, true );
ArrayList<Integer> goldPosCandidates = new ArrayList<>();
//find all potential gold cells that are exposed
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){
if (level.insideMap(i+j) && DungeonTileSheet.floorTile(map[i+j])){
goldPosCandidates.add(i);
break;
}
}
}
}
Random.shuffle(goldPosCandidates);
//fill in only the exposed potential gold cells...
for (int i : goldPosCandidates){
if (map[i] == Terrain.WALL) {
map[i] = Terrain.BARRICADE;
goldToAdd--;
}
//...with some preference to fill in neighbours
for (int k : PathFinder.NEIGHBOURS4){
if (!level.insideMap(i+k)) continue;
if (goldToAdd > 0 && goldPosCandidates.contains(i+k) && map[i+k] == Terrain.WALL){
map[i+k] = Terrain.BARRICADE;
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.BARRICADE;
goldToAdd--;
}
};
if (goldToAdd <= 0) break;
}
}
//if we don't have enough gold yet, loop
} while (goldToAdd > 0);
}
/*
//spreads gold over an entire cluster, currently unused
private void spreadGold(int i, boolean[] gold){
for (int k : PathFinder.NEIGHBOURS4){
if (!insideMap(i+k)) continue;
if (goldToAdd > 0 && gold[i+k] && map[i+k] == Terrain.WALL){
map[i+k] = Terrain.BARRICADE;
goldToAdd--;
spreadGold(i+k, gold);
}
}
}
*/
}