Files
DarkflameServer/dScripts/ai/AG/AgBusDoor.cpp
Aaron Kimbrell c6f6aa5d2b fix(scripts): AG elevator, bus door and property platform drive their movers as their live scripts did
StopPathing, StartPathing and GoToWaypoint instead of hand-made resyncs; a built platform starts before the scripts hear of it so a script can stop it; the FV tree platform's resync hack is gone.

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

70 lines
2.4 KiB
C++

#include "AgBusDoor.h"
#include "Entity.h"
#include "GameMessages.h"
#include "EffectsMessages.h"
#include "MovingPlatformComponent.h"
#include "ProximityMonitorComponent.h"
void AgBusDoor::OnStartup(Entity* self) {
m_Counter = 0;
m_OuterCounter = 0;
self->SetProximityRadius(75, "busDoor");
self->SetProximityRadius(85, "busDoorOuter");
// L_AG_BUS_DOOR: the door only moves when sent
if (auto* const platform = self->GetComponent<MovingPlatformComponent>()) platform->StopPathing();
}
void AgBusDoor::OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) {
if (name != "busDoor" && name != "busDoorOuter") return;
// Make sure only humans are taken into account
if (!entering->GetCharacter()) return;
auto* proximityMonitorComponent = self->GetComponent<ProximityMonitorComponent>();
if (proximityMonitorComponent == nullptr) return;
m_Counter = 0;
m_OuterCounter = 0;
for (const auto id : proximityMonitorComponent->GetProximityObjects("busDoor")) {
const auto* const entity = Game::entityManager->GetEntity(id);
if (entity != nullptr && entity->IsPlayer()) m_Counter++;
}
for (const auto id : proximityMonitorComponent->GetProximityObjects("busDoorOuter")) {
const auto* const entity = Game::entityManager->GetEntity(id);
if (entity != nullptr && entity->IsPlayer()) m_OuterCounter++;
}
if (status == "ENTER") {
// move up when a player is inside both radii
if (m_Counter > 0) {
MoveDoor(self, true);
}
} else if (status == "LEAVE") {
// move down when no players are inside either radii
if (m_Counter <= 0) {
MoveDoor(self, false);
}
}
}
void AgBusDoor::MoveDoor(Entity* self, bool bOpen) {
if (bOpen) {
if (auto* const platform = self->GetComponent<MovingPlatformComponent>()) platform->GotoWaypoint(0);
} else {
if (auto* const platform = self->GetComponent<MovingPlatformComponent>()) platform->GotoWaypoint(1);
self->AddTimer("dustTimer", 2.0f);
}
//This is currently commented out because it might be the reason that people's audio is cutting out.
GameMessages::PlayNDAudioEmitter(self->GetObjectID(), "{9a24f1fa-3177-4745-a2df-fbd996d6e1e3}").Send(UNASSIGNED_SYSTEM_ADDRESS);
}
void AgBusDoor::OnTimerDone(Entity* self, std::string timerName) {
if (timerName == "dustTimer") {
GameMessages::PlayFXEffect(self->GetObjectID(), 642, u"create", "busDust").Send(UNASSIGNED_SYSTEM_ADDRESS);
}
}