OpenClonk
C4Landscape.cpp File Reference
Include dependency graph for C4Landscape.cpp:

Go to the source code of this file.

Classes

struct  C4Landscape::P
 
struct  CPolyEdge
 

Macros

#define PRETTY_TEMP_CONV
 
#define POLYGON_FIX_SHIFT   16
 

Functions

int32_t PixCol2Mat (BYTE pixc)
 
bool AboveSemiSolid (int32_t &rx, int32_t &ry)
 
bool AboveSolid (int32_t &rx, int32_t &ry)
 
bool SemiAboveSolid (int32_t &rx, int32_t &ry)
 
bool FindLiquidHeight (int32_t cx, int32_t &ry, int32_t hgt)
 
bool FindTunnelHeight (int32_t cx, int32_t &ry, int32_t hgt)
 
bool FindSolidGround (int32_t &rx, int32_t &ry, int32_t width)
 
bool FindSurfaceLiquid (int32_t &rx, int32_t &ry, int32_t width, int32_t height)
 
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 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)
 
bool PathFreePix (int32_t x, int32_t y)
 
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 PathFreeIgnoreVehiclePix (int32_t x, int32_t y)
 
bool PathFreeIgnoreVehicle (int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t *ix, int32_t *iy)
 
int32_t TrajectoryDistance (int32_t iFx, int32_t iFy, C4Real iXDir, C4Real iYDir, int32_t iTx, int32_t iTy)
 
bool FindThrowingPosition (int32_t iTx, int32_t iTy, C4Real fXDir, C4Real fYDir, int32_t iHeight, int32_t &rX, int32_t &rY)
 
bool FindClosestFree (int32_t &rX, int32_t &rY, int32_t iAngle1, int32_t iAngle2, int32_t iExcludeAngle1, int32_t iExcludeAngle2)
 
bool ConstructionCheck (C4PropList *PropList, int32_t iX, int32_t iY, C4Object *pByObj)
 

Variables

const int QuickPolyBufSize = 20
 
CPolyEdge QuickPolyBuf [QuickPolyBufSize]
 
C4Landscape Landscape
 

Class Documentation

◆ CPolyEdge

struct CPolyEdge

Definition at line 1146 of file C4Landscape.cpp.

Collaboration diagram for CPolyEdge:
[legend]
Class Members
int bottom
int dx
struct CPolyEdge * next
struct CPolyEdge * prev
int w
int x
int y

Macro Definition Documentation

◆ POLYGON_FIX_SHIFT

#define POLYGON_FIX_SHIFT   16

Definition at line 1157 of file C4Landscape.cpp.

◆ PRETTY_TEMP_CONV

#define PRETTY_TEMP_CONV

Definition at line 268 of file C4Landscape.cpp.

Function Documentation

◆ AboveSemiSolid()

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(), and FindSurfaceLiquid().

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:

◆ AboveSolid()

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:

◆ ConstructionCheck()

bool ConstructionCheck ( C4PropList PropList,
int32_t  iX,
int32_t  iY,
C4Object pByObj 
)

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
int32_t Wdt
Definition: C4Rect.h:30
C4Shape Shape
Definition: C4Def.h:104
C4Landscape Landscape
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
virtual const char * GetName() const
Definition: C4PropList.cpp:649
virtual C4Def const * GetDef() const
Definition: C4PropList.cpp:685
int32_t Hgt
Definition: C4Rect.h:30
int32_t AreaSolidCount(int32_t x, int32_t y, int32_t wdt, int32_t hgt) const
int32_t ConSizeOff
Definition: C4Def.h:143
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
Here is the call graph for this function:

◆ FindClosestFree()

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.

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
int32_t GetWidth() const
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
Here is the caller graph for this function:

◆ FindConSiteSpot()

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

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
int32_t GetWidth() const
T Abs(T val)
Definition: Standard.h:42
bool AboveSemiSolid(int32_t &rx, int32_t &ry)
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:

◆ FindLevelGround()

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
int32_t GetWidth() const
T Abs(T val)
Definition: Standard.h:42
bool AboveSemiSolid(int32_t &rx, int32_t &ry)
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:

◆ FindLiquid()

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

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:

◆ FindLiquidHeight()

bool FindLiquidHeight ( int32_t  cx,
int32_t &  ry,
int32_t  hgt 
)

Definition at line 2558 of file C4Landscape.cpp.

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

Referenced by FindLiquid().

