OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ScenarioParameters.h
Go to the documentation of this file.
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 // Maps IDs to achievement graphics to be shown beside scenarios (and maybe other things)
25 {
26  std::map<StdCopyStrBuf, C4FacetSurface *> Graphics;
27  int32_t idGrp; // ID of group file from which achievements were loaded
28 
29 public:
30  C4AchievementGraphics() : idGrp(0) {}
31 
32  // Init will always load all achievement files from the first group that contains achievements
33  bool Init(C4Group &File);
34  bool Init(C4GroupSet &Files);
35  void Clear();
36 
37  C4FacetSurface *FindByName(const char *name) const;
38 };
39 
40 // Definition for a custom setting for the scenario
42 {
43 public:
44  // what kind of parameter?
46  {
47  SPDT_Enum, // only one type so far
48  };
49 
50  // single option for an enum type parameter
51  struct Option
52  {
53  int32_t Value; // integer value that will be assigned to the script constant
54  StdCopyStrBuf Name; // localized name
55  StdCopyStrBuf Description; // localized description. to be displayed as hover text for this option.
56 
57  void CompileFunc(StdCompiler *pComp);
58  };
59 
60 private:
61  StdCopyStrBuf Name; // localized name
62  StdCopyStrBuf Description; // localized description. to be displayed as hover text for this parameter input control
63  StdCopyStrBuf ID; // Identifier for value storage and script access
64  ParameterType Type; // Type of parameter. Always enum.
65 
66  std::vector<Option> Options; // possible options to be selected for an enum type
67  int32_t Default; // value of option selected by default for an enum type
68  int32_t LeagueValue; // if nonzero, option is forced to this value in league games
69 
70  StdCopyStrBuf Achievement; // if this parameter is an achievement, this string contains the name of the achievement graphics to be used
71 
72 public:
73  C4ScenarioParameterDef() : Default(0), LeagueValue(0) {}
75 
76  const char *GetName() const { return Name.getData(); }
77  const char *GetDescription() const { return Description.getData(); }
78  const char *GetID() const { return ID.getData(); }
79  ParameterType GetType() const { return Type; }
80  int32_t GetDefault() const { return Default; }
81  int32_t GetLeagueValue() const { return LeagueValue; }
82  const Option *GetOptionByValue(int32_t val) const;
83  const Option *GetOptionByIndex(size_t idx) const;
84 
85  bool IsAchievement() const { return Achievement.getLength()>0; }
86  const char *GetAchievement() const { return Achievement.getData(); }
87 
88  void CompileFunc(StdCompiler *pComp);
89 };
90 
91 // Definitions of custom parameters that can be set before scenario start
93 {
94  std::vector<C4ScenarioParameterDef> Parameters;
95 
96 public:
99 
100  void Clear() { Parameters.clear(); }
101 
102  const C4ScenarioParameterDef *GetParameterDefByIndex(size_t idx) const;
103 
104  bool Load(C4Group &hGroup, class C4LangStringTable *pLang);
105  void CompileFunc(StdCompiler *pComp);
106 
107  void RegisterScriptConstants(const class C4ScenarioParameters &values); // register constants for all parameters in script engine
108 };
109 
110 // Parameter values that correspond to settings offered in C4ScenarioParameterDefs
112 {
113  std::map<StdCopyStrBuf, int32_t> Parameters;
114 
115 public:
118 
119  void Clear();
120  void Merge(const C4ScenarioParameters &other);
121 
122  int32_t GetValueByID(const char *id, int32_t default_value) const;
123  void SetValue(const char *id, int32_t value, bool only_if_larger);
124 
125  void CompileFunc(StdCompiler *pComp);
126 
127  static StdStrBuf AddFilename2ID(const char *filename, const char *id);
128 };
129 
130 
131 
132 #endif // INC_C4ScenarioParameters
const char * getData() const
Definition: StdBuf.h:450
bool Load(C4Group &hGroup, class C4LangStringTable *pLang)
const C4ScenarioParameterDef * GetParameterDefByIndex(size_t idx) const
const Option * GetOptionByIndex(size_t idx) const
void CompileFunc(StdCompiler *pComp)
static StdStrBuf AddFilename2ID(const char *filename, const char *id)
void CompileFunc(StdCompiler *pComp)
bool Init(C4Group &File)
ParameterType GetType() const
const char * GetName() const
const char * GetDescription() const
const char * GetID() const
int32_t GetLeagueValue() const
const Option * GetOptionByValue(int32_t val) const
void Merge(const C4ScenarioParameters &other)
void CompileFunc(StdCompiler *pComp)
C4FacetSurface * FindByName(const char *name) const
const char * GetAchievement() const
size_t getLength() const
Definition: StdBuf.h:453
void CompileFunc(StdCompiler *pComp)
void RegisterScriptConstants(const class C4ScenarioParameters &values)
int32_t GetValueByID(const char *id, int32_t default_value) const
void SetValue(const char *id, int32_t value, bool only_if_larger)