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 2463 of file C4Landscape.cpp.

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

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

2464 {
2465  int32_t cy1 = ry, cy2 = ry;
2466  bool UseUpwardsNextFree = false, UseDownwardsNextSolid = false;
2467 
2468  while ((cy1 >= 0) || (cy2 < ::Landscape.GetHeight()))
2469  {
2470  // Check upwards
2471  if (cy1 >= 0)
2472  {
2473  if (GBackSemiSolid(rx, cy1)) UseUpwardsNextFree = true;
2474  else if (UseUpwardsNextFree) { ry = cy1; return true; }
2475  }
2476  // Check downwards
2477  if (cy2 < ::Landscape.GetHeight())
2478  {
2479  if (!GBackSemiSolid(rx, cy2)) UseDownwardsNextSolid = true;
2480  else if (UseDownwardsNextSolid) { ry = cy2; return true; }
2481  }
2482  // Advance
2483  cy1--; cy2++;
2484  }
2485 
2486  return false;
2487 }
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 2490 of file C4Landscape.cpp.

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

Referenced by FindSolidGround().

2491 {
2492  int32_t cy1 = ry, cy2 = ry;
2493 
2494  while ((cy1 >= 0) || (cy2 < ::Landscape.GetHeight()))
2495  {
2496  // Check upwards
2497  if (cy1 >= 0)
2498  if (!GBackSemiSolid(rx, cy1))
2499  if (GBackSolid(rx, cy1 + 1))
2500  {
2501  ry = cy1; return true;
2502  }
2503  // Check downwards
2504  if (cy2 + 1 < ::Landscape.GetHeight())
2505  if (!GBackSemiSolid(rx, cy2))
2506  if (GBackSolid(rx, cy2 + 1))
2507  {
2508  ry = cy2; return true;
2509  }
2510  // Advance
2511  cy1--; cy2++;
2512  }
2513 
2514  return false;
2515 }
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 3052 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.

3053 {
3054  C4Def *ndef;
3055  // Check def
3056  if (!(ndef = PropList->GetDef()))
3057  {
3058  if (pByObj) GameMsgObjectError(FormatString(LoadResStr("IDS_OBJ_UNDEF"), PropList->GetName()).getData(), pByObj);
3059  return false;
3060  }
3061  // Constructable?
3062  if (!ndef->Constructable)
3063  {
3064  if (pByObj) GameMsgObjectError(FormatString(LoadResStr("IDS_OBJ_NOCON"), ndef->GetName()).getData(), pByObj);
3065  return false;
3066  }
3067  // Check area
3068  int32_t rtx, rty, wdt, hgt;
3069  wdt = ndef->Shape.Wdt; hgt = ndef->Shape.Hgt - ndef->ConSizeOff;
3070  rtx = iX - wdt / 2; rty = iY - hgt;
3071  if (::Landscape.AreaSolidCount(rtx, rty, wdt, hgt) > (wdt*hgt / 20))
3072  {
3073  if (pByObj) GameMsgObjectError(LoadResStr("IDS_OBJ_NOROOM"), pByObj);
3074  return false;
3075  }
3076  if (::Landscape.AreaSolidCount(rtx, rty + hgt, wdt, 5) < (wdt * 2))
3077  {
3078  if (pByObj) GameMsgObjectError(LoadResStr("IDS_OBJ_NOLEVEL"), pByObj);
3079  return false;
3080  }
3081  // Check other structures
3082  C4Object *other;
3083  if ((other = Game.FindConstuctionSiteBlock(rtx, rty, wdt, hgt)))
3084  {
3085  if (pByObj) GameMsgObjectError(FormatString(LoadResStr("IDS_OBJ_NOOTHER"), other->GetName()).getData(), pByObj);
3086  return false;
3087  }
3088  return true;
3089 }
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 3032 of file C4Landscape.cpp.

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

Referenced by C4Command::Get().

3034 {
3035  int32_t iX, iY;
3036  for (int32_t iR = Closest_Step; iR < Closest_MaxRange; iR += Closest_Step)
3037  for (int32_t iAngle = iAngle1; iAngle < iAngle2; iAngle += Closest_Step)
3038  if (!Inside(iAngle, iExcludeAngle1, iExcludeAngle2))
3039  {
3040  iX = rX + fixtoi(Sin(itofix(iAngle))*iR);
3041  iY = rY - fixtoi(Cos(itofix(iAngle))*iR);
3042  if (Inside<int32_t>(iX, 0, ::Landscape.GetWidth() - 1))
3043  if (Inside<int32_t>(iY, 0, ::Landscape.GetHeight() - 1))
3044  if (!GBackSemiSolid(iX, iY))
3045  {
3046  rX = iX; rY = iY; return true;
3047  }
3048  }
3049  return false;
3050 }
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 2789 of file C4Landscape.cpp.

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

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

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

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

