Ejemplo n.º 1
0
 def match(self, emap):
     for row in range(len(MAP)):
         for col in range(len(MAP[row])):
             if rlfl.has_flag(self.map, (row, col), rlfl.CELL_SEEN):
                 self.assertEqual(emap[row][0][col], 'S')
             else:
                 self.assertEqual(emap[row][0][col], '-')
Ejemplo n.º 2
0
 def print_map(self, p):
     fov = []
     for row in range(len(self.map)):
         for col in range(len(self.map[row])):
             if rlfl.has_flag(self.mapnum, (row, col), rlfl.CELL_SEEN):
                 fov.append((row, col))
     super().print_map(fov, p, p)
Ejemplo n.º 3
0
    def render_examine(self, player, map):
        libtcod.console_clear(self.con_full)
        _x, _y = self.viewport.look_x, self.viewport.look_y
        if (_x, _y) == self.viewport.playerxy:
            #starting point of view
            libtcod.console_set_default_foreground(self.panel_msg, libtcod.white)
            libtcod.console_print(self.con_full, 1, 0, 'This is you'.ljust(SCREEN_WIDTH, ' '))
            libtcod.console_print(self.con_full, 1, 1, 'Press e to go back to look-around mode'.ljust(SCREEN_WIDTH, ' '))
        else:
            visible = rlfl.has_flag(map.current.fov_map0, (_x, _y), rlfl.CELL_MEMO)
            if not visible:
                libtcod.console_set_default_foreground(self.panel_msg, libtcod.white)
                libtcod.console_print(self.con_full, 1, 0, 'You can\'t see this far'.ljust(SCREEN_WIDTH, ' '))
                libtcod.console_print(self.con_full, 1, 1, 'Press e to go back to look-around mode'.ljust(SCREEN_WIDTH, ' '))
                return

            result = ''
            crit = map.critter_at(_x, _y)
            if crit:
                result +=  getattr(crit, 'description_' + player.time)
            tile_at = map.tile_at(_x, _y)
            result += tile_at.get_full_description(player.time)
            result += '\n\nPress e to go back to look-around mode.'
            libtcod.console_set_default_foreground(self.panel_msg, libtcod.white)
            libtcod.console_print(self.con_full, 0, 0, result.ljust(SCREEN_WIDTH, ' '))
            libtcod.console_blit(self.con_full, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
            libtcod.console_flush()
Ejemplo n.º 4
0
 def print_map(self, p):
     fov = []
     for row in range(len(self.map)):
         for col in range(len(self.map[row])):
             if rlfl.has_flag(self.mapnum, (row, col), rlfl.CELL_SEEN):
                 fov.append((row, col))
     super(FOV_example, self).print_map(fov, p, p)
Ejemplo n.º 5
0
 def match(self, emap):
    for row in range(len(MAP)):
         for col in range(len(MAP[row])):
             if rlfl.has_flag(self.map, (row, col), rlfl.CELL_SEEN):
                 self.assertEqual(emap[row][0][col], 'S')
             else:
                 self.assertEqual(emap[row][0][col], '-') 
Ejemplo n.º 6
0
    def iterate_fov(self, x, y, range, action):
        xy = util.iterate_fov(x, y, range, self.current.width - 1, self.current.height - 1)
        for x,y in xy:
#            if libtcod.map_is_in_fov(self.current.fov_map, x, y):
            if rlfl.has_flag(self.current.fov_map0, (x, y), rlfl.CELL_SEEN):
                tile = self.current._map[y][x]
                if tile:
                    action(tile, x, y, self.current)
Ejemplo n.º 7
0
 def iterate_fov(self, x, y, range, action):
     xy = util.iterate_fov(x, y, range, self.current.width - 1,
                           self.current.height - 1)
     for x, y in xy:
         #            if libtcod.map_is_in_fov(self.current.fov_map, x, y):
         if rlfl.has_flag(self.current.fov_map0, (x, y), rlfl.CELL_SEEN):
             tile = self.current._map[y][x]
             if tile:
                 action(tile, x, y, self.current)
Ejemplo n.º 8
0
 def test_scatter(self):
     p = ORIGOS[1]
     x, y = p
     for i in range(10):
         px, py = rlfl.scatter(self.map, p, 10, rlfl.CELL_OPEN)
         self.assertTrue(px < (x + 10))
         self.assertTrue(px >= (x - 10))
         self.assertTrue(py < (y + 10))
         self.assertTrue(py >= (y - 10))
         self.assertTrue(rlfl.has_flag(self.map, (px, py), rlfl.CELL_OPEN))
Ejemplo n.º 9
0
 def test_scatter(self):
     p = ORIGOS[1]
     x, y = p
     for i in range(10):
         px, py = rlfl.scatter(self.map, p, 10, rlfl.CELL_OPEN)
         self.assertTrue(px < (x + 10))
         self.assertTrue(px >= (x - 10))
         self.assertTrue(py < (y + 10))
         self.assertTrue(py >= (y - 10))
         self.assertTrue(rlfl.has_flag(self.map, (px, py), rlfl.CELL_OPEN))
Ejemplo n.º 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))
Ejemplo n.º 11
0
 def test_map(self):
     m = rlfl.create_map(20, 20)
     rlfl.fill_map(m, rlfl.CELL_SEEN)
     for i in range(20):
         for j in range(20):
             self.assertTrue(rlfl.has_flag(m, (i, j), rlfl.CELL_SEEN))
     rlfl.clear_map(m)
     for i in range(20):
         for j in range(20):
             self.assertFalse(rlfl.has_flag(m, (i, j), rlfl.CELL_SEEN))
     test = (
         {
             'm': -1,
             's': 'Map not initialized',
             'f': rlfl.CELL_OPEN
         },
         {
             'm': 3,
             's': 'Map not initialized',
             'f': rlfl.CELL_OPEN
         },
         {
             'm': m,
             's': 'Invalid flag used',
             'f': -1
         },
     )
     for func in ['fill_map', 'clear_map']:
         for i in test:
             try:
                 getattr(rlfl, func)(i['m'], i['f'])
             except Exception as e:
                 self.assertEqual(str(e), i['s'])
                 self.assertEqual(str(e.__class__), "<class 'rlfl.Error'>")
             else:
                 self.fail('Expected Exception: func: %s, %s' %
                           (func, i['s']))
