Skip to content

Commit

Permalink
Fix and test OpenEnroth#1342
Browse files Browse the repository at this point in the history
  • Loading branch information
captainurist committed Oct 15, 2023
1 parent 7e9ba74 commit 32bda77
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Engine/Graphics/Indoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2046,7 +2046,7 @@ void SpawnRandomTreasure(MapInfo *mapInfo, SpawnPoint *a2) {
a1a.uType = pItemTable->pItems[a1a.containing_item.uItemID].uSpriteID;
a1a.containing_item.SetIdentified();
a1a.uObjectDescID = pObjectList->ObjectIDByItemID(a1a.uType);
a1a.containing_item.special_enchantment = (ItemEnchantment)v34;
a1a.containing_item.goldAmount = v34;
} else {
if (!a1a.containing_item.GenerateArtifact())
return;
Expand Down
2 changes: 1 addition & 1 deletion test/Bin/GameTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if(OE_BUILD_TESTS)
ExternalProject_Add(OpenEnroth_TestData
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/test_data_tmp
GIT_REPOSITORY https://github.com/OpenEnroth/OpenEnroth_TestData.git
GIT_TAG a880c8bc91c4bfb16398c4064529cb4857a74dc6
GIT_TAG 10ddfb20b6b1196158a3e8740c31e55d1830ee4c
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/test_data
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
Expand Down
19 changes: 18 additions & 1 deletion test/Bin/GameTest/GameTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,8 @@ GAME_TEST(Issues, Issue1340) {
auto statusTape = tapes.statusBar();
auto screenTape = tapes.screen();
test.playTraceFromTestData("issue_1340.mm7", "issue_1340.json");
EXPECT_EQ(mapTape, tape("out01.odm", "d29.blv")); // Emerald Isle -> Castle Harmondale.
EXPECT_EQ(mapTape, tape("out01.odm", "d29.blv")); // Emerald Isle -> Castle Harmondale. Map change is important because
// we want to trigger map respawn on first visit.
EXPECT_TRUE(screenTape.contains(SCREEN_CHEST));
EXPECT_GT(goldTape.delta(), 0); // Party should have picked some gold from the chest.
EXPECT_FALSE(statusTape.contains("You found 0 gold!")); // No piles of 0 size.
Expand All @@ -1748,3 +1749,19 @@ GAME_TEST(Issues, Issue1341) {
EXPECT_TRUE(statusTape.contains(fmt::format("Roderick stole {} gold!", peasantGoldTape.max()))); // And succeeded.
EXPECT_EQ(deadTape, tape(0)); // No one died in the process.
}

GAME_TEST(Issues, Issue1342) {
// Gold piles are generated with 0 gold.
auto goldTape = tapes.gold();
auto pilesTape = tapes.mapItemCount(ITEM_GOLD_SMALL);
auto statusTape = tapes.statusBar();
auto mapTape = tapes.map();
test.playTraceFromTestData("issue_1342.mm7", "issue_1342.json");
EXPECT_EQ(mapTape, tape("out01.odm", "d28.blv")); // Emerald Isle -> Dragon Cave. Map change is important here
// because we need to trigger map respawn on first visit.
EXPECT_GT(goldTape.delta(), 0); // We picked up some gold.
EXPECT_EQ(pilesTape, tape(0, 6, 5, 4)); // Minus two small gold piles.
EXPECT_FALSE(statusTape.contains("You found 0 gold!")); // No piles of 0 size.
for (int gold : goldTape.adjacentDeltas())
EXPECT_TRUE(statusTape.contains(fmt::format("You found {} gold!", gold)));
}
4 changes: 2 additions & 2 deletions test/Testing/Game/CommonTapeRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ TestTape<bool> CommonTapeRecorder::turnBasedMode() {
TestTape<int> CommonTapeRecorder::mapItemCount() {
return custom([] {
return static_cast<int>(std::ranges::count_if(pSpriteObjects, [] (const SpriteObject &object) {
return object.containing_item.uItemID != ITEM_NULL;
return object.uObjectDescID != 0 && object.containing_item.uItemID != ITEM_NULL;
}));
});
}

TestTape<int> CommonTapeRecorder::mapItemCount(ItemId itemId) {
return custom([itemId] {
return static_cast<int>(std::ranges::count_if(pSpriteObjects, [itemId] (const SpriteObject &object) {
return object.containing_item.uItemID == itemId;
return object.uObjectDescID != 0 && object.containing_item.uItemID == itemId;
}));
});
}

0 comments on commit 32bda77

Please sign in to comment.