OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Landscape.h File Reference
#include "C4Prototypes.h"
#include "config/C4Constants.h"
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 30 of file C4Landscape.h.

Function Documentation

bool AboveSemiSolid ( int32_t &  rx,
int32_t &  ry 
)

Definition at line 2466 of file C4Landscape.cpp.

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

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

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

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

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

Referenced by FindSolidGround().

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

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

3056 {
3057  C4Def *ndef;
3058  // Check def
3059  if (!(ndef = PropList->GetDef()))
3060  {
3061  if (pByObj) GameMsgObjectError(FormatString(LoadResStr("IDS_OBJ_UNDEF"), PropList->GetName()).getData(), pByObj);
3062  return false;
3063  }
3064  // Constructable?
3065  if (!ndef->Constructable)
3066  {
3067  if (pByObj) GameMsgObjectError(FormatString(LoadResStr("IDS_OBJ_NOCON"), ndef->GetName()).getData(), pByObj);
3068  return false;
3069  }
3070  // Check area
3071  int32_t rtx, rty, wdt, hgt;
3072  wdt = ndef->Shape.Wdt; hgt = ndef->Shape.Hgt - ndef->ConSizeOff;
3073  rtx = iX - wdt / 2; rty = iY - hgt;
3074  if (::Landscape.AreaSolidCount(rtx, rty, wdt, hgt) > (wdt*hgt / 20))
3075  {
3076  if (pByObj) GameMsgObjectError(LoadResStr("IDS_OBJ_NOROOM"), pByObj);
3077  return false;
3078  }
3079  if (::Landscape.AreaSolidCount(rtx, rty + hgt, wdt, 5) < (wdt * 2))
3080  {
3081  if (pByObj) GameMsgObjectError(LoadResStr("IDS_OBJ_NOLEVEL"), pByObj);
3082  return false;
3083  }
3084  // Check other structures
3085  C4Object *other;
3086  if ((other = Game.FindConstuctionSiteBlock(rtx, rty, wdt, hgt)))
3087  {
3088  if (pByObj) GameMsgObjectError(FormatString(LoadResStr("IDS_OBJ_NOOTHER"), other->GetName()).getData(), pByObj);
3089  return false;
3090  }
3091  return true;
3092 }
virtual const char * GetName() const
Definition: C4PropList.cpp:267
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
int32_t Wdt
Definition: C4Rect.h:32
C4Shape Shape
Definition: C4Def.h:106
C4Landscape Landscape
virtual const char * GetName() const
Definition: C4PropList.cpp:626
int32_t Constructable
Definition: C4Def.h:120
Definition: C4Def.h:100
C4Object * FindConstuctionSiteBlock(int32_t tx, int32_t ty, int32_t wdt, int32_t hgt)
Definition: C4Game.cpp:1146
virtual C4Def const * GetDef() const
Definition: C4Def.h:217
int32_t AreaSolidCount(int32_t x, int32_t y, int32_t wdt, int32_t hgt) const
int32_t Hgt
Definition: C4Rect.h:32
int32_t ConSizeOff
Definition: C4Def.h:146
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

Here is the call graph for this function:

bool DensityLiquid ( int32_t  dens)
inline

Definition at line 209 of file C4Landscape.h.

References C4M_Liquid, and C4M_Solid.

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

210 {
211  return ((dens>=C4M_Liquid) && (dens<C4M_Solid));
212 }
const int32_t C4M_Solid
Definition: C4Constants.h:173
const int32_t C4M_Liquid
Definition: C4Constants.h:175

Here is the caller graph for this function:

bool DensitySemiSolid ( int32_t  dens)
inline

Definition at line 204 of file C4Landscape.h.

References C4M_SemiSolid.

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

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

Here is the caller graph for this function:

bool DensitySolid ( int32_t  dens)
inline

Definition at line 199 of file C4Landscape.h.

References C4M_Solid.

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

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

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

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

Referenced by C4Command::Get().

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

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

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

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

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

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

Referenced by C4Player::PlaceReadyVehic().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Referenced by C4Game::PlaceVegetation().

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

228 {
230 }
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 242 of file C4Landscape.h.

References DensityLiquid(), and GBackDensity().

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

243 {
244  return DensityLiquid(GBackDensity(x,y));
245 }
bool DensityLiquid(int32_t dens)
Definition: C4Landscape.h:209
int32_t GBackDensity(int32_t x, int32_t y)
Definition: C4Landscape.h:227

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

223 {
225 }
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 237 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().

238 {
239  return DensitySemiSolid(GBackDensity(x,y));
240 }
bool DensitySemiSolid(int32_t dens)
Definition: C4Landscape.h:204
int32_t GBackDensity(int32_t x, int32_t y)
Definition: C4Landscape.h:227

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

233 {
234  return DensitySolid(GBackDensity(x,y));
235 }
int32_t GBackDensity(int32_t x, int32_t y)
Definition: C4Landscape.h:227
bool DensitySolid(int32_t dens)
Definition: C4Landscape.h:199

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

References PathFreePix().

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

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

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

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

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

References PathFreeIgnoreVehiclePix().

Referenced by C4Shape::LineConnect().

2977 {
2978  return ForLine(x1, y1, x2, y2, &PathFreeIgnoreVehiclePix, ix, iy);
2979 }
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 1962 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().

1963 {
1964  // Get texture
1965  int32_t iTex = PixCol2Tex(pixc);
1966  if (!iTex) return MNone;
1967  // Get material-texture mapping
1968  const C4TexMapEntry *pTex = ::TextureMap.GetEntry(iTex);
1969  // Return material
1970  return pTex ? pTex->GetMaterialIndex() : MNone;
1971 }
int32_t GetMaterialIndex() const
Definition: C4Texture.h:62
C4TextureMap TextureMap
Definition: C4Texture.cpp:580
const C4TexMapEntry * GetEntry(int32_t iIndex) const
Definition: C4Texture.h:85
Definition: C4Texture.h:48
const int32_t MNone
Definition: C4Constants.h:178
int32_t PixCol2Tex(BYTE pixc)
Definition: C4Landscape.h:214

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

References C4M_MaxTexIndex.

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

215 {
216  // Validate
217  if (pixc >= C4M_MaxTexIndex) return 0;
218  // Done
219  return pixc;
220 }
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 2521 of file C4Landscape.cpp.

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

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

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

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

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

const int32_t C4MaxMaterial = 125
C4Landscape Landscape

Definition at line 4329 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(), 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().