diff --git a/Source/engine/render/scrollrt.cpp b/Source/engine/render/scrollrt.cpp index 0cbfedbf0..9b4da91be 100644 --- a/Source/engine/render/scrollrt.cpp +++ b/Source/engine/render/scrollrt.cpp @@ -735,7 +735,9 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit } Player *player = PlayerAtPosition(tilePosition); if (player != nullptr) { - auto playerId = static_cast(player->getId() + 1); + uint8_t pid = player->getId(); + assert(pid < MAX_PLRS); + int playerId = static_cast(pid) + 1; // If sprite is moving southwards or east, we want to draw it offset from the tile it's moving to, so we need negative ID // This respests the order that tiles are drawn. By using the negative id, we ensure that the sprite is drawn with priority if (player->_pmode == PM_WALK_SOUTHWARDS || (player->_pmode == PM_WALK_SIDEWAYS && player->_pdir == Direction::East)) @@ -768,7 +770,9 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit Monster *monster = FindMonsterAtPosition(tilePosition); if (monster != nullptr) { - auto monsterId = static_cast(monster->getId() + 1); + auto mid = monster->getId(); + assert(mid < MaxMonsters); + int monsterId = static_cast(mid) + 1; // If sprite is moving southwards or east, we want to draw it offset from the tile it's moving to, so we need negative ID // This respests the order that tiles are drawn. By using the negative id, we ensure that the sprite is drawn with priority if (monster->mode == MonsterMode::MoveSouthwards || (monster->mode == MonsterMode::MoveSideways && monster->direction == Direction::East)) @@ -809,17 +813,17 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit } if (leveltype != DTYPE_TOWN) { - char bArch = dSpecial[tilePosition.x][tilePosition.y]; - if (bArch != 0) { + int8_t bArch = dSpecial[tilePosition.x][tilePosition.y] - 1; + if (bArch >= 0) { bool transparency = TransList[bMap]; #ifdef _DEBUG // Turn transparency off here for debugging transparency = transparency && (SDL_GetModState() & KMOD_ALT) == 0; #endif if (transparency) { - ClxDrawLightBlended(out, targetBufferPosition, (*pSpecialCels)[bArch - 1]); + ClxDrawLightBlended(out, targetBufferPosition, (*pSpecialCels)[bArch]); } else { - ClxDrawLight(out, targetBufferPosition, (*pSpecialCels)[bArch - 1]); + ClxDrawLight(out, targetBufferPosition, (*pSpecialCels)[bArch]); } } } else { @@ -827,10 +831,9 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit // So delay the rendering until after the next row is being drawn. // This could probably have been better solved by sprites in screen space. if (tilePosition.x > 0 && tilePosition.y > 0 && targetBufferPosition.y > TILE_HEIGHT) { - char bArch = dSpecial[tilePosition.x - 1][tilePosition.y - 1]; - if (bArch != 0) { - ClxDraw(out, targetBufferPosition + Displacement { 0, -TILE_HEIGHT }, (*pSpecialCels)[bArch - 1]); - } + int8_t bArch = dSpecial[tilePosition.x - 1][tilePosition.y - 1] - 1; + if (bArch >= 0) + ClxDraw(out, targetBufferPosition + Displacement { 0, -TILE_HEIGHT }, (*pSpecialCels)[bArch]); } } }