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

Go to the source code of this file.

Macros

#define IntPar   IntPar(pParser, szSVal, iVal, ValType)
 
#define StrPar   StrPar(pParser, szSVal, iVal, ValType)
 
#define a   pOvrl->Alpha
 
#define b   pOvrl->Beta
 
#define s   pOvrl->Seed
 
#define z   C4MC_ZoomRes
 
#define z2   (C4MC_ZoomRes*C4MC_ZoomRes)
 
#define offsC4MCOvrl(x)   reinterpret_cast<C4MCOverlayOffsetType>(&C4MCOverlay::x)
 

Enumerations

enum  C4MCValueType
 

Functions

bool PreparePeek (C4MCOverlay **ppOvrl, int32_t &iX, int32_t &iY, C4MCOverlay **ppTopOvrl)
 
bool AlgoSolid (C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
 
bool AlgoRandom (C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
 
bool AlgoChecker (C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
 
bool AlgoBozo (C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
 
bool AlgoSin (C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
 
bool AlgoBoxes (C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
 
bool AlgoRndChecker (C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
 
bool AlgoLines (C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
 
bool AlgoBorder (C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
 
bool AlgoMandel (C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
 
bool AlgoGradient (C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
 
bool AlgoScript (C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
 
bool AlgoRndAll (C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
 
bool AlgoPolygon (C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
 

Variables

C4MCAlgorithm C4MCAlgoMap []
 

Macro Definition Documentation

#define IntPar   IntPar(pParser, szSVal, iVal, ValType)

Definition at line 291 of file C4MapCreatorS2.cpp.

#define offsC4MCOvrl (   x)    reinterpret_cast<C4MCOverlayOffsetType>(&C4MCOverlay::x)

Definition at line 1766 of file C4MapCreatorS2.cpp.

#define s   pOvrl->Seed

Definition at line 1535 of file C4MapCreatorS2.cpp.

Referenced by AlgoBoxes(), AlgoBozo(), AlgoLines(), AlgoRandom(), and AlgoRndAll().

#define StrPar   StrPar(pParser, szSVal, iVal, ValType)

Definition at line 292 of file C4MapCreatorS2.cpp.

#define z2   (C4MC_ZoomRes*C4MC_ZoomRes)

Definition at line 1537 of file C4MapCreatorS2.cpp.

Referenced by AlgoBozo().

Enumeration Type Documentation

Definition at line 30 of file C4MapCreatorS2.cpp.

31  {
32  C4MCV_None,
33  C4MCV_Integer,
34  C4MCV_Percent,
35  C4MCV_Pixels,
36  C4MCV_Material,
37  C4MCV_Texture,
38  C4MCV_Algorithm,
39  C4MCV_Boolean,
40  C4MCV_Zoom,
41  C4MCV_ScriptFunc
42  };

Function Documentation

bool AlgoBorder ( C4MCOverlay pOvrl,
int32_t  iX,
int32_t  iY 
)

Definition at line 1596 of file C4MapCreatorS2.cpp.

References a, b, C4MCOverlay::Hgt, C4MCOverlay::InBounds(), C4MCOverlay::PeekPix(), PreparePeek(), and C4MCOverlay::Wdt.

1597 {
1598  C4MCOverlay *pTopOvrl;
1599  // get params before, since pOvrl will be changed by PreparePeek
1600  int32_t la=a.Evaluate(pOvrl->Wdt); int32_t lb=b.Evaluate(pOvrl->Hgt);
1601  // prepare a pixel peek from owner
1602  if (!PreparePeek(&pOvrl, iX, iY, &pTopOvrl)) return false;
1603  // query a/b pixels in x/y-directions
1604  for (int32_t x=iX-la; x<=iX+la; x++) if (pTopOvrl->InBounds(x, iY)) if (!pOvrl->PeekPix(x, iY)) return true;
1605  for (int32_t y=iY-lb; y<=iY+lb; y++) if (pTopOvrl->InBounds(iX, y)) if (!pOvrl->PeekPix(iX, y)) return true;
1606  // nothing found
1607  return false;
1608 }
#define b
#define a
bool PreparePeek(C4MCOverlay **ppOvrl, int32_t &iX, int32_t &iY, C4MCOverlay **ppTopOvrl)
bool PeekPix(int32_t iX, int32_t iY)
bool InBounds(int32_t iX, int32_t iY)

Here is the call graph for this function:

bool AlgoBoxes ( C4MCOverlay pOvrl,
int32_t  iX,
int32_t  iY 
)

Definition at line 1572 of file C4MapCreatorS2.cpp.

References a, Abs(), b, s, C4MCOverlay::Wdt, and z.

1573 {
1574  // For percents instead of Pixels
1575  int32_t pxb = b.Evaluate(pOvrl->Wdt);
1576  int32_t pxa = a.Evaluate(pOvrl->Wdt);
1577  // return whether inside box
1578  return Abs(iX+(s%4738))%(pxb*z+1)<pxa*z+1 && Abs(iY+(s/4738))%(pxb*z+1)<pxa*z+1;
1579 }
#define z
#define b
#define a
#define s
T Abs(T val)
Definition: Standard.h:42

Here is the call graph for this function:

bool AlgoBozo ( C4MCOverlay pOvrl,
int32_t  iX,
int32_t  iY 
)

Definition at line 1557 of file C4MapCreatorS2.cpp.

References a, Abs(), C4MC_SizeRes, s, z, and z2.

1558 {
1559  // do some bozo stuff - keep it regular here, since it may be modified by turbulence
1560  int32_t iXC=(iX/10+s+(iY/80))%(z*2)-z;
1561  int32_t iYC=(iY/10+s+(iX/80))%(z*2)-z;
1562  int32_t id=Abs(iXC*iYC); // ((iSeed^iX^iY)%z)
1563  return id > z2*(a.Evaluate(C4MC_SizeRes)+10)/50;
1564 }
#define z
#define C4MC_SizeRes
#define z2
#define a
#define s
T Abs(T val)
Definition: Standard.h:42

Here is the call graph for this function:

bool AlgoChecker ( C4MCOverlay pOvrl,
int32_t  iX,
int32_t  iY 
)

Definition at line 1551 of file C4MapCreatorS2.cpp.

References z.

1552 {
1553  // checkers with size of 10
1554  return !(((iX/(z*10))%2)^((iY/(z*10))%2));
1555 }
#define z
bool AlgoGradient ( C4MCOverlay pOvrl,
int32_t  iX,
int32_t  iY 
)

Definition at line 1632 of file C4MapCreatorS2.cpp.

References C4MCOverlay::Wdt, and z.

1633 {
1634  return (std::abs((iX^(iY*3)) * 2531011L) % 214013L) % z > iX / pOvrl->Wdt;
1635 }
#define z
bool AlgoLines ( C4MCOverlay pOvrl,
int32_t  iX,
int32_t  iY 
)

Definition at line 1587 of file C4MapCreatorS2.cpp.

References a, Abs(), b, s, C4MCOverlay::Wdt, and z.

1588 {
1589  // For percents instead of Pixels
1590  int32_t pxb = b.Evaluate(pOvrl->Wdt);
1591  int32_t pxa = a.Evaluate(pOvrl->Wdt);
1592  // return whether inside line
1593  return Abs(iX+(s%4738))%(pxb*z+1)<pxa*z+1;
1594 }
#define z
#define b
#define a
#define s
T Abs(T val)
Definition: Standard.h:42

Here is the call graph for this function:

bool AlgoMandel ( C4MCOverlay pOvrl,
int32_t  iX,
int32_t  iY 
)

Definition at line 1610 of file C4MapCreatorS2.cpp.

References a, C4MC_SizeRes, C4MCOverlay::Hgt, C4MCOverlay::Wdt, z, C4MCOverlay::ZoomX, and C4MCOverlay::ZoomY.

1611 {
1612  // how many iterations?
1613  uint32_t iMandelIter = a.Evaluate(C4MC_SizeRes) != 0 ? a.Evaluate(C4MC_SizeRes) : 1000;
1614  if (iMandelIter < 10) iMandelIter = 10;
1615  // calc c & ci values
1616  double c = ((double) iX / z / pOvrl->Wdt - .5 * ((double) pOvrl->ZoomX / z)) * 4;
1617  double ci = ((double) iY / z / pOvrl->Hgt - .5 * ((double) pOvrl->ZoomY / z)) * 4;
1618  // create _z & _zi
1619  double _z = c, _zi = ci;
1620  double xz;
1621  uint32_t i;
1622  for (i=0; i<iMandelIter; i++)
1623  {
1624  xz = _z * _z - _zi * _zi;
1625  _zi = 2 * _z * _zi + ci;
1626  _z = xz + c;
1627  if (_z * _z + _zi * _zi > 4) break;
1628  }
1629  return !(i<iMandelIter);
1630 }
#define z
#define C4MC_SizeRes
#define a
bool AlgoPolygon ( C4MCOverlay pOvrl,
int32_t  iX,
int32_t  iY 
)

Definition at line 1649 of file C4MapCreatorS2.cpp.

References C4MCNode::Child0, MCN_Point, C4MCNode::Prev, C4MCNode::Type(), and X.

1650 {
1651  // Wo do not support empty polygons.
1652  if (!pOvrl -> ChildL) return false;
1653  int32_t uX = 0; // last point before current point
1654  int32_t uY = 0; // with uY != iY
1655  int32_t cX, cY; // current point
1656  int32_t lX = 0; // x of really last point before current point
1657  int32_t count = 0;
1658  bool ignore = false;
1659  int32_t zX; //Where edge intersects with line
1660  C4MCNode *pChild, *pStartChild;
1661  //get a point with uY!=iY, or anyone
1662  for (pChild = pOvrl -> ChildL; pChild->Prev; pChild = pChild->Prev)
1663  if (pChild->Type() == MCN_Point)
1664  {
1665  uX = ((C4MCPoint*) pChild) -> X * 100;
1666  lX = uX;
1667  uY = ((C4MCPoint*) pChild) -> Y * 100;
1668  if (iY != uY) break;
1669  }
1670  pStartChild = pChild -> Next;
1671  if (!pStartChild) pStartChild = pOvrl->Child0;
1672  if (!pStartChild) return false;
1673  for (pChild = pStartChild; ; pChild=pChild -> Next)
1674  {
1675  if (!pChild) pChild = pOvrl->Child0;
1676  if (pChild->Type() == MCN_Point)
1677  {
1678  cX = ((C4MCPoint*) pChild) -> X * 100;
1679  cY = ((C4MCPoint*) pChild) -> Y * 100;
1680  //If looking at line
1681  if (ignore)
1682  {
1683  //if C is on line
1684  if (cY == iY)
1685  {
1686  //if I is on edge
1687  if (((lX < iX) == (iX < cX)) || (cX == iX)) return true;
1688  }
1689  else
1690  {
1691  //if edge intersects line
1692  if ((uY < iY) == (iY < cY) && (lX >= iX)) count++;
1693  ignore = false;
1694  uX = cX;
1695  uY = cY;
1696  }
1697  }
1698  //if looking at ray
1699  else
1700  {
1701  //If point C lays on ray
1702  if (cY == iY)
1703  {
1704  //are I and C the same points?
1705  if (cX == iX) return true;
1706  //skip this point for now
1707  ignore = true;
1708  }
1709  else
1710  {
1711  //if edge intersects line
1712  if ((uY < iY) == (iY <= cY))
1713  {
1714  //and edge intersects ray, because both points are right of iX
1715  if (iX < std::min (uX, cX))
1716  {
1717  count++;
1718  }
1719  //or one is right of I
1720  else if (iX <= std::max (uX, cX))
1721  {
1722  //and edge intersects with ray
1723  if (iX < (zX = ((cX - uX) * (iY - uY) / (cY - uY)) + uX)) count++;
1724  //if I lays on CU
1725  if (zX == iX) return true;
1726  }
1727  }
1728  uX = cX;
1729  uY = cY;
1730  }
1731  }
1732  lX = cX;
1733  }
1734  if (pChild -> Next == pStartChild) break;
1735  if (!pChild -> Next) if (pStartChild == pOvrl->Child0) break;
1736  }
1737  //if edge has changed side of ray uneven times
1738  if ((count & 1) > 0) return true; else return false;
1739 }
virtual C4MCNodeType Type()
C4MCNode * Child0
#define X(sdl, oc)
C4MCNode * Prev

Here is the call graph for this function:

bool AlgoRandom ( C4MCOverlay pOvrl,
int32_t  iX,
int32_t  iY 
)

Definition at line 1545 of file C4MapCreatorS2.cpp.

References a, C4MC_SizeRes, and s.

Referenced by AlgoRndChecker().

1546 {
1547  // totally random
1548  return !((((s ^ (iX<<2) ^ (iY<<5))^((s>>16)+1+iX+(iY<<2)))/17)%(a.Evaluate(C4MC_SizeRes)+2));
1549 }
#define C4MC_SizeRes
#define a
#define s

Here is the caller graph for this function:

bool AlgoRndAll ( C4MCOverlay pOvrl,
int32_t  iX,
int32_t  iY 
)

Definition at line 1643 of file C4MapCreatorS2.cpp.

References a, C4MC_SizeRes, and s.

1644 {
1645  // return by seed and params; ignore pos
1646  return s%100<a.Evaluate(C4MC_SizeRes);
1647 }
#define C4MC_SizeRes
#define a
#define s
bool AlgoRndChecker ( C4MCOverlay pOvrl,
int32_t  iX,
int32_t  iY 
)

Definition at line 1581 of file C4MapCreatorS2.cpp.

References AlgoRandom(), and z.

1582 {
1583  // randomly set squares with size of 10
1584  return AlgoRandom(pOvrl, iX/(z*10), iY/(z*10));
1585 }
#define z
bool AlgoRandom(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)

Here is the call graph for this function:

bool AlgoScript ( C4MCOverlay pOvrl,
int32_t  iX,
int32_t  iY 
)

Definition at line 1637 of file C4MapCreatorS2.cpp.

References C4MCOverlay::Alpha, C4MCOverlay::Beta, C4MC_SizeRes, C4GameScriptHost::Call(), C4MCNode::int_bool::Evaluate(), FormatString(), GameScript, StdStrBuf::getData(), and C4MCNode::Name.

1638 {
1639  C4AulParSet Pars(iX, iY, pOvrl->Alpha.Evaluate(C4MC_SizeRes), pOvrl->Beta.Evaluate(C4MC_SizeRes));
1640  return ::GameScript.Call(FormatString("ScriptAlgo%s", pOvrl->Name).getData(), &Pars).getBool();
1641 }
const char * getData() const
Definition: StdBuf.h:442
C4GameScriptHost GameScript
C4Value Call(const char *szFunction, C4AulParSet *pPars=nullptr, bool fPassError=false)
#define C4MC_SizeRes
char Name[C4MaxName]
int_bool Beta
int_bool Alpha
int32_t Evaluate(int32_t relative_to)
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

bool AlgoSin ( C4MCOverlay pOvrl,
int32_t  iX,
int32_t  iY 
)

Definition at line 1566 of file C4MapCreatorS2.cpp.

References fixtoi(), itofix(), Sin(), and z.

1567 {
1568  // a sine curve where bottom is filled
1569  return iY > fixtoi((Sin(itofix(iX/z*10))+1)*z*10);
1570 }
#define z
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
C4Real Sin(const C4Real &fAngle)
Definition: C4Real.h:265
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259

Here is the call graph for this function:

bool AlgoSolid ( C4MCOverlay pOvrl,
int32_t  iX,
int32_t  iY 
)

Definition at line 1539 of file C4MapCreatorS2.cpp.

1540 {
1541  // solid always solid :)
1542  return true;
1543 }
bool PreparePeek ( C4MCOverlay **  ppOvrl,
int32_t &  iX,
int32_t &  iY,
C4MCOverlay **  ppTopOvrl 
)

Definition at line 1515 of file C4MapCreatorS2.cpp.

References C4MCOverlay::FirstOfChain(), and C4MCNode::OwnerOverlay().

Referenced by AlgoBorder().

1516 {
1517  // zoom out
1518  iX/=(*ppOvrl)->ZoomX; iY/=(*ppOvrl)->ZoomY;
1519  // get owning overlay
1520  C4MCOverlay *pOvrl2=(*ppOvrl)->OwnerOverlay();
1521  if (!pOvrl2) return false;
1522  // get uppermost overlay
1523  C4MCOverlay *pNextOvrl;
1524  for (*ppTopOvrl=pOvrl2; (pNextOvrl=(*ppTopOvrl)->OwnerOverlay()); *ppTopOvrl=pNextOvrl) {}
1525  // get first of operator-chain
1526  pOvrl2=pOvrl2->FirstOfChain();
1527  // set new overlay
1528  *ppOvrl=pOvrl2;
1529  // success
1530  return true;
1531 }
C4MCOverlay * OwnerOverlay()
C4MCOverlay * FirstOfChain()

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

C4MCAlgorithm C4MCAlgoMap[]
Initial value:
=
{
{ "solid", &AlgoSolid },
{ "random", &AlgoRandom },
{ "checker", &AlgoChecker },
{ "bozo", &AlgoBozo },
{ "sin", &AlgoSin },
{ "boxes", &AlgoBoxes },
{ "rndchecker", &AlgoRndChecker },
{ "lines", &AlgoLines },
{ "border", &AlgoBorder },
{ "mandel", &AlgoMandel },
{ "gradient", &AlgoGradient },
{ "script", &AlgoScript },
{ "rndall", &AlgoRndAll },
{ "poly", &AlgoPolygon },
{ "", nullptr }
}
bool AlgoSolid(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoRndChecker(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoRandom(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoPolygon(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoScript(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoBozo(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoBorder(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoChecker(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoGradient(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoSin(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoBoxes(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoRndAll(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoMandel(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoLines(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)

Definition at line 1747 of file C4MapCreatorS2.cpp.

Referenced by C4MCOverlay::GetAlgo().