• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ Map::getAllTiles(floorMin, floorMax)

Itutorial

Legendary OT User
Joined
Dec 23, 2014
Messages
2,331
Solutions
68
Reaction score
1,008
This probably cant happen like this but im just trying to get something figured out. If I can get an answer for this I would be able to start the trial and error. I know why this isnt a good idea.

Pretty much I dont know how to add the tiles to a vector. There is Map::getTile(x, y) which works the same but returns one tile. Help please

C++:
Tile* Map::getAllTiles(uint8_t floorMin, uint8_t floorMax) const
{
    if (floorMax >= MAP_MAX_LAYERS) {
        floorMax = MAP_MAX_LAYERS;
    }

    if (floorMin < 0) {
        floorMin = 0;
    }

    uint16_t maxX = 5000;
    uint16_t maxY = 5000;
    uint8_t currentZ = 0;
    uint8_t cFloorMax = 0;

    if (floorMin) {
        currentZ = floorMin;
    }

    if (floorMax) {
        cFloorMax = floorMax;
    }

    std::vector<Floor> floorArray;

    for (currentZ; currentZ <= cFloorMax; currentZ++) {
        for (uint16_t currentY = 0; currentY < maxY; currentY++) {
            for (uint16_t currentX = 0; currentX < maxX; currentX++) {
                if (currentX == maxX && currentY == maxY && currentZ == cFloorMax) {
                    break;
                }

                if (currentX > maxX) {
                    currentX = maxX;
                }

                if (currentY > maxY) {
                    currentY = maxY;
                }

                const QTreeLeafNode* leaf = QTreeNode::getLeafStatic<const QTreeLeafNode*, const QTreeNode*>(&root, currentX, currentY);
                if (!leaf) {
                    return nullptr;
                }

                const Floor* floor = leaf->getFloor(currentZ);
                if (!floor) {
                    return nullptr;
                }

                floorArray.push_back(floor->tiles[currentX & FLOOR_MASK][currentY & FLOOR_MASK]);
            }
        }
    }
}
Post automatically merged:

I figured this problem out. I needed the vector to be a Tile* vector (could be a new problem though)


New problem

C++:
std::vector<Tile*> tileVector = map->getAllTiles(0, 15);

show.png

Figured this out too. This can be closed.
 
Last edited:
you trying to return a vector of tiles but your function is not a vector
Tile* Map::getAllTiles -> std::vector<Tile*> Map::getAllTiles
 
Solution
you trying to return a vector of tiles but your function is not a vector
Tile* Map::getAllTiles -> std::vector<Tile*> Map::getAllTiles
Yeah, I don't mess with c++ much as you can tell plus it was 6am (and I didn't just wake up). I did figure it out before I went to bed. Thanks for the reply.

To be more clear for anyone that doesn't understand.

The Map::getAllTiles() was declared as

C++:
Tile* Map::getAllTiles()

when it should of been

C++:
std::vector<Tile*> Map::getAllTiles()

I never even returned the data on line 51 which because the Map::getAllTiles() returned as a Tile* it would only be able to return a single Tile* object which I don't think a vector of tiles can even be used to create a Tile* object.

After changing Map::getAllTiles() to a vector it obviously returned as one and I could use:

C++:
std::vector<Tile*> tileVector = Map::getAllTiles();

to call the vector of tiles.
 
Last edited:
Back
Top