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

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

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

2477 {
2478  int32_t cy1 = ry, cy2 = ry;
2479  bool UseUpwardsNextFree = false, UseDownwardsNextSolid = false;
2480 
2481  while ((cy1 >= 0) || (cy2 < ::Landscape.GetHeight()))
2482  {
2483  // Check upwards
2484  if (cy1 >= 0)
2485  {
2486  if (GBackSemiSolid(rx, cy1)) UseUpwardsNextFree = true;
2487  else if (UseUpwardsNextFree) { ry = cy1; return true; }
2488  }
2489  // Check downwards
2490  if (cy2 < ::Landscape.GetHeight())
2491  {
2492  if (!GBackSemiSolid(rx, cy2)) UseDownwardsNextSolid = true;
2493  else if (UseDownwardsNextSolid) { ry = cy2; return true; }
2494  }
2495  // Advance
2496  cy1--; cy2++;
2497  }
2498 
2499  return false;
2500 }
C4Landscape Landscape
int32_t GetHeight() const
bool GBackSemiSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:234

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

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

Referenced by FindSolidGround().

2504 {
2505  int32_t cy1 = ry, cy2 = ry;
2506 
2507  while ((cy1 >= 0) || (cy2 < ::Landscape.GetHeight()))
2508  {
2509  // Check upwards
2510  if (cy1 >= 0)
2511  if (!GBackSemiSolid(rx, cy1))
2512  if (GBackSolid(rx, cy1 + 1))
2513  {
2514  ry = cy1; return true;
2515  }
2516  // Check downwards
2517  if (cy2 + 1 < ::Landscape.GetHeight())
2518  if (!GBackSemiSolid(rx, cy2))
2519  if (GBackSolid(rx, cy2 + 1))
2520  {
2521  ry = cy2; return true;
2522  }
2523  // Advance
2524  cy1--; cy2++;
2525  }
2526 
2527  return false;
2528 }
C4Landscape Landscape
int32_t GetHeight() const
bool GBackSemiSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:234
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:229

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 3065 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.

3066 {
3067  C4Def *ndef;
3068  // Check def
3069  if (!(ndef = PropList->GetDef()))
3070  {
3071  if (pByObj) GameMsgObjectError(FormatString(LoadResStr("IDS_OBJ_UNDEF"), PropList->GetName()).getData(), pByObj);
3072  return false;
3073  }
3074  // Constructable?
3075  if (!ndef->Constructable)
3076  {
3077  if (pByObj) GameMsgObjectError(FormatString(LoadResStr("IDS_OBJ_NOCON"), ndef->GetName()).getData(), pByObj);
3078  return false;
3079  }
3080  // Check area
3081  int32_t rtx, rty, wdt, hgt;
3082  wdt = ndef->Shape.Wdt; hgt = ndef->Shape.Hgt - ndef->ConSizeOff;
3083  rtx = iX - wdt / 2; rty = iY - hgt;
3084  if (::Landscape.AreaSolidCount(rtx, rty, wdt, hgt) > (wdt*hgt / 20))
3085  {
3086  if (pByObj) GameMsgObjectError(LoadResStr("IDS_OBJ_NOROOM"), pByObj);
3087  return false;
3088  }
3089  if (::Landscape.AreaSolidCount(rtx, rty + hgt, wdt, 5) < (wdt * 2))
3090  {
3091  if (pByObj) GameMsgObjectError(LoadResStr("IDS_OBJ_NOLEVEL"), pByObj);
3092  return false;
3093  }
3094  // Check other structures
3095  C4Object *other;
3096  if ((other = Game.FindConstuctionSiteBlock(rtx, rty, wdt, hgt)))
3097  {
3098  if (pByObj) GameMsgObjectError(FormatString(LoadResStr("IDS_OBJ_NOOTHER"), other->GetName()).getData(), pByObj);
3099  return false;
3100  }
3101  return true;
3102 }
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 206 of file C4Landscape.h.

References C4M_Liquid, and C4M_Solid.

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

207 {
208  return ((dens>=C4M_Liquid) && (dens<C4M_Solid));
209 }
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 201 of file C4Landscape.h.

References C4M_SemiSolid.

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

202 {
203  return (dens>=C4M_SemiSolid);
204 }
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 196 of file C4Landscape.h.

