def new_game():
    """
    Starts a new game, with a default player on level 1 of the dungeon.
    Returns the player object.
    """
    # Must initialize the log before we do anything that might emit a message.
    log.init()

    fighter_component = Fighter(hp=100, defense=1, power=2, xp=0, death_function=player_death)
    player = Object(algebra.Location(0, 0), '@', 'player', libtcod.white, blocks=True, fighter=fighter_component)
    player.inventory = []
    player.level = 1
    player.game_state = 'playing'
    # True if there's a (hostile) fighter in FOV
    player.endangered = False

    obj = miscellany.dagger()
    player.inventory.append(obj)
    actions.equip(player, obj.equipment, False)
    obj.always_visible = True

    cartographer.make_map(player, 1)
    renderer.clear_console()
    renderer.update_camera(player)

    log.message('Welcome stranger! Prepare to perish in the Tombs of the Ancient Kings.', libtcod.red)
    log.message('Press ? or F1 for help.')

    return player
def next_level(player, portal):
    """
    Advance to the next level (changing player.current_map).
    Heals the player 50%.
    Returns the Map of the new level.
    """
    log.message('You take a moment to rest, and recover your strength.', libtcod.light_violet)
    actions.heal(player.fighter, player.fighter.max_hp / 2)

    log.message('After a rare moment of peace, you descend deeper into the heart of the dungeon...', libtcod.red)
    old_map = player.current_map
    cartographer.make_map(player, player.current_map.dungeon_level + 1)
    renderer.clear_console()
    renderer.update_camera(player)

    # Create the up stairs at the current position.
    stairs = Object(player.pos, '>', 'stairs up', libtcod.white, always_visible=True)
    stairs.destination = old_map
    stairs.dest_position = portal.pos
    player.current_map.objects.insert(0, stairs)
    player.current_map.portals.insert(0, stairs)

    return player.current_map