2559 {
2560  int32_t cy1 = ry, cy2 = ry, rl1 = 0, rl2 = 0;
2561 
2562  while ((cy1 >= 0) || (cy2 < ::Landscape.GetHeight()))
2563  {
2564  // Check upwards
2565  if (cy1 >= 0)
2566  {
2567  if (GBackLiquid(cx, cy1))
2568  {
2569  rl1++; if (rl1 >= hgt) { ry = cy1 + hgt / 2; return true; }
2570  }
2571  else rl1 = 0;
2572  }
2573  // Check downwards
2574  if (cy2 + 1 < ::Landscape.GetHeight())
2575  {
2576  if (GBackLiquid(cx, cy2))
2577  {
2578  rl2++; if (rl2 >= hgt) { ry = cy2 - hgt / 2; return true; }
2579  }
2580  else rl2 = 0;
2581  }
2582  // Advance
2583  cy1--; cy2++;
2584  }
2585 
2586  return false;
2587 }
C4Landscape Landscape
int32_t GetHeight() const
bool GBackLiquid(int32_t x, int32_t y)
Definition: C4Landscape.h:239
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindSolidGround()

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
int32_t GetWidth() const
bool AboveSolid(int32_t &rx, int32_t &ry)
bool AboveSemiSolid(int32_t &rx, int32_t &ry)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindSurfaceLiquid()

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

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
int32_t GetWidth() const
bool AboveSemiSolid(int32_t &rx, int32_t &ry)
bool GBackLiquid(int32_t x, int32_t y)
Definition: C4Landscape.h:239
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindThrowingPosition()

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, and SemiAboveSolid().

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
int32_t GetWidth() const
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43
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:

◆ FindTunnel()

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.

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:

◆ FindTunnelHeight()

bool FindTunnelHeight ( int32_t  cx,
int32_t &  ry,
int32_t  hgt 
)

Definition at line 2589 of file C4Landscape.cpp.

References C4M_Liquid, GBackMat(), C4Landscape::GetBackPix(), C4Landscape::GetHeight(), Landscape, and MatDensity().

Referenced by FindTunnel().

2590 {
2591  int32_t cy1 = ry, cy2 = ry, rl1 = 0, rl2 = 0;
2592 
2593  while ((cy1 >= 0) || (cy2 < ::Landscape.GetHeight()))
2594  {
2595  // Check upwards
2596  if (cy1 >= 0)
2597  {
2598  if (Landscape.GetBackPix(cx, cy1) != 0 && MatDensity(GBackMat(cx, cy1)) < C4M_Liquid)
2599  {
2600  rl1++; if (rl1 >= hgt) { ry = cy1 + hgt / 2; return true; }
2601  }
2602  else rl1 = 0;
2603  }
2604  // Check downwards
2605  if (cy2 + 1 < ::Landscape.GetHeight())
2606  {
2607  if (Landscape.GetBackPix(cx, cy2) != 0 && MatDensity(GBackMat(cx, cy2)) < C4M_Liquid)
2608  {
2609  rl2++; if (rl2 >= hgt) { ry = cy2 - hgt / 2; return true; }
2610  }
2611  else rl2 = 0;
2612  }
2613  // Advance
2614  cy1--; cy2++;
2615  }
2616 
2617  return false;
2618 }
BYTE GetBackPix(int32_t x, int32_t y) const
int32_t MatDensity(int32_t mat)
Definition: C4Material.h:240
C4Landscape Landscape
int32_t GetHeight() const
const int32_t C4M_Liquid
Definition: C4Constants.h:174
int32_t GBackMat(int32_t x, int32_t y)
Definition: C4Landscape.h:219
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PathFree() [1/2]

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

◆ PathFree() [2/2]

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:

◆ PathFreeIgnoreVehicle()

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

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:

◆ PathFreeIgnoreVehiclePix()

bool PathFreeIgnoreVehiclePix ( int32_t  x,
int32_t  y 
)

Definition at line 2980 of file C4Landscape.cpp.

References DensitySolid(), C4Landscape::GetPix(), C4Landscape::GetPixMat(), Landscape, and MVehic.

Referenced by PathFreeIgnoreVehicle().

2981 {
2982  BYTE byPix = ::Landscape.GetPix(x, y);
2983  return !byPix || !DensitySolid(::Landscape.GetPixMat(byPix)) || ::Landscape.GetPixMat(byPix) == MVehic;
2984 }
uint8_t BYTE
C4Landscape Landscape
int32_t MVehic
Definition: C4Material.cpp:36
int32_t GetPixMat(BYTE byPix) const
BYTE GetPix(int32_t x, int32_t y) const
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:

◆ PathFreePix()

bool PathFreePix ( int32_t  x,
int32_t  y 
)

