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

#include <C4Teams.h>

Public Types

enum  ConfigValue {
  TEAM_None = 0, TEAM_Custom = 1, TEAM_Active = 2, TEAM_AllowHostilityChange = 3,
  TEAM_Dist = 4, TEAM_AllowTeamSwitch = 5, TEAM_AutoGenerateTeams = 6, TEAM_TeamColors = 7
}
 
enum  TeamDist {
  TEAMDIST_First = 0, TEAMDIST_Free = 0, TEAMDIST_Host = 1, TEAMDIST_None = 2,
  TEAMDIST_Random = 3, TEAMDIST_RandomInv = 4, TEAMDIST_Last = 4
}
 

Public Member Functions

 C4TeamList ()=default
 
 ~C4TeamList ()
 
void Clear ()
 
C4TeamListoperator= (const C4TeamList &rCopy)
 
C4TeamGetTeamByID (int32_t iID) const
 
C4TeamGetGenerateTeamByID (int32_t iID)
 
C4TeamGetTeamByIndex (int32_t iIndex) const
 
C4TeamGetTeamByName (const char *szName) const
 
C4TeamGetTeamByPlayerID (int32_t iID) const
 
int32_t GetLargestTeamID () const
 
C4TeamGetRandomSmallestTeam () const
 
int32_t GetTeamCount () const
 
C4TeamCreateTeam (const char *szName)
 
bool IsMultiTeams () const
 
bool IsCustom () const
 
bool IsHostilityChangeAllowed () const
 
bool IsTeamSwitchAllowed () const
 
bool CanLocalChooseTeam () const
 
bool CanLocalChooseTeam (int32_t idPlayer) const
 
bool CanLocalSeeTeam () const
 
bool IsTeamColors () const
 
bool IsRandomTeam () const
 
bool IsJoin2TeamAllowed (int32_t idTeam, C4PlayerType plrType)
 
bool IsAutoGenerateTeams () const
 
bool IsRuntimeJoinTeamChoice () const
 
int32_t GetMaxScriptPlayers () const
 
int32_t GetForcedTeamSelection (int32_t idForPlayer) const
 
StdStrBuf GetScriptPlayerName () const
 
bool IsTeamVisible () const
 
void EnforceLeagueRules ()
 
bool RecheckPlayerInfoTeams (C4PlayerInfo &rNewJoin, bool fByHost)
 
void CompileFunc (StdCompiler *pComp)
 
bool Load (C4Group &hGroup, class C4Scenario *pInitDefault, class C4LangStringTable *pLang)
 
bool Save (C4Group &hGroup)
 
void RecheckPlayers ()
 
void RecheckTeams ()
 
void ReassignAllTeams ()
 
void FillTeamDistOptions (C4GUI::ComboBox_FillCB *pFiller) const
 
void SendSetTeamDist (TeamDist eNewDist)
 
TeamDist GetTeamDist () const
 
StdStrBuf GetTeamDistString () const
 
bool HasTeamDistOptions () const
 
void SetTeamDistribution (TeamDist eToVal)
 
void SendSetTeamColors (bool fEnabled)
 
void SetTeamColors (bool fEnabled)
 
int32_t GetStartupTeamCount (int32_t startup_player_count)
 

Detailed Description

Definition at line 88 of file C4Teams.h.

Member Enumeration Documentation

Enumerator
TEAM_None 
TEAM_Custom 
TEAM_Active 
TEAM_AllowHostilityChange 
TEAM_Dist 
TEAM_AllowTeamSwitch 
TEAM_AutoGenerateTeams 
TEAM_TeamColors 

Definition at line 92 of file C4Teams.h.

Enumerator
TEAMDIST_First 
TEAMDIST_Free 
TEAMDIST_Host 
TEAMDIST_None 
TEAMDIST_Random 
TEAMDIST_RandomInv 
TEAMDIST_Last 

Definition at line 105 of file C4Teams.h.

106  {
107  TEAMDIST_First = 0,
108  TEAMDIST_Free = 0, // anyone can choose teams
109  TEAMDIST_Host = 1, // host decides teams
110  TEAMDIST_None = 2, // no teams
111  TEAMDIST_Random = 3, // fixed random teams
112  TEAMDIST_RandomInv = 4, // fixed random teams invisible in lobby
113  TEAMDIST_Last = 4,
114  };

Constructor & Destructor Documentation

C4TeamList::C4TeamList ( )
default
C4TeamList::~C4TeamList ( )
inline

Definition at line 135 of file C4Teams.h.

References Clear().

135 { Clear(); }
void Clear()
Definition: C4Teams.cpp:255

Here is the call graph for this function:

Member Function Documentation

bool C4TeamList::CanLocalChooseTeam ( ) const

Definition at line 292 of file C4Teams.cpp.

References Control, C4GameControl::isCtrlHost(), TEAMDIST_Free, TEAMDIST_Host, TEAMDIST_None, TEAMDIST_Random, and TEAMDIST_RandomInv.

Referenced by CanLocalChooseTeam().

293 {
294  // only if there are any teams
295  if (!fActive) return false;
296  // check by mode
297  switch (eTeamDist)
298  {
299  case TEAMDIST_Free: return true;
301  case TEAMDIST_None:
302  case TEAMDIST_Random:
303  case TEAMDIST_RandomInv:
304  return false;
305  default: assert(false); return false;
306  }
307 }
bool isCtrlHost() const
Definition: C4GameControl.h:99
C4GameControl Control

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4TeamList::CanLocalChooseTeam ( int32_t  idPlayer) const

Definition at line 309 of file C4Teams.cpp.

References CanLocalChooseTeam(), GetTeamByIndex(), GetTeamByPlayerID(), and IsAutoGenerateTeams().

310 {
311  // must be possible at all
312  if (!CanLocalChooseTeam()) return false;
313  // there must be space in a target team
314  // always possible if teams are generated on the fly
315  if (IsAutoGenerateTeams()) return true;
316  // also possible if one of the teams that's not the player's is not full
317  C4Team *pCurrentTeam = nullptr, *pCheck;
318  if (idPlayer) pCurrentTeam = GetTeamByPlayerID(idPlayer);
319  int32_t iCheckTeam=0;
320  while ((pCheck = GetTeamByIndex(iCheckTeam++)))
321  if (pCheck != pCurrentTeam)
322  if (!pCheck->IsFull())
323  break;
324  return !!pCheck;
325 }
Definition: C4Teams.h:30
bool IsAutoGenerateTeams() const
Definition: C4Teams.h:172
bool CanLocalChooseTeam() const
Definition: C4Teams.cpp:292
C4Team * GetTeamByIndex(int32_t iIndex) const
Definition: C4Teams.cpp:404
C4Team * GetTeamByPlayerID(int32_t iID) const
Definition: C4Teams.cpp:420

Here is the call graph for this function:

bool C4TeamList::CanLocalSeeTeam ( ) const

Definition at line 327 of file C4Teams.cpp.

References Game, C4Game::IsRunning, and TEAMDIST_RandomInv.

Referenced by C4PlayerInfoListBox::Update().

328 {
329  if (!fActive) return false;
330  // invisible teams aren't revealed before game start
331  if (eTeamDist != TEAMDIST_RandomInv) return true;
332  return !!Game.IsRunning;
333 }
bool IsRunning
Definition: C4Game.h:139
C4Game Game
Definition: C4Globals.cpp:52

Here is the caller graph for this function:

void C4TeamList::Clear ( )

Definition at line 255 of file C4Teams.cpp.

References StdStrBuf::Clear(), and TEAMDIST_Free.

Referenced by C4GameParameters::Clear(), Load(), operator=(), and ~C4TeamList().

256 {
257  // del all teams
258  ClearTeams();
259  // del player team vector
260  delete [] ppList; ppList = nullptr;
261  iTeamCapacity = 0;
262  fAllowHostilityChange = true;
263  fAllowTeamSwitch = false;
264  fCustom = false;
265  fActive = true;
266  fTeamColors = false;
267  eTeamDist = TEAMDIST_Free;
268  fAutoGenerateTeams = false;
269  iMaxScriptPlayers = 0;
270  sScriptPlayerNames.Clear();
271 }
void Clear()
Definition: StdBuf.h:466

Here is the call graph for this function:

Here is the caller graph for this function:

void C4TeamList::CompileFunc ( StdCompiler pComp)

Definition at line 545 of file C4Teams.cpp.

References GetLargestTeamID(), StdCompiler::isDeserializer(), mkArrayAdaptMap(), mkNamingAdapt(), mkNamingCountAdapt(), mkParAdapt(), mkPtrAdaptNoNull(), StdCompiler::RCT_All, TEAMDIST_Free, TEAMDIST_Host, TEAMDIST_None, TEAMDIST_Random, TEAMDIST_RandomInv, and StdCompiler::Value().

546 {
547  // if (pComp->isDeserializer()) Clear(); - do not clear, because this would corrupt the fCustom-flag
548  pComp->Value(mkNamingAdapt(fActive, "Active", true));
549  pComp->Value(mkNamingAdapt(fCustom, "Custom", true));
550  pComp->Value(mkNamingAdapt(fAllowHostilityChange, "AllowHostilityChange", false));
551  pComp->Value(mkNamingAdapt(fAllowTeamSwitch, "AllowTeamSwitch", false));
552  pComp->Value(mkNamingAdapt(fAutoGenerateTeams, "AutoGenerateTeams", false));
553  pComp->Value(mkNamingAdapt(iLastTeamID, "LastTeamID", 0));
554 
555  StdEnumEntry<TeamDist> TeamDistEntries[] =
556  {
557  { "Free", TEAMDIST_Free },
558  { "Host", TEAMDIST_Host },
559  { "None", TEAMDIST_None },
560  { "Random", TEAMDIST_Random },
561  { "RandomInv", TEAMDIST_RandomInv },
562  };
563  pComp->Value(mkNamingAdapt(mkEnumAdaptT<uint8_t>(eTeamDist, TeamDistEntries), "TeamDistribution", TEAMDIST_Free));
564 
565  pComp->Value(mkNamingAdapt(fTeamColors, "TeamColors", false));
566  pComp->Value(mkNamingAdapt(iMaxScriptPlayers, "MaxScriptPlayers", 0));
567  pComp->Value(mkNamingAdapt(mkParAdapt(sScriptPlayerNames, StdCompiler::RCT_All), "ScriptPlayerNames", StdStrBuf()));
568 
569  int32_t iOldTeamCount = iTeamCount;
570  pComp->Value(mkNamingCountAdapt(iTeamCount, "Team"));
571 
572  if (pComp->isDeserializer())
573  {
574  while (iOldTeamCount--) delete ppList[iOldTeamCount];
575  delete [] ppList;
576  if ((iTeamCapacity = iTeamCount))
577  {
578  ppList = new C4Team *[iTeamCapacity];
579  memset(ppList, 0, sizeof(C4Team *)*iTeamCapacity);
580  }
581  else
582  ppList = nullptr;
583  }
584 
585  if (iTeamCount)
586  {
587  // Force compiler to spezialize
588  mkPtrAdaptNoNull(*ppList);
589  // Save team list, using map-function.
590  pComp->Value(mkNamingAdapt(
591  mkArrayAdaptMap(ppList, iTeamCount, mkPtrAdaptNoNull<C4Team>),
592  "Team"));
593  }
594 
595  if (pComp->isDeserializer())
596  {
597  // adjust last team ID, which may not be set properly for player-generated team files
598  iLastTeamID = std::max(GetLargestTeamID(), iLastTeamID);
599  // force automatic generation of teams if none are defined
600  if (!iTeamCount) fAutoGenerateTeams = true;
601  }
602 }
Definition: StdAdaptors.h:762
StdNamingCountAdapt< int_t > mkNamingCountAdapt(int_t &iCount, const char *szName)
Definition: StdAdaptors.h:976
Definition: C4Teams.h:30
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
StdPtrAdapt< T > mkPtrAdaptNoNull(T *&rpObj)
Definition: StdAdaptors.h:606
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
int32_t GetLargestTeamID() const
Definition: C4Teams.cpp:427
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:458
StdArrayAdapt< T, M > mkArrayAdaptMap(T *pArray, int iSize, M &&map)
Definition: StdAdaptors.h:313

Here is the call graph for this function:

C4Team * C4TeamList::CreateTeam ( const char *  szName)

Definition at line 360 of file C4Teams.cpp.

References C4MaxName, C4Team::iID, C4Team::Name, C4Team::RecheckColor(), and SCopy().

361 {
362  // custom team
363  C4Team *pNewTeam = new C4Team();
364  pNewTeam->iID = iLastTeamID + 1;
365  SCopy(szName, pNewTeam->Name, C4MaxName);
366  AddTeam(pNewTeam);
367  pNewTeam->RecheckColor(*this);
368  return pNewTeam;
369 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
char Name[C4MaxName+1]
Definition: C4Teams.h:47
void RecheckColor(C4TeamList &rForList)
Definition: C4Teams.cpp:169
Definition: C4Teams.h:30
const unsigned int C4MaxName
int32_t iID
Definition: C4Teams.h:46

Here is the call graph for this function:

void C4TeamList::EnforceLeagueRules ( )

Definition at line 843 of file C4Teams.cpp.

Referenced by C4GameParameters::EnforceLeagueRules().

844 {
845  // enforce some league settings
846  // allow temp hostility switching; often used e.g. to unstick friendly Clonks, but:
847  fAllowTeamSwitch = false; // switching teams in league games? Yeah, sure...
848 }

Here is the caller graph for this function:

void C4TeamList::FillTeamDistOptions ( C4GUI::ComboBox_FillCB pFiller) const

Definition at line 765 of file C4Teams.cpp.

References C4GUI::ComboBox_FillCB::AddEntry(), IsAutoGenerateTeams(), TEAMDIST_Free, TEAMDIST_Host, TEAMDIST_None, TEAMDIST_Random, and TEAMDIST_RandomInv.

766 {
767  // no teams if disabled
768  if (!fActive) return;
769  // team distribution options
770  pFiller->AddEntry(GetTeamDistName(TEAMDIST_Free).getData(), TEAMDIST_Free);
771  pFiller->AddEntry(GetTeamDistName(TEAMDIST_Host).getData(), TEAMDIST_Host);
772  if (IsAutoGenerateTeams()) pFiller->AddEntry(GetTeamDistName(TEAMDIST_None).getData(), TEAMDIST_None); // no teams: only for regular melees
773  pFiller->AddEntry(GetTeamDistName(TEAMDIST_Random).getData(), TEAMDIST_Random);
774  pFiller->AddEntry(GetTeamDistName(TEAMDIST_RandomInv).getData(), TEAMDIST_RandomInv);
775  }
bool IsAutoGenerateTeams() const
Definition: C4Teams.h:172
void AddEntry(const char *szText, int32_t id)

Here is the call graph for this function:

int32_t C4TeamList::GetForcedTeamSelection ( int32_t  idForPlayer) const

Definition at line 850 of file C4Teams.cpp.

References C4Team::GetID(), GetTeamByIndex(), GetTeamByPlayerID(), IsAutoGenerateTeams(), and TEAMID_New.

Referenced by C4Player::Execute().

851 {
852  // if there's only one team for the player to join, return that team ID
853  C4Team *pOKTeam = nullptr, *pCheck;
854  if (idForPlayer) pOKTeam = GetTeamByPlayerID(idForPlayer); // curent team is always possible, even if full
855  int32_t iCheckTeam=0;
856  while ((pCheck = GetTeamByIndex(iCheckTeam++)))
857  if (!pCheck->IsFull())
858  {
859  // this team could be joined
860  if (pOKTeam && pOKTeam != pCheck)
861  {
862  // there already was a team that could be joined
863  // two alternatives -> team selection is not forced
864  return 0;
865  }
866  pOKTeam = pCheck;
867  }
868  // was there a team that could be joined?
869  if (pOKTeam)
870  {
871  // if teams are generated on the fly, there would always be the possibility of creating a new team }
872  if (IsAutoGenerateTeams()) return 0;
873  // otherwise, this team is forced!
874  return pOKTeam->GetID();
875  }
876  // no team could be joined: Teams auto generated?
877  if (IsAutoGenerateTeams())
878  {
879  // then the only possible way is to join a new team
880  return TEAMID_New;
881  }
882  // otherwise, nothing can be done...
883  return 0;
884 }
int32_t GetID() const
Definition: C4Teams.h:66
Definition: C4Teams.h:30
bool IsAutoGenerateTeams() const
Definition: C4Teams.h:172
C4Team * GetTeamByIndex(int32_t iIndex) const
Definition: C4Teams.cpp:404
C4Team * GetTeamByPlayerID(int32_t iID) const
Definition: C4Teams.cpp:420
const int32_t TEAMID_New
Definition: C4Teams.h:27

Here is the call graph for this function:

Here is the caller graph for this function:

C4Team * C4TeamList::GetGenerateTeamByID ( int32_t  iID)

Definition at line 390 of file C4Teams.cpp.

References GetLargestTeamID(), GetTeamByID(), IsMultiTeams(), and TEAMID_New.

Referenced by C4PlayerInfoList::AddInfo(), C4Player::Init(), C4PlayerInfoList::RecheckAutoGeneratedTeams(), and C4Player::ScenarioAndTeamInit().

391 {
392  // only if enabled
393  if (!IsMultiTeams()) return nullptr;
394  // new team?
395  if (iID == TEAMID_New) iID = GetLargestTeamID()+1;
396  // find in list
397  C4Team *pTeam = GetTeamByID(iID);
398  if (pTeam) return pTeam;
399  // not found: Generate
400  GenerateDefaultTeams(iID);
401  return GetTeamByID(iID);
402 }
Definition: C4Teams.h:30
bool IsMultiTeams() const
Definition: C4Teams.h:162
C4Team * GetTeamByID(int32_t iID) const
Definition: C4Teams.cpp:383
const int32_t TEAMID_New
Definition: C4Teams.h:27
int32_t GetLargestTeamID() const
Definition: C4Teams.cpp:427

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t C4TeamList::GetLargestTeamID ( ) const

Definition at line 427 of file C4Teams.cpp.

References iCnt.

Referenced by CompileFunc(), and GetGenerateTeamByID().

428 {
429  int32_t iLargest = 0;
430  C4Team **ppCheck=ppList; int32_t iCnt=iTeamCount;
431  for (; iCnt--; ++ppCheck) iLargest = std::max((*ppCheck)->GetID(), iLargest);
432  return iLargest;
433 }
Definition: C4Teams.h:30
int iCnt
Definition: TstC4NetIO.cpp:32

Here is the caller graph for this function:

int32_t C4TeamList::GetMaxScriptPlayers ( ) const
inline

Definition at line 174 of file C4Teams.h.

174 { return iMaxScriptPlayers; } // return max number of script players to be added inthe lobby
C4Team * C4TeamList::GetRandomSmallestTeam ( ) const

Definition at line 435 of file C4Teams.cpp.

References C4Team::GetPlayerCount(), iCnt, and UnsyncedRandom().

Referenced by RecheckPlayerInfoTeams(), and RecheckTeams().

436 {
437  C4Team *pLowestTeam = nullptr; int iLowestTeamCount = 0;
438  C4Team **ppCheck=ppList; int32_t iCnt=iTeamCount;
439  for (; iCnt--; ++ppCheck)
440  {
441  if ((*ppCheck)->IsFull()) continue; // do not join into full teams
442  if (!pLowestTeam || pLowestTeam->GetPlayerCount() > (*ppCheck)->GetPlayerCount())
443  {
444  pLowestTeam = *ppCheck;
445  iLowestTeamCount = 1;
446  }
447  else if (pLowestTeam->GetPlayerCount() == (*ppCheck)->GetPlayerCount())
448  if (!UnsyncedRandom(++iLowestTeamCount))
449  pLowestTeam = *ppCheck;
450  }
451  return pLowestTeam;
452 }
int32_t GetPlayerCount() const
Definition: C4Teams.h:64
uint32_t UnsyncedRandom()
Definition: C4Random.cpp:58
Definition: C4Teams.h:30
int iCnt
Definition: TstC4NetIO.cpp:32

Here is the call graph for this function:

Here is the caller graph for this function:

StdStrBuf C4TeamList::GetScriptPlayerName ( ) const

Definition at line 886 of file C4Teams.cpp.

References Game, C4PlayerInfoList::GetActivePlayerInfoByName(), StdStrBuf::getData(), StdStrBuf::getLength(), StdStrBuf::GetSection(), LoadResStr(), C4Game::PlayerInfos, and UnsyncedRandom().

887 {
888  // get a name to assign to a new script player. Try to avoid name conflicts
889  if (!sScriptPlayerNames.getLength()) return StdStrBuf(LoadResStr("IDS_TEXT_COMPUTER")); // default name
890  // test available script names
891  int32_t iNameIdx = 0; StdStrBuf sOut;
892  while (sScriptPlayerNames.GetSection(iNameIdx++, &sOut, '|'))
894  return sOut;
895  // none are available: Return a random name
896  sScriptPlayerNames.GetSection(UnsyncedRandom(iNameIdx-1), &sOut, '|');
897  return sOut;
898 }
const char * getData() const
Definition: StdBuf.h:442
bool GetSection(size_t idx, StdStrBuf *psOutSection, char cSeparator=';') const
Definition: StdBuf.cpp:369
C4Game Game
Definition: C4Globals.cpp:52
uint32_t UnsyncedRandom()
Definition: C4Random.cpp:58
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4PlayerInfo * GetActivePlayerInfoByName(const char *szName)
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
size_t getLength() const
Definition: StdBuf.h:445

Here is the call graph for this function:

int32_t C4TeamList::GetStartupTeamCount ( int32_t  startup_player_count)

Definition at line 900 of file C4Teams.cpp.

References C4Team::GetPlayerCount(), GetTeamByIndex(), GetTeamCount(), IsAutoGenerateTeams(), IsCustom(), and IsRandomTeam().

Referenced by C4Game::InitGame().

901 {
902  // Count non-empty teams
903  int32_t i_team = 0; C4Team *team;
904  int32_t team_count = 0;
905  while ((team = GetTeamByIndex(i_team++)))
906  {
907  if (team->GetPlayerCount() > 0) ++team_count;
908  }
909  // No populated teams found? This can happen in non-network mode when no players are assigned
910  if (!team_count)
911  {
912  // Teams have not been selected yet, but the map script may want to have an estimate
913  // in this case, calculate prospective teams from startup player count
914  if (IsCustom() && !IsAutoGenerateTeams())
915  {
916  // Teams are pre-defined. Assume players will try to distribute broadly on these teams
917  team_count = std::min<int32_t>(startup_player_count, GetTeamCount());
918  }
919  else if (IsRandomTeam())
920  {
921  // Randomized teams: Players will be put into two teams.
922  team_count = std::min<int32_t>(startup_player_count, 2);
923  }
924  else
925  {
926  // Teams are auto-added -> fallback to player count
927  team_count = startup_player_count;
928  }
929  }
930 
931  return team_count;
932 }
int32_t GetPlayerCount() const
Definition: C4Teams.h:64
bool IsRandomTeam() const
Definition: C4Teams.h:170
Definition: C4Teams.h:30
bool IsAutoGenerateTeams() const
Definition: C4Teams.h:172
C4Team * GetTeamByIndex(int32_t iIndex) const
Definition: C4Teams.cpp:404
bool IsCustom() const
Definition: C4Teams.h:163
int32_t GetTeamCount() const
Definition: C4Teams.h:158

Here is the call graph for this function:

Here is the caller graph for this function:

C4Team * C4TeamList::GetTeamByID ( int32_t  iID) const

Definition at line 383 of file C4Teams.cpp.

References iCnt.

Referenced by C4Player::Execute(), C4Player::FindNewOwner(), GetGenerateTeamByID(), C4PlayerInfo::GetLobbyColor(), C4PlayerInfo::HasTeamWon(), C4Player::Init(), IsJoin2TeamAllowed(), RecheckPlayerInfoTeams(), C4Player::ScenarioAndTeamInit(), C4Player::ScenarioInit(), C4PlayerInfoList::UpdatePlayerAttributes(), and C4GameSave::WriteDescPlayers().

384 {
385  C4Team **ppCheck=ppList; int32_t iCnt=iTeamCount;
386  for (; iCnt--; ++ppCheck) if ((*ppCheck)->GetID() == iID) return *ppCheck;
387  return nullptr;
388 }
Definition: C4Teams.h:30
int iCnt
Definition: TstC4NetIO.cpp:32

Here is the caller graph for this function:

C4Team * C4TeamList::GetTeamByIndex ( int32_t  iIndex) const

Definition at line 404 of file C4Teams.cpp.

Referenced by C4GameOverDlg::C4GameOverDlg(), CanLocalChooseTeam(), C4MainMenu::DoRefillInternal(), GetForcedTeamSelection(), GetStartupTeamCount(), Load(), C4Team::RecheckColor(), RecheckPlayerInfoTeams(), and C4GameSave::WriteDescPlayers().

405 {
406  // safety
407  if (!Inside<int32_t>(iIndex, 0, iTeamCount-1)) return nullptr;
408  // direct list access
409  return ppList[iIndex];
410 }

Here is the caller graph for this function:

C4Team * C4TeamList::GetTeamByName ( const char *  szName) const

Definition at line 412 of file C4Teams.cpp.

References iCnt, and SEqual().

413 {
414  assert(szName);
415  C4Team **ppCheck=ppList; int32_t iCnt=iTeamCount;
416  for (; iCnt--; ++ppCheck) if (SEqual((*ppCheck)->GetName(), szName)) return *ppCheck;
417  return nullptr;
418 }
Definition: C4Teams.h:30
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
int iCnt
Definition: TstC4NetIO.cpp:32

Here is the call graph for this function:

C4Team * C4TeamList::GetTeamByPlayerID ( int32_t  iID) const

Definition at line 420 of file C4Teams.cpp.

References iCnt.

Referenced by CanLocalChooseTeam(), GetForcedTeamSelection(), and RecheckPlayerInfoTeams().

421 {
422  C4Team **ppCheck=ppList; int32_t iCnt=iTeamCount;
423  for (; iCnt--; ++ppCheck) if ((*ppCheck)->IsPlayerIDInTeam(iID)) return *ppCheck;
424  return nullptr;
425 }
Definition: C4Teams.h:30
int iCnt
Definition: TstC4NetIO.cpp:32

Here is the caller graph for this function:

int32_t C4TeamList::GetTeamCount ( ) const
inline

Definition at line 158 of file C4Teams.h.

Referenced by C4GameOverDlg::C4GameOverDlg(), GetStartupTeamCount(), ReassignAllTeams(), RecheckPlayerInfoTeams(), and RecheckTeams().

158 { return iTeamCount; }

Here is the caller graph for this function:

TeamDist C4TeamList::GetTeamDist ( ) const
inline

Definition at line 208 of file C4Teams.h.

Referenced by C4PlayerInfo::GetLobbyColor().

208 { return eTeamDist; }

Here is the caller graph for this function:

StdStrBuf C4TeamList::GetTeamDistString ( ) const

Definition at line 784 of file C4Teams.cpp.

785 {
786  // return name of current team distribution setting
787  return GetTeamDistName(eTeamDist);
788 }
bool C4TeamList::HasTeamDistOptions ( ) const

Definition at line 790 of file C4Teams.cpp.

791 {
792  // team distribution can be changed if teams are enabled
793  return fActive;
794 }
bool C4TeamList::IsAutoGenerateTeams ( ) const
inline

Definition at line 172 of file C4Teams.h.

Referenced by C4GameOverDlg::C4GameOverDlg(), CanLocalChooseTeam(), C4MainMenu::DoRefillInternal(), FillTeamDistOptions(), GetForcedTeamSelection(), GetStartupTeamCount(), C4Player::Init(), IsJoin2TeamAllowed(), ReassignAllTeams(), RecheckPlayerInfoTeams(), RecheckTeams(), C4Player::ScenarioAndTeamInit(), and C4GameSave::WriteDescPlayers().

172 { return fAutoGenerateTeams; }

Here is the caller graph for this function:

bool C4TeamList::IsCustom ( ) const
inline

Definition at line 163 of file C4Teams.h.

Referenced by GetStartupTeamCount(), and IsRuntimeJoinTeamChoice().

163 { return fCustom; } // whether teams are not generated as default

Here is the caller graph for this function:

bool C4TeamList::IsHostilityChangeAllowed ( ) const
inline

Definition at line 164 of file C4Teams.h.

Referenced by C4MainMenu::MenuCommand().

164 { return fAllowHostilityChange; } // allow (temporary) hostility changes at runtime

Here is the caller graph for this function:

bool C4TeamList::IsJoin2TeamAllowed ( int32_t  idTeam,
C4PlayerType  plrType 
)

Definition at line 534 of file C4Teams.cpp.

References C4PT_Script, GetTeamByID(), IsAutoGenerateTeams(), C4Team::IsFull(), and TEAMID_New.

Referenced by RecheckPlayerInfoTeams(), and C4Player::ScenarioAndTeamInit().

535 {
536  // join to new team: Only if new teams can be created
537  if (idTeam == TEAMID_New) return IsAutoGenerateTeams();
538  // team number must be valid
539  C4Team *pTeam = GetTeamByID(idTeam);
540  if (!pTeam) return false;
541  // team player count must not exceed the limit, unless it is a script player
542  return !pTeam->IsFull() || plrType == C4PT_Script;
543 }
Definition: C4Teams.h:30
bool IsAutoGenerateTeams() const
Definition: C4Teams.h:172
C4Team * GetTeamByID(int32_t iID) const
Definition: C4Teams.cpp:383
bool IsFull() const
Definition: C4Teams.h:72
const int32_t TEAMID_New
Definition: C4Teams.h:27

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4TeamList::IsMultiTeams ( ) const
inline

Definition at line 162 of file C4Teams.h.

Referenced by C4PlayerInfoList::AssignTeams(), GetGenerateTeamByID(), C4PlayerInfoList::InitLocal(), IsRuntimeJoinTeamChoice(), C4GameLobby::MainDlg::MainDlg(), C4GameLobby::MainDlg::OnRightTabContext(), RecheckPlayerInfoTeams(), and C4GameSave::WriteDescPlayers().

162 { return fActive; } // teams can be selected

Here is the caller graph for this function:

bool C4TeamList::IsRandomTeam ( ) const
inline

Definition at line 170 of file C4Teams.h.

References TEAMDIST_Random, and TEAMDIST_RandomInv.

Referenced by GetStartupTeamCount(), ReassignAllTeams(), RecheckPlayerInfoTeams(), RecheckTeams(), and SetTeamDistribution().

170 { return eTeamDist==TEAMDIST_Random ||eTeamDist==TEAMDIST_RandomInv; } // whether a random team mode is selected

Here is the caller graph for this function:

bool C4TeamList::IsRuntimeJoinTeamChoice ( ) const
inline

Definition at line 173 of file C4Teams.h.

References IsCustom(), and IsMultiTeams().

Referenced by C4Player::Init(), and RecheckPlayerInfoTeams().

173 { return IsCustom() && IsMultiTeams(); } // whether players joining at runtime must select a team first
bool IsMultiTeams() const
Definition: C4Teams.h:162
bool IsCustom() const
Definition: C4Teams.h:163

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4TeamList::IsTeamColors ( ) const
inline

Definition at line 169 of file C4Teams.h.

Referenced by C4Team::AddPlayer(), C4PlayerInfo::GetLobbyColor(), and C4PlayerInfoList::UpdatePlayerAttributes().

169 { return fTeamColors; } // whether team colors are enabled

Here is the caller graph for this function:

bool C4TeamList::IsTeamSwitchAllowed ( ) const
inline

Definition at line 165 of file C4Teams.h.

Referenced by C4MainMenu::ActivateMain(), and C4MainMenu::MenuCommand().

165 { return fAllowTeamSwitch; } // allow permanent team changes at runtime

Here is the caller graph for this function:

bool C4TeamList::IsTeamVisible ( ) const

Definition at line 454 of file C4Teams.cpp.

References C4Network2::isLobbyActive(), Network, and TEAMDIST_RandomInv.

Referenced by C4MessageInput::ProcessInput().

455 {
456  // teams invisible during lobby time if random surprise teams
457  if (eTeamDist == TEAMDIST_RandomInv)
458  if (::Network.isLobbyActive())
459  return false;
460  return true;
461 }
bool isLobbyActive() const
Definition: C4Network2.h:204
C4Network2 Network
Definition: C4Globals.cpp:53

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4TeamList::Load ( C4Group hGroup,
class C4Scenario pInitDefault,
class C4LangStringTable pLang 
)

Definition at line 604 of file C4Teams.cpp.

References C4CFN_Teams, Clear(), C4Scenario::Game, GetTeamByIndex(), C4SGame::IsMelee(), C4Group::LoadEntryString(), mkNamingAdapt(), C4Team::RecheckColor(), and C4LangStringTable::ReplaceStrings().

Referenced by C4GameParameters::Load().

605 {
606  // clear previous
607  Clear();
608  // load file contents
609  StdStrBuf Buf;
610  if (!hGroup.LoadEntryString(C4CFN_Teams, &Buf))
611  {
612  // no teams: Try default init
613  if (!pInitDefault) return false;
614  // no teams defined: Activate default melee teams if a melee rule is found
615  // default: FFA for anything that looks like melee
616  if ( pInitDefault->Game.IsMelee())
617  {
618  fAllowHostilityChange = true;
619  fActive = true;
620  fAutoGenerateTeams = true;
621  }
622  else
623  {
624  // No goals/rules whatsoever: They could be present in the objects.txt, but parsing that would be a bit of
625  // overkill
626  // So just keep the old behaviour here, and disallow teams
627  fAllowHostilityChange = true;
628  fActive = false;
629  }
630  fCustom = false;
631  }
632  else
633  {
634  // team definition file may be localized
635  if (pLang) pLang->ReplaceStrings(Buf);
636  // compile
637  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(*this, "Teams"), Buf, C4CFN_Teams)) return false;
638  }
639  // post-initialization: Generate default team colors
640  int32_t iTeam=0; C4Team *pTeam;
641  while ((pTeam = GetTeamByIndex(iTeam++)))
642  pTeam->RecheckColor(*this);
643  return true;
644 }
#define C4CFN_Teams
Definition: C4Components.h:127
void RecheckColor(C4TeamList &rForList)
Definition: C4Teams.cpp:169
Definition: C4Teams.h:30
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
C4Team * GetTeamByIndex(int32_t iIndex) const
Definition: C4Teams.cpp:404
bool LoadEntryString(const char *szEntryName, StdStrBuf *Buf)
Definition: C4Group.cpp:1932
void Clear()
Definition: C4Teams.cpp:255

Here is the call graph for this function:

Here is the caller graph for this function:

C4TeamList & C4TeamList::operator= ( const C4TeamList rCopy)

Definition at line 273 of file C4Teams.cpp.

References Clear().

274 {
275  Clear();
276  if ((iTeamCount = iTeamCapacity = rCopy.iTeamCount))
277  ppList = new C4Team *[iTeamCapacity];
278  for (int i = 0; i < iTeamCount; i++)
279  ppList[i] = new C4Team(*rCopy.ppList[i]);
280  iLastTeamID = rCopy.iLastTeamID;
281  fAllowHostilityChange = rCopy.fAllowHostilityChange;
282  fAllowTeamSwitch = rCopy.fAllowTeamSwitch;
283  fCustom = rCopy.fCustom;
284  fActive = rCopy.fActive;
285  eTeamDist = rCopy.eTeamDist;
286  fTeamColors = rCopy.fTeamColors;
287  fAutoGenerateTeams = rCopy.fAutoGenerateTeams;
288  sScriptPlayerNames = rCopy.sScriptPlayerNames;
289  return *this;
290 }
Definition: C4Teams.h:30
void Clear()
Definition: C4Teams.cpp:255

Here is the call graph for this function:

void C4TeamList::ReassignAllTeams ( )

Definition at line 713 of file C4Teams.cpp.

References Control, Game, C4PlayerInfoList::GetClientInfoByPlayerID(), C4PlayerInfo::GetID(), C4PlayerInfoList::GetNextPlayerInfoByID(), C4PlayerInfo::GetTeam(), GetTeamCount(), C4PlayerInfo::HasJoinIssued(), IsAutoGenerateTeams(), C4GameControl::isCtrlHost(), IsRandomTeam(), C4Game::PlayerInfos, RecheckPlayerInfoTeams(), RecheckPlayers(), C4PlayerInfo::SetTeam(), and C4ClientPlayerInfos::SetUpdated().

Referenced by RecheckTeams(), and SetTeamDistribution().

714 {
715  assert(::Control.isCtrlHost());
716  if (!::Control.isCtrlHost()) return;
717  // go through all player infos; reset team in them
718  int32_t idStart = -1; C4PlayerInfo *pNfo;
719  while ((pNfo = Game.PlayerInfos.GetNextPlayerInfoByID(idStart)))
720  {
721  idStart = pNfo->GetID();
722  if (pNfo->HasJoinIssued()) continue;
723  pNfo->SetTeam(0);
724  // mark changed info as updated
726  assert(pCltInfo);
727  if (pCltInfo)
728  {
729  pCltInfo->SetUpdated();
730  }
731  }
732  // clear players from team lists
733  RecheckPlayers();
734  // in random autogenerate mode, there must be exactly two teams
735  if (IsRandomTeam())
736  if (IsAutoGenerateTeams() && GetTeamCount() != 2)
737  {
738  ClearTeams();
739  GenerateDefaultTeams(2);
740  }
741  // reassign them
742  idStart = -1;
743  while ((pNfo = Game.PlayerInfos.GetNextPlayerInfoByID(idStart)))
744  {
745  idStart = pNfo->GetID();
746  if (pNfo->HasJoinIssued()) continue;
747  assert(!pNfo->GetTeam());
748  RecheckPlayerInfoTeams(*pNfo, true);
749  }
750 }
void RecheckPlayers()
Definition: C4Teams.cpp:663
bool isCtrlHost() const
Definition: C4GameControl.h:99
C4Game Game
Definition: C4Globals.cpp:52
bool IsRandomTeam() const
Definition: C4Teams.h:170
void SetTeam(int32_t idToTeam)
Definition: C4PlayerInfo.h:120
bool IsAutoGenerateTeams() const
Definition: C4Teams.h:172
C4PlayerInfo * GetNextPlayerInfoByID(int32_t id) const
C4ClientPlayerInfos * GetClientInfoByPlayerID(int32_t id) const
bool RecheckPlayerInfoTeams(C4PlayerInfo &rNewJoin, bool fByHost)
Definition: C4Teams.cpp:463
C4GameControl Control
int32_t GetTeam() const
Definition: C4PlayerInfo.h:195
bool HasJoinIssued() const
Definition: C4PlayerInfo.h:167
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
int32_t GetTeamCount() const
Definition: C4Teams.h:158
int32_t GetID() const
Definition: C4PlayerInfo.h:194

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4TeamList::RecheckPlayerInfoTeams ( C4PlayerInfo rNewJoin,
bool  fByHost 
)

Definition at line 463 of file C4Teams.cpp.

References C4Team::AddPlayer(), C4PT_User, C4Game::fLobby, Game, C4Team::GetID(), C4PlayerInfo::GetID(), C4Team::GetPlayerCount(), GetRandomSmallestTeam(), C4PlayerInfo::GetTeam(), GetTeamByID(), GetTeamByIndex(), GetTeamByPlayerID(), GetTeamCount(), C4PlayerInfo::GetType(), IsAutoGenerateTeams(), C4Network2::isEnabled(), IsJoin2TeamAllowed(), C4Network2::isLobbyActive(), IsMultiTeams(), C4Network2Status::isPastLobby(), IsRandomTeam(), IsRuntimeJoinTeamChoice(), Network, C4PlayerInfo::SetTeam(), C4Network2::Status, TEAMDIST_Free, TEAMDIST_Host, and TEAMID_New.

Referenced by C4PlayerInfoList::AssignTeams(), and ReassignAllTeams().

464 {
465  // only if enabled
466  assert(IsMultiTeams());
467  if (!IsMultiTeams()) return false;
468  // check whether a new team is to be assigned first
469  C4Team *pCurrentTeam = GetTeamByPlayerID(rNewJoin.GetID());
470  int32_t idCurrentTeam = pCurrentTeam ? pCurrentTeam->GetID() : 0;
471  if (rNewJoin.GetTeam())
472  {
473  // was that team a change to the current team?
474  // no change anyway: OK, skip this info
475  if (idCurrentTeam == rNewJoin.GetTeam()) return true;
476  // the player had a different team assigned: Check if changes are allowed at all
477  if (eTeamDist == TEAMDIST_Free || (eTeamDist == TEAMDIST_Host && fByHost))
478  // also make sure that selecting this team is allowed, e.g. doesn't break the team limit
479  // this also checks whether the team number is a valid team - but it would accept TEAMID_New, which shouldn't be used in player infos!
480  if (rNewJoin.GetTeam() != TEAMID_New && IsJoin2TeamAllowed(rNewJoin.GetTeam(), rNewJoin.GetType()))
481  // okay; accept change
482  return true;
483  // Reject change by reassigning the current team
484  rNewJoin.SetTeam(idCurrentTeam);
485  // and determine a new team, if none has been assigned yet
486  if (idCurrentTeam) return true;
487  }
488  // new team assignment
489  // teams are always needed in the lobby, so there's a team preset to change
490  // for runtime joins, teams are needed if specified by teams.txt or if any teams have been created before (to avoid mixed team-noteam-scenarios)
491  // but only assign teams in runtime join if the player won't pick it himself
492  bool fWillHaveLobby = ::Network.isEnabled() && !::Network.Status.isPastLobby() && Game.fLobby;
493  bool fHasOrWillHaveLobby = ::Network.isLobbyActive() || fWillHaveLobby;
494  bool fCanPickTeamAtRuntime = !IsRandomTeam() && (rNewJoin.GetType() == C4PT_User) && IsRuntimeJoinTeamChoice();
495  bool fIsTeamNeeded = IsRuntimeJoinTeamChoice() || GetTeamCount();
496  if (!fHasOrWillHaveLobby && (!fIsTeamNeeded || fCanPickTeamAtRuntime)) return false;
497  // get least-used team
498  C4Team *pAssignTeam=nullptr;
499  C4Team *pLowestTeam = GetRandomSmallestTeam();
500  // melee mode
501  if (IsAutoGenerateTeams() && !IsRandomTeam())
502  {
503  // reuse old team only if it's empty
504  if (pLowestTeam && !pLowestTeam->GetPlayerCount())
505  pAssignTeam = pLowestTeam;
506  else
507  {
508  // no empty team: generate new
509  GenerateDefaultTeams(iLastTeamID+1);
510  pAssignTeam = GetTeamByID(iLastTeamID);
511  }
512  }
513  else
514  {
515  if (!pLowestTeam)
516  {
517  // not enough teams defined in teamwork mode?
518  // then create two teams as default
519  if (!GetTeamByIndex(1))
520  GenerateDefaultTeams(2);
521  else
522  // otherwise, all defined teams are full. This is a scenario error, because MaxPlayer should have been adjusted
523  return false;
524  pLowestTeam = GetTeamByIndex(0);
525  }
526  pAssignTeam = pLowestTeam;
527  }
528  // assign it
529  if (!pAssignTeam) return false;
530  pAssignTeam->AddPlayer(rNewJoin, true);
531  return true;
532 }
int32_t GetPlayerCount() const
Definition: C4Teams.h:64
int32_t GetID() const
Definition: C4Teams.h:66
C4Game Game
Definition: C4Globals.cpp:52
bool IsRandomTeam() const
Definition: C4Teams.h:170
Definition: C4Teams.h:30
bool isLobbyActive() const
Definition: C4Network2.h:204
void SetTeam(int32_t idToTeam)
Definition: C4PlayerInfo.h:120
bool IsAutoGenerateTeams() const
Definition: C4Teams.h:172
bool IsMultiTeams() const
Definition: C4Teams.h:162
C4Team * GetTeamByID(int32_t iID) const
Definition: C4Teams.cpp:383
C4Team * GetRandomSmallestTeam() const
Definition: C4Teams.cpp:435
C4Network2 Network
Definition: C4Globals.cpp:53
bool isPastLobby() const
Definition: C4Network2.h:88
void AddPlayer(class C4PlayerInfo &rInfo, bool fAdjustPlayer)
Definition: C4Teams.cpp:52
C4Team * GetTeamByIndex(int32_t iIndex) const
Definition: C4Teams.cpp:404
int32_t GetTeam() const
Definition: C4PlayerInfo.h:195
C4Network2Status Status
Definition: C4Network2.h:122
bool isEnabled() const
Definition: C4Network2.h:203
C4Team * GetTeamByPlayerID(int32_t iID) const
Definition: C4Teams.cpp:420
const int32_t TEAMID_New
Definition: C4Teams.h:27
int32_t GetTeamCount() const
Definition: C4Teams.h:158
int32_t GetID() const
Definition: C4PlayerInfo.h:194
C4PlayerType GetType() const
Definition: C4PlayerInfo.h:152
bool IsRuntimeJoinTeamChoice() const
Definition: C4Teams.h:173
bool IsJoin2TeamAllowed(int32_t idTeam, C4PlayerType plrType)
Definition: C4Teams.cpp:534
bool fLobby
Definition: C4Game.h:118

