mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Avoid placing site2 houses on paths (this affects worldgen even with train tracks disabled, since the paths are already there).
This commit is contained in:
parent
f83afcd5a8
commit
2242f7245d
@ -38,4 +38,11 @@ impl<'a> Land<'a> {
|
||||
pub fn get_chunk_wpos(&self, wpos: Vec2<i32>) -> Option<&sim::SimChunk> {
|
||||
self.sim.and_then(|sim| sim.get_wpos(wpos))
|
||||
}
|
||||
|
||||
pub fn get_nearest_path(
|
||||
&self,
|
||||
wpos: Vec2<i32>,
|
||||
) -> Option<(f32, Vec2<f32>, sim::Path, Vec2<f32>)> {
|
||||
self.sim.and_then(|sim| sim.get_nearest_path(wpos))
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ pub use self::{
|
||||
util::Dir,
|
||||
};
|
||||
use crate::{
|
||||
sim::Path,
|
||||
site::{namegen::NameGen, SpawnRules},
|
||||
util::{attempt, DHashSet, Grid, CARDINALS, SQUARE_4, SQUARE_9},
|
||||
Canvas, Land,
|
||||
@ -323,9 +324,10 @@ impl Site {
|
||||
Spiral2d::new()
|
||||
.take((SEARCH_RADIUS * 2 + 1).pow(2) as usize)
|
||||
.for_each(|tile| {
|
||||
let wpos = self.tile_center_wpos(tile);
|
||||
if let Some(kind) = Spiral2d::new()
|
||||
.take(9)
|
||||
.find_map(|rpos| wpos_is_hazard(land, self.tile_center_wpos(tile) + rpos))
|
||||
.find_map(|rpos| wpos_is_hazard(land, wpos + rpos))
|
||||
{
|
||||
for &rpos in &SQUARE_4 {
|
||||
// `get_mut` doesn't increase generation bounds
|
||||
@ -334,6 +336,13 @@ impl Site {
|
||||
.map(|tile| tile.kind = TileKind::Hazard(kind));
|
||||
}
|
||||
}
|
||||
if let Some((dist, _, Path { width }, _)) = land.get_nearest_path(wpos) {
|
||||
if dist < 2.0 * width {
|
||||
self.tiles
|
||||
.get_mut(tile)
|
||||
.map(|tile| tile.kind = TileKind::Path);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -1004,7 +1013,7 @@ impl Site {
|
||||
|
||||
#[allow(clippy::single_match)]
|
||||
match &tile.kind {
|
||||
TileKind::Plaza => {
|
||||
TileKind::Plaza | TileKind::Path => {
|
||||
let near_roads = CARDINALS.iter().filter_map(|rpos| {
|
||||
if self.tiles.get(tpos + rpos) == tile {
|
||||
Some(Aabr {
|
||||
|
@ -181,6 +181,7 @@ pub enum TileKind {
|
||||
Field,
|
||||
Plaza,
|
||||
Road { a: u16, b: u16, w: u16 },
|
||||
Path,
|
||||
Building,
|
||||
Castle,
|
||||
Wall(Dir),
|
||||
@ -219,7 +220,12 @@ impl Tile {
|
||||
|
||||
pub fn is_natural(&self) -> bool { matches!(self.kind, TileKind::Empty | TileKind::Hazard(_)) }
|
||||
|
||||
pub fn is_road(&self) -> bool { matches!(self.kind, TileKind::Plaza | TileKind::Road { .. }) }
|
||||
pub fn is_road(&self) -> bool {
|
||||
matches!(
|
||||
self.kind,
|
||||
TileKind::Plaza | TileKind::Road { .. } | TileKind::Path
|
||||
)
|
||||
}
|
||||
|
||||
pub fn is_obstacle(&self) -> bool {
|
||||
matches!(self.kind, TileKind::Hazard(_)) || self.is_building()
|
||||
|
Loading…
x
Reference in New Issue
Block a user