mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add config file for dungeon distribution
- Now you can specify probability of "spawn" of dungeon with specific difficulty
This commit is contained in:
parent
e7f54d6306
commit
e5c63b2ca7
20
assets/world/dungeon/difficulty_distribution.ron
Normal file
20
assets/world/dungeon/difficulty_distribution.ron
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/// Distribution of different dungeon levels.
|
||||||
|
///
|
||||||
|
/// first number is dungeon level, integer
|
||||||
|
/// second number is probability, any normal positive float (not a NaN, for example)
|
||||||
|
///
|
||||||
|
/// Values are relative to each other,
|
||||||
|
/// lesser probability means there will be less dungeons.
|
||||||
|
///
|
||||||
|
/// General rules:
|
||||||
|
/// 1) Probability should not be less or equal to zero
|
||||||
|
/// 2) Keep it synced with number of dungeon levels
|
||||||
|
/// 3) Keep these pairs sorted from lowest to highest tier
|
||||||
|
([
|
||||||
|
(0, 1.0),
|
||||||
|
(1, 1.0),
|
||||||
|
(2, 1.0),
|
||||||
|
(3, 1.0),
|
||||||
|
(4, 1.0),
|
||||||
|
(5, 1.0),
|
||||||
|
])
|
@ -9,7 +9,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use common::{
|
use common::{
|
||||||
assets::AssetHandle,
|
assets::{self, AssetExt, AssetHandle},
|
||||||
astar::Astar,
|
astar::Astar,
|
||||||
comp::{self},
|
comp::{self},
|
||||||
generation::{ChunkSupplement, EntityInfo},
|
generation::{ChunkSupplement, EntityInfo},
|
||||||
@ -20,7 +20,7 @@ use common::{
|
|||||||
use core::{f32, hash::BuildHasherDefault};
|
use core::{f32, hash::BuildHasherDefault};
|
||||||
use fxhash::FxHasher64;
|
use fxhash::FxHasher64;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use rand::prelude::*;
|
use rand::{prelude::*, seq::SliceRandom};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
@ -47,13 +47,34 @@ pub struct Colors {
|
|||||||
|
|
||||||
const ALT_OFFSET: i32 = -2;
|
const ALT_OFFSET: i32 = -2;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct DungeonDistribution(Vec<(u32, f32)>);
|
||||||
|
impl assets::Asset for DungeonDistribution {
|
||||||
|
type Loader = assets::RonLoader;
|
||||||
|
|
||||||
|
const EXTENSION: &'static str = "ron";
|
||||||
|
}
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref DUNGEON_DISTRIBUTION: Vec<(u32, f32)> =
|
||||||
|
DungeonDistribution::load_expect("world.dungeon.difficulty_distribution")
|
||||||
|
.read()
|
||||||
|
.0
|
||||||
|
.clone();
|
||||||
|
}
|
||||||
|
|
||||||
impl Dungeon {
|
impl Dungeon {
|
||||||
#[allow(clippy::let_and_return)] // TODO: Pending review in #587
|
|
||||||
pub fn generate(wpos: Vec2<i32>, sim: Option<&WorldSim>, rng: &mut impl Rng) -> Self {
|
pub fn generate(wpos: Vec2<i32>, sim: Option<&WorldSim>, rng: &mut impl Rng) -> Self {
|
||||||
let mut ctx = GenCtx { sim, rng };
|
let mut ctx = GenCtx { sim, rng };
|
||||||
let difficulty = ctx.rng.gen_range(0..6);
|
|
||||||
|
let difficulty = DUNGEON_DISTRIBUTION
|
||||||
|
.choose_weighted(&mut ctx.rng, |pair| pair.1)
|
||||||
|
.map(|(difficulty, _)| *difficulty)
|
||||||
|
.expect("this can never fail");
|
||||||
|
|
||||||
let floors = 3 + difficulty / 2;
|
let floors = 3 + difficulty / 2;
|
||||||
let this = Self {
|
|
||||||
|
Self {
|
||||||
name: {
|
name: {
|
||||||
let name = NameGen::location(ctx.rng).generate();
|
let name = NameGen::location(ctx.rng).generate();
|
||||||
match ctx.rng.gen_range(0..5) {
|
match ctx.rng.gen_range(0..5) {
|
||||||
@ -81,9 +102,7 @@ impl Dungeon {
|
|||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
difficulty,
|
difficulty,
|
||||||
};
|
}
|
||||||
|
|
||||||
this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &str { &self.name }
|
pub fn name(&self) -> &str { &self.name }
|
||||||
|
Loading…
Reference in New Issue
Block a user