1
0
forked from 0ad/0ad

Added active field to players to check whether the player is a human or CPU.

This was SVN commit r6267.
This commit is contained in:
Matei 2008-07-23 05:21:57 +00:00
parent 95f3036e74
commit aebe9a7936
3 changed files with 14 additions and 36 deletions

View File

@ -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<CPlayerSlot *> oldSlots;
oldSlots.swap(m_PlayerSlots);
std::vector<CPlayer *> 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;i<oldSlots.size();i++)
{
CPlayerSlot *slot=oldSlots[i];
EPlayerSlotAssignment assignment=slot->GetAssignment();
for (size_t i=0; i<m_PlayerSlots.size(); i++) {
CPlayerSlot *slot = m_PlayerSlots[i];
EPlayerSlotAssignment assignment = slot->GetAssignment();
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)

View File

@ -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<jsval_t, &CPlayer::JSI_GetDiplomaticStance>("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 );

View File

@ -36,6 +36,7 @@ private:
SPlayerColour m_Colour;
int /*EDiplomaticStance*/ m_DiplomaticStance[PS_MAX_PLAYERS+1];
std::vector<CTechnology*> 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<HEntity>& controlled_entities);
// JS Interface Functions