mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Gnarling dungeons now only generate near forests.
This commit is contained in:
parent
31192c80bc
commit
b28f6276dd
@ -16,7 +16,6 @@
|
||||
/// 1) Set every probability to 0.0 and left one with any other number
|
||||
/// and you will have map full of dungeons of same level
|
||||
([
|
||||
(0, 0.25),
|
||||
(1, 0.20),
|
||||
(2, 0.20),
|
||||
(3, 0.15),
|
||||
|
@ -4,7 +4,7 @@ mod econ;
|
||||
|
||||
use crate::{
|
||||
config::CONFIG,
|
||||
sim::WorldSim,
|
||||
sim::{SimChunk, WorldSim},
|
||||
site::{namegen::NameGen, Castle, Settlement, Site as WorldSite, Tree},
|
||||
site2,
|
||||
util::{attempt, seed_expan, DHashMap, DHashSet, NEIGHBORS},
|
||||
@ -15,7 +15,7 @@ use common::{
|
||||
path::Path,
|
||||
spiral::Spiral2d,
|
||||
store::{Id, Store},
|
||||
terrain::{uniform_idx_as_vec2, MapSizeLg, TerrainChunkSize},
|
||||
terrain::{uniform_idx_as_vec2, BiomeKind, MapSizeLg, TerrainChunkSize},
|
||||
vol::RectVolSize,
|
||||
};
|
||||
use core::{fmt, hash::BuildHasherDefault, ops::Range};
|
||||
@ -110,6 +110,7 @@ impl Civs {
|
||||
(SiteKind::Tree, 4)
|
||||
}
|
||||
},
|
||||
32..=37 => (SiteKind::Gnarling, 3),
|
||||
_ => (SiteKind::Dungeon, 0),
|
||||
};
|
||||
let loc = find_site_loc(&mut ctx, None, size, kind)?;
|
||||
@ -136,6 +137,7 @@ impl Civs {
|
||||
SiteKind::Refactor => (32i32, 10.0),
|
||||
SiteKind::Tree => (12i32, 8.0),
|
||||
SiteKind::GiantTree => (12i32, 8.0),
|
||||
SiteKind::Gnarling => (16i32, 5.0),
|
||||
};
|
||||
|
||||
let (raise, raise_dist, make_waypoint): (f32, i32, bool) = match &site.kind {
|
||||
@ -219,6 +221,11 @@ impl Civs {
|
||||
&mut rng,
|
||||
wpos,
|
||||
)),
|
||||
SiteKind::Gnarling => WorldSite::gnarling(site2::Site::generate_gnarling(
|
||||
&Land::from_sim(ctx.sim),
|
||||
&mut rng,
|
||||
wpos,
|
||||
)),
|
||||
});
|
||||
sim_site.site_tmp = Some(site);
|
||||
let site_ref = &index.sites[site];
|
||||
@ -442,10 +449,11 @@ impl Civs {
|
||||
}
|
||||
|
||||
fn birth_civ(&mut self, ctx: &mut GenCtx<impl Rng>) -> Option<Id<Civ>> {
|
||||
let kind = SiteKind::Settlement;
|
||||
let site = attempt(5, || {
|
||||
let loc = find_site_loc(ctx, None, 1, SiteKind::Settlement)?;
|
||||
let loc = find_site_loc(ctx, None, 1, kind)?;
|
||||
Some(self.establish_site(ctx, loc, |place| Site {
|
||||
kind: SiteKind::Settlement,
|
||||
kind,
|
||||
site_tmp: None,
|
||||
center: loc,
|
||||
place,
|
||||
@ -1007,6 +1015,7 @@ fn loc_suitable_for_site(sim: &WorldSim, loc: Vec2<i32>, site_kind: SiteKind) ->
|
||||
.get_gradient_approx(loc)
|
||||
.map(|grad| grad < 1.0)
|
||||
.unwrap_or(false)
|
||||
&& site_kind.is_suitable_loc(chunk)
|
||||
} else {
|
||||
false
|
||||
}) && check_chunk_occupation(sim, loc, site_kind.exclusion_radius())
|
||||
@ -1045,7 +1054,7 @@ fn find_site_loc(
|
||||
}
|
||||
|
||||
loc = ctx.sim.get(test_loc).and_then(|c| {
|
||||
Some(
|
||||
site_kind.is_suitable_loc(c).then_some(
|
||||
c.downhill?
|
||||
.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| e / (sz as i32)),
|
||||
)
|
||||
@ -1105,6 +1114,16 @@ pub enum SiteKind {
|
||||
Refactor,
|
||||
Tree,
|
||||
GiantTree,
|
||||
Gnarling,
|
||||
}
|
||||
|
||||
impl SiteKind {
|
||||
pub fn is_suitable_loc(&self, chunk: &SimChunk) -> bool {
|
||||
match self {
|
||||
SiteKind::Gnarling => matches!(chunk.get_biome(), BiomeKind::Forest),
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SiteKind {
|
||||
|
@ -156,6 +156,8 @@ impl World {
|
||||
civ::SiteKind::Castle => world_msg::SiteKind::Castle,
|
||||
civ::SiteKind::Refactor => world_msg::SiteKind::Town,
|
||||
civ::SiteKind::Tree | civ::SiteKind::GiantTree => world_msg::SiteKind::Tree,
|
||||
// TODO: Maybe change?
|
||||
civ::SiteKind::Gnarling => world_msg::SiteKind::Dungeon { difficulty: 0 },
|
||||
},
|
||||
wpos: site.center * TerrainChunkSize::RECT_SIZE.map(|e| e as i32),
|
||||
}
|
||||
|
@ -208,6 +208,7 @@ fn simulate_return(index: &mut Index, world: &mut WorldSim) -> Result<(), std::i
|
||||
SiteKind::Tree(_) => (),
|
||||
SiteKind::Refactor(_) => towns += site.economy.pop,
|
||||
SiteKind::GiantTree(_) => (),
|
||||
SiteKind::Gnarling(_) => {},
|
||||
}
|
||||
}
|
||||
if towns.valid() {
|
||||
|
@ -63,6 +63,7 @@ pub enum SiteKind {
|
||||
Refactor(site2::Site),
|
||||
Tree(tree::Tree),
|
||||
GiantTree(site2::Site),
|
||||
Gnarling(site2::Site),
|
||||
}
|
||||
|
||||
impl Site {
|
||||
@ -80,6 +81,13 @@ impl Site {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn gnarling(g: site2::Site) -> Self {
|
||||
Self {
|
||||
kind: SiteKind::Gnarling(g),
|
||||
economy: Economy::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn castle(c: Castle) -> Self {
|
||||
Self {
|
||||
kind: SiteKind::Castle(c),
|
||||
@ -116,6 +124,7 @@ impl Site {
|
||||
SiteKind::Refactor(s) => s.radius(),
|
||||
SiteKind::Tree(t) => t.radius(),
|
||||
SiteKind::GiantTree(gt) => gt.radius(),
|
||||
SiteKind::Gnarling(g) => g.radius(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,6 +136,7 @@ impl Site {
|
||||
SiteKind::Refactor(s) => s.origin,
|
||||
SiteKind::Tree(t) => t.origin,
|
||||
SiteKind::GiantTree(gt) => gt.origin,
|
||||
SiteKind::Gnarling(g) => g.origin,
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,6 +148,7 @@ impl Site {
|
||||
SiteKind::Refactor(s) => s.spawn_rules(wpos),
|
||||
SiteKind::Tree(t) => t.spawn_rules(wpos),
|
||||
SiteKind::GiantTree(gt) => gt.spawn_rules(wpos),
|
||||
SiteKind::Gnarling(g) => g.spawn_rules(wpos),
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,6 +160,7 @@ impl Site {
|
||||
SiteKind::Refactor(s) => s.name(),
|
||||
SiteKind::Tree(_) => "Giant Tree",
|
||||
SiteKind::GiantTree(gt) => gt.name(),
|
||||
SiteKind::Gnarling(g) => g.name(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,6 +194,7 @@ impl Site {
|
||||
SiteKind::Refactor(s) => s.render(canvas, dynamic_rng),
|
||||
SiteKind::Tree(t) => t.render(canvas, dynamic_rng),
|
||||
SiteKind::GiantTree(gt) => gt.render(canvas, dynamic_rng),
|
||||
SiteKind::Gnarling(g) => g.render(canvas, dynamic_rng),
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,6 +219,7 @@ impl Site {
|
||||
SiteKind::Refactor(_) => {},
|
||||
SiteKind::Tree(_) => {},
|
||||
SiteKind::GiantTree(gt) => gt.apply_supplement(dynamic_rng, wpos2d, supplement),
|
||||
SiteKind::Gnarling(g) => g.apply_supplement(dynamic_rng, wpos2d, supplement),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -376,37 +376,59 @@ impl Site {
|
||||
site
|
||||
}
|
||||
|
||||
pub fn generate_giant_tree(land: &Land, rng: &mut impl Rng, origin: Vec2<i32>) -> Self {
|
||||
pub fn generate_gnarling(land: &Land, rng: &mut impl Rng, origin: Vec2<i32>) -> Self {
|
||||
let mut rng = reseed(rng);
|
||||
|
||||
let mut site = Site {
|
||||
origin,
|
||||
..Site::default()
|
||||
};
|
||||
site.demarcate_obstacles(land);
|
||||
let gnarling_fortification = plot::GnarlingFortification::generate(origin, land, &mut rng);
|
||||
site.name = gnarling_fortification.name().to_string();
|
||||
let size = gnarling_fortification.radius() / tile::TILE_SIZE as i32;
|
||||
let aabr = Aabr {
|
||||
min: Vec2::broadcast(-size),
|
||||
max: Vec2::broadcast(size),
|
||||
};
|
||||
let plot = site.create_plot(Plot {
|
||||
kind: PlotKind::Gnarling(gnarling_fortification),
|
||||
root_tile: aabr.center(),
|
||||
tiles: aabr_tiles(aabr).collect(),
|
||||
seed: rng.gen(),
|
||||
});
|
||||
site.blit_aabr(aabr, Tile {
|
||||
kind: TileKind::GnarlingFortification,
|
||||
plot: Some(plot),
|
||||
hard_alt: None,
|
||||
});
|
||||
site
|
||||
}
|
||||
|
||||
pub fn generate_giant_tree(land: &Land, rng: &mut impl Rng, origin: Vec2<i32>) -> Self {
|
||||
let mut rng = reseed(rng);
|
||||
let mut site = Site {
|
||||
origin,
|
||||
..Site::default()
|
||||
};
|
||||
site.demarcate_obstacles(land);
|
||||
let giant_tree = plot::GiantTree::generate(&site, Vec2::zero(), land, &mut rng);
|
||||
site.name = giant_tree.name().to_string();
|
||||
let size = (giant_tree.radius() / tile::TILE_SIZE as f32).ceil() as i32;
|
||||
|
||||
let aabr = Aabr {
|
||||
min: Vec2::broadcast(-size),
|
||||
max: Vec2::broadcast(size) + 1,
|
||||
};
|
||||
|
||||
let plot = site.create_plot(Plot {
|
||||
kind: PlotKind::GiantTree(giant_tree),
|
||||
root_tile: aabr.center(),
|
||||
tiles: aabr_tiles(aabr).collect(),
|
||||
seed: rng.gen(),
|
||||
});
|
||||
|
||||
site.blit_aabr(aabr, Tile {
|
||||
kind: TileKind::Building,
|
||||
plot: Some(plot),
|
||||
hard_alt: None,
|
||||
});
|
||||
|
||||
site
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ pub struct Dungeon {
|
||||
#[allow(dead_code)]
|
||||
noise: RandomField,
|
||||
floors: Vec<Floor>,
|
||||
difficulty: u32,
|
||||
pub difficulty: u32,
|
||||
}
|
||||
|
||||
pub struct GenCtx<'a, R: Rng> {
|
||||
|
Loading…
Reference in New Issue
Block a user