# HG changeset patch # User Jeremy Thurgood # Date 1252093770 0 # Node ID 696936621a93b5e9b24a85894a29b6f2920b5501 # Parent 355eaae40b1fc1528c9d62d60b59d9ab077b5e9a Buildings can affect visual acuity. diff -r 355eaae40b1f -r 696936621a93 gamelib/animal.py --- a/gamelib/animal.py Fri Sep 04 19:34:01 2009 +0000 +++ b/gamelib/animal.py Fri Sep 04 19:49:30 2009 +0000 @@ -15,6 +15,8 @@ """Base class for animals""" STEALTH = 0 + VISION_BONUS = 0 + VISION_RANGE_PENALTY = 10 def __init__(self, image_left, image_right, tile_pos): # Create the animal somewhere far off screen @@ -415,7 +417,16 @@ self.hunting = False self.last_steps = [] +def _get_vision_param(parameter, watcher): + param = getattr(watcher, parameter) + if watcher.abode: + modifier = getattr(watcher.abode.building, 'MODIFY_'+parameter, lambda r: r) + param = modifier(param) + return param + def visible(watcher, watchee): + vision_bonus = _get_vision_param('VISION_BONUS', watcher) + range_penalty = _get_vision_param('VISION_RANGE_PENALTY', watcher) + distance = watcher.pos.dist(watchee.pos) - 1 roll = random.randint(1, 100) - distance = watcher.pos.dist(watchee.pos) - 1 - return roll > watchee.STEALTH + 10*distance + return roll > watchee.STEALTH - vision_bonus + range_penalty*distance diff -r 355eaae40b1f -r 696936621a93 gamelib/buildings.py --- a/gamelib/buildings.py Fri Sep 04 19:34:01 2009 +0000 +++ b/gamelib/buildings.py Fri Sep 04 19:49:30 2009 +0000 @@ -214,6 +214,8 @@ MODIFY_GUN_RANGE = lambda s, x: (3*x)/2 MODIFY_GUN_BASE_HIT = lambda s, x: x-5 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 def is_building(obj): """Return true if obj is a build class."""