fix captain dismounting and don't panic in RandomField::choose

This commit is contained in:
Isse 2023-12-12 20:12:45 +01:00
parent 8569f30336
commit 96a3c81cbb
4 changed files with 14 additions and 9 deletions

View File

@ -237,7 +237,13 @@ impl<'a> AgentData<'a> {
'activity: { 'activity: {
match agent.rtsim_controller.activity { match agent.rtsim_controller.activity {
Some(NpcActivity::Goto(travel_to, speed_factor)) => { 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 has an rtsim destination and can fly, then it should.
// If it is flying and bumps something above it, then it should move down. // If it is flying and bumps something above it, then it should move down.

View File

@ -2146,7 +2146,7 @@ impl FigureMgr {
active_tool_kind, active_tool_kind,
second_tool_kind, second_tool_kind,
character_activity character_activity
.and_then(|a| a.steer_dir) .map(|a| a.steer_dir)
.unwrap_or(0.0), .unwrap_or(0.0),
time, time,
), ),

View File

@ -942,7 +942,7 @@ impl Structure for Tavern {
let mut offset = 0; let mut offset = 0;
let mut choose = |slice: &[Rgb<u8>]| -> Rgb<u8> { let mut choose = |slice: &[Rgb<u8>]| -> Rgb<u8> {
offset += 1; offset += 1;
*field.choose(self.door_wpos + offset, slice) *field.choose(self.door_wpos + offset, slice).unwrap()
}; };
let detail_fill = Fill::Brick( let detail_fill = Fill::Brick(

View File

@ -16,14 +16,13 @@ impl RandomField {
(self.get(pos) % (1 << 16)) as f32 / ((1 << 16) as f32) (self.get(pos) % (1 << 16)) as f32 / ((1 << 16) as f32)
} }
/// # Panics pub fn choose<'a, T>(&self, pos: Vec3<i32>, slice: &'a [T]) -> Option<&'a T> {
/// Panics if the slice is empty. if slice.is_empty() {
pub fn choose<'a, T>(&self, pos: Vec3<i32>, slice: &'a [T]) -> &'a T { return None;
assert!(!slice.is_empty()); }
let i = self.get(pos) as usize; let i = self.get(pos) as usize;
slice.get(i % slice.len())
&slice[i % slice.len()]
} }
} }