diff --git a/Source/levels/gendung.cpp b/Source/levels/gendung.cpp index 341de6ff5..0c9b27d49 100644 --- a/Source/levels/gendung.cpp +++ b/Source/levels/gendung.cpp @@ -537,19 +537,17 @@ void DRLG_CopyTrans(int sx, int sy, int dx, int dy) void LoadTransparency(const uint16_t *dunData) { - int width = SDL_SwapLE16(dunData[0]); - int height = SDL_SwapLE16(dunData[1]); + WorldTileSize size = GetDunSize(dunData); - int layer2Offset = 2 + width * height; + int layer2Offset = 2 + size.width * size.height; // The rest of the layers are at dPiece scale - width *= 2; - height *= 2; + size *= static_cast(2); - const uint16_t *transparentLayer = &dunData[layer2Offset + width * height * 3]; + const uint16_t *transparentLayer = &dunData[layer2Offset + size.width * size.height * 3]; - for (int j = 0; j < height; j++) { - for (int i = 0; i < width; i++) { + for (WorldTileCoord j = 0; j < size.height; j++) { + for (WorldTileCoord i = 0; i < size.width; i++) { dTransVal[16 + i][16 + j] = SDL_SwapLE16(*transparentLayer); transparentLayer++; } @@ -631,14 +629,13 @@ std::optional PlaceMiniSet(const Miniset &miniset, int tries, bool drlg1Q void PlaceDunTiles(const uint16_t *dunData, Point position, int floorId) { - int width = SDL_SwapLE16(dunData[0]); - int height = SDL_SwapLE16(dunData[1]); + WorldTileSize size = GetDunSize(dunData); const uint16_t *tileLayer = &dunData[2]; - for (int j = 0; j < height; j++) { - for (int i = 0; i < width; i++) { - auto tileId = static_cast(SDL_SwapLE16(tileLayer[j * width + i])); + for (WorldTileCoord j = 0; j < size.height; j++) { + for (WorldTileCoord i = 0; i < size.width; i++) { + auto tileId = static_cast(SDL_SwapLE16(tileLayer[j * size.width + i])); if (tileId != 0) { dungeon[position.x + i][position.y + j] = tileId; Protected.set(position.x + i, position.y + j); diff --git a/Source/levels/town.cpp b/Source/levels/town.cpp index 5799f2994..786d80601 100644 --- a/Source/levels/town.cpp +++ b/Source/levels/town.cpp @@ -24,20 +24,18 @@ void FillSector(const char *path, int xi, int yy) { auto dunData = LoadFileInMem(path); - int width = SDL_SwapLE16(dunData[0]); - int height = SDL_SwapLE16(dunData[1]); - + WorldTileSize size = GetDunSize(dunData.get()); const uint16_t *tileLayer = &dunData[2]; - for (int j = 0; j < height; j++) { + for (WorldTileCoord j = 0; j < size.height; j++) { int xx = xi; - for (int i = 0; i < width; i++) { + for (WorldTileCoord i = 0; i < size.width; i++) { int v1 = 218; int v2 = 218; int v3 = 218; int v4 = 218; - int tileId = SDL_SwapLE16(tileLayer[j * width + i]) - 1; + int tileId = SDL_SwapLE16(tileLayer[j * size.width + i]) - 1; if (tileId >= 0) { MegaTile mega = pMegaTiles[tileId]; v1 = SDL_SwapLE16(mega.micro1); diff --git a/Source/monster.cpp b/Source/monster.cpp index 46a01cd4f..303b2b70a 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -3601,20 +3601,18 @@ void SetMapMonsters(const uint16_t *dunData, Point startPosition) PlaceUniqueMonst(UniqueMonsterType::BlackJade, 0, 0); } - int width = SDL_SwapLE16(dunData[0]); - int height = SDL_SwapLE16(dunData[1]); + WorldTileSize size = GetDunSize(dunData); - int layer2Offset = 2 + width * height; + int layer2Offset = 2 + size.width * size.height; // The rest of the layers are at dPiece scale - width *= 2; - height *= 2; + size *= static_cast(2); - const uint16_t *monsterLayer = &dunData[layer2Offset + width * height]; + const uint16_t *monsterLayer = &dunData[layer2Offset + size.width * size.height]; - for (int j = 0; j < height; j++) { - for (int i = 0; i < width; i++) { - auto monsterId = static_cast(SDL_SwapLE16(monsterLayer[j * width + i])); + for (WorldTileCoord j = 0; j < size.height; j++) { + for (WorldTileCoord i = 0; i < size.width; i++) { + auto monsterId = static_cast(SDL_SwapLE16(monsterLayer[j * size.width + i])); if (monsterId != 0) { const size_t typeIndex = AddMonsterType(MonstConvTbl[monsterId - 1], PLACE_SPECIAL); PlaceMonster(ActiveMonsterCount++, typeIndex, startPosition + Displacement { i, j }); diff --git a/Source/objects.cpp b/Source/objects.cpp index d4dce3d79..e39cf5f29 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -559,20 +559,18 @@ void LoadMapObjects(const char *path, Point start, WorldTileRectangle mapRange = auto dunData = LoadFileInMem(path); - int width = SDL_SwapLE16(dunData[0]); - int height = SDL_SwapLE16(dunData[1]); + WorldTileSize size = GetDunSize(dunData.get()); - int layer2Offset = 2 + width * height; + int layer2Offset = 2 + size.width * size.height; // The rest of the layers are at dPiece scale - width *= 2; - height *= 2; + size.width *= static_cast(2); - const uint16_t *objectLayer = &dunData[layer2Offset + width * height * 2]; + const uint16_t *objectLayer = &dunData[layer2Offset + size.width * size.height * 2]; - for (int j = 0; j < height; j++) { - for (int i = 0; i < width; i++) { - auto objectId = static_cast(SDL_SwapLE16(objectLayer[j * width + i])); + for (WorldTileCoord j = 0; j < size.height; j++) { + for (WorldTileCoord i = 0; i < size.width; i++) { + auto objectId = static_cast(SDL_SwapLE16(objectLayer[j * size.width + i])); if (objectId != 0) { Point mapPos = start + Displacement { i, j }; Object *mapObject = AddObject(ObjTypeConv[objectId], mapPos); @@ -3949,20 +3947,18 @@ void SetMapObjects(const uint16_t *dunData, int startx, int starty) ClrAllObjects(); - int width = SDL_SwapLE16(dunData[0]); - int height = SDL_SwapLE16(dunData[1]); + WorldTileSize size = GetDunSize(dunData); - int layer2Offset = 2 + width * height; + int layer2Offset = 2 + size.width * size.height; // The rest of the layers are at dPiece scale - width *= 2; - height *= 2; + size.width *= static_cast(2); - const uint16_t *objectLayer = &dunData[layer2Offset + width * height * 2]; + const uint16_t *objectLayer = &dunData[layer2Offset + size.width * size.height * 2]; - for (int j = 0; j < height; j++) { - for (int i = 0; i < width; i++) { - auto objectId = static_cast(SDL_SwapLE16(objectLayer[j * width + i])); + for (WorldTileCoord j = 0; j < size.height; j++) { + for (WorldTileCoord i = 0; i < size.width; i++) { + auto objectId = static_cast(SDL_SwapLE16(objectLayer[j * size.width + i])); if (objectId != 0) { const ObjectData &objectData = AllObjects[ObjTypeConv[objectId]]; filesWidths[objectData.ofindex] = objectData.animWidth; @@ -3972,9 +3968,9 @@ void SetMapObjects(const uint16_t *dunData, int startx, int starty) LoadLevelObjects(filesWidths); - for (int j = 0; j < height; j++) { - for (int i = 0; i < width; i++) { - auto objectId = static_cast(SDL_SwapLE16(objectLayer[j * width + i])); + for (WorldTileCoord j = 0; j < size.height; j++) { + for (WorldTileCoord i = 0; i < size.width; i++) { + auto objectId = static_cast(SDL_SwapLE16(objectLayer[j * size.width + i])); if (objectId != 0) { AddObject(ObjTypeConv[objectId], { startx + 16 + i, starty + 16 + j }); } diff --git a/Source/quests.cpp b/Source/quests.cpp index 063ceb2e0..53fbf6d84 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -167,16 +167,15 @@ void DrawLTBanner(Point position) { auto dunData = LoadFileInMem("levels\\l1data\\banner1.dun"); - int width = SDL_SwapLE16(dunData[0]); - int height = SDL_SwapLE16(dunData[1]); + WorldTileSize size = GetDunSize(dunData.get()); - SetPiece = { position, GetDunSize(dunData.get()) }; + SetPiece = { position, size }; const uint16_t *tileLayer = &dunData[2]; - for (int j = 0; j < height; j++) { - for (int i = 0; i < width; i++) { - auto tileId = static_cast(SDL_SwapLE16(tileLayer[j * width + i])); + for (WorldTileCoord j = 0; j < size.height; j++) { + for (WorldTileCoord i = 0; i < size.width; i++) { + auto tileId = static_cast(SDL_SwapLE16(tileLayer[j * size.width + i])); if (tileId != 0) { pdungeon[position.x + i][position.y + j] = tileId; }