OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Landscape.h File Reference
Include dependency graph for C4Landscape.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  C4Landscape
 

Enumerations

enum  LandscapeMode { LandscapeMode::Undefined = 0, LandscapeMode::Dynamic = 1, LandscapeMode::Static = 2, LandscapeMode::Exact = 3 }
 

Functions

bool AboveSolid (int32_t &rx, int32_t &ry)
 
bool AboveSemiSolid (int32_t &rx, int32_t &ry)
 
bool SemiAboveSolid (int32_t &rx, int32_t &ry)
 
bool FindSolidGround (int32_t &rx, int32_t &ry, int32_t width)
 
bool FindLiquid (int32_t &rx, int32_t &ry, int32_t width, int32_t height)
 
bool FindTunnel (int32_t &rx, int32_t &ry, int32_t width, int32_t height)
 
bool FindSurfaceLiquid (int32_t &rx, int32_t &ry, int32_t width, int32_t height)
 
bool FindLevelGround (int32_t &rx, int32_t &ry, int32_t width, int32_t hrange)
 
bool FindConSiteSpot (int32_t &rx, int32_t &ry, int32_t wdt, int32_t hgt, int32_t hrange=-1)
 
bool FindThrowingPosition (int32_t iTx, int32_t iTy, C4Real fXDir, C4Real fYDir, int32_t iHeight, int32_t &rX, int32_t &rY)
 
bool PathFree (int32_t x1, int32_t y1, int32_t x2, int32_t y2)
 
bool PathFree (int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t *ix, int32_t *iy)
 
bool PathFreeIgnoreVehicle (int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t *ix=nullptr, int32_t *iy=nullptr)
 
bool FindClosestFree (int32_t &rX, int32_t &rY, int32_t iAngle1, int32_t iAngle2, int32_t iExcludeAngle1, int32_t iExcludeAngle2)
 
bool ConstructionCheck (C4PropList *, int32_t iX, int32_t iY, C4Object *pByObj=nullptr)
 
int32_t PixCol2Mat (BYTE pixc)
 
bool DensitySolid (int32_t dens)
 
bool DensitySemiSolid (int32_t dens)
 
bool DensityLiquid (int32_t dens)
 
int32_t PixCol2Tex (BYTE pixc)
 
int32_t GBackMat (int32_t x, int32_t y)
 
int32_t GBackDensity (int32_t x, int32_t y)
 
bool GBackSolid (int32_t x, int32_t y)
 
bool GBackSemiSolid (int32_t x, int32_t y)
 
bool GBackLiquid (int32_t x, int32_t y)
 

Variables

const int32_t C4MaxMaterial = 125
 
const int32_t C4LS_MaxRelights = 50
 
C4Landscape Landscape
 

Enumeration Type Documentation

enum LandscapeMode
strong
Enumerator
Undefined 
Dynamic 
Static 
Exact 

Definition at line 29 of file C4Landscape.h.

Function Documentation

bool AboveSemiSolid ( int32_t &  rx,
int32_t &  ry 
)

Definition at line 2462 of file C4Landscape.cpp.

References GBackSemiSolid(), C4Landscape::GetHeight(), and Landscape.

Referenced by FindConSiteSpot(), FindLevelGround(), FindSolidGround(), FindSurfaceLiquid(), and C4Game::PlaceVegetation().

2463 {
2464  int32_t cy1 = ry, cy2 = ry;
2465  bool UseUpwardsNextFree = false, UseDownwardsNextSolid = false;
2466 
2467  while ((cy1 >= 0) || (cy2 < ::Landscape.GetHeight()))
2468  {
2469  // Check upwards
2470  if (cy1 >= 0)
2471  {
2472  if (GBackSemiSolid(rx, cy1)) UseUpwardsNextFree = true;
2473  else if (UseUpwardsNextFree) { ry = cy1; return true; }
2474  }
2475  // Check downwards
2476  if (cy2 < ::Landscape.GetHeight())
2477  {
2478  if (!GBackSemiSolid(rx, cy2)) UseDownwardsNextSolid = true;
2479  else if (UseDownwardsNextSolid) { ry = cy2; return true; }
2480  }
2481  // Advance
2482  cy1--; cy2++;
2483  }
2484 
2485  return false;
2486 }
C4Landscape Landscape
int32_t GetHeight() const
bool GBackSemiSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:236

Here is the call graph for this function:

Here is the caller graph for this function:

bool AboveSolid ( int32_t &  rx,
int32_t &  ry 
)

Definition at line 2489 of file C4Landscape.cpp.

References GBackSemiSolid(), GBackSolid(), C4Landscape::GetHeight(), and Landscape.

Referenced by FindSolidGround().

2490 {
2491  int32_t cy1 = ry, cy2 = ry;
2492 
2493  while ((cy1 >= 0) || (cy2 < ::Landscape.GetHeight()))
2494  {
2495  // Check upwards
2496  if (cy1 >= 0)
2497  if (!GBackSemiSolid(rx, cy1))
2498  if (GBackSolid(rx, cy1 + 1))
2499  {
2500  ry = cy1; return true;
2501  }
2502  // Check downwards
2503  if (cy2 + 1 < ::Landscape.GetHeight())
2504  if (!GBackSemiSolid(rx, cy2))
2505  if (GBackSolid(rx, cy2 + 1))
2506  {
2507  ry = cy2; return true;
2508  }
2509  // Advance
2510  cy1--; cy2++;
2511  }
2512 
2513  return false;
2514 }
C4Landscape Landscape
int32_t GetHeight() const
bool GBackSemiSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:236
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:231

Here is the call graph for this function:

Here is the caller graph for this function:

bool ConstructionCheck ( C4PropList ,
int32_t  iX,
int32_t  iY,
C4Object pByObj = nullptr 
)

Definition at line 3051 of file C4Landscape.cpp.

References C4Landscape::AreaSolidCount(), C4Def::ConSizeOff, C4Def::Constructable, C4Game::FindConstuctionSiteBlock(), FormatString(), Game, GameMsgObjectError(), C4PropList::GetDef(), C4PropList::GetName(), C4PropListStatic::GetName(), C4Rect::Hgt, Landscape, LoadResStr(), C4Def::Shape, and C4Rect::Wdt.

3052 {
3053  C4Def *ndef;
3054  // Check def
3055  if (!(ndef = PropList->GetDef()))
3056  {
3057  if (pByObj) GameMsgObjectError(FormatString(LoadResStr("IDS_OBJ_UNDEF"), PropList->GetName()).getData(), pByObj);
3058  return false;
3059  }
3060  // Constructable?
3061  if (!ndef->Constructable)
3062  {
3063  if (pByObj) GameMsgObjectError(FormatString(LoadResStr("IDS_OBJ_NOCON"), ndef->GetName()).getData(), pByObj);
3064  return false;
3065  }
3066  // Check area
3067  int32_t rtx, rty, wdt, hgt;
3068  wdt = ndef->Shape.Wdt; hgt = ndef->Shape.Hgt - ndef->ConSizeOff;
3069  rtx = iX - wdt / 2; rty = iY - hgt;
3070  if (::Landscape.AreaSolidCount(rtx, rty, wdt, hgt) > (wdt*hgt / 20))
3071  {
3072  if (pByObj) GameMsgObjectError(LoadResStr("IDS_OBJ_NOROOM"), pByObj);
3073  return false;
3074  }
3075  if (::Landscape.AreaSolidCount(rtx, rty + hgt, wdt, 5) < (wdt * 2))
3076  {
3077  if (pByObj) GameMsgObjectError(LoadResStr("IDS_OBJ_NOLEVEL"), pByObj);
3078  return false;
3079  }
3080  // Check other structures
3081  C4Object *other;
3082  if ((other = Game.FindConstuctionSiteBlock(rtx, rty, wdt, hgt)))
3083  {
3084  if (pByObj) GameMsgObjectError(FormatString(LoadResStr("IDS_OBJ_NOOTHER"), other->GetName()).getData(), pByObj);
3085  return false;
3086  }
3087  return true;
3088 }
C4Game Game
Definition: C4Globals.cpp:52
void GameMsgObjectError(const char *szText, C4Object *pTarget, bool Red)
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
const char * GetName() const override
Definition: C4PropList.cpp:267
C4Def const * GetDef() const override
Definition: C4Def.h:214
int32_t Wdt
Definition: C4Rect.h:30
C4Shape Shape
Definition: C4Def.h:104
C4Landscape Landscape
virtual const char * GetName() const
Definition: C4PropList.cpp:649
int32_t Constructable
Definition: C4Def.h:118
Definition: C4Def.h:98
C4Object * FindConstuctionSiteBlock(int32_t tx, int32_t ty, int32_t wdt, int32_t hgt)
Definition: C4Game.cpp:1142
int32_t AreaSolidCount(int32_t x, int32_t y, int32_t wdt, int32_t hgt) const
int32_t Hgt
Definition: C4Rect.h:30
int32_t ConSizeOff
Definition: C4Def.h:143
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

bool DensityLiquid ( int32_t  dens)
inline

Definition at line 208 of file C4Landscape.h.

References C4M_Liquid, and C4M_Solid.

Referenced by C4MaterialMap::CrossMapMaterials(), GBackLiquid(), C4MaterialCore::Load(), and SimFlightHitsLiquid().

209 {
210  return ((dens>=C4M_Liquid) && (dens<C4M_Solid));
211 }
const int32_t C4M_Solid
Definition: C4Constants.h:172
const int32_t C4M_Liquid
Definition: C4Constants.h:174

Here is the caller graph for this function:

bool DensitySemiSolid ( int32_t  dens)
inline

Definition at line 203 of file C4Landscape.h.

References C4M_SemiSolid.

Referenced by C4MaterialMap::CrossMapMaterials(), C4TextureMap::DefaultBkgMatTex(), GBackSemiSolid(), and C4ToolsDlg::SetTexture().

204 {
205  return (dens>=C4M_SemiSolid);
206 }
const int32_t C4M_SemiSolid
Definition: C4Constants.h:173

Here is the caller graph for this function:

bool DensitySolid ( int32_t  dens)
inline

Definition at line 198 of file C4Landscape.h.

References C4M_Solid.

Referenced by C4Landscape::CheckInstability(), C4MaterialMap::CrossMapMaterials(), C4Landscape::P::DoScan(), GBackSolid(), LandscapeFree(), C4MaterialCore::Load(), and PathFreeIgnoreVehiclePix().

199 {
200  return (dens>=C4M_Solid);
201 }
const int32_t C4M_Solid
Definition: C4Constants.h:172

