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 290 of file C4MapCreatorS2.cpp.

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

Definition at line 1765 of file C4MapCreatorS2.cpp.

#define s   pOvrl->Seed

Definition at line 1534 of file C4MapCreatorS2.cpp.

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

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

Definition at line 291 of file C4MapCreatorS2.cpp.

#define z2   (C4MC_ZoomRes*C4MC_ZoomRes)

Definition at line 1536 of file C4MapCreatorS2.cpp.

Referenced by AlgoBozo().

Enumeration Type Documentation

Definition at line 29 of file C4MapCreatorS2.cpp.

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

Function Documentation

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

Definition at line 1595 of file C4MapCreatorS2.cpp.

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

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

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

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

Here is the call graph for this function:

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

Definition at line 1556 of file C4MapCreatorS2.cpp.

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

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

Here is the call graph for this function:

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

Definition at line 1550 of file C4MapCreatorS2.cpp.

References z.

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

Definition at line 1631 of file C4MapCreatorS2.cpp.

References C4MCOverlay::Wdt, and z.

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

Definition at line 1586 of file C4MapCreatorS2.cpp.

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

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

Here is the call graph for this function:

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

Definition at line 1609 of file C4MapCreatorS2.cpp.

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

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

Definition at line 1648 of file C4MapCreatorS2.cpp.

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

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

References a, C4MC_SizeRes, and s.

Referenced by AlgoRndChecker().

1545 {
1546  // totally random
1547  return !((((s ^ (iX<<2) ^ (iY<<5))^((s>>16)+1+iX+(iY<<2)))/17)%(a.Evaluate(C4MC_SizeRes)+2));
1548 }
#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 1642 of file C4MapCreatorS2.cpp.

References a, C4MC_SizeRes, and s.

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

Definition at line 1580 of file C4MapCreatorS2.cpp.

References AlgoRandom(), and z.

1581 {
1582  // randomly set squares with size of 10
1583  return AlgoRandom(pOvrl, iX/(z*10), iY/(z*10));
1584 }
#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 1636 of file C4MapCreatorS2.cpp.

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

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

Here is the call graph for this function:

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

Definition at line 1565 of file C4MapCreatorS2.cpp.

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

1566 {
1567  // a sine curve where bottom is filled
1568  return iY > fixtoi((Sin(itofix(iX/z*10))+1)*z*10);
1569 }
#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 1538 of file C4MapCreatorS2.cpp.

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

Definition at line 1514 of file C4MapCreatorS2.cpp.

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

Referenced by AlgoBorder().

1515 {
1516  // zoom out
1517  iX/=(*ppOvrl)->ZoomX; iY/=(*ppOvrl)->ZoomY;
1518  // get owning overlay
1519  C4MCOverlay *pOvrl2=(*ppOvrl)->OwnerOverlay();
1520  if (!pOvrl2) return false;
1521  // get uppermost overlay
1522  C4MCOverlay *pNextOvrl;
1523  for (*ppTopOvrl=pOvrl2; (pNextOvrl=(*ppTopOvrl)->OwnerOverlay()); *ppTopOvrl=pNextOvrl) {}
1524  // get first of operator-chain
1525  pOvrl2=pOvrl2->FirstOfChain();
1526  // set new overlay
1527  *ppOvrl=pOvrl2;
1528  // success
1529  return true;
1530 }
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 },
{ "", 0 }
}
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 1746 of file C4MapCreatorS2.cpp.

Referenced by C4MCOverlay::GetAlgo().