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