From 4ff10c525685b173e0a4d924b830c270123592b6 Mon Sep 17 00:00:00 2001 From: Matthew Jimenez Date: Sat, 28 Jan 2023 18:05:40 -0600 Subject: [PATCH] ULTIMA8: Add test case for inventory item sort rule --- engines/ultima/ultima8/world/sort_item.h | 5 +--- test/engines/ultima/ultima8/world/sort_item.h | 30 +++++++++++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/engines/ultima/ultima8/world/sort_item.h b/engines/ultima/ultima8/world/sort_item.h index 97bb2e65ebd..64b36ee4316 100644 --- a/engines/ultima/ultima8/world/sort_item.h +++ b/engines/ultima/ultima8/world/sort_item.h @@ -421,10 +421,7 @@ inline bool SortItem::below(const SortItem &si2) const { // Are overlapping in all 3 dimensions if we come here // Inv items always drawn after - // 2 places in Crusader have keycards on tables - // but their z position is the bottom z of the table. - // TODO: Find these cases and add unit test - if (si1._invitem != si2._invitem) + if (si1._invitem != si2._invitem) return si1._invitem < si2._invitem; // Flat always gets drawn before diff --git a/test/engines/ultima/ultima8/world/sort_item.h b/test/engines/ultima/ultima8/world/sort_item.h index 715478955cc..d287ce37d41 100644 --- a/test/engines/ultima/ultima8/world/sort_item.h +++ b/test/engines/ultima/ultima8/world/sort_item.h @@ -6,11 +6,6 @@ * * Be aware that the x and y coordinates go opposite to what you might expect, * see the notes in sort_item.h - * - * Still TODO tests: - * * overlapping in various dimensions - * * flat (z == zTop) items with various flags - * * special case for crusader inventory items */ class U8SortItemTestSuite : public CxxTest::TestSuite { public: @@ -80,6 +75,31 @@ class U8SortItemTestSuite : public CxxTest::TestSuite { TS_ASSERT(!si2.below(si1)); } + /** + * Inventory items can have a z at the same z of the surface below them + * Test case for keycard rendering issue at MainActor::teleport 9 34174 41502 0 + */ + void test_inv_item_sort() { + Ultima::Ultima8::SortItem si1(nullptr); + Ultima::Ultima8::SortItem si2(nullptr); + + Ultima::Ultima8::Box b1(34142, 41150, 0, 256, 64, 8); + si1.setBoxBounds(b1, 0, 0); + si2._solid = true; + si2._land = true; + + Ultima::Ultima8::Box b2(34110, 41118, 0, 64, 64, 0); + si2.setBoxBounds(b2, 0, 0); + si2._flat = true; + si2._invitem = true; + + TS_ASSERT(si1.overlap(si2)); + TS_ASSERT(si2.overlap(si1)); + + TS_ASSERT(si1.below(si2)); + TS_ASSERT(!si2.below(si1)); + } + /* Overlapping flat items (generally the floor) follow a set of rules */ void test_flat_sort() { Ultima::Ultima8::SortItem si1(nullptr);