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 /* Structures for object and player info components */ 19 20 #ifndef INC_C4ScenarioParameters 21 #define INC_C4ScenarioParameters 22 23 // Definition for a custom setting for the scenario 24 class C4ScenarioParameterDef 25 { 26 public: 27 // what kind of parameter? 28 enum ParameterType 29 { 30 SPDT_Enum, // only one type so far 31 }; 32 33 // single option for an enum type parameter 34 struct Option 35 { 36 int32_t Value; // integer value that will be assigned to the script constant 37 StdCopyStrBuf Name; // localized name 38 StdCopyStrBuf Description; // localized description. to be displayed as hover text for this option. 39 40 void CompileFunc(StdCompiler *pComp); 41 }; 42 43 private: 44 StdCopyStrBuf Name; // localized name 45 StdCopyStrBuf Description; // localized description. to be displayed as hover text for this parameter input control 46 StdCopyStrBuf ID; // Identifier for value storage and script access 47 ParameterType Type; // Type of parameter. Always enum. 48 49 std::vector<Option> Options; // possible options to be selected for an enum type 50 int32_t Default{0}; // value of option selected by default for an enum type 51 int32_t LeagueValue{0}; // if nonzero, option is forced to this value in league games 52 53 StdCopyStrBuf Achievement; // if this parameter is an achievement, this string contains the name of the achievement graphics to be used 54 55 public: 56 C4ScenarioParameterDef() = default; 57 ~C4ScenarioParameterDef() = default; 58 GetName()59 const char *GetName() const { return Name.getData(); } GetDescription()60 const char *GetDescription() const { return Description.getData(); } GetID()61 const char *GetID() const { return ID.getData(); } GetType()62 ParameterType GetType() const { return Type; } GetDefault()63 int32_t GetDefault() const { return Default; } GetLeagueValue()64 int32_t GetLeagueValue() const { return LeagueValue; } 65 const Option *GetOptionByValue(int32_t val) const; 66 const Option *GetOptionByIndex(size_t idx) const; 67 IsAchievement()68 bool IsAchievement() const { return Achievement.getLength()>0; } GetAchievement()69 const char *GetAchievement() const { return Achievement.getData(); } 70 71 void CompileFunc(StdCompiler *pComp); 72 }; 73 74 // Definitions of custom parameters that can be set before scenario start 75 class C4ScenarioParameterDefs 76 { 77 std::vector<C4ScenarioParameterDef> Parameters; 78 79 public: 80 C4ScenarioParameterDefs() = default; 81 ~C4ScenarioParameterDefs() = default; 82 Clear()83 void Clear() { Parameters.clear(); } 84 85 const C4ScenarioParameterDef *GetParameterDefByIndex(size_t idx) const; 86 87 bool Load(C4Group &hGroup, class C4LangStringTable *pLang); 88 void CompileFunc(StdCompiler *pComp); 89 90 void RegisterScriptConstants(const class C4ScenarioParameters &values); // register constants for all parameters in script engine 91 }; 92 93 // Parameter values that correspond to settings offered in C4ScenarioParameterDefs 94 class C4ScenarioParameters 95 { 96 std::map<StdCopyStrBuf, int32_t> Parameters; 97 98 public: 99 C4ScenarioParameters() = default; 100 ~C4ScenarioParameters() = default; 101 102 void Clear(); 103 void Merge(const C4ScenarioParameters &other); 104 105 int32_t GetValueByID(const char *id, int32_t default_value) const; 106 void SetValue(const char *id, int32_t value, bool only_if_larger); 107 108 void CompileFunc(StdCompiler *pComp); 109 110 static StdStrBuf AddFilename2ID(const char *filename, const char *id); 111 }; 112 113 114 115 #endif // INC_C4ScenarioParameters 116