References C4M_Solid.

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

197 {
198  return (dens>=C4M_Solid);
199 }
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 3045 of file C4Landscape.cpp.

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

Referenced by C4Command::Get().

3047 {
3048  int32_t iX, iY;
3049  for (int32_t iR = Closest_Step; iR < Closest_MaxRange; iR += Closest_Step)
3050  for (int32_t iAngle = iAngle1; iAngle < iAngle2; iAngle += Closest_Step)
3051  if (!Inside(iAngle, iExcludeAngle1, iExcludeAngle2))
3052  {
3053  iX = rX + fixtoi(Sin(itofix(iAngle))*iR);
3054  iY = rY - fixtoi(Cos(itofix(iAngle))*iR);
3055  if (Inside<int32_t>(iX, 0, ::Landscape.GetWidth() - 1))
3056  if (Inside<int32_t>(iY, 0, ::Landscape.GetHeight() - 1))
3057  if (!GBackSemiSolid(iX, iY))
3058  {
3059  rX = iX; rY = iY; return true;
3060  }
3061  }
3062  return false;
3063 }
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:234
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 2802 of file C4Landscape.cpp.

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

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

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

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

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

Referenced by C4Player::PlaceReadyVehic().

2749 {
2750  bool fFound = false;
2751 
2752  int32_t cx1, cx2, cy1, cy2, rh1, rh2, rl1, rl2;
2753 
2754  cx1 = cx2 = rx; cy1 = cy2 = ry;
2755  rh1 = cy1; rh2 = cy2;
2756  rl1 = rl2 = 0;
2757 
2758  for (cx1--, cx2++; (cx1 > 0) || (cx2 < ::Landscape.GetWidth()); cx1--, cx2++)
2759  {
2760  // Left search
2761  if (cx1 > 0) // Still going
2762  {
2763  if (!AboveSemiSolid(cx1, cy1)) cx1 = -1; // Abort left
2764  else
2765  {
2766  if (GBackSolid(cx1, cy1 + 1) && (Abs(cy1 - rh1) < hrange))
2767  rl1++; // Run okay
2768  else
2769  {
2770  rl1 = 0; rh1 = cy1;
2771  } // No run
2772  }
2773  }
2774 
2775  // Right search
2776  if (cx2 < ::Landscape.GetWidth()) // Still going
2777  {
2778  if (!AboveSemiSolid(cx2, cy2)) cx2 = ::Landscape.GetWidth(); // Abort right
2779  else
2780  {
2781  if (GBackSolid(cx2, cy2 + 1) && (Abs(cy2 - rh2) < hrange))
2782  rl2++; // Run okay
2783  else
2784  {
2785  rl2 = 0; rh2 = cy2;
2786  } // No run
2787  }
2788  }
2789 
2790  // Check runs
2791  if (rl1 >= width) { rx = cx1 + rl1 / 2; ry = cy1; fFound = true; break; }
2792  if (rl2 >= width) { rx = cx2 - rl2 / 2; ry = cy2; fFound = true; break; }
2793  }
2794 
2795  if (fFound) AboveSemiSolid(rx, ry);
2796 
2797  return fFound;
2798 }
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:229

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

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

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

2693 {
2694  int32_t cx1, cx2, cy1, cy2, rl1 = 0, rl2 = 0;
2695 
2696  for (cx1 = cx2 = rx, cy1 = cy2 = ry; (cx1 > 0) || (cx2 < ::Landscape.GetWidth()); cx1--, cx2++)
2697  {
2698  // Left search
2699  if (cx1 > 0)
2700  {
2701  if (FindLiquidHeight(cx1, cy1, height)) rl1++;
2702  else rl1 = 0;
2703  }
2704  // Right search
2705  if (cx2 < ::Landscape.GetWidth())
2706  {
2707  if (FindLiquidHeight(cx2, cy2, height)) rl2++;
2708  else rl2 = 0;
2709  }
2710  // Check runs
2711  if (rl1 >= width) { rx = cx1 + rl1 / 2; ry = cy1; return true; }
2712  if (rl2 >= width) { rx = cx2 - rl2 / 2; ry = cy2; return true; }
2713  }
2714 
2715  return false;
2716 }
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 2622 of file C4Landscape.cpp.

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

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

2623 {
2624  bool fFound = false;
2625 
2626  int32_t cx1, cx2, cy1, cy2, rl1 = 0, rl2 = 0;
2627 
2628  for (cx1 = cx2 = rx, cy1 = cy2 = ry; (cx1 > 0) || (cx2 < ::Landscape.GetWidth()); cx1--, cx2++)
2629  {
2630  // Left search
2631  if (cx1 >= 0) // Still going
2632  {
2633  if (AboveSolid(cx1, cy1)) rl1++; // Run okay
2634  else rl1 = 0; // No run
2635  }
2636  // Right search
2637  if (cx2 < ::Landscape.GetWidth()) // Still going
2638  {
2639  if (AboveSolid(cx2, cy2)) rl2++; // Run okay
2640  else rl2 = 0; // No run
2641  }
2642  // Check runs
2643  if (rl1 >= width) { rx = cx1 + rl1 / 2; ry = cy1; fFound = true; break; }
2644  if (rl2 >= width) { rx = cx2 - rl2 / 2; ry = cy2; fFound = true; break; }
2645  }
2646 
2647  if (fFound) AboveSemiSolid(rx, ry);
2648 
2649  return fFound;
2650 }
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 2652 of file C4Landscape.cpp.

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

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

2653 {
2654  bool fFound = false;
2655 
2656  int32_t cx1, cx2, cy1, cy2, rl1 = 0, rl2 = 0, cnt;
2657  bool lokay;
2658  for (cx1 = cx2 = rx, cy1 = cy2 = ry; (cx1 > 0) || (cx2 < ::Landscape.GetWidth()); cx1--, cx2++)
2659  {
2660  // Left search
2661  if (cx1 > 0) // Still going
2662  {
2663  if (!AboveSemiSolid(cx1, cy1)) cx1 = -1; // Abort left
2664  else
2665  {
2666  for (lokay = true, cnt = 0; cnt < height; cnt++) if (!GBackLiquid(cx1, cy1 + 1 + cnt)) lokay = false;
2667  if (lokay) rl1++; // Run okay
2668  else rl1 = 0; // No run
2669  }
2670  }
2671  // Right search
2672  if (cx2 < ::Landscape.GetWidth()) // Still going
2673  {
2674  if (!AboveSemiSolid(cx2, cy2)) cx2 = ::Landscape.GetWidth(); // Abort right
2675  else
2676  {
2677  for (lokay = true, cnt = 0; cnt < height; cnt++) if (!GBackLiquid(cx2, cy2 + 1 + cnt)) lokay = false;
2678  if (lokay) rl2++; // Run okay
2679  else rl2 = 0; // No run
2680  }
2681  }
2682  // Check runs
2683  if (rl1 >= width) { rx = cx1 + rl1 / 2; ry = cy1; fFound = true; break; }
2684  if (rl2 >= width) { rx = cx2 - rl2 / 2; ry = cy2; fFound = true; break; }
2685  }
2686 
2687  if (fFound) AboveSemiSolid(rx, ry);
2688 
2689  return fFound;
2690 }
C4Landscape Landscape
bool AboveSemiSolid(int32_t &rx, int32_t &ry)
bool GBackLiquid(int32_t x, int32_t y)
Definition: C4Landscape.h:239
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 3010 of file C4Landscape.cpp.

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

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

3011 {
3012 
3013  // Start underneath throwing target
3014  rX = iTx; rY = iTy; // improve: check from overhanging cliff
3015  if (!SemiAboveSolid(rX, rY)) return false;
3016 
3017  // Target too far above surface
3018  if (!Inside(rY - iTy, -Throwing_MaxVertical, +Throwing_MaxVertical)) return false;
3019 
3020  // Search in direction according to launch fXDir
3021  int32_t iDir = +1; if (fXDir > 0) iDir = -1;
3022 
3023  // Move along surface
3024  for (int32_t cnt = 0; Inside<int32_t>(rX, 0, ::Landscape.GetWidth() - 1) && (cnt <= Throwing_MaxHorizontal); rX += iDir, cnt++)
3025  {
3026  // Adjust to surface
3027  if (!SemiAboveSolid(rX, rY)) return false;
3028 
3029  // Check trajectory distance
3030  int32_t itjd = TrajectoryDistance(rX, rY - iHeight, fXDir, fYDir, iTx, iTy);
3031 
3032  // Hitting range: success
3033  if (itjd <= 2) return true;
3034  }
3035 
3036  // Failure
3037  return false;
3038 
3039 }
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 2720 of file C4Landscape.cpp.

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

