Only set spectator camera if player haven't spawned already. Don't spawn player if they switch to class pick screen.

This commit is contained in:
William Moberg
2016-03-07 15:05:37 +01:00
parent 0dfe00b406
commit 282e0bf7c4
2 changed files with 43 additions and 26 deletions
+30 -23
View File
@@ -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 {