| 1 | /* |
| 2 | * LegacyClonk |
| 3 | * |
| 4 | * Copyright (c) 1998-2000, Matthes Bender (RedWolf Design) |
| 5 | * Copyright (c) 2017-2022, The LegacyClonk 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 | |
| 17 | /* Core component of a scenario file */ |
| 18 | |
| 19 | #pragma once |
| 20 | |
| 21 | #include "C4ForwardDeclarations.h" |
| 22 | #include <C4NameList.h> |
| 23 | #include <C4IDList.h> |
| 24 | |
| 25 | #include <string> |
| 26 | |
| 27 | class C4SVal |
| 28 | { |
| 29 | public: |
| 30 | C4SVal(int32_t std = 0, int32_t rnd = 0, int32_t min = 0, int32_t max = 100); |
| 31 | |
| 32 | public: |
| 33 | int32_t Std, Rnd, Min, Max; |
| 34 | |
| 35 | public: |
| 36 | void Default(); |
| 37 | void Set(int32_t std = 0, int32_t rnd = 0, int32_t min = 0, int32_t max = 100); |
| 38 | int32_t Evaluate(); |
| 39 | void CompileFunc(StdCompiler *pComp); |
| 40 | }; |
| 41 | |
| 42 | inline bool operator==(C4SVal Val1, C4SVal Val2) |
| 43 | { |
| 44 | return std::memcmp(s1: &Val1, s2: &Val2, n: sizeof(C4SVal)) == 0; |
| 45 | } |
| 46 | |
| 47 | #define C4SGFXMODE_NEWGFX 1 |
| 48 | #define C4SGFXMODE_OLDGFX 2 |
| 49 | |
| 50 | // flags for section reloading |
| 51 | #define C4S_SAVE_LANDSCAPE 1 |
| 52 | #define C4S_SAVE_OBJECTS 2 |
| 53 | #define C4S_KEEP_EFFECTS 4 |
| 54 | |
| 55 | enum C4SForceFairCrew |
| 56 | { |
| 57 | C4SFairCrew_Free = 0, |
| 58 | C4SFairCrew_FairCrew = 1, |
| 59 | C4SFairCrew_NormalCrew = 2, |
| 60 | }; |
| 61 | |
| 62 | enum C4SFilmMode |
| 63 | { |
| 64 | C4SFilm_None = 0, |
| 65 | C4SFilm_Normal = 1, |
| 66 | C4SFilm_Cinematic = 2, |
| 67 | }; |
| 68 | |
| 69 | class C4SHead |
| 70 | { |
| 71 | public: |
| 72 | int32_t C4XVer[5]{}; |
| 73 | char Title[C4MaxTitle + 1]{"Default Title" }; |
| 74 | char Loader[C4MaxTitle + 1]{}; |
| 75 | char Font[C4MaxTitle + 1]{}; // scenario specific font; may be 0 |
| 76 | int32_t Difficulty{}; |
| 77 | int32_t Icon{18}; |
| 78 | int32_t NoInitialize{}; |
| 79 | int32_t MaxPlayer, MinPlayer{}, MaxPlayerLeague; |
| 80 | int32_t SaveGame{}; |
| 81 | int32_t Replay{}; |
| 82 | int32_t Film{}; |
| 83 | int32_t DisableMouse{}; |
| 84 | int32_t RandomSeed{}; |
| 85 | char Engine[C4MaxTitle + 1]{}; // Relative filename of engine to be used for this scenario |
| 86 | char MissionAccess[C4MaxTitle + 1]{}; |
| 87 | bool NetworkGame{}; |
| 88 | bool NetworkRuntimeJoin{}; |
| 89 | int32_t ForcedGfxMode{}; // 0: free; 1/2: newgfx/oldgfx |
| 90 | int32_t ForcedFairCrew{}; // 0: free; 1: force FairCrew; 2: force normal Crew (C4SForceFairCrew) |
| 91 | int32_t FairCrewStrength{}; |
| 92 | int32_t {-1}; // -1: Not forced; 0: Force off; 1: Force on |
| 93 | int32_t ForcedControlStyle{-1}; // -1: Not forced; 0: Force off; 1: Force on |
| 94 | StdStrBuf Origin{}; // original oath and filename to scenario (for records and savegames) |
| 95 | |
| 96 | public: |
| 97 | C4SHead(); |
| 98 | void Default(); |
| 99 | void CompileFunc(StdCompiler *pComp, bool fSection); |
| 100 | |
| 101 | private: |
| 102 | static int32_t MainForcedAutoContextMenu; |
| 103 | static int32_t MainForcedControlStyle; |
| 104 | }; |
| 105 | |
| 106 | const int32_t C4S_MaxDefinitions = 10; |
| 107 | |
| 108 | class C4SDefinitions |
| 109 | { |
| 110 | public: |
| 111 | bool LocalOnly; |
| 112 | bool AllowUserChange; |
| 113 | std::vector<std::string> Definitions; |
| 114 | C4IDList SkipDefs; |
| 115 | |
| 116 | public: |
| 117 | void SetModules(const std::vector<std::string> &modules, const std::string &relativeToPath = "" , const std::string &relativeToPath2 = "" ); |
| 118 | std::vector<std::string> GetModules() const; |
| 119 | void Default(); |
| 120 | void CompileFunc(StdCompiler *pComp); |
| 121 | }; |
| 122 | |
| 123 | class C4SRealism |
| 124 | { |
| 125 | public: |
| 126 | bool ConstructionNeedsMaterial; |
| 127 | bool StructuresNeedEnergy; |
| 128 | C4IDList ValueOverloads; |
| 129 | int32_t LandscapePushPull; // Use new experimental push-pull-algorithms |
| 130 | int32_t LandscapeInsertThrust; // Inserted material may thrust material of lower density aside |
| 131 | int32_t BaseFunctionality; // functions a base can fulfill (BASEFUNC_*-constants) |
| 132 | int32_t BaseRegenerateEnergyPrice; // price for 100 points of energy |
| 133 | |
| 134 | public: |
| 135 | void Default(); |
| 136 | }; |
| 137 | |
| 138 | class C4SGame |
| 139 | { |
| 140 | public: |
| 141 | int32_t Mode; |
| 142 | int32_t Elimination; |
| 143 | bool EnableRemoveFlag; |
| 144 | |
| 145 | // Player winning |
| 146 | int32_t ValueGain; // If nonzero and value gain is equal or higher |
| 147 | // Cooperative game over |
| 148 | C4IDList CreateObjects; // If all these objects exist |
| 149 | C4IDList ClearObjects; // If fewer than these objects exist |
| 150 | C4NameList ClearMaterial; // If less than these materials exist |
| 151 | int32_t CooperativeGoal; // Master selection for Frontend |
| 152 | |
| 153 | C4IDList Goals; |
| 154 | C4IDList Rules; |
| 155 | |
| 156 | uint32_t FoWColor; // color of FoW; may contain transparency |
| 157 | |
| 158 | C4SRealism Realism; |
| 159 | |
| 160 | public: |
| 161 | bool IsMelee(); |
| 162 | void ConvertGoals(C4SRealism &rRealism); |
| 163 | void Default(); |
| 164 | void CompileFunc(StdCompiler *pComp, bool fSection); |
| 165 | |
| 166 | protected: |
| 167 | void ClearOldGoals(); |
| 168 | }; |
| 169 | |
| 170 | // Game mode |
| 171 | |
| 172 | const int32_t C4S_Cooperative = 0, |
| 173 | C4S_Melee = 1, |
| 174 | C4S_MeleeTeamwork = 2; |
| 175 | |
| 176 | // Player elimination |
| 177 | |
| 178 | const int32_t C4S_KillTheCaptain = 0, |
| 179 | C4S_EliminateCrew = 1, |
| 180 | C4S_CaptureTheFlag = 2; |
| 181 | |
| 182 | // Cooperative goals |
| 183 | |
| 184 | const int32_t C4S_NoGoal = 0, |
| 185 | C4S_Goldmine = 1, |
| 186 | C4S_Monsterkill = 2, |
| 187 | C4S_ValueGain = 3, |
| 188 | C4S_Extended = 4; |
| 189 | |
| 190 | // Maximum map player extend factor |
| 191 | |
| 192 | const int32_t C4S_MaxMapPlayerExtend = 4; |
| 193 | |
| 194 | class C4SPlrStart |
| 195 | { |
| 196 | public: |
| 197 | C4ID NativeCrew; // Obsolete |
| 198 | C4SVal Crew; // Obsolete |
| 199 | C4SVal Wealth; |
| 200 | int32_t Position[2]; |
| 201 | int32_t EnforcePosition; |
| 202 | C4IDList ReadyCrew; |
| 203 | C4IDList ReadyBase; |
| 204 | C4IDList ReadyVehic; |
| 205 | C4IDList ReadyMaterial; |
| 206 | C4IDList BuildKnowledge; |
| 207 | C4IDList HomeBaseMaterial; |
| 208 | C4IDList HomeBaseProduction; |
| 209 | C4IDList Magic; |
| 210 | |
| 211 | public: |
| 212 | void Default(); |
| 213 | void CompileFunc(StdCompiler *pComp); |
| 214 | }; |
| 215 | |
| 216 | class C4SLandscape |
| 217 | { |
| 218 | public: |
| 219 | bool ExactLandscape; |
| 220 | C4SVal VegLevel; |
| 221 | C4IDList Vegetation; |
| 222 | C4SVal InEarthLevel; |
| 223 | C4IDList InEarth; |
| 224 | bool BottomOpen, TopOpen; |
| 225 | int32_t LeftOpen, RightOpen; |
| 226 | bool AutoScanSideOpen; |
| 227 | char SkyDef[C4MaxDefString + 1]; |
| 228 | int32_t SkyDefFade[6]; |
| 229 | bool NoSky; |
| 230 | bool NoScan; |
| 231 | C4SVal Gravity; |
| 232 | // Dynamic map |
| 233 | C4SVal MapWdt, MapHgt, MapZoom; |
| 234 | C4SVal Amplitude, Phase, Period, Random; |
| 235 | C4SVal LiquidLevel; |
| 236 | bool MapPlayerExtend; |
| 237 | C4NameList Layers; |
| 238 | char Material[C4M_MaxDefName + 1]; |
| 239 | char Liquid[C4M_MaxDefName + 1]; |
| 240 | bool KeepMapCreator; // set if the mapcreator will be needed in the scenario (for DrawDefMap) |
| 241 | int32_t SkyScrollMode; // sky scrolling mode for newgfx |
| 242 | int32_t NewStyleLandscape; // if set to 2, the landscape uses up to 125 mat/texture pairs |
| 243 | int32_t FoWRes; // chunk size of FoGOfWar |
| 244 | bool ShadeMaterials; |
| 245 | |
| 246 | public: |
| 247 | void Default(); |
| 248 | void GetMapSize(int32_t &rWdt, int32_t &rHgt, int32_t iPlayerNum); |
| 249 | void CompileFunc(StdCompiler *pComp, bool newScenario = true); |
| 250 | }; |
| 251 | |
| 252 | class C4SWeather |
| 253 | { |
| 254 | public: |
| 255 | C4SVal Climate; |
| 256 | C4SVal StartSeason, YearSpeed; |
| 257 | C4SVal Rain, Lightning, Wind; |
| 258 | char Precipitation[C4M_MaxName + 1]; |
| 259 | bool NoGamma; |
| 260 | |
| 261 | public: |
| 262 | void Default(); |
| 263 | void CompileFunc(StdCompiler *pComp); |
| 264 | }; |
| 265 | |
| 266 | class C4SAnimals |
| 267 | { |
| 268 | public: |
| 269 | C4IDList FreeLife; |
| 270 | C4IDList EarthNest; |
| 271 | |
| 272 | public: |
| 273 | void Default(); |
| 274 | void CompileFunc(StdCompiler *pComp); |
| 275 | }; |
| 276 | |
| 277 | class C4SEnvironment |
| 278 | { |
| 279 | public: |
| 280 | C4IDList Objects; |
| 281 | |
| 282 | public: |
| 283 | void Default(); |
| 284 | void CompileFunc(StdCompiler *pComp); |
| 285 | }; |
| 286 | |
| 287 | class C4SDisasters |
| 288 | { |
| 289 | public: |
| 290 | C4SVal Volcano; |
| 291 | C4SVal Earthquake; |
| 292 | C4SVal Meteorite; |
| 293 | |
| 294 | public: |
| 295 | void Default(); |
| 296 | void CompileFunc(StdCompiler *pComp); |
| 297 | }; |
| 298 | |
| 299 | class C4Scenario |
| 300 | { |
| 301 | public: |
| 302 | C4Scenario(); |
| 303 | |
| 304 | public: |
| 305 | C4SHead Head; |
| 306 | C4SDefinitions Definitions; |
| 307 | C4SGame Game; |
| 308 | C4SPlrStart PlrStart[C4S_MaxPlayer]; |
| 309 | C4SLandscape Landscape; |
| 310 | C4SAnimals Animals; |
| 311 | C4SWeather Weather; |
| 312 | C4SDisasters Disasters; |
| 313 | C4SEnvironment Environment; |
| 314 | |
| 315 | public: |
| 316 | void SetExactLandscape(); |
| 317 | void Clear(); |
| 318 | void Default(); |
| 319 | bool Load(C4Group &hGroup, bool fLoadSection = false); |
| 320 | bool Save(C4Group &hGroup, bool fSaveSection = false); |
| 321 | void CompileFunc(StdCompiler *pComp, bool fSection); |
| 322 | int32_t GetMinPlayer(); // will try to determine the minimum player count for this scenario |
| 323 | |
| 324 | protected: |
| 325 | bool Compile(const char *szSource, bool fLoadSection = false); |
| 326 | }; |
| 327 | |
| 328 | class C4ScenarioSection; |
| 329 | |
| 330 | extern const char *C4ScenSect_Main; |
| 331 | |
| 332 | // ref to one scenario section |
| 333 | class C4ScenarioSection |
| 334 | { |
| 335 | public: |
| 336 | C4ScenarioSection(char *szName); |
| 337 | ~C4ScenarioSection(); |
| 338 | |
| 339 | public: |
| 340 | bool fModified; // if set, the file is temp and contains runtime landscape and/or object data |
| 341 | |
| 342 | C4ScenarioSection *pNext; // next member of linked list |
| 343 | |
| 344 | public: |
| 345 | bool ScenarioLoad(char *szFilename); // called when scenario is loaded: extract to temp store |
| 346 | C4Group *GetGroupfile(C4Group &rGrp); // get group at section file (returns temp group, scenario subgroup or scenario group itself) |
| 347 | bool EnsureTempStore(bool fExtractLandscape, bool ); // make sure that a temp file is created, and nothing is modified within the main scenario file |
| 348 | const char *GetName() const; |
| 349 | const char *GetTempFilename() const; |
| 350 | |
| 351 | private: |
| 352 | std::string Name; // section name |
| 353 | std::string TempFilename; // filename of data file if in temp dir |
| 354 | std::string Filename; // filename of section in scenario file |
| 355 | }; |
| 356 | |