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

◆ ~C4GameParameters()

C4GameParameters::~C4GameParameters ( )
default

Member Function Documentation

◆ Clear()

void C4GameParameters::Clear ( )

Definition at line 385 of file C4GameParameters.cpp.

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: C4Client.cpp:170
C4GameResList GameRes
C4ClientList Clients
C4ScenarioParameters ScenarioParameters
StdCopyStrBuf League
C4PlayerInfoList RestorePlayerInfos
StdCopyStrBuf LeagueAddress
C4PlayerInfoList PlayerInfos
void Clear()
Definition: stub-handle.cpp:64
void Clear()
Definition: C4Teams.cpp:255
void Clear()
Definition: StdBuf.h:466

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

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

Here is the call graph for this function:
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.

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 }
C4Application Application
Definition: C4Globals.cpp:44
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
C4IDList Goals
Definition: C4Scenario.h:122
C4IDList Rules
Definition: C4Scenario.h:123
int32_t MaxPlayer
Definition: C4Scenario.h:70
C4SGame Game
Definition: C4Scenario.h:234
C4SHead Head
Definition: C4Scenario.h:232
void Value(const T &rStruct)
Definition: StdCompiler.h:161

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

Here is the call graph for this function:

◆ doStreaming()

bool C4GameParameters::doStreaming ( ) const
inline

Definition at line 147 of file C4GameParameters.h.

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

References StdStrBuf::getLength(), and StreamAddress.

Referenced by C4Game::InitControl().

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.

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 }
C4Game Game
Definition: C4Globals.cpp:52
class C4ScenarioParameterDefs & ScenarioParameterDefs
Definition: C4Game.h:75
const char * GetID() const
int32_t GetLeagueValue() const
const C4ScenarioParameterDef * GetParameterDefByIndex(size_t idx) const
void SetValue(const char *id, int32_t value, bool only_if_larger)
void EnforceLeagueRules()
Definition: C4Teams.cpp:856

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

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.

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 size_t C4MaxTitle
Definition: C4Constants.h:25
C4Def * C4Id2Def(C4ID id)
Definition: C4DefList.h:84
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
Definition: C4Def.h:99
bool IsRunning
Definition: C4Game.h:140
Definition: C4Id.h:26
const char * ToString() const
Definition: C4Id.h:56
static const C4ID None
Definition: C4Id.h:39
C4ID GetID(size_t index, int32_t *ipCount=nullptr) const
Definition: C4IDList.cpp:103
int32_t GetNumberOfIDs() const
Definition: C4IDList.cpp:231
const char * GetName() const override
Definition: C4PropList.cpp:243
void SetLength(size_t iLength)
Definition: StdBuf.h:509
const char * getData() const
Definition: StdBuf.h:442
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519

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

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.

148 { return League.getData(); }

References StdStrBuf::getData(), and League.

Referenced by C4StartupNetListEntry::SetReference().

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.

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 *pResList)
bool InitNetwork(C4Network2ResList *pNetResList)

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

Referenced by C4Network2::InitHost().

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

◆ isLeague()

bool C4GameParameters::isLeague ( ) const
inline

◆ 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.

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 }
#define C4CFN_PlayerInfos
Definition: C4Components.h:124
#define C4CFN_Parameters
Definition: C4Components.h:128
#define C4CFN_SavePlayerInfos
Definition: C4Components.h:125
C4Config Config
Definition: C4Config.cpp:930
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:239
@ NRT_Scenario
Definition: C4Network2Res.h:43
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:490
int32_t AutoFrameSkip
Definition: C4Config.h:116
C4ConfigNetwork Network
Definition: C4Config.h:259
C4ConfigGraphics Graphics
Definition: C4Config.h:257
int32_t ControlRate
Definition: C4Config.h:139
bool NetworkActive
Definition: C4Game.h:123
bool isLeague() const
void EnforceLeagueRules(class C4Scenario *pScenario)
void SetFile(C4Network2ResType eType, const char *szFile)
bool Load(C4Group &hGroup, C4Scenario *pScenario, const char *szDefinitionFilenames)
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2638
bool LoadEntryString(const char *entry_name, StdStrBuf *buffer)
Definition: C4Group.cpp:2430
bool FindEntry(const char *wildcard, StdStrBuf *filename=nullptr, size_t *size=nullptr)
Definition: C4Group.cpp:2211
void SetIDCounter(int32_t idNewCounter)
Definition: C4PlayerInfo.h:394
bool Load(C4Group &hGroup, const char *szFromFile, class C4LangStringTable *pLang=nullptr)
int32_t GetIDCounter()
Definition: C4PlayerInfo.h:395
bool Load(C4Group &hGroup, class C4Scenario *pInitDefault, class C4LangStringTable *pLang)
Definition: C4Teams.cpp:604
void Compile(T &&rStruct)
Definition: StdCompiler.h:173

References C4ConfigGraphics::AutoFrameSkip, AutoFrameSkip, C4CFN_Parameters, C4CFN_PlayerInfos, C4CFN_SavePlayerInfos, Clear(), StdCompiler::Compile(), Config, C4ConfigNetwork::ControlRate, 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().

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.

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

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

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 CompileFunc(), C4ApplicationGameTimer::Execute(), and Load().

◆ Clients

◆ ControlRate

int32_t C4GameParameters::ControlRate

◆ GameRes

◆ Goals

C4IDList C4GameParameters::Goals

Definition at line 129 of file C4GameParameters.h.

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

◆ IsEditor

bool C4GameParameters::IsEditor

Definition at line 116 of file C4GameParameters.h.

Referenced by CompileFunc().

◆ IsNetworkGame

bool C4GameParameters::IsNetworkGame

Definition at line 113 of file C4GameParameters.h.

Referenced by CompileFunc(), and Load().

◆ League

◆ LeagueAddress

StdCopyStrBuf C4GameParameters::LeagueAddress

◆ MaxPlayers

◆ PlayerInfos

◆ RestorePlayerInfos

C4PlayerInfoList C4GameParameters::RestorePlayerInfos

Definition at line 140 of file C4GameParameters.h.

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

◆ Rules

C4IDList C4GameParameters::Rules

Definition at line 128 of file C4GameParameters.h.

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

◆ Scenario

◆ ScenarioParameters

◆ StreamAddress

StdCopyStrBuf C4GameParameters::StreamAddress

Definition at line 107 of file C4GameParameters.h.

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

◆ Teams

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: