fix(spawner): spawn on smash for a network named by spawner name

A spawner with spawnsGroupOnSmash and spawnNetNameForSpawnGroupOnSmash
naming a zone spawner network only logged when an object of that
network died, so quick builds behind crates (Fire Temple rooms and
waves, Aura Mar bouncers) never appeared. A spawner with no_auto_spawn
now spawns when an object of the named network dies, as the group
paths already did. A spawner without no_auto_spawn is not linked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-11-28 23:18:07 -06:00
parent fb1edd52f3
commit 87873a7b11
3 changed files with 123 additions and 2 deletions

View File

@@ -57,9 +57,14 @@ Spawner::Spawner(const SpawnerInfo& info) {
for (Spawner* ssSpawner : spawnSmashSpawnersN) {
m_SpawnSmashFoundGroup = true;
m_SpawnOnSmashID = ssSpawner ? ssSpawner->m_Info.spawnerID : LWOOBJID_EMPTY;
// A spawner that only appears on a smash (no_auto_spawn) spawns when an object of the network it names dies.
// Every such entry in the game's levels names a zone spawner network and has no_auto_spawn but one.
if (!m_Info.noAutoSpawn) {
LOG_DEBUG("Spawner %s (LOT %i) names network %s to spawn on smash but has no no_auto_spawn, not linked", m_Info.name.c_str(), m_EntityInfo.lot, m_Info.spawnOnSmashGroupName.c_str());
continue;
}
ssSpawner->AddSpawnedEntityDieCallback([=, this]() {
// Intentionally left as a non debug log since i have no idea how much stuff this would affect
LOG("WOULD HAVE SPAWNED %i", m_EntityInfo.lot);
Spawn();
});
}
}

View File

@@ -40,6 +40,7 @@ set(DCOMPONENTS_TESTS
"UseItemResultTests.cpp"
"LootMetricsTests.cpp"
"SpawnerComponentTests.cpp"
"SpawnOnSmashTests.cpp"
"SkillComponentTests.cpp"
)

View File

@@ -0,0 +1,115 @@
#include "GameDependencies.h"
#include "CDClientDatabase.h"
#include "CDClientManager.h"
#include "CDComponentsRegistryTable.h"
#include "Entity.h"
#include "EntityManager.h"
#include "Spawner.h"
#include "dZoneManager.h"
#include <gtest/gtest.h>
// A spawner with spawnsGroupOnSmash and spawnNetNameForSpawnGroupOnSmash spawns when an object of the zone spawner
// network it names (a crate) dies.
class SpawnOnSmashTests : public GameDependenciesTest {
protected:
static constexpr LOT CrateLot = 16830;
static constexpr LOT QuickBuildLot = 16834;
static constexpr const char* CrateNetwork = "Room02Smash01";
void SetUp() override {
SetUpDependencies();
// Creating an entity looks its LOT up in the CDClient
CDClientDatabase::Connect(":memory:");
for (const auto* const table : {
"ComponentsRegistry (id INTEGER, component_type INTEGER, component_id INTEGER)",
"Objects (id INTEGER, name TEXT, type TEXT, interactionDistance REAL)",
}) {
CDClientDatabase::ExecuteDML(std::string("CREATE TABLE IF NOT EXISTS ") + table + ";");
}
// None of these LOTs has components, so nothing is looked up in a database
auto& registry = CDClientManager::GetEntriesMutable<CDComponentsRegistryTable>();
for (const LOT lot : { 176, CrateLot, QuickBuildLot }) registry.insert_or_assign(static_cast<uint64_t>(lot), 0);
}
void TearDown() override { TearDownDependencies(); }
SpawnerInfo WithOneNode(const LOT lot) {
SpawnerInfo spawnerInfo{};
spawnerInfo.templateID = lot;
spawnerInfo.nodes.push_back(m_Nodes.emplace_back(std::make_unique<SpawnerNode>()).get());
return spawnerInfo;
}
// The zone spawner network, made first as the zone file is loaded before the levels
Spawner* MakeCrateNetwork() {
auto spawnerInfo = WithOneNode(CrateLot);
spawnerInfo.name = CrateNetwork;
spawnerInfo.isNetwork = true;
return Game::zoneManager->GetSpawner(Game::zoneManager->MakeSpawner(spawnerInfo));
}
Spawner* MakeQuickBuild(const bool noAutoSpawn) {
auto spawnerInfo = WithOneNode(QuickBuildLot);
spawnerInfo.spawnsOnSmash = true;
spawnerInfo.spawnOnSmashGroupName = CrateNetwork;
spawnerInfo.noAutoSpawn = noAutoSpawn;
spawnerInfo.respawnTime = 20.0f;
return Game::zoneManager->GetSpawner(Game::zoneManager->MakeSpawner(spawnerInfo));
}
static void SmashCrate(Spawner& crates) {
auto* const crate = crates.Spawn();
ASSERT_NE(crate, nullptr);
crates.NotifyOfEntityDeath(crate->GetObjectID());
}
std::vector<std::unique_ptr<SpawnerNode>> m_Nodes;
};
TEST_F(SpawnOnSmashTests, TheQuickBuildWaitsForTheSmash) {
MakeCrateNetwork();
auto* const quickBuild = MakeQuickBuild(true);
ASSERT_NE(quickBuild, nullptr);
EXPECT_TRUE(quickBuild->GetIsSpawnSmashGroup());
// No timed spawn before the crate is smashed
quickBuild->Update(30.0f);
quickBuild->Update(30.0f);
EXPECT_TRUE(quickBuild->GetSpawnedObjectIDs().empty());
}
TEST_F(SpawnOnSmashTests, SmashingTheCrateSpawnsTheQuickBuild) {
auto* const crates = MakeCrateNetwork();
auto* const quickBuild = MakeQuickBuild(true);
ASSERT_NE(crates, nullptr);
ASSERT_NE(quickBuild, nullptr);
SmashCrate(*crates);
const auto spawned = quickBuild->GetSpawnedObjectIDs();
ASSERT_EQ(spawned.size(), 1);
auto* const entity = Game::entityManager->GetEntity(spawned[0]);
ASSERT_NE(entity, nullptr);
EXPECT_EQ(entity->GetLOT(), QuickBuildLot);
}
TEST_F(SpawnOnSmashTests, AnotherSmashKeepsOneQuickBuild) {
auto* const crates = MakeCrateNetwork();
auto* const quickBuild = MakeQuickBuild(true);
SmashCrate(*crates);
SmashCrate(*crates);
EXPECT_EQ(quickBuild->GetSpawnedObjectIDs().size(), 1);
}
TEST_F(SpawnOnSmashTests, WithoutNoAutoSpawnTheSmashSpawnsNothing) {
auto* const crates = MakeCrateNetwork();
auto* const quickBuild = MakeQuickBuild(false);
SmashCrate(*crates);
EXPECT_TRUE(quickBuild->GetSpawnedObjectIDs().empty());
}