Mercurial > rinkhals
changeset 398:082b1ea5f98d
Regain time lost when adding foxes to buildings
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Mon, 16 Nov 2009 15:27:36 +0000 |
parents | 532f1ea476ff |
children | 3294929223bd |
files | gamelib/animal.py |
diffstat | 1 files changed, 15 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/gamelib/animal.py Fri Nov 13 14:14:57 2009 +0000 +++ b/gamelib/animal.py Mon Nov 16 15:27:36 2009 +0000 @@ -466,7 +466,10 @@ def move(self, gameboard): """Foxes will aim to move towards the closest henhouse or free chicken""" - if self.dig_pos: + if self.safe: + # We're safe, so do nothing + return + elif self.dig_pos: if self.tick: self.tick -= 1 # We're still digging through the fence @@ -476,25 +479,26 @@ this_tile = gameboard.tv.get(self.dig_pos.to_tile_tuple()) if tiles.TILE_MAP[this_tile] == 'broken fence': self.tick = 0 - return else: # We've dug through the fence, so make a hole self._make_hole(gameboard) return - if self.hunting: + elif self.hunting: desired_pos = self._find_path_to_chicken(gameboard) else: desired_pos = self._find_path_to_woodland(gameboard) final_pos = self._update_pos(gameboard, desired_pos) self._fix_face(final_pos) self.pos = final_pos + change_visible = False # See if we're entering/leaving a building building = gameboard.get_building(final_pos.to_tile_tuple()) if building and self.outside(): - # Check if we need to enter - if self.closest and not self.closest.outside() and \ - self.closest.abode.building is building: - building.add_predator(self) + # Check if we need to enter + if self.closest and not self.closest.outside() and \ + self.closest.abode.building is building: + building.add_predator(self) + change_visible = True elif self.building and final_pos.z == 0: # can only leave from the ground floor if building == self.building: @@ -502,10 +506,13 @@ if not self.hunting or (self.closest and self.closest.abode.building is not building): self.building.remove_predator(self) + change_visible = True else: # we've moved away from the building we were in self.building.remove_predator(self) - gameboard.set_visibility(self) + change_visible = True + if change_visible: + gameboard.set_visibility(self) class NinjaFox(Fox):