Beispiel #1
0
    def show(self):
        # Start by creating a map on which to work
        # We shall import a dummy map to use

        # Import the map
        import tmap
        self.map, self.origos = tmap.MAP
        p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 = self.origos

        # Create the RLFL internal map
        width = len(self.map)
        height = len(self.map[0])
        self.map_number = rlfl.create_map(width, height)

        # We now have a map number representing the
        # internal map in rlfl

        # initialize the map
        for row in range(len(self.map)):
            for col in range(len(self.map[row])):
                if self.map[row][col] != '#':
                    p = (row, col)

                    # Set non-wall grids as open and seen
                    rlfl.set_flag(self.map_number, p, rlfl.CELL_SEEN)
                    rlfl.set_flag(self.map_number, p, rlfl.CELL_OPEN)

        # we now have a map to work on
        # LOS between 1 and 4 on the map above
        have_los = rlfl.los(self.map_number, p1, p2)
        assert (have_los == False)
        # LOS between 2 and 3
        have_los = rlfl.los(self.map_number, p2, p3)
        assert (have_los == True)

        # Measure distance
        dist = rlfl.distance(p1, p4)

        # Plot simple paths
        flags = 0
        # range (-1 for max range)
        r = -1
        path = rlfl.path(self.map_number, p1, p2, rlfl.PATH_BASIC, r, flags,
                         0.0)

        # Or real path A*
        path = rlfl.path(self.map_number, p1, p2, rlfl.PATH_ASTAR, r, flags,
                         7.0)

        # Lets calculate FOV from 3 using recursive shadowcasting
        # with a light source radius of 6
        rlfl.fov(self.map_number, p3, rlfl.FOV_SHADOW, 6)
        self.print_map(p3)

        # Use the scatter function to find a random spot (summon, teleport)
        # Here we want an open cell within range 16 from p
        require_los = False
        ps = rlfl.scatter(self.map_number, p0, 16, rlfl.CELL_OPEN, require_los)
        super(Full_example, self).print_map([], p0, ps)
Beispiel #2
0
 def setUp(self):
     rlfl.delete_all_maps()
     self.map = rlfl.create_map(len(MAP), len(MAP[0]))
     for row in range(len(MAP)):
         for col in range(len(MAP[row])):
             if MAP[row][col] != '#':
                 p = (row, col)
                 rlfl.set_flag(self.map, p, rlfl.CELL_SEEN)
                 rlfl.set_flag(self.map, p, rlfl.CELL_OPEN)
Beispiel #3
0
 def setUp(self):
     rlfl.delete_all_maps()
     self.map = rlfl.create_map(len(TMAP), len(TMAP[0]))
     for row in range(len(TMAP)):
         for col in range(len(TMAP[row])):
             if TMAP[row][col] != '#':
                 p = (row, col)
                 rlfl.set_flag(self.map, p, rlfl.CELL_SEEN) 
                 rlfl.set_flag(self.map, p, rlfl.CELL_OPEN) 
Beispiel #4
0
 def show(self):
     # Start by creating a map on which to work
     # We shall import a dummy map to use
     
     # Import the map
     import tmap
     self.map, self.origos = tmap.MAP
     p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 = self.origos
     
     # Create the RLFL internal map
     width = len(self.map)
     height = len(self.map[0])
     self.map_number = rlfl.create_map(width, height)
     
     # We now have a map number representing the 
     # internal map in rlfl
     
     # initialize the map
     for row in range(len(self.map)):
         for col in range(len(self.map[row])):
             if self.map[row][col] != '#':
                 p = (row, col)
                 
                 # Set non-wall grids as open and seen
                 rlfl.set_flag(self.map_number, p, rlfl.CELL_SEEN) 
                 rlfl.set_flag(self.map_number, p, rlfl.CELL_OPEN)
                 
     # we now have a map to work on
     # LOS between 1 and 4 on the map above
     have_los = rlfl.los(self.map_number, p1, p2)
     assert(have_los == False)
     # LOS between 2 and 3
     have_los = rlfl.los(self.map_number, p2, p3)
     assert(have_los == True)
     
     # Measure distance
     dist = rlfl.distance(p1, p4)
     
     # Plot simple paths
     flags = 0
     # range (-1 for max range)
     r = -1 
     path = rlfl.path(self.map_number, p1, p2, rlfl.PATH_BASIC, r, flags, 0.0)
     
     # Or real path A*
     path = rlfl.path(self.map_number, p1, p2, rlfl.PATH_ASTAR, r, flags, 7.0)
     
     # Lets calculate FOV from 3 using recursive shadowcasting
     # with a light source radius of 6
     rlfl.fov(self.map_number, p3, rlfl.FOV_SHADOW, 6)
     self.print_map(p3) 
     
     # Use the scatter function to find a random spot (summon, teleport)
     # Here we want an open cell within range 16 from p
     require_los = False
     ps = rlfl.scatter(self.map_number, p0, 16, rlfl.CELL_OPEN, require_los)
     super(Full_example, self).print_map([], p0, ps)
Beispiel #5
0
 def create_map(self, m):
     # Import the map
     imap = __import__(m)
     self.map, self.origos = imap.MAP
     
     # Create the RLFL internal map
     self.mapnum = rlfl.create_map(len(self.map), len(self.map[0]))
     for row in range(len(self.map)):
         for col in range(len(self.map[row])):
             if self.map[row][col] != '#':
                 p = (row, col)
                 # Set non-wall grids as open
                 rlfl.set_flag(self.mapnum, p, rlfl.CELL_OPEN)
Beispiel #6
0
    def create_map(self, m):
        # Import the map
        imap = __import__(m)
        self.map, self.origos = imap.MAP

        # Create the RLFL internal map
        self.mapnum = rlfl.create_map(len(self.map), len(self.map[0]))
        for row in range(len(self.map)):
            for col in range(len(self.map[row])):
                if self.map[row][col] != '#':
                    p = (row, col)
                    # Set non-wall grids as open
                    rlfl.set_flag(self.mapnum, p, rlfl.CELL_OPEN)
Beispiel #7
0
 def test_gf(self):
     m = rlfl.create_map(20, 20)
     rlfl.set_flag(m, (10, 10), rlfl.CELL_OPEN)
     self.assertTrue(rlfl.has_flag(m, (10, 10), rlfl.CELL_OPEN))
     rlfl.set_flag(m, (10, 10), rlfl.CELL_WALK)
     self.assertTrue(rlfl.has_flag(m, (10, 10), rlfl.CELL_OPEN|rlfl.CELL_WALK))
     rlfl.clear_flag(m, (10, 10), rlfl.CELL_WALK)
     self.assertTrue(rlfl.has_flag(m, (10, 10), rlfl.CELL_OPEN|rlfl.CELL_WALK))
     rlfl.clear_flag(m, (10, 10), rlfl.CELL_OPEN)
     self.assertFalse(rlfl.has_flag(m, (10, 10), rlfl.CELL_OPEN|rlfl.CELL_WALK))
     for i in range(0, 20):
         self.assertTrue(rlfl.has_flag(m, (0, i), rlfl.CELL_PERM))
         self.assertTrue(rlfl.has_flag(m, (19, i), rlfl.CELL_PERM))
         self.assertTrue(rlfl.has_flag(m, (i, 0), rlfl.CELL_PERM))
         self.assertTrue(rlfl.has_flag(m, (i, 19), rlfl.CELL_PERM))
Beispiel #8
0
    def update_fov_for(self, x, y):
#        libtcod.map_set_properties(self.current.fov_map, x, y, not self.tile_at(x, y).flags & features.BLOCK_LOS,
#                                           not self.tile_at(x, y).flags & features.BLOCK_WALK)

#        if self.tile_at(x, y).flags & features.BLOCK_LOS:
#            flags = rlfl.CELL_WALK
        xy = (x, y)
        fov_map_ = self.current.fov_map0
        tile = self.tile_at(*xy)
        if not tile:
            return
        if tile.flags & features.BLOCK_WALK:
            if tile.flags & features.BLOCK_LOS == features.BLOCK_LOS:
                return

        flags = rlfl.get_flags(fov_map_, xy)
        flags |= rlfl.CELL_OPEN | rlfl.CELL_WALK
        rlfl.set_flag(fov_map_, xy, flags)
