OpenClonk
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 EnsureTeamCount ()
 
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

◆ ConfigValue

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.

93  {
94  TEAM_None = 0,
95  TEAM_Custom = 1,
96  TEAM_Active = 2,
98  TEAM_Dist = 4,
101  TEAM_TeamColors = 7
102  };
@ TEAM_None
Definition: C4Teams.h:94
@ TEAM_Dist
Definition: C4Teams.h:98
@ TEAM_Active
Definition: C4Teams.h:96
@ TEAM_AllowTeamSwitch
Definition: C4Teams.h:99
@ TEAM_Custom
Definition: C4Teams.h:95
@ TEAM_AllowHostilityChange
Definition: C4Teams.h:97
@ TEAM_TeamColors
Definition: C4Teams.h:101
@ TEAM_AutoGenerateTeams
Definition: C4Teams.h:100

◆ TeamDist

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  };
@ TEAMDIST_First
Definition: C4Teams.h:107
@ TEAMDIST_Random
Definition: C4Teams.h:111
@ TEAMDIST_Host
Definition: C4Teams.h:109
@ TEAMDIST_Last
Definition: C4Teams.h:113
@ TEAMDIST_None
Definition: C4Teams.h:110
@ TEAMDIST_Free
Definition: C4Teams.h:108
@ TEAMDIST_RandomInv
Definition: C4Teams.h:112

Constructor & Destructor Documentation

◆ C4TeamList()

C4TeamList::C4TeamList ( )
default

◆ ~C4TeamList()

C4TeamList::~C4TeamList ( )
inline

Definition at line 135 of file C4Teams.h.

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

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ CanLocalChooseTeam() [1/2]

bool C4TeamList::CanLocalChooseTeam ( ) const

Definition at line 292 of file C4Teams.cpp.

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 }
C4GameControl Control
bool isCtrlHost() const
Definition: C4GameControl.h:99

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

Referenced by CanLocalChooseTeam().

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

◆ CanLocalChooseTeam() [2/2]

bool C4TeamList::CanLocalChooseTeam ( int32_t  idPlayer) const

Definition at line 309 of file C4Teams.cpp.

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:31
C4Team * GetTeamByIndex(int32_t iIndex) const
Definition: C4Teams.cpp:404
C4Team * GetTeamByPlayerID(int32_t iID) const
Definition: C4Teams.cpp:420
bool CanLocalChooseTeam() const
Definition: C4Teams.cpp:292
bool IsAutoGenerateTeams() const
Definition: C4Teams.h:172

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

Here is the call graph for this function:

◆ CanLocalSeeTeam()

bool C4TeamList::CanLocalSeeTeam ( ) const

Definition at line 327 of file C4Teams.cpp.

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 }
C4Game Game
Definition: C4Globals.cpp:52
bool IsRunning
Definition: C4Game.h:140

References Game, C4Game::IsRunning, and TEAMDIST_RandomInv.

◆ Clear()

void C4TeamList::Clear ( )

Definition at line 255 of file C4Teams.cpp.

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

References StdStrBuf::Clear(), and TEAMDIST_Free.

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

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

◆ CompileFunc()

void C4TeamList::CompileFunc ( StdCompiler pComp)

Definition at line 545 of file C4Teams.cpp.

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 }
StdPtrAdapt< T > mkPtrAdaptNoNull(T *&rpObj)
Definition: StdAdaptors.h:638
StdArrayAdapt< T, M > mkArrayAdaptMap(T *pArray, int iSize, M &&map)
Definition: StdAdaptors.h:340
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:490
StdNamingCountAdapt< int_t > mkNamingCountAdapt(int_t &iCount, const char *szName)
Definition: StdAdaptors.h:1008
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
Definition: StdAdaptors.h:795
int32_t GetLargestTeamID() const
Definition: C4Teams.cpp:427
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53

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().

Here is the call graph for this function:

◆ CreateTeam()

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

Definition at line 360 of file C4Teams.cpp.

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 }
const unsigned int C4MaxName
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
int32_t iID
Definition: C4Teams.h:46
void RecheckColor(C4TeamList &rForList)
Definition: C4Teams.cpp:169
char Name[C4MaxName+1]
Definition: C4Teams.h:47

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

Here is the call graph for this function:

◆ EnforceLeagueRules()

void C4TeamList::EnforceLeagueRules ( )

Definition at line 856 of file C4Teams.cpp.

857 {
858  // enforce some league settings
859  // allow temp hostility switching; often used e.g. to unstick friendly Clonks, but:
860  fAllowTeamSwitch = false; // switching teams in league games? Yeah, sure...
861 }

Referenced by C4GameParameters::EnforceLeagueRules().

Here is the caller graph for this function:

◆ EnsureTeamCount()

void C4TeamList::EnsureTeamCount ( )

Definition at line 719 of file C4Teams.cpp.

720 {
721  // in random autogenerate mode, there must be exactly two teams
722  if (IsRandomTeam())
723  {
724  if (IsAutoGenerateTeams() && GetTeamCount() != 2)
725  {
726  ClearTeams();
727  GenerateDefaultTeams(2);
728  }
729  }
730 }
int32_t GetTeamCount() const
Definition: C4Teams.h:158
bool IsRandomTeam() const
Definition: C4Teams.h:170

References GetTeamCount(), IsAutoGenerateTeams(), and IsRandomTeam().

Referenced by ReassignAllTeams(), and RecheckTeams().

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

◆ FillTeamDistOptions()

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

Definition at line 778 of file C4Teams.cpp.

779 {
780  // no teams if disabled
781  if (!fActive) return;
782  // team distribution options
783  pFiller->AddEntry(GetTeamDistName(TEAMDIST_Free).getData(), TEAMDIST_Free);
784  pFiller->AddEntry(GetTeamDistName(TEAMDIST_Host).getData(), TEAMDIST_Host);
785  if (IsAutoGenerateTeams()) pFiller->AddEntry(GetTeamDistName(TEAMDIST_None).getData(), TEAMDIST_None); // no teams: only for regular melees
786  pFiller->AddEntry(GetTeamDistName(TEAMDIST_Random).getData(), TEAMDIST_Random);
787  pFiller->AddEntry(GetTeamDistName(TEAMDIST_RandomInv).getData(), TEAMDIST_RandomInv);
788  }
void AddEntry(const char *szText, int32_t id)

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

Here is the call graph for this function:

◆ GetForcedTeamSelection()

int32_t C4TeamList::GetForcedTeamSelection ( int32_t  idForPlayer) const

Definition at line 863 of file C4Teams.cpp.

864 {
865  // if there's only one team for the player to join, return that team ID
866  C4Team *pOKTeam = nullptr, *pCheck;
867  if (idForPlayer) pOKTeam = GetTeamByPlayerID(idForPlayer); // curent team is always possible, even if full
868  int32_t iCheckTeam=0;
869  while ((pCheck = GetTeamByIndex(iCheckTeam++)))
870  if (!pCheck->IsFull())
871  {
872  // this team could be joined
873  if (pOKTeam && pOKTeam != pCheck)
874  {
875  // there already was a team that could be joined
876  // two alternatives -> team selection is not forced
877  return 0;
878  }
879  pOKTeam = pCheck;
880  }
881  // was there a team that could be joined?
882  if (pOKTeam)
883  {
884  // if teams are generated on the fly, there would always be the possibility of creating a new team }
885  if (IsAutoGenerateTeams()) return 0;
886  // otherwise, this team is forced!
887  return pOKTeam->GetID();
888  }
889  // no team could be joined: Teams auto generated?
890  if (IsAutoGenerateTeams())
891  {
892  // then the only possible way is to join a new team
893  return TEAMID_New;
894  }
895  // otherwise, nothing can be done...
896  return 0;
897 }
const int32_t TEAMID_New
Definition: C4Teams.h:27
int32_t GetID() const
Definition: C4Teams.h:66

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

Referenced by C4Player::Execute().

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

◆ GetGenerateTeamByID()

C4Team * C4TeamList::GetGenerateTeamByID ( int32_t  iID)

Definition at line 390 of file C4Teams.cpp.

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 }
bool IsMultiTeams() const
Definition: C4Teams.h:162
C4Team * GetTeamByID(int32_t iID) const
Definition: C4Teams.cpp:383

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

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

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

◆ GetLargestTeamID()

int32_t C4TeamList::GetLargestTeamID ( ) const

Definition at line 427 of file C4Teams.cpp.

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 }
int iCnt
Definition: TstC4NetIO.cpp:32

References iCnt.

Referenced by CompileFunc(), and GetGenerateTeamByID().

Here is the caller graph for this function:

◆ GetMaxScriptPlayers()

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

◆ GetRandomSmallestTeam()

