veloren/rtsim/src/gen/site.rs

36 lines
964 B
Rust
Raw Normal View History

2022-09-03 09:47:18 +00:00
use crate::data::{FactionId, Site};
2022-08-11 14:44:57 +00:00
use common::store::Id;
2022-08-15 14:00:39 +00:00
use vek::*;
use world::{
site::{Site as WorldSite, SiteKind},
IndexRef, World,
};
2022-08-11 14:44:57 +00:00
impl Site {
2022-09-03 09:47:18 +00:00
pub fn generate(
world_site_id: Id<WorldSite>,
2022-09-03 09:47:18 +00:00
world: &World,
index: IndexRef,
nearby_factions: &[(Vec2<i32>, FactionId)],
) -> Self {
let world_site = index.sites.get(world_site_id);
let wpos = world_site.get_origin();
2022-08-11 14:44:57 +00:00
Self {
2022-08-15 14:00:39 +00:00
wpos,
world_site: Some(world_site_id),
faction: if matches!(
&world_site.kind,
SiteKind::Refactor(_) | SiteKind::CliffTown(_) | SiteKind::DesertCity(_)
) {
nearby_factions
.iter()
.min_by_key(|(faction_wpos, _)| faction_wpos.distance_squared(wpos))
.map(|(_, faction)| *faction)
} else {
None
},
2022-08-11 14:44:57 +00:00
}
}
}