Here is the caller graph for this function:

bool FindClosestFree ( int32_t &  rX,
int32_t &  rY,
int32_t  iAngle1,
int32_t  iAngle2,
int32_t  iExcludeAngle1,
int32_t  iExcludeAngle2 
)

Definition at line 3031 of file C4Landscape.cpp.

References Cos(), fixtoi(), GBackSemiSolid(), C4Landscape::GetHeight(), C4Landscape::GetWidth(), Inside(), itofix(), Landscape, and Sin().

Referenced by C4Command::Get().

3033 {
3034  int32_t iX, iY;
3035  for (int32_t iR = Closest_Step; iR < Closest_MaxRange; iR += Closest_Step)
3036  for (int32_t iAngle = iAngle1; iAngle < iAngle2; iAngle += Closest_Step)
3037  if (!Inside(iAngle, iExcludeAngle1, iExcludeAngle2))
3038  {
3039  iX = rX + fixtoi(Sin(itofix(iAngle))*iR);
3040  iY = rY - fixtoi(Cos(itofix(iAngle))*iR);
3041  if (Inside<int32_t>(iX, 0, ::Landscape.GetWidth() - 1))
3042  if (Inside<int32_t>(iY, 0, ::Landscape.GetHeight() - 1))
3043  if (!GBackSemiSolid(iX, iY))
3044  {
3045  rX = iX; rY = iY; return true;
3046  }
3047  }
3048  return false;
3049 }
C4Landscape Landscape
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
int32_t GetHeight() const
bool GBackSemiSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:236
C4Real Sin(const C4Real &fAngle)
Definition: C4Real.h:265
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43
C4Real Cos(const C4Real &fAngle)
Definition: C4Real.h:266
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

bool FindConSiteSpot ( int32_t &  rx,
int32_t &  ry,
int32_t  wdt,
int32_t  hgt,
int32_t  hrange = -1 
)

Definition at line 2788 of file C4Landscape.cpp.

References AboveSemiSolid(), Abs(), C4Game::FindConstuctionSiteBlock(), Game, GBackSolid(), C4Landscape::GetWidth(), and Landscape.

Referenced by C4Player::PlaceReadyBase(), and C4Player::ScenarioInit().

2789 {
2790  bool fFound = false;
2791 
2792  // No hrange limit, use standard smooth surface limit
2793  if (hrange == -1) hrange = std::max(wdt / 4, 5);
2794 
2795  int32_t cx1, cx2, cy1, cy2, rh1, rh2, rl1, rl2;
2796 
2797  // Left offset starting position
2798  cx1 = std::min(rx + wdt / 2, ::Landscape.GetWidth() - 1); cy1 = ry;
2799  // No good: use centered starting position
2800  if (!AboveSemiSolid(cx1, cy1)) { cx1 = std::min<int32_t>(rx, ::Landscape.GetWidth() - 1); cy1 = ry; }
2801  // Right offset starting position
2802  cx2 = std::max(rx - wdt / 2, 0); cy2 = ry;
2803  // No good: use centered starting position
2804  if (!AboveSemiSolid(cx2, cy2)) { cx2 = std::min<int32_t>(rx, ::Landscape.GetWidth() - 1); cy2 = ry; }
2805 
2806  rh1 = cy1; rh2 = cy2; rl1 = rl2 = 0;
2807 
2808  for (cx1--, cx2++; (cx1 > 0) || (cx2 < ::Landscape.GetWidth()); cx1--, cx2++)
2809  {
2810  // Left search
2811  if (cx1 > 0) // Still going
2812  {
2813  if (!AboveSemiSolid(cx1, cy1))
2814  cx1 = -1; // Abort left
2815  else
2816  {
2817  if (GBackSolid(cx1, cy1 + 1) && (Abs(cy1 - rh1) < hrange))
2818  rl1++; // Run okay
2819  else
2820  {
2821  rl1 = 0; rh1 = cy1;
2822  } // No run
2823  }
2824  }
2825 
2826  // Right search
2827  if (cx2 < ::Landscape.GetWidth()) // Still going
2828  {
2829  if (!AboveSemiSolid(cx2, cy2))
2830  cx2 = ::Landscape.GetWidth(); // Abort right
2831  else
2832  {
2833  if (GBackSolid(cx2, cy2 + 1) && (Abs(cy2 - rh2) < hrange))
2834  rl2++; // Run okay
2835  else
2836  {
2837  rl2 = 0; rh2 = cy2;
2838  } // No run
2839  }
2840  }
2841 
2842  // Check runs & object overlap
2843  if (rl1 >= wdt) if (cx1 > 0)
2844  if (!Game.FindConstuctionSiteBlock(cx1, cy1 - hgt - 10, wdt, hgt + 40))
2845  {
2846  rx = cx1 + wdt / 2; ry = cy1; fFound = true; break;
2847  }
2848  if (rl2 >= wdt) if (cx2 < ::Landscape.GetWidth())
2849  if (!Game.FindConstuctionSiteBlock(cx2 - wdt, cy2 - hgt - 10, wdt, hgt + 40))
2850  {
2851  rx = cx2 - wdt / 2; ry = cy2; fFound = true; break;
2852  }
2853  }
2854 
2855  if (fFound) AboveSemiSolid(rx, ry);
2856 
2857  return fFound;
2858 }
C4Game Game
Definition: C4Globals.cpp:52
C4Landscape Landscape
C4Object * FindConstuctionSiteBlock(int32_t tx, int32_t ty, int32_t wdt, int32_t hgt)
Definition: C4Game.cpp:1142
T Abs(T val)
Definition: Standard.h:42
bool AboveSemiSolid(int32_t &rx, int32_t &ry)
int32_t GetWidth() const
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:231

Here is the call graph for this function:

Here is the caller graph for this function:

bool FindLevelGround ( int32_t &  rx,
int32_t &  ry,
int32_t  width,
int32_t  hrange 
)

Definition at line 2734 of file C4Landscape.cpp.

References AboveSemiSolid(), Abs(), GBackSolid(), C4Landscape::GetWidth(), and Landscape.

Referenced by C4Player::PlaceReadyVehic().

2735 {
2736  bool fFound = false;
2737 
2738  int32_t cx1, cx2, cy1, cy2, rh1, rh2, rl1, rl2;
2739 
2740  cx1 = cx2 = rx; cy1 = cy2 = ry;
2741  rh1 = cy1; rh2 = cy2;
2742  rl1 = rl2 = 0;
2743 
2744  for (cx1--, cx2++; (cx1 > 0) || (cx2 < ::Landscape.GetWidth()); cx1--, cx2++)
2745  {
2746  // Left search
2747  if (cx1 > 0) // Still going
2748  {
2749  if (!AboveSemiSolid(cx1, cy1)) cx1 = -1; // Abort left
2750  else
2751  {
2752  if (GBackSolid(cx1, cy1 + 1) && (Abs(cy1 - rh1) < hrange))
2753  rl1++; // Run okay
2754  else
2755  {
2756  rl1 = 0; rh1 = cy1;
2757  } // No run
2758  }
2759  }
2760 
2761  // Right search
2762  if (cx2 < ::Landscape.GetWidth()) // Still going
2763  {
2764  if (!AboveSemiSolid(cx2, cy2)) cx2 = ::Landscape.GetWidth(); // Abort right
2765  else
2766  {
2767  if (GBackSolid(cx2, cy2 + 1) && (Abs(cy2 - rh2) < hrange))
2768  rl2++; // Run okay
2769  else
2770  {
2771  rl2 = 0; rh2 = cy2;
2772  } // No run
2773  }
2774  }
2775 
2776  // Check runs
2777  if (rl1 >= width) { rx = cx1 + rl1 / 2; ry = cy1; fFound = true; break; }
2778  if (rl2 >= width) { rx = cx2 - rl2 / 2; ry = cy2; fFound = true; break; }
2779  }
2780 
2781  if (fFound) AboveSemiSolid(rx, ry);
2782 
2783  return fFound;
2784 }
C4Landscape Landscape
T Abs(T val)
Definition: Standard.h:42
bool AboveSemiSolid(int32_t &rx, int32_t &ry)
int32_t GetWidth() const
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:231

Here is the call graph for this function:

Here is the caller graph for this function:

bool FindLiquid ( int32_t &  rx,
int32_t &  ry,
int32_t  width,
int32_t  height 
)

Definition at line 2678 of file C4Landscape.cpp.

References FindLiquidHeight(), C4Landscape::GetWidth(), and Landscape.

Referenced by C4Game::PlaceAnimal(), and C4Game::PlaceVegetation().

2679 {
2680  int32_t cx1, cx2, cy1, cy2, rl1 = 0, rl2 = 0;
2681 
2682  for (cx1 = cx2 = rx, cy1 = cy2 = ry; (cx1 > 0) || (cx2 < ::Landscape.GetWidth()); cx1--, cx2++)
2683  {
2684  // Left search
2685  if (cx1 > 0)
2686  {
2687  if (FindLiquidHeight(cx1, cy1, height)) rl1++;
2688  else rl1 = 0;
2689  }
2690  // Right search
2691  if (cx2 < ::Landscape.GetWidth())
2692  {
2693  if (FindLiquidHeight(cx2, cy2, height)) rl2++;
2694  else rl2 = 0;
2695  }
2696  // Check runs
2697  if (rl1 >= width) { rx = cx1 + rl1 / 2; ry = cy1; return true; }
2698  if (rl2 >= width) { rx = cx2 - rl2 / 2; ry = cy2; return true; }
2699  }
2700 
2701  return false;
2702 }
bool FindLiquidHeight(int32_t cx, int32_t &ry, int32_t hgt)
C4Landscape Landscape
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

bool FindSolidGround ( int32_t &  rx,
int32_t &  ry,
int32_t  width 
)

Definition at line 2608 of file C4Landscape.cpp.

References AboveSemiSolid(), AboveSolid(), C4Landscape::GetWidth(), and Landscape.

Referenced by C4Game::PlaceAnimal(), C4Player::PlaceReadyCrew(), C4Player::PlaceReadyMaterial(), and C4Player::ScenarioInit().