C4Team * C4TeamList::GetRandomSmallestTeam ( ) const

Definition at line 435 of file C4Teams.cpp.

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 }
uint32_t UnsyncedRandom()
Definition: C4Random.cpp:58
int32_t GetPlayerCount() const
Definition: C4Teams.h:64

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

Referenced by RecheckPlayerInfoTeams(), and RecheckTeams().

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

◆ GetScriptPlayerName()

StdStrBuf C4TeamList::GetScriptPlayerName ( ) const

Definition at line 899 of file C4Teams.cpp.

900 {
901  // get a name to assign to a new script player. Try to avoid name conflicts
902  if (!sScriptPlayerNames.getLength()) return StdStrBuf(LoadResStr("IDS_TEXT_COMPUTER")); // default name
903  // test available script names
904  int32_t iNameIdx = 0; StdStrBuf sOut;
905  while (sScriptPlayerNames.GetSection(iNameIdx++, &sOut, '|'))
907  return sOut;
908  // none are available: Return a random name
909  sScriptPlayerNames.GetSection(UnsyncedRandom(iNameIdx-1), &sOut, '|');
910  return sOut;
911 }
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4PlayerInfoList & PlayerInfos
Definition: C4Game.h:71
C4PlayerInfo * GetActivePlayerInfoByName(const char *szName)
const char * getData() const
Definition: StdBuf.h:442
size_t getLength() const
Definition: StdBuf.h:445
bool GetSection(size_t idx, StdStrBuf *psOutSection, char cSeparator=';') const
Definition: StdBuf.cpp:369

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

Here is the call graph for this function:

◆ GetStartupTeamCount()

int32_t C4TeamList::GetStartupTeamCount ( int32_t  startup_player_count)

Definition at line 913 of file C4Teams.cpp.

914 {
915  // Count non-empty teams
916  int32_t i_team = 0; C4Team *team;
917  int32_t team_count = 0;
918  while ((team = GetTeamByIndex(i_team++)))
919  {
920  if (team->GetPlayerCount() > 0) ++team_count;
921  }
922  // No populated teams found? This can happen in non-network mode when no players are assigned
923  if (!team_count)
924  {
925  // Teams have not been selected yet, but the map script may want to have an estimate
926  // in this case, calculate prospective teams from startup player count
927  if (IsCustom() && !IsAutoGenerateTeams())
928  {
929  // Teams are pre-defined. Assume players will try to distribute broadly on these teams
930  team_count = std::min<int32_t>(startup_player_count, GetTeamCount());
931  }
932  else if (IsRandomTeam())
933  {
934  // Randomized teams: Players will be put into two teams.
935  team_count = std::min<int32_t>(startup_player_count, 2);
936  }
937  else
938  {
939  // Teams are auto-added -> fallback to player count
940  team_count = startup_player_count;
941  }
942  }
943 
944  return team_count;
945 }
bool IsCustom() const
Definition: C4Teams.h:163

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

Here is the call graph for this function:

◆ GetTeamByID()

C4Team * C4TeamList::GetTeamByID ( int32_t  iID) const

Definition at line 383 of file C4Teams.cpp.

384 {
385  C4Team **ppCheck=ppList; int32_t iCnt=iTeamCount;
386  for (; iCnt--; ++ppCheck) if ((*ppCheck)->GetID() == iID) return *ppCheck;
387  return nullptr;
388 }

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().

Here is the caller graph for this function:

◆ GetTeamByIndex()

C4Team * C4TeamList::GetTeamByIndex ( int32_t  iIndex) const

Definition at line 404 of file C4Teams.cpp.

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

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

Here is the caller graph for this function:

◆ GetTeamByName()

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

Definition at line 412 of file C4Teams.cpp.

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 }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93

References iCnt, and SEqual().

Here is the call graph for this function:

◆ GetTeamByPlayerID()

C4Team * C4TeamList::GetTeamByPlayerID ( int32_t  iID) const

Definition at line 420 of file C4Teams.cpp.

421 {
422  C4Team **ppCheck=ppList; int32_t iCnt=iTeamCount;
423  for (; iCnt--; ++ppCheck) if ((*ppCheck)->IsPlayerIDInTeam(iID)) return *ppCheck;
424  return nullptr;
425 }

References iCnt.

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

Here is the caller graph for this function:

◆ GetTeamCount()

int32_t C4TeamList::GetTeamCount ( ) const
inline

Definition at line 158 of file C4Teams.h.

158 { return iTeamCount; }

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

Here is the caller graph for this function:

◆ GetTeamDist()

TeamDist C4TeamList::GetTeamDist ( ) const
inline

Definition at line 211 of file C4Teams.h.

211 { return eTeamDist; }

Referenced by C4PlayerInfo::GetLobbyColor().

Here is the caller graph for this function:

◆ GetTeamDistString()

StdStrBuf C4TeamList::GetTeamDistString ( ) const

Definition at line 797 of file C4Teams.cpp.

798 {
799  // return name of current team distribution setting
800  return GetTeamDistName(eTeamDist);
801 }

◆ HasTeamDistOptions()

bool C4TeamList::HasTeamDistOptions ( ) const

Definition at line 803 of file C4Teams.cpp.

804 {
805  // team distribution can be changed if teams are enabled
806  return fActive;
807 }

◆ IsAutoGenerateTeams()

bool C4TeamList::IsAutoGenerateTeams ( ) const
inline

Definition at line 172 of file C4Teams.h.

172 { return fAutoGenerateTeams; }

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

Here is the caller graph for this function:

◆ IsCustom()

bool C4TeamList::IsCustom ( ) const
inline

Definition at line 163 of file C4Teams.h.

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

Referenced by GetStartupTeamCount(), and IsRuntimeJoinTeamChoice().

Here is the caller graph for this function:

◆ IsHostilityChangeAllowed()

bool C4TeamList::IsHostilityChangeAllowed ( ) const
inline

Definition at line 164 of file C4Teams.h.

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

Referenced by C4MainMenu::MenuCommand().

Here is the caller graph for this function:

◆ IsJoin2TeamAllowed()

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

Definition at line 534 of file C4Teams.cpp.

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 }
@ C4PT_Script
Definition: C4Constants.h:155
bool IsFull() const
Definition: C4Teams.h:72

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

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

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

◆ IsMultiTeams()

bool C4TeamList::IsMultiTeams ( ) const
inline

Definition at line 162 of file C4Teams.h.

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

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

Here is the caller graph for this function:

◆ IsRandomTeam()

bool C4TeamList::IsRandomTeam ( ) const
inline

Definition at line 170 of file C4Teams.h.

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

References TEAMDIST_Random, and TEAMDIST_RandomInv.

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

Here is the caller graph for this function:

◆ IsRuntimeJoinTeamChoice()

bool C4TeamList::IsRuntimeJoinTeamChoice ( ) const
inline

Definition at line 173 of file C4Teams.h.

173 { return IsCustom() && IsMultiTeams(); } // whether players joining at runtime must select a team first

References IsCustom(), and IsMultiTeams().

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

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

◆ IsTeamColors()

bool C4TeamList::IsTeamColors ( ) const
inline

Definition at line 169 of file C4Teams.h.

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

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

Here is the caller graph for this function:

◆ IsTeamSwitchAllowed()

bool C4TeamList::IsTeamSwitchAllowed ( ) const
inline

Definition at line 165 of file C4Teams.h.

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

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

Here is the caller graph for this function:

◆ IsTeamVisible()

bool C4TeamList::IsTeamVisible ( ) const

Definition at line 454 of file C4Teams.cpp.

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 }
C4Network2 Network
Definition: C4Globals.cpp:53
bool isLobbyActive() const
Definition: C4Network2.h:204

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

Referenced by C4MessageInput::ProcessInput().

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

◆ Load()

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

Definition at line 604 of file C4Teams.cpp.

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
bool LoadEntryString(const char *entry_name, StdStrBuf *buffer)
Definition: C4Group.cpp:2430

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

Referenced by C4GameParameters::Load().

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

◆ operator=()

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

Definition at line 273 of file C4Teams.cpp.

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 }

References Clear().

Here is the call graph for this function:

◆ ReassignAllTeams()

void C4TeamList::ReassignAllTeams ( )

Definition at line 732 of file C4Teams.cpp.

733 {
734  assert(::Control.isCtrlHost());
735  if (!::Control.isCtrlHost()) return;
736  // go through all player infos; reset team in them
737  int32_t idStart = -1; C4PlayerInfo *pNfo;
738  while ((pNfo = Game.PlayerInfos.GetNextPlayerInfoByID(idStart)))
739  {
740  idStart = pNfo->GetID();
741  if (pNfo->HasJoinIssued()) continue;
742  pNfo->SetTeam(0);
743  // mark changed info as updated
745  assert(pCltInfo);
746  if (pCltInfo)
747  {
748  pCltInfo->SetUpdated();
749  }
750  }
751  // clear players from team lists
752  RecheckPlayers();
753  EnsureTeamCount();
754  // reassign them
755  idStart = -1;
756  while ((pNfo = Game.PlayerInfos.GetNextPlayerInfoByID(idStart)))
757  {
758  idStart = pNfo->GetID();
759  if (pNfo->HasJoinIssued()) continue;
760  assert(!pNfo->GetTeam());
761  RecheckPlayerInfoTeams(*pNfo, true);
762  }
763 }
int32_t GetTeam() const
Definition: C4PlayerInfo.h:195
bool HasJoinIssued() const
Definition: C4PlayerInfo.h:167
int32_t GetID() const
Definition: C4PlayerInfo.h:194
void SetTeam(int32_t idToTeam)
Definition: C4PlayerInfo.h:120
C4PlayerInfo * GetNextPlayerInfoByID(int32_t id) const
C4ClientPlayerInfos * GetClientInfoByPlayerID(int32_t id) const
void EnsureTeamCount()
Definition: C4Teams.cpp:719
void RecheckPlayers()
Definition: C4Teams.cpp:663
bool RecheckPlayerInfoTeams(C4PlayerInfo &rNewJoin, bool fByHost)
Definition: C4Teams.cpp:463

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

Referenced by RecheckTeams(), and SetTeamDistribution().

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

◆ RecheckPlayerInfoTeams()

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

Definition at line 463 of file C4Teams.cpp.

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 }
@ C4PT_User
Definition: C4Constants.h:154
bool fLobby
Definition: C4Game.h:119
C4Network2Status Status
Definition: C4Network2.h:122
bool isEnabled() const
Definition: C4Network2.h:203
bool isPastLobby() const
Definition: C4Network2.h:88
C4PlayerType GetType() const
Definition: C4PlayerInfo.h:152
void AddPlayer(class C4PlayerInfo &rInfo, bool fAdjustPlayer)
Definition: C4Teams.cpp:52
bool IsRuntimeJoinTeamChoice() const
Definition: C4Teams.h:173
C4Team * GetRandomSmallestTeam() const
Definition: C4Teams.cpp:435
bool IsJoin2TeamAllowed(int32_t idTeam, C4PlayerType plrType)
Definition: C4Teams.cpp:534

References C4Team::AddPlayer(), C4PT_User, C4Game::fLobby, Game, C4PlayerInfo::GetID(), C4Team::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().

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

◆ RecheckPlayers()

void C4TeamList::RecheckPlayers ( )

Definition at line 663 of file C4Teams.cpp.

664 {
665  C4Team **ppCheck=ppList; int32_t iCnt=iTeamCount;
666  for (; iCnt--; ++ppCheck) (*ppCheck)->RecheckPlayers();
667 }

References iCnt.

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

Here is the caller graph for this function:

◆ RecheckTeams()

void C4TeamList::RecheckTeams ( )

Definition at line 669 of file C4Teams.cpp.

670 {
671  // automatic team distributions only
672  if (!IsRandomTeam()) return;
673  // host decides random teams
674  if (!::Control.isCtrlHost())
675  {
676  // Still make sure that we have the right number of teams on the clients as well so that
677  // GetTeamCount() does not report inconsistent values.
678  EnsureTeamCount();
679  return;
680  }
681  // random teams in auto generate mode? Make sure there are exactly two teams
682  if (IsAutoGenerateTeams() && GetTeamCount() != 2)
683  {
685  return;
686  }
687  // redistribute players of largest team that has relocatable players left towards smaller teams
688  for (;;)
689  {
690  C4Team *pLowestTeam = GetRandomSmallestTeam();
691  if (!pLowestTeam) break; // no teams: Nothing to re-distribute.
692  // get largest team that has relocateable players
693  C4Team *pLargestTeam = nullptr;
694  C4Team **ppCheck=ppList; int32_t iCnt=iTeamCount;
695  for (; iCnt--; ++ppCheck) if (!pLargestTeam || pLargestTeam->GetPlayerCount() > (*ppCheck)->GetPlayerCount())
696  if ((*ppCheck)->GetFirstUnjoinedPlayerID())
697  pLargestTeam = *ppCheck;
698  // no team can redistribute?
699  if (!pLargestTeam) break;
700  // redistribution won't help much?
701  if (pLargestTeam->GetPlayerCount() - pLowestTeam->GetPlayerCount() <= 1) break;
702  // okay; redistribute one player!
703  int32_t idRedistPlayer = pLargestTeam->GetFirstUnjoinedPlayerID();
704  C4PlayerInfo *pInfo = Game.PlayerInfos.GetPlayerInfoByID(idRedistPlayer);
705  assert(pInfo);
706  if (!pInfo) break; // umn...serious problems
707  pLargestTeam->RemovePlayerByID(idRedistPlayer);
708  pLowestTeam->AddPlayer(*pInfo, true);
709  C4ClientPlayerInfos *pClrInfo = Game.PlayerInfos.GetClientInfoByPlayerID(idRedistPlayer);
710  assert(pClrInfo);
711  // player info change: mark updated to remote clients get information
712  if (pClrInfo)
713  {
714  pClrInfo->SetUpdated();
715  }
716  }
717 }
C4PlayerInfo * GetPlayerInfoByID(int32_t id) const
int32_t GetFirstUnjoinedPlayerID() const
Definition: C4Teams.cpp:112
void RemovePlayerByID(int32_t iID)
Definition: C4Teams.cpp:94
void ReassignAllTeams()
Definition: C4Teams.cpp:732

References C4Team::AddPlayer(), Control, EnsureTeamCount(), 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().

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

◆ Save()

bool C4TeamList::Save ( C4Group hGroup)

Definition at line 646 of file C4Teams.cpp.

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 }
bool DeleteEntry(const char *filename, bool do_recycle=false)
Definition: C4Group.cpp:1695
bool Add(const char *filename, const char *entry_name)
Definition: C4Group.cpp:1621

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

Here is the call graph for this function:

◆ SendSetTeamColors()

void C4TeamList::SendSetTeamColors ( bool  fEnabled)

Definition at line 833 of file C4Teams.cpp.

834 {
835  // set it for all clients
837 }
@ C4CVT_TeamColors
Definition: C4Control.h:107
@ CDT_Sync
Definition: C4GameControl.h:35
@ CID_Set
Definition: C4PacketBase.h:153
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)

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

Here is the call graph for this function:

◆ SendSetTeamDist()

void C4TeamList::SendSetTeamDist ( TeamDist  eNewDist)

Definition at line 790 of file C4Teams.cpp.

791 {
792  assert(::Control.isCtrlHost());
793  // set it for all clients
795 }
@ C4CVT_TeamDistribution
Definition: C4Control.h:106

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

Here is the call graph for this function:

◆ SetTeamColors()

void C4TeamList::SetTeamColors ( bool  fEnabled)

Definition at line 839 of file C4Teams.cpp.

840 {
841  // change only
842  if (fEnabled == fTeamColors) return;
843  // reflect change
844  fTeamColors = fEnabled;
845  // update colors of all players
846  if (!::Control.isCtrlHost()) return;
847  // go through all player infos; reset color in them
848  Game.PlayerInfos.UpdatePlayerAttributes(); // sets team and savegame colors
849  if (::Network.isEnabled())
850  {
851  // sends color updates to all clients
853  }
854 }
C4Network2Players Players
Definition: C4Network2.h:119
void UpdatePlayerAttributes(C4ClientPlayerInfos *pForInfo, bool fResolveConflicts)

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

Here is the call graph for this function:

◆ SetTeamDistribution()

void C4TeamList::SetTeamDistribution ( TeamDist  eToVal)

Definition at line 809 of file C4Teams.cpp.

810 {
811  if (!Inside(eToVal, TEAMDIST_First, TEAMDIST_Last)) { assert(false); return; }
812  eTeamDist = eToVal;
813  // team distribution mode changed: Host may beed to redistribute
814  if (::Control.isCtrlHost())
815  {
816  // if a random team mode was set, reassign all teams so it's really random.
817  // Also reassign in no-team-mode so enough teams for all players exist
818  if (IsRandomTeam() || eTeamDist==TEAMDIST_None)
820  else
821  {
822  // otherwise, it's sufficient to just reassign any teams that are incorrect for the current mode
823  RecheckTeams();
824  }
825  // send updates to other clients and reset flags
826  if (::Network.isEnabled())
827  {
829  }
830  }
831 }
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43
void RecheckTeams()
Definition: C4Teams.cpp:669

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

Here is the call graph for this function:

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