# HG changeset patch # User Jeremy Thurgood # Date 1258826128 0 # Node ID 95b81e9173994852ab14d0c7cb657e61474c0bce # Parent 2b4cd86dfcaf418eb1a7c04cad83eb0e8f8dd086 Buildings block line-of-sight, except for occupants. diff -r 2b4cd86dfcaf -r 95b81e917399 gamelib/animal.py --- 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 diff -r 2b4cd86dfcaf -r 95b81e917399 gamelib/buildings.py --- a/gamelib/buildings.py Sat Nov 21 17:47:27 2009 +0000 +++ b/gamelib/buildings.py Sat Nov 21 17:55:28 2009 +0000 @@ -70,6 +70,7 @@ ABODE = False FLOORS = None HENHOUSE = False + BLOCKS_VISION = True SIMPLIFY = [ 'pos', @@ -366,6 +367,7 @@ MODIFY_GUN_RANGE_PENALTY = lambda s, x: x-1 MODIFY_VISION_BONUS = lambda s, x: x+10 MODIFY_VISION_RANGE_PENALTY = lambda s, x: x-2 + BLOCKS_VISION = False class Fence(Building): """A fence.""" @@ -384,6 +386,8 @@ SELECTED_IMAGE_BROKEN = 'tiles/broken_fence.png' NAME = 'Fence' + BLOCKS_VISION = False + def is_building(obj): """Return true if obj is a build class."""