Referenced by C4Game::PlaceVegetation().

2721 {
2722  int32_t cx1, cx2, cy1, cy2, rl1 = 0, rl2 = 0;
2723 
2724  for (cx1 = cx2 = rx, cy1 = cy2 = ry; (cx1 > 0) || (cx2 < ::Landscape.GetWidth()); cx1--, cx2++)
2725  {
2726  // Left search
2727  if (cx1 > 0)
2728  {
2729  if (FindTunnelHeight(cx1, cy1, height)) rl1++;
2730  else rl1 = 0;
2731  }
2732  // Right search
2733  if (cx2 < ::Landscape.GetWidth())
2734  {
2735  if (FindTunnelHeight(cx2, cy2, height)) rl2++;
2736  else rl2 = 0;
2737  }
2738  // Check runs
2739  if (rl1 >= width) { rx = cx1 + rl1 / 2; ry = cy1; return true; }
2740  if (rl2 >= width) { rx = cx2 - rl2 / 2; ry = cy2; return true; }
2741  }
2742 
2743  return false;
2744 }
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 224 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().

225 {
227 }
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 239 of file C4Landscape.h.

References DensityLiquid(), and GBackDensity().

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

240 {
241  return DensityLiquid(GBackDensity(x,y));
242 }
bool DensityLiquid(int32_t dens)
Definition: C4Landscape.h:206
int32_t GBackDensity(int32_t x, int32_t y)
Definition: C4Landscape.h:224

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

220 {
222 }
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 234 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().

235 {
236  return DensitySemiSolid(GBackDensity(x,y));
237 }
bool DensitySemiSolid(int32_t dens)
Definition: C4Landscape.h:201
int32_t GBackDensity(int32_t x, int32_t y)
Definition: C4Landscape.h:224

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

230 {
231  return DensitySolid(GBackDensity(x,y));
232 }
int32_t GBackDensity(int32_t x, int32_t y)
Definition: C4Landscape.h:224
bool DensitySolid(int32_t dens)
Definition: C4Landscape.h:196

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

References PathFreePix().

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

2881 {
2882  return ForLine(x1, y1, x2, y2, &PathFreePix);
2883 }
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 2885 of file C4Landscape.cpp.

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

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

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

References PathFreeIgnoreVehiclePix().

Referenced by C4Shape::LineConnect().

2987 {
2988  return ForLine(x1, y1, x2, y2, &PathFreeIgnoreVehiclePix, ix, iy);
2989 }
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 1939 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().

1940 {
1941  // Get texture
1942  int32_t iTex = PixCol2Tex(pixc);
1943  if (!iTex) return MNone;
1944  // Get material-texture mapping
1945  const C4TexMapEntry *pTex = ::TextureMap.GetEntry(iTex);
1946  // Return material
1947  return pTex ? pTex->GetMaterialIndex() : MNone;
1948 }
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:211

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 211 of file C4Landscape.h.

References C4M_MaxTexIndex.

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

212 {
213  // Validate
214  if (pixc >= C4M_MaxTexIndex) return 0;
215  // Done
216  return pixc;
217 }
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 2531 of file C4Landscape.cpp.

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

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

2532 {
2533  int32_t cy1 = ry, cy2 = ry;
2534 
2535  while ((cy1 >= 0) || (cy2 < ::Landscape.GetHeight()))
2536  {
2537  // Check upwards
2538  if (cy1 >= 0)
2539  if (!GBackSolid(rx, cy1))
2540  if (GBackSolid(rx, cy1 + 1))
2541  {
2542  ry = cy1; return true;
2543  }
2544  // Check downwards
2545  if (cy2 + 1 < ::Landscape.GetHeight())
2546  if (!GBackSolid(rx, cy2))
2547  if (GBackSolid(rx, cy2 + 1))
2548  {
2549  ry = cy2; return true;
2550  }
2551  // Advance
2552  cy1--; cy2++;
2553  }
2554 
2555  return false;
2556 }
C4Landscape Landscape
int32_t GetHeight() const
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:229

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