2609 {
2610  bool fFound = false;
2611 
2612  int32_t cx1, cx2, cy1, cy2, rl1 = 0, rl2 = 0;
2613 
2614  for (cx1 = cx2 = rx, cy1 = cy2 = ry; (cx1 > 0) || (cx2 < ::Landscape.GetWidth()); cx1--, cx2++)
2615  {
2616  // Left search
2617  if (cx1 >= 0) // Still going
2618  {
2619  if (AboveSolid(cx1, cy1)) rl1++; // Run okay
2620  else rl1 = 0; // No run
2621  }
2622  // Right search
2623  if (cx2 < ::Landscape.GetWidth()) // Still going
2624  {
2625  if (AboveSolid(cx2, cy2)) rl2++; // Run okay
2626  else rl2 = 0; // No run
2627  }
2628  // Check runs
2629  if (rl1 >= width) { rx = cx1 + rl1 / 2; ry = cy1; fFound = true; break; }
2630  if (rl2 >= width) { rx = cx2 - rl2 / 2; ry = cy2; fFound = true; break; }
2631  }
2632 
2633  if (fFound) AboveSemiSolid(rx, ry);
2634 
2635  return fFound;
2636 }
C4Landscape Landscape
bool AboveSolid(int32_t &rx, int32_t &ry)
bool AboveSemiSolid(int32_t &rx, int32_t &ry)
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

bool FindSurfaceLiquid ( int32_t &  rx,
int32_t &  ry,
int32_t  width,
int32_t  height 
)

Definition at line 2638 of file C4Landscape.cpp.

References AboveSemiSolid(), GBackLiquid(), C4Landscape::GetWidth(), and Landscape.

Referenced by C4Game::PlaceAnimal(), and C4Game::PlaceVegetation().

2639 {
2640  bool fFound = false;
2641 
2642  int32_t cx1, cx2, cy1, cy2, rl1 = 0, rl2 = 0, cnt;
2643  bool lokay;
2644  for (cx1 = cx2 = rx, cy1 = cy2 = ry; (cx1 > 0) || (cx2 < ::Landscape.GetWidth()); cx1--, cx2++)
2645  {
2646  // Left search
2647  if (cx1 > 0) // Still going
2648  {
2649  if (!AboveSemiSolid(cx1, cy1)) cx1 = -1; // Abort left
2650  else
2651  {
2652  for (lokay = true, cnt = 0; cnt < height; cnt++) if (!GBackLiquid(cx1, cy1 + 1 + cnt)) lokay = false;
2653  if (lokay) rl1++; // Run okay
2654  else rl1 = 0; // No run
2655  }
2656  }
2657  // Right search
2658  if (cx2 < ::Landscape.GetWidth()) // Still going
2659  {
2660  if (!AboveSemiSolid(cx2, cy2)) cx2 = ::Landscape.GetWidth(); // Abort right
2661  else
2662  {
2663  for (lokay = true, cnt = 0; cnt < height; cnt++) if (!GBackLiquid(cx2, cy2 + 1 + cnt)) lokay = false;
2664  if (lokay) rl2++; // Run okay
2665  else rl2 = 0; // No run
2666  }
2667  }
2668  // Check runs
2669  if (rl1 >= width) { rx = cx1 + rl1 / 2; ry = cy1; fFound = true; break; }
2670  if (rl2 >= width) { rx = cx2 - rl2 / 2; ry = cy2; fFound = true; break; }
2671  }
2672 
2673  if (fFound) AboveSemiSolid(rx, ry);
2674 
2675  return fFound;
2676 }
C4Landscape Landscape
bool AboveSemiSolid(int32_t &rx, int32_t &ry)
bool GBackLiquid(int32_t x, int32_t y)
Definition: C4Landscape.h:241
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

bool FindThrowingPosition ( int32_t  iTx,
int32_t  iTy,
C4Real  fXDir,
C4Real  fYDir,
int32_t  iHeight,
int32_t &  rX,
int32_t &  rY 
)

Definition at line 2996 of file C4Landscape.cpp.

References C4Landscape::GetWidth(), Inside(), Landscape, SemiAboveSolid(), and TrajectoryDistance().

Referenced by C4Command::Put(), and C4Command::Throw().

2997 {
2998 
2999  // Start underneath throwing target
3000  rX = iTx; rY = iTy; // improve: check from overhanging cliff
3001  if (!SemiAboveSolid(rX, rY)) return false;
3002 
3003  // Target too far above surface
3004  if (!Inside(rY - iTy, -Throwing_MaxVertical, +Throwing_MaxVertical)) return false;
3005 
3006  // Search in direction according to launch fXDir
3007  int32_t iDir = +1; if (fXDir > 0) iDir = -1;
3008 
3009  // Move along surface
3010  for (int32_t cnt = 0; Inside<int32_t>(rX, 0, ::Landscape.GetWidth() - 1) && (cnt <= Throwing_MaxHorizontal); rX += iDir, cnt++)
3011  {
3012  // Adjust to surface
3013  if (!SemiAboveSolid(rX, rY)) return false;
3014 
3015  // Check trajectory distance
3016  int32_t itjd = TrajectoryDistance(rX, rY - iHeight, fXDir, fYDir, iTx, iTy);
3017 
3018  // Hitting range: success
3019  if (itjd <= 2) return true;
3020  }
3021 
3022  // Failure
3023  return false;
3024 
3025 }
bool SemiAboveSolid(int32_t &rx, int32_t &ry)
C4Landscape Landscape
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43
int32_t GetWidth() const
int32_t TrajectoryDistance(int32_t iFx, int32_t iFy, C4Real iXDir, C4Real iYDir, int32_t iTx, int32_t iTy)

Here is the call graph for this function:

Here is the caller graph for this function:

bool FindTunnel ( int32_t &  rx,
int32_t &  ry,
int32_t  width,
int32_t  height 
)

