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

#include <C4ScenarioParameters.h>

Public Member Functions

 C4ScenarioParameterDefs ()=default
 ~C4ScenarioParameterDefs ()=default
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 75 of file C4ScenarioParameters.h.

Constructor & Destructor Documentation

C4ScenarioParameterDefs::C4ScenarioParameterDefs ( )
C4ScenarioParameterDefs::~C4ScenarioParameterDefs ( )

Member Function Documentation

void C4ScenarioParameterDefs::Clear ( )

Definition at line 83 of file C4ScenarioParameters.h.

Referenced by C4Game::Clear().

83 { Parameters.clear(); }

Here is the caller graph for this function:

void C4ScenarioParameterDefs::CompileFunc ( StdCompiler pComp)

Definition at line 66 of file C4ScenarioParameters.cpp.

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

67 {
68  pComp->Value(mkSTLContainerAdapt(Parameters, StdCompiler::SEP_NONE));
69 }
void Value(const T &rStruct)
Definition: StdCompiler.h:161
StdSTLContainerAdapt< C > mkSTLContainerAdapt(C &rTarget, StdCompiler::Sep eSep=StdCompiler::SEP_SEP)
Definition: StdAdaptors.h:699

Here is the call graph for this function:

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

Definition at line 71 of file C4ScenarioParameters.cpp.

Referenced by C4GameParameters::EnforceLeagueRules().

72 {
73  if (idx >= Parameters.size()) return nullptr;
74  return &Parameters[idx];
75 }

Here is the caller graph for this function:

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

Definition at line 77 of file C4ScenarioParameters.cpp.

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

Referenced by C4Game::OpenScenario().

78 {
79  // Load buffer, localize and parse
80  StdStrBuf Buf;
81  if (!hGroup.LoadEntryString(C4CFN_ScenarioParameterDefs,&Buf)) return false;
82  if (pLang) pLang->ReplaceStrings(Buf);
83  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(*this, Buf, C4CFN_ScenarioParameterDefs))
84  { return false; }
85  return true;
86 }
#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 88 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().

89 {
90  // register constants for all parameters in script engine
92  // old-style: one constant per parameter
93  for (const auto & Parameter : Parameters)
94  {
95  StdStrBuf constant_name;
96  constant_name.Format("SCENPAR_%s", Parameter.GetID());
97  int32_t constant_value = values.GetValueByID(Parameter.GetID(), Parameter.GetDefault());
98  ::ScriptEngine.RegisterGlobalConstant(constant_name.getData(), C4VInt(constant_value));
99  }
101  // new-style: all constants in a proplist
102  auto scenpar = C4PropList::NewStatic(nullptr, nullptr, &Strings.P[P_SCENPAR]);
103  for (const auto & Parameter : Parameters)
104  {
105  int32_t constant_value = values.GetValueByID(Parameter.GetID(), Parameter.GetDefault());
106  scenpar->SetPropertyByS(Strings.RegString(StdStrBuf(Parameter.GetID())), C4VInt(constant_value));
107  }
108  scenpar->Freeze();
109  ::ScriptEngine.RegisterGlobalConstant("SCENPAR", C4Value(scenpar));
110 }
const char * getData() const
Definition: StdBuf.h:442
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:174
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: