diff --git a/src/Game/Systems/PlayerDeathSystem.cpp b/src/Game/Systems/PlayerDeathSystem.cpp index bb9a807c..95709e88 100644 --- a/src/Game/Systems/PlayerDeathSystem.cpp +++ b/src/Game/Systems/PlayerDeathSystem.cpp @@ -18,6 +18,8 @@ bool PlayerDeathSystem::OnPlayerDeath(Events::PlayerDeath& e) return false; } + LOG_DEBUG("------ Player #%i died.", e.Player.ID); + createDeathEffect(e.Player); // Delete player @@ -36,6 +38,7 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player) auto playerModel = player.FirstChildByName("PlayerModel"); if (!playerModel.Valid() || !playerModel.HasComponent("Model") || !playerModel.HasComponent("Animation")) { if (player == LocalPlayer) { + LOG_DEBUG("------ LocalPlayer's death effect could not be spawned, setting to spectator instead of death cam."); setSpectatorCamera(); } return; @@ -57,6 +60,7 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player) //camera (with lifetime) behind the player if (player == LocalPlayer) { + LOG_DEBUG("------ LocalPlayer's death effect spawning, setting to death camera."); m_LocalPlayerDeathEffect = deathEffectEW; auto cam = deathEffectEW.FirstChildByName("Camera"); Events::SetCamera eSetCamera; @@ -71,8 +75,14 @@ bool PlayerDeathSystem::OnEntityDeleted(Events::EntityDeleted& e) if (m_LocalPlayerDeathEffect.ID != e.DeletedEntity) { return false; } - - setSpectatorCamera(); + + // If the player hasn't spawned already, activate the spectator camera. + if (!LocalPlayer.Valid()) { + LOG_DEBUG("------ LocalPlayer's death effect removed, setting to spectator."); + setSpectatorCamera(); + } else { + LOG_DEBUG("------ LocalPlayer's death effect removed, player is already spawned, not setting spectator."); + } return true; } @@ -80,7 +90,7 @@ void PlayerDeathSystem::setSpectatorCamera() { // Look for the spectator camera entity in the level. EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera"); - if (!spectatorCam.Valid() || !spectatorCam.HasComponent("Camera") || LocalPlayer.Valid()) { + if (!spectatorCam.Valid() || !spectatorCam.HasComponent("Camera")) { return; } Events::SetCamera eSetCamera; diff --git a/src/Game/Systems/PlayerSpawnSystem.cpp b/src/Game/Systems/PlayerSpawnSystem.cpp index 7692b0a7..2e55965e 100644 --- a/src/Game/Systems/PlayerSpawnSystem.cpp +++ b/src/Game/Systems/PlayerSpawnSystem.cpp @@ -59,13 +59,15 @@ void PlayerSpawnSystem::Update(double dt) return; } - int numSpawnedPlayers = 0; + int numHandledRequests = 0; + int playersStillPickingClass = 0; + const int numRequestsToHandle = (int)m_SpawnRequests.size(); for (auto it = m_SpawnRequests.begin(); it != m_SpawnRequests.end(); ++it) { // TODO: -1 Signifies no class picked, enum here later? - // Increase num spawned players if they didn't pick class yet since it is valid + // It is valid if they didn't pick class yet // but don't spawn anything, goto next spawnrequest. if (it->Class == -1) { - ++numSpawnedPlayers; + ++playersStillPickingClass; break; } for (auto& cPlayerSpawn : *playerSpawns) { @@ -78,10 +80,11 @@ void PlayerSpawnSystem::Update(double dt) if (spawner.HasComponent("Team")) { auto cSpawnerTeam = spawner["Team"]; if ((int)cSpawnerTeam["Team"] != it->Team) { - // Increase num spawned players if someone picks spectator since it is valid + // It is valid if someone picks spectator // but don't spawn anything, goto next spawnrequest. if (it->Team == (int)cSpawnerTeam["Team"].Enum("Spectator")) { - ++numSpawnedPlayers; + ++numHandledRequests; + it = m_SpawnRequests.erase(it); break; } continue; @@ -103,7 +106,7 @@ void PlayerSpawnSystem::Update(double dt) m_EventBroker->Publish(e); Events::LockMouse lock; m_EventBroker->Publish(lock); - ++numSpawnedPlayers; + ++numHandledRequests; it = m_SpawnRequests.erase(it); break; } @@ -111,17 +114,18 @@ void PlayerSpawnSystem::Update(double dt) break; } } - if (numSpawnedPlayers != (int)m_SpawnRequests.size()) { - LOG_DEBUG("%i players were supposed to be spawned or set as spectator, but only %i was handled.", (int)m_SpawnRequests.size(), numSpawnedPlayers); + if (numHandledRequests != numRequestsToHandle - playersStillPickingClass) { + LOG_DEBUG("%i players were supposed to be spawned or set as spectator, but only %i was handled.", numRequestsToHandle, numHandledRequests); } else { - LOG_DEBUG("%i players were spawned or set as spectator.", numSpawnedPlayers); + std::string dbg = numHandledRequests != 0 ? std::to_string(numHandledRequests) + " players were spawned or set as spectator. " : ""; + dbg += playersStillPickingClass != 0 ? std::to_string(playersStillPickingClass) + " players are still picking class and will be spawned later." : ""; + LOG_DEBUG(dbg.c_str()); } } bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e) { - bool removeRequest = e.Command == "SwapToClassPick" || e.Command == "SwapToTeamPick"; - if (e.Command != "PickTeam" && e.Command != "PickClass" && !removeRequest) { + if (e.Command != "PickTeam" && e.Command != "PickClass" && e.Command != "SwapToTeamPick" && e.Command != "SwapToClassPick") { return false; } @@ -139,28 +143,29 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e) auto iter = m_SpawnRequests.begin(); for (; iter != m_SpawnRequests.end(); ++iter) { if (iter->PlayerID == e.PlayerID) { - // If player wants to switch class, remove their spawn request. - if (removeRequest) { + // If player wants to switch team, remove their spawn request. + if (e.Command == "SwapToTeamPick") { m_SpawnRequests.erase(iter); + } else if (e.Command == "SwapToClassPick") { + // If player wants to switch class, remove their selected class so they don't spawn. + iter->Class = -1; + } else { + break; } - break; + return true; } } - // Return if we were only supposed to remove a request, not add one. - if (removeRequest) { - return true; - } - //If we get here, add or alter a spawn request. + //If we get here we got a PickTeam or PickClass, so add or alter a spawn request. if (iter != m_SpawnRequests.end()) { // If player is in queue to spawn, then change their team affiliation or class in the request. if (e.Command == "PickTeam") { iter->Team = (ComponentInfo::EnumType)e.Value; - LOG_INFO("old request swap Team"); + LOG_DEBUG("old spawn request setting Team"); } else { iter->Class = (ComponentInfo::EnumType)e.Value; - LOG_INFO("old request swap Class"); + LOG_DEBUG("old spawn request setting Class"); } } else if (m_PlayerEntities.count(e.PlayerID) == 0 || !m_PlayerEntities[e.PlayerID].Valid()) { // If player is not in queue to spawn, then create a spawn request, @@ -170,11 +175,13 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e) if (e.Command == "PickTeam") { req.Team = (ComponentInfo::EnumType)e.Value; req.Class = -1; // TODO: -1 Signifies no class picked, enum here later? - LOG_INFO("new request set Team"); + LOG_DEBUG("new spawn request setting Team"); } else { + // Should never get here, since you should have picked a team before you ever get a chance to pick class. + LOG_WARNING("Sequence error: Should not be able to pick class before team"); req.Team = 1; // TODO: 1 Signifies spectator, should probably have real enum here later. req.Class = (ComponentInfo::EnumType)e.Value; - LOG_INFO("new request set Class"); + LOG_DEBUG("new spawn request setting Class"); } m_SpawnRequests.push_back(req); } else {