Beispiel #9
0
    def update_fov_for(self, x, y):
        #        libtcod.map_set_properties(self.current.fov_map, x, y, not self.tile_at(x, y).flags & features.BLOCK_LOS,
        #                                           not self.tile_at(x, y).flags & features.BLOCK_WALK)

        #        if self.tile_at(x, y).flags & features.BLOCK_LOS:
        #            flags = rlfl.CELL_WALK
        xy = (x, y)
        fov_map_ = self.current.fov_map0
        tile = self.tile_at(*xy)
        if not tile:
            return
        if tile.flags & features.BLOCK_WALK:
            if tile.flags & features.BLOCK_LOS == features.BLOCK_LOS:
                return

        flags = rlfl.get_flags(fov_map_, xy)
        flags |= rlfl.CELL_OPEN | rlfl.CELL_WALK
        rlfl.set_flag(fov_map_, xy, flags)
Beispiel #10
0
 def test_gf(self):
     m = rlfl.create_map(20, 20)
     rlfl.set_flag(m, (10, 10), rlfl.CELL_OPEN)
     self.assertTrue(rlfl.has_flag(m, (10, 10), rlfl.CELL_OPEN))
     rlfl.set_flag(m, (10, 10), rlfl.CELL_WALK)
     self.assertTrue(
         rlfl.has_flag(m, (10, 10), rlfl.CELL_OPEN | rlfl.CELL_WALK))
     rlfl.clear_flag(m, (10, 10), rlfl.CELL_WALK)
     self.assertTrue(
         rlfl.has_flag(m, (10, 10), rlfl.CELL_OPEN | rlfl.CELL_WALK))
     rlfl.clear_flag(m, (10, 10), rlfl.CELL_OPEN)
     self.assertFalse(
         rlfl.has_flag(m, (10, 10), rlfl.CELL_OPEN | rlfl.CELL_WALK))
     for i in range(0, 20):
         self.assertTrue(rlfl.has_flag(m, (0, i), rlfl.CELL_PERM))
         self.assertTrue(rlfl.has_flag(m, (19, i), rlfl.CELL_PERM))
         self.assertTrue(rlfl.has_flag(m, (i, 0), rlfl.CELL_PERM))
         self.assertTrue(rlfl.has_flag(m, (i, 19), rlfl.CELL_PERM))
Beispiel #11
0
    def show_path_away(self, p1, p2, type, m, r=30, flags=0, diagonal=1.0):
        # Import the map
        imap = __import__(m)
        self.map, origos = imap.MAP

        # Create the RLFL internal map
        mapnum = rlfl.create_map(len(self.map), len(self.map[0]))
        for row in range(len(self.map)):
            for col in range(len(self.map[row])):
                if self.map[row][col] != '#':
                    p = (row, col)
                    # Set non-wall grids as open and seen
                    rlfl.set_flag(mapnum, p, rlfl.CELL_SEEN)
                    rlfl.set_flag(mapnum, p, rlfl.CELL_OPEN)

        # Fetch points to path
        p1, p2 = (origos[p1], origos[p2])

        # Create the path
        path = rlfl.path_away(mapnum, p1, p2, type, r, flags, diagonal)

        # Print the path
        self.print_map(path, p1, p2)
Beispiel #12
0
 def show_path_away(self, p1, p2, type, m, r=30, flags=0, diagonal=1.0):
     # Import the map
     imap = __import__(m)
     self.map, origos = imap.MAP
     
     # Create the RLFL internal map
     mapnum = rlfl.create_map(len(self.map), len(self.map[0]))
     for row in range(len(self.map)):
         for col in range(len(self.map[row])):
             if self.map[row][col] != '#':
                 p = (row, col)
                 # Set non-wall grids as open and seen
                 rlfl.set_flag(mapnum, p, rlfl.CELL_SEEN) 
                 rlfl.set_flag(mapnum, p, rlfl.CELL_OPEN)
                 
     # Fetch points to path
     p1, p2 = (origos[p1], origos[p2])    
     
     # Create the path
     path = rlfl.path_away(mapnum, p1, p2, type, r, flags, diagonal)
     
     # Print the path
     self.print_map(path, p1, p2)