OpenClonk
C4GameParameters.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2013-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 /* Game parameters - game data that is valid before the game is started */
17 
18 #ifndef C4GAMEPARAMETERS_H
19 #define C4GAMEPARAMETERS_H
20 
21 #include "control/C4PlayerInfo.h"
22 #include "control/C4Teams.h"
23 #include "object/C4IDList.h"
24 #include "object/C4InfoCore.h"
25 
26 class C4GameRes
27 {
28  friend class C4GameResList;
29 public:
30  C4GameRes();
31  C4GameRes(const C4GameRes &Res);
32  ~C4GameRes();
33 
34  C4GameRes &operator = (const C4GameRes &Res);
35 
36 private:
38  StdCopyStrBuf File;
39  const C4Network2ResCore *pResCore{nullptr};
40  C4Network2Res::Ref pNetRes;
41 
42 public:
43  C4Network2ResType getType() const { return eType; }
44  const char *getFile() const { return File.getData(); }
45  bool isPresent() const { return !! File; }
46  const C4Network2ResCore *getResCore() const { return pResCore; }
47  C4Network2Res::Ref getNetRes() const { return pNetRes; }
48 
49  void SetFile(C4Network2ResType eType, const char *szFile);
50  void SetResCore(C4Network2ResCore *pResCore);
51  void SetNetRes(C4Network2Res::Ref pRes);
52 
53  bool Publish(C4Network2ResList *pResList);
54  bool Load(C4Network2ResList *pResList);
55  bool InitNetwork(C4Network2ResList *pResList);
56 
57  void CalcHash();
58 
59  void Clear();
60 
61  void CompileFunc(StdCompiler *pComp);
62 };
63 
65 {
66 private:
67  C4GameRes **pResList{nullptr};
68  int32_t iResCount{0}, iResCapacity{0};
69 
70 public:
71  C4GameResList() = default;
73 
75 
76  int32_t getResCount() const { return iResCount; }
77 
79 
80  void Clear();
81  bool Load(C4Group &hGroup, C4Scenario *pScenario, const char * szDefinitionFilenames); // host: create res cores by definition filenames
82 
83  C4GameRes *CreateByFile(C4Network2ResType eType, const char *szFile);
85  bool InitNetwork(C4Network2ResList *pNetResList);
86 
87  void CalcHashes();
88 
89  bool RetrieveFiles(); // client: make sure all definition files are loaded
90 
91  void CompileFunc(StdCompiler *pComp);
92 
93 protected:
94  void Add(C4GameRes *pRes);
95  void LoadFoldersWithLocalDefs(const char *szPath);
96 };
97 
99 {
100 public:
103 
104  // League (empty if it's not a league game)
108 
109  // Maximum player count allowed
110  int32_t MaxPlayers;
111 
112  // Original network game? Also set in replays of network games for sync safety
114 
115  // Originally hosted in editor (also in replays from editor)
116  bool IsEditor;
117 
118  // Control rate
119  int32_t ControlRate;
120 
121  // Automatic frame skip enabled for this game?
123 
124  // Allow debug mode?
126 
127  // Active rules and goals
130 
131  // Game resources
134 
135  // Clients
137 
138  // Players & Teams
142 
143  // Custom scenario parameters
145 
146  bool isLeague() const { return !!LeagueAddress.getLength(); }
147  bool doStreaming() const { return !!StreamAddress.getLength(); }
148  const char* getLeague() { return League.getData(); }
150  void EnforceLeagueRules(class C4Scenario *pScenario);
151 
152  void Clear();
153  bool Load(C4Group &hGroup, C4Scenario *pDefault, const char *szGameText, C4LangStringTable *pLang, const char *DefinitionFilenames, C4ScenarioParameters *pStartupScenarioParameters);
154  bool InitNetwork(C4Network2ResList *pResList);
155  bool Save(C4Group &hGroup, C4Scenario *pDefault);
156 
157  void CompileFunc(StdCompiler *pComp, C4Scenario *pScenario = nullptr);
158 };
159 
160 #endif // C4GAMEPARAMETERS_H
C4Network2ResType
Definition: C4Network2Res.h:41
@ NRT_Null
Definition: C4Network2Res.h:42
bool isLeague() const
C4GameResList GameRes
C4ClientList Clients
bool doStreaming() const
C4ScenarioParameters ScenarioParameters
const char * getLeague()
StdStrBuf GetGameGoalString() const
bool Load(C4Group &hGroup, C4Scenario *pDefault, const char *szGameText, C4LangStringTable *pLang, const char *DefinitionFilenames, C4ScenarioParameters *pStartupScenarioParameters)
StdCopyStrBuf StreamAddress
bool InitNetwork(C4Network2ResList *pResList)
void EnforceLeagueRules(class C4Scenario *pScenario)
StdCopyStrBuf League
C4PlayerInfoList RestorePlayerInfos
void CompileFunc(StdCompiler *pComp, C4Scenario *pScenario=nullptr)
StdCopyStrBuf LeagueAddress
bool Save(C4Group &hGroup, C4Scenario *pDefault)
C4PlayerInfoList PlayerInfos
void SetNetRes(C4Network2Res::Ref pRes)
C4Network2Res::Ref getNetRes() const
bool isPresent() const
void SetFile(C4Network2ResType eType, const char *szFile)
void CompileFunc(StdCompiler *pComp)
void SetResCore(C4Network2ResCore *pResCore)
C4Network2ResType getType() const
const char * getFile() const
C4GameRes & operator=(const C4GameRes &Res)
const C4Network2ResCore * getResCore() const
bool Load(C4Network2ResList *pResList)
bool Publish(C4Network2ResList *pResList)
bool InitNetwork(C4Network2ResList *pResList)
C4GameResList & operator=(const C4GameResList &List)
C4GameRes * CreateByFile(C4Network2ResType eType, const char *szFile)
void LoadFoldersWithLocalDefs(const char *szPath)
void Add(C4GameRes *pRes)
C4GameRes * iterRes(C4GameRes *pLast, C4Network2ResType eType=NRT_Null)
C4GameRes * CreateByNetRes(C4Network2Res::Ref pNetRes)
void CompileFunc(StdCompiler *pComp)
C4GameResList()=default
bool InitNetwork(C4Network2ResList *pNetResList)
int32_t getResCount() const
bool Load(C4Group &hGroup, C4Scenario *pScenario, const char *szDefinitionFilenames)
const char * getData() const
Definition: StdBuf.h:442
size_t getLength() const
Definition: StdBuf.h:445