Here is the call graph for this function:

Here is the caller graph for this function:

void C4TeamList::RecheckPlayers ( )

Definition at line 663 of file C4Teams.cpp.

References iCnt.

Referenced by C4PlayerInfoList::CreateRestoreInfosForJoinedScriptPlayers(), C4Network2Players::HandlePlayerInfo(), C4Game::InitGame(), C4Network2Players::OnClientPart(), ReassignAllTeams(), and C4PlayerInfoList::RestoreSavegameInfos().

664 {
665  C4Team **ppCheck=ppList; int32_t iCnt=iTeamCount;
666  for (; iCnt--; ++ppCheck) (*ppCheck)->RecheckPlayers();
667 }
Definition: C4Teams.h:30
int iCnt
Definition: TstC4NetIO.cpp:32

Here is the caller graph for this function:

void C4TeamList::RecheckTeams ( )

Definition at line 669 of file C4Teams.cpp.

References C4Team::AddPlayer(), Control, Game, C4PlayerInfoList::GetClientInfoByPlayerID(), C4Team::GetFirstUnjoinedPlayerID(), C4Team::GetPlayerCount(), C4PlayerInfoList::GetPlayerInfoByID(), GetRandomSmallestTeam(), GetTeamCount(), iCnt, IsAutoGenerateTeams(), C4GameControl::isCtrlHost(), IsRandomTeam(), C4Game::PlayerInfos, ReassignAllTeams(), C4Team::RemovePlayerByID(), and C4ClientPlayerInfos::SetUpdated().

Referenced by C4Network2Players::HandlePlayerInfo(), C4Network2Players::OnClientPart(), and SetTeamDistribution().

670 {
671  // automatic team distributions only
672  if (!IsRandomTeam()) return;
673  // host decides random teams
674  if (!::Control.isCtrlHost()) return;
675  // random teams in auto generate mode? Make sure there are exactly two teams
676  if (IsAutoGenerateTeams() && GetTeamCount() != 2)
677  {
679  return;
680  }
681  // redistribute players of largest team that has relocatable players left towards smaller teams
682  for (;;)
683  {
684  C4Team *pLowestTeam = GetRandomSmallestTeam();
685  if (!pLowestTeam) break; // no teams: Nothing to re-distribute.
686  // get largest team that has relocateable players
687  C4Team *pLargestTeam = nullptr;
688  C4Team **ppCheck=ppList; int32_t iCnt=iTeamCount;
689  for (; iCnt--; ++ppCheck) if (!pLargestTeam || pLargestTeam->GetPlayerCount() > (*ppCheck)->GetPlayerCount())
690  if ((*ppCheck)->GetFirstUnjoinedPlayerID())
691  pLargestTeam = *ppCheck;
692  // no team can redistribute?
693  if (!pLargestTeam) break;
694  // redistribution won't help much?
695  if (pLargestTeam->GetPlayerCount() - pLowestTeam->GetPlayerCount() <= 1) break;
696  // okay; redistribute one player!
697  int32_t idRedistPlayer = pLargestTeam->GetFirstUnjoinedPlayerID();
698  C4PlayerInfo *pInfo = Game.PlayerInfos.GetPlayerInfoByID(idRedistPlayer);
699  assert(pInfo);
700  if (!pInfo) break; // umn...serious problems
701  pLargestTeam->RemovePlayerByID(idRedistPlayer);
702  pLowestTeam->AddPlayer(*pInfo, true);
703  C4ClientPlayerInfos *pClrInfo = Game.PlayerInfos.GetClientInfoByPlayerID(idRedistPlayer);
704  assert(pClrInfo);
705  // player info change: mark updated to remote clients get information
706  if (pClrInfo)
707  {
708  pClrInfo->SetUpdated();
709  }
710  }
711 }
int32_t GetPlayerCount() const
Definition: C4Teams.h:64
bool isCtrlHost() const
Definition: C4GameControl.h:99
C4Game Game
Definition: C4Globals.cpp:52
bool IsRandomTeam() const
Definition: C4Teams.h:170
Definition: C4Teams.h:30
bool IsAutoGenerateTeams() const
Definition: C4Teams.h:172
C4Team * GetRandomSmallestTeam() const
Definition: C4Teams.cpp:435
void ReassignAllTeams()
Definition: C4Teams.cpp:713
C4PlayerInfo * GetPlayerInfoByID(int32_t id) const
C4ClientPlayerInfos * GetClientInfoByPlayerID(int32_t id) const
int iCnt
Definition: TstC4NetIO.cpp:32
C4GameControl Control
void AddPlayer(class C4PlayerInfo &rInfo, bool fAdjustPlayer)
Definition: C4Teams.cpp:52
void RemovePlayerByID(int32_t iID)
Definition: C4Teams.cpp:94
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
int32_t GetFirstUnjoinedPlayerID() const
Definition: C4Teams.cpp:112
int32_t GetTeamCount() const
Definition: C4Teams.h:158

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4TeamList::Save ( C4Group hGroup)

Definition at line 646 of file C4Teams.cpp.

References C4Group::Add(), C4CFN_Teams, C4Group::DeleteEntry(), and mkNamingAdapt().

647 {
648  // remove previous entry from group
649  hGroup.DeleteEntry(C4CFN_Teams);
650  // decompile
651  try
652  {
653  StdStrBuf Buf = DecompileToBuf<StdCompilerINIWrite>(mkNamingAdapt(*this, "Teams"));
654  // save it
655  hGroup.Add(C4CFN_Teams, Buf, false, true);
656  }
657  catch (StdCompiler::Exception *)
658  { return false; }
659  // done, success
660  return true;
661 }
#define C4CFN_Teams
Definition: C4Components.h:127
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
bool DeleteEntry(const char *szFilename, bool fRecycle=false)
Definition: C4Group.cpp:1384
bool Add(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1316

Here is the call graph for this function:

void C4TeamList::SendSetTeamColors ( bool  fEnabled)

Definition at line 820 of file C4Teams.cpp.

References C4CVT_TeamColors, CDT_Sync, CID_Set, Control, and C4GameControl::DoInput().

821 {
822  // set it for all clients
824 }
C4GameControl Control
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)

Here is the call graph for this function:

void C4TeamList::SendSetTeamDist ( TeamDist  eNewDist)

Definition at line 777 of file C4Teams.cpp.

References C4CVT_TeamDistribution, CDT_Sync, CID_Set, Control, C4GameControl::DoInput(), and C4GameControl::isCtrlHost().

778 {
779  assert(::Control.isCtrlHost());
780  // set it for all clients
782 }
bool isCtrlHost() const
Definition: C4GameControl.h:99
C4GameControl Control
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)

Here is the call graph for this function:

void C4TeamList::SetTeamColors ( bool  fEnabled)

Definition at line 826 of file C4Teams.cpp.

References Control, Game, C4GameControl::isCtrlHost(), C4Network2::isEnabled(), Network, C4Game::PlayerInfos, C4Network2::Players, C4Network2Players::SendUpdatedPlayers(), and C4PlayerInfoList::UpdatePlayerAttributes().

827 {
828  // change only
829  if (fEnabled == fTeamColors) return;
830  // reflect change
831  fTeamColors = fEnabled;
832  // update colors of all players
833  if (!::Control.isCtrlHost()) return;
834  // go through all player infos; reset color in them
835  Game.PlayerInfos.UpdatePlayerAttributes(); // sets team and savegame colors
836  if (::Network.isEnabled())
837  {
838  // sends color updates to all clients
840  }
841 }
bool isCtrlHost() const
Definition: C4GameControl.h:99
C4Game Game
Definition: C4Globals.cpp:52
void UpdatePlayerAttributes(C4ClientPlayerInfos *pForInfo, bool fResolveConflicts)
C4Network2 Network
Definition: C4Globals.cpp:53
C4GameControl Control
bool isEnabled() const
Definition: C4Network2.h:203
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
C4Network2Players Players
Definition: C4Network2.h:119

Here is the call graph for this function:

void C4TeamList::SetTeamDistribution ( TeamDist  eToVal)

Definition at line 796 of file C4Teams.cpp.

References Control, Inside(), C4GameControl::isCtrlHost(), C4Network2::isEnabled(), IsRandomTeam(), Network, C4Network2::Players, ReassignAllTeams(), RecheckTeams(), C4Network2Players::SendUpdatedPlayers(), TEAMDIST_First, TEAMDIST_Last, and TEAMDIST_None.

797 {
798  if (!Inside(eToVal, TEAMDIST_First, TEAMDIST_Last)) { assert(false); return; }
799  eTeamDist = eToVal;
800  // team distribution mode changed: Host may beed to redistribute
801  if (::Control.isCtrlHost())
802  {
803  // if a random team mode was set, reassign all teams so it's really random.
804  // Also reassign in no-team-mode so enough teams for all players exist
805  if (IsRandomTeam() || eTeamDist==TEAMDIST_None)
807  else
808  {
809  // otherwise, it's sufficient to just reassign any teams that are incorrect for the current mode
810  RecheckTeams();
811  }
812  // send updates to other clients and reset flags
813  if (::Network.isEnabled())
814  {
816  }
817  }
818 }
void RecheckTeams()
Definition: C4Teams.cpp:669
bool isCtrlHost() const
Definition: C4GameControl.h:99
bool IsRandomTeam() const
Definition: C4Teams.h:170
void ReassignAllTeams()
Definition: C4Teams.cpp:713
C4Network2 Network
Definition: C4Globals.cpp:53
C4GameControl Control
bool isEnabled() const
Definition: C4Network2.h:203
C4Network2Players Players
Definition: C4Network2.h:119
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43

Here is the call graph for this function:


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