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:668
int32_t GetPropertyInt(C4PropertyName k, int32_t default_val=0) const
Definition: C4PropList.cpp:863
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

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 220 of file C4MapScript.cpp.

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

221 {
222  // Convert rect parameter passed to script function to C4Rect structure
223  // and makes sure it is completely contained in bounding rectangle of layer
224  // rect==nullptr defaults to bounding rectangle of layer
225  *rc_bounds = layer->GetBounds();
226  if (!rect) return true; // nil is OK for rect parameter. Defaults to bounds rectangle
227  if (rect->GetSize() != 4) return false;
228  rc_bounds->Intersect(C4Rect(rect->GetItem(0).getInt(), rect->GetItem(1).getInt(), rect->GetItem(2).getInt(), rect->GetItem(3).getInt()));
229  return true;
230 }
Definition: C4Rect.h:29
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 47 of file C4MapScript.cpp.

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

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

Here is the call graph for this function:

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

Definition at line 36 of file C4MapScript.cpp.

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

Referenced by FnParTexCol().

37 {
38  if (SEqual(mattex, DrawFn_Transparent_Name)) { col = 0; return true; }
39  if (SEqual(mattex, DrawFn_Sky_Name)) { col = C4M_MaxTexIndex; return true; }
40 
41  col = ::MapScript.pTexMap->GetIndexMatTex(mattex);
42  if (col == 0) return false;
43 
44  return true;
45 }
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
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:450

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation