Files
DarkflameServer/tests/dGameTests/PreconditionItemCostTests.cpp
Aaron Kimbrell b8a7ac897d fix(quickbuild): take precondition items when the build starts, give them back on cancel
A quickbuild's HasItem preconditions took their items only when the build
completed and never gave them back. Live took them when the build started
and gave them back when it was cancelled: the FV Stone Warrior pedestal
(LOT 8551, precondition 99: 5 of LOT 6194) took the items at Building 5
times and added them back with the loot source Quickbuild on each of the 3
cancels in the live captures.

Preconditions now report their item costs instead of removing items while
checking. A quickbuild takes them at the start, gives them back on cancel
or a reset during the build, keeps them on completion, and gives them back
when the builder leaves the world mid-build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 13:06:37 -05:00

33 lines
1.2 KiB
C++

#include "Preconditions.h"
#include <map>
#include <gtest/gtest.h>
// The items a quickbuild's HasItem precondition takes when the build starts
// (the FV Stone Warrior pedestal: precondition 99, 5 of LOT 6194).
namespace {
std::function<uint32_t(LOT)> Holding(const std::map<LOT, uint32_t>& inventory) {
return [inventory](const LOT lot) {
const auto it = inventory.find(lot);
return it == inventory.end() ? 0u : it->second;
};
}
}
TEST(PreconditionItemCostTests, TakesTheCountOfTheHeldLot) {
EXPECT_EQ(Precondition::PickItemCost({ 6194 }, 5, Holding({ { 6194, 7 } })), (ItemCost{ 6194, 5 }));
EXPECT_EQ(Precondition::PickItemCost({ 6194 }, 5, Holding({ { 6194, 5 } })), (ItemCost{ 6194, 5 }));
}
TEST(PreconditionItemCostTests, NotEnoughTakesNothing) {
EXPECT_FALSE(Precondition::PickItemCost({ 6194 }, 5, Holding({ { 6194, 4 } })));
EXPECT_FALSE(Precondition::PickItemCost({ 6194 }, 5, Holding({})));
}
// A precondition that lists several LOTs is met by any of them: the first one held is taken
TEST(PreconditionItemCostTests, TakesTheFirstHeldOfSeveralLots) {
EXPECT_EQ(Precondition::PickItemCost({ 100, 200, 300 }, 2, Holding({ { 100, 1 }, { 200, 2 }, { 300, 9 } })), (ItemCost{ 200, 2 }));
}