Files
DarkflameServer/tests/dGameTests/dComponentsTests/DestroyableLevelConfigTests.cpp
Aaron Kimbrell 721925add0 fix(factions): override_faction 0 keeps the template's factions
The client (LWODestroyableComponent::LoadConfigData 0x00c44cb0) uses a
level object's set_faction only when override_faction is absent or true;
with override_faction=0 LoadDataFromTemplate (0x00c9f900) puts the
DestructibleComponent factionList back. 2948 level objects have
override_faction=0, and DLU applied their set_faction anyway. The
resolution is now DestroyableComponent::GetLevelFactions, with tests.
No wire change.

In game: enemies and smashables placed in levels with a set_faction but
override_faction=0 (most smashables, many enemies) are targeted and
aggro as before for the common case; check a few enemies in AG/GF/FV
still fight you and friendly objects are not attacked, and that
smashables still smash and give credit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 23:34:22 -05:00

47 lines
1.6 KiB
C++

#include "GameDependencies.h"
#include "DestroyableComponent.h"
#include "Entity.h"
#include <gtest/gtest.h>
// How a level object's config changes its DestroyableComponent, as the client's
// LWODestroyableComponent::LoadConfigData (0x00c44cb0) and LoadDataFromTemplate (0x00c9f900) resolve it.
class DestroyableLevelConfigTests : public GameDependenciesTest {
protected:
std::unique_ptr<Entity> entity;
void SetUp() override {
SetUpDependencies();
entity = std::make_unique<Entity>(1, info);
}
void TearDown() override {
entity.reset();
TearDownDependencies();
}
};
TEST_F(DestroyableLevelConfigTests, NoSetFactionKeepsTheTemplateFactions) {
EXPECT_FALSE(DestroyableComponent::GetLevelFactions(*entity));
entity->SetVar<bool>(u"override_faction", true);
EXPECT_FALSE(DestroyableComponent::GetLevelFactions(*entity));
}
TEST_F(DestroyableLevelConfigTests, SetFactionWithoutOverrideFactionIsUsed) {
entity->SetVar<std::string>(u"set_faction", "6 ");
EXPECT_EQ(DestroyableComponent::GetLevelFactions(*entity), std::vector<int32_t>{ 6 });
}
TEST_F(DestroyableLevelConfigTests, SetFactionWithOverrideFactionTrueIsUsed) {
entity->SetVar<std::string>(u"set_faction", "4; 6");
entity->SetVar<bool>(u"override_faction", true);
EXPECT_EQ(DestroyableComponent::GetLevelFactions(*entity), (std::vector<int32_t>{ 4, 6 }));
}
TEST_F(DestroyableLevelConfigTests, OverrideFactionFalseIgnoresSetFaction) {
entity->SetVar<std::string>(u"set_faction", "-1");
entity->SetVar<bool>(u"override_faction", false);
EXPECT_FALSE(DestroyableComponent::GetLevelFactions(*entity));
}