Trading for travelers

This commit is contained in:
Joshua Barretto 2021-10-18 10:46:00 +01:00
parent 0cb88139c9
commit 9ce057212b
2 changed files with 19 additions and 10 deletions

View File

@ -46,6 +46,7 @@ const PERM_BODY: u32 = 1;
const PERM_LOADOUT: u32 = 2;
const PERM_LEVEL: u32 = 3;
const PERM_GENUS: u32 = 4;
const PERM_TRADE: u32 = 5;
impl Entity {
pub fn rng(&self, perm: u32) -> impl Rng { RandomPerm::new(self.seed + perm) }
@ -89,6 +90,23 @@ impl Entity {
}
}
pub fn get_trade_info(&self, world: &World, index: &world::IndexOwned) -> Option<trade::SiteInformation> {
let site = match self.kind {
RtSimEntityKind::Random if self.rng(PERM_TRADE).gen_bool(0.5) && false => match self.brain.route {
Travel::Path { target_id, .. } => Some(target_id),
_ => None,
},
RtSimEntityKind::Merchant => self.brain.begin_site(),
_ => None,
}?;
let site = world
.civs()
.sites[site]
.site_tmp?;
index.sites[site].trade_information(site.id())
}
pub fn get_entity_config(&self) -> &str {
match self.get_body() {
comp::Body::Humanoid(_) => humanoid_config(self.kind),

View File

@ -140,16 +140,7 @@ impl<'a> System<'a> for Sys {
.with_lazy_loadout(ad_hoc_loadout)
.with_health_scaling(10);
// Merchants can be traded with
if let Some(economy) = matches!(entity.kind, RtSimEntityKind::Merchant)
.then(|| {
entity
.brain
.begin_site()
.and_then(|home| world.civs().sites[home].site_tmp)
.and_then(|site| index.sites[site].trade_information(site.id()))
})
.flatten()
{
if let Some(economy) = entity.get_trade_info(&world, &index) {
entity_info = entity_info
.with_agent_mark(comp::agent::Mark::Merchant)
.with_economy(&economy);