OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ScenarioParameterDefs Class Reference

#include <C4ScenarioParameters.h>

Public Member Functions

 C4ScenarioParameterDefs ()
 
 ~C4ScenarioParameterDefs ()
 
void Clear ()
 
const C4ScenarioParameterDefGetParameterDefByIndex (size_t idx) const
 
bool Load (C4Group &hGroup, class C4LangStringTable *pLang)
 
void CompileFunc (StdCompiler *pComp)
 
void RegisterScriptConstants (const class C4ScenarioParameters &values)
 

Detailed Description

Definition at line 92 of file C4ScenarioParameters.h.

Constructor & Destructor Documentation

C4ScenarioParameterDefs::C4ScenarioParameterDefs ( )
inline

Definition at line 97 of file C4ScenarioParameters.h.

97 {}
C4ScenarioParameterDefs::~C4ScenarioParameterDefs ( )
inline

Definition at line 98 of file C4ScenarioParameters.h.

98 {}

Member Function Documentation

void C4ScenarioParameterDefs::Clear ( )
inline

Definition at line 100 of file C4ScenarioParameters.h.

Referenced by C4Game::Clear().

100 { Parameters.clear(); }

Here is the caller graph for this function:

void C4ScenarioParameterDefs::CompileFunc ( StdCompiler pComp)

Definition at line 123 of file C4ScenarioParameters.cpp.

References mkSTLContainerAdapt(), StdCompiler::SEP_NONE, and StdCompiler::Value().

124 {
125  pComp->Value(mkSTLContainerAdapt(Parameters, StdCompiler::SEP_NONE));
126 }
void Value(const T &rStruct)
Definition: StdCompiler.h:171
StdSTLContainerAdapt< C > mkSTLContainerAdapt(C &rTarget, StdCompiler::Sep eSep=StdCompiler::SEP_SEP)
Definition: StdAdaptors.h:679

Here is the call graph for this function:

const C4ScenarioParameterDef * C4ScenarioParameterDefs::GetParameterDefByIndex ( size_t  idx) const

Definition at line 128 of file C4ScenarioParameters.cpp.

Referenced by C4GameParameters::EnforceLeagueRules(), and C4ScenarioListLoader::Scenario::LoadCustomPre().

129 {
130  if (idx >= Parameters.size()) return nullptr;
131  return &Parameters[idx];
132 }

Here is the caller graph for this function:

bool C4ScenarioParameterDefs::Load ( C4Group hGroup,
class C4LangStringTable pLang 
)

Definition at line 134 of file C4ScenarioParameters.cpp.

References C4CFN_ScenarioParameterDefs, C4Group::LoadEntryString(), and C4LangStringTable::ReplaceStrings().

Referenced by C4Game::OpenScenario().

135 {
136  // Load buffer, localize and parse
137  StdStrBuf Buf;
138  if (!hGroup.LoadEntryString(C4CFN_ScenarioParameterDefs,&Buf)) return false;
139  if (pLang) pLang->ReplaceStrings(Buf);
140  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(*this, Buf, C4CFN_ScenarioParameterDefs))
141  { return false; }
142  return true;
143 }
#define C4CFN_ScenarioParameterDefs
Definition: C4Components.h:43
bool LoadEntryString(const char *szEntryName, StdStrBuf *Buf)
Definition: C4Group.cpp:1932

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ScenarioParameterDefs::RegisterScriptConstants ( const class C4ScenarioParameters values)

Definition at line 145 of file C4ScenarioParameters.cpp.

References C4VInt(), StdStrBuf::Format(), StdStrBuf::getData(), C4ScenarioParameters::GetValueByID(), C4PropList::NewStatic(), C4StringTable::P, P_SCENPAR, C4AulScriptEngine::RegisterGlobalConstant(), C4StringTable::RegString(), ScriptEngine, and Strings.

Referenced by C4Game::InitGame().

146 {
147  // register constants for all parameters in script engine
148 
149  // old-style: one constant per parameter
150  for (auto i = Parameters.cbegin(); i != Parameters.cend(); ++i)
151  {
152  StdStrBuf constant_name;
153  constant_name.Format("SCENPAR_%s", i->GetID());
154  int32_t constant_value = values.GetValueByID(i->GetID(), i->GetDefault());
155  ::ScriptEngine.RegisterGlobalConstant(constant_name.getData(), C4VInt(constant_value));
156  }
157 
158  // new-style: all constants in a proplist
159  auto scenpar = C4PropList::NewStatic(nullptr, nullptr, &Strings.P[P_SCENPAR]);
160  for (auto i = Parameters.cbegin(); i != Parameters.cend(); ++i)
161  {
162  int32_t constant_value = values.GetValueByID(i->GetID(), i->GetDefault());
163  scenpar->SetPropertyByS(Strings.RegString(StdStrBuf(i->GetID())), C4VInt(constant_value));
164  }
165  scenpar->Freeze();
166  ::ScriptEngine.RegisterGlobalConstant("SCENPAR", C4Value(scenpar));
167 }
const char * getData() const
Definition: StdBuf.h:450
C4String P[P_LAST]
void RegisterGlobalConstant(const char *szName, const C4Value &rValue)
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
C4String * RegString(StdStrBuf String)
C4Value C4VInt(int32_t i)
Definition: C4Value.h:242
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
C4StringTable Strings
Definition: C4Globals.cpp:42
static C4PropListStatic * NewStatic(C4PropList *prototype, const C4PropListStatic *parent, C4String *key)
Definition: C4PropList.cpp:70

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: