From aebe9a793668189ab2d86a1406f21bb384cb8208 Mon Sep 17 00:00:00 2001 From: Matei Date: Wed, 23 Jul 2008 05:21:57 +0000 Subject: [PATCH] Added active field to players to check whether the player is a human or CPU. This was SVN commit r6267. --- source/ps/GameAttributes.cpp | 39 ++++-------------------------------- source/ps/Player.cpp | 5 ++++- source/ps/Player.h | 6 ++++++ 3 files changed, 14 insertions(+), 36 deletions(-) diff --git a/source/ps/GameAttributes.cpp b/source/ps/GameAttributes.cpp index 4b43c6eb0a..3aa0769eb0 100644 --- a/source/ps/GameAttributes.cpp +++ b/source/ps/GameAttributes.cpp @@ -351,45 +351,14 @@ CPlayerSlot *CGameAttributes::GetSlot(size_t index) void CGameAttributes::FinalizeSlots() { - // This method was causing players to be mis-assigned, partly because the - // slot status changes did not seem to get broadcasted correctly. However, - // fundamentally, we really don't want to reassign players' IDs this way. - // We want to keep around dummy players for those that aren't human. So - // let's not mess with the array indices, etc unless it is really needed. - return; - - /* - // Back up our old slots, and empty the resulting std::vector - std::vector oldSlots; - oldSlots.swap(m_PlayerSlots); - std::vector oldPlayers; - oldPlayers.swap(m_Players); - m_Players.push_back(oldPlayers[0]); // Gaia - - // Copy over the slots we want - size_t assignedSlots=0; - for (size_t i=0;iGetAssignment(); + for (size_t i=0; iGetAssignment(); if (assignment != SLOT_OPEN && assignment != SLOT_CLOSED) { - m_PlayerSlots.push_back(slot); - slot->GetPlayer()->SetPlayerID(assignedSlots+1); - m_Players.push_back(slot->GetPlayer()); - - assignedSlots++; - } - else - { - LOG(CLogger::Error, "", "CGameAttributes::FinalizeSlots(): slot %d deleted", i); - delete slot->GetPlayer(); - delete slot; + slot->GetPlayer()->SetActive(true); } } - - m_NumSlots=assignedSlots; - */ } void CGameAttributes::SetValue(const CStrW& name, const CStrW& value) diff --git a/source/ps/Player.cpp b/source/ps/Player.cpp index bf0ab29b67..5ab936a111 100644 --- a/source/ps/Player.cpp +++ b/source/ps/Player.cpp @@ -12,7 +12,8 @@ CPlayer::CPlayer(size_t playerID): m_Name(CStrW(L"Player #")+CStrW((unsigned)playerID)), m_Civilization(L""), m_Colour(0.7f, 0.7f, 0.7f), - m_UpdateCB(0) + m_UpdateCB(0), + m_Active(false) { m_LOSToken = LOS_GetTokenFor(playerID); @@ -73,6 +74,8 @@ void CPlayer::ScriptingInit() AddMethod("getDiplomaticStance", 1); AddProperty( L"id", &CPlayer::m_PlayerID, true ); + AddProperty( L"active", &CPlayer::m_Active, true ); + AddProperty( L"name", &CPlayer::m_Name, true ); // MT: Work out how this fits with the Synched stuff... // AddClassProperty( L"name", &CPlayer::m_Name ); diff --git a/source/ps/Player.h b/source/ps/Player.h index 7c1651ca81..ae10760213 100644 --- a/source/ps/Player.h +++ b/source/ps/Player.h @@ -36,6 +36,7 @@ private: SPlayerColour m_Colour; int /*EDiplomaticStance*/ m_DiplomaticStance[PS_MAX_PLAYERS+1]; std::vector m_ActiveTechs; + bool m_Active; // Is this an active player, or a dummy? UpdateCallback *m_UpdateCB; void *m_UpdateCBData; @@ -88,6 +89,11 @@ public: return m_ActiveTechs; } + inline bool IsActive() const + { return m_Active; } + inline void SetActive(bool active) + { m_Active = active; } + void GetControlledEntities(std::vector& controlled_entities); // JS Interface Functions