1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Core component of a scenario file */
19 
20 #ifndef INC_C4Scenario
21 #define INC_C4Scenario
22 
23 #include "lib/C4NameList.h"
24 #include "object/C4IDList.h"
25 
26 class C4SVal
27 {
28 public:
29 	C4SVal(int32_t std=0, int32_t rnd=0, int32_t min=0, int32_t max=100);
30 public:
31 	int32_t Std,Rnd,Min,Max;
32 public:
33 	void Default();
34 	void Set(int32_t std=0, int32_t rnd=0, int32_t min=0, int32_t max=100);
35 	void SetConstant(int32_t val);
36 	int32_t Evaluate();
37 	void CompileFunc(StdCompiler *pComp);
38 public:
39 	inline bool operator==(const C4SVal &rhs) const
40 	{
41 		return rhs.Std == Std && rhs.Rnd == Rnd && rhs.Min == Min && rhs.Max == Max;
42 	}
43 };
44 
45 #define C4S_SECTIONLOAD 1 /* parts of the C4S that are modifyable for different landcape sections */
46 
47 // flags for section reloading
48 #define C4S_SAVE_LANDSCAPE 1
49 #define C4S_SAVE_OBJECTS   2
50 #define C4S_KEEP_EFFECTS   4
51 #define C4S_REINIT_SCENARIO 8
52 
53 enum C4SFilmMode
54 {
55 	C4SFilm_None      = 0,
56 	C4SFilm_Normal    = 1,
57 	C4SFilm_Cinematic = 2
58 };
59 
60 class C4SHead
61 {
62 public:
63 	int32_t  C4XVer[2];
64 	std::string Title;
65 	std::string Loader;
66 	std::string Font; // scenario specific font; may be 0
67 	int32_t  Difficulty;
68 	int32_t  Icon;
69 	bool  NoInitialize;
70 	int32_t  MaxPlayer, MinPlayer, MaxPlayerLeague;
71 	bool  SaveGame;
72 	bool  Replay;
73 	int32_t  Film;
74 	int32_t  RandomSeed;
75 	std::string Engine; // Relative filename of engine to be used for this scenario
76 	std::string MissionAccess;
77 	bool Secret; // if true, scenario is invisible if MissionAccess has not been granted
78 	bool NetworkGame;
79 	bool NetworkRuntimeJoin;
80 	StdCopyStrBuf Origin; // original oath and filename to scenario (for records and savegames)
81 public:
82 	void Default();
83 	void CompileFunc(StdCompiler *pComp, bool fSection);
84 };
85 
86 
87 const int32_t C4S_MaxDefinitions = 10;
88 
89 class C4SDefinitions
90 {
91 public:
92 	bool LocalOnly;
93 	bool AllowUserChange;
94 	C4IDList SkipDefs;
95 	void SetModules(const char *szList, const char *szRelativeToPath=nullptr, const char *szRelativeToPath2=nullptr);
96 	bool GetModules(StdStrBuf *psOutModules) const;
97 	std::list<const char *> GetModulesAsList() const; // get definitions as string pointers into this structure
98 	void Default();
99 	void CompileFunc(StdCompiler *pComp);
100 
101 private:
102 	char Definition[C4S_MaxDefinitions][_MAX_PATH+1];
103 };
104 
105 
106 class C4SRealism
107 {
108 public:
109 	C4IDList ValueOverloads;
110 	bool LandscapePushPull; // Use new experimental push-pull-algorithms
111 	bool LandscapeInsertThrust; // Inserted material may thrust material of lower density aside
112 
113 public:
114 	void Default();
115 };
116 
117 
118 class C4SGame
119 {
120 public:
121 	StdCopyStrBuf Mode; // Game mode used by league to determine correct evaluation
122 	C4IDList Goals;
123 	C4IDList Rules;
124 
125 	bool FoWEnabled;
126 
127 	C4SRealism Realism;
128 
129 	bool EvaluateOnAbort;
130 
131 public:
132 	bool IsMelee();
133 	void Default();
134 	void CompileFunc(StdCompiler *pComp, bool fSection);
135 };
136 
137 // Maximum map player extend factor
138 
139 const int32_t C4S_MaxMapPlayerExtend = 4;
140 
141 class C4SPlrStart
142 {
143 public:
144 	C4SVal Wealth;
145 	int32_t Position[2];
146 	int32_t EnforcePosition;
147 	C4IDList ReadyCrew;
148 	C4IDList ReadyBase;
149 	C4IDList ReadyVehic;
150 	C4IDList ReadyMaterial;
151 	C4IDList BuildKnowledge;
152 	C4IDList BaseMaterial;
153 	C4IDList BaseProduction;
154 public:
155 	void Default();
156 	bool EquipmentEqual(C4SPlrStart &rhs);
157 	bool operator==(const C4SPlrStart& rhs);
158 	void CompileFunc(StdCompiler *pComp);
159 };
160 
161 
162 class C4SLandscape
163 {
164 public:
165 	bool ExactLandscape;
166 	C4SVal VegLevel;
167 	C4IDList Vegetation;
168 	C4SVal InEarthLevel;
169 	C4IDList InEarth;
170 	int32_t BottomOpen,TopOpen;
171 	int32_t LeftOpen,RightOpen;
172 	int32_t AutoScanSideOpen;
173 	std::string SkyDef;
174 	int32_t SkyDefFade[6];
175 	bool NoScan;
176 	C4SVal Gravity;
177 	// Dynamic map
178 	C4SVal MapWdt,MapHgt,MapZoom;
179 	C4SVal Amplitude,Phase,Period,Random;
180 	C4SVal LiquidLevel;
181 	int32_t MapPlayerExtend;
182 	C4NameList Layers;
183 	std::string Material;
184 	std::string Liquid;
185 	bool KeepMapCreator; // set if the mapcreator will be needed in the scenario (for DrawDefMap)
186 	int32_t SkyScrollMode;  // sky scrolling mode for newgfx
187 	int32_t MaterialZoom;
188 	bool FlatChunkShapes; // if true, all material chunks are drawn flat
189 	bool Secret; // hide map from observers (except in dev mode and the like)
190 public:
191 	void Default();
192 	void GetMapSize(int32_t &rWdt, int32_t &rHgt, int32_t iPlayerNum);
193 	void CompileFunc(StdCompiler *pComp);
194 };
195 
196 class C4SWeather
197 {
198 public:
199 	C4SVal Climate;
200 	C4SVal StartSeason,YearSpeed;
201 	C4SVal Wind;
202 	bool NoGamma;
203 public:
204 	void Default();
205 	void CompileFunc(StdCompiler *pComp);
206 };
207 
208 class C4SAnimals
209 {
210 public:
211 	C4IDList FreeLife;
212 	C4IDList EarthNest;
213 public:
214 	void Default();
215 	void CompileFunc(StdCompiler *pComp);
216 };
217 
218 class C4SEnvironment
219 {
220 public:
221 	C4IDList Objects;
222 public:
223 	void Default();
224 	void CompileFunc(StdCompiler *pComp);
225 };
226 
227 class C4Scenario
228 {
229 public:
230 	C4Scenario();
231 public:
232 	C4SHead         Head;
233 	C4SDefinitions  Definitions;
234 	C4SGame         Game;
235 	C4SPlrStart     PlrStart[C4S_MaxPlayer];
236 	C4SLandscape    Landscape;
237 	C4SAnimals      Animals;
238 	C4SWeather      Weather;
239 	C4SEnvironment  Environment;
240 public:
241 	void SetExactLandscape();
242 	void Clear();
243 	void Default();
244 	bool Load(C4Group &hGroup, bool fLoadSection = false, bool suppress_errors = false);
245 	bool Save(C4Group &hGroup, bool fSaveSection=false);
246 	void CompileFunc(StdCompiler *pComp, bool fSection);
247 	int32_t GetMinPlayer(); // will try to determine the minimum player count for this scenario
248 };
249 
250 extern const char *C4ScenSect_Main;
251 
252 // ref to one scenario section
253 class C4ScenarioSection
254 {
255 public:
256 	C4ScenarioSection(const char *szName);  // ctor
257 	~C4ScenarioSection(); // dtor
258 
259 public:
260 	StdCopyStrBuf name;          // section name
261 	StdCopyStrBuf temp_filename; // filename of data file if in temp dir
262 	StdCopyStrBuf filename;      // filename of section in scenario file
263 	bool fModified;       // if set, the file is temp and contains runtime landscape and/or object data
264 	class C4ScenarioObjectsScriptHost *pObjectScripts; // points to loaded script file for section Objects.c
265 
266 	C4ScenarioSection *pNext; // next member of linked list
267 
268 public:
269 	bool ScenarioLoad(const char *szFilename, bool is_temp_file);  // called when scenario is loaded: extract to temp store
270 	C4Group *GetGroupfile(C4Group &rGrp); // get group at section file (returns temp group, scenario subgroup or scenario group itself)
271 	bool EnsureTempStore(bool fExtractLandscape, bool fExtractObjects);               // make sure that a temp file is created, and nothing is modified within the main scenario file
272 };
273 
274 
275 
276 #endif // INC_C4Scenario
277