diff gamelib/animal.py @ 437:95b81e917399

Buildings block line-of-sight, except for occupants.
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 21 Nov 2009 17:55:28 +0000
parents 129de5883524
children 16437cf4a2b8
line wrap: on
line diff
--- a/gamelib/animal.py	Sat Nov 21 17:47:27 2009 +0000
+++ b/gamelib/animal.py	Sat Nov 21 17:55:28 2009 +0000
@@ -250,7 +250,7 @@
         """Choose a random fox within range of this weapon."""
         killable_foxes = []
         for fox in gameboard.foxes:
-            if not visible(self, fox):
+            if not visible(self, fox, gameboard):
                 continue
             if weapon.in_range(gameboard, self, fox):
                 killable_foxes.append(fox)
@@ -659,9 +659,15 @@
         param = modifier(param)
     return param
 
-def visible(watcher, watchee):
+def visible(watcher, watchee, gameboard):
     vision_bonus = _get_vision_param('VISION_BONUS', watcher)
     range_penalty = _get_vision_param('VISION_RANGE_PENALTY', watcher)
+    positions = watcher.pos.intermediate_positions(watchee.pos)
+    for pos in positions:
+        building = gameboard.get_building(pos.to_tile_tuple())
+        # This allows chickens to fire across GuardTowers and Fences.
+        if building and building.BLOCKS_VISION and not (watcher in building.occupants()):
+            return False
     distance = watcher.pos.dist(watchee.pos) - 1
     roll = random.randint(1, 100)
     return roll > watchee.STEALTH - vision_bonus + range_penalty*distance