Definition at line 2706 of file C4Landscape.cpp.

References FindTunnelHeight(), C4Landscape::GetWidth(), and Landscape.

Referenced by C4Game::PlaceVegetation().

2707 {
2708  int32_t cx1, cx2, cy1, cy2, rl1 = 0, rl2 = 0;
2709 
2710  for (cx1 = cx2 = rx, cy1 = cy2 = ry; (cx1 > 0) || (cx2 < ::Landscape.GetWidth()); cx1--, cx2++)
2711  {
2712  // Left search
2713  if (cx1 > 0)
2714  {
2715  if (FindTunnelHeight(cx1, cy1, height)) rl1++;
2716  else rl1 = 0;
2717  }
2718  // Right search
2719  if (cx2 < ::Landscape.GetWidth())
2720  {
2721  if (FindTunnelHeight(cx2, cy2, height)) rl2++;
2722  else rl2 = 0;
2723  }
2724  // Check runs
2725  if (rl1 >= width) { rx = cx1 + rl1 / 2; ry = cy1; return true; }
2726  if (rl2 >= width) { rx = cx2 - rl2 / 2; ry = cy2; return true; }
2727  }
2728 
2729  return false;
2730 }
C4Landscape Landscape
bool FindTunnelHeight(int32_t cx, int32_t &ry, int32_t hgt)
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t GBackDensity ( int32_t  x,
int32_t  y 
)
inline

Definition at line 226 of file C4Landscape.h.

References C4Landscape::GetDensity(), and Landscape.

Referenced by C4Particle::Exec(), C4PXS::Execute(), GBackLiquid(), GBackSemiSolid(), GBackSolid(), C4DensityProvider::GetDensity(), C4Command::JumpControl(), LandscapeFree(), SimFlight(), and SimFlightHitsLiquid().

227 {
229 }
C4Landscape Landscape
int32_t GetDensity(int32_t x, int32_t y) const

Here is the call graph for this function:

Here is the caller graph for this function:

bool GBackLiquid ( int32_t  x,
int32_t  y 
)
inline

Definition at line 241 of file C4Landscape.h.

References DensityLiquid(), and GBackDensity().

Referenced by C4Object::ExecAction(), FindLiquidHeight(), FindSurfaceLiquid(), InitGameFunctionMap(), C4Object::IsInLiquidCheck(), and SimFlightHitsLiquid().

242 {
243  return DensityLiquid(GBackDensity(x,y));
244 }
bool DensityLiquid(int32_t dens)
Definition: C4Landscape.h:208
int32_t GBackDensity(int32_t x, int32_t y)
Definition: C4Landscape.h:226

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t GBackMat ( int32_t  x,
int32_t  y 
)
inline

Definition at line 221 of file C4Landscape.h.

References C4Landscape::GetMat(), and Landscape.

Referenced by C4EditCursor::ApplyToolPicker(), C4Shape::Attach(), C4Shape::ContactCheck(), C4MassMover::Corrosion(), C4Object::ExecLife(), C4MassMover::Execute(), C4PXS::Execute(), FindTunnelHeight(), C4MassMover::Init(), C4MaterialMap::mrfConvert(), C4Game::PlaceInEarth(), and C4Game::PlaceVegetation().

222 {
224 }
C4Landscape Landscape
int32_t GetMat(int32_t x, int32_t y) const

Here is the call graph for this function:

Here is the caller graph for this function:

bool GBackSemiSolid ( int32_t  x,
int32_t  y 
)
inline

Definition at line 236 of file C4Landscape.h.

References DensitySemiSolid(), and GBackDensity().

Referenced by AboveSemiSolid(), AboveSolid(), AdjustMoveToTarget(), C4Object::ContactAction(), C4Object::ExecLife(), FindClosestFree(), InitGameFunctionMap(), C4Game::PlaceAnimal(), C4Game::PlaceVegetation(), C4Object::SetOCF(), and C4Object::UpdateOCF().

237 {
238  return DensitySemiSolid(GBackDensity(x,y));
239 }
bool DensitySemiSolid(int32_t dens)
Definition: C4Landscape.h:203
int32_t GBackDensity(int32_t x, int32_t y)
Definition: C4Landscape.h:226

Here is the call graph for this function:

Here is the caller graph for this function:

bool GBackSolid ( int32_t  x,
int32_t  y 
)
inline

Definition at line 231 of file C4Landscape.h.

References DensitySolid(), and GBackDensity().

Referenced by AboveSolid(), AdjustMoveToTarget(), AdjustSolidOffset(), C4Object::AdjustWalkRotation(), C4Landscape::AreaSolidCount(), C4Landscape::CheckInstability(), FindConSiteSpot(), FindLevelGround(), C4Command::FlightControl(), C4TransferZone::GetEntryPoint(), InitGameFunctionMap(), C4Command::JumpControl(), PathFree(), PathFreePix(), C4Landscape::P::PostFreeShape(), C4Landscape::RaiseTerrain(), SemiAboveSolid(), C4Object::SetOCF(), SolidOnWhichSide(), TrajectoryDistance(), C4FoWLightSection::Update(), C4Object::UpdateOCF(), and VisibilityCheck().

232 {
233  return DensitySolid(GBackDensity(x,y));
234 }
int32_t GBackDensity(int32_t x, int32_t y)
Definition: C4Landscape.h:226
bool DensitySolid(int32_t dens)
Definition: C4Landscape.h:198