Ejemplo n.º 12
0
 def test_map(self):
     m = rlfl.create_map(20, 20)
     rlfl.fill_map(m, rlfl.CELL_SEEN)
     for i in range(20):
         for j in range(20):
             self.assertTrue(rlfl.has_flag(m, (i, j), rlfl.CELL_SEEN))
     rlfl.clear_map(m)
     for i in range(20):
         for j in range(20):
             self.assertFalse(rlfl.has_flag(m, (i, j), rlfl.CELL_SEEN))
     test = (
         {
             'm': -1,
             's': 'Map not initialized',
             'f': rlfl.CELL_OPEN
         },
         {
             'm': 3,
             's': 'Map not initialized',
             'f': rlfl.CELL_OPEN
         },
         {
             'm': m,
             's': 'Invalid flag used',
             'f': -1
         },
     )
     for func in ['fill_map', 'clear_map']:
         for i in test:
             try:
                 getattr(rlfl, func)(i['m'], i['f'])
             except Exception as e:
                 self.assertEqual(str(e), i['s'])
                 self.assertEqual(str(e.__class__), "<class 'rlfl.Error'>")
             else:
                 self.fail('Expected Exception: func: %s, %s' % (func, i['s']))
Ejemplo n.º 13
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))
Ejemplo n.º 14
0
    def render_tile_description(self, map, player):
        libtcod.console_clear(self.panel_msg)
        _x, _y = self.viewport.look_x, self.viewport.look_y
        if (_x, _y) == self.viewport.playerxy:
            #starting point of view
            libtcod.console_set_default_foreground(self.panel_msg, libtcod.white)
            libtcod.console_print(self.panel_msg, 0, 0, 'Look-around mode. Use keys to move cursor'.ljust(SCREEN_WIDTH, ' '))
        else:
            visible = rlfl.has_flag(map.current.fov_map0, (_x, _y), rlfl.CELL_MEMO)
            if not visible:
                libtcod.console_set_default_foreground(self.panel_msg, libtcod.white)
                libtcod.console_print(self.panel_msg, 0, 0, 'You can\'t see this far'.ljust(SCREEN_WIDTH, ' '))
                return

            result = ''
            crit = map.critter_at(_x, _y)
            if crit:
                result += 'You see ' + crit.name + '.\n'
            tile_at = map.tile_at(_x, _y)
            result += tile_at.get_view_description()
            result += 'Press e to examine'
            libtcod.console_set_default_foreground(self.panel_msg, libtcod.white)
            libtcod.console_print(self.panel_msg, 0, 0, result.ljust(SCREEN_WIDTH, ' '))
Ejemplo n.º 15
0
    def render_map(self, map, player):
        #todo optimize (see http://umbrarumregnum.110mb.com/cookbook/node/24)
        if not self.viewport:
            self.viewport = Viewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, map)
        if gl.__fov_recompute__:
            gl.logger.debug('Recomputing fov')
            gl.__fov_recompute__ = False
            map.recompute_fov()

        consolex, consoley, xx = 0,0, 0
        self.viewport.update_coords(player.x, player.y)
        gl.logger.debug('Diplaying viewport from %d:%d to %d:%d' % (self.viewport.x, self.viewport.y, self.viewport.x2, self.viewport.y2))
        buffer = libtcod.ConsoleBuffer(VIEWPORT_WIDTH, VIEWPORT_HEIGHT)
        for y in xrange(self.viewport.y, self.viewport.y2):
            for x in xrange(self.viewport.x, self.viewport.x2):

                tile = map.tile_at(x, y)
                if not tile:
                    consolex += 1
                    continue
                xy = (x, y)
                seen = rlfl.has_flag(map.current.fov_map0, xy, rlfl.CELL_MEMO) | gl.__wizard_mode__
                #                visible = libtcod.map_is_in_fov(map.current.fov_map, x, y)
                visible = rlfl.has_flag(map.current.fov_map0, xy, rlfl.CELL_SEEN)
                del xy
                #if tile is seen or visible to player - print it
                char = None
                if seen or visible:
                    if tile.items and len(tile.items):
                        char = tile.items[-1].char
                    else:
                        char = tile.char
                    #                    libtcod.console_set_char(self.con, consolex, consoley, char)
                    #if it's not in LOS, but seen - print in dim color
                else:
                    char = ' '
                fc = tile.dim_color
                bc = None
                if not visible and not seen:
                    bc = BLACK
                else:
                    #if it's in LOS - print
                    fc = tile.color
                    if tile.items and len(tile.items) > 1:
                        bc = libtcod.desaturated_yellow
                    else:
                        bc = tile.color_back
                buffer.set(consolex, consoley, bc[0], bc[1], bc[2], fc[0], fc[1], fc[2], char)
                consolex += 1
            xx = consolex
            consolex = 0
            consoley += 1

        gl.logger.debug('Printing critters')
        for critter in map.critters:
            if not self.viewport.in_view(critter.x, critter.y):
                continue
            if critter.last_seen_at and not self.viewport.in_view(*critter.last_seen_at):
                continue
            fc = critter.color
            x, y = self.viewport.adjust_coords(critter.x, critter.y)
            if rlfl.has_flag(map.current.fov_map0, (critter.x, critter.y), rlfl.CELL_SEEN) or gl.__wizard_mode__:
                critter.last_seen_at = critter.x, critter.y
                buffer.set_fore(x, y, fc[0], fc[1], fc[2], critter.char)
            elif critter.last_seen_at is not None:
                color = dim_color(critter.color)
                fc = color
                buffer.set_fore(x, y, fc[0], fc[1], fc[2], critter.char)

        gl.logger.debug('Printing player')
        x, y = self.viewport.adjust_coords(player.x, player.y)
        buffer.set_fore(x, y, player.color[0], player.color[1], player.color[2], player.char)
        tile = map.tile_at(player.x, player.y)
        if tile.color_back > (200, 200, 200):
            buffer.set_back(x, y, 200, 200, 200)

        if gl.__wizard_mode__:
            libtcod.console_print(self.con, 0, VIEWPORT_HEIGHT - 1, 'WIZ MODE')

        for x in xrange(0, VIEWPORT_WIDTH):
            for y in xrange(0, VIEWPORT_HEIGHT):
                if x >= xx:
                    buffer.set_fore(x, y, 0, 0, 0, ' ')

        if gl.__lookmode__:
            buffer.set_back(self.viewport.look_x - self.viewport.x, self.viewport.look_y - self.viewport.y, 255, 255, 255)
        buffer.blit(self.con)
        libtcod.console_blit(self.con, 0, 0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 0, 0, 0)
        libtcod.console_flush()