comparison gamelib/animal.py @ 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
comparison
equal deleted inserted replaced
397:532f1ea476ff 398:082b1ea5f98d
464 self.dig_pos = None 464 self.dig_pos = None
465 465
466 def move(self, gameboard): 466 def move(self, gameboard):
467 """Foxes will aim to move towards the closest henhouse or free 467 """Foxes will aim to move towards the closest henhouse or free
468 chicken""" 468 chicken"""
469 if self.dig_pos: 469 if self.safe:
470 # We're safe, so do nothing
471 return
472 elif self.dig_pos:
470 if self.tick: 473 if self.tick:
471 self.tick -= 1 474 self.tick -= 1
472 # We're still digging through the fence 475 # We're still digging through the fence
473 # Check the another fox hasn't dug a hole for us 476 # Check the another fox hasn't dug a hole for us
474 # We're too busy digging to notice if a hole appears nearby, 477 # We're too busy digging to notice if a hole appears nearby,
475 # but we'll notice if the fence we're digging vanishes 478 # but we'll notice if the fence we're digging vanishes
476 this_tile = gameboard.tv.get(self.dig_pos.to_tile_tuple()) 479 this_tile = gameboard.tv.get(self.dig_pos.to_tile_tuple())
477 if tiles.TILE_MAP[this_tile] == 'broken fence': 480 if tiles.TILE_MAP[this_tile] == 'broken fence':
478 self.tick = 0 481 self.tick = 0
479 return
480 else: 482 else:
481 # We've dug through the fence, so make a hole 483 # We've dug through the fence, so make a hole
482 self._make_hole(gameboard) 484 self._make_hole(gameboard)
483 return 485 return
484 if self.hunting: 486 elif self.hunting:
485 desired_pos = self._find_path_to_chicken(gameboard) 487 desired_pos = self._find_path_to_chicken(gameboard)
486 else: 488 else:
487 desired_pos = self._find_path_to_woodland(gameboard) 489 desired_pos = self._find_path_to_woodland(gameboard)
488 final_pos = self._update_pos(gameboard, desired_pos) 490 final_pos = self._update_pos(gameboard, desired_pos)
489 self._fix_face(final_pos) 491 self._fix_face(final_pos)
490 self.pos = final_pos 492 self.pos = final_pos
493 change_visible = False
491 # See if we're entering/leaving a building 494 # See if we're entering/leaving a building
492 building = gameboard.get_building(final_pos.to_tile_tuple()) 495 building = gameboard.get_building(final_pos.to_tile_tuple())
493 if building and self.outside(): 496 if building and self.outside():
494 # Check if we need to enter 497 # Check if we need to enter
495 if self.closest and not self.closest.outside() and \ 498 if self.closest and not self.closest.outside() and \
496 self.closest.abode.building is building: 499 self.closest.abode.building is building:
497 building.add_predator(self) 500 building.add_predator(self)
501 change_visible = True
498 elif self.building and final_pos.z == 0: 502 elif self.building and final_pos.z == 0:
499 # can only leave from the ground floor 503 # can only leave from the ground floor
500 if building == self.building: 504 if building == self.building:
501 # Check if we need to leave the building 505 # Check if we need to leave the building
502 if not self.hunting or (self.closest and 506 if not self.hunting or (self.closest and
503 self.closest.abode.building is not building): 507 self.closest.abode.building is not building):
504 self.building.remove_predator(self) 508 self.building.remove_predator(self)
509 change_visible = True
505 else: 510 else:
506 # we've moved away from the building we were in 511 # we've moved away from the building we were in
507 self.building.remove_predator(self) 512 self.building.remove_predator(self)
508 gameboard.set_visibility(self) 513 change_visible = True
514 if change_visible:
515 gameboard.set_visibility(self)
509 516
510 517
511 class NinjaFox(Fox): 518 class NinjaFox(Fox):
512 """Ninja foxes are hard to see""" 519 """Ninja foxes are hard to see"""
513 520