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

#include <C4GameParameters.h>

Collaboration diagram for C4GameParameters:
[legend]

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 ( )
default
C4GameParameters::~C4GameParameters ( )
default

Member Function Documentation

void C4GameParameters::Clear ( )

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

380 {
381  League.Clear();
383  Rules.Clear();
384  Goals.Clear();
385  Scenario.Clear();
386  GameRes.Clear();
387  Clients.Clear();
388  PlayerInfos.Clear();
390  Teams.Clear();
392 }
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 508 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().

509 {
510  pComp->Value(mkNamingAdapt(MaxPlayers, "MaxPlayers", !pScenario ? 0 : pScenario->Head.MaxPlayer));
511  pComp->Value(mkNamingAdapt(AllowDebug, "AllowDebug", true));
512  pComp->Value(mkNamingAdapt(IsNetworkGame, "IsNetworkGame", false));
513  pComp->Value(mkNamingAdapt(IsEditor, "IsEditor", !!::Application.isEditor));
514  pComp->Value(mkNamingAdapt(ControlRate, "ControlRate", -1));
515  pComp->Value(mkNamingAdapt(AutoFrameSkip, "AutoFrameSkip", false));
516  pComp->Value(mkNamingAdapt(Rules, "Rules", !pScenario ? C4IDList() : pScenario->Game.Rules));
517  pComp->Value(mkNamingAdapt(Goals, "Goals", !pScenario ? C4IDList() : pScenario->Game.Goals));
518  pComp->Value(mkNamingAdapt(League, "League", StdStrBuf()));
519 
520  // These values are either stored separately (see Load/Save) or
521  // don't make sense for savegames.
522  if (!pScenario)
523  {
524  pComp->Value(mkNamingAdapt(LeagueAddress, "LeagueAddress", ""));
525 
526  pComp->Value(mkNamingAdapt(Scenario, "Scenario" ));
527  pComp->Value(GameRes);
528 
529  pComp->Value(mkNamingAdapt(PlayerInfos, "PlayerInfos" ));
530  pComp->Value(mkNamingAdapt(RestorePlayerInfos,"RestorePlayerInfos"));
531  pComp->Value(mkNamingAdapt(Teams, "Teams" ));
532  }
533 
534  pComp->Value(Clients);
535 
536  pComp->Value(mkNamingAdapt(ScenarioParameters, "ScenarioParameters"));
537 
538 }
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: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
inline

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

467 {
468  Scenario.CalcHash();
471  AllowDebug = false;
472  if (pScenario) MaxPlayers = pScenario->Head.MaxPlayerLeague;
473  // forced league values in custom scenario parameters
474  size_t idx=0; const C4ScenarioParameterDef *pdef; int32_t val;
475  while ((pdef = ::Game.ScenarioParameterDefs.GetParameterDefByIndex(idx++)))
476  if ((val = pdef->GetLeagueValue()))
477  ScenarioParameters.SetValue(pdef->GetID(), val, false);
478 }
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 540 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().

541 {
542  // getting game goals from the ID list
543  // unfortunately, names cannot be deduced before object definitions are loaded
544  StdStrBuf sResult;
545  C4ID idGoal;
546  for (int32_t i=0; i<Goals.GetNumberOfIDs(); ++i)
547  if ((idGoal = Goals.GetID(i))) if (idGoal != C4ID::None)
548  {
549  if (Game.IsRunning)
550  {
551  C4Def *pDef = C4Id2Def(idGoal);
552  if (pDef)
553  {
554  if (sResult.getLength()) sResult.Append(", ");
555  sResult.Append(pDef->GetName());
556  }
557  }
558  else
559  {
560  if (sResult.getLength()) sResult.Append(", ");
561  sResult.Append(idGoal.ToString());
562  }
563  }
564  // Max length safety
565  if (sResult.getLength() > C4MaxTitle) sResult.SetLength(C4MaxTitle);
566  // Compose desc string
567  if (sResult.getLength())
568  return FormatString("%s: %s", LoadResStr("IDS_MENU_CPGOALS"), sResult.getData());
569  else
570  return StdCopyStrBuf(LoadResStr("IDS_CTL_NOGOAL"), true);
571 }
const char * getData() const
Definition: StdBuf.h:442
bool IsRunning
Definition: C4Game.h:139
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 ( )
inline

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 493 of file C4GameParameters.cpp.

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

Referenced by C4Network2::InitHost().

494 {
495 
496  // Scenario & material resource
497  if (!Scenario.InitNetwork(pResList))
498  return false;
499 
500  // Other game resources
501  if (!GameRes.InitNetwork(pResList))
502  return false;
503 
504  // Done
505  return true;
506 }
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
inline
bool C4GameParameters::Load ( C4Group hGroup,
C4Scenario pDefault,
const char *  szGameText,
C4LangStringTable pLang,
const char *  DefinitionFilenames,
C4ScenarioParameters pStartupScenarioParameters 
)

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

395 {
396  // Clear previous data
397  Clear();
398 
399  // Scenario
401 
402  // Additional game resources
403  if (!GameRes.Load(hGroup, pScenario, DefinitionFilenames))
404  return false;
405 
406  // Player infos (replays only)
407  if (pScenario->Head.Replay)
408  if (hGroup.FindEntry(C4CFN_PlayerInfos))
410 
411  // Savegame restore infos: Used for savegames to rejoin joined players
412  if (hGroup.FindEntry(C4CFN_SavePlayerInfos))
413  {
414  // load to savegame info list
416  // transfer counter to allow for additional player joins in savegame resumes
418  // in network mode, savegame players may be reassigned in the lobby
419  // in any mode, the final player restoration will be done in InitPlayers()
420  // dropping any players that could not be restored
421  }
422 
423  // Load teams
424  if (!Teams.Load(hGroup, pScenario, pLang))
425  { LogFatal(LoadResStr("IDS_PRC_ERRORLOADINGTEAMS")); return false; }
426 
427  // Compile data
428  StdStrBuf Buf;
429  if (hGroup.LoadEntryString(C4CFN_Parameters, &Buf))
430  {
431  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(
432  mkNamingAdapt(mkParAdapt(*this, pScenario), "Parameters"),
433  Buf,
435  return false;
436  }
437  else
438  {
439 
440  // Set default values
441  StdCompilerNull DefaultCompiler;
442  DefaultCompiler.Compile(mkParAdapt(*this, pScenario));
443 
444  // Set control rate default
445  if (ControlRate < 0)
447 
448  // network game?
450 
451  // Auto frame skip by options
453 
454  // custom parameters from startup
455  if (pStartupScenarioParameters) ScenarioParameters = *pStartupScenarioParameters;
456  }
457 
458 
459  // enforce league settings
460  if (isLeague()) EnforceLeagueRules(pScenario);
461 
462  // Done
463  return true;
464 }
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:122
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:458
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 480 of file C4GameParameters.cpp.

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

481 {
482 
483  // Write Parameters.txt
484  StdStrBuf ParData = DecompileToBuf<StdCompilerINIWrite>(
485  mkNamingAdapt(mkParAdapt(*this, pScenario), "Parameters"));
486  if (!hGroup.Add(C4CFN_Parameters, ParData, false, true))
487  return false;
488 
489  // Done
490  return true;
491 }
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:458

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: