2023-01-05 20:25:32 +00:00
|
|
|
use crate::data::{FactionId, Factions, Site};
|
2022-08-11 14:44:57 +00:00
|
|
|
use common::store::Id;
|
2023-04-06 17:25:33 +00:00
|
|
|
use rand::prelude::*;
|
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>,
|
2023-03-22 09:59:34 +00:00
|
|
|
_world: &World,
|
2022-09-03 09:47:18 +00:00
|
|
|
index: IndexRef,
|
|
|
|
nearby_factions: &[(Vec2<i32>, FactionId)],
|
2023-01-05 20:25:32 +00:00
|
|
|
factions: &Factions,
|
2023-04-06 17:25:33 +00:00
|
|
|
rng: &mut impl Rng,
|
2022-09-03 09:47:18 +00:00
|
|
|
) -> 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
|
|
|
|
2023-01-05 20:25:32 +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
|
2023-03-21 01:34:18 +00:00
|
|
|
SiteKind::Dungeon(_)
|
|
|
|
| SiteKind::ChapelSite(_)
|
|
|
|
| SiteKind::Gnarling(_)
|
|
|
|
| SiteKind::Adlet(_) => Some(false),
|
2023-01-05 20:25:32 +00:00
|
|
|
// Neutral
|
|
|
|
SiteKind::Settlement(_)
|
|
|
|
| SiteKind::Castle(_)
|
|
|
|
| SiteKind::Tree(_)
|
|
|
|
| SiteKind::GiantTree(_)
|
|
|
|
| SiteKind::Bridge(_) => None,
|
|
|
|
};
|
|
|
|
|
2022-08-11 14:44:57 +00:00
|
|
|
Self {
|
2023-04-06 17:25:33 +00:00
|
|
|
seed: rng.gen(),
|
2022-08-15 14:00:39 +00:00
|
|
|
wpos,
|
2022-09-05 14:03:21 +00:00
|
|
|
world_site: Some(world_site_id),
|
2023-01-05 20:25:32 +00:00
|
|
|
faction: good_or_evil.and_then(|good_or_evil| {
|
2022-09-05 14:03:21 +00:00
|
|
|
nearby_factions
|
|
|
|
.iter()
|
2023-01-05 20:25:32 +00:00
|
|
|
.filter(|(_, faction)| {
|
|
|
|
factions
|
|
|
|
.get(*faction)
|
|
|
|
.map_or(false, |f| f.good_or_evil == good_or_evil)
|
|
|
|
})
|
2022-09-05 14:03:21 +00:00
|
|
|
.min_by_key(|(faction_wpos, _)| faction_wpos.distance_squared(wpos))
|
|
|
|
.map(|(_, faction)| *faction)
|
2023-01-05 20:25:32 +00:00
|
|
|
}),
|
2023-04-06 17:25:33 +00:00
|
|
|
population: Default::default(),
|
|
|
|
known_reports: Default::default(),
|
2023-04-13 13:34:31 +00:00
|
|
|
nearby_sites_by_size: Vec::new(),
|
2022-08-11 14:44:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|