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::*;
|
2022-09-05 14:03:21 +00:00
|
|
|
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(
|
2022-09-05 14:03:21 +00:00
|
|
|
world_site_id: Id<WorldSite>,
|
2022-09-03 09:47:18 +00:00
|
|
|
world: &World,
|
|
|
|
index: IndexRef,
|
|
|
|
nearby_factions: &[(Vec2<i32>, FactionId)],
|
|
|
|
) -> Self {
|
2022-09-05 14:03:21 +00:00
|
|
|
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,
|
2022-09-05 14:03:21 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|