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

Definition at line 377 of file C4GameParameters.cpp.

378 {
380 }
C4GameParameters::~C4GameParameters ( )

Definition at line 382 of file C4GameParameters.cpp.

383 {
385 }

Member Function Documentation

void C4GameParameters::Clear ( )

Definition at line 387 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().

388 {
389  League.Clear();
391  Rules.Clear();
392  Goals.Clear();
393  Scenario.Clear();
394  GameRes.Clear();
395  Clients.Clear();
396  PlayerInfos.Clear();
398  Teams.Clear();
400 }
void Clear()
Definition: stub-handle.cpp:64
void Clear()
Definition: StdBuf.h:474
StdCopyStrBuf League
C4ClientList Clients
C4ScenarioParameters ScenarioParameters
C4GameResList GameRes
void Clear()
Definition: C4Client.cpp:187
C4PlayerInfoList RestorePlayerInfos
void Clear()
Definition: C4Teams.cpp:256
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 516 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().

517 {
518  pComp->Value(mkNamingAdapt(MaxPlayers, "MaxPlayers", !pScenario ? 0 : pScenario->Head.MaxPlayer));
519  pComp->Value(mkNamingAdapt(AllowDebug, "AllowDebug", true));
520  pComp->Value(mkNamingAdapt(IsNetworkGame, "IsNetworkGame", false));
521  pComp->Value(mkNamingAdapt(IsEditor, "IsEditor", !!::Application.isEditor));
522  pComp->Value(mkNamingAdapt(ControlRate, "ControlRate", -1));
523  pComp->Value(mkNamingAdapt(AutoFrameSkip, "AutoFrameSkip", false));
524  pComp->Value(mkNamingAdapt(Rules, "Rules", !pScenario ? C4IDList() : pScenario->Game.Rules));
525  pComp->Value(mkNamingAdapt(Goals, "Goals", !pScenario ? C4IDList() : pScenario->Game.Goals));
526  pComp->Value(mkNamingAdapt(League, "League", StdStrBuf()));
528  // These values are either stored separately (see Load/Save) or
529  // don't make sense for savegames.
530  if (!pScenario)
531  {
532  pComp->Value(mkNamingAdapt(LeagueAddress, "LeagueAddress", ""));
534  pComp->Value(mkNamingAdapt(Scenario, "Scenario" ));
535  pComp->Value(GameRes);
537  pComp->Value(mkNamingAdapt(PlayerInfos, "PlayerInfos" ));
538  pComp->Value(mkNamingAdapt(RestorePlayerInfos,"RestorePlayerInfos"));
539  pComp->Value(mkNamingAdapt(Teams, "Teams" ));
540  }
542  pComp->Value(Clients);
544  pComp->Value(mkNamingAdapt(ScenarioParameters, "ScenarioParameters"));
546 }
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:93
C4ScenarioParameters ScenarioParameters
int32_t MaxPlayer
Definition: C4Scenario.h:70
C4GameResList GameRes
void Value(const T &rStruct)
Definition: StdCompiler.h:171
C4PlayerInfoList RestorePlayerInfos
C4PlayerInfoList PlayerInfos
C4SGame Game
Definition: C4Scenario.h:232
C4SHead Head
Definition: C4Scenario.h:230
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:453

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

475 {
476  Scenario.CalcHash();
479  AllowDebug = false;
480  if (pScenario) MaxPlayers = pScenario->Head.MaxPlayerLeague;
481  // forced league values in custom scenario parameters
482  size_t idx=0; const C4ScenarioParameterDef *pdef; int32_t val;
483  while ((pdef = ::Game.ScenarioParameterDefs.GetParameterDefByIndex(idx++)))
484  if ((val = pdef->GetLeagueValue()))
485  ScenarioParameters.SetValue(pdef->GetID(), val, false);
486 }
const C4ScenarioParameterDef * GetParameterDefByIndex(size_t idx) const
C4Game Game
Definition: C4Globals.cpp:52
class C4ScenarioParameterDefs & ScenarioParameterDefs
Definition: C4Game.h:77
C4ScenarioParameters ScenarioParameters
C4GameResList GameRes
const char * GetID() const
int32_t GetLeagueValue() const
void EnforceLeagueRules()
Definition: C4Teams.cpp:844
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 548 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().

549 {
550  // getting game goals from the ID list
551  // unfortunately, names cannot be deduced before object definitions are loaded
552  StdStrBuf sResult;
553  C4ID idGoal;
554  for (int32_t i=0; i<Goals.GetNumberOfIDs(); ++i)
555  if ((idGoal = Goals.GetID(i))) if (idGoal != C4ID::None)
556  {
557  if (Game.IsRunning)
558  {
559  C4Def *pDef = C4Id2Def(idGoal);
560  if (pDef)
561  {
562  if (sResult.getLength()) sResult.Append(", ");
563  sResult.Append(pDef->GetName());
564  }
565  }
566  else
567  {
568  if (sResult.getLength()) sResult.Append(", ");
569  sResult.Append(idGoal.ToString());
570  }
571  }
572  // Max length safety
573  if (sResult.getLength() > C4MaxTitle) sResult.SetLength(C4MaxTitle);
574  // Compose desc string
575  if (sResult.getLength())
576  return FormatString("%s: %s", LoadResStr("IDS_MENU_CPGOALS"), sResult.getData());
577  else
578  return StdCopyStrBuf(LoadResStr("IDS_CTL_NOGOAL"), true);
579 }
const char * getData() const
Definition: StdBuf.h:450
bool IsRunning
Definition: C4Game.h:141
const size_t C4MaxTitle
Definition: C4Constants.h:25
virtual const char * GetName() const
Definition: C4PropList.cpp:267
C4Game Game
Definition: C4Globals.cpp:52
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
static const C4ID None
Definition: C4Id.h:42
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:527
Definition: C4Def.h:100
Definition: C4Id.h:28
C4Def * C4Id2Def(C4ID id)
Definition: C4DefList.h:80
const char * ToString() const
Definition: C4Id.h:62
size_t getLength() const
Definition: StdBuf.h:453
void SetLength(size_t iLength)
Definition: StdBuf.h:517
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:277

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:450
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 501 of file C4GameParameters.cpp.

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

Referenced by C4Network2::InitHost().

502 {
504  // Scenario & material resource
505  if (!Scenario.InitNetwork(pResList))
506  return false;
508  // Other game resources
509  if (!GameRes.InitNetwork(pResList))
510  return false;
512  // Done
513  return true;
514 }
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 402 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().

403 {
404  // Clear previous data
405  Clear();
407  // Scenario
410  // Additional game resources
411  if (!GameRes.Load(hGroup, pScenario, DefinitionFilenames))
412  return false;
414  // Player infos (replays only)
415  if (pScenario->Head.Replay)
416  if (hGroup.FindEntry(C4CFN_PlayerInfos))
419  // Savegame restore infos: Used for savegames to rejoin joined players
420  if (hGroup.FindEntry(C4CFN_SavePlayerInfos))
421  {
422  // load to savegame info list
424  // transfer counter to allow for additional player joins in savegame resumes
426  // in network mode, savegame players may be reassigned in the lobby
427  // in any mode, the final player restoration will be done in InitPlayers()
428  // dropping any players that could not be restored
429  }
431  // Load teams
432  if (!Teams.Load(hGroup, pScenario, pLang))
433  { LogFatal(LoadResStr("IDS_PRC_ERRORLOADINGTEAMS")); return false; }
435  // Compile data
436  StdStrBuf Buf;
437  if (hGroup.LoadEntryString(C4CFN_Parameters, &Buf))
438  {
439  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(
440  mkNamingAdapt(mkParAdapt(*this, pScenario), "Parameters"),
441  Buf,
443  return false;
444  }
445  else
446  {
448  // Set default values
449  StdCompilerNull DefaultCompiler;
450  DefaultCompiler.Compile(mkParAdapt(*this, pScenario));
452  // Set control rate default
453  if (ControlRate < 0)
456  // network game?
459  // Auto frame skip by options
462  // custom parameters from startup
463  if (pStartupScenarioParameters) ScenarioParameters = *pStartupScenarioParameters;
464  }
467  // enforce league settings
468  if (isLeague()) EnforceLeagueRules(pScenario);
470  // Done
471  return true;
472 }
const char * getData() const
Definition: StdBuf.h:450
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
C4Config Config
Definition: C4Config.cpp:837
void SetIDCounter(int32_t idNewCounter)
Definition: C4PlayerInfo.h:397
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:140
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
void Compile(T &&rStruct)
Definition: StdCompiler.h:183
bool Load(C4Group &hGroup, class C4Scenario *pInitDefault, class C4LangStringTable *pLang)
Definition: C4Teams.cpp:605
C4ConfigGraphics Graphics
Definition: C4Config.h:254
C4ScenarioParameters ScenarioParameters
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
#define C4CFN_SavePlayerInfos
Definition: C4Components.h:125
C4GameResList GameRes
C4ConfigNetwork Network
Definition: C4Config.h:256
#define C4CFN_Parameters
Definition: C4Components.h:128
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:230
bool NetworkActive
Definition: C4Game.h:124
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:398
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:459
int32_t AutoFrameSkip
Definition: C4Config.h:117
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 488 of file C4GameParameters.cpp.

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

489 {
491  // Write Parameters.txt
492  StdStrBuf ParData = DecompileToBuf<StdCompilerINIWrite>(
493  mkNamingAdapt(mkParAdapt(*this, pScenario), "Parameters"));
494  if (!hGroup.Add(C4CFN_Parameters, ParData, false, true))
495  return false;
497  // Done
498  return true;
499 }
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
#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:459

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: