changeset 199:696936621a93

Buildings can affect visual acuity.
author Jeremy Thurgood <firxen@gmail.com>
date Fri, 04 Sep 2009 19:49:30 +0000
parents 355eaae40b1f
children 67d10f7e0159
files gamelib/animal.py gamelib/buildings.py
diffstat 2 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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."""