From a75623b41d67c2dbb0d0363865c675797240f001 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Fri, 27 Nov 2026 22:22:51 -0600 Subject: [PATCH] feat(scripts): Medusa and its five snake parts ported from the original L_WILD_MEDUSA.lua (LOT 6602) loads the snake parts 6564-6568 at +-5 around it; each part (L_WILD_snake_01..05.lua) joins the group, follows the part before it (radius 4.5, speed 1, keepFollowing) and on its death tells the group, turning the next part to faction 4 with its effect. Part 5 starts hostile and glows red; the chain ends with the Medusa. The Set tables are put on the combat and movement AI the way the Lua AI uses them. OverrideFriction is a client-side message only, so it is a no-op. Co-Authored-By: Claude Opus 5.5 --- dScripts/CppScripts.cpp | 7 ++ dScripts/ai/WILD/CMakeLists.txt | 2 + dScripts/ai/WILD/WildMedusa.cpp | 100 ++++++++++++++++++++++++++++ dScripts/ai/WILD/WildMedusa.h | 18 +++++ dScripts/ai/WILD/WildMedusaData.cpp | 39 +++++++++++ dScripts/ai/WILD/WildMedusaData.h | 93 ++++++++++++++++++++++++++ 6 files changed, 259 insertions(+) create mode 100644 dScripts/ai/WILD/WildMedusa.cpp create mode 100644 dScripts/ai/WILD/WildMedusa.h create mode 100644 dScripts/ai/WILD/WildMedusaData.cpp create mode 100644 dScripts/ai/WILD/WildMedusaData.h diff --git a/dScripts/CppScripts.cpp b/dScripts/CppScripts.cpp index b4161b7a4..6c1818eea 100644 --- a/dScripts/CppScripts.cpp +++ b/dScripts/CppScripts.cpp @@ -348,6 +348,7 @@ #include "WildNinjaStudent.h" #include "WildNinjaSensei.h" #include "WildNinjaBricks.h" +#include "WildMedusa.h" #include "VisToggleNotifierServer.h" #include "LupGenericInteract.h" #include "WblRobotCitizen.h" @@ -775,6 +776,12 @@ namespace { {"scripts\\ai\\WILD\\L_WILD_AMBIENT_CRAB.lua", []() {return new WildAmbientCrab();}}, {"scripts\\ai\\WILD\\L_WILD_PANTS.lua", []() {return new WildPants();}}, {"scripts\\ai\\WILD\\L_WILD_NINJA_BRICKS.lua", []() {return new WildNinjaBricks();}}, + {"scripts\\ai\\WILD\\L_WILD_MEDUSA.lua", []() {return new WildMedusa();}}, + {"scripts\\ai\\WILD\\L_WILD_snake_01.lua", []() {return new WildSnake();}}, + {"scripts\\ai\\WILD\\L_WILD_snake_02.lua", []() {return new WildSnake();}}, + {"scripts\\ai\\WILD\\L_WILD_snake_03.lua", []() {return new WildSnake();}}, + {"scripts\\ai\\WILD\\L_WILD_snake_04.lua", []() {return new WildSnake();}}, + {"scripts\\ai\\WILD\\L_WILD_snake_05.lua", []() {return new WildSnake();}}, {"scripts\\ai\\WILD\\L_WILD_NINJA_STUDENT.lua", []() {return new WildNinjaStudent();}}, {"scripts\\ai\\WILD\\L_WILD_NINJA_SENSEI.lua", []() {return new WildNinjaSensei();}}, {"scripts\\ai\\WILD\\L_LUP_generic_interact.lua", []() {return new LupGenericInteract();}}, diff --git a/dScripts/ai/WILD/CMakeLists.txt b/dScripts/ai/WILD/CMakeLists.txt index 5d4f43c31..6aed1bc10 100644 --- a/dScripts/ai/WILD/CMakeLists.txt +++ b/dScripts/ai/WILD/CMakeLists.txt @@ -5,6 +5,8 @@ set(DSCRIPTS_SOURCES_AI_WILD "WildAmbientCrab.cpp" "WildAndScared.cpp" "WildGfGlowbug.cpp" + "WildMedusa.cpp" + "WildMedusaData.cpp" "WildNinjaBricks.cpp" "WildNinjaStudent.cpp" "WildNinjaSensei.cpp" diff --git a/dScripts/ai/WILD/WildMedusa.cpp b/dScripts/ai/WILD/WildMedusa.cpp new file mode 100644 index 000000000..b42e87edc --- /dev/null +++ b/dScripts/ai/WILD/WildMedusa.cpp @@ -0,0 +1,100 @@ +#include "WildMedusa.h" + +#include "WildMedusaData.h" +#include "Entity.h" +#include "EntityInfo.h" +#include "EntityManager.h" +#include "GameMessages.h" +#include "EffectsMessages.h" +#include "MovementAIComponent.h" + +namespace { + // SetFaction { faction = 4 } and PlayFXEffect { effectType = effect } + void TurnHostile(Entity* self, const std::u16string& effect) { + GameMessages::SetFaction setFaction{}; + setFaction.target = self->GetObjectID(); + setFaction.factionID = MedusaSnakes::HOSTILE_FACTION; + setFaction.Send(); + if (!effect.empty()) GameMessages::PlayFXEffect(self->GetObjectID(), -1, effect, "").Send(UNASSIGNED_SYSTEM_ADDRESS); + } +}; + +// L_WILD_MEDUSA.lua onStartup +void WildMedusa::OnStartup(Entity* self) { + // The original adds a SnakeStartup timer here with nothing to handle it + self->AddTimer("SnakeStartup", MedusaSnakes::STARTUP_TIME); + self->AddToGroup(MedusaSnakes::GROUP); + // Its OverrideFriction is commented out in the original + + // Spawn snake pieces: RESMGR:LoadObject { owner = self } at the offsets + const auto position = self->GetPosition(); + for (const auto& part : MedusaSnakes::PARTS) { + EntityInfo info{}; + info.lot = part.lot; + info.pos = position + part.offset; + info.rot = QuatUtils::IDENTITY; + info.spawnerID = self->GetObjectID(); + auto* const spawned = Game::entityManager->CreateEntity(info); + if (spawned) Game::entityManager->ConstructEntity(spawned); + } + + // loadOnce, getVarables, CreateStates, oStart + MedusaSnakes::LuaAi::Apply(self, MedusaSnakes::LuaAi::MEDUSA); +} + +// L_WILD_MEDUSA.lua onNotifyObject +void WildMedusa::OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1, int32_t param2) { + if (name == MedusaSnakes::MEDUSA_NOTIFY) TurnHostile(self, MedusaSnakes::MEDUSA_EFFECT); +} + +// L_WILD_snake_0N.lua onStartup +void WildSnake::OnStartup(Entity* self) { + self->AddTimer("SnakeStartup", MedusaSnakes::STARTUP_TIME); + self->AddTimer("SnakeFollow", MedusaSnakes::FOLLOW_TIME); + const auto* const part = MedusaSnakes::GetPart(self->GetLOT()); + if (part && part->turnsHostileOn[0] == '\0') self->AddTimer("SnakeGlow", MedusaSnakes::GLOW_TIME); + + // loadOnce, getVarables, CreateStates, oStart + MedusaSnakes::LuaAi::Apply(self, MedusaSnakes::LuaAi::SNAKE); +} + +// L_WILD_snake_0N.lua onDie +void WildSnake::OnDie(Entity* self, Entity* killer) { + const auto* const part = MedusaSnakes::GetPart(self->GetLOT()); + if (!part) return; + for (auto* const snake : Game::entityManager->GetEntitiesInGroup(MedusaSnakes::GROUP)) { + snake->NotifyObject(self, part->notifyOnDeath); + } +} + +// L_WILD_snake_01..04.lua onNotifyObject (part 5 has none) +void WildSnake::OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1, int32_t param2) { + const auto* const part = MedusaSnakes::GetPart(self->GetLOT()); + if (!part || part->turnsHostileOn[0] == '\0' || name != part->turnsHostileOn) return; + TurnHostile(self, part->hostileEffect); +} + +// L_WILD_snake_0N.lua onTimerDone +void WildSnake::OnTimerDone(Entity* self, std::string timerName) { + const auto* const part = MedusaSnakes::GetPart(self->GetLOT()); + if (!part) return; + + if (timerName == "SnakeStartup") { + self->AddToGroup(MedusaSnakes::GROUP); + // OverrideFriction { bEnableOverride = true, fFriction = 10 }: the client sends it only inside its own + // process (a friction phantom physics effect sends it to the objects in it), it is no network message + // and the server's movement has no friction, so there is nothing to do here + // Part 5 is the first to fight + if (part->turnsHostileOn[0] == '\0') TurnHostile(self, u""); + } else if (timerName == "SnakeFollow") { + auto* const movement = self->GetComponent(); + if (!movement) return; + for (auto* const friend_ : Game::entityManager->GetEntitiesInGroup(MedusaSnakes::GROUP)) { + if (friend_->GetLOT() == part->follows) { + movement->FollowTarget(friend_->GetObjectID(), MedusaSnakes::FOLLOW_RADIUS, MedusaSnakes::FOLLOW_SPEED, MedusaSnakes::FOLLOW_KEEP); + } + } + } else if (timerName == "SnakeGlow") { + GameMessages::PlayFXEffect(self->GetObjectID(), -1, MedusaSnakes::GLOW_EFFECT, "").Send(UNASSIGNED_SYSTEM_ADDRESS); + } +} diff --git a/dScripts/ai/WILD/WildMedusa.h b/dScripts/ai/WILD/WildMedusa.h new file mode 100644 index 000000000..a03237aeb --- /dev/null +++ b/dScripts/ai/WILD/WildMedusa.h @@ -0,0 +1,18 @@ +#pragma once +#include "CppScripts.h" + +// L_WILD_MEDUSA.lua: spawns the five snake parts around it and turns hostile once the last of them dies +class WildMedusa final : public CppScripts::Script { +public: + void OnStartup(Entity* self) override; + void OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1 = 0, int32_t param2 = 0) override; +}; + +// L_WILD_snake_01..05.lua: a snake part that follows the part before it and, when it dies, turns the next one hostile +class WildSnake final : public CppScripts::Script { +public: + void OnStartup(Entity* self) override; + void OnDie(Entity* self, Entity* killer) override; + void OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1 = 0, int32_t param2 = 0) override; + void OnTimerDone(Entity* self, std::string timerName) override; +}; diff --git a/dScripts/ai/WILD/WildMedusaData.cpp b/dScripts/ai/WILD/WildMedusaData.cpp new file mode 100644 index 000000000..30c1c3f30 --- /dev/null +++ b/dScripts/ai/WILD/WildMedusaData.cpp @@ -0,0 +1,39 @@ +#include "WildMedusaData.h" + +#include "Entity.h" +#include "BaseCombatAIComponent.h" +#include "MovementAIComponent.h" + +const MedusaSnakes::Part* MedusaSnakes::GetPart(const LOT lot) { + for (const auto& part : PARTS) { + if (part.lot == lot) return ∂ + } + return nullptr; +} + +void MedusaSnakes::LuaAi::Apply(Entity* self, const Settings& set) { + auto* const combat = self->GetComponent(); + if (combat) { + // oStart: the aggroRadius proximity, for an Aggressive one only + if (set.aggression == Aggression::Aggressive) combat->SetAggroRadius(set.aggroRadius); + // aggro.onEnter: SetTetherPoint { radius = tetherRadius } and + // FollowTarget { radius = AggroDist, speed = AggroSpeed * 2, keepFollowing = true } + combat->SetHardTetherRadius(set.tetherRadius); + combat->SetAttackRadius(set.aggroDist); + combat->SetPursuitSpeed(PursuitSpeed(set)); + // tether.onEnter: GoTo { speed = tetherSpeed } + combat->SetTetherSpeed(set.tetherSpeed); + } + + // conductRadius: no conduct proximity is made, nothing reads it + + auto* const movement = self->GetComponent(); + if (movement) { + // Meander: GoTo { speed = WanderSpeed } within wanderRadius, then a WanderDelayMin..Max pause. Only a + // Wander one has the Meander state; a Guard one stays put + movement->SetWanderRadius(set.wanderRadius); + movement->SetWanderSpeed(set.wanderSpeed); + movement->SetWanderDelay(set.wanderDelayMin, set.wanderDelayMax); + movement->SetWanderChance(set.movementType == MovementType::Wander ? set.wanderChance : 0.0f); + } +} diff --git a/dScripts/ai/WILD/WildMedusaData.h b/dScripts/ai/WILD/WildMedusaData.h new file mode 100644 index 000000000..fd2832ea8 --- /dev/null +++ b/dScripts/ai/WILD/WildMedusaData.h @@ -0,0 +1,93 @@ +#pragma once + +// The Medusa (L_WILD_MEDUSA.lua) and its five snake parts (L_WILD_snake_01..05.lua): the parts it spawns, the +// chain of notifications that turns each one hostile when the one before it dies, and the Lua AI settings (the +// scripts' Set tables) they run with. + +#include "dCommonVars.h" +#include "NiPoint3.h" + +#include +#include + +class Entity; + +namespace MedusaSnakes { + constexpr LOT MEDUSA_LOT = 6602; + constexpr const char* GROUP = "snakesonaplane"; + // The Medusa turns hostile on this one, from the last part to die + constexpr const char* MEDUSA_NOTIFY = "next5"; + constexpr const char16_t* MEDUSA_EFFECT = u"medusa"; + constexpr int32_t HOSTILE_FACTION = 4; + + // The parts' SnakeStartup and SnakeFollow timers, and part 5's SnakeGlow + constexpr float STARTUP_TIME = 0.2f; + constexpr float FOLLOW_TIME = 0.3f; + constexpr float GLOW_TIME = 2.0f; + constexpr const char16_t* GLOW_EFFECT = u"red"; + + // FollowTarget { radius = 4.5, speed = 1, keepFollowing = true } + constexpr float FOLLOW_RADIUS = 4.5f; + constexpr float FOLLOW_SPEED = 1.0f; + constexpr bool FOLLOW_KEEP = true; + + // OverrideFriction { bEnableOverride = true, fFriction = 10 } + constexpr float PART_FRICTION = 10.0f; + + struct Part { + LOT lot; + // Where the Medusa's onStartup loads it, from the Medusa's position + NiPoint3 offset; + // What its onDie tells the group + const char* notifyOnDeath; + // What turns it hostile (none for part 5, hostile from its startup) + const char* turnsHostileOn; + const char16_t* hostileEffect; + // The part it follows + LOT follows; + }; + + // In the order the Medusa loads them; part 5 (6568) is the first one to fight + constexpr std::array PARTS{ { + { 6564, { 0.0f, 0.0f, 5.0f }, "next5", "next4", u"purple", MEDUSA_LOT }, + { 6565, { 0.0f, 0.0f, -5.0f }, "next4", "next3", u"blue", 6564 }, + { 6566, { 5.0f, 0.0f, 0.0f }, "next3", "next2", u"green", 6565 }, + { 6567, { -5.0f, 0.0f, 0.0f }, "next2", "next1", u"yellow", 6566 }, + { 6568, { 5.0f, 0.0f, -5.0f }, "next1", "", u"", 6567 }, + } }; + + // The part with this LOT, or nullptr + const Part* GetPart(LOT lot); + + // The Lua AI settings of the scripts' Set tables that change the server's AI + namespace LuaAi { + enum class Aggression { Aggressive, Neutral, Passive, PassiveAggres }; + enum class MovementType { Guard, Wander }; + + struct Settings { + float aggroRadius; + // Read only by the conduct proximity, which oStart never makes: no effect + float conductRadius; + float tetherRadius; + float tetherSpeed; + float wanderRadius; + Aggression aggression; + float aggroDist; + float aggroSpeed; + MovementType movementType; + float wanderChance; + float wanderDelayMin; + float wanderDelayMax; + float wanderSpeed; + }; + + constexpr Settings MEDUSA{ 15.0f, 15.0f, 50.0f, 1.0f, 25.0f, Aggression::Aggressive, 8.0f, 1.0f, MovementType::Wander, 100.0f, 1.0f, 10.0f, 0.65f }; + constexpr Settings SNAKE{ 50.0f, 15.0f, 50.0f, 8.0f, 8.0f, Aggression::Passive, 7.0f, 3.5f, MovementType::Guard, 0.0f, 9999.0f, 9999.0f, 0.5f }; + + // The aggro state's FollowTarget speed: AggroSpeed * 2 + constexpr float PursuitSpeed(const Settings& set) { return set.aggroSpeed * 2.0f; } + + // oStart and the states it makes: puts the settings on the entity's combat and movement AI, where it has them + void Apply(Entity* self, const Settings& set); + }; +};