Beispiel #1
0
void _take_stairs(stairs_t* stairs)
{
    dungeon_t* prev_dungeon = current_dungeon;

    TRACE("take_stairs: stairs->to_branch=%s", stairs->to_branch.c_str());

    // Arrive from town to infinite dungeon: clear infinite dungeon.
    if (stairs->to && stairs->to_branch == BRANCH_INFINITE_DUNGEON && current_branch->name != BRANCH_INFINITE_DUNGEON)
    {
        stairs->to = nullptr;
        branch_t* inf_branch = find_branch(stairs->to_branch);

        for (dungeon_t* dungeon : inf_branch->dungeons)
        {
            destroy_dungeon(dungeon);
        }
        inf_branch->dungeons.clear();
    }

    // Generate the next dungeon if needed.
    if (stairs->to == nullptr && stairs->to_branch == current_branch->name)
    {
        dungeon_t* next_level = generate_next_level(current_branch);
        create_up_stairs(next_level, current_branch, prev_dungeon, stairs);
    }
    else if (stairs->to == nullptr)
    {
        // Stairs to a new branch.
        branch_t* prev_branch = current_branch;
        current_branch = create_branch(stairs->to_branch);

        dungeon_t* next_level = current_branch->dungeons.front();

        // Check if the level has stairs that lead back to the branch already.
        bool has_stairs = false;
        for (int i = 0; i < next_level->num_stairs; i++)
        {
            if (next_level->stairs[i]->to_branch == prev_branch->name)
                has_stairs = true;
        }

        if (!has_stairs)
            create_up_stairs(next_level, prev_branch, prev_dungeon, stairs);
        else
            stairs->to = next_level;
    }

    dungeon_t* dst = stairs->to;
    current_dungeon = dst;
    current_branch = find_branch(stairs->to_branch);

    player.pos.x = stairs->warp_x;
    player.pos.y = stairs->warp_y;

    // Do not follow player to the world map.
    if (current_branch->name != "World")
    {
        std::vector<coord_t> free_coords;
        for (int y = player.pos.y - 1; y <= player.pos.y + 1; y++)
            for (int x = player.pos.x - 1; x <= player.pos.x + 1; x++)
                if (place_free(current_dungeon, x, y))
                    free_coords.push_back( coord_t { x, y} );

        std::vector<creature_t*> following_creatures;
        for (int y = stairs->y - 1; y <= stairs->y + 1; y++)
        {
            for (int x = stairs->x - 1; x <= stairs->x + 1; x++)
            {
                creature_t* creature = get_creature_at(prev_dungeon, x, y);

                if (creature && following_creatures.size() < free_coords.size())
                {
                    following_creatures.push_back(creature);
                    remove_creature_no_destroy(prev_dungeon, creature);
                }
            }
        }

        for (size_t i = 0; i < following_creatures.size(); i++)
        {
            add_creature_to_dungeon(current_dungeon, following_creatures[i], free_coords[i].x, free_coords[i].y);
        }

        if (following_creatures.size() == 1)
            append_msg_log("%s follows you.", capitalize(following_creatures.front()->get_full_name()).c_str());
        else if (following_creatures.size() > 1)
            append_msg_log("Some creatures follow you.");
    }

    clear_action_list();
    append_action_list(&player);
}
Beispiel #2
0
void test_load() {
	player_descr* pc = malloc(sizeof(player_descr));
	FILE* example = fopen("example.txt", "r");
	dungeon* d = load_dungeon(example, pc);
	destroy_dungeon(d);		
}