mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added rtsim merchants to site2
This commit is contained in:
parent
bacb2aa504
commit
e3ab8fc8ce
@ -137,7 +137,7 @@ impl assets::Asset for EntityConfig {
|
||||
impl EntityConfig {
|
||||
pub fn from_asset_expect(asset_specifier: &str) -> Self {
|
||||
Self::load_owned(asset_specifier)
|
||||
.unwrap_or_else(|e| panic!("Failed to load {}. Error: {}", asset_specifier, e))
|
||||
.unwrap_or_else(|e| panic!("Failed to load {}. Error: {:?}", asset_specifier, e))
|
||||
}
|
||||
|
||||
pub fn with_body(mut self, body: BodyBuilder) -> Self {
|
||||
|
@ -31,6 +31,7 @@ pub enum RtSimEntityKind {
|
||||
Random,
|
||||
Cultist,
|
||||
Villager,
|
||||
Merchant,
|
||||
}
|
||||
|
||||
const BIRD_LARGE_ROSTER: &[comp::bird_large::Species] = &[
|
||||
@ -79,13 +80,7 @@ impl Entity {
|
||||
},
|
||||
}
|
||||
},
|
||||
RtSimEntityKind::Cultist => {
|
||||
let species = *(&comp::humanoid::ALL_SPECIES)
|
||||
.choose(&mut self.rng(PERM_SPECIES))
|
||||
.unwrap();
|
||||
comp::humanoid::Body::random_with(&mut self.rng(PERM_BODY), &species).into()
|
||||
},
|
||||
RtSimEntityKind::Villager => {
|
||||
RtSimEntityKind::Cultist | RtSimEntityKind::Villager | RtSimEntityKind::Merchant => {
|
||||
let species = *(&comp::humanoid::ALL_SPECIES)
|
||||
.choose(&mut self.rng(PERM_SPECIES))
|
||||
.unwrap();
|
||||
@ -109,14 +104,21 @@ impl Entity {
|
||||
// is not used for RtSim as of now.
|
||||
pub fn get_adhoc_loadout(
|
||||
&self,
|
||||
world: &World,
|
||||
index: &world::IndexOwned,
|
||||
) -> fn(LoadoutBuilder, Option<&trade::SiteInformation>) -> LoadoutBuilder {
|
||||
let body = self.get_body();
|
||||
let kind = &self.kind;
|
||||
let kind = self.kind;
|
||||
|
||||
// give potions to traveler humanoids or return loadout as is otherwise
|
||||
if let (comp::Body::Humanoid(_), RtSimEntityKind::Random) = (body, kind) {
|
||||
|l, _| l.bag(ArmorSlot::Bag1, Some(make_potion_bag(100)))
|
||||
} else {
|
||||
|l, _| l
|
||||
match (body, kind) {
|
||||
(comp::Body::Humanoid(_), RtSimEntityKind::Random) => {
|
||||
|l, _| l.bag(ArmorSlot::Bag1, Some(make_potion_bag(100)))
|
||||
},
|
||||
(_, RtSimEntityKind::Merchant) => {
|
||||
|l, trade| l.with_creator(world::site::settlement::merchant_loadout, trade)
|
||||
},
|
||||
_ => |l, _| l,
|
||||
}
|
||||
}
|
||||
|
||||
@ -666,7 +668,7 @@ impl Brain {
|
||||
|
||||
pub fn villager(home_id: Id<Site>) -> Self {
|
||||
Self {
|
||||
begin: None,
|
||||
begin: Some(home_id),
|
||||
tgt: None,
|
||||
route: Travel::Idle,
|
||||
last_visited: None,
|
||||
@ -674,6 +676,18 @@ impl Brain {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merchant(home_id: Id<Site>) -> Self {
|
||||
Self {
|
||||
begin: Some(home_id),
|
||||
tgt: None,
|
||||
route: Travel::Idle,
|
||||
last_visited: None,
|
||||
memories: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn begin_site(&self) -> Option<Id<Site>> { self.begin }
|
||||
|
||||
pub fn add_memory(&mut self, memory: Memory) { self.memories.push(memory); }
|
||||
|
||||
pub fn forget_enemy(&mut self, to_forget: &str) {
|
||||
@ -733,6 +747,7 @@ fn humanoid_config(kind: RtSimEntityKind) -> &'static str {
|
||||
RtSimEntityKind::Cultist => "common.entity.dungeon.tier-5.cultist",
|
||||
RtSimEntityKind::Random => "common.entity.world.traveler",
|
||||
RtSimEntityKind::Villager => "common.loadout.village.villager",
|
||||
RtSimEntityKind::Merchant => "common.loadout.village.merchant",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -217,6 +217,29 @@ pub fn init(
|
||||
brain: Brain::villager(site_id),
|
||||
});
|
||||
}
|
||||
|
||||
for _ in 0..site2.plazas().len() * 3 {
|
||||
rtsim.entities.insert(Entity {
|
||||
is_loaded: false,
|
||||
pos: site2
|
||||
.plazas()
|
||||
.choose(&mut thread_rng())
|
||||
.map_or(site.get_origin(), |p| {
|
||||
site2.tile_center_wpos(site2.plot(p).root_tile())
|
||||
+ Vec2::new(
|
||||
thread_rng().gen_range(-8..9),
|
||||
thread_rng().gen_range(-8..9),
|
||||
)
|
||||
})
|
||||
.with_z(0)
|
||||
.map(|e| e as f32),
|
||||
seed: thread_rng().gen(),
|
||||
controller: RtSimController::default(),
|
||||
last_time_ticked: 0.0,
|
||||
kind: RtSimEntityKind::Merchant,
|
||||
brain: Brain::merchant(site_id),
|
||||
});
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ impl<'a> System<'a> for Sys {
|
||||
} else {
|
||||
let entity_config_path = entity.get_entity_config();
|
||||
let mut loadout_rng = entity.loadout_rng();
|
||||
let ad_hoc_loadout = entity.get_adhoc_loadout();
|
||||
let ad_hoc_loadout = entity.get_adhoc_loadout(&world, &index);
|
||||
// Body is rewritten so that body parameters
|
||||
// are consistent between reifications
|
||||
let entity_config = EntityConfig::from_asset_expect(entity_config_path)
|
||||
|
@ -2,7 +2,7 @@ mod block_mask;
|
||||
mod castle;
|
||||
pub mod economy;
|
||||
pub mod namegen;
|
||||
mod settlement;
|
||||
pub mod settlement;
|
||||
mod tree;
|
||||
|
||||
// Reexports
|
||||
@ -120,6 +120,24 @@ impl Site {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn trade_information(
|
||||
&self,
|
||||
site_id: common::trade::SiteId,
|
||||
) -> Option<common::trade::SiteInformation> {
|
||||
match &self.kind {
|
||||
SiteKind::Settlement(s) => Some(common::trade::SiteInformation {
|
||||
id: site_id,
|
||||
unconsumed_stock: self
|
||||
.economy
|
||||
.unconsumed_stock
|
||||
.iter()
|
||||
.map(|(g, a)| (g.into(), *a))
|
||||
.collect(),
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply_to<'a>(&'a self, canvas: &mut Canvas, dynamic_rng: &mut impl Rng) {
|
||||
let info = canvas.info();
|
||||
let get_col = |wpos| info.col(wpos + info.wpos);
|
||||
@ -143,15 +161,9 @@ impl Site {
|
||||
) {
|
||||
match &self.kind {
|
||||
SiteKind::Settlement(s) => {
|
||||
let economy = common::trade::SiteInformation {
|
||||
id: site_id,
|
||||
unconsumed_stock: self
|
||||
.economy
|
||||
.unconsumed_stock
|
||||
.iter()
|
||||
.map(|(g, a)| (g.into(), *a))
|
||||
.collect(),
|
||||
};
|
||||
let economy = self
|
||||
.trade_information(site_id)
|
||||
.expect("Settlement has no economy");
|
||||
s.apply_supplement(dynamic_rng, wpos2d, get_column, supplement, economy)
|
||||
},
|
||||
SiteKind::Dungeon(d) => d.apply_supplement(dynamic_rng, wpos2d, supplement),
|
||||
|
@ -1022,7 +1022,7 @@ fn humanoid(pos: Vec3<f32>, economy: &SiteInformation, dynamic_rng: &mut impl Rn
|
||||
}
|
||||
}
|
||||
|
||||
fn merchant_loadout(
|
||||
pub fn merchant_loadout(
|
||||
loadout_builder: LoadoutBuilder,
|
||||
economy: Option<&trade::SiteInformation>,
|
||||
) -> LoadoutBuilder {
|
||||
|
@ -79,6 +79,10 @@ impl Site {
|
||||
|
||||
pub fn plots(&self) -> impl ExactSizeIterator<Item = &Plot> + '_ { self.plots.values() }
|
||||
|
||||
pub fn plazas(&self) -> impl ExactSizeIterator<Item = Id<Plot>> + '_ {
|
||||
self.plazas.iter().copied()
|
||||
}
|
||||
|
||||
pub fn create_plot(&mut self, plot: Plot) -> Id<Plot> { self.plots.insert(plot) }
|
||||
|
||||
pub fn blit_aabr(&mut self, aabr: Aabr<i32>, tile: Tile) {
|
||||
|
Loading…
Reference in New Issue
Block a user