OpenClonk
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)
 

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

◆ a

#define a   pOvrl->Alpha

Definition at line 1533 of file C4MapCreatorS2.cpp.

◆ b

#define b   pOvrl->Beta

Definition at line 1534 of file C4MapCreatorS2.cpp.

◆ IntPar

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

Definition at line 291 of file C4MapCreatorS2.cpp.

◆ offsC4MCOvrl

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

Definition at line 1766 of file C4MapCreatorS2.cpp.

◆ s

#define s   pOvrl->Seed

Definition at line 1535 of file C4MapCreatorS2.cpp.

◆ StrPar

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

Definition at line 292 of file C4MapCreatorS2.cpp.

◆ z

#define z   C4MC_ZoomRes

Definition at line 1536 of file C4MapCreatorS2.cpp.

◆ z2

#define z2   (C4MC_ZoomRes*C4MC_ZoomRes)

Definition at line 1537 of file C4MapCreatorS2.cpp.

Function Documentation

◆ AlgoBorder()

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

Definition at line 1596 of file C4MapCreatorS2.cpp.

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 }
bool PreparePeek(C4MCOverlay **ppOvrl, int32_t &iX, int32_t &iY, C4MCOverlay **ppTopOvrl)
#define a
#define b
bool PeekPix(int32_t iX, int32_t iY)
bool InBounds(int32_t iX, int32_t iY)

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

Here is the call graph for this function:

◆ AlgoBoxes()

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

Definition at line 1572 of file C4MapCreatorS2.cpp.

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 s
#define z
T Abs(T val)
Definition: Standard.h:42

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

Here is the call graph for this function:

◆ AlgoBozo()

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

Definition at line 1557 of file C4MapCreatorS2.cpp.

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 z2
#define C4MC_SizeRes

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

Here is the call graph for this function:

◆ AlgoChecker()

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

Definition at line 1551 of file C4MapCreatorS2.cpp.

1552 {
1553  // checkers with size of 10
1554  return !(((iX/(z*10))%2)^((iY/(z*10))%2));
1555 }

References z.

◆ AlgoGradient()

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

Definition at line 1632 of file C4MapCreatorS2.cpp.

1633 {
1634  return (std::abs((iX^(iY*3)) * 2531011L) % 214013L) % z > iX / pOvrl->Wdt;
1635 }

References C4MCOverlay::Wdt, and z.

◆ AlgoLines()

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

Definition at line 1587 of file C4MapCreatorS2.cpp.

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 }

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

Here is the call graph for this function:

◆ AlgoMandel()

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

Definition at line 1610 of file C4MapCreatorS2.cpp.

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 }

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

◆ AlgoPolygon()

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

Definition at line 1649 of file C4MapCreatorS2.cpp.

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 }
#define X(sdl, oc)
@ MCN_Point
C4MCNode * Child0
virtual C4MCNodeType Type()
C4MCNode * Prev

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

Here is the call graph for this function:

◆ AlgoRandom()

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

Definition at line 1545 of file C4MapCreatorS2.cpp.

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

References a, C4MC_SizeRes, and s.

Referenced by AlgoRndChecker().

Here is the caller graph for this function:

◆ AlgoRndAll()

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

Definition at line 1643 of file C4MapCreatorS2.cpp.

1644 {
1645  // return by seed and params; ignore pos
1646  return s%100<a.Evaluate(C4MC_SizeRes);
1647 }

References a, C4MC_SizeRes, and s.

◆ AlgoRndChecker()

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

Definition at line 1581 of file C4MapCreatorS2.cpp.

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

References AlgoRandom(), and z.

Here is the call graph for this function:

◆ AlgoScript()

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

Definition at line 1637 of file C4MapCreatorS2.cpp.

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 }
C4GameScriptHost GameScript
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
C4Value Call(const char *szFunction, C4AulParSet *pPars=nullptr, bool fPassError=false)
int32_t Evaluate(int32_t relative_to)
char Name[C4MaxName]
int_bool Beta
int_bool Alpha
bool getBool() const
Definition: C4Value.h:113
const char * getData() const
Definition: StdBuf.h:442

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

Here is the call graph for this function:

◆ AlgoSin()

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

Definition at line 1566 of file C4MapCreatorS2.cpp.

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

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

Here is the call graph for this function:

◆ AlgoSolid()

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 }

◆ PreparePeek()

bool PreparePeek ( C4MCOverlay **  ppOvrl,
int32_t &  iX,
int32_t &  iY,
C4MCOverlay **  ppTopOvrl 
)

Definition at line 1515 of file C4MapCreatorS2.cpp.

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()

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

Referenced by AlgoBorder().

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

Variable Documentation

◆ C4MCAlgoMap

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 AlgoBoxes(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoChecker(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoRndChecker(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoSin(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoLines(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoGradient(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoPolygon(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoBozo(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 AlgoScript(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoSolid(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)
bool AlgoBorder(C4MCOverlay *pOvrl, int32_t iX, int32_t iY)

Definition at line 1747 of file C4MapCreatorS2.cpp.

Referenced by C4MCOverlay::GetAlgo().