OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4MapScript.cpp File Reference
Include dependency graph for C4MapScript.cpp:

Go to the source code of this file.

Functions

C4MapScriptAlgoFnParAlgo (C4PropList *algo_par)
 
bool TexColSingle (const char *mattex, uint8_t &col)
 
bool FnParTexCol (C4String *mattex, uint8_t &fg, uint8_t &bg)
 
bool FnParRect (C4MapScriptLayer *layer, C4ValueArray *rect, C4Rect *rc_bounds)
 

Variables

C4MapScriptHost MapScript
 

Function Documentation

C4MapScriptAlgo * FnParAlgo ( C4PropList algo_par)

Definition at line 490 of file C4MapScriptAlgo.cpp.

References FormatString(), C4PropList::GetMapScriptLayer(), C4PropList::GetPropertyInt(), MAPALGO_And, MAPALGO_Border, MAPALGO_Ellipsis, MAPALGO_Filter, MAPALGO_Layer, MAPALGO_Lines, MAPALGO_Not, MAPALGO_Offset, MAPALGO_Or, MAPALGO_Polygon, MAPALGO_Rect, MAPALGO_RndChecker, MAPALGO_Rotate, MAPALGO_Scale, MAPALGO_Turbulence, MAPALGO_Xor, and P_Algo.

Referenced by C4MapScriptAlgoModifier::C4MapScriptAlgoModifier().

491 {
492  // Convert script function parameter to internal C4MapScriptAlgo class. Also resolve all parameters and nested child algos.
493  if (!algo_par) return nullptr;
494  // if algo is a layer, take that directly
495  C4MapScriptLayer *algo_layer = algo_par->GetMapScriptLayer();
496  if (algo_layer) return new C4MapScriptAlgoLayer(algo_layer);
497  // otherwise, determine by proplist parameter "algo"
498  switch (algo_par->GetPropertyInt(P_Algo))
499  {
500  case MAPALGO_Layer: return new C4MapScriptAlgoLayer(algo_par);
501  case MAPALGO_RndChecker: return new C4MapScriptAlgoRndChecker(algo_par);
502  case MAPALGO_And: return new C4MapScriptAlgoAnd(algo_par);
503  case MAPALGO_Or: return new C4MapScriptAlgoOr(algo_par);
504  case MAPALGO_Xor: return new C4MapScriptAlgoXor(algo_par);
505  case MAPALGO_Not: return new C4MapScriptAlgoNot(algo_par);
506  case MAPALGO_Offset: return new C4MapScriptAlgoOffset(algo_par);
507  case MAPALGO_Scale: return new C4MapScriptAlgoScale(algo_par);
508  case MAPALGO_Rotate: return new C4MapScriptAlgoRotate(algo_par);
509  case MAPALGO_Rect: return new C4MapScriptAlgoRect(algo_par);
510  case MAPALGO_Ellipsis: return new C4MapScriptAlgoEllipsis(algo_par);
511  case MAPALGO_Polygon: return new C4MapScriptAlgoPolygon(algo_par);
512  case MAPALGO_Lines: return new C4MapScriptAlgoLines(algo_par);
513  case MAPALGO_Turbulence: return new C4MapScriptAlgoTurbulence(algo_par);
514  case MAPALGO_Border: return new C4MapScriptAlgoBorder(algo_par);
515  case MAPALGO_Filter: return new C4MapScriptAlgoFilter(algo_par);
516  default:
517  throw C4AulExecError(FormatString("got invalid algo: %d", algo_par->GetPropertyInt(P_Algo)).getData());
518  }
519  return nullptr;
520 }
virtual class C4MapScriptLayer * GetMapScriptLayer()
Definition: C4PropList.cpp:687
int32_t GetPropertyInt(C4PropertyName k, int32_t default_val=0) const
Definition: C4PropList.cpp:882
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

Here is the caller graph for this function:

bool FnParRect ( C4MapScriptLayer layer,
C4ValueArray rect,
C4Rect rc_bounds 
)

Definition at line 221 of file C4MapScript.cpp.

References C4MapScriptLayer::GetBounds(), C4Value::getInt(), C4ValueArray::GetItem(), C4ValueArray::GetSize(), and C4Rect::Intersect().

222 {
223  // Convert rect parameter passed to script function to C4Rect structure
224  // and makes sure it is completely contained in bounding rectangle of layer
225  // rect==nullptr defaults to bounding rectangle of layer
226  *rc_bounds = layer->GetBounds();
227  if (!rect) return true; // nil is OK for rect parameter. Defaults to bounds rectangle
228  if (rect->GetSize() != 4) return false;
229  rc_bounds->Intersect(C4Rect(rect->GetItem(0).getInt(), rect->GetItem(1).getInt(), rect->GetItem(2).getInt(), rect->GetItem(3).getInt()));
230  return true;
231 }
Definition: C4Rect.h:27
C4Rect GetBounds() const
void Intersect(const C4Rect &r2)
Definition: C4Rect.cpp:100
const C4Value & GetItem(int32_t iElem) const
Definition: C4ValueArray.h:38
int32_t GetSize() const
Definition: C4ValueArray.h:36
int32_t getInt() const
Definition: C4Value.h:112

Here is the call graph for this function:

bool FnParTexCol ( C4String mattex,
uint8_t &  fg,
uint8_t &  bg 
)

Definition at line 48 of file C4MapScript.cpp.

References C4M_MaxTexIndex, C4TextureMap::DefaultBkgMatTex(), C4String::GetCStr(), MapScript, C4MapScriptHost::pTexMap, SCharPos(), and TexColSingle().

49 {
50  // Return index of material-texture definition for a single color
51  // Defaults to underground (tunnel background) color. Prefix material with ^ to get overground (sky background) color,
52  // or specify as mattex1:mattex2 for foreground-background pair.
53  if (!mattex || !mattex->GetCStr()) return false;
54 
55  int sep_pos = SCharPos(':', mattex->GetCStr());
56  if (sep_pos == -1)
57  {
58  const char *cmattex = mattex->GetCStr();
59  bool ift = true;
60  if (*cmattex == '^') { ift=false; ++cmattex; }
61 
62  uint8_t col;
63  if (!TexColSingle(cmattex, col)) return false;
64 
65  fg = col;
66  if (ift)
68  else
69  bg = C4M_MaxTexIndex; // sky
70 
71  return true;
72  }
73  else
74  {
75  const char *cmattex = mattex->GetCStr();
76  std::string fg_mattex(cmattex, cmattex + sep_pos);
77  std::string bg_mattex(cmattex + sep_pos + 1);
78 
79  uint8_t fg_col, bg_col;
80  if (!TexColSingle(fg_mattex.c_str(), fg_col)) return false;
81  if (!TexColSingle(bg_mattex.c_str(), bg_col)) return false;
82 
83  fg = fg_col; bg = bg_col;
84  return true;
85  }
86 }
BYTE DefaultBkgMatTex(BYTE fg) const
Definition: C4Texture.cpp:504
const char * GetCStr() const
Definition: C4StringTable.h:49
bool TexColSingle(const char *mattex, uint8_t &col)
Definition: C4MapScript.cpp:37
C4MapScriptHost MapScript
C4TextureMap * pTexMap
Definition: C4MapScript.h:353
const int C4M_MaxTexIndex
Definition: C4Constants.h:51
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:211

Here is the call graph for this function:

bool TexColSingle ( const char *  mattex,
uint8_t &  col 
)

Definition at line 37 of file C4MapScript.cpp.

References C4M_MaxTexIndex, C4TextureMap::GetIndexMatTex(), MapScript, C4MapScriptHost::pTexMap, and SEqual().

Referenced by FnParTexCol().

38 {
39  if (SEqual(mattex, DrawFn_Transparent_Name)) { col = 0; return true; }
40  if (SEqual(mattex, DrawFn_Sky_Name)) { col = C4M_MaxTexIndex; return true; }
41 
42  col = ::MapScript.pTexMap->GetIndexMatTex(mattex);
43  if (col == 0) return false;
44 
45  return true;
46 }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
C4MapScriptHost MapScript
C4TextureMap * pTexMap
Definition: C4MapScript.h:353
const int C4M_MaxTexIndex
Definition: C4Constants.h:51
int32_t GetIndexMatTex(const char *szMaterialTexture, const char *szDefaultTexture=nullptr, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr)
Definition: C4Texture.cpp:441

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation