From 8885f6d978c0d23b5d2dd2fa6a8155c4173b0be9 Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Thu, 5 Oct 2023 23:09:08 -0700 Subject: [PATCH] Cannon Cove: Fix incorrect sign Update CMakeVariables.txt Cannon Cove: Fix incorrect sign --- .../ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp | 278 ++++++++++-------- dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h | 6 + 2 files changed, 161 insertions(+), 123 deletions(-) diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp index 66171b953..97798dc8c 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.cpp @@ -160,166 +160,198 @@ void SGCannon::OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button } } -void SGCannon::OnActivityTimerDone(Entity* self, const std::string& name) { - if (name == SuperChargeTimer && !self->GetVar(SuperChargePausedVariable)) { - if (self->GetVar(WaveStatusVariable) || self->GetVar(CurrentSuperChargedTimeVariable) < 1) { - self->SetNetworkVar(ChargeCountingVariable, 99); - self->SetNetworkVar(SuperChargeBarVariable, 0); - ToggleSuperCharge(self, false); - } - } else if (name == SpawnWaveTimer) { - if (self->GetVar(GameStartedVariable)) { - self->SetVar(WaveStatusVariable, true); - const auto wave = (int32_t)self->GetVar(ThisWaveVariable); +void SGCannon::SuperChargeTimerFunc(Entity* self) { + if (self->GetVar(WaveStatusVariable) || self->GetVar(CurrentSuperChargedTimeVariable) < 1) { + self->SetNetworkVar(ChargeCountingVariable, 99); + self->SetNetworkVar(SuperChargeBarVariable, 0); + ToggleSuperCharge(self, false); + } +} - if (wave != 0 && self->GetVar(SuperChargePausedVariable)) { - StartChargedCannon(self, self->GetVar(CurrentSuperChargedTimeVariable)); - self->SetVar(CurrentSuperChargedTimeVariable, 0); - } +void SGCannon::SpawnWaveTimerFunc(Entity* self) { + if (self->GetVar(GameStartedVariable)) { + self->SetVar(WaveStatusVariable, true); + const auto wave = (int32_t)self->GetVar(ThisWaveVariable); - TimerToggle(self, true); + if (wave != 0 && self->GetVar(SuperChargePausedVariable)) { + StartChargedCannon(self, self->GetVar(CurrentSuperChargedTimeVariable)); + self->SetVar(CurrentSuperChargedTimeVariable, 0); + } - for (const auto& enemyToSpawn : m_Waves.at(self->GetVar(ThisWaveVariable))) { - SpawnObject(self, enemyToSpawn, true); - } + TimerToggle(self, true); - Game::logger->Log("SGCannon", "Current wave spawn: %i/%i", wave, m_Waves.size()); + for (const auto& enemyToSpawn : m_Waves.at(self->GetVar(ThisWaveVariable))) { + SpawnObject(self, enemyToSpawn, true); + } - // All waves completed - const auto timeLimit = (float_t)self->GetVar(TimeLimitVariable); - if (wave >= m_Waves.size()) { - ActivityTimerStart(self, GameOverTimer, timeLimit, timeLimit); - } else { - ActivityTimerStart(self, EndWaveTimer, timeLimit, timeLimit); - } + Game::logger->Log("SGCannon", "Current wave spawn: %i/%i", wave, m_Waves.size()); - const auto* player = Game::entityManager->GetEntity(self->GetVar(PlayerIDVariable)); - if (player != nullptr) { - GameMessages::SendPlayFXEffect(player->GetObjectID(), -1, u"SG-start", ""); + // All waves completed + const auto timeLimit = (float_t)self->GetVar(TimeLimitVariable); + if (wave >= m_Waves.size()) { + ActivityTimerStart(self, GameOverTimer, timeLimit, timeLimit); + } else { + ActivityTimerStart(self, EndWaveTimer, timeLimit, timeLimit); + } - GameMessages::SendStartActivityTime(self->GetObjectID(), timeLimit, player->GetSystemAddress()); - Game::logger->Log("SGCannon", "Sending ActivityPause false"); + const auto* player = Game::entityManager->GetEntity(self->GetVar(PlayerIDVariable)); + if (player != nullptr) { + GameMessages::SendPlayFXEffect(player->GetObjectID(), -1, u"SG-start", ""); - GameMessages::SendActivityPause(self->GetObjectID(), false, player->GetSystemAddress()); - } - } - } else if (name == EndWaveTimer) { - self->SetVar(WaveStatusVariable, false); - TimerToggle(self); - RecordPlayerScore(self); + GameMessages::SendStartActivityTime(self->GetObjectID(), timeLimit, player->GetSystemAddress()); + Game::logger->Log("SGCannon", "Sending ActivityPause false"); - if (self->GetVar(ThisWaveVariable) >= 2) { - GameMessages::SendActivityPause(self->GetObjectID(), true); - ActivityTimerStart(self, GameOverTimer, 0.1, 0.1); - return; + GameMessages::SendActivityPause(self->GetObjectID(), false, player->GetSystemAddress()); } + } +} - self->SetVar(ThisWaveVariable, self->GetVar(ThisWaveVariable) + 1); - PlaySceneAnimation(self, u"wave" + GeneralUtils::to_u16string(self->GetVar(ThisWaveVariable)), true, true, 1.7f); - self->SetNetworkVar(WaveNumVariable, self->GetVar(ThisWaveVariable) + 1); - self->SetNetworkVar(WaveStrVariable, self->GetVar(TimeLimitVariable)); +void SGCannon::EndWaveTimerFunc(Entity* self) { + self->SetVar(WaveStatusVariable, false); + TimerToggle(self); + RecordPlayerScore(self); - Game::logger->Log("SGCannon", "Current wave: %i/%i", self->GetVar(ThisWaveVariable), m_Waves.size()); + if (self->GetVar(ThisWaveVariable) >= 2) { + GameMessages::SendActivityPause(self->GetObjectID(), true); + ActivityTimerStart(self, GameOverTimer, 0.1, 0.1); + return; + } - if (self->GetVar(ThisWaveVariable) >= m_Waves.size()) { - ActivityTimerStart(self, GameOverTimer, 0.1, 0.1); - } else { - ActivityTimerStart(self, SpawnWaveTimer, constants.inBetweenWavePause, constants.inBetweenWavePause); - } + self->SetVar(ThisWaveVariable, self->GetVar(ThisWaveVariable) + 1); + PlaySceneAnimation(self, u"wave" + GeneralUtils::to_u16string(self->GetVar(ThisWaveVariable)), true, true, 1.7f); + self->SetNetworkVar(WaveNumVariable, self->GetVar(ThisWaveVariable) + 1); + self->SetNetworkVar(WaveStrVariable, self->GetVar(TimeLimitVariable)); + + Game::logger->Log("SGCannon", "Current wave: %i/%i", self->GetVar(ThisWaveVariable), m_Waves.size()); + + if (self->GetVar(ThisWaveVariable) >= m_Waves.size()) { + ActivityTimerStart(self, GameOverTimer, 0.1, 0.1); + } else { + ActivityTimerStart(self, SpawnWaveTimer, constants.inBetweenWavePause, constants.inBetweenWavePause); + } + + Game::logger->Log("SGCannon", "Sending ActivityPause true"); + + GameMessages::SendActivityPause(self->GetObjectID(), true); + if (self->GetVar(SuperChargeActiveVariable) && !self->GetVar(SuperChargePausedVariable)) { + PauseChargeCannon(self); + } +} +void SGCannon::GameOverTimerFunc(Entity* self) { + auto* player = Game::entityManager->GetEntity(self->GetVar(PlayerIDVariable)); + if (player != nullptr) { Game::logger->Log("SGCannon", "Sending ActivityPause true"); - GameMessages::SendActivityPause(self->GetObjectID(), true); - if (self->GetVar(SuperChargeActiveVariable) && !self->GetVar(SuperChargePausedVariable)) { - PauseChargeCannon(self); - } - } else if (name == GameOverTimer) { - auto* player = Game::entityManager->GetEntity(self->GetVar(PlayerIDVariable)); - if (player != nullptr) { - Game::logger->Log("SGCannon", "Sending ActivityPause true"); + GameMessages::SendActivityPause(self->GetObjectID(), true, player->GetSystemAddress()); - GameMessages::SendActivityPause(self->GetObjectID(), true, player->GetSystemAddress()); + /*const auto leftoverCannonballs = Game::entityManager->GetEntitiesInGroup("cannonball"); + if (leftoverCannonballs.empty()) { + RecordPlayerScore(self); - /*const auto leftoverCannonballs = Game::entityManager->GetEntitiesInGroup("cannonball"); - if (leftoverCannonballs.empty()) { - RecordPlayerScore(self); + } else { + ActivityTimerStart(self, EndGameBufferTimer, 1, leftoverCannonballs.size()); + }*/ - } else { - ActivityTimerStart(self, EndGameBufferTimer, 1, leftoverCannonballs.size()); - }*/ + ActivityTimerStart(self, EndGameBufferTimer, 1, 1); - ActivityTimerStart(self, EndGameBufferTimer, 1, 1); + TimerToggle(self); + } +} - TimerToggle(self); +void SGCannon::DoSpawnTimerFunc(Entity* self, const std::string& name) { + if (self->GetVar(GameStartedVariable)) { + Game::logger->LogDebug("SGCannon", "time name %s %s", name.c_str(), name.substr(7).c_str()); + const auto spawnNumber = (uint32_t)std::stoi(name.substr(7)); + const auto& activeSpawns = self->GetVar>(ActiveSpawnsVariable); + Game::logger->LogDebug("SGCannon", "size %i, %i", activeSpawns.size(), spawnNumber); + if (activeSpawns.size() <= spawnNumber) { + Game::logger->Log("SGCannon", "Trying to spawn %i when spawns size is only %i", spawnNumber, activeSpawns.size()); + return; } - } else if (name.rfind(DoSpawnTimer, 0) == 0) { - if (self->GetVar(GameStartedVariable)) { - const auto spawnNumber = (uint32_t)std::stoi(name.substr(7)); - const auto& activeSpawns = self->GetVar>(ActiveSpawnsVariable); - if (activeSpawns.size() < spawnNumber) { - Game::logger->Log("SGCannon", "Trying to spawn %i when spawns size is only %i", spawnNumber, activeSpawns.size()); - return; - } - const auto& toSpawn = activeSpawns.at(spawnNumber); - const auto pathIndex = GeneralUtils::GenerateRandomNumber(0, toSpawn.spawnPaths.size() - 1); - const auto* path = Game::zoneManager->GetZone()->GetPath(toSpawn.spawnPaths.at(pathIndex)); - if (!path) { - Game::logger->Log("SGCannon", "Path %s at index %i is null", toSpawn.spawnPaths.at(pathIndex).c_str(), pathIndex); - return; - } - auto info = EntityInfo{}; - info.lot = toSpawn.lot; - info.spawnerID = self->GetObjectID(); - info.pos = path->pathWaypoints.at(0).position; + const auto& toSpawn = activeSpawns.at(spawnNumber); + Game::logger->LogDebug("SGCannon", "toSpawn %i", toSpawn.spawnPaths.size()); + const auto pathIndex = GeneralUtils::GenerateRandomNumber(0, toSpawn.spawnPaths.size() - 1); + Game::logger->LogDebug("SGCannon", "index %f", pathIndex); + Game::logger->LogDebug("SGCannon", "%s", toSpawn.spawnPaths.at(pathIndex).c_str()); + const auto* path = Game::zoneManager->GetZone()->GetPath(toSpawn.spawnPaths.at(pathIndex)); + if (!path) { + Game::logger->Log("SGCannon", "Path %s at index %i is null", toSpawn.spawnPaths.at(pathIndex).c_str(), pathIndex); + return; + } - info.settings = { - new LDFData(u"SpawnData", toSpawn), - new LDFData(u"custom_script_server", "scripts/ai/ACT/SG_TARGET.lua"), - new LDFData(u"custom_script_client", "scripts/client/ai/SG_TARGET_CLIENT.lua"), - new LDFData(u"attached_path", path->pathName), - new LDFData(u"attached_path_start", 0), - new LDFData(u"groupID", u"SGEnemy") - }; + Game::logger->LogDebug("SGCannon", "%s", path->pathName.c_str()); - Game::logger->Log("SGCannon", "Spawning enemy %i on path %s", toSpawn.lot, path->pathName.c_str()); + auto info = EntityInfo{}; + info.lot = toSpawn.lot; + info.spawnerID = self->GetObjectID(); + info.pos = path->pathWaypoints.at(0).position; - auto* enemy = Game::entityManager->CreateEntity(info, nullptr, self); - Game::entityManager->ConstructEntity(enemy); + info.settings = { + new LDFData(u"SpawnData", toSpawn), + new LDFData(u"custom_script_server", "scripts/ai/ACT/SG_TARGET.lua"), + new LDFData(u"custom_script_client", "scripts/client/ai/SG_TARGET_CLIENT.lua"), + new LDFData(u"attached_path", path->pathName), + new LDFData(u"attached_path_start", 0), + new LDFData(u"groupID", u"SGEnemy") + }; - auto* movementAI = new MovementAIComponent(enemy, {}); + Game::logger->Log("SGCannon", "Spawning enemy %i on path %s", toSpawn.lot, path->pathName.c_str()); - enemy->AddComponent(eReplicaComponentType::MOVEMENT_AI, movementAI); + auto* enemy = Game::entityManager->CreateEntity(info, nullptr, self); + Game::entityManager->ConstructEntity(enemy); - movementAI->SetMaxSpeed(toSpawn.initialSpeed); - movementAI->SetCurrentSpeed(toSpawn.initialSpeed); - movementAI->SetHaltDistance(0.0f); + auto* movementAI = new MovementAIComponent(enemy, {}); - std::vector pathWaypoints; + enemy->AddComponent(eReplicaComponentType::MOVEMENT_AI, movementAI); - for (const auto& waypoint : path->pathWaypoints) { - pathWaypoints.push_back(waypoint.position); - } + movementAI->SetMaxSpeed(toSpawn.initialSpeed); + movementAI->SetCurrentSpeed(toSpawn.initialSpeed); + movementAI->SetHaltDistance(0.0f); - if (GeneralUtils::GenerateRandomNumber(0, 1) < 0.5f) { - std::reverse(pathWaypoints.begin(), pathWaypoints.end()); - } + std::vector pathWaypoints; - movementAI->SetPath(pathWaypoints); + for (const auto& waypoint : path->pathWaypoints) { + pathWaypoints.push_back(waypoint.position); + } - enemy->AddDieCallback([this, self, enemy, name]() { - RegisterHit(self, enemy, name); - }); + if (GeneralUtils::GenerateRandomNumber(0, 1) < 0.5f) { + std::reverse(pathWaypoints.begin(), pathWaypoints.end()); + } - // Save the enemy and tell it to start pathing - if (enemy != nullptr) { - const_cast&>(self->GetVar>(SpawnedObjects)).push_back(enemy->GetObjectID()); - GameMessages::SendPlatformResync(enemy, UNASSIGNED_SYSTEM_ADDRESS); - } + movementAI->SetPath(pathWaypoints); + + enemy->AddDieCallback([this, self, enemy, name]() { + RegisterHit(self, enemy, name); + }); + + // Save the enemy and tell it to start pathing + if (enemy != nullptr) { + const_cast&>(self->GetVar>(SpawnedObjects)).push_back(enemy->GetObjectID()); + GameMessages::SendPlatformResync(enemy, UNASSIGNED_SYSTEM_ADDRESS); } + } +} + +void SGCannon::EndGameBufferTimerFunc(Entity* self) { + RecordPlayerScore(self); + StopGame(self, false); +} + +void SGCannon::OnActivityTimerDone(Entity* self, const std::string& name) { + if (name == SuperChargeTimer && !self->GetVar(SuperChargePausedVariable)) { + SuperChargeTimerFunc(self); + } else if (name == SpawnWaveTimer) { + SpawnWaveTimerFunc(self); + } else if (name == EndWaveTimer) { + EndWaveTimerFunc(self); + } else if (name == GameOverTimer) { + GameOverTimerFunc(self); + } else if (name.rfind(DoSpawnTimer, 0) == 0) { + DoSpawnTimerFunc(self, name); } else if (name == EndGameBufferTimer) { - RecordPlayerScore(self); - StopGame(self, false); + EndGameBufferTimerFunc(self); } } diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h index b20fae6de..712983c9e 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h @@ -68,6 +68,12 @@ class SGCannon : public ActivityManager { void OnActivityTimerDone(Entity* self, const std::string& name) override; void OnActivityTimerUpdate(Entity* self, const std::string& name, float_t timeRemaining, float_t elapsedTime) override; void OnRequestActivityExit(Entity* self, LWOOBJID player, bool canceled) override; + void SuperChargeTimerFunc(Entity* self); + void SpawnWaveTimerFunc(Entity* self); + void EndWaveTimerFunc(Entity* self); + void GameOverTimerFunc(Entity* self); + void DoSpawnTimerFunc(Entity* self, const std::string& name); + void EndGameBufferTimerFunc(Entity* self); private: static std::vector> GetWaves(); static SGConstants GetConstants();