Here is the call graph for this function:

Here is the caller graph for this function:

bool PathFree ( int32_t  x1,
int32_t  y1,
int32_t  x2,
int32_t  y2 
)

Definition at line 2866 of file C4Landscape.cpp.

References PathFreePix().

Referenced by C4Command::Get(), InitGameFunctionMap(), C4Command::JumpControl(), C4Shape::LineConnect(), C4Command::MoveTo(), and ReduceLineSegments().

2867 {
2868  return ForLine(x1, y1, x2, y2, &PathFreePix);
2869 }
bool PathFreePix(int32_t x, int32_t y)

Here is the call graph for this function:

Here is the caller graph for this function:

bool PathFree ( int32_t  x1,
int32_t  y1,
int32_t  x2,
int32_t  y2,
int32_t *  ix,
int32_t *  iy 
)

Definition at line 2871 of file C4Landscape.cpp.

References Abs(), GBackSolid(), CPolyEdge::x, and CPolyEdge::y.

2872 {
2873  // use the standard Bresenham algorithm and just adjust it to behave correctly in the inversed case
2874  bool reverse = false;
2875  bool steep = Abs(y2 - y1) > Abs(x2 - x1);
2876 
2877  if (steep)
2878  {
2879  std::swap(x1, y1);
2880  std::swap(x2, y2);
2881  }
2882 
2883  if (x1 > x2)
2884  {
2885  std::swap(x1, x2);
2886  std::swap(y1, y2);
2887  reverse = true;
2888  }
2889 
2890  if (!reverse)
2891  {
2892  int32_t deltax = x2 - x1;
2893  int32_t deltay = Abs(y2 - y1);
2894  int32_t error = 0;
2895  int32_t ystep = (y1 < y2) ? 1 : -1;
2896  int32_t y = y1;
2897 
2898  for (int32_t x = x1; x <= x2; x++)
2899  {
2900  if (steep)
2901  {
2902  if (GBackSolid(y, x))
2903  {
2904  if (ix) { *ix = y; *iy = x; }
2905  return false;
2906  }
2907  }
2908  else
2909  {
2910  if (GBackSolid(x, y))
2911  {
2912  if (ix) { *ix = x; *iy = y; }
2913  return false;
2914  }
2915  }
2916 
2917  error += deltay;
2918  if (2 * error >= deltax)
2919  {
2920  y += ystep;
2921  error -= deltax;
2922  }
2923  }
2924  }
2925  else // reverse
2926  {
2927  int32_t deltax = x2 - x1;
2928  int32_t deltay = Abs(y2 - y1);
2929  int32_t error = 0;
2930  int32_t ystep = (y1 < y2) ? 1 : -1;
2931  int32_t y = y2;
2932 
2933  // normal (inverse) routine
2934  for (int32_t x = x2; x >= x1; x--)
2935  {
2936  if (steep)
2937  {
2938  if (GBackSolid(y, x))
2939  {
2940  if (ix) { *ix = y; *iy = x; }
2941  return false;
2942  }
2943  }
2944  else
2945  {
2946  if (GBackSolid(x, y))
2947  {
2948  if (ix) { *ix = x; *iy = y; }
2949  return false;
2950  }
2951  }
2952 
2953  error -= deltay;
2954  if (2 * error <= -deltax)
2955  {
2956  y -= ystep;
2957  error += deltax;
2958  }
2959 
2960  }
2961  }
2962  // no solid material encountered: path free!
2963  return true;
2964 }
T Abs(T val)
Definition: Standard.h:42
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:231

Here is the call graph for this function:

bool PathFreeIgnoreVehicle ( int32_t  x1,
int32_t  y1,
int32_t  x2,
int32_t  y2,
int32_t *  ix = nullptr,
int32_t *  iy = nullptr 
)

Definition at line 2972 of file C4Landscape.cpp.

References PathFreeIgnoreVehiclePix().

Referenced by C4Shape::LineConnect().

2973 {
2974  return ForLine(x1, y1, x2, y2, &PathFreeIgnoreVehiclePix, ix, iy);
2975 }
bool PathFreeIgnoreVehiclePix(int32_t x, int32_t y)

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t PixCol2Mat ( BYTE  pixc)

Definition at line 1958 of file C4Landscape.cpp.

References C4TextureMap::GetEntry(), C4TexMapEntry::GetMaterialIndex(), MNone, PixCol2Tex(), and TextureMap.

Referenced by C4Landscape::P::DoScan(), C4Landscape::Load(), C4Landscape::RaiseTerrain(), and C4Landscape::UpdatePixMaps().

1959 {
1960  // Get texture
1961  int32_t iTex = PixCol2Tex(pixc);
1962  if (!iTex) return MNone;
1963  // Get material-texture mapping
1964  const C4TexMapEntry *pTex = ::TextureMap.GetEntry(iTex);
1965  // Return material
1966  return pTex ? pTex->GetMaterialIndex() : MNone;
1967 }
int32_t GetMaterialIndex() const
Definition: C4Texture.h:62
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
const C4TexMapEntry * GetEntry(int32_t iIndex) const
Definition: C4Texture.h:85
Definition: C4Texture.h:48
const int32_t MNone
Definition: C4Constants.h:177
int32_t PixCol2Tex(BYTE pixc)
Definition: C4Landscape.h:213

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t PixCol2Tex ( BYTE  pixc)
inline

