Пример #1
0
 def __merge_rooms(self, _sqrs, _floors):
     _rooms = split_sets(_floors)
     while len(_rooms.keys()) > 1:
         _start = self.__pick_room(_rooms)
         _dir = self.__pick_dir(_start.value)
         r = _start.value[0]+_dir[0]
         c = _start.value[1]+_dir[1]
         
         _reject = False
         while self.__look_ahead(_sqrs, _start, _dir, r, c):
             r += _dir[0]
             c += _dir[1]
             
             if not self.__in_bounds(r,c):
                 _reject = True
                 break
         if _reject: continue
         
         if not self.__check_for_short_hallway(r, c, _dir, _sqrs, _start):
             if self.__vet_door(r, c, _dir, _sqrs, _start):
                 union(_start, _sqrs[r][c])
                 union(_start, _sqrs[r+_dir[0]][c+_dir[1]])
                 if randrange(4) < 3:
                     self._map[r][c] = self.__tf.get_terrain_tile(DOOR)
                 else:
                     self._map[r][c] = self.__floor
         _rooms = split_sets(_floors)
Пример #2
0
 def gen_map(self):
     for _row in self.__ds_nodes:
         for _node in _row:
             _merge = self.__get_candidate(_node)
             if _merge != None:
                 union(_node, _merge[0])
                 self.map[_merge[1]][_merge[2]] = self.__floor
     return self.map
Пример #3
0
 def __mark_adjacent(self, _sqr, _sqrs):
     _value = _sqr.value
     _m_row = _value[0]
     _m_col = _value[1]
     
     for r in (-1, 0, 1):
         for c in (-1, 0, 1):
             if self._map[_m_row+r][_m_col+c].get_type() == FLOOR:
                 union(_sqr, _sqrs[_m_row+r][_m_col+c])
Пример #4
0
    def __union_adj_sqr(self,sr,sc):
        if self.map[sr][sc].get_type() != FLOOR:
            return
        
        loc = (sr,sc)

        for r in (-1,0,1):
            for c in (-1,0,1):
                if self.map[sr+r][sc+c].get_type() == FLOOR \
                        and self.ds_nodes[sr][sc].parent != self.ds_nodes[sr+r][sc+c].parent:
                    union(self.ds_nodes[sr][sc], self.ds_nodes[sr+r][sc+c])
Пример #5
0
    def join_points(self,pt1):
        next_pt = pt1
        while 1:
            dir = self.get_tunnel_dir(pt1,self.center_pt)
            move = randrange(0,3)

            if move == 0:
                next_pt = (pt1[0] + dir[0],pt1[1])
            elif move == 1:
                next_pt = (pt1[0],pt1[1] + dir[1])
            else:
                next_pt = (pt1[0] + dir[0],pt1[1] + dir[1])

            if self.stop_drawing(pt1,next_pt,self.center_pt):
                return
            
            union(self.ds_nodes[next_pt[0]][next_pt[1]], self.ds_nodes[pt1[0]][pt1[1]])
            self.set_cell(next_pt[0],next_pt[1],self.__tf.get_terrain_tile(FLOOR))

            pt1 = next_pt
Пример #6
0
    def __check_for_short_hallway(self, r, c, _dir, _sqrs, start):
        _second_r = r + _dir[0]
        _second_c = c + _dir[1]
        _third_r = _second_r + _dir[0]
        _third_c = _second_c + _dir[1]

        if not self.__in_bounds(_second_r, _second_c) or not self.__in_bounds(_third_r, _third_c):
            return False
        if not self._map[_second_r][_second_c].get_type() == WALL:
            return False
        if not self._map[_third_r][_third_c].get_type() == FLOOR:
            return False
        if find(start) == find(_sqrs[_third_r][_third_c]):
            return False
    
        self._map[r][c] = self.__floor
        union(start, _sqrs[r][c])
        self._map[_second_r][_second_c] = self.__floor
        union(start, _sqrs[_second_r][_second_c])
        union(start, _sqrs[_third_r][_third_c])
    
        return True