veloren/rtsim/src/gen/site.rs

56 lines
1.7 KiB
Rust
Raw Normal View History

use crate::data::{FactionId, Factions, Site};
2022-08-11 14:44:57 +00:00
use common::store::Id;
2023-03-09 15:07:06 +00:00
use hashbrown::HashSet;
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)],
factions: &Factions,
2022-09-03 09:47:18 +00:00
) -> Self {
let world_site = index.sites.get(world_site_id);
let wpos = world_site.get_origin();
2022-08-11 14:44:57 +00:00
// TODO: This is stupid, do better
let good_or_evil = match &world_site.kind {
// Good
SiteKind::Refactor(_)
| SiteKind::CliffTown(_)
| SiteKind::DesertCity(_)
| SiteKind::SavannahPit(_) => Some(true),
// Evil
SiteKind::Dungeon(_) | SiteKind::ChapelSite(_) | SiteKind::Gnarling(_) => Some(false),
// Neutral
SiteKind::Settlement(_)
| SiteKind::Castle(_)
| SiteKind::Tree(_)
| SiteKind::GiantTree(_)
| SiteKind::Bridge(_) => None,
};
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: good_or_evil.and_then(|good_or_evil| {
nearby_factions
.iter()
.filter(|(_, faction)| {
factions
.get(*faction)
.map_or(false, |f| f.good_or_evil == good_or_evil)
})
.min_by_key(|(faction_wpos, _)| faction_wpos.distance_squared(wpos))
.map(|(_, faction)| *faction)
}),
2023-03-09 15:07:06 +00:00
population: HashSet::new(),
2022-08-11 14:44:57 +00:00
}
}
}