Referenced by C4Player::PlaceReadyVehic().

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

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

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

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

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

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

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

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

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

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

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

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

2998 {
2999 
3000  // Start underneath throwing target
3001  rX = iTx; rY = iTy; // improve: check from overhanging cliff
3002  if (!SemiAboveSolid(rX, rY)) return false;
3003 
3004  // Target too far above surface
3005  if (!Inside(rY - iTy, -Throwing_MaxVertical, +Throwing_MaxVertical)) return false;
3006 
3007  // Search in direction according to launch fXDir
3008  int32_t iDir = +1; if (fXDir > 0) iDir = -1;
3009 
3010  // Move along surface
3011  for (int32_t cnt = 0; Inside<int32_t>(rX, 0, ::Landscape.GetWidth() - 1) && (cnt <= Throwing_MaxHorizontal); rX += iDir, cnt++)
3012  {
3013  // Adjust to surface
3014  if (!SemiAboveSolid(rX, rY)) return false;
3015 
3016  // Check trajectory distance
3017  int32_t itjd = TrajectoryDistance(rX, rY - iHeight, fXDir, fYDir, iTx, iTy);
3018 
3019  // Hitting range: success
3020  if (itjd <= 2) return true;
3021  }
3022 
3023  // Failure
3024  return false;
3025 
3026 }
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 2707 of file C4Landscape.cpp.

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

Referenced by C4Game::PlaceVegetation().

2708 {
2709  int32_t cx1, cx2, cy1, cy2, rl1 = 0, rl2 = 0;
2710 
2711  for (cx1 = cx2 = rx, cy1 = cy2 = ry; (cx1 > 0) || (cx2 < ::Landscape.GetWidth()); cx1--, cx2++)
2712  {
2713  // Left search
2714  if (cx1 > 0)
2715  {
2716  if (FindTunnelHeight(cx1, cy1, height)) rl1++;
2717  else rl1 = 0;
2718  }
2719  // Right search
2720  if (cx2 < ::Landscape.GetWidth())
2721  {
2722  if (FindTunnelHeight(cx2, cy2, height)) rl2++;
2723  else rl2 = 0;
2724  }
2725  // Check runs
2726  if (rl1 >= width) { rx = cx1 + rl1 / 2; ry = cy1; return true; }
2727  if (rl2 >= width) { rx = cx2 - rl2 / 2; ry = cy2; return true; }
2728  }
2729 
2730  return false;
2731 }
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(), C4PXS::Execute(), C4MassMover::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 2867 of file C4Landscape.cpp.

References PathFreePix().

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

2868 {
2869  return ForLine(x1, y1, x2, y2, &PathFreePix);
2870 }
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 2872 of file C4Landscape.cpp.

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

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

References PathFreeIgnoreVehiclePix().

Referenced by C4Shape::LineConnect().

2974 {
2975  return ForLine(x1, y1, x2, y2, &PathFreeIgnoreVehiclePix, ix, iy);
2976 }
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 1959 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().

1960 {
1961  // Get texture
1962  int32_t iTex = PixCol2Tex(pixc);
1963  if (!iTex) return MNone;
1964  // Get material-texture mapping
1965  const C4TexMapEntry *pTex = ::TextureMap.GetEntry(iTex);
1966  // Return material
1967  return pTex ? pTex->GetMaterialIndex() : MNone;
1968 }
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 2518 of file C4Landscape.cpp.

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

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

2519 {
2520  int32_t cy1 = ry, cy2 = ry;
2521 
2522  while ((cy1 >= 0) || (cy2 < ::Landscape.GetHeight()))
2523  {
2524  // Check upwards
2525  if (cy1 >= 0)
2526  if (!GBackSolid(rx, cy1))
2527  if (GBackSolid(rx, cy1 + 1))
2528  {
2529  ry = cy1; return true;
2530  }
2531  // Check downwards
2532  if (cy2 + 1 < ::Landscape.GetHeight())
2533  if (!GBackSolid(rx, cy2))
2534  if (GBackSolid(rx, cy2 + 1))
2535  {
2536  ry = cy2; return true;
2537  }
2538  // Advance
2539  cy1--; cy2++;
2540  }
2541 
2542  return false;
2543 }
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 4326 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(), C4PXS::Execute(), C4MassMover::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().