Mercurial > rinkhals
changeset 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 | 2b4cd86dfcaf |
children | 16437cf4a2b8 |
files | gamelib/animal.py gamelib/buildings.py |
diffstat | 2 files changed, 12 insertions(+), 2 deletions(-) [+] |
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
--- 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."""