OpenClonk
C4PlayerList Class Reference

#include <C4PlayerList.h>

Collaboration diagram for C4PlayerList:
[legend]

Public Member Functions

 C4PlayerList ()
 
 ~C4PlayerList ()
 
void Default ()
 
void Clear ()
 
void Execute ()
 
void DenumeratePointers ()
 
void ClearPointers (C4Object *pObj)
 
int GetCount () const
 
int GetCount (C4PlayerType eType) const
 
int GetIndex (C4Player *pPlr) const
 
int GetCountNotEliminated () const
 
int AverageScoreGain () const
 
C4PlayerGet (int iPlayer) const
 
C4PlayerGetByIndex (int iIndex) const
 
C4PlayerGetByIndex (int iIndex, C4PlayerType eType) const
 
C4PlayerGetByName (const char *szName, int iExcluding=NO_OWNER) const
 
C4PlayerGetLocalByIndex (int iIndex) const
 
C4PlayerGetAtClient (int iClient, int iIndex=0) const
 
C4PlayerGetAtClient (const char *szName, int iIndex=0) const
 
C4PlayerGetAtRemoteClient (int iIndex=0) const
 
C4PlayerGetByInfoID (int iInfoID) const
 
C4PlayerJoin (const char *szFilename, bool fScenarioInit, int iAtClient, const char *szAtClientName, class C4PlayerInfo *pInfo, C4ValueNumbers *)
 
void JoinNew (const char *szFilename)
 
bool CtrlJoin (const class C4Network2ResCore &ResCore, int iClientID, int idPlayerInfo)
 
bool FileInUse (const char *szFilename) const
 
bool Retire (C4Player *pPlr)
 
bool Evaluate ()
 
bool Save (bool fSaveLocalOnly)
 
bool Save (C4Group &hGroup, bool fStoreTiny, const C4PlayerInfoList &rStoreList)
 
bool Remove (int iPlayer, bool fDisonnected, bool fNoCalls)
 
bool RemoveUnjoined (int32_t iPlayer)
 
bool Remove (C4Player *pPlr, bool fDisonnected, bool fNoCalls)
 
bool RemoveAtRemoteClient (bool fDisonnected, bool fNoCalls)
 
bool RemoveLocal (bool fDisonnected, bool fNoCalls)
 
bool MouseControlTaken () const
 
bool RemoveAtClient (int iClient, bool fDisconnect)
 
bool RemoveAtClient (const char *szName, bool fDisconnect)
 
bool CtrlRemove (int iPlayer, bool fDisonnected)
 
bool CtrlRemoveAtClient (int iClient, bool fDisonnected)
 
bool CtrlRemoveAtClient (const char *szName, bool fDisonnected)
 
bool Valid (int iPlayer) const
 
bool Hostile (int iPlayer1, int iPlayer2) const
 
bool HostilityDeclared (int iPlayer1, int iPlayer2) const
 
bool PositionTaken (int iPosition) const
 
int CheckColorDw (DWORD dwColor, C4Player *pExclude)
 
bool SynchronizeLocalFiles ()
 
bool HasPlayerInTeamSelection ()
 

Public Attributes

C4PlayerFirst
 

Protected Member Functions

int GetFreeNumber () const
 
void RecheckPlayerSort (C4Player *pForPlayer)
 

Friends

class C4Player
 

Detailed Description

Definition at line 25 of file C4PlayerList.h.

Constructor & Destructor Documentation

◆ C4PlayerList()

C4PlayerList::C4PlayerList ( )

Definition at line 35 of file C4PlayerList.cpp.

36 {
37  Default();
38 }

References Default().

Here is the call graph for this function:

◆ ~C4PlayerList()

C4PlayerList::~C4PlayerList ( )

Definition at line 40 of file C4PlayerList.cpp.

41 {
42  Clear();
43 }

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ AverageScoreGain()

int C4PlayerList::AverageScoreGain ( ) const

Definition at line 408 of file C4PlayerList.cpp.

409 {
410  int iResult=0;
411  if (First)
412  {
413  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
414  iResult+=std::max<int32_t>(pPlr->CurrentScore-pPlr->InitialScore,0);
415  iResult/=GetCount();
416  }
417  return iResult;
418 }
int iResult
Definition: C4GroupMain.cpp:40
C4Player * Next
Definition: C4Player.h:142
C4Player * First
Definition: C4PlayerList.h:31
int GetCount() const

References First, GetCount(), iResult, and C4Player::Next.

Referenced by C4Player::Evaluate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckColorDw()

int C4PlayerList::CheckColorDw ( DWORD  dwColor,
C4Player pExclude 
)

Definition at line 116 of file C4PlayerList.cpp.

117 {
118  // maximum difference
119  int iDiff=255+255+255;
120  // check all player's color difference
121  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next) if (pPlr != pExclude)
122  {
123  // get color
124  DWORD dwClr2=pPlr->ColorDw;
125  // assign difference, if less than smallest difference found
126  iDiff=std::min(iDiff,
127  Abs(GetBlueValue(dwColor) - GetBlueValue(dwClr2))
128  + Abs(GetGreenValue(dwColor) - GetGreenValue(dwClr2))
129  + Abs(GetRedValue(dwColor) - GetRedValue(dwClr2)));
130  }
131  // return the difference
132  return iDiff;
133 }
uint32_t DWORD
T Abs(T val)
Definition: Standard.h:42
#define GetRedValue(rgb)
Definition: StdColors.h:29
#define GetGreenValue(rgb)
Definition: StdColors.h:28
#define GetBlueValue(rgb)
Definition: StdColors.h:27

References Abs(), First, GetBlueValue, GetGreenValue, GetRedValue, and C4Player::Next.

Here is the call graph for this function:

◆ Clear()

void C4PlayerList::Clear ( )

Definition at line 50 of file C4PlayerList.cpp.

51 {
52  C4Player *pPlr;
53  while ((pPlr = First))
54  { First = pPlr->Next; delete pPlr; }
55  First = nullptr;
56 }

References First, and C4Player::Next.

Referenced by C4Game::Clear(), and ~C4PlayerList().

Here is the caller graph for this function:

◆ ClearPointers()

void C4PlayerList::ClearPointers ( C4Object pObj)

Definition at line 70 of file C4PlayerList.cpp.

71 {
72  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
73  pPlr->ClearPointers(pObj, false);
74 }

References First, and C4Player::Next.

Referenced by C4Game::ClearPointers(), and C4Object::GrabInfo().

Here is the caller graph for this function:

◆ CtrlJoin()

bool C4PlayerList::CtrlJoin ( const class C4Network2ResCore ResCore,
int  iClientID,
int  idPlayerInfo 
)

◆ CtrlRemove()

bool C4PlayerList::CtrlRemove ( int  iPlayer,
bool  fDisonnected 
)

Definition at line 490 of file C4PlayerList.cpp.

491 {
492  // Add packet to input
493  Game.Input.Add(CID_RemovePlr, new C4ControlRemovePlr(iPlayer, fDisconnect));
494  return true;
495 }
C4Game Game
Definition: C4Globals.cpp:52
@ CID_RemovePlr
Definition: C4PacketBase.h:160
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
Definition: C4Control.h:82
C4Control & Input
Definition: C4Game.h:82

References C4Control::Add(), CID_RemovePlr, Game, and C4Game::Input.

Referenced by CtrlRemoveAtClient().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CtrlRemoveAtClient() [1/2]

bool C4PlayerList::CtrlRemoveAtClient ( const char *  szName,
bool  fDisonnected 
)

Definition at line 507 of file C4PlayerList.cpp.

508 {
509  // Get players
510  for (C4Player *pPlr = First; pPlr; pPlr = pPlr->Next)
511  if (SEqual(pPlr->AtClientName, szName))
512  if (!CtrlRemove(pPlr->Number, fDisconnect))
513  return false;
514  return true;
515 }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
bool CtrlRemove(int iPlayer, bool fDisonnected)

References CtrlRemove(), First, C4Player::Next, and SEqual().

Here is the call graph for this function:

◆ CtrlRemoveAtClient() [2/2]

bool C4PlayerList::CtrlRemoveAtClient ( int  iClient,
bool  fDisonnected 
)

Definition at line 497 of file C4PlayerList.cpp.

498 {
499  // Get players
500  for (C4Player *pPlr = First; pPlr; pPlr = pPlr->Next)
501  if (pPlr->AtClient == iClient)
502  if (!CtrlRemove(pPlr->Number, fDisconnect))
503  return false;
504  return true;
505 }

References CtrlRemove(), First, and C4Player::Next.

Here is the call graph for this function:

◆ Default()

void C4PlayerList::Default ( )

Definition at line 45 of file C4PlayerList.cpp.

46 {
47  First=nullptr;
48 }

References First.

Referenced by C4PlayerList(), and C4Game::Default().

Here is the caller graph for this function:

◆ DenumeratePointers()

void C4PlayerList::DenumeratePointers ( )

Definition at line 586 of file C4PlayerList.cpp.

587 {
588  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
589  pPlr->DenumeratePointers();
590 }

References First, and C4Player::Next.

◆ Evaluate()

bool C4PlayerList::Evaluate ( )

Definition at line 387 of file C4PlayerList.cpp.

388 {
389  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
390  pPlr->Evaluate();
391  return true;
392 }

References First, and C4Player::Next.

Referenced by C4Game::Evaluate().

Here is the caller graph for this function:

◆ Execute()

void C4PlayerList::Execute ( )

Definition at line 58 of file C4PlayerList.cpp.

59 {
60  C4Player *pPlr;
61  // Execute
62  for (pPlr=First; pPlr; pPlr=pPlr->Next)
63  pPlr->Execute();
64  // Check retirement
65  for (pPlr=First; pPlr; pPlr=pPlr->Next)
66  if (pPlr->Eliminated && !pPlr->RetireDelay)
67  { Retire(pPlr); break; }
68 }
int32_t Eliminated
Definition: C4Player.h:83
int32_t RetireDelay
Definition: C4Player.h:95
void Execute()
Definition: C4Player.cpp:162
bool Retire(C4Player *pPlr)

References C4Player::Eliminated, C4Player::Execute(), First, C4Player::Next, Retire(), and C4Player::RetireDelay.

Referenced by C4Game::Execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FileInUse()

bool C4PlayerList::FileInUse ( const char *  szFilename) const

Definition at line 429 of file C4PlayerList.cpp.

430 {
431  // Check original player files
432  C4Player *cPlr=First;
433  for (; cPlr; cPlr=cPlr->Next)
434  if (ItemIdentical(cPlr->Filename,szFilename))
435  return true;
436  // Compare to any network path player files with prefix (hack)
437  if (::Network.isEnabled())
438  {
439  char szWithPrefix[_MAX_PATH_LEN];
440  SCopy(GetFilename(szFilename),szWithPrefix);
441  SetClientPrefix(szWithPrefix, Game.Clients.getLocalName());
442  for (cPlr=First; cPlr; cPlr=cPlr->Next)
443  if (SEqualNoCase(GetFilename(cPlr->Filename),szWithPrefix))
444  return true;
445  }
446  // Not in use
447  return false;
448 }
C4Network2 Network
Definition: C4Globals.cpp:53
void SetClientPrefix(char *szFilename, const char *szClient)
#define _MAX_PATH_LEN
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:213
bool ItemIdentical(const char *szFilename1, const char *szFilename2)
Definition: StdFile.cpp:879
char * GetFilename(char *szPath)
Definition: StdFile.cpp:42
const char * getLocalName() const
Definition: C4Client.h:170
C4ClientList & Clients
Definition: C4Game.h:69
bool isEnabled() const
Definition: C4Network2.h:203
char Filename[_MAX_PATH_LEN]
Definition: C4Player.h:80

References _MAX_PATH_LEN, C4Game::Clients, C4Player::Filename, First, Game, GetFilename(), C4ClientList::getLocalName(), C4Network2::isEnabled(), ItemIdentical(), Network, C4Player::Next, SCopy(), SEqualNoCase(), and SetClientPrefix().

Referenced by C4MainMenu::ActivateNewPlayer(), and Join().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get()

C4Player * C4PlayerList::Get ( int  iPlayer) const

Definition at line 135 of file C4PlayerList.cpp.

136 {
137  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
138  if (pPlr->Number==iNumber)
139  return pPlr;
140  return nullptr;
141 }

References First, and C4Player::Next.

Referenced by C4MainMenu::ActivateMain(), C4Viewport::AdjustPosition(), C4Object::AssignDeath(), C4Object::AssignInfo(), C4MouseControl::ButtonUpDragScript(), C4Viewport::CalculateZoom(), C4Object::ChangeDef(), ConsoleDlgProc(), C4ViewportList::CreateViewport(), C4MouseControl::DoMoveInput(), C4MainMenu::DoRefillInternal(), C4Viewport::Draw(), C4Viewport::DrawMenu(), C4Viewport::DrawPlayerStartup(), C4Viewport::EnableFoW(), C4Game::FindVisObject(), C4Object::GetDataString(), C4Object::GrabInfo(), C4Menu::HasMouse(), Hostile(), HostilityDeclared(), C4Object::Init(), C4ViewportWindow::Init(), C4Viewport::InitZoom(), C4Object::IsPlayerObject(), C4ObjectMenu::IsReadOnly(), C4Object::IsUserPlayerObject(), C4Viewport::IsViewportMenu(), C4MainMenu::MenuCommand(), C4MouseControl::Move(), C4Viewport::NextPlayer(), C4ChatInputDialog::OnChatCancel(), C4ChatInputDialog::OnChatInput(), Remove(), C4Player::SetHostility(), C4Viewport::SetOutputSize(), C4Object::SetOwner(), C4ViewportList::SortViewportsByPlayerControl(), C4MouseControl::UpdateCursorTarget(), C4Viewport::UpdateOutputSize(), and C4MouseControl::UpdateSingleSelection().

Here is the caller graph for this function:

◆ GetAtClient() [1/2]

C4Player * C4PlayerList::GetAtClient ( const char *  szName,
int  iIndex = 0 
) const

Definition at line 529 of file C4PlayerList.cpp.

530 {
531  int cindex=0;
532  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
533  if (SEqualNoCase(pPlr->AtClientName,szName))
534  {
535  if (cindex==iIndex) return pPlr;
536  cindex++;
537  }
538  return nullptr;
539 }

References First, C4Player::Next, and SEqualNoCase().

Here is the call graph for this function:

◆ GetAtClient() [2/2]

C4Player * C4PlayerList::GetAtClient ( int  iClient,
int  iIndex = 0 
) const

Definition at line 517 of file C4PlayerList.cpp.

518 {
519  int cindex=0;
520  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
521  if (pPlr->AtClient == iClient)
522  {
523  if (cindex==iIndex) return pPlr;
524  cindex++;
525  }
526  return nullptr;
527 }

References First, and C4Player::Next.

Referenced by C4Player::Eliminate(), C4MainMenu::MenuCommand(), C4MessageInput::ProcessCommand(), RemoveAtClient(), and C4Network2ClientList::UpdateClientActivity().

Here is the caller graph for this function:

◆ GetAtRemoteClient()

C4Player * C4PlayerList::GetAtRemoteClient ( int  iIndex = 0) const

Definition at line 555 of file C4PlayerList.cpp.

556 {
557  int cindex=0;
558  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
559  if (pPlr->AtClient != ::Control.ClientID())
560  {
561  if (cindex==iIndex) return pPlr;
562  cindex++;
563  }
564  return nullptr;
565 }
C4GameControl Control
int32_t ClientID() const

References C4GameControl::ClientID(), Control, First, and C4Player::Next.

Referenced by RemoveAtRemoteClient().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetByIndex() [1/2]

C4Player * C4PlayerList::GetByIndex ( int  iIndex) const

Definition at line 152 of file C4PlayerList.cpp.

153 {
154  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
155  if (!iIndex--)
156  return pPlr;
157  return nullptr;
158 }

References First, and C4Player::Next.

Referenced by C4MainMenu::DoRefillInternal(), C4Player::DrawHostility(), and C4Game::InitGameFinal().

Here is the caller graph for this function:

◆ GetByIndex() [2/2]

C4Player * C4PlayerList::GetByIndex ( int  iIndex,
C4PlayerType  eType 
) const

Definition at line 160 of file C4PlayerList.cpp.

161 {
162  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
163  if (pPlr->GetType() == eType)
164  if (!iIndex--)
165  return pPlr;
166  return nullptr;
167 }

References First, and C4Player::Next.

◆ GetByInfoID()

C4Player * C4PlayerList::GetByInfoID ( int  iInfoID) const

Definition at line 169 of file C4PlayerList.cpp.

170 {
171  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
172  if (pPlr->ID == iInfoID) return pPlr;
173  return nullptr;
174 }

References First, and C4Player::Next.

Referenced by C4Team::AddPlayer().

Here is the caller graph for this function:

◆ GetByName()

C4Player * C4PlayerList::GetByName ( const char *  szName,
int  iExcluding = NO_OWNER 
) const

Definition at line 420 of file C4PlayerList.cpp.

421 {
422  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
423  if (SEqual(pPlr->GetName(),szName))
424  if (pPlr->Number!=iExcluding)
425  return pPlr;
426  return nullptr;
427 }

References First, C4Player::Next, and SEqual().

Referenced by C4MessageBoard::GetMessagePlayer(), and C4MessageInput::ProcessInput().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCount() [1/2]

int C4PlayerList::GetCount ( ) const

Definition at line 176 of file C4PlayerList.cpp.

177 {
178  int iCount = 0;
179  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
180  iCount++;
181  return iCount;
182 }

References First, and C4Player::Next.

Referenced by C4MainMenu::ActivateMain(), C4MainMenu::ActivateNewPlayer(), AverageScoreGain(), C4Game::InitGameFinal(), Join(), C4Game::LoadScenarioSection(), and C4Game::OnPlayerJoinFinished().

Here is the caller graph for this function:

◆ GetCount() [2/2]

int C4PlayerList::GetCount ( C4PlayerType  eType) const

Definition at line 184 of file C4PlayerList.cpp.

185 {
186  int iCount = 0;
187  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
188  if (pPlr->GetType() == eType)
189  iCount++;
190  return iCount;
191 }

References First, and C4Player::Next.

◆ GetCountNotEliminated()

int C4PlayerList::GetCountNotEliminated ( ) const

Definition at line 601 of file C4PlayerList.cpp.

602 {
603  int iCount = 0;
604  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
605  if (!pPlr->Eliminated)
606  iCount++;
607  return iCount;
608 }

References First, and C4Player::Next.

Referenced by C4Game::GameOverCheck().

Here is the caller graph for this function:

◆ GetFreeNumber()

int C4PlayerList::GetFreeNumber ( ) const
protected

Definition at line 193 of file C4PlayerList.cpp.

194 {
195  int iNumber=-1;
196  bool fFree;
197  do
198  {
199  iNumber++; fFree=true;
200  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
201  if (pPlr->Number==iNumber)
202  fFree=false;
203  }
204  while (!fFree);
205  return iNumber;
206 }

References First, and C4Player::Next.

Referenced by Join().

Here is the caller graph for this function:

◆ GetIndex()

int C4PlayerList::GetIndex ( C4Player pPlr) const

Definition at line 143 of file C4PlayerList.cpp.

144 {
145  int cindex=0;
146  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next, cindex++)
147  if (pPlr==tPlr)
148  return cindex;
149  return -1;
150 }

References First, and C4Player::Next.

◆ GetLocalByIndex()

C4Player * C4PlayerList::GetLocalByIndex ( int  iIndex) const

Definition at line 450 of file C4PlayerList.cpp.

451 {
452  int cindex=0;
453  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
454  if (pPlr->LocalControl)
455  {
456  if (cindex==iIndex) return pPlr;
457  cindex++;
458  }
459  return nullptr;
460 }

References First, and C4Player::Next.

Referenced by C4Game::Abort(), C4Game::ActivateMenu(), C4MainMenu::MenuCommand(), C4GameControl::PrepareInput(), C4MessageInput::ProcessCommand(), and C4MessageInput::ProcessInput().

Here is the caller graph for this function:

◆ HasPlayerInTeamSelection()

bool C4PlayerList::HasPlayerInTeamSelection ( )

Definition at line 624 of file C4PlayerList.cpp.

625 {
626  for (C4Player *pPlr = First; pPlr; pPlr = pPlr->Next)
627  if (pPlr->IsChosingTeam())
628  return true;
629  return false;
630 }

References First, and C4Player::Next.

Referenced by C4Game::OnPlayerJoinFinished().

Here is the caller graph for this function:

◆ Hostile()

bool C4PlayerList::Hostile ( int  iPlayer1,
int  iPlayer2 
) const

Definition at line 84 of file C4PlayerList.cpp.

85 {
86  C4Player *pPlr1=Get(iPlayer1);
87  C4Player *pPlr2=Get(iPlayer2);
88  if (!pPlr1 || !pPlr2) return false;
89  if (pPlr1->Number==pPlr2->Number) return false;
90  if ( pPlr1->IsHostileTowards(pPlr2)
91  || pPlr2->IsHostileTowards(pPlr1) )
92  return true;
93  return false;
94 }
bool IsHostileTowards(const C4Player *opponent) const
Definition: C4Player.cpp:860
int32_t Number
Definition: C4Player.h:86
C4Player * Get(int iPlayer) const

References Get(), C4Player::IsHostileTowards(), and C4Player::Number.

Referenced by C4Player::FindNewOwner(), and Hostile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HostilityDeclared()

bool C4PlayerList::HostilityDeclared ( int  iPlayer1,
int  iPlayer2 
) const

Definition at line 96 of file C4PlayerList.cpp.

97 {
98  // check one-way-hostility
99  C4Player *pPlr1=Get(iPlayer1);
100  C4Player *pPlr2=Get(iPlayer2);
101  if (!pPlr1 || !pPlr2) return false;
102  if (pPlr1->Number==pPlr2->Number) return false;
103  if ( pPlr1->IsHostileTowards(pPlr2))
104  return true;
105  return false;
106 }

References Get(), C4Player::IsHostileTowards(), and C4Player::Number.

Referenced by C4MainMenu::MenuCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Join()

C4Player * C4PlayerList::Join ( const char *  szFilename,
bool  fScenarioInit,
int  iAtClient,
const char *  szAtClientName,
class C4PlayerInfo pInfo,
C4ValueNumbers numbers 
)

Definition at line 275 of file C4PlayerList.cpp.

276 {
277  assert(pInfo);
278  assert(fScenarioInit || numbers);
279 
280  // safeties
281  if (szFilename && !*szFilename) szFilename = nullptr;
282 
283  // Log
284  LogF(LoadResStr(fScenarioInit ? "IDS_PRC_JOINPLR" : "IDS_PRC_RECREATE"),pInfo->GetName());
285 
286  // Too many players
287  if (true) // replay needs to check, too!
289  {
290  LogF(LoadResStr("IDS_PRC_TOOMANYPLRS"),Game.Parameters.MaxPlayers);
291  return nullptr;
292  }
293 
294  // Check duplicate file usage
295  if (szFilename) if (FileInUse(szFilename))
296  { Log(LoadResStr("IDS_PRC_PLRFILEINUSE")); return nullptr; }
297 
298  // Create
299  C4Player *pPlr = new C4Player;
300 
301  // Append to player list
302  C4Player *pLast=First;
303  while (pLast && pLast->Next) pLast=pLast->Next;
304  if (pLast) pLast->Next=pPlr; else First = pPlr;
305 
306  // Init
307  if (!pPlr->Init(GetFreeNumber(),iAtClient,szAtClientName,szFilename,fScenarioInit,pInfo, numbers))
308  { Remove(pPlr, false, false); Log(LoadResStr("IDS_PRC_JOINFAIL")); return nullptr; }
309 
310  // Done
311  return pPlr;
312 }
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool Log(const char *szMessage)
Definition: C4Log.cpp:204
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:262
C4GameParameters & Parameters
Definition: C4Game.h:67
bool Init(int32_t iNumber, int32_t iAtClient, const char *szAtClientName, const char *szFilename, bool fScenarioInit, class C4PlayerInfo *pInfo, C4ValueNumbers *)
Definition: C4Player.cpp:257
bool Remove(int iPlayer, bool fDisonnected, bool fNoCalls)
friend class C4Player
Definition: C4PlayerList.h:82
bool FileInUse(const char *szFilename) const
int GetFreeNumber() const

References C4Player, FileInUse(), First, Game, GetCount(), GetFreeNumber(), C4PlayerInfo::GetName(), C4Player::Init(), LoadResStr(), Log(), LogF(), C4GameParameters::MaxPlayers, C4Player::Next, C4Game::Parameters, and Remove().

Referenced by C4Game::JoinPlayer(), and C4PlayerInfoList::RecreatePlayers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ JoinNew()

void C4PlayerList::JoinNew ( const char *  szFilename)

Definition at line 315 of file C4PlayerList.cpp.

316 {
317  if (::Network.isEnabled())
318  {
319  ::Network.Players.JoinLocalPlayer(szFilename);
320  return;
321  }
322  // security
323  if (!ItemExists(szFilename)) return;
324  // join via player info
326 }
bool ItemExists(const char *szItemName)
Definition: StdFile.h:75
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
C4Network2Players Players
Definition: C4Network2.h:119
bool JoinLocalPlayer(const char *szLocalPlayerFilename, bool initial=false)
bool DoLocalNonNetworkPlayerJoin(const char *szPlayerFile)

References C4PlayerInfoList::DoLocalNonNetworkPlayerJoin(), Game, C4Network2::isEnabled(), ItemExists(), C4Network2Players::JoinLocalPlayer(), Network, C4Game::PlayerInfos, and C4Network2::Players.

Referenced by C4MainMenu::MenuCommand(), and C4Console::PlayerJoin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MouseControlTaken()

bool C4PlayerList::MouseControlTaken ( ) const

Definition at line 592 of file C4PlayerList.cpp.

593 {
594  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
595  if (pPlr->MouseControl)
596  if (pPlr->LocalControl)
597  return true;
598  return false;
599 }

References First, and C4Player::Next.

Referenced by C4Player::InitControl(), and C4Player::ToggleMouseControl().

Here is the caller graph for this function:

◆ PositionTaken()

bool C4PlayerList::PositionTaken ( int  iPosition) const

Definition at line 108 of file C4PlayerList.cpp.

109 {
110  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
111  if (pPlr->Position==iPosition)
112  return true;
113  return false;
114 }

References First, and C4Player::Next.

Referenced by C4Player::ScenarioInit().

Here is the caller graph for this function:

◆ RecheckPlayerSort()

void C4PlayerList::RecheckPlayerSort ( C4Player pForPlayer)
protected

Definition at line 632 of file C4PlayerList.cpp.

633 {
634  if (!pForPlayer || !First) return;
635  int iNumber = pForPlayer->Number;
636  // get entry that should be the previous
637  // (use '<=' to run past pForPlayer itself)
638  C4Player *pPrev = First;
639  while (pPrev->Next && pPrev->Next->Number <= iNumber)
640  pPrev=pPrev->Next;
641  // if it's correctly sorted, pPrev should point to pForPlayer itself
642  if (pPrev == pForPlayer) return;
643  // otherwise, pPrev points to the entry that should be the new previous
644  // or to First if pForPlayer should be the head entry
645  // re-link it there
646  // first remove from old link pos
647  C4Player **pOldLink = &First;
648  while (*pOldLink && *pOldLink != pForPlayer) pOldLink = &((*pOldLink)->Next);
649  if (*pOldLink) *pOldLink = pForPlayer->Next;
650  // then link into new
651  if (pPrev == First && pPrev->Number > iNumber)
652  {
653  // at head
654  pForPlayer->Next = pPrev;
655  First = pForPlayer;
656  }
657  else
658  {
659  // after prev
660  pForPlayer->Next = pPrev->Next;
661  pPrev->Next = pForPlayer;
662  }
663 }

References First, C4Player::Next, and C4Player::Number.

Referenced by C4Player::Init().

Here is the caller graph for this function:

◆ Remove() [1/2]

bool C4PlayerList::Remove ( C4Player pPlr,
bool  fDisonnected,
bool  fNoCalls 
)

Definition at line 223 of file C4PlayerList.cpp.

224 {
225  if (!pPlr) return false;
226 
227  // inform script
228  if (!fNoCalls)
230 
231  // Transfer ownership of other objects to team members
232  if (!fNoCalls) pPlr->NotifyOwnedObjects();
233 
234  // NET2: update player info list
235  if (pPlr->ID)
236  {
238  if (pInfo)
239  {
240  pInfo->SetRemoved();
241  if (fDisconnect)
242  pInfo->SetDisconnected();
243  }
244  // if player wasn't evaluated, store round results anyway
245  if (!pPlr->Evaluated) Game.RoundResults.EvaluatePlayer(pPlr);
246  }
247 
248  C4Player *pPrev=First;
249  while (pPrev && pPrev->Next!=pPlr) pPrev=pPrev->Next;
250  if (pPrev) pPrev->Next=pPlr->Next;
251  else First=pPlr->Next;
252 
253  // Remove eliminated crew
254  if (!fNoCalls) pPlr->RemoveCrewObjects();
255 
256  // Clear object info pointers
258 
259  // Clear viewports
260  ::Viewports.CloseViewport(pPlr->Number, fNoCalls);
261  // Check fullscreen viewports
263 
264  // Remove player
265  delete pPlr;
266 
267  // Validate object owners
269 
270  // Update console
272  return true;
273 }
#define PSF_RemovePlayer
Definition: C4GameScript.h:46
C4Console Console
Definition: C4Globals.cpp:45
C4GameObjects Objects
Definition: C4Globals.cpp:48
C4FullScreen FullScreen
Definition: C4Globals.cpp:46
C4ViewportList Viewports
void UpdateMenus()
Definition: C4Console.cpp:504
bool ViewportCheck()
C4RoundResults & RoundResults
Definition: C4Game.h:73
C4Value GRBroadcast(const char *function, C4AulParSet *pars=nullptr, bool pass_error=false, bool reject_test=false)
Definition: C4Game.cpp:4761
bool ValidateOwners() override
C4ObjectInfoList CrewInfoList
Definition: C4Player.h:124
void RemoveCrewObjects()
Definition: C4Player.cpp:1271
void NotifyOwnedObjects()
Definition: C4Player.cpp:1311
int32_t Team
Definition: C4Player.h:88
int32_t ID
Definition: C4Player.h:87
bool Evaluated
Definition: C4Player.h:85
void SetDisconnected()
Definition: C4PlayerInfo.h:200
C4PlayerInfo * GetPlayerInfoByID(int32_t id) const
void EvaluatePlayer(C4Player *pPlr)
bool CloseViewport(int32_t player_nr, bool silent)

References C4ViewportList::CloseViewport(), Console, C4Player::CrewInfoList, C4ObjectInfoList::DetachFromObjects(), C4Player::Evaluated, C4RoundResults::EvaluatePlayer(), First, FullScreen, Game, C4PlayerInfoList::GetPlayerInfoByID(), C4Game::GRBroadcast(), C4Player::ID, C4Player::Next, C4Player::NotifyOwnedObjects(), C4Player::Number, Objects, C4Game::PlayerInfos, PSF_RemovePlayer, C4Player::RemoveCrewObjects(), C4Game::RoundResults, C4PlayerInfo::SetDisconnected(), C4PlayerInfo::SetRemoved(), C4Player::Team, C4Console::UpdateMenus(), C4GameObjects::ValidateOwners(), C4FullScreen::ViewportCheck(), and Viewports.

Here is the call graph for this function:

◆ Remove() [2/2]

bool C4PlayerList::Remove ( int  iPlayer,
bool  fDisonnected,
bool  fNoCalls 
)

Definition at line 208 of file C4PlayerList.cpp.

209 {
210  return Remove(Get(iPlayer), fDisconnect, fNoCalls);
211 }

References Get().

Referenced by C4Game::InitGameFinal(), Join(), RemoveAtClient(), RemoveAtRemoteClient(), RemoveLocal(), and Retire().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveAtClient() [1/2]

bool C4PlayerList::RemoveAtClient ( const char *  szName,
bool  fDisconnect 
)

Definition at line 476 of file C4PlayerList.cpp.

477 {
478  C4Player *pPlr;
479  // Get players
480  while ((pPlr = GetAtClient(szName)))
481  {
482  // Log
483  Log(FormatString(LoadResStr("IDS_PRC_REMOVEPLR"),pPlr->GetName()).getData());
484  // Remove
485  Remove(pPlr, fDisconnect, false);
486  }
487  return true;
488 }
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
const char * GetName() const
Definition: C4Player.h:151
C4Player * GetAtClient(int iClient, int iIndex=0) const
const char * getData() const
Definition: StdBuf.h:442

References FormatString(), GetAtClient(), StdStrBuf::getData(), C4Player::GetName(), LoadResStr(), Log(), and Remove().

Here is the call graph for this function:

◆ RemoveAtClient() [2/2]

bool C4PlayerList::RemoveAtClient ( int  iClient,
bool  fDisconnect 
)

Definition at line 462 of file C4PlayerList.cpp.

463 {
464  C4Player *pPlr;
465  // Get players
466  while ((pPlr = GetAtClient(iClient)))
467  {
468  // Log
469  Log(FormatString(LoadResStr("IDS_PRC_REMOVEPLR"),pPlr->GetName()).getData());
470  // Remove
471  Remove(pPlr, fDisconnect, false);
472  }
473  return true;
474 }

References FormatString(), GetAtClient(), StdStrBuf::getData(), C4Player::GetName(), LoadResStr(), Log(), and Remove().

Referenced by C4Client::Remove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveAtRemoteClient()

bool C4PlayerList::RemoveAtRemoteClient ( bool  fDisonnected,
bool  fNoCalls 
)

Definition at line 541 of file C4PlayerList.cpp.

542 {
543  C4Player *pPlr;
544  // Get players
545  while ((pPlr = GetAtRemoteClient()))
546  {
547  // Log
548  Log(FormatString(LoadResStr("IDS_PRC_REMOVEPLR"),pPlr->GetName()).getData());
549  // Remove
550  Remove(pPlr, fDisconnect, fNoCalls);
551  }
552  return true;
553 }
C4Player * GetAtRemoteClient(int iIndex=0) const

References FormatString(), GetAtRemoteClient(), StdStrBuf::getData(), C4Player::GetName(), LoadResStr(), Log(), and Remove().

Referenced by C4Game::Abort().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveLocal()

bool C4PlayerList::RemoveLocal ( bool  fDisonnected,
bool  fNoCalls 
)

Definition at line 567 of file C4PlayerList.cpp.

568 {
569  // (used by league system the set local fate)
570  C4Player *pPlr;
571  do
572  for (pPlr = First; pPlr; pPlr = pPlr->Next)
573  if (pPlr->LocalControl)
574  {
575  // Log
576  Log(FormatString(LoadResStr("IDS_PRC_REMOVEPLR"),pPlr->GetName()).getData());
577  // Remove
578  Remove(pPlr, fDisconnect, fNoCalls);
579  break;
580  }
581  while (pPlr);
582 
583  return true;
584 }
bool LocalControl
Definition: C4Player.h:99

References First, FormatString(), StdStrBuf::getData(), C4Player::GetName(), LoadResStr(), C4Player::LocalControl, Log(), C4Player::Next, and Remove().

Referenced by C4Game::Abort().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveUnjoined()

bool C4PlayerList::RemoveUnjoined ( int32_t  iPlayer)

Definition at line 213 of file C4PlayerList.cpp.

214 {
215  // Savegame resume missing player: Remove player objects only
216  for (C4Object *pObj : Objects)
217  if (pObj->Status)
218  if (pObj->IsPlayerObject(iPlayer))
219  pObj->AssignRemoval(true);
220  return true;
221 }

References Objects.

Referenced by C4PlayerInfoList::RemoveUnassociatedPlayers().

Here is the caller graph for this function:

◆ Retire()

bool C4PlayerList::Retire ( C4Player pPlr)

Definition at line 394 of file C4PlayerList.cpp.

395 {
396  if (!pPlr) return false;
397 
398  if (!pPlr->Evaluated)
399  {
400  pPlr->Evaluate();
401  if (!::Control.isReplay() && pPlr->GetType() != C4PT_Script) pPlr->Save();
402  }
403  Remove(pPlr, false, false);
404 
405  return true;
406 }
@ C4PT_Script
Definition: C4Constants.h:155
bool isReplay() const
Definition: C4GameControl.h:98
void Evaluate()
Definition: C4Player.cpp:787
C4PlayerType GetType() const
Definition: C4Player.cpp:1727
bool Save()
Definition: C4Player.cpp:415

References C4PT_Script, Control, C4Player::Evaluate(), C4Player::Evaluated, C4Player::GetType(), C4GameControl::isReplay(), Remove(), and C4Player::Save().

Referenced by Execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Save() [1/2]

bool C4PlayerList::Save ( bool  fSaveLocalOnly)

Definition at line 374 of file C4PlayerList.cpp.

375 {
376  // do not save in replays
377  if (Game.C4S.Head.Replay) return true;
378  // Save to external player files
379  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
380  if (pPlr->GetType() != C4PT_Script)
381  if (!fSaveLocalOnly || pPlr->LocalControl)
382  if (!pPlr->Save())
383  return false;
384  return true;
385 }
C4Scenario C4S
Definition: C4Game.h:74
bool Replay
Definition: C4Scenario.h:72
C4SHead Head
Definition: C4Scenario.h:232

References C4PT_Script, C4Game::C4S, First, Game, C4Scenario::Head, C4Player::Next, and C4SHead::Replay.

Referenced by C4Game::Evaluate().

Here is the caller graph for this function:

◆ Save() [2/2]

bool C4PlayerList::Save ( C4Group hGroup,
bool  fStoreTiny,
const C4PlayerInfoList rStoreList 
)

Definition at line 343 of file C4PlayerList.cpp.

344 {
345  StdStrBuf sTempFilename;
346  bool fSuccess = true;
347  // Save to external player files and add to group
348  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
349  {
350  // save only those in the list, and only those with a filename
351  C4PlayerInfo *pNfo = rStoreList.GetPlayerInfoByID(pPlr->ID);
352  if (!pNfo) continue;
353  if (!pNfo->GetFilename() || !*pNfo->GetFilename()) continue;;
354  // save over original file?
355  bool fStoreOnOriginal = (!fStoreTiny && pNfo->GetType() == C4PT_User);
356  // Create temporary file
357  sTempFilename.Copy(Config.AtTempPath(pNfo->GetFilename()));
358  if (fStoreOnOriginal)
359  if (!C4Group_CopyItem(pPlr->Filename, sTempFilename.getData()))
360  return false;
361  // Open group
362  C4Group PlrGroup;
363  if (!PlrGroup.Open(sTempFilename.getData(), !fStoreOnOriginal))
364  return false;
365  // Save player
366  if (!pPlr->Save(PlrGroup, true, fStoreOnOriginal)) return false;
367  PlrGroup.Close();
368  // Add temp file to group
369  if (!hGroup.Move(sTempFilename.getData(), pNfo->GetFilename())) return false;
370  }
371  return fSuccess;
372 }
C4Config Config
Definition: C4Config.cpp:930
@ C4PT_User
Definition: C4Constants.h:154
bool C4Group_CopyItem(const char *source, const char *target, bool no_sorting, bool reset_attributes)
Definition: C4Group.cpp:115
const char * AtTempPath(const char *filename)
Definition: C4Config.cpp:600
bool Close()
Definition: C4Group.cpp:971
bool Move(const char *filename, const char *entry_name)
Definition: C4Group.cpp:1633
bool Open(const char *group_name, bool do_create=false)
Definition: C4Group.cpp:660
C4PlayerType GetType() const
Definition: C4PlayerInfo.h:152
const char * GetFilename() const
Definition: C4PlayerInfo.h:161
void Copy()
Definition: StdBuf.h:467

References C4Config::AtTempPath(), C4Group_CopyItem(), C4PT_User, C4Group::Close(), Config, StdStrBuf::Copy(), First, StdStrBuf::getData(), C4PlayerInfo::GetFilename(), C4PlayerInfoList::GetPlayerInfoByID(), C4PlayerInfo::GetType(), C4Group::Move(), C4Player::Next, and C4Group::Open().

Here is the call graph for this function:

◆ SynchronizeLocalFiles()

bool C4PlayerList::SynchronizeLocalFiles ( )

Definition at line 610 of file C4PlayerList.cpp.

611 {
612  // message
613  Log(LoadResStr("IDS_PRC_SYNCPLRS"));
614  bool fSuccess = true;
615  // check all players
616  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
617  // eliminated players will be saved soon, anyway
618  if (!pPlr->Eliminated)
619  if (!pPlr->LocalSync()) fSuccess = false;
620  // done
621  return fSuccess;
622 }

References First, LoadResStr(), Log(), and C4Player::Next.

Referenced by C4GameSaveSavegame::OnSaving(), and C4Game::Synchronize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Valid()

bool C4PlayerList::Valid ( int  iPlayer) const

Definition at line 76 of file C4PlayerList.cpp.

77 {
78  for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
79  if (pPlr->Number==iPlayer)
80  return true;
81  return false;
82 }

References First, and C4Player::Next.

Referenced by ValidPlr().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ C4Player

friend class C4Player
friend

Definition at line 82 of file C4PlayerList.h.

Referenced by Join().

Member Data Documentation

◆ First


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