Class enum instead of hardcoded ints.
Removed superfluous .Valid() checks. Check for spectator spawnrequest in case they somehow has a class, so we don't get "x players were supposed to be spawned but failed" if it happens.
This commit is contained in:
@@ -63,10 +63,9 @@ void PlayerSpawnSystem::Update(double dt)
|
||||
int playersSpectating = 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, or they are a spectator, enum here later?
|
||||
// It is valid if they didn't pick class yet
|
||||
// but don't spawn anything, goto next spawnrequest.
|
||||
if (it->Class == -1) {
|
||||
if (it->Class == PlayerClass::None) {
|
||||
++playersSpectating;
|
||||
continue;
|
||||
}
|
||||
@@ -80,6 +79,11 @@ void PlayerSpawnSystem::Update(double dt)
|
||||
if (spawner.HasComponent("Team")) {
|
||||
auto cSpawnerTeam = spawner["Team"];
|
||||
if ((int)cSpawnerTeam["Team"] != it->Team) {
|
||||
// If they somehow has a valid class as spectator, don't spawn them.
|
||||
if (it->Team == cSpawnerTeam["Team"].Enum("Spectator")) {
|
||||
++playersSpectating;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -136,7 +140,7 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
|
||||
if (iter->PlayerID == e.PlayerID) {
|
||||
// If player wants to switch team or class , remove their selected class so they don't spawn.
|
||||
if (e.Command == "SwapToTeamPick" || e.Command == "SwapToClassPick") {
|
||||
iter->Class = -1;
|
||||
iter->Class = PlayerClass::None;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -150,7 +154,7 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
|
||||
if (e.Command == "PickTeam") {
|
||||
iter->Team = (ComponentInfo::EnumType)e.Value;
|
||||
} else {
|
||||
iter->Class = (ComponentInfo::EnumType)e.Value;
|
||||
iter->Class = static_cast<PlayerClass>(e.Value);
|
||||
}
|
||||
} 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,
|
||||
@@ -159,12 +163,12 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
|
||||
req.PlayerID = e.PlayerID;
|
||||
if (e.Command == "PickTeam") {
|
||||
req.Team = (ComponentInfo::EnumType)e.Value;
|
||||
req.Class = -1; // TODO: -1 Signifies no class picked, enum here later?
|
||||
req.Class = PlayerClass::None;
|
||||
} 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;
|
||||
req.Class = static_cast<PlayerClass>(e.Value);
|
||||
}
|
||||
m_SpawnRequests.push_back(req);
|
||||
} else {
|
||||
@@ -229,10 +233,6 @@ bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
|
||||
return false;
|
||||
}
|
||||
ComponentWrapper cTeam = e.Player["Team"];
|
||||
// A spectator can't die anyway
|
||||
if ((ComponentInfo::EnumType)cTeam["Team"] == cTeam["Team"].Enum("Spectator")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_PlayerIDs.count(e.Player.ID) == 0) {
|
||||
return false;
|
||||
@@ -241,13 +241,15 @@ bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
|
||||
SpawnRequest req;
|
||||
req.PlayerID = m_PlayerIDs.at(e.Player.ID);
|
||||
req.Team = cTeam["Team"];
|
||||
// TODO: Better than temp class state code.
|
||||
// TODO: Something better than temp class state code, if we ever add class enums in .xml
|
||||
if (e.Player.HasComponent("DashAbility")) {
|
||||
req.Class = 1; // Assault
|
||||
req.Class = PlayerClass::Assault;
|
||||
} else if (e.Player.HasComponent("SprintAbility")) {
|
||||
req.Class = 3; // Sniper
|
||||
req.Class = PlayerClass::Sniper;
|
||||
} else if (e.Player.HasComponent("ShieldAbility")) {
|
||||
req.Class = PlayerClass::Defender;
|
||||
} else {
|
||||
req.Class = 2; // Defender
|
||||
req.Class = PlayerClass::None;
|
||||
}
|
||||
m_SpawnRequests.push_back(req);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user