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

#include <C4GameParameters.h>

Collaboration diagram for C4GameParameters:

Public Member Functions

 C4GameParameters ()
 ~C4GameParameters ()
bool isLeague () const
bool doStreaming () const
const char * getLeague ()
StdStrBuf GetGameGoalString () const
void EnforceLeagueRules (class C4Scenario *pScenario)
void Clear ()
bool Load (C4Group &hGroup, C4Scenario *pDefault, const char *szGameText, C4LangStringTable *pLang, const char *DefinitionFilenames, C4ScenarioParameters *pStartupScenarioParameters)
bool InitNetwork (C4Network2ResList *pResList)
bool Save (C4Group &hGroup, C4Scenario *pDefault)
void CompileFunc (StdCompiler *pComp, C4Scenario *pScenario=nullptr)

Public Attributes

StdCopyStrBuf League
StdCopyStrBuf LeagueAddress
StdCopyStrBuf StreamAddress
int32_t MaxPlayers
bool IsNetworkGame
bool IsEditor
int32_t ControlRate
bool AutoFrameSkip
bool AllowDebug
C4IDList Rules
C4IDList Goals
C4GameRes Scenario
C4GameResList GameRes
C4ClientList Clients
C4PlayerInfoList PlayerInfos
C4PlayerInfoList RestorePlayerInfos
C4TeamList Teams
C4ScenarioParameters ScenarioParameters

Detailed Description

Definition at line 98 of file C4GameParameters.h.

Constructor & Destructor Documentation

C4GameParameters::C4GameParameters ( )
C4GameParameters::~C4GameParameters ( )

Member Function Documentation

void C4GameParameters::Clear ( )

Definition at line 385 of file C4GameParameters.cpp.

References C4IDList::Clear(), C4GameRes::Clear(), C4GameResList::Clear(), C4ScenarioParameters::Clear(), C4TeamList::Clear(), C4ClientList::Clear(), C4PlayerInfoList::Clear(), StdStrBuf::Clear(), Clients, GameRes, Goals, League, LeagueAddress, PlayerInfos, RestorePlayerInfos, Rules, Scenario, ScenarioParameters, and Teams.

Referenced by C4Game::Clear(), and Load().

386 {
387  League.Clear();
389  Rules.Clear();
390  Goals.Clear();
391  Scenario.Clear();
392  GameRes.Clear();
393  Clients.Clear();
394  PlayerInfos.Clear();
396  Teams.Clear();
398 }
void Clear()
Definition: stub-handle.cpp:64
void Clear()
Definition: StdBuf.h:466
StdCopyStrBuf League
C4ClientList Clients
C4ScenarioParameters ScenarioParameters
C4GameResList GameRes
void Clear()
Definition: C4Client.cpp:170
C4PlayerInfoList RestorePlayerInfos
void Clear()
Definition: C4Teams.cpp:255
C4PlayerInfoList PlayerInfos
StdCopyStrBuf LeagueAddress

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameParameters::CompileFunc ( StdCompiler pComp,
C4Scenario pScenario = nullptr 

Definition at line 514 of file C4GameParameters.cpp.

References AllowDebug, Application, AutoFrameSkip, Clients, ControlRate, C4Scenario::Game, GameRes, C4SGame::Goals, Goals, C4Scenario::Head, C4Application::isEditor, IsEditor, IsNetworkGame, League, LeagueAddress, C4SHead::MaxPlayer, MaxPlayers, mkNamingAdapt(), PlayerInfos, RestorePlayerInfos, C4SGame::Rules, Rules, Scenario, ScenarioParameters, Teams, and StdCompiler::Value().

515 {
516  pComp->Value(mkNamingAdapt(MaxPlayers, "MaxPlayers", !pScenario ? 0 : pScenario->Head.MaxPlayer));
517  pComp->Value(mkNamingAdapt(AllowDebug, "AllowDebug", true));
518  pComp->Value(mkNamingAdapt(IsNetworkGame, "IsNetworkGame", false));
519  pComp->Value(mkNamingAdapt(IsEditor, "IsEditor", !!::Application.isEditor));
520  pComp->Value(mkNamingAdapt(ControlRate, "ControlRate", -1));
521  pComp->Value(mkNamingAdapt(AutoFrameSkip, "AutoFrameSkip", false));
522  pComp->Value(mkNamingAdapt(Rules, "Rules", !pScenario ? C4IDList() : pScenario->Game.Rules));
523  pComp->Value(mkNamingAdapt(Goals, "Goals", !pScenario ? C4IDList() : pScenario->Game.Goals));
524  pComp->Value(mkNamingAdapt(League, "League", StdStrBuf()));
526  // These values are either stored separately (see Load/Save) or
527  // don't make sense for savegames.
528  if (!pScenario)
529  {
530  pComp->Value(mkNamingAdapt(LeagueAddress, "LeagueAddress", ""));
532  pComp->Value(mkNamingAdapt(Scenario, "Scenario" ));
533  pComp->Value(GameRes);
535  pComp->Value(mkNamingAdapt(PlayerInfos, "PlayerInfos" ));
536  pComp->Value(mkNamingAdapt(RestorePlayerInfos,"RestorePlayerInfos"));
537  pComp->Value(mkNamingAdapt(Teams, "Teams" ));
538  }
540  pComp->Value(Clients);
542  pComp->Value(mkNamingAdapt(ScenarioParameters, "ScenarioParameters"));
544 }
C4IDList Goals
Definition: C4Scenario.h:122
C4IDList Rules
Definition: C4Scenario.h:123
StdCopyStrBuf League
C4ClientList Clients
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
C4ScenarioParameters ScenarioParameters
int32_t MaxPlayer
Definition: C4Scenario.h:70
C4GameResList GameRes
void Value(const T &rStruct)
Definition: StdCompiler.h:161
C4PlayerInfoList RestorePlayerInfos
C4PlayerInfoList PlayerInfos
C4SGame Game
Definition: C4Scenario.h:234
C4SHead Head
Definition: C4Scenario.h:232
StdCopyStrBuf LeagueAddress
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

bool C4GameParameters::doStreaming ( ) const

Definition at line 147 of file C4GameParameters.h.

References StdStrBuf::getLength().

Referenced by C4Game::InitControl().

147 { return !!StreamAddress.getLength(); }
StdCopyStrBuf StreamAddress
size_t getLength() const
Definition: StdBuf.h:445

Here is the call graph for this function:

Here is the caller graph for this function:

void C4GameParameters::EnforceLeagueRules ( class C4Scenario pScenario)

Definition at line 472 of file C4GameParameters.cpp.

References AllowDebug, C4GameRes::CalcHash(), C4GameResList::CalcHashes(), C4TeamList::EnforceLeagueRules(), Game, GameRes, C4ScenarioParameterDef::GetID(), C4ScenarioParameterDef::GetLeagueValue(), C4ScenarioParameterDefs::GetParameterDefByIndex(), C4Scenario::Head, C4SHead::MaxPlayerLeague, MaxPlayers, Scenario, C4Game::ScenarioParameterDefs, ScenarioParameters, C4ScenarioParameters::SetValue(), and Teams.

Referenced by C4Network2::InitLeague(), and Load().

473 {
474  Scenario.CalcHash();
477  AllowDebug = false;
478  if (pScenario) MaxPlayers = pScenario->Head.MaxPlayerLeague;
479  // forced league values in custom scenario parameters
480  size_t idx=0; const C4ScenarioParameterDef *pdef; int32_t val;
481  while ((pdef = ::Game.ScenarioParameterDefs.GetParameterDefByIndex(idx++)))
482  if ((val = pdef->GetLeagueValue()))
483  ScenarioParameters.SetValue(pdef->GetID(), val, false);
484 }
const C4ScenarioParameterDef * GetParameterDefByIndex(size_t idx) const
C4Game Game
Definition: C4Globals.cpp:52
class C4ScenarioParameterDefs & ScenarioParameterDefs
Definition: C4Game.h:75
C4ScenarioParameters ScenarioParameters
C4GameResList GameRes
const char * GetID() const
int32_t GetLeagueValue() const
void EnforceLeagueRules()
Definition: C4Teams.cpp:843
void SetValue(const char *id, int32_t value, bool only_if_larger)

Here is the call graph for this function:

Here is the caller graph for this function:

StdStrBuf C4GameParameters::GetGameGoalString ( ) const

Definition at line 546 of file C4GameParameters.cpp.

References StdStrBuf::Append(), C4Id2Def(), C4MaxTitle, FormatString(), Game, StdStrBuf::getData(), C4IDList::GetID(), StdStrBuf::getLength(), C4PropListStatic::GetName(), C4IDList::GetNumberOfIDs(), Goals, C4Game::IsRunning, LoadResStr(), C4ID::None, StdStrBuf::SetLength(), and C4ID::ToString().

Referenced by C4Network2Reference::getGameGoalString().

547 {
548  // getting game goals from the ID list
549  // unfortunately, names cannot be deduced before object definitions are loaded
550  StdStrBuf sResult;
551  C4ID idGoal;
552  for (int32_t i=0; i<Goals.GetNumberOfIDs(); ++i)
553  if ((idGoal = Goals.GetID(i))) if (idGoal != C4ID::None)
554  {
555  if (Game.IsRunning)
556  {
557  C4Def *pDef = C4Id2Def(idGoal);
558  if (pDef)
559  {
560  if (sResult.getLength()) sResult.Append(", ");
561  sResult.Append(pDef->GetName());
562  }
563  }
564  else
565  {
566  if (sResult.getLength()) sResult.Append(", ");
567  sResult.Append(idGoal.ToString());
568  }
569  }
570  // Max length safety
571  if (sResult.getLength() > C4MaxTitle) sResult.SetLength(C4MaxTitle);
572  // Compose desc string
573  if (sResult.getLength())
574  return FormatString("%s: %s", LoadResStr("IDS_MENU_CPGOALS"), sResult.getData());
575  else
576  return StdCopyStrBuf(LoadResStr("IDS_CTL_NOGOAL"), true);
577 }
const char * getData() const
Definition: StdBuf.h:442
bool IsRunning
Definition: C4Game.h:140
const size_t C4MaxTitle
Definition: C4Constants.h:25
C4Game Game
Definition: C4Globals.cpp:52
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
const char * GetName() const override
Definition: C4PropList.cpp:267
static const C4ID None
Definition: C4Id.h:39
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
Definition: C4Def.h:98
Definition: C4Id.h:25
C4Def * C4Id2Def(C4ID id)
Definition: C4DefList.h:84
const char * ToString() const
Definition: C4Id.h:59
size_t getLength() const
Definition: StdBuf.h:445
void SetLength(size_t iLength)
Definition: StdBuf.h:509
C4ID GetID(size_t index, int32_t *ipCount=nullptr) const
Definition: C4IDList.cpp:99
int32_t GetNumberOfIDs() const
Definition: C4IDList.cpp:197
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

Here is the caller graph for this function:

const char* C4GameParameters::getLeague ( )

Definition at line 148 of file C4GameParameters.h.

References StdStrBuf::getData().

Referenced by C4StartupNetListEntry::SetReference().

148 { return League.getData(); }
const char * getData() const
Definition: StdBuf.h:442
StdCopyStrBuf League

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameParameters::InitNetwork ( C4Network2ResList pResList)

Definition at line 499 of file C4GameParameters.cpp.

References GameRes, C4GameRes::InitNetwork(), C4GameResList::InitNetwork(), and Scenario.

Referenced by C4Network2::InitHost().

500 {
502  // Scenario & material resource
503  if (!Scenario.InitNetwork(pResList))
504  return false;
506  // Other game resources
507  if (!GameRes.InitNetwork(pResList))
508  return false;
510  // Done
511  return true;
512 }
bool InitNetwork(C4Network2ResList *pNetResList)
bool InitNetwork(C4Network2ResList *pResList)
C4GameResList GameRes

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameParameters::isLeague ( ) const
bool C4GameParameters::Load ( C4Group hGroup,
C4Scenario pDefault,
const char *  szGameText,
C4LangStringTable pLang,
const char *  DefinitionFilenames,
C4ScenarioParameters pStartupScenarioParameters 

Definition at line 400 of file C4GameParameters.cpp.

References C4ConfigGraphics::AutoFrameSkip, AutoFrameSkip, C4CFN_Parameters, C4CFN_PlayerInfos, C4CFN_SavePlayerInfos, Clear(), StdCompiler::Compile(), Config, ControlRate, C4ConfigNetwork::ControlRate, EnforceLeagueRules(), C4Group::FindEntry(), Game, GameRes, StdStrBuf::getData(), C4Group::GetFullName(), C4PlayerInfoList::GetIDCounter(), C4Config::Graphics, C4Scenario::Head, isLeague(), IsNetworkGame, C4GameResList::Load(), C4TeamList::Load(), C4PlayerInfoList::Load(), C4Group::LoadEntryString(), LoadResStr(), LogFatal(), mkNamingAdapt(), mkParAdapt(), C4Config::Network, C4Game::NetworkActive, NRT_Scenario, PlayerInfos, C4SHead::Replay, RestorePlayerInfos, Scenario, ScenarioParameters, C4GameRes::SetFile(), C4PlayerInfoList::SetIDCounter(), and Teams.

Referenced by C4Game::OpenScenario().

401 {
402  // Clear previous data
403  Clear();
405  // Scenario
408  // Additional game resources
409  if (!GameRes.Load(hGroup, pScenario, DefinitionFilenames))
410  return false;
412  // Player infos (replays only)
413  if (pScenario->Head.Replay)
414  if (hGroup.FindEntry(C4CFN_PlayerInfos))
417  // Savegame restore infos: Used for savegames to rejoin joined players
418  if (hGroup.FindEntry(C4CFN_SavePlayerInfos))
419  {
420  // load to savegame info list
422  // transfer counter to allow for additional player joins in savegame resumes
424  // in network mode, savegame players may be reassigned in the lobby
425  // in any mode, the final player restoration will be done in InitPlayers()
426  // dropping any players that could not be restored
427  }
429  // Load teams
430  if (!Teams.Load(hGroup, pScenario, pLang))
431  { LogFatal(LoadResStr("IDS_PRC_ERRORLOADINGTEAMS")); return false; }
433  // Compile data
434  StdStrBuf Buf;
435  if (hGroup.LoadEntryString(C4CFN_Parameters, &Buf))
436  {
437  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(
438  mkNamingAdapt(mkParAdapt(*this, pScenario), "Parameters"),
439  Buf,
441  return false;
442  }
443  else
444  {
446  // Set default values
447  StdCompilerNull DefaultCompiler;
448  DefaultCompiler.Compile(mkParAdapt(*this, pScenario));
450  // Set control rate default
451  if (ControlRate < 0)
454  // network game?
457  // Auto frame skip by options
460  // custom parameters from startup
461  if (pStartupScenarioParameters) ScenarioParameters = *pStartupScenarioParameters;
462  }
465  // enforce league settings
466  if (isLeague()) EnforceLeagueRules(pScenario);
468  // Done
469  return true;
470 }
const char * getData() const
Definition: StdBuf.h:442
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
C4Config Config
Definition: C4Config.cpp:833
void SetIDCounter(int32_t idNewCounter)
Definition: C4PlayerInfo.h:394
bool Load(C4Group &hGroup, C4Scenario *pScenario, const char *szDefinitionFilenames)
C4Game Game
Definition: C4Globals.cpp:52
void EnforceLeagueRules(class C4Scenario *pScenario)
int32_t ControlRate
Definition: C4Config.h:139
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
void Compile(T &&rStruct)
Definition: StdCompiler.h:173
bool Load(C4Group &hGroup, class C4Scenario *pInitDefault, class C4LangStringTable *pLang)
Definition: C4Teams.cpp:604
C4ConfigGraphics Graphics
Definition: C4Config.h:253
C4ScenarioParameters ScenarioParameters
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
#define C4CFN_SavePlayerInfos
Definition: C4Components.h:125
C4GameResList GameRes
C4ConfigNetwork Network
Definition: C4Config.h:255
#define C4CFN_Parameters
Definition: C4Components.h:128
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:237
bool NetworkActive
Definition: C4Game.h:123
C4PlayerInfoList RestorePlayerInfos
#define C4CFN_PlayerInfos
Definition: C4Components.h:124
bool Load(C4Group &hGroup, const char *szFromFile, class C4LangStringTable *pLang=nullptr)
bool LoadEntryString(const char *szEntryName, StdStrBuf *Buf)
Definition: C4Group.cpp:1932
C4PlayerInfoList PlayerInfos
bool isLeague() const
int32_t GetIDCounter()
Definition: C4PlayerInfo.h:395
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:476
int32_t AutoFrameSkip
Definition: C4Config.h:116
void SetFile(C4Network2ResType eType, const char *szFile)

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4GameParameters::Save ( C4Group hGroup,
C4Scenario pDefault 

Definition at line 486 of file C4GameParameters.cpp.

References C4Group::Add(), C4CFN_Parameters, mkNamingAdapt(), and mkParAdapt().

487 {
489  // Write Parameters.txt
490  StdStrBuf ParData = DecompileToBuf<StdCompilerINIWrite>(
491  mkNamingAdapt(mkParAdapt(*this, pScenario), "Parameters"));
492  if (!hGroup.Add(C4CFN_Parameters, ParData, false, true))
493  return false;
495  // Done
496  return true;
497 }
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
#define C4CFN_Parameters
Definition: C4Components.h:128
bool Add(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1316
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:476

Here is the call graph for this function:

Member Data Documentation

bool C4GameParameters::AllowDebug
bool C4GameParameters::AutoFrameSkip

Definition at line 122 of file C4GameParameters.h.

Referenced by CompileFunc(), C4ApplicationGameTimer::Execute(), and Load().

int32_t C4GameParameters::ControlRate
C4IDList C4GameParameters::Goals

Definition at line 129 of file C4GameParameters.h.

Referenced by Clear(), CompileFunc(), GetGameGoalString(), and C4Game::InitGoals().

bool C4GameParameters::IsEditor

Definition at line 116 of file C4GameParameters.h.

Referenced by CompileFunc().

bool C4GameParameters::IsNetworkGame

Definition at line 113 of file C4GameParameters.h.

Referenced by CompileFunc(), and Load().

StdCopyStrBuf C4GameParameters::LeagueAddress
C4PlayerInfoList C4GameParameters::RestorePlayerInfos

Definition at line 140 of file C4GameParameters.h.

Referenced by Clear(), CompileFunc(), and Load().

C4IDList C4GameParameters::Rules

Definition at line 128 of file C4GameParameters.h.

Referenced by Clear(), CompileFunc(), and C4Game::InitRules().

StdCopyStrBuf C4GameParameters::StreamAddress

Definition at line 107 of file C4GameParameters.h.

Referenced by C4Network2::LeagueStart(), and C4Network2::StreamOut().

C4TeamList C4GameParameters::Teams

Definition at line 141 of file C4GameParameters.h.

Referenced by Clear(), CompileFunc(), EnforceLeagueRules(), and Load().

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