mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Rebalance chest density in dungeons
- Make it depend on relative floor and not absolute floor to keep it the same through different dungeons. - Make it start around the middle of dungeon to avoid chest only runs.
This commit is contained in:
parent
970d57f905
commit
38493b615b
@ -63,6 +63,8 @@ lazy_static! {
|
|||||||
.clone();
|
.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn floor_amount(difficulty: u32) -> u32 { 3 + difficulty / 2 }
|
||||||
|
|
||||||
impl Dungeon {
|
impl Dungeon {
|
||||||
pub fn generate(wpos: Vec2<i32>, land: &Land, rng: &mut impl Rng) -> Self {
|
pub fn generate(wpos: Vec2<i32>, land: &Land, rng: &mut impl Rng) -> Self {
|
||||||
let mut ctx = GenCtx { land, rng };
|
let mut ctx = GenCtx { land, rng };
|
||||||
@ -75,7 +77,7 @@ impl Dungeon {
|
|||||||
err
|
err
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
let floors = 3 + difficulty / 2;
|
let floors = floor_amount(difficulty);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
name: {
|
name: {
|
||||||
@ -383,7 +385,7 @@ impl Floor {
|
|||||||
difficulty: u32,
|
difficulty: u32,
|
||||||
) -> (Self, Vec2<i32>) {
|
) -> (Self, Vec2<i32>) {
|
||||||
const MAX_WIDTH: u32 = 4;
|
const MAX_WIDTH: u32 = 4;
|
||||||
let floors = 3 + difficulty / 2;
|
let floors = floor_amount(difficulty);
|
||||||
let final_level = level == floors as i32 - 1;
|
let final_level = level == floors as i32 - 1;
|
||||||
let width = (2 + difficulty / 2).min(MAX_WIDTH);
|
let width = (2 + difficulty / 2).min(MAX_WIDTH);
|
||||||
let height = (15 + difficulty * 3).min(30);
|
let height = (15 + difficulty * 3).min(30);
|
||||||
@ -516,11 +518,20 @@ impl Floor {
|
|||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let loot_density = |difficulty, level| {
|
||||||
|
let max_floor = floor_amount(difficulty);
|
||||||
|
// We count floors from 0, don't divide by zero
|
||||||
|
let current_floor = level + 1;
|
||||||
|
let ratio = f64::from(current_floor) / f64::from(max_floor);
|
||||||
|
// filter starting floors
|
||||||
|
let ratio = 0.0_f64.max(ratio - 0.55);
|
||||||
|
0.00175 * ratio as f32
|
||||||
|
};
|
||||||
match ctx.rng.gen_range(0..5) {
|
match ctx.rng.gen_range(0..5) {
|
||||||
// Miniboss room
|
// Miniboss room
|
||||||
0 => self.create_room(Room {
|
0 => self.create_room(Room {
|
||||||
seed: ctx.rng.gen(),
|
seed: ctx.rng.gen(),
|
||||||
loot_density: 0.000025 + level as f32 * 0.00015,
|
loot_density: loot_density(self.difficulty, level),
|
||||||
kind: RoomKind::Miniboss,
|
kind: RoomKind::Miniboss,
|
||||||
area,
|
area,
|
||||||
height: ctx.rng.gen_range(15..20),
|
height: ctx.rng.gen_range(15..20),
|
||||||
@ -530,7 +541,7 @@ impl Floor {
|
|||||||
// Fight room with enemies in it
|
// Fight room with enemies in it
|
||||||
_ => self.create_room(Room {
|
_ => self.create_room(Room {
|
||||||
seed: ctx.rng.gen(),
|
seed: ctx.rng.gen(),
|
||||||
loot_density: 0.000025 + level as f32 * 0.00015,
|
loot_density: loot_density(self.difficulty, level),
|
||||||
kind: RoomKind::Fight,
|
kind: RoomKind::Fight,
|
||||||
area,
|
area,
|
||||||
height: ctx.rng.gen_range(10..15),
|
height: ctx.rng.gen_range(10..15),
|
||||||
@ -1219,8 +1230,9 @@ impl Floor {
|
|||||||
let seed = room.seed;
|
let seed = room.seed;
|
||||||
let loot_density = room.loot_density;
|
let loot_density = room.loot_density;
|
||||||
let difficulty = room.difficulty;
|
let difficulty = room.difficulty;
|
||||||
// Place chests with a random distribution based on the room's loot density in
|
// Place chests with a random distribution based on the
|
||||||
// valid sprite locations, filled based on the room's difficulty
|
// room's loot density in valid sprite locations,
|
||||||
|
// filled based on the room's difficulty
|
||||||
let chest_sprite = prim(Primitive::Sampling(
|
let chest_sprite = prim(Primitive::Sampling(
|
||||||
sprite_layer,
|
sprite_layer,
|
||||||
Box::new(move |pos| RandomField::new(seed).chance(pos, loot_density * 0.5)),
|
Box::new(move |pos| RandomField::new(seed).chance(pos, loot_density * 0.5)),
|
||||||
@ -1236,9 +1248,10 @@ impl Floor {
|
|||||||
}));
|
}));
|
||||||
chests = Some((chest_sprite, chest_sprite_fill));
|
chests = Some((chest_sprite, chest_sprite_fill));
|
||||||
|
|
||||||
// If a room has pillars, the current tile aligns with the pillar spacing, and
|
// If a room has pillars, the current tile aligns with
|
||||||
// we're not too close to a wall (i.e. the adjacent tiles are rooms and not
|
// the pillar spacing, and we're not too close to a wall
|
||||||
// hallways/solid), place a pillar
|
// (i.e. the adjacent tiles are rooms and not hallways/solid),
|
||||||
|
// place a pillar
|
||||||
if room
|
if room
|
||||||
.pillars
|
.pillars
|
||||||
.map(|pillar_space| {
|
.map(|pillar_space| {
|
||||||
|
Loading…
Reference in New Issue
Block a user