Mercurial > rinkhals
comparison gamelib/animal.py @ 397:532f1ea476ff
Make foxes enter buildings, with a seperate count for them
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Fri, 13 Nov 2009 14:14:57 +0000 |
parents | 19e583e5cdc0 |
children | 082b1ea5f98d |
comparison
equal
deleted
inserted
replaced
396:19e583e5cdc0 | 397:532f1ea476ff |
---|---|
271 self.dig_pos = None | 271 self.dig_pos = None |
272 self.tick = 0 | 272 self.tick = 0 |
273 self.safe = False | 273 self.safe = False |
274 self.closest = None | 274 self.closest = None |
275 self.last_steps = [] | 275 self.last_steps = [] |
276 # Foxes don't occupy places in the same way chickens do, but they | |
277 # can still be inside | |
278 self.building = None | |
279 | |
280 def outside(self): | |
281 return self.building is None | |
276 | 282 |
277 def _game_death(self, gameboard): | 283 def _game_death(self, gameboard): |
278 gameboard.kill_fox(self) | 284 gameboard.kill_fox(self) |
279 | 285 |
280 def _cost_tile(self, pos, gameboard): | 286 def _cost_tile(self, pos, gameboard): |
467 # Check the another fox hasn't dug a hole for us | 473 # Check the another fox hasn't dug a hole for us |
468 # We're too busy digging to notice if a hole appears nearby, | 474 # We're too busy digging to notice if a hole appears nearby, |
469 # but we'll notice if the fence we're digging vanishes | 475 # but we'll notice if the fence we're digging vanishes |
470 this_tile = gameboard.tv.get(self.dig_pos.to_tile_tuple()) | 476 this_tile = gameboard.tv.get(self.dig_pos.to_tile_tuple()) |
471 if tiles.TILE_MAP[this_tile] == 'broken fence': | 477 if tiles.TILE_MAP[this_tile] == 'broken fence': |
472 self.tick = 0 | 478 self.tick = 0 |
473 return | 479 return |
474 else: | 480 else: |
475 # We've dug through the fence, so make a hole | 481 # We've dug through the fence, so make a hole |
476 self._make_hole(gameboard) | 482 self._make_hole(gameboard) |
477 return | 483 return |
478 if self.hunting: | 484 if self.hunting: |
479 desired_pos = self._find_path_to_chicken(gameboard) | 485 desired_pos = self._find_path_to_chicken(gameboard) |
480 else: | 486 else: |
481 desired_pos = self._find_path_to_woodland(gameboard) | 487 desired_pos = self._find_path_to_woodland(gameboard) |
482 final_pos = self._update_pos(gameboard, desired_pos) | 488 final_pos = self._update_pos(gameboard, desired_pos) |
483 self._fix_face(final_pos) | 489 self._fix_face(final_pos) |
484 self.pos = final_pos | 490 self.pos = final_pos |
491 # See if we're entering/leaving a building | |
492 building = gameboard.get_building(final_pos.to_tile_tuple()) | |
493 if building and self.outside(): | |
494 # Check if we need to enter | |
495 if self.closest and not self.closest.outside() and \ | |
496 self.closest.abode.building is building: | |
497 building.add_predator(self) | |
498 elif self.building and final_pos.z == 0: | |
499 # can only leave from the ground floor | |
500 if building == self.building: | |
501 # Check if we need to leave the building | |
502 if not self.hunting or (self.closest and | |
503 self.closest.abode.building is not building): | |
504 self.building.remove_predator(self) | |
505 else: | |
506 # we've moved away from the building we were in | |
507 self.building.remove_predator(self) | |
508 gameboard.set_visibility(self) | |
509 | |
485 | 510 |
486 class NinjaFox(Fox): | 511 class NinjaFox(Fox): |
487 """Ninja foxes are hard to see""" | 512 """Ninja foxes are hard to see""" |
488 | 513 |
489 STEALTH = 60 | 514 STEALTH = 60 |