示例#1
0
 def _link_stairs_in_room(self, next_level, stairs_type, current_level,
                          room):
     """ _link_stairs_in_room([][], str, [][], Room) => None
     Finds stairs on next level of type stairs_type and matches with oppositite
     type of stairs on current_level """
     current_type = 'StairsUp' if stairs_type == 'StairsDown' else 'StairsDown'
     #we try to find DonwStairs on the level above
     next_level_stairs = find_feature(next_level,
                                      oftype=stairs_type,
                                      multiple=True,
                                      filter=lambda x: x.pair is None)
     if next_level_stairs:  #if there are any downstairs
         for next_stairs, x, y in next_level_stairs:
             #first we check if this stairs are id-linked
             if next_stairs.id and isinstance(next_stairs.id, str):
                 pair = find_feature(current_level, id=next_stairs.id)
                 if not pair:
                     raise RuntimeError(
                         'Failed to find pair for staircases with id %s in room %s'
                         % (next_stairs.id, room.id))
                 next_stairs = _materialize_piece(next_stairs)
                 replace_feature_atxy(next_level, x, y, next_stairs)
                 next_stairs.pair = pair
                 pair[0].pair = next_stairs, x, y
                 continue
             #now for each DownStair in the upper room we find
             #UpStairs in current room, sort them by relative distance from current
             #stairs and see which of them doesn't have pair
             #todo - add id matching
             #adjust xy to room geometry
             candidates = square_search_nearest(x,
                                                y,
                                                current_level,
                                                oftype=current_type)
             if not candidates:
                 raise RuntimeError('Failed to map stairs for room %s' %
                                    room.id)
             candidates = filter(lambda x: x[0].pair is None, candidates)
             if not candidates:
                 raise RuntimeError('Failed to map stairs for room %s' %
                                    room.id)
             next_stairs = _materialize_piece(next_stairs)
             replace_feature_atxy(next_level, x, y, next_stairs)
             next_stairs.pair = candidates[0][
                 0], room.x + candidates[0][1], room.y + candidates[0][2]
             candidates[0][0].pair = next_stairs, room.x + x, room.y + y
     #time to check we matched everything
     errors = find_feature(current_level,
                           oftype=current_type,
                           filter=lambda x: x.pair is None)
     if errors:
         raise RuntimeError('Failed to map %d %s for room %s' %
                            (len(errors), current_type, room.id))
示例#2
0
    def configure(self):
        """
            configure() => None
            Invoked after place_player(player) takes place. This method should configure
            all features/critters dependant on player.
            1. It sets target monster's HD (=player.xl)
            2. Sets the levels of traps for this level

            HD-adjustment's are not made if strict_hd is specified for a critter
        """
        #first adjust creatures' HDs
        for crit in self.critters:
            if not getattr(crit, 'strict_hd', False):
                #we assume all critters has critter.hd set and we just call adjust_hd which will reset
                #critter's hd to hd + player.xl
                crit.adjust_hd(self.player.xl)
        #now configure hiddens
        hiddens = find_feature(self.current._map,
                               oftype=features.HiddenFeature,
                               multiple=True)
        #actualy all hiddens should have relative HD. So we add player's HD to that of hidden
        if hiddens:
            for hidden_feature, x, y in hiddens:
                if not (getattr(hidden_feature, 'strict_hd', False)):
                    hidden_feature.skill += self.player.xl
示例#3
0
 def _link_stairs_in_room(self, next_level, stairs_type, current_level, room):
     """ _link_stairs_in_room([][], str, [][], Room) => None
     Finds stairs on next level of type stairs_type and matches with oppositite
     type of stairs on current_level """
     current_type = 'StairsUp' if stairs_type == 'StairsDown' else 'StairsDown'
     #we try to find DonwStairs on the level above
     next_level_stairs = find_feature(next_level, oftype=stairs_type, multiple = True, filter = lambda x: x.pair is None)
     if next_level_stairs: #if there are any downstairs
         for next_stairs, x, y in next_level_stairs:
             #first we check if this stairs are id-linked
             if next_stairs.id and isinstance(next_stairs.id, str):
                 pair = find_feature(current_level, id=next_stairs.id)
                 if not pair:
                     raise RuntimeError('Failed to find pair for staircases with id %s in room %s' % (next_stairs.id, room.id))
                 next_stairs = _materialize_piece(next_stairs)
                 replace_feature_atxy(next_level, x, y, next_stairs)
                 next_stairs.pair = pair
                 pair[0].pair = next_stairs, x, y
                 continue
             #now for each DownStair in the upper room we find
             #UpStairs in current room, sort them by relative distance from current
             #stairs and see which of them doesn't have pair
             #todo - add id matching
             #adjust xy to room geometry
             candidates = square_search_nearest(x, y, current_level, oftype=current_type)
             if not candidates:
                 raise RuntimeError('Failed to map stairs for room %s' % room.id)
             candidates = filter(lambda x: x[0].pair is None, candidates)
             if not candidates:
                 raise RuntimeError('Failed to map stairs for room %s' % room.id)
             next_stairs = _materialize_piece(next_stairs)
             replace_feature_atxy(next_level, x, y, next_stairs)
             next_stairs.pair = candidates[0][0], room.x + candidates[0][1], room.y + candidates[0][2]
             candidates[0][0].pair = next_stairs, room.x + x, room.y + y
     #time to check we matched everything
     errors =  find_feature(current_level, oftype=current_type, filter=lambda x: x.pair is None)
     if errors:
         raise RuntimeError('Failed to map %d %s for room %s' %(len(errors), current_type, room.id))
示例#4
0
    def configure(self):
        """
            configure() => None
            Invoked after place_player(player) takes place. This method should configure
            all features/critters dependant on player.
            1. It sets target monster's HD (=player.xl)
            2. Sets the levels of traps for this level

            HD-adjustment's are not made if strict_hd is specified for a critter
        """
        #first adjust creatures' HDs
        for crit in self.critters:
            if not getattr(crit, 'strict_hd', False):
                #we assume all critters has critter.hd set and we just call adjust_hd which will reset
                #critter's hd to hd + player.xl
                crit.adjust_hd(self.player.xl)
        #now configure hiddens
        hiddens = find_feature(self.current._map, oftype=features.HiddenFeature, multiple=True)
        #actualy all hiddens should have relative HD. So we add player's HD to that of hidden
        if hiddens:
            for hidden_feature, x, y in hiddens:
                if not(getattr(hidden_feature, 'strict_hd', False)):
                    hidden_feature.skill += self.player.xl
 def find_features(self, id=None, oftype=None, filter=None):
     return find_feature(self.map, id, oftype, multiple=True, filter=filter)
 def find_features(self, id=None, oftype=None, filter=None):
     return find_feature(self.map, id, oftype, multiple=True, filter=filter)
示例#7
0
 def find_feature(self, id=None, oftype=None, multiple=False, filter=None):
     return find_feature(self._map, id, oftype, multiple, filter)
示例#8
0
 def find_feature(self, id=None, oftype=None, multiple=False, filter=None):
     return find_feature(self._map, id, oftype, multiple, filter)