Definition at line 2875 of file C4Landscape.cpp.

References GBackSolid().

Referenced by PathFree().

2876 {
2877  return !GBackSolid(x, y);
2878 }
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:

◆ PixCol2Mat()

int32_t PixCol2Mat ( BYTE  pixc)

Definition at line 1939 of file C4Landscape.cpp.

Referenced by C4Landscape::P::DoScan(), C4Landscape::RaiseTerrain(), C4LandscapeRenderGL::Update(), 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 }
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
Definition: C4Texture.h:48
const C4TexMapEntry * GetEntry(int32_t iIndex) const
Definition: C4Texture.h:85
const int32_t MNone
Definition: C4Constants.h:177
int32_t PixCol2Tex(BYTE pixc)
Definition: C4Landscape.h:211
int32_t GetMaterialIndex() const
Definition: C4Texture.h:62
Here is the caller graph for this function:

◆ SemiAboveSolid()

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

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:

◆ TrajectoryDistance()

int32_t TrajectoryDistance ( int32_t  iFx,
int32_t  iFy,
C4Real  iXDir,
C4Real  iYDir,
int32_t  iTx,
int32_t  iTy 
)

Definition at line 2991 of file C4Landscape.cpp.

References Distance(), fixtoi(), GBackSolid(), C4Landscape::GetHeight(), C4Landscape::GetWidth(), GravAccel, Inside(), itofix(), and Landscape.

2992 {
2993  int32_t iClosest = Distance(iFx, iFy, iTx, iTy);
2994  // Follow free trajectory, take closest point distance
2995  C4Real cx = itofix(iFx), cy = itofix(iFy);
2996  int32_t cdis;
2997  while (Inside(fixtoi(cx), 0, ::Landscape.GetWidth() - 1) && Inside(fixtoi(cy), 0, ::Landscape.GetHeight() - 1) && !GBackSolid(fixtoi(cx), fixtoi(cy)))
2998  {
2999  cdis = Distance(fixtoi(cx), fixtoi(cy), iTx, iTy);
3000  if (cdis < iClosest) iClosest = cdis;
3001  cx += iXDir; cy += iYDir; iYDir += GravAccel;
3002  }
3003  return iClosest;
3004 }
#define GravAccel
Definition: C4Physics.h:27
Definition: C4Real.h:58
int32_t Distance(int32_t iX1, int32_t iY1, int32_t iX2, int32_t iY2)
Definition: Standard.cpp:25
C4Landscape Landscape
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
int32_t GetHeight() const
int32_t GetWidth() const
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:229
Here is the call graph for this function:

Variable Documentation

◆ Landscape

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(), C4ControlEMDrawTool::C4ControlEMDrawTool(), C4Viewport::CalculateZoom(), C4Viewport::CenterPosition(), C4SolidMask::CheckConsistency(), C4Game::Clear(), C4Game::ClearPointers(), C4ConsoleGUIPreviewWindow::Close(), C4Scenario::CompileFunc(), C4Game::CompileFunc(), ConstructionCheck(), C4Shape::ContactCheck(), C4FoWAmbient::CreateFromLandscape(), C4Game::CreateObjectConstruction(), C4Game::Default(), C4Scenario::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(), FindConSiteSpot(), FindLevelGround(), FindLiquid(), FindLiquidHeight(), FindSolidGround(), FindSurfaceLiquid(), FindThrowingPosition(), FindTunnel(), FindTunnelHeight(), C4Sky::GetSkyFadeClr(), C4ParticleValueProvider::GetValue(), C4Shape::GetVertexOutline(), C4Weather::GetWind(), C4MassMover::Init(), C4Player::Init(), C4Game::InitInEarth(), C4Game::InitVegetation(), C4Viewport::InitZoom(), LandscapeFree(), C4Game::LoadScenarioSection(), C4MaterialMap::mrfCorrode(), C4MaterialMap::mrfIncinerate(), C4MaterialMap::mrfInsert(), mrfInsertCheck(), C4MaterialMap::mrfPoof(), PathFreeIgnoreVehiclePix(), C4Game::PlaceAnimal(), C4Game::PlaceInEarth(), 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(), C4MapCreatorS2::SetC4SLandscape(), C4Scenario::SetExactLandscape(), 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().

◆ QuickPolyBuf

CPolyEdge QuickPolyBuf[QuickPolyBufSize]

Definition at line 1210 of file C4Landscape.cpp.

Referenced by C4Landscape::P::ForPolygon().

◆ QuickPolyBufSize

const int QuickPolyBufSize = 20

Definition at line 1209 of file C4Landscape.cpp.