changeset 394:ad77b3b71b08

Fix crash when multiple foxes finish digging at the same time
author Neil Muller <drnlmuller@gmail.com>
date Thu, 12 Nov 2009 15:19:12 +0000
parents 8104e82afd7a
children 2d0ff46118e2
files gamelib/animal.py
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/animal.py	Wed Nov 11 16:17:02 2009 +0000
+++ b/gamelib/animal.py	Thu Nov 12 15:19:12 2009 +0000
@@ -426,7 +426,10 @@
 
     def _make_hole(self, gameboard):
         """Make a hole in the fence"""
-        gameboard.get_building(self.dig_pos.to_tuple()).damage(gameboard.tv)
+        fence = gameboard.get_building(self.dig_pos.to_tuple())
+        # Another fox could have made the same hole this turn
+        if fence:
+            fence.damage(gameboard.tv)
         self.dig_pos = None
 
     def move(self, gameboard):
@@ -511,8 +514,9 @@
     def _make_hole(self, gameboard):
         """The Rinkhals eats fences"""
         fence = gameboard.get_building(self.dig_pos.to_tuple())
-        fence.remove(gameboard.tv)
-        gameboard.remove_building(fence)
+        if fence:
+            fence.remove(gameboard.tv)
+            gameboard.remove_building(fence)
         self.dig_pos = None
 
     def damage(self, gameboard):