veloren_rtsim/rule/npc_ai/
util.rs1use super::*;
2
3pub fn site_name(ctx: &NpcCtx, site_id: impl Into<Option<SiteId>>) -> Option<String> {
4 let world_site = ctx.state.data().sites.get(site_id.into()?)?.world_site?;
5 Some(ctx.index.sites.get(world_site).name().to_string())
6}
7
8pub fn locate_actor(ctx: &NpcCtx, actor: Actor) -> Option<Vec3<f32>> {
9 match actor {
10 Actor::Npc(npc_id) => ctx.state.data().npcs.get(npc_id).map(|npc| npc.wpos),
11 Actor::Character(character_id) => ctx
12 .system_data
13 .id_maps
14 .character_entity(character_id)
15 .and_then(|c| ctx.system_data.positions.get(c))
16 .map(|p| p.0),
17 }
18}
19
20pub fn actor_exists(ctx: &NpcCtx, actor: Actor) -> bool {
21 match actor {
22 Actor::Npc(npc_id) => ctx.state.data().npcs.contains_key(npc_id),
23 Actor::Character(character_id) => ctx
24 .system_data
25 .id_maps
26 .character_entity(character_id)
27 .is_some(),
28 }
29}