Definition at line 213 of file C4Landscape.h.

References C4M_MaxTexIndex.

Referenced by C4TextureMap::DefaultBkgMatTex(), and PixCol2Mat().

214 {
215  // Validate
216  if (pixc >= C4M_MaxTexIndex) return 0;
217  // Done
218  return pixc;
219 }
const int C4M_MaxTexIndex
Definition: C4Constants.h:51

Here is the caller graph for this function:

bool SemiAboveSolid ( int32_t &  rx,
int32_t &  ry 
)

Definition at line 2517 of file C4Landscape.cpp.

References GBackSolid(), C4Landscape::GetHeight(), and Landscape.

Referenced by FindThrowingPosition(), and C4Game::PlaceVegetation().

2518 {
2519  int32_t cy1 = ry, cy2 = ry;
2520 
2521  while ((cy1 >= 0) || (cy2 < ::Landscape.GetHeight()))
2522  {
2523  // Check upwards
2524  if (cy1 >= 0)
2525  if (!GBackSolid(rx, cy1))
2526  if (GBackSolid(rx, cy1 + 1))
2527  {
2528  ry = cy1; return true;
2529  }
2530  // Check downwards
2531  if (cy2 + 1 < ::Landscape.GetHeight())
2532  if (!GBackSolid(rx, cy2))
2533  if (GBackSolid(rx, cy2 + 1))
2534  {
2535  ry = cy2; return true;
2536  }
2537  // Advance
2538  cy1--; cy2++;
2539  }
2540 
2541  return false;
2542 }
C4Landscape Landscape
int32_t GetHeight() const
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:231

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const int32_t C4LS_MaxRelights = 50

Definition at line 27 of file C4Landscape.h.

Referenced by C4Landscape::_SetPix2(), and C4Landscape::DoRelights().

const int32_t C4MaxMaterial = 125
C4Landscape Landscape

Definition at line 4325 of file C4Landscape.cpp.

Referenced by AboveSemiSolid(), AboveSolid(), C4TextureMap::AddEntry(), AdjustMoveToTarget(), C4Viewport::AdjustPosition(), C4EditCursor::ApplyToolBrush(), C4EditCursor::ApplyToolFill(), C4EditCursor::ApplyToolLine(), C4EditCursor::ApplyToolPicker(), C4EditCursor::ApplyToolRect(), C4ToolsDlg::AssertValidBackTexture(), C4ToolsDlg::AssertValidTexture(), C4Viewport::CalculateZoom(), C4Viewport::CenterPosition(), C4SolidMask::CheckConsistency(), C4Game::Clear(), C4Game::ClearPointers(), C4Game::CompileFunc(), ConstructionCheck(), C4Shape::ContactCheck(), C4FoWAmbient::CreateFromLandscape(), C4Game::CreateObjectConstruction(), C4Game::Default(), DoBridge(), C4Object::DoMovement(), C4GraphicsSystem::DoSaveScreenshot(), C4Landscape::P::DoScan(), C4TextureShape::Draw(), C4PXSSystem::Draw(), C4Viewport::Draw(), C4Viewport::EnableFoW(), C4Object::ExecMovement(), C4MassMover::Execute(), C4PXS::Execute(), C4Player::Execute(), C4Game::Execute(), FindClosestFree(), FindConSiteSpot(), FindLevelGround(), FindLiquid(), FindLiquidHeight(), FindSolidGround(), FindSurfaceLiquid(), FindThrowingPosition(), FindTunnel(), FindTunnelHeight(), GBackDensity(), GBackMat(), C4Sky::GetSkyFadeClr(), C4Weather::GetWind(), C4MassMover::Init(), C4Player::Init(), C4Game::InitGame(), C4Game::InitInEarth(), C4Game::InitVegetation(), C4Viewport::InitZoom(), LandscapeFree(), C4Game::LoadScenarioSection(), C4MaterialMap::mrfCorrode(), C4MaterialMap::mrfIncinerate(), C4MaterialMap::mrfInsert(), mrfInsertCheck(), C4MaterialMap::mrfPoof(), PathFreeIgnoreVehiclePix(), C4Game::PlaceAnimal(), C4Game::PlaceInEarth(), C4Game::PlaceVegetation(), C4SolidMask::Put(), C4SolidMask::PutSolidMasks(), C4SolidMask::PutTemporary(), C4Landscape::RaiseTerrain(), C4SolidMask::Remove(), C4SolidMask::RemoveSolidMasks(), C4SolidMask::RemoveTemporary(), C4SolidMask::Repair(), C4Console::SaveScenario(), C4Player::ScenarioInit(), C4Player::ScrollView(), SemiAboveSolid(), C4ToolsDlg::SetBackMaterial(), C4ToolsDlg::SetLandscapeMode(), C4ToolsDlg::SetMaterial(), C4Viewport::SetViewX(), C4Viewport::SetViewY(), C4Object::SideBounds(), SimFlight(), C4Object::StatusDeactivate(), C4Game::Synchronize(), TrajectoryDistance(), C4FoWLightSection::Update(), C4MouseControl::UpdateFogOfWar(), C4FoWAmbient::UpdateFromLandscape(), C4Object::UpdateLight(), C4EditCursor::UpdateStatusBar(), and C4Object::VerticalBounds().