def move_astar(self, target): libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y1 in range(MAP_HEIGHT): for x1 in range(MAP_WIDTH): libtcod.map_set_properties(fov, x1, y1, not map[x1][y1].block_sight, not map[x1][y1].blocked) for obj in objects: if obj.blocks and obj != self and obj != target: libtcod.map_set_properties(fov, obj.x, obj.y, True, False)
def initialize_fov(): """ calculate FOV and FOH Maps of the Player """ libtcod.console_clear(gvar.con) gvar.fov_recompute = True gvar.fov_map = libtcod.map_new(gvar.MAP_WIDTH, gvar.MAP_HEIGHT) gvar.foh_map = libtcod.map_new(gvar.MAP_WIDTH, gvar.MAP_HEIGHT) currentMap = gvar.game.player.currentmap().map for y in range(gvar.MAP_HEIGHT): for x in range(gvar.MAP_WIDTH): libtcod.map_set_properties(gvar.fov_map, x, y, not currentMap[x][y].block_sight, not currentMap[x][y].blocked) libtcod.map_set_properties(gvar.foh_map, x, y, True, True)
def __init__(self, radius=0, intensity=1.0, light_colour=Mappable.LIGHT_H_CLAMP): self._radius = radius == 0 and 100 or radius # TODO: more sensible behaviour for infinite r self.intensity = intensity self.raw_light_colour = light_colour self.light_enabled = True self.__tcod_light_map = libtcod.map_new(radius * 2 + 1, radius * 2 + 1) self.__tcod_light_image = libtcod.image_new(radius * 2 + 1, radius * 2 + 1)
def create_position_map(squad): _coverage_positions = set() _known_targets = set() _known_squads = set() for member_id in squad['members']: _member = entities.get_entity(member_id) _x, _y = movement.get_position(_member) _sight = stats.get_vision(_member) if member_id in squad['member_position_maps']: _old_coverage_positions = squad['member_position_maps'][member_id].copy() else: _old_coverage_positions = set() _map_size = zones.get_active_size() squad['member_position_maps'][member_id] = set() squad['member_los_maps'][member_id] = tcod.map_new(_map_size[0], _map_size[1]) tcod.map_copy(zones.get_active_los_map(), squad['member_los_maps'][member_id]) _t = time.time() tcod.map_compute_fov(squad['member_los_maps'][member_id], _x, _y, radius=_sight, light_walls=False, algo=tcod.FOV_PERMISSIVE_2) for pos in shapes.circle(_x, _y, _sight): if pos[0] < 0 or pos[0] >= _map_size[0] or pos[1] < 0 or pos[1] >= _map_size[1]: continue if not tcod.map_is_in_fov(squad['member_los_maps'][member_id], pos[0], pos[1]): continue _coverage_positions.add(pos) squad['member_position_maps'][member_id].add(pos) #TODO: Do this elsewhere for target_id in _member['ai']['visible_targets']: if not target_id in entities.ENTITIES: continue _target = entities.get_entity(target_id) _known_squads.add((_target['ai']['faction'], _target['ai']['squad'])) #TODO: Is this right? _known_targets.update(_member['ai']['visible_targets']) _positions_to_remove = _old_coverage_positions - _coverage_positions squad['known_targets'].update(_known_targets) squad['known_squads'].update(_known_squads) squad['coverage_positions'].update(_coverage_positions) squad['coverage_positions'] = squad['coverage_positions'] - _positions_to_remove if squad['known_targets']: update_position_maps(squad) logging.debug('Updated local position map - requesting squad update') else: logging.debug('Updated local position map.')
def set_fov_elevation(self, player): elevation = self.elevation(player.pos.x, player.pos.y) self.fov_needs_recompute = True self.fov_map = libtcod.map_new(self.width, self.height) for y in range(self.height): for x in range(self.width): blocks_sight = (terrain_types[self.terrain[x][y]].blocks_sight or (self.region_elevations[self.region[x][y]] > elevation + 1)) libtcod.map_set_properties( self.fov_map, x, y, not blocks_sight, not terrain_types[self.terrain[x][y]].blocks) for obj in self.objects: if obj.blocks_sight or obj.blocks: blocks = obj.blocks or terrain_types[self.terrain[obj.pos.x][ obj.pos.y]].blocks blocks_sight = (obj.blocks_sight or terrain_types[self.terrain[ obj.pos.x][obj.pos.y]].blocks_sight or (self.region_elevations[self.region[x][y]] > elevation + 1)) libtcod.map_set_properties(self.fov_map, obj.pos.x, obj.pos.y, not blocks_sight, not blocks) libtcod.map_compute_fov(player.current_map.fov_map, player.x, player.y, config.TORCH_RADIUS, config.FOV_LIGHT_WALLS, config.FOV_ALGO)
def make_map(): global map, leafs, rooms, doors, fov_map map = [[Tile(True) for y in range(MAP_HEIGHT) ] for x in range(MAP_WIDTH) ] leafs = [] rooms = [] doors = [] fov_map = tcod.map_new(MAP_WIDTH, MAP_HEIGHT) bsp = tcod.bsp_new_with_size(2, 2, MAP_WIDTH-3, MAP_HEIGHT-3) tcod.bsp_split_recursive(bsp, 0, 4 , MIN_LEAF_SIZE, MAX_LEAF_SIZE, 1.5, 1.5) tcod.bsp_traverse_inverted_level_order(bsp, bsp_callback) n=0 #create numerated rooms from leafs for object in leafs: make_room(object, n) n += 1 for object in rooms: #dig rooms & corridors dig(object) make_doors(object, object.number) for object in doors: prev = doors[object.number-1] dig_h_tunnel(prev.center_x, object.center_x, prev.center_y) dig_v_tunnel(prev.center_y, object.center_y, object.center_x) for x in range(0, MAP_WIDTH): set_diggable(x,0,False) set_diggable(x,MAP_HEIGHT-1,False) for y in range(0, MAP_HEIGHT): set_diggable(0,y,False) set_diggable(MAP_WIDTH-1,y,False) populate() fov_init()
def __init__(self, con, width, height, max_room_size, min_room_size, max_rooms, torch_radius, light_walls, algorithm): """Initialize the map to a width and height :width: width of the map :height: height of the map """ self.dark_wall = tcod.Color(0, 0, 100) self.light_wall = tcod.Color(130, 110, 50) self.dark_ground = tcod.Color(50, 50, 150) self.light_ground = tcod.Color(200, 180, 50) self._torch_radius = torch_radius self._light_walls = light_walls self._algorithm = algorithm self._max_room_size = max_room_size self._min_room_size = min_room_size self._max_rooms = max_rooms self._width = width self._height = height self._map = [ [Tile(True) for y in range(self._height) ] for x in range(self._width) ] self._fov_map = tcod.map_new(width, height) self._con = con
def scrolling_view(self): ##============================================================================ pass self.view_map = [] self.width = MAP_WIDTH self.height= MAP_HEIGHT self.fov_map = libtcod.map_new(self.width,self.height) self.view_map = [[" " for x in range(self.width)] for y in range(self.width)] self.item_view = [] self.vx, self.vy = self.width//2, self.height//2 ##Viewport code written by George from the libtcod forums ##==== Drawing the view port ============== for m in range(self.height): if self.player.y >= (self.map_y - self.height//2): y = (self.map_y - self.height) + m self.vy = (self.height//2) + (self.height//2 - (self.map_y - self.player.y)+1) elif self.player.y < self.height//2: y = 0 + m self.vy = self.player.y else: y = self.player.y - (self.height//2) + m for n in range(self.width): if self.player.x >= (self.map_x - self.width//2): x = (self.map_x - self.width) + n self.vx = (self.width//2) + (self.width//2 - (self.map_x - self.player.x) +1) elif self.player.x < self.width//2: x = 0 + n self.vx = self.player.x else: x = self.player.x - (self.width//2) + n
def init_fov_map(tilemap): consts = Constants.consts fov_map = libtcod.map_new(consts['MAP_WIDTH'], consts['MAP_HEIGHT']) for y in range(consts['MAP_HEIGHT']): for x in range(consts['MAP_WIDTH']): libtcod.map_set_properties(fov_map, x, y, not tilemap[x][y].block_sight, not tilemap[x][y].blocked) return fov_map
def __init__(self, width, height): self.x1 = 0 self.y1 = 0 self.x2 = width self.y2 = height self.houses = [None] self.theMap = [[ Tile(False) for y in range(self.y2)] for x in range(self.x2)] #TODO: mark tiles for transporting to a new map instead of blocking for y in range (self.y2): self.theMap[self.x1][y].blocked = True self.theMap[self.x2 - 1][y].blocked = True for x in range (self.x2): self.theMap[x][self.y1].blocked = True self.theMap[x][self.y2 - 1].blocked = True #Set up doodads self.doodads =[] #fill with grass for x in range(self.x2): for y in range(self.y2): grassDoodad = doodad.Grass(x, y) self.doodads.append(grassDoodad) #create other doodads otherDoodadsCount = libtcod.random_get_int(0, 0, 130) for i in range(otherDoodadsCount): doodadType = libtcod.random_get_int(0,0,1) if doodadType == 0: #make a tree theDoodad = doodad.Tree(libtcod.random_get_int(0, self.x1, self.x2), libtcod.random_get_int(0, self.y1, self.y2)) elif doodadType == 1: #make a lake theDoodad = doodad.Lake(libtcod.random_get_int(0, self.x1, self.x2), libtcod.random_get_int(0, self.y1, self.y2)) #check doodad for blocked status blocked = False for x in range(theDoodad.tileSize / 2): for y in range(theDoodad.tileSize / 2): if theDoodad.x + x > self.x1 or theDoodad.y + y > self.y1: continue if self.theMap[theDoodad.x + x][theDoodad.y + y].blocked: blocked = True break if blocked: continue else: # block tiles for x in range(theDoodad.tileSize / 2): for y in range(theDoodad.tileSize / 2): if theDoodad.x + x > self.x2 - 1 or theDoodad.y + y > self.y2 - 1: continue self.theMap[theDoodad.x + x][theDoodad.y + y].blocked = theDoodad.blocks self.theMap[theDoodad.x + x][theDoodad.y + y].block_sight = theDoodad.blockSight self.doodads.append(theDoodad) #set up FOV for player self.fovMap = libtcod.map_new(width, height) for y in range(height): for x in range(width): libtcod.map_set_properties(self.fovMap, x, y, not self.theMap[x][y].block_sight, not self.theMap[x][y].blocked)
def __init__(self, size, intensity=1.0, light_colour=Mappable.LIGHT_H_CLAMP): self._size = size self.intensity = intensity self.raw_light_colour = light_colour self.light_enabled = True self.__tcod_light_map = libtcod.map_new(size.x + 2, size.y + 2) self.__tcod_light_image = libtcod.image_new(size.x + 2, size.y + 2)
def _init_dungeon_map(self): """ Initiates the dungeon map of a dungeon_level. """ self.dungeon_map = libtcod.map_new( self.parent.dungeon_level.value.width, self.parent.dungeon_level.value.height)
def gen_map(): global tile_map global explore_map global path_map global base_path gen_colors() tile_map = [[ wall_tile for y in range(MAP_HEIGHT) ] for x in range(MAP_WIDTH) ] explore_map = [[ False for y in range(MAP_HEIGHT) ] for x in range(MAP_WIDTH) ] rooms = [] num_rooms = 0 for r in range(dungeon_level+1): w = random.randint(ROOM_MIN_SIZE, ROOM_MAX_SIZE) h = random.randint(ROOM_MIN_SIZE, ROOM_MAX_SIZE) x = random.randint(1, MAP_WIDTH - w - 2) y = random.randint(1, MAP_HEIGHT - h - 2) new_room = Rect(x, y, w, h) failed = False for other_room in rooms: if new_room.intersect(other_room): failed = True break if not failed: carve_room(new_room) (new_x, new_y) = new_room.center() if num_rooms == 0: player.x = new_x player.y = new_y else: populate(new_room) (prev_x, prev_y) = rooms[num_rooms-1].center() if random.randint(0,1) == 1: carve_h_tunnel(prev_x, new_x, prev_y) carve_v_tunnel(prev_y, new_y, new_x) else: carve_h_tunnel(prev_x, new_x, new_y) carve_v_tunnel(prev_y, new_y, prev_x) rooms.append(new_room) num_rooms += 1 last_room = rooms[num_rooms-1] (stairs_x, stairs_y) = last_room.center() tile_map[stairs_x][stairs_y] = stair_tile path_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.map_set_properties(path_map, x, y, not tile_map[x][y].blocks, not tile_map[x][y].blocks_sight) base_path = libtcod.path_new_using_map(path_map)
def moveAStar(self, target, entities, gameMap): # Create a new FOV map fov = tcod.map_new(gameMap.mapWidth, gameMap.mapHeight) # Scan current map and set all walls as unwalkable for y1 in range(gameMap.mapHeight): for x1 in range(gameMap.mapWidth): tcod.map_set_properties(fov, x1, y1, not gameMap.tiles[x1][y1].blockSight, not gameMap.tiles[x1][y1].blocked) # Scan for blocking entities for entity in entities: if entity.blocks and entity != self and entity != target: tcod.map_set_properties(fov, entity.x, entity.y, True, False) # Allocate A* Path - No Diagonal Movement path = tcod.path_new_using_map(fov, 0.0) # Compute path tcod.path_compute(path, self.x, self.y, target.x, target.y) # Check if path exists and is shorter than 25 moves if not tcod.path_is_empty(path) and tcod.path_size(path) < 25: x, y = tcod.path_walk(path, recompute = True) # Set X and Y coordinates if x or y: self.x = x self.y = y else: # Backup Move Function self.moveTowards(target.x, target.y, gameMap, entities) tcod.path_delete(path)
def move_astar(self, target): fov = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y1 in range(MAP_HEIGHT): for x1 in range(MAP_WIDTH): libtcod.map_set_properties(fov, x1, y1, not map[x1][y1].block_sight, not map[x1][y1].blocked) for obj in objects: if obj.blocks and obj != self and obj != target: libtcod.map_set_properties(fov, obj.x, obj.y, True, False) my_path = libtcod.path_new_using_map(fov, 1.41) libtcod.path_compute(my_path, self.x, self.y, target.x, target.y) if not libtcod.path_is_empty( my_path) and libtcod.path_size(my_path) < 25: x, y = libtcod.path_walk(my_path, True) if x or y: self.x = x self.y = y else: self.move_towards(target.x, target.y) libtcod.path_delete(my_path)
def __init__(self): #create new fov_map for area around planted node #add to array of nodes, have render_all cycle through all nodes self.fov_map = libtcod.map_new(config.MAP_WIDTH, config.MAP_HEIGHT) for y in range(config.MAP_HEIGHT): for x in range(config.MAP_WIDTH): libtcod.map_set_properties(self.fov_map, x, y, not config.map[x][y].block_sight, not config.map[x][y].blocked)
def __init__(self, ID, monst, items): self.ID = ID self.num_monster = monst self.num_items = items self.w = 30 self.h = 20 self.map = [[1 for y in range(self.h)] for x in range(self.w)] self.tiles = [[None for y in range(self.h)] for x in range(self.w)] self.up = (self.w / 2, self.h / 2) self.down = (self.w / 2 + 4, self.h / 2 + 4) self.rects = [] self.construct_floor() self.objects = [] self.entities = [] self.construct_objects() self.fov_map = libtcod.map_new(self.w, self.h) self.make_fov_map() self.assign_tiles()
def move_astar(self, target): fov = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) #set move, sight blockers for y1 in range(MAP_HEIGHT): for x1 in range(MAP_WIDTH): libtcod.map_set_properties(fov, x1, y1, not map[x1][y1].sight_blocker, not map[x1][y1].move_blocker) #Treat tiles occupied by monsters as move blocked for obj in objects: if obj.move_blocker and obj != self and obj != target: libtcod.map_set_properties(fov, obj.x, obj.y, True, False) #Allocate path. Use roguelike geometry (diagonals = cardinals). my_path = libtcod.path_new_using_map(fov, 1.0) #Compute path libtcod.path_compute(my_path, self.x, self.y, target.x, target.y) #Confirm path was found, and is short, then take step. if not libtcod.path_is_empty(my_path) and libtcod.path_size(my_path) < MAX_ASTAR_PATH_LENGTH: x, y = libtcod.path_walk(my_path, True) if x or y: #self.move takes dx, dy so don't use that self.x = x self.y = y #If the path is bad, take direct path to player. #This happens if, say, player is behind a monster in a corridor. else: self.move_towards(target.x, target.y) #Deallocate path memory libtcod.path_delete(my_path)
def init_fov_and_pathfinding(self): print("initting fov and pathfinding") # init fov self.fov_map = tcod.map_new(self.width, self.height) self.update_fov_map() # init pathfinding self.path = tcod.path_new_using_map(self.fov_map, self.diagonal_cost)
def move_astar(self, target, entities, game_map): fov = libtcod.map_new(game_map.width, game_map.height) for y1 in range(game_map.height): for x1 in range(game_map.width): libtcod.map_set_properties( fov, x1, y1, not game_map.tiles[x1][y1].block_sight, not game_map.tiles[x1][y1].blocked) for entity in entities: if entity.blocks and entity != self and entity != target: libtcod.map_set_properties(fov, entity.x, entity.y, True, False) my_path = libtcod.path_new_using_map(fov, 1.41) libtcod.path_compute(my_path, self.x, self.y, target.x, target.y) max_path_length = 25 if not libtcod.path_is_empty( my_path) and libtcod.path_size(my_path) < max_path_length: x, y = libtcod.path_walk(my_path, True) if x or y: self.x = x self.y = y else: self.move_towards(target.x, target.y, game_map, entities) libtcod.path_delete(my_path)
def initialize_fov(self, map): fov = tcod.map_new(map.width, map.height) for y in range(map.height): for x in range(map.width): tcod.map_set_properties(fov, x, y, not map.tiles[x][y].opaque, not map.tiles[x][y].solid) return fov
def path_towards_astar(self, game, origin, target): # getting the fov vamp from currentDrawMap doesn't work in debug mode since it isn't initialized # so for the moment I'm recomputing it every time, it's super wasteful but the game chugs along nicely fov = libtcod.map_new(self.width, self.height) list( map( lambda tile: libtcod.map_set_properties( fov, tile.x, tile.y, tile.trasparent, not tile.block), self.get_map_list())) for entity in self.entity_list: if entity != origin and entity != target: libtcod.map_set_properties(fov, entity.x, entity.y, True, False) my_path = libtcod.path_new_using_map(fov, 0.0) libtcod.path_compute(my_path, origin.x, origin.y, target.x, target.y) return_direction = (0, 0) if not libtcod.path_is_empty( my_path) and libtcod.path_size(my_path) < 30: x, y = libtcod.path_walk(my_path, True) if x or y: x1 = 1 if origin.x < x else -1 if origin.x > x else 0 y1 = 1 if origin.y < y else -1 if origin.y > y else 0 return_direction = (x1, y1) else: return_direction = self.get_step_towards(origin.x, origin.y, target.x, target.y) libtcod.path_delete(my_path) return return_direction
def read_zone(self, zone): """Read the zone and adjust map values accordingly""" self.map = libtcod.map_new(zone.width, zone.height) for y in range(zone.height): for x in range(zone.width): #libtcode requires the opposite values, so invert them! libtcod.map_set_properties(self.map, x, y, not zone[x][y].block_sight, not zone[x][y].blocked)
def initialize_field_of_view(): global fovMap fovMap = tcod.map_new(data.map_width, data.map_height) for y in range(data.map_height): for x in range(data.map_width): tcod.map_set_properties(fovMap, x, y, not maps.field[x][ y].block_sight, not maps.field[x][y].blocked)
def astar(source, target): # create a FOV map that has the dimensions of the map fov = lib.map_new(var.MAP_WIDTH, var.MAP_HEIGHT) # scan the current map each turn and set all walls as unwalkable for y1 in range(var.MAP_HEIGHT): for x1 in range(var.MAP_WIDTH): lib.map_set_properties(fov, x1, y1, not var.map[x1][y1].block_sight, not var.map[x1][y1].blocked) # scan all objects to see if there are objects that must be navigated around # check also that the object isn't self or the target (start and end points are free) # the ai class handles the situation if self is next to the target, so it will not use this A* function anyway for ent in var.entities: if ent.blocks and ent != var.player and ent != target: # set the tile as a wall so it must be navigated around lib.map_set_properties(fov, ent.x, ent.y, True, False) # allocate the A* path # The 1.41 is the normal diagonal cost of moving, set to 0 if diagonals are prohibited my_path = lib.path_new_using_map(fov, 1.41) # compute the path between self's coordinates and the targets lib.path_compute(my_path, source.x, source.y, target.x, target.y) # check if the path exists, and in this case, also the path is shorter than 25 tiles if not lib.path_is_empty(my_path) and lib.path_size(my_path) < 25: # find the next coordinates in the computed full path (x, y) = lib.path_walk(my_path, True) else: (x, y) = (None, None) # delete the path lib.path_delete(my_path) return x, y
def create_path(self, gamemap_instance): mymap = gamemap_instance.level #Create the path map self.path_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for x in range(1, MAP_WIDTH): for y in range(1, MAP_HEIGHT): libtcod.map_set_properties(self.path_map, x, y, not mymap[x][y].block_sight, not mymap[x][y].blocked) print 'Builder created self.path_map' self.is_pathmap_created = True # now use the path map to create the path from the explorer's current position to another spot: self.path = libtcod.path_new_using_map(self.path_map) destinationx, destinationy = self.pick_spot_to_work(gamemap_instance) if destinationx is not None: self.work_target = (destinationx, destinationy) print 'Builder chose a work target at ' + str(self.work_target[0]) +', ' + str(self.work_target[1]) + '.' libtcod.path_compute(self.path, self.owner.x, self.owner.y, destinationx, destinationy) #originx, originy = libtcod.path_get_origin(self.path) #destx, desty = libtcod.path_get_destination(self.path) elif destinationx is None: print 'destinationx is None.'
def make_fov_map(self): self.fov_recompute = True fov_map = libtcod.map_new(self.width, self.height) for y in range(self.height): for x in range(self.width): libtcod.map_set_properties(fov_map, x, y, not self.map[x][y].block_sight, not self.map[x][y].blocked) return fov_map
def __init__(self,owner,flags=[]): self.owner = owner self.flags = flags self.navmap = libtcod.map_new(MAP_WIDTH,MAP_HEIGHT) self.currentpath = None self.currenttarget = None self.currentlyonpath = False
def map_(): map_ = libtcodpy.map_new(MAP_WIDTH, MAP_HEIGHT) for y, line in enumerate(MAP): for x, ch in enumerate(line): libtcodpy.map_set_properties(map_, x, y, ch == ' ', ch == ' ') yield map_ libtcodpy.map_delete(map_)
def find_astar(origin, dest, game_map): # Create a FOV map that has the dimensions of the map fov = tcod.map_new(game_map.width, game_map.height) # Scan the current map each turn and set all the walls as unwalkable for y1 in range(game_map.height): for x1 in range(game_map.width): tcod.map_set_properties(fov, x1, y1, not game_map.is_opaque( (x1, y1)), game_map.is_passable((x1, y1))) # Scan all the objects to see if there are objects that must be navigated around # Check also that the object isn't self or the target (so that the start and the end points are free) # The AI class handles the situation if self is next to the target so it will not use this A* function anyway for pos in [actor.pos for actor in game_map.actors]: if pos != origin and pos != dest: # Set the tile as a wall so it must be navigated around tcod.map_set_properties(fov, pos[0], pos[1], True, False) # Allocate a A* path my_path = tcod.path_new_using_map(fov, 1) # Compute the path between self's coordinates and the target's coordinates tcod.path_compute(my_path, origin[0], origin[1], dest[0], dest[1]) # Check if the path exists if not tcod.path_is_empty(my_path): # Find the next coordinates in the computed full path x, y = tcod.path_walk(my_path, True) # Delete the path to free memory tcod.path_delete(my_path) if x or y: delta = (x - origin[0], y - origin[1]) for act, move in MOVES.items(): if move == delta: return act
def move_astar(self, target, entities, game_map, check_explored=False, max_path=25): # Create a FOV map that has the dimensions of the map fov = libtcod.map_new(game_map.width, game_map.height) # Scan the current map each turn and set all the walls as unwalkable for y1 in range(game_map.height): for x1 in range(game_map.width): if check_explored: libtcod.map_set_properties( fov, x1, y1, not game_map.tiles[x1][y1].block_sight, not game_map.tiles[x1][y1].blocked and game_map.tiles[x1][y1].explored) else: libtcod.map_set_properties( fov, x1, y1, not game_map.tiles[x1][y1].block_sight, not game_map.tiles[x1][y1].blocked) # Scan all the objects to see if there are objects that must be navigated around # Check also that the object isn't self or the target (so that the start and the end points are free) # The AI class handles the situation if self is next to the target so it will not use this A* function anyway for entity in entities: if entity.blocks and entity != self and entity != target: # Set the tile as a wall so it must be navigated around libtcod.map_set_properties(fov, entity.x, entity.y, True, False) # Allocate a A* path # The 1.41 is the normal diagonal cost of moving, it can be set as 0.0 if diagonal moves are prohibited my_path = libtcod.path_new_using_map(fov, 1.41) # Compute the path between self's coordinates and the target's coordinates libtcod.path_compute(my_path, self.x, self.y, target.x, target.y) # Check if the path exists, and in this case, also the path is shorter than 25 tiles # The path size matters if you want the monster to use alternative longer paths (for example through other rooms) if for example the player is in a corridor # It makes sense to keep path size relatively low to keep the monsters from running around the map if there's an alternative path really far away if not libtcod.path_is_empty( my_path) and libtcod.path_size(my_path) < max_path: # Find the next coordinates in the computed full path x, y = libtcod.path_walk(my_path, True) if x or y: # Set self's coordinates to the next path tile self.x = x self.y = y return True else: return False else: # Keep the old move function as a backup so that if there are no paths (for example another monster blocks a corridor) # it will still try to move towards the player (closer to the corridor opening) return self.move_towards(target.x, target.y, game_map, entities) # Delete the path to free memory libtcod.path_delete(my_path)
def new_fov_pathing_map(map): width = MAP_WIDTH height = MAP_HEIGHT fov_pathing_map = libtcod.map_new(width, height) for y in range(height): for x in range(width): libtcod.map_set_properties(fov_pathing_map, x, y, not map[x][y].block_sight, (not map[x][y].blocked and map[x][y].explored)) return fov_pathing_map
def init_los(game_map): los_map = tcod.map_new(game_map.width, game_map.height) for x in range(game_map.width): for y in range(game_map.height): tcod.map_set_properties(los_map, x, y, not game_map.is_opaque((x, y)), game_map.is_passable((x, y))) return los_map
def new_fov_map(game): width = game.map_width height = game.map_height fov_map = libtcod.map_new(width, height) for y in range(height): for x in range(width): libtcod.map_set_properties(fov_map, x, y, not game.map[x][y].block_sight, not game.map[x][y].blocked) return fov_map
def make_fov_map(): global fov_map fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.map_set_properties(fov_map, x, y, not map[x][y].block_sight, not map[x][y].blocked)
def make_fov_map(tiles): """Take the list of tiles and feed it to libtcod to generate the fov_map, taking into account tiles that block sight""" global fov_map fov_map = libtcod.map_new(init.map_width, init.map_height) for tile in tiles: libtcod.map_set_properties(fov_map, tile['Position']['x'], tile['Position']['y'], can_see_through(tile), can_pass_through(tile)) return fov_map
def __init__(self): self.lifespan = 50 self.radius = config.FLARE_RADIUS self.fov_map = libtcod.map_new(config.MAP_WIDTH, config.MAP_HEIGHT) for y in range(config.MAP_HEIGHT): for x in range(config.MAP_WIDTH): libtcod.map_set_properties(self.fov_map, x, y, not config.map[x][y].block_sight, not config.map[x][y].blocked)
def create_fov(self): self.fov_map = tcod.map_new(engine.dun_level.MAP_W, engine.dun_level.MAP_H) for y in xrange(engine.dun_level.MAP_H): for x in xrange(engine.dun_level.MAP_W): tcod.map_set_properties(self.fov_map, x, y, engine.dun_level.map[x][y].transparent, engine.dun_level.map[x][y].walkable)
def create_fov_map(self): self.fov_map = libtcod.map_new(self.map.width, self.map.height) for x in xrange(self.map.width): for y in xrange(self.map.height): libtcod.map_set_properties( self.fov_map, x, y, not self.map.tiles[x][y].block_sight, not self.map.tiles[x][y].blocked)
def initialize_fov(self): self.recompute_fov = True self.fov_map = libtcodpy.map_new(self.map_width, self.map_height) for y in range(self.map_height): for x in range(self.map_width): libtcodpy.map_set_properties(self.fov_map, x, y, self.is_transparent[x][y], self.is_walkable[x][y])
def generate_fov_map(width, height): fov_map = libtcod.map_new(width, height) for y in range(height): for x in range(width): libtcod.map_set_properties(fov_map, x, y, not Map_Tiles[x][y].block_sight, not Map_Tiles[x][y].blocked) return fov_map
def set_dijkstra_map(self): fov_map = libtcod.map_new(game.WORLDMAP_WIDTH, game.WORLDMAP_HEIGHT) for y in range(game.WORLDMAP_HEIGHT): for x in range(game.WORLDMAP_WIDTH): libtcod.map_set_properties(fov_map, x, y, True, True) path = libtcod.dijkstra_new(fov_map) libtcod.dijkstra_compute(path, self.originx, self.originy) return path
def initialize_fov(game_map): fov_map = libtcod.map_new(game_map.width, game_map.height) for y in range(game_map.height): for x in range(game_map.width): libtcod.map_set_properties(fov_map, x, y, not game_map.tiles[x][y].block_sight, not game_map.tiles[x][y].blocked) return fov_map
def init_fov(self): self.fov_map = libtcod.map_new(self.map_width, self.map_height) for y in range(self.map_height): for x in range(self.map_width): libtcod.map_set_properties(self.fov_map, x, y, not self.level_map[x][y].tile_property["blocks_walking"], not self.level_map[x][y].tile_property["blocks_visibility"])
def initialize_fov(): global fov_recompute, fov_map fov_recompute = True #create the DOV map, according to generated map fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.map_set_properties(fov_map, x, y, not map[x][y].block_sight, not map[x][y].blocked)
def map_make_fov(incoming_map): global FOV_MAP FOV_MAP = libtcod.map_new(constants.MAP_HEIGHT, constants.MAP_HEIGHT) for y in range(constants.MAP_HEIGHT): for x in range(constants.MAP_WIDTH): libtcod.map_set_properties(FOV_MAP, x, y, not incoming_map[x][y].block_path, not incoming_map[x][y].block_path)
def initialize_fov(): global fov_recompute, fov_map libtcod.console_clear(con) fov_recompute = True fov_map = libtcod.map_new(opt.MAP_WIDTH, opt.MAP_HEIGHT) for y in range(opt.MAP_HEIGHT): for x in range(opt.MAP_WIDTH): libtcod.map_set_properties(fov_map, x, y, not map[x][y].block_sight, not map[x][y].blocked)
def load_map(self, map_data): self.map_data = map_data self.map = libtcod.map_new(len(map_data[0]), len(map_data)) self.map_size = (len(map_data[0]), len(map_data)) for y in range(len(map_data)): for x in range(len(map_data[y])): libtcod.map_set_properties(self.map, x, y, map_data[y][x].isVisible, map_data[y][x].isWalkable)
def initialize_fov(self): """This is needed to allow field of view stuff. It requires the GameMap instance to already have a level (a Tile array).""" #create the FOV map according to the generated map self.fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.map_set_properties(self.fov_map, x, y, not self.level[x][y].block_sight, not self.level[x][y].blocked)
def gen_map():#generate map (at this point it's not drawn to the screen) global fov_map, map make_map() #create the FOV map, according to the generated map fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.map_set_properties(fov_map, x, y, not map[x][y].blocked, not map[x][y].block_sight)
def initialize_fov(): global fov_recompute, fov_map fov_recompute = True #fov libtcod.console_clear(con) #unexplored areas start black fov_map = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.map_set_properties(fov_map, x, y, not map[x][y].block_sight, not map[x][y].blocked)
def add_map(self, fov): new_map = libtcod.map_new(self.width, self.height) if self.libtcod_map is None: self.init_map() self.libtcod_map_owners.append(fov.owner) libtcod.map_copy(self.libtcod_map, new_map) return new_map
def create_path(self, coords, map): map_path = libtcod.map_new(MAP_WIDTH, MAP_HEIGHT) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): libtcod.map_set_properties(map_path, x, y, False, not map.cells[y][x].block_path) path = libtcod.path_new_using_map(map_path, 1.41) libtcod.path_compute(path, self.x, self.y, coords[0], coords[1]) return path
def create_fov_map(self): self.fov_map = libtcod.map_new(self.map.width, self.map.height) for x in xrange(self.map.width): for y in xrange(self.map.height): libtcod.map_set_properties(self.fov_map, x, y, not self.map.tiles[x][y].block_sight, not self.map.tiles[x][y].blocked)
def generate_fov(self): fov_map = libtcod.map_new(self.width, self.height) for y in range(self.height): for x in range(self.width): passable = self.is_passable(x, y) libtcod.map_set_properties(fov_map, x, y, passable, passable) self.fov_map = fov_map
def initialize_fov(): #initialize the FOV global fov_recompute, fov_map fov_recompute = True ######## FOV fov_map = libtcod.map_new(CONFIG.MAP_WIDTH, CONFIG.MAP_HEIGHT) for y in range(CONFIG.MAP_HEIGHT): for x in range(CONFIG.MAP_WIDTH): libtcod.map_set_properties(fov_map, x, y, not CurrentMap[x][y].block_sight, not CurrentMap[x][y].blocked)
def translate_level(level): new_level = libtcod.map_new(const.MAP_WIDTH, const.MAP_HEIGHT) for y in range(const.MAP_HEIGHT): for x in range(const.MAP_WIDTH): libtcod.map_set_properties(new_level, x, y, True, level[x][y].blocked) return new_level