diff --git a/Source/gendung.h b/Source/gendung.h index 5ddf67524..3ac2bef82 100644 --- a/Source/gendung.h +++ b/Source/gendung.h @@ -134,7 +134,7 @@ struct ShadowStruct { }; /** Contains the tile IDs of the map. */ -extern uint8_t dungeon[DMAXX][DMAXY]; +extern DVL_API_FOR_TEST uint8_t dungeon[DMAXX][DMAXY]; /** Contains a backup of the tile IDs of the map. */ extern uint8_t pdungeon[DMAXX][DMAXY]; extern uint8_t dflags[DMAXX][DMAXY]; @@ -152,7 +152,7 @@ extern std::unique_ptr pSetPiece; extern bool setloadflag; extern std::optional pSpecialCels; /** Specifies the tile definitions of the active dungeon type; (e.g. levels/l1data/l1.til). */ -extern std::unique_ptr pMegaTiles; +extern DVL_API_FOR_TEST std::unique_ptr pMegaTiles; extern std::unique_ptr pLevelPieces; extern std::unique_ptr pDungeonCels; /** @@ -190,7 +190,7 @@ extern _setlevels setlvlnum; /** Specifies the player viewpoint X-coordinate of the map. */ extern dungeon_type setlvltype; /** Specifies the player viewpoint X,Y-coordinates of the map. */ -extern Point ViewPosition; +extern DVL_API_FOR_TEST Point ViewPosition; extern ScrollStruct ScrollInfo; extern int MicroTileLen; extern char TransVal; @@ -201,7 +201,7 @@ extern DVL_API_FOR_TEST int dPiece[MAXDUNX][MAXDUNY]; /** Specifies the dungeon piece information for a given coordinate and block number. */ extern MICROS dpiece_defs_map_2[MAXDUNX][MAXDUNY]; /** Specifies the transparency at each coordinate of the map. */ -extern int8_t dTransVal[MAXDUNX][MAXDUNY]; +extern DVL_API_FOR_TEST int8_t dTransVal[MAXDUNX][MAXDUNY]; extern DVL_API_FOR_TEST char dLight[MAXDUNX][MAXDUNY]; extern char dPreLight[MAXDUNX][MAXDUNY]; /** Holds various information about dungeon tiles, @see DungeonFlag */ diff --git a/Source/setmaps.cpp b/Source/setmaps.cpp index a7726866f..21f388d66 100644 --- a/Source/setmaps.cpp +++ b/Source/setmaps.cpp @@ -129,12 +129,12 @@ void SetMapTransparency(const char *path) width *= 2; height *= 2; - const uint16_t *transparantLayer = &dunData[layer2Offset + width * height * 3]; + const uint16_t *transparentLayer = &dunData[layer2Offset + width * height * 3]; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { - dTransVal[16 + i][16 + j] = SDL_SwapLE16(*transparantLayer); - transparantLayer++; + dTransVal[16 + i][16 + j] = SDL_SwapLE16(*transparentLayer); + transparentLayer++; } } } diff --git a/test/drlg_l1_test.cpp b/test/drlg_l1_test.cpp index 2a094b96b..c34b4a9e7 100644 --- a/test/drlg_l1_test.cpp +++ b/test/drlg_l1_test.cpp @@ -1,11 +1,18 @@ +#include #include #include "diablo.h" #include "drlg_l1.h" +#include "engine/load_file.hpp" #include "lighting.h" +#include "player.h" +#include "quests.h" +#include "utils/paths.h" using namespace devilution; +namespace { + TEST(Drlg_l1, DRLG_Init_Globals_noflag) { DisableLighting = false; @@ -19,3 +26,134 @@ TEST(Drlg_l1, DRLG_Init_Globals) DRLG_Init_Globals(); EXPECT_EQ(dLight[0][0], 0); } + +void TestCreateL5Dungeon(bool hellfire, int level, uint32_t seed, lvl_entry entry) +{ + pMegaTiles = std::make_unique(1648); + + MyPlayer->pOriginalCathedral = !hellfire; + + currlevel = level; + leveltype = DTYPE_CATHEDRAL; + + CreateL5Dungeon(seed, entry); + + std::string path = paths::BasePath(); + + paths::SetPrefPath(path); + std::string dunPath; + if (hellfire) + dunPath = fmt::format("../test/fixtures/hellfire/{}-{}.dun", level, seed); + else + dunPath = fmt::format("../test/fixtures/diablo/{}-{}.dun", level, seed); + auto dunData = LoadFileInMem(dunPath.c_str()); + ASSERT_EQ(DMAXX, dunData[0]); + ASSERT_EQ(DMAXY, dunData[1]); + + const uint16_t *tileLayer = &dunData[2]; + + for (int y = 0; y < DMAXY; y++) { + for (int x = 0; x < DMAXX; x++) { + auto tileId = static_cast(SDL_SwapLE16(*tileLayer)); + tileLayer++; + ASSERT_EQ(dungeon[x][y], tileId); + } + } + + const uint16_t *transparentLayer = &dunData[2 + DMAXX * DMAXY * 13]; + + for (int y = 16; y < 16 + DMAXY * 2; y++) { + for (int x = 16; x < 16 + DMAXX * 2; x++) { + auto sectorId = static_cast(SDL_SwapLE16(*transparentLayer)); + transparentLayer++; + ASSERT_EQ(dTransVal[x][y], sectorId) << "Room/region indexes don't match"; + } + } +} + +TEST(Drlg_l1, CreateL5Dungeon_diablo_1_743271966) +{ + TestCreateL5Dungeon(false, 1, 743271966, ENTRY_MAIN); + EXPECT_EQ(ViewPosition.x, 51); + EXPECT_EQ(ViewPosition.y, 82); + TestCreateL5Dungeon(false, 1, 743271966, ENTRY_PREV); + EXPECT_EQ(ViewPosition.x, 81); + EXPECT_EQ(ViewPosition.y, 47); +} + +TEST(Drlg_l1, CreateL5Dungeon_diablo_2_1383137027) +{ + Quests[Q_PWATER]._qlevel = 2; + Quests[Q_PWATER]._qactive = QUEST_INIT; + + TestCreateL5Dungeon(false, 2, 1383137027, ENTRY_MAIN); + EXPECT_EQ(ViewPosition.x, 57); + EXPECT_EQ(ViewPosition.y, 74); + TestCreateL5Dungeon(false, 2, 1383137027, ENTRY_PREV); + EXPECT_EQ(ViewPosition.x, 57); + EXPECT_EQ(ViewPosition.y, 79); +} + +TEST(Drlg_l1, CreateL5Dungeon_diablo_3_844660068) +{ + TestCreateL5Dungeon(false, 3, 844660068, ENTRY_MAIN); + EXPECT_EQ(ViewPosition.x, 67); + EXPECT_EQ(ViewPosition.y, 52); + TestCreateL5Dungeon(false, 3, 844660068, ENTRY_PREV); + EXPECT_EQ(ViewPosition.x, 85); + EXPECT_EQ(ViewPosition.y, 45); +} + +TEST(Drlg_l1, CreateL5Dungeon_diablo_4_609325643) +{ + TestCreateL5Dungeon(false, 4, 609325643, ENTRY_MAIN); + EXPECT_EQ(ViewPosition.x, 85); + EXPECT_EQ(ViewPosition.y, 78); + TestCreateL5Dungeon(false, 4, 609325643, ENTRY_PREV); + EXPECT_EQ(ViewPosition.x, 55); + EXPECT_EQ(ViewPosition.y, 47); +} + +TEST(Drlg_l1, CreateL5Dungeon_hellfire_1_401921334) +{ + TestCreateL5Dungeon(true, 1, 401921334, ENTRY_MAIN); + EXPECT_EQ(ViewPosition.x, 79); + EXPECT_EQ(ViewPosition.y, 80); + TestCreateL5Dungeon(true, 1, 401921334, ENTRY_PREV); + EXPECT_EQ(ViewPosition.x, 49); + EXPECT_EQ(ViewPosition.y, 63); +} + +TEST(Drlg_l1, CreateL5Dungeon_hellfire_2_128964898) +{ + Quests[Q_PWATER]._qactive = QUEST_NOTAVAIL; + + TestCreateL5Dungeon(true, 2, 128964898, ENTRY_MAIN); + EXPECT_EQ(ViewPosition.x, 55); + EXPECT_EQ(ViewPosition.y, 68); + TestCreateL5Dungeon(true, 2, 128964898, ENTRY_PREV); + EXPECT_EQ(ViewPosition.x, 49); + EXPECT_EQ(ViewPosition.y, 63); +} + +TEST(Drlg_l1, CreateL5Dungeon_hellfire_3_1799396623) +{ + TestCreateL5Dungeon(true, 3, 1799396623, ENTRY_MAIN); + EXPECT_EQ(ViewPosition.x, 59); + EXPECT_EQ(ViewPosition.y, 68); + TestCreateL5Dungeon(true, 3, 1799396623, ENTRY_PREV); + EXPECT_EQ(ViewPosition.x, 47); + EXPECT_EQ(ViewPosition.y, 55); +} + +TEST(Drlg_l1, CreateL5Dungeon_hellfire_4_1190318991) +{ + TestCreateL5Dungeon(true, 4, 1190318991, ENTRY_MAIN); + EXPECT_EQ(ViewPosition.x, 67); + EXPECT_EQ(ViewPosition.y, 80); + TestCreateL5Dungeon(true, 4, 1190318991, ENTRY_PREV); + EXPECT_EQ(ViewPosition.x, 77); + EXPECT_EQ(ViewPosition.y, 45); +} + +} // namespace diff --git a/test/fixtures/diablo/1-743271966.dun b/test/fixtures/diablo/1-743271966.dun new file mode 100644 index 000000000..fa943b67d Binary files /dev/null and b/test/fixtures/diablo/1-743271966.dun differ diff --git a/test/fixtures/diablo/2-1383137027.dun b/test/fixtures/diablo/2-1383137027.dun new file mode 100644 index 000000000..263f312cc Binary files /dev/null and b/test/fixtures/diablo/2-1383137027.dun differ diff --git a/test/fixtures/diablo/3-844660068.dun b/test/fixtures/diablo/3-844660068.dun new file mode 100644 index 000000000..817fa52fc Binary files /dev/null and b/test/fixtures/diablo/3-844660068.dun differ diff --git a/test/fixtures/diablo/4-609325643.dun b/test/fixtures/diablo/4-609325643.dun new file mode 100644 index 000000000..47118871d Binary files /dev/null and b/test/fixtures/diablo/4-609325643.dun differ diff --git a/test/fixtures/hellfire/1-401921334.dun b/test/fixtures/hellfire/1-401921334.dun new file mode 100644 index 000000000..0b3c3e611 Binary files /dev/null and b/test/fixtures/hellfire/1-401921334.dun differ diff --git a/test/fixtures/hellfire/2-128964898.dun b/test/fixtures/hellfire/2-128964898.dun new file mode 100644 index 000000000..ad9341a1f Binary files /dev/null and b/test/fixtures/hellfire/2-128964898.dun differ diff --git a/test/fixtures/hellfire/3-1799396623.dun b/test/fixtures/hellfire/3-1799396623.dun new file mode 100644 index 000000000..5f320c4e1 Binary files /dev/null and b/test/fixtures/hellfire/3-1799396623.dun differ diff --git a/test/fixtures/hellfire/4-1190318991.dun b/test/fixtures/hellfire/4-1190318991.dun new file mode 100644 index 000000000..90c13b353 Binary files /dev/null and b/test/fixtures/hellfire/4-1190318991.dun differ