summaryrefslogtreecommitdiff
path: root/src/character.rs
diff options
context:
space:
mode:
authorTom Barrett <tombarrett@siu.edu>2017-11-23 05:16:55 -0600
committerTom Barrett <tombarrett@siu.edu>2017-11-23 05:16:55 -0600
commitce594dbdc346bef9b951b56e5eb103a0029c4d11 (patch)
tree0a7deb1c243422606014b52e8b21576b06b32047 /src/character.rs
parentaed9ad18c72c016da7894328710e9996c5629c0a (diff)
-fixed path bug
Diffstat (limited to 'src/character.rs')
-rw-r--r--src/character.rs23
1 files changed, 15 insertions, 8 deletions
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
+ }
+ };
}
}
}