OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ClientPlayerInfos Class Reference

#include <C4PlayerInfo.h>

Public Member Functions

 C4ClientPlayerInfos (const char *szJoinFilenames=nullptr, bool fAdd=false, C4PlayerInfo *pAddInfo=nullptr)
 
 C4ClientPlayerInfos (const C4ClientPlayerInfos &rCopy)
 
 ~C4ClientPlayerInfos ()
 
C4ClientPlayerInfosoperator= (const C4ClientPlayerInfos &rCopy)
 
void Clear ()
 
void GrabMergeFrom (C4ClientPlayerInfos &rFrom)
 
void AddInfo (C4PlayerInfo *pAddInfo)
 
void RemoveIndexedInfo (int32_t iAtIndex)
 
void RemoveInfo (int32_t idPlr)
 
void SetUpdated ()
 
bool IsUpdated ()
 
void ResetUpdated ()
 
void SetAdd ()
 
void ResetAdd ()
 
int32_t GetPlayerCount () const
 
int32_t GetFlaggedPlayerCount (DWORD dwFlag) const
 
C4PlayerInfoGetPlayerInfo (int32_t iIndex) const
 
C4PlayerInfoGetPlayerInfo (int32_t iIndex, C4PlayerType eType) const
 
C4PlayerInfoGetPlayerInfoByID (int32_t id) const
 
C4PlayerInfoGetPlayerInfoByRes (int32_t idResID) const
 
int32_t GetClientID () const
 
bool HasUnjoinedPlayers () const
 
int32_t GetJoinedPlayerCount () const
 
bool IsAddPacket () const
 
bool IsInitialPacket () const
 
bool IsDeveloperPacket () const
 
void LoadResources ()
 
void CompileFunc (StdCompiler *pComp)
 

Detailed Description

Definition at line 211 of file C4PlayerInfo.h.

Constructor & Destructor Documentation

C4ClientPlayerInfos::C4ClientPlayerInfos ( const char *  szJoinFilenames = nullptr,
bool  fAdd = false,
C4PlayerInfo pAddInfo = nullptr 
)

Definition at line 375 of file C4PlayerInfo.cpp.

References _MAX_PATH, C4GameControl::ClientID(), Config, Control, FormatString(), C4Config::GetRegistrationData(), C4GameControl::isNetwork(), C4PlayerInfo::LoadFromLocalFile(), LoadResStr(), Log(), SGetModule(), SModuleCount(), and SSearch().

376  : iPlayerCount(0), iPlayerCapacity(0), ppPlayers(nullptr), iClientID(-1), dwFlags(0)
377 {
378  // init for local client?
379  if (szJoinFilenames || pAddInfo)
380  {
381  // set developer flag for developer hosts
382  if (SSearch(Config.GetRegistrationData("Type"), "Developer"))
383  dwFlags |= CIF_Developer;
384  // set local ID
385  iClientID = ::Control.ClientID();
386  // maybe control is not preinitialized
387  if (!::Control.isNetwork() && iClientID < 0) iClientID = 0;
388  // join packet or initial packet?
389  if (fAdd)
390  // packet is to be added to other players
391  dwFlags |= CIF_AddPlayers;
392  else
393  // set initial flag for first-time join packet
394  dwFlags |= CIF_Initial;
395  // join all players in list
396  if ((iPlayerCapacity = (szJoinFilenames ? SModuleCount(szJoinFilenames) : 0) + !!pAddInfo))
397  {
398  ppPlayers = new C4PlayerInfo *[iPlayerCapacity];
399  if (szJoinFilenames)
400  {
401  char szPlrFile[_MAX_PATH+1];
402  for (int32_t i=0; i<iPlayerCapacity; ++i)
403  if (SGetModule(szJoinFilenames, i, szPlrFile, _MAX_PATH))
404  {
405  C4PlayerInfo *pNewInfo = new C4PlayerInfo();
406  if (pNewInfo->LoadFromLocalFile(szPlrFile))
407  {
408  // player def loaded; register and count it
409  ppPlayers[iPlayerCount++] = pNewInfo;
410  }
411  else
412  {
413  // loading failure; clear info class
414  delete pNewInfo;
415  //
416  Log(FormatString(LoadResStr("IDS_ERR_LOAD_PLAYER"), szPlrFile).getData());
417  }
418  }
419  }
420  if (pAddInfo)
421  ppPlayers[iPlayerCount++] = pAddInfo;
422  }
423  }
424 }
bool SGetModule(const char *szList, int iIndex, char *sTarget, int iSize)
Definition: Standard.cpp:510
C4Config Config
Definition: C4Config.cpp:837
const char * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:340
#define _MAX_PATH
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
const char * GetRegistrationData(const char *strField)
Definition: C4Config.h:282
bool isNetwork() const
Definition: C4GameControl.h:97
C4GameControl Control
int SModuleCount(const char *szList)
Definition: Standard.cpp:588
int32_t ClientID() const
bool LoadFromLocalFile(const char *szFilename)
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

Here is the call graph for this function:

C4ClientPlayerInfos::C4ClientPlayerInfos ( const C4ClientPlayerInfos rCopy)

Definition at line 426 of file C4PlayerInfo.cpp.

427 {
428  // copy fields
429  iClientID = rCopy.iClientID;
430  if ((iPlayerCount = rCopy.iPlayerCount))
431  {
432  // copy player infos
433  ppPlayers = new C4PlayerInfo *[iPlayerCapacity = rCopy.iPlayerCapacity];
434  int32_t i = iPlayerCount;
435  C4PlayerInfo **ppCurrPlrInfo = ppPlayers, **ppSrcPlrInfo = rCopy.ppPlayers;
436  while (i--) *ppCurrPlrInfo++ = new C4PlayerInfo(**ppSrcPlrInfo++);
437  }
438  // no players
439  else
440  {
441  ppPlayers = nullptr;
442  iPlayerCapacity = 0;
443  }
444  // misc fields
445  dwFlags = rCopy.dwFlags;
446 }
C4ClientPlayerInfos::~C4ClientPlayerInfos ( )
inline

Definition at line 236 of file C4PlayerInfo.h.

References Clear().

236 { Clear(); } // dtor

Here is the call graph for this function:

Member Function Documentation

void C4ClientPlayerInfos::AddInfo ( C4PlayerInfo pAddInfo)

Definition at line 512 of file C4PlayerInfo.cpp.

Referenced by C4PlayerInfoList::CreateRestoreInfosForJoinedScriptPlayers().

513 {
514  // grow list if necessary
515  if (iPlayerCount == iPlayerCapacity) GrowList(4);
516  // add info
517  ppPlayers[iPlayerCount++] = pAddInfo;
518 }

Here is the caller graph for this function:

void C4ClientPlayerInfos::Clear ( )

Definition at line 473 of file C4PlayerInfo.cpp.

Referenced by CompileFunc(), operator=(), and ~C4ClientPlayerInfos().

474 {
475  // del player infos
476  int32_t i = iPlayerCount; C4PlayerInfo **ppCurrPlrInfo = ppPlayers;
477  while (i--) delete *ppCurrPlrInfo++;
478  // del player info vector
479  delete [] ppPlayers; ppPlayers = nullptr;
480  // reset other fields
481  iPlayerCount = iPlayerCapacity = 0;
482  iClientID=-1;
483  dwFlags = 0;
484 }

Here is the caller graph for this function:

void C4ClientPlayerInfos::CompileFunc ( StdCompiler pComp)

Definition at line 640 of file C4PlayerInfo.cpp.

References C4ClientIDUnknown, C4MaxPlayer, Clear(), StdCompiler::excCorrupt(), StdCompiler::isDeserializer(), mkArrayAdaptMap(), mkBitfieldAdapt(), mkNamingAdapt(), StdCompiler::Value(), and ZeroMem().

641 {
642  bool deserializing = pComp->isDeserializer();
643  if (deserializing) Clear();
644  pComp->Value(mkNamingAdapt(iClientID, "ID", C4ClientIDUnknown));
645 
646  // Flags
647  StdBitfieldEntry<uint32_t> Entries[] =
648  {
649  { "AddPlayers", CIF_AddPlayers },
650  { "Updated", CIF_Updated },
651  { "Initial", CIF_Initial },
652  { "Developer", CIF_Developer },
653 
654  { nullptr, 0 }
655  };
656  pComp->Value(mkNamingAdapt(mkBitfieldAdapt(dwFlags, Entries), "Flags", 0u));
657 
658  pComp->Value(mkNamingCountAdapt<int32_t>(iPlayerCount, "Player"));
659  if (iPlayerCount < 0 || iPlayerCount > C4MaxPlayer)
660  { pComp->excCorrupt("player count out of range"); return; }
661  // Grow list, if necessary
662  if (deserializing && iPlayerCount > iPlayerCapacity)
663  {
664  GrowList(iPlayerCount - iPlayerCapacity);
665  ZeroMem(ppPlayers, sizeof(*ppPlayers) * iPlayerCount);
666  }
667  // Compile
668  pComp->Value(mkNamingAdapt(mkArrayAdaptMap(ppPlayers, iPlayerCount, mkPtrAdaptNoNull<C4PlayerInfo>), "Player"));
669  // Force specialization
670  mkPtrAdaptNoNull<C4PlayerInfo>(*ppPlayers);
671 }
Definition: StdAdaptors.h:851
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:259
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
StdBitfieldAdapt< T > mkBitfieldAdapt(T &rVal, const StdBitfieldEntry< T > *pNames)
Definition: StdAdaptors.h:954
void Value(const T &rStruct)
Definition: StdCompiler.h:171
const int32_t C4ClientIDUnknown
Definition: C4Client.h:24
const int32_t C4MaxPlayer
Definition: C4Player.h:39
virtual bool isDeserializer()
Definition: StdCompiler.h:63
std::enable_if< std::is_pod< T >::value >::type ZeroMem(T *lpMem, size_t dwSize)
Definition: Standard.h:63
StdArrayAdapt< T, M > mkArrayAdaptMap(T *pArray, int iSize, M &&map)
Definition: StdAdaptors.h:314

Here is the call graph for this function:

int32_t C4ClientPlayerInfos::GetClientID ( ) const
inline

Definition at line 260 of file C4PlayerInfo.h.

Referenced by C4PlayerInfoList::AddInfo(), C4PlayerInfoList::GetActivePlayerNames(), C4Network2Players::GetLocalPlayerInfoPacket(), C4PlayerInfoList::GetPlayerInfoByID(), C4Network2Players::OnStatusGoReached(), C4MessageInput::ProcessCommand(), C4PlayerInfoList::RecreatePlayers(), and C4PlayerInfoList::SetAsRestoreInfos().

260 { return iClientID; } // get target client ID

Here is the caller graph for this function:

int32_t C4ClientPlayerInfos::GetFlaggedPlayerCount ( DWORD  dwFlag) const

Definition at line 561 of file C4PlayerInfo.cpp.

562 {
563  // check all players
564  int32_t iCount = 0;
565  int32_t i = iPlayerCount; C4PlayerInfo **ppCurrPlrInfo = ppPlayers;
566  while (i--) if ((*ppCurrPlrInfo++)->GetFlags() | dwFlag)
567  ++iCount;
568  // return number of matching infos
569  return iCount;
570 }
int32_t C4ClientPlayerInfos::GetJoinedPlayerCount ( ) const

Definition at line 632 of file C4PlayerInfo.cpp.

Referenced by C4Network2::OpenVoteDialog(), and C4PlayerInfoList::RecreatePlayers().

633 {
634  // count all players with IsJoined()
635  int32_t i = iPlayerCount; int32_t cnt=0; C4PlayerInfo **ppCurrPlrInfo = ppPlayers;
636  while (i--) if ((*ppCurrPlrInfo++)->IsJoined()) ++cnt;
637  return cnt;
638 }

Here is the caller graph for this function:

int32_t C4ClientPlayerInfos::GetPlayerCount ( ) const
inline

Definition at line 254 of file C4PlayerInfo.h.

Referenced by C4PlayerInfoList::AssignPlayerIDs(), C4PlayerInfoList::GetActivePlayerCount(), C4PlayerInfoList::GetActivePlayerNames(), C4PlayerInfoList::GetActiveScriptPlayerCount(), C4PlayerInfoList::GetJoinIssuedPlayerCount(), C4PlayerInfoList::GetJoinPendingPlayerCount(), C4Network2Players::JoinLocalPlayer(), C4Network2::OpenVoteDialog(), C4PlayerInfoList::RecreatePlayers(), and C4PlayerInfoList::SetAsRestoreInfos().

254 { return iPlayerCount; } // get number of player infos available

Here is the caller graph for this function:

C4PlayerInfo * C4ClientPlayerInfos::GetPlayerInfo ( int32_t  iIndex,
C4PlayerType  eType 
) const

Definition at line 580 of file C4PlayerInfo.cpp.

References C4PlayerInfo::GetType().

581 {
582  // get indexed matching info
583  for (int32_t iCheck=0; iCheck<iPlayerCount; ++iCheck)
584  {
585  C4PlayerInfo *pNfo = ppPlayers[iCheck];
586  if (pNfo->GetType() == eType)
587  if (!iIndex--)
588  return pNfo;
589  }
590  // nothing found
591  return nullptr;
592 }
C4PlayerType GetType() const
Definition: C4PlayerInfo.h:155

Here is the call graph for this function:

C4PlayerInfo * C4ClientPlayerInfos::GetPlayerInfoByID ( int32_t  id) const

Definition at line 594 of file C4PlayerInfo.cpp.

Referenced by C4MessageInput::ProcessCommand().

595 {
596  // check all infos
597  int32_t i = iPlayerCount; C4PlayerInfo **ppCurrPlrInfo = ppPlayers;
598  while (i--)
599  {
600  if ((*ppCurrPlrInfo)->GetID() == id) return *ppCurrPlrInfo;
601  ++ppCurrPlrInfo;
602  }
603  // none matched
604  return nullptr;
605 }

Here is the caller graph for this function:

C4PlayerInfo * C4ClientPlayerInfos::GetPlayerInfoByRes ( int32_t  idResID) const

Definition at line 607 of file C4PlayerInfo.cpp.

References C4Network2Res::getResID().

Referenced by C4Network2Players::HandlePlayerInfoUpdRequest().

608 {
609  int32_t i = iPlayerCount; C4PlayerInfo **ppCurrPlrInfo = ppPlayers;
610  C4Network2Res *pRes;
611  while (i--)
612  {
613  if ((pRes = (*ppCurrPlrInfo)->GetRes()))
614  if (pRes->getResID() == idResID)
615  // only if the player is actually using the resource
616  if ((*ppCurrPlrInfo)->IsUsingPlayerFile())
617  return *ppCurrPlrInfo;
618  ++ppCurrPlrInfo;
619  }
620  return nullptr;
621 }
int32_t getResID() const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ClientPlayerInfos::GrabMergeFrom ( C4ClientPlayerInfos rFrom)

Definition at line 486 of file C4PlayerInfo.cpp.

Referenced by C4PlayerInfoList::AddInfo().

487 {
488  // anything to grab?
489  if (!rFrom.iPlayerCount) return;
490  // any previous players to copy?
491  if (iPlayerCount)
492  {
493  // buffer sufficient?
494  if (iPlayerCount + rFrom.iPlayerCount > iPlayerCapacity)
495  GrowList(rFrom.iPlayerCount);
496  // merge into new buffer
497  memcpy(ppPlayers + iPlayerCount, rFrom.ppPlayers, rFrom.iPlayerCount * sizeof(C4PlayerInfo *));
498  iPlayerCount += rFrom.iPlayerCount;
499  rFrom.iPlayerCount = rFrom.iPlayerCapacity = 0;
500  delete [] rFrom.ppPlayers; rFrom.ppPlayers = nullptr;
501  }
502  else
503  {
504  // no own players: take over buffer of pFrom
505  if (ppPlayers) delete [] ppPlayers;
506  ppPlayers = rFrom.ppPlayers; rFrom.ppPlayers = nullptr;
507  iPlayerCount = rFrom.iPlayerCount; rFrom.iPlayerCount = 0;
508  iPlayerCapacity = rFrom.iPlayerCapacity; rFrom.iPlayerCapacity = 0;
509  }
510 }

Here is the caller graph for this function:

bool C4ClientPlayerInfos::HasUnjoinedPlayers ( ) const

Definition at line 623 of file C4PlayerInfo.cpp.

Referenced by C4Network2Players::OnStatusGoReached().

624 {
625  // check all players
626  int32_t i = iPlayerCount; C4PlayerInfo **ppCurrPlrInfo = ppPlayers;
627  while (i--) if (!(*ppCurrPlrInfo++)->HasJoined()) return true;
628  // all joined
629  return false;
630 }

Here is the caller graph for this function:

bool C4ClientPlayerInfos::IsAddPacket ( ) const
inline

Definition at line 263 of file C4PlayerInfo.h.

Referenced by C4PlayerInfoList::AddInfo().

263 { return !!(dwFlags & CIF_AddPlayers); } // return whether players are to be added to the current list (otherwise overwrite)

Here is the caller graph for this function:

bool C4ClientPlayerInfos::IsDeveloperPacket ( ) const
inline

Definition at line 265 of file C4PlayerInfo.h.

265 { return !!(dwFlags & CIF_Developer); } // returns whether packet was created by a developer host - client side check only!
bool C4ClientPlayerInfos::IsInitialPacket ( ) const
inline

Definition at line 264 of file C4PlayerInfo.h.

264 { return !!(dwFlags & CIF_Initial); } // returns whether this packet was sent as the first local-join packet
bool C4ClientPlayerInfos::IsUpdated ( )
inline

Definition at line 248 of file C4PlayerInfo.h.

Referenced by C4Network2Players::SendUpdatedPlayers().

248 { return !!(dwFlags & CIF_Updated); }

Here is the caller graph for this function:

void C4ClientPlayerInfos::LoadResources ( )

Definition at line 673 of file C4PlayerInfo.cpp.

674 {
675  // load for all players
676  int32_t i = iPlayerCount; C4PlayerInfo **ppCurrPlrInfo = ppPlayers;
677  while (i--) (*ppCurrPlrInfo++)->LoadResource();
678 }
C4ClientPlayerInfos & C4ClientPlayerInfos::operator= ( const C4ClientPlayerInfos rCopy)

Definition at line 448 of file C4PlayerInfo.cpp.

References Clear().

449 {
450  Clear();
451  // copy fields
452  iClientID = rCopy.iClientID;
453  if ((iPlayerCount = rCopy.iPlayerCount))
454  {
455  // copy player infos
456  ppPlayers = new C4PlayerInfo *[iPlayerCapacity = rCopy.iPlayerCapacity];
457  int32_t i = iPlayerCount;
458  C4PlayerInfo **ppCurrPlrInfo = ppPlayers, **ppSrcPlrInfo = rCopy.ppPlayers;
459  while (i--) *ppCurrPlrInfo++ = new C4PlayerInfo(**ppSrcPlrInfo++);
460  }
461  // no players
462  else
463  {
464  ppPlayers = nullptr;
465  iPlayerCapacity = 0;
466  }
467  // misc fields
468  dwFlags = rCopy.dwFlags;
469  return *this;
470 }

Here is the call graph for this function:

void C4ClientPlayerInfos::RemoveIndexedInfo ( int32_t  iAtIndex)

Definition at line 520 of file C4PlayerInfo.cpp.

Referenced by C4PlayerInfoList::AssignPlayerIDs(), RemoveInfo(), and C4PlayerInfoList::SetAsRestoreInfos().

521 {
522  // bounds check
523  if (iAtIndex<0 || iAtIndex>=iPlayerCount) return;
524  // del player info at index
525  delete ppPlayers[iAtIndex];
526  // move down last index (may self-assign a ptr)
527  ppPlayers[iAtIndex] = ppPlayers[--iPlayerCount];
528 }

Here is the caller graph for this function:

void C4ClientPlayerInfos::RemoveInfo ( int32_t  idPlr)

Definition at line 530 of file C4PlayerInfo.cpp.

References RemoveIndexedInfo().

531 {
532  // check all infos; remove the one that matches
533  int32_t i = 0; C4PlayerInfo **ppCurrPlrInfo = ppPlayers;
534  while (i < iPlayerCount)
535  {
536  if ((*ppCurrPlrInfo)->GetID() == idPlr)
537  {
539  return;
540  }
541  ++ppCurrPlrInfo; ++i;
542  }
543  // none matched
544  return;
545 }
void RemoveIndexedInfo(int32_t iAtIndex)

Here is the call graph for this function:

void C4ClientPlayerInfos::ResetAdd ( )
inline

Definition at line 251 of file C4PlayerInfo.h.

Referenced by C4PlayerInfoList::AddInfo().

251 { dwFlags &= ~CIF_AddPlayers; }

Here is the caller graph for this function:

void C4ClientPlayerInfos::ResetUpdated ( )
inline

Definition at line 249 of file C4PlayerInfo.h.

Referenced by C4Network2Players::ResetUpdatedPlayers(), and C4Network2Players::SendUpdatedPlayers().

249 { dwFlags &= ~CIF_Updated; }

Here is the caller graph for this function:

void C4ClientPlayerInfos::SetAdd ( )
inline

Definition at line 250 of file C4PlayerInfo.h.

250 { dwFlags |= CIF_AddPlayers; }
void C4ClientPlayerInfos::SetUpdated ( )
inline

Definition at line 247 of file C4PlayerInfo.h.

Referenced by C4Network2::LeagueUpdateProcessReply(), C4TeamList::ReassignAllTeams(), C4TeamList::RecheckTeams(), C4PlayerInfoList::ResetLeagueProjectedGain(), and C4PlayerInfoList::UpdatePlayerAttributes().

247 { dwFlags |= CIF_Updated; }

Here is the caller graph for this function:


The documentation for this class was generated from the following files: