From 7a6a1124f3ac3a56570c8506078b2e6f632f1bc2 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Fri, 27 Nov 2026 19:09:53 -0600 Subject: [PATCH 1/4] feat(zone): waypoints keep every name / value pair as the file has it The Arrived message's actions are the waypoint's raw pairs in order; DLU dropped the ones that are no waypoint command (PlayAim). Co-Authored-By: Claude Opus 5.5 --- dCommon/ZoneFile.cpp | 1 + dCommon/ZoneFile.h | 2 ++ tests/dCommonTests/ZoneFileTests.cpp | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/dCommon/ZoneFile.cpp b/dCommon/ZoneFile.cpp index 317eaddfd..4c71fe4e2 100644 --- a/dCommon/ZoneFile.cpp +++ b/dCommon/ZoneFile.cpp @@ -226,6 +226,7 @@ bool ZoneFile::ReadLdfConfig(std::istream& file, PathType pathType, PathWaypoint std::string value; BinaryIO::ReadString(file, value, BinaryIO::ReadType::WideString); + waypoint.actions.emplace_back(parameter, value); if (pathType != PathType::Spawner) { // cause NetDevil puts spaces in things that don't need spaces diff --git a/dCommon/ZoneFile.h b/dCommon/ZoneFile.h index df015dc31..2059e71d9 100644 --- a/dCommon/ZoneFile.h +++ b/dCommon/ZoneFile.h @@ -90,6 +90,8 @@ struct PathWaypoint { float speed{}; LwoNameValue config; std::vector commands; + // Every name / value pair of the waypoint as the file has it, in order (the Arrived message's actions) + std::vector> actions; }; enum class PathType : uint32_t { diff --git a/tests/dCommonTests/ZoneFileTests.cpp b/tests/dCommonTests/ZoneFileTests.cpp index 622def895..ed42cd0b7 100644 --- a/tests/dCommonTests/ZoneFileTests.cpp +++ b/tests/dCommonTests/ZoneFileTests.cpp @@ -101,6 +101,24 @@ TEST(ZoneFileTests, ReadsScenesAndPaths) { } // Boundary lines sit between the scenes and the terrain file's name +// A waypoint keeps every name / value pair as the file has it, in order, also the ones that are no waypoint command +TEST(ZoneFileTests, WaypointsKeepTheirActions) { + ZoneBytes w; + w.Put(3).Wide("PlayAim").Wide("idle").Wide("de lay").Wide(" 2 ").Wide("spawner_node_id").Wide("1:4"); + std::istringstream file(w.data); + PathWaypoint waypoint; + ASSERT_TRUE(ZoneFile::ReadLdfConfig(file, PathType::MovingPlatform, waypoint)); + const std::vector> expected{ { "PlayAim", "idle" }, { "de lay", " 2 " }, { "spawner_node_id", "1:4" } }; + EXPECT_EQ(waypoint.actions, expected); + ASSERT_EQ(waypoint.commands.size(), 1u); + EXPECT_EQ(waypoint.commands[0].data, "2"); + + std::istringstream again(w.data); + PathWaypoint spawner; + ASSERT_TRUE(ZoneFile::ReadLdfConfig(again, PathType::Spawner, spawner)); + EXPECT_EQ(spawner.actions, expected); +} + TEST(ZoneFileTests, ReadsZoneBoundaries) { ZoneBytes w; w.Put(41).Put(3).Put(1150); From 22e115414fe7b81b1d77fe1dad37541c3f066833 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Fri, 27 Nov 2026 19:09:53 -0600 Subject: [PATCH 2/4] feat(activity): GetActivityUser, the first player with activity data Co-Authored-By: Claude Opus 5.5 --- dGame/dComponents/Activity/ActivityComponent.cpp | 4 ++++ dGame/dComponents/Activity/ActivityComponent.h | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/dGame/dComponents/Activity/ActivityComponent.cpp b/dGame/dComponents/Activity/ActivityComponent.cpp index d727cf1d2..aedf42625 100644 --- a/dGame/dComponents/Activity/ActivityComponent.cpp +++ b/dGame/dComponents/Activity/ActivityComponent.cpp @@ -275,6 +275,10 @@ float_t ActivityComponent::GetActivityValue(LWOOBJID playerID, uint32_t index) c return value; } +LWOOBJID ActivityComponent::GetActivityUser() const { + return m_ActivityPlayers.empty() ? LWOOBJID_EMPTY : m_ActivityPlayers.begin()->first; +} + void ActivityComponent::SetActivityValue(LWOOBJID playerID, uint32_t index, float_t value) { auto& data = m_ActivityPlayers[playerID]; data[std::min(index, static_cast(9))] = value; diff --git a/dGame/dComponents/Activity/ActivityComponent.h b/dGame/dComponents/Activity/ActivityComponent.h index 324ff2382..32916d2a0 100644 --- a/dGame/dComponents/Activity/ActivityComponent.h +++ b/dGame/dComponents/Activity/ActivityComponent.h @@ -268,6 +268,11 @@ public: */ float_t GetActivityValue(LWOOBJID playerID, uint32_t index) const; + /** + * The activity's user (GetActivityUser): the first player with activity data, or LWOOBJID_EMPTY when none has any + */ + LWOOBJID GetActivityUser() const; + /** * Removes activity score tracking for some entity * @param playerID the entity to remove score for From ce4f557c81000e130ff3d9fe3b3b3581346b3766 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Fri, 27 Nov 2026 19:09:53 -0600 Subject: [PATCH 3/4] feat(scripts): SG_TARGET time score write, PlayAim and ChangeSpeed timer Ports the parts of SG_TARGET.lua shipped data never reaches: the SetActivityUserData typeIndex 5 write, the PlayAim waypoint action and the ChangeSpeed timer branch. Co-Authored-By: Claude Opus 5.5 --- .../ai/MINIGAME/SG_GF/SERVER/SgTarget.cpp | 52 +++++++++++---- dScripts/ai/MINIGAME/SG_GF/SERVER/SgTarget.h | 10 ++- .../MovingPlatformComponentTests.cpp | 64 +++++++++++++++++++ 3 files changed, 111 insertions(+), 15 deletions(-) diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SgTarget.cpp b/dScripts/ai/MINIGAME/SG_GF/SERVER/SgTarget.cpp index 03bbb3f22..9f6510f12 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SgTarget.cpp +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SgTarget.cpp @@ -1,10 +1,12 @@ #include "SgTarget.h" +#include "ScriptedActivityComponent.h" #include "DestroyableComponent.h" #include "Entity.h" #include "EntityManager.h" #include "GeneralUtils.h" #include "MovementAIComponent.h" +#include "RenderComponent.h" #include "SGCannon.h" #include "Zone.h" #include "dZoneManager.h" @@ -15,7 +17,20 @@ void SgTarget::OnStartup(Entity* self) { } int32_t SgTarget::GetActivityPoints(Entity* self) { - return self->HasVar(u"SpawnData") ? self->GetVar(u"SpawnData").score : 0; + if (!self->HasVar(u"SpawnData")) return 0; + const int32_t points = self->GetVar(u"SpawnData").score; + // SetActivityUserData{userID = zone control's GetActivityUser, typeIndex 5, value = points} on the target: only an + // activity takes it, and the zone control without one has no user + const auto* const zoneControl = Game::entityManager->GetZoneControlEntity(); + const auto* const zoneActivity = zoneControl != nullptr ? zoneControl->GetComponent() : nullptr; + const LWOOBJID userID = zoneActivity != nullptr ? zoneActivity->GetActivityUser() : LWOOBJID_EMPTY; + if (auto* const activity = self->GetComponent()) activity->SetActivityValue(userID, 5, static_cast(points)); + return points; +} + +std::string SgTarget::GetPlayAimAnimation(const PathWaypoint& waypoint) { + if (waypoint.actions.empty() || waypoint.actions.front().first != "PlayAim") return ""; + return waypoint.actions.front().second; } bool SgTarget::DiedSilently(Entity* self) { @@ -31,8 +46,12 @@ void SgTarget::OnWaypointReached(Entity* self, const uint32_t waypointIndex) { return; } ChangeSpeed(self); - // The script also plays the animation a waypoint's PlayAim action names; no path in the game has one. Then it - // continues its waypoints, which the movement does by itself. + // A first action of PlayAim plays the animation it names, when the target has it (no path in the game has one) + if (path != nullptr && waypointIndex < path->pathWaypoints.size()) { + const auto animation = GetPlayAimAnimation(path->pathWaypoints[waypointIndex]); + if (!animation.empty() && RenderComponent::GetAnimationTime(self, animation) > 0.0f) RenderComponent::PlayAnimation(self, animation); + } + // Then it continues its waypoints, which the movement does by itself } // The cannon spawns the next one (as after a hit, without a score); then the target despawns @@ -53,23 +72,30 @@ void SgTarget::NotifyParentToRespawn(Entity* self) { self->AddTimer("Despawn", spawnData.isMovingPlatform ? 2.0f : 1.0f); } +// ChangeSpeed: a speed of 1 to 4 every 5 s (the script's startup never starts this timer); Despawn: dies silently void SgTarget::OnTimerDone(Entity* self, std::string timerName) { - if (timerName != "Despawn") return; - self->CancelAllTimers(); - self->SetVar(u"SilentDeath", true); - self->Smash(self->GetObjectID(), eKillType::SILENT); + if (timerName == "ChangeSpeed") { + SetPathingSpeed(self, static_cast(GeneralUtils::GenerateRandomNumber(1, 4))); + self->AddTimer("ChangeSpeed", 5.0f); + } else if (timerName == "Despawn") { + self->CancelAllTimers(); + self->SetVar(u"SilentDeath", true); + self->Smash(self->GetObjectID(), eKillType::SILENT); + } } -// With its spawn data's chance, a new speed between its least and most (whole numbers, as Lua's math.random). The -// script sets it with SetPathingSpeed, which only an object following waypoints takes (a moving platform has no -// handler for it). +// With its spawn data's chance, a new speed between its least and most (whole numbers, as Lua's math.random) void SgTarget::ChangeSpeed(Entity* self) { if (!self->HasVar(u"SpawnData")) return; const auto& spawnData = self->GetVar(u"SpawnData"); if (!spawnData.changeSpeedAtWaypoint || GeneralUtils::GenerateRandomNumber(0.0f, 1.0f) > spawnData.speedChangeChance) return; - const auto newSpeed = static_cast(GeneralUtils::GenerateRandomNumber(static_cast(spawnData.minSpeed), static_cast(spawnData.maxSpeed))); + SetPathingSpeed(self, static_cast(GeneralUtils::GenerateRandomNumber(static_cast(spawnData.minSpeed), static_cast(spawnData.maxSpeed)))); +} + +// SetPathingSpeed: only an object following waypoints takes it (a moving platform has no handler for it) +void SgTarget::SetPathingSpeed(Entity* self, const float speed) { if (auto* const movementAI = self->GetComponent()) { - movementAI->SetMaxSpeed(newSpeed); - movementAI->SetCurrentSpeed(newSpeed); + movementAI->SetMaxSpeed(speed); + movementAI->SetCurrentSpeed(speed); } } diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SgTarget.h b/dScripts/ai/MINIGAME/SG_GF/SERVER/SgTarget.h index 928d474ef..727d76b2b 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SgTarget.h +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SgTarget.h @@ -1,10 +1,12 @@ #pragma once #include "CppScripts.h" +#include "ZoneFile.h" /** * A GF shooting gallery target (SG_TARGET.lua, set by the cannon as the target's custom_script_server): its explode * factor, its score, and what it does at the waypoints of its path. At the last one it tells the cannon - * (FinishedPath, the cannon spawns the next one) and dies silently a moment later; at the others it may change speed. + * (FinishedPath, the cannon spawns the next one) and dies silently a moment later; at the others it may change speed + * and plays the animation a PlayAim action names. */ class SgTarget : public CppScripts::Script { public: @@ -12,11 +14,15 @@ public: void OnWaypointReached(Entity* self, uint32_t waypointIndex) override; void OnTimerDone(Entity* self, std::string timerName) override; - // The points a hit gives (the script's GetActivityPoints: its spawn data's score; the spawn data has no time score) + // The points a hit gives (the script's GetActivityPoints: its spawn data's score; the spawn data has no time score). + // Also writes them as user data 5 of the zone control's activity user on the target's own activity, if it has one. static int32_t GetActivityPoints(Entity* self); + // The animation a waypoint's first action names when that action is PlayAim, else empty + static std::string GetPlayAimAnimation(const PathWaypoint& waypoint); // Whether it died silently at the end of its path (that is no hit) static bool DiedSilently(Entity* self); private: void NotifyParentToRespawn(Entity* self); void ChangeSpeed(Entity* self); + void SetPathingSpeed(Entity* self, float speed); }; diff --git a/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp b/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp index 74929ac78..7b2a59ba4 100644 --- a/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp +++ b/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp @@ -7,6 +7,7 @@ #include +#include "ScriptedActivityComponent.h" #include "BitStream.h" #include "CDClientDatabase.h" #include "Entity.h" @@ -1203,3 +1204,66 @@ TEST_F(MovingPlatformComponentTest, ShootingGalleryTargetAtTheEndOfItsPath) { EXPECT_TRUE(entity.HasTimer("Despawn")); EXPECT_FALSE(SgTarget::DiedSilently(&entity)); } + +// SG_TARGET.lua's PlayAim: only a waypoint whose first action is PlayAim names an animation +TEST_F(MovingPlatformComponentTest, ShootingGalleryTargetPlayAimAction) { + PathWaypoint waypoint; + EXPECT_EQ(SgTarget::GetPlayAimAnimation(waypoint), ""); + waypoint.actions = { { "PlayAim", "attack" } }; + EXPECT_EQ(SgTarget::GetPlayAimAnimation(waypoint), "attack"); + waypoint.actions = { { "delay", "1" }, { "PlayAim", "attack" } }; + EXPECT_EQ(SgTarget::GetPlayAimAnimation(waypoint), ""); + + // A target without the animation (no render component) arrives there as at any other waypoint + Path path; + path.pathType = PathType::MovingPlatform; + path.pathName = "TestAimPath"; + path.pathBehavior = PathBehavior::Once; + PathWaypoint first; + first.speed = 10.0f; + first.actions = { { "PlayAim", "attack" } }; + PathWaypoint second = first; + second.position = NiPoint3(10.0f, 0.0f, 0.0f); + path.pathWaypoints = { first, second }; + const_cast(Game::zoneManager->GetZone())->AddPath(path); + info.settings.Insert(u"attached_path", "TestAimPath"); + Entity entity(288300744895900140, info); + info.settings.values.clear(); + entity.SetVar(u"SpawnData", SGEnemy{}); + SgTarget script; + script.OnWaypointReached(&entity, 0); + entity.Update(0.0f); + EXPECT_FALSE(entity.HasTimer("Despawn")); +} + +// SG_TARGET.lua's ChangeSpeed timer: it starts again every time it runs (5 s); Despawn cancels it +TEST_F(MovingPlatformComponentTest, ShootingGalleryTargetChangeSpeedTimer) { + Entity entity(288300744895900141, info); + SgTarget script; + script.OnTimerDone(&entity, "ChangeSpeed"); + entity.Update(0.0f); + EXPECT_TRUE(entity.HasTimer("ChangeSpeed")); + EXPECT_FALSE(SgTarget::DiedSilently(&entity)); + script.OnTimerDone(&entity, "Despawn"); + entity.Update(0.0f); + EXPECT_FALSE(entity.HasTimer("ChangeSpeed")); + EXPECT_TRUE(SgTarget::DiedSilently(&entity)); +} + +// SG_TARGET.lua's GetActivityPoints writes the points as user data 5 on the target's own activity, for the zone +// control's activity user (none here: no zone control) +TEST_F(MovingPlatformComponentTest, ShootingGalleryTargetWritesItsTimeScore) { + Entity entity(288300744895900142, info); + SGEnemy spawnData{}; + spawnData.score = 500; + entity.SetVar(u"SpawnData", spawnData); + auto* const activity = entity.AddComponent(-1); + EXPECT_EQ(SgTarget::GetActivityPoints(&entity), 500); + EXPECT_FLOAT_EQ(activity->GetActivityValue(LWOOBJID_EMPTY, 5), 500.0f); + EXPECT_FLOAT_EQ(activity->GetActivityValue(LWOOBJID_EMPTY, 0), 0.0f); + + Entity noData(288300744895900143, info); + auto* const otherActivity = noData.AddComponent(-1); + EXPECT_EQ(SgTarget::GetActivityPoints(&noData), 0); + EXPECT_FALSE(otherActivity->PlayerHasActivityData(LWOOBJID_EMPTY)); +} From b5ead35a7955524a6e21042ffc801a09bc0f0313 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Fri, 27 Nov 2026 20:10:09 -0600 Subject: [PATCH 4/4] test: waypoint actions through a whole zone file; include order Co-Authored-By: Claude Opus 5.5 --- tests/dCommonTests/ZoneFileTests.cpp | 26 ++++++++----------- .../MovingPlatformComponentTests.cpp | 2 +- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/tests/dCommonTests/ZoneFileTests.cpp b/tests/dCommonTests/ZoneFileTests.cpp index ed42cd0b7..78f8f4114 100644 --- a/tests/dCommonTests/ZoneFileTests.cpp +++ b/tests/dCommonTests/ZoneFileTests.cpp @@ -101,22 +101,18 @@ TEST(ZoneFileTests, ReadsScenesAndPaths) { } // Boundary lines sit between the scenes and the terrain file's name -// A waypoint keeps every name / value pair as the file has it, in order, also the ones that are no waypoint command +// A waypoint keeps every name / value pair as the file has it, in order (names with their spaces), also on a +// spawner path, whose pairs are LDF config TEST(ZoneFileTests, WaypointsKeepTheirActions) { - ZoneBytes w; - w.Put(3).Wide("PlayAim").Wide("idle").Wide("de lay").Wide(" 2 ").Wide("spawner_node_id").Wide("1:4"); - std::istringstream file(w.data); - PathWaypoint waypoint; - ASSERT_TRUE(ZoneFile::ReadLdfConfig(file, PathType::MovingPlatform, waypoint)); - const std::vector> expected{ { "PlayAim", "idle" }, { "de lay", " 2 " }, { "spawner_node_id", "1:4" } }; - EXPECT_EQ(waypoint.actions, expected); - ASSERT_EQ(waypoint.commands.size(), 1u); - EXPECT_EQ(waypoint.commands[0].data, "2"); - - std::istringstream again(w.data); - PathWaypoint spawner; - ASSERT_TRUE(ZoneFile::ReadLdfConfig(again, PathType::Spawner, spawner)); - EXPECT_EQ(spawner.actions, expected); + std::istringstream stream(SampleZone()); + ZoneFile zone; + zone.Read(stream); + ASSERT_EQ(zone.paths.size(), 3u); + const std::vector> patrol{ { "de lay", " 2 " } }; + EXPECT_EQ(zone.paths[0].pathWaypoints.at(0).actions, patrol); + const std::vector> spawner{ { "spawner_node_id", "1:4" } }; + EXPECT_EQ(zone.paths[1].pathWaypoints.at(0).actions, spawner); + EXPECT_TRUE(zone.paths[2].pathWaypoints.at(0).actions.empty()); } TEST(ZoneFileTests, ReadsZoneBoundaries) { diff --git a/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp b/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp index 7b2a59ba4..672c49f45 100644 --- a/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp +++ b/tests/dGameTests/dComponentsTests/MovingPlatformComponentTests.cpp @@ -7,7 +7,6 @@ #include -#include "ScriptedActivityComponent.h" #include "BitStream.h" #include "CDClientDatabase.h" #include "Entity.h" @@ -20,6 +19,7 @@ #include "ai/MINIGAME/SG_GF/SERVER/SGCannon.h" #include "ai/MINIGAME/SG_GF/SERVER/SgTarget.h" #include "ScriptComponent.h" +#include "ScriptedActivityComponent.h" #include "SimplePhysicsComponent.h" #include "Zone.h" #include "dZoneManager.h"