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

#include <C4MapScript.h>

Inheritance diagram for C4MapScriptAlgoRndChecker:
Collaboration diagram for C4MapScriptAlgoRndChecker:

Public Member Functions

 C4MapScriptAlgoRndChecker (const C4PropList *props)
bool operator() (int32_t x, int32_t y, uint8_t &fg, uint8_t &bg) const override

Protected Member Functions

bool GetXYProps (const C4PropList *props, C4PropertyName k, int32_t *out_xy, bool zero_defaults)

Detailed Description

Definition at line 103 of file C4MapScript.h.

Constructor & Destructor Documentation

C4MapScriptAlgoRndChecker::C4MapScriptAlgoRndChecker ( const C4PropList props)

Definition at line 69 of file C4MapScriptAlgo.cpp.

References Abs(), Clamp(), C4Value::getBool(), C4PropList::GetProperty(), C4PropList::GetPropertyInt(), P_FixedOffset, P_Hgt, P_Ratio, P_Seed, P_Wdt, and Random().

70 {
71  // Get MAPALGO_RndChecker properties
72  seed = props->GetPropertyInt(P_Seed);
73  if (!seed) seed = Random(65536);
74  set_percentage = Clamp(props->GetPropertyInt(P_Ratio), 0, 100);
75  if (!set_percentage) set_percentage = 50;
76  checker_wdt = Abs(props->GetPropertyInt(P_Wdt));
77  if (!checker_wdt) checker_wdt = 10;
78  checker_hgt = Abs(props->GetPropertyInt(P_Hgt));
79  if (!checker_hgt) checker_hgt = 10;
80  C4Value is_fixed_offset_v;
81  if (props->GetProperty(P_FixedOffset, &is_fixed_offset_v))
82  is_fixed_offset = is_fixed_offset_v.getBool();
83  else
84  is_fixed_offset = false;
85 }
uint32_t Random()
Definition: C4Random.cpp:43
bool GetProperty(C4PropertyName k, C4Value *pResult) const
Definition: C4PropList.h:101
bool getBool() const
Definition: C4Value.h:113
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44
int32_t GetPropertyInt(C4PropertyName k, int32_t default_val=0) const
Definition: C4PropList.cpp:886
T Abs(T val)
Definition: Standard.h:42

Here is the call graph for this function:

Member Function Documentation

bool C4MapScriptAlgo::GetXYProps ( const C4PropList props,
C4PropertyName  k,
int32_t *  out_xy,
bool  zero_defaults 

Definition at line 26 of file C4MapScriptAlgo.cpp.

References FormatString(), C4Value::getArray(), C4String::GetCStr(), C4Value::getInt(), C4ValueArray::GetItem(), C4PropList::GetProperty(), C4ValueArray::GetSize(), C4PropList::HasProperty(), C4StringTable::P, and Strings.

Referenced by C4MapScriptAlgoBorder::C4MapScriptAlgoBorder(), and C4MapScriptAlgoTurbulence::C4MapScriptAlgoTurbulence().

27 {
28  // Evaluate property named "k" in proplist props to store two numbers in out_xy:
29  // If props->k is a single integer, fill both numbers in out_xy with it
30  // If props->k is an array, check that it contains two numbers and store them in out_xy
31  if (!props->HasProperty(&Strings.P[k]))
32  {
33  if (zero_defaults) out_xy[0] = out_xy[1] = 0;
34  return false;
35  }
36  C4Value val; C4ValueArray *arr;
37  props->GetProperty(k, &val);
38  if ((arr = val.getArray()))
39  {
40  if (arr->GetSize() != 2)
41  throw C4AulExecError(FormatString(R"(C4MapScriptAlgo: Expected either integer or array with two integer elements in property "%s".)", Strings.P[k].GetCStr()).getData());
42  out_xy[0] = arr->GetItem(0).getInt();
43  out_xy[1] = arr->GetItem(1).getInt();
44  }
45  else
46  {
47  out_xy[0] = out_xy[1] = val.getInt();
48  }
49  return true;
50 }
C4String P[P_LAST]
bool GetProperty(C4PropertyName k, C4Value *pResult) const
Definition: C4PropList.h:101
const char * GetCStr() const
Definition: C4StringTable.h:49
const C4Value & GetItem(int32_t iElem) const
Definition: C4ValueArray.h:38
C4StringTable Strings
Definition: C4Globals.cpp:42
C4ValueArray * getArray() const
Definition: C4Value.h:118
int32_t GetSize() const
Definition: C4ValueArray.h:36
int32_t getInt() const
Definition: C4Value.h:112
bool HasProperty(C4String *k) const
Definition: C4PropList.h:118
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 C4MapScriptAlgoRndChecker::operator() ( int32_t  x,
int32_t  y,
uint8_t &  fg,
uint8_t &  bg 
) const

Implements C4MapScriptAlgo.

Definition at line 99 of file C4MapScriptAlgo.cpp.

References QuerySeededRandomField().

100 {
101  // Evaluate MAPALGO_RndChecker at x,y: Query a seeded random field scaled by checker_wdt,checker_hgt
102  if (!is_fixed_offset) { x+=seed%checker_wdt; y+=((seed*214013)%checker_hgt); }
103  x = divD(x, checker_wdt); y = divD(y, checker_hgt);
104  return QuerySeededRandomField(seed, x,y, 100) < set_percentage;
105 }
int32_t QuerySeededRandomField(int32_t seed, int32_t x, int32_t y, int32_t scale)

Here is the call graph for this function:

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