OpenClonk
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

◆ FnParAlgo()

C4MapScriptAlgo * FnParAlgo ( C4PropList algo_par)

Definition at line 541 of file C4MapScriptAlgo.cpp.

542 {
543  // Convert script function parameter to internal C4MapScriptAlgo class. Also resolve all parameters and nested child algos.
544  if (!algo_par) return nullptr;
545 
546  C4MapScriptAlgo *inner = FnParAlgoInner(algo_par);
547 
548  // if the Material property is set, use that material:
549  C4String *material = algo_par->GetPropertyStr(P_Material);
550  if (material) { // set inner material by wrapping with SetMaterial algo.
551  uint8_t fg = 0, bg = 0;
552  if (!FnParTexCol(material, fg, bg))
553  throw C4AulExecError("Invalid Material in map script algorithm.");
554  return new C4MapScriptAlgoSetMaterial(inner, fg, bg);
555  }
556 
557  return inner; // otherwise, just return the original algo
558 }
bool FnParTexCol(C4String *mattex, uint8_t &fg, uint8_t &bg)
Definition: C4MapScript.cpp:48
@ P_Material
C4String * GetPropertyStr(C4PropertyName k) const
Definition: C4PropList.cpp:744

Referenced by C4MapScriptAlgoModifier::C4MapScriptAlgoModifier().

Here is the caller graph for this function:

◆ FnParRect()

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

Definition at line 221 of file C4MapScript.cpp.

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 }
C4Rect GetBounds() const
Definition: C4Rect.h:28
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

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

Here is the call graph for this function:

◆ FnParTexCol()

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

Definition at line 48 of file C4MapScript.cpp.

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 }
const int C4M_MaxTexIndex
Definition: C4Constants.h:51
C4MapScriptHost MapScript
bool TexColSingle(const char *mattex, uint8_t &col)
Definition: C4MapScript.cpp:37
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:239
C4TextureMap * pTexMap
Definition: C4MapScript.h:365
const char * GetCStr() const
Definition: C4StringTable.h:49
BYTE DefaultBkgMatTex(BYTE fg) const
Definition: C4Texture.cpp:504

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

Here is the call graph for this function:

◆ TexColSingle()

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

Definition at line 37 of file C4MapScript.cpp.

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
int32_t GetIndexMatTex(const char *szMaterialTexture, const char *szDefaultTexture=nullptr, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr)
Definition: C4Texture.cpp:441

References SEqual().

Referenced by FnParTexCol().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ MapScript