From 96a3c81cbbc725ebc1f0189a162b65b8e8c0d82e Mon Sep 17 00:00:00 2001 From: Isse Date: Tue, 12 Dec 2023 20:12:45 +0100 Subject: [PATCH] fix captain dismounting and don't panic in RandomField::choose --- server/agent/src/action_nodes.rs | 8 +++++++- voxygen/src/scene/figure/mod.rs | 2 +- world/src/site2/plot/tavern.rs | 2 +- world/src/util/random.rs | 11 +++++------ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/server/agent/src/action_nodes.rs b/server/agent/src/action_nodes.rs index 6189744136..bf83a93e44 100644 --- a/server/agent/src/action_nodes.rs +++ b/server/agent/src/action_nodes.rs @@ -237,7 +237,13 @@ impl<'a> AgentData<'a> { 'activity: { match agent.rtsim_controller.activity { Some(NpcActivity::Goto(travel_to, speed_factor)) => { - self.dismount(controller, read_data); + if read_data + .is_volume_riders + .get(*self.entity) + .map_or(false, |r| !r.is_steering_entity()) + { + controller.push_event(ControlEvent::Unmount); + } // If it has an rtsim destination and can fly, then it should. // If it is flying and bumps something above it, then it should move down. diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 4ac0c3afb8..720baee7f0 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -2146,7 +2146,7 @@ impl FigureMgr { active_tool_kind, second_tool_kind, character_activity - .and_then(|a| a.steer_dir) + .map(|a| a.steer_dir) .unwrap_or(0.0), time, ), diff --git a/world/src/site2/plot/tavern.rs b/world/src/site2/plot/tavern.rs index e647626dab..0b1987d630 100644 --- a/world/src/site2/plot/tavern.rs +++ b/world/src/site2/plot/tavern.rs @@ -942,7 +942,7 @@ impl Structure for Tavern { let mut offset = 0; let mut choose = |slice: &[Rgb]| -> Rgb { offset += 1; - *field.choose(self.door_wpos + offset, slice) + *field.choose(self.door_wpos + offset, slice).unwrap() }; let detail_fill = Fill::Brick( diff --git a/world/src/util/random.rs b/world/src/util/random.rs index 00e05bf1fb..ceee42c7ab 100644 --- a/world/src/util/random.rs +++ b/world/src/util/random.rs @@ -16,14 +16,13 @@ impl RandomField { (self.get(pos) % (1 << 16)) as f32 / ((1 << 16) as f32) } - /// # Panics - /// Panics if the slice is empty. - pub fn choose<'a, T>(&self, pos: Vec3, slice: &'a [T]) -> &'a T { - assert!(!slice.is_empty()); + pub fn choose<'a, T>(&self, pos: Vec3, slice: &'a [T]) -> Option<&'a T> { + if slice.is_empty() { + return None; + } let i = self.get(pos) as usize; - - &slice[i % slice.len()] + slice.get(i % slice.len()) } }