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

Referenced by C4GameResList::CompileFunc().

Here is the caller graph for this function:

◆ ~C4GameParameters()

C4GameParameters::~C4GameParameters ( )
default

Referenced by C4GameResList::CompileFunc().

Here is the caller graph for this function:

Member Function Documentation

◆ Clear()

void C4GameParameters::Clear ( )

Definition at line 385 of file C4GameParameters.cpp.

Referenced by C4Game::Clear().

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 caller graph for this function:

◆ CompileFunc()

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

Definition at line 514 of file C4GameParameters.cpp.

References Application, C4Scenario::Game, C4SGame::Goals, C4Scenario::Head, C4Application::isEditor, C4SHead::MaxPlayer, mkNamingAdapt(), C4SGame::Rules, 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()));
525 
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", ""));
531 
532  pComp->Value(mkNamingAdapt(Scenario, "Scenario" ));
533  pComp->Value(GameRes);
534 
535  pComp->Value(mkNamingAdapt(PlayerInfos, "PlayerInfos" ));
536  pComp->Value(mkNamingAdapt(RestorePlayerInfos,"RestorePlayerInfos"));
537  pComp->Value(mkNamingAdapt(Teams, "Teams" ));
538  }
539 
540  pComp->Value(Clients);
541 
542  pComp->Value(mkNamingAdapt(ScenarioParameters, "ScenarioParameters"));
543 
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:

◆ doStreaming()

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:

◆ EnforceLeagueRules()

void C4GameParameters::EnforceLeagueRules ( class C4Scenario pScenario)

Definition at line 472 of file C4GameParameters.cpp.

References Game, C4ScenarioParameterDef::GetID(), C4ScenarioParameterDef::GetLeagueValue(), C4ScenarioParameterDefs::GetParameterDefByIndex(), C4Scenario::Head, C4SHead::MaxPlayerLeague, and C4Game::ScenarioParameterDefs.

Referenced by C4Network2::InitLeague().

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 }
int32_t GetLeagueValue() const
C4Game Game
Definition: C4Globals.cpp:52
const C4ScenarioParameterDef * GetParameterDefByIndex(size_t idx) const
class C4ScenarioParameterDefs & ScenarioParameterDefs
Definition: C4Game.h:75
const char * GetID() const
C4ScenarioParameters ScenarioParameters
C4GameResList GameRes
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:

◆ GetGameGoalString()

StdStrBuf C4GameParameters::GetGameGoalString ( ) const

Definition at line 546 of file C4GameParameters.cpp.

References StdStrBuf::Append(), C4Id2Def(), C4MaxTitle, FormatString(), Game, StdStrBuf::getData(), StdStrBuf::getLength(), C4PropListStatic::GetName(), 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 }
bool IsRunning
Definition: C4Game.h:140
const size_t C4MaxTitle
Definition: C4Constants.h:25
const char * ToString() const
Definition: C4Id.h:59
int32_t GetNumberOfIDs() const
Definition: C4IDList.cpp:197
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
C4ID GetID(size_t index, int32_t *ipCount=nullptr) const
Definition: C4IDList.cpp:99
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
const char * getData() const
Definition: StdBuf.h:442
C4Def * C4Id2Def(C4ID id)
Definition: C4DefList.h:84
void SetLength(size_t iLength)
Definition: StdBuf.h:509
size_t getLength() const
Definition: StdBuf.h:445
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:

◆ getLeague()

const char* C4GameParameters::getLeague ( )
inline

Definition at line 148 of file C4GameParameters.h.

References C4GameRes::Clear(), C4GameRes::CompileFunc(), StdStrBuf::getData(), C4GameRes::InitNetwork(), and C4GameRes::Load().

Referenced by C4StartupNetListEntry::SetReference().

148 { return League.getData(); }
StdCopyStrBuf League
const char * getData() const
Definition: StdBuf.h:442
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitNetwork()

bool C4GameParameters::InitNetwork ( C4Network2ResList pResList)

Definition at line 499 of file C4GameParameters.cpp.

Referenced by C4Network2::InitHost().

500 {
501 
502  // Scenario & material resource
503  if (!Scenario.InitNetwork(pResList))
504  return false;
505 
506  // Other game resources
507  if (!GameRes.InitNetwork(pResList))
508  return false;
509 
510  // Done
511  return true;
512 }
bool InitNetwork(C4Network2ResList *pNetResList)
bool InitNetwork(C4Network2ResList *pResList)
C4GameResList GameRes
Here is the caller graph for this function:

◆ isLeague()

◆ Load()

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, C4CFN_Parameters, C4CFN_PlayerInfos, C4CFN_SavePlayerInfos, C4GameRes::Clear(), StdCompiler::Compile(), Config, C4ConfigNetwork::ControlRate, C4Group::FindEntry(), Game, StdStrBuf::getData(), C4Group::GetFullName(), C4Config::Graphics, C4Scenario::Head, C4Group::LoadEntryString(), LoadResStr(), LogFatal(), mkNamingAdapt(), mkParAdapt(), C4Config::Network, C4Game::NetworkActive, NRT_Scenario, and C4SHead::Replay.

Referenced by C4Game::OpenScenario().

401 {
402  // Clear previous data
403  Clear();
404 
405  // Scenario
407 
408  // Additional game resources
409  if (!GameRes.Load(hGroup, pScenario, DefinitionFilenames))
410  return false;
411 
412  // Player infos (replays only)
413  if (pScenario->Head.Replay)
414  if (hGroup.FindEntry(C4CFN_PlayerInfos))
416 
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  }
428 
429  // Load teams
430  if (!Teams.Load(hGroup, pScenario, pLang))
431  { LogFatal(LoadResStr("IDS_PRC_ERRORLOADINGTEAMS")); return false; }
432 
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  {
445 
446  // Set default values
447  StdCompilerNull DefaultCompiler;
448  DefaultCompiler.Compile(mkParAdapt(*this, pScenario));
449 
450  // Set control rate default
451  if (ControlRate < 0)
453 
454  // network game?
456 
457  // Auto frame skip by options
459 
460  // custom parameters from startup
461  if (pStartupScenarioParameters) ScenarioParameters = *pStartupScenarioParameters;
462  }
463 
464 
465  // enforce league settings
466  if (isLeague()) EnforceLeagueRules(pScenario);
467 
468  // Done
469  return true;
470 }
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
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
C4ScenarioParameters ScenarioParameters
#define C4CFN_SavePlayerInfos
Definition: C4Components.h:125
bool isLeague() const
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
const char * getData() const
Definition: StdBuf.h:442
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
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:

◆ Save()

bool C4GameParameters::Save ( C4Group hGroup,
C4Scenario pDefault 
)

Definition at line 486 of file C4GameParameters.cpp.

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

487 {
488 
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;
494 
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

◆ AllowDebug

bool C4GameParameters::AllowDebug

◆ AutoFrameSkip

bool C4GameParameters::AutoFrameSkip

Definition at line 122 of file C4GameParameters.h.

Referenced by C4ApplicationGameTimer::Execute().

◆ Clients

◆ ControlRate

int32_t C4GameParameters::ControlRate

◆ GameRes

C4GameResList C4GameParameters::GameRes

◆ Goals

C4IDList C4GameParameters::Goals

Definition at line 129 of file C4GameParameters.h.

Referenced by C4Game::InitGoals().

◆ IsEditor

bool C4GameParameters::IsEditor

Definition at line 116 of file C4GameParameters.h.

◆ IsNetworkGame

bool C4GameParameters::IsNetworkGame

Definition at line 113 of file C4GameParameters.h.

◆ League

◆ LeagueAddress

StdCopyStrBuf C4GameParameters::LeagueAddress

◆ MaxPlayers

◆ PlayerInfos

◆ RestorePlayerInfos

C4PlayerInfoList C4GameParameters::RestorePlayerInfos

Definition at line 140 of file C4GameParameters.h.

◆ Rules

C4IDList C4GameParameters::Rules

Definition at line 128 of file C4GameParameters.h.

Referenced by C4Game::InitRules().

◆ Scenario

◆ ScenarioParameters

C4ScenarioParameters C4GameParameters::ScenarioParameters

◆ StreamAddress

StdCopyStrBuf C4GameParameters::StreamAddress

Definition at line 107 of file C4GameParameters.h.

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

◆ Teams

C4TeamList C4GameParameters::Teams

Definition at line 141 of file C4GameParameters.h.


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