From ce594dbdc346bef9b951b56e5eb103a0029c4d11 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Thu, 23 Nov 2017 05:16:55 -0600 Subject: -fixed path bug --- src/character.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/character.rs') diff --git a/src/character.rs b/src/character.rs index e2e2af0..a5f05b5 100644 --- a/src/character.rs +++ b/src/character.rs @@ -33,7 +33,7 @@ impl Character { pub fn action(&mut self, free_spaces : Vec<(Location,usize)>) { if self.order == Orders::Wander as u8 { - self.needs_path == false; + self.needs_path = false; self.wander(free_spaces); } else if self.order == Orders::Move as u8 { @@ -47,13 +47,20 @@ impl Character { Some(target) => { let location = self.location; let result = astar(&location, - |l| l.neighbours(impassable.clone()), - |l| l.distance(&target), - |l| *l == target); - let mut result = result.expect("No way to get to target.").0; - result.reverse(); - result.pop(); - self.path = Some(result); + |l| l.neighbours(impassable.clone()), + |l| l.distance(&target), + |l| *l == target); + self.path = match result { + Some(mut result) => { + result.0.reverse(); + result.0.pop(); + Some(result.0) + } + None => { + self.order = Orders::Wander as u8; + None + } + }; } } } -- cgit v1.2.3