Mercurial > rinkhals
comparison 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 |
comparison
equal
deleted
inserted
replaced
436:2b4cd86dfcaf | 437:95b81e917399 |
---|---|
248 | 248 |
249 def _find_killable_fox(self, weapon, gameboard): | 249 def _find_killable_fox(self, weapon, gameboard): |
250 """Choose a random fox within range of this weapon.""" | 250 """Choose a random fox within range of this weapon.""" |
251 killable_foxes = [] | 251 killable_foxes = [] |
252 for fox in gameboard.foxes: | 252 for fox in gameboard.foxes: |
253 if not visible(self, fox): | 253 if not visible(self, fox, gameboard): |
254 continue | 254 continue |
255 if weapon.in_range(gameboard, self, fox): | 255 if weapon.in_range(gameboard, self, fox): |
256 killable_foxes.append(fox) | 256 killable_foxes.append(fox) |
257 if not killable_foxes: | 257 if not killable_foxes: |
258 return None | 258 return None |
657 if watcher.abode: | 657 if watcher.abode: |
658 modifier = getattr(watcher.abode.building, 'MODIFY_'+parameter, lambda r: r) | 658 modifier = getattr(watcher.abode.building, 'MODIFY_'+parameter, lambda r: r) |
659 param = modifier(param) | 659 param = modifier(param) |
660 return param | 660 return param |
661 | 661 |
662 def visible(watcher, watchee): | 662 def visible(watcher, watchee, gameboard): |
663 vision_bonus = _get_vision_param('VISION_BONUS', watcher) | 663 vision_bonus = _get_vision_param('VISION_BONUS', watcher) |
664 range_penalty = _get_vision_param('VISION_RANGE_PENALTY', watcher) | 664 range_penalty = _get_vision_param('VISION_RANGE_PENALTY', watcher) |
665 positions = watcher.pos.intermediate_positions(watchee.pos) | |
666 for pos in positions: | |
667 building = gameboard.get_building(pos.to_tile_tuple()) | |
668 # This allows chickens to fire across GuardTowers and Fences. | |
669 if building and building.BLOCKS_VISION and not (watcher in building.occupants()): | |
670 return False | |
665 distance = watcher.pos.dist(watchee.pos) - 1 | 671 distance = watcher.pos.dist(watchee.pos) - 1 |
666 roll = random.randint(1, 100) | 672 roll = random.randint(1, 100) |
667 return roll > watchee.STEALTH - vision_bonus + range_penalty*distance | 673 return roll > watchee.STEALTH - vision_bonus + range_penalty*distance |
668 | 674 |
669 # These don't have to add up to 100, but it's easier to think | 675 # These don't have to add up to 100, but it's easier to think |