OpenClonk
C4Landscape Class Reference

#include <C4Landscape.h>

Classes

struct  P
 

Public Member Functions

 C4Landscape ()
 
 ~C4Landscape ()
 
void Default ()
 
void Clear (bool fClearMapCreator=true, bool fClearSky=true, bool fClearRenderer=true)
 
void Execute ()
 
void Synchronize ()
 
void Draw (C4TargetFacet &cgo, class C4FoWRegion *pLight=nullptr)
 
void ScenarioInit ()
 
void DrawMaterialRect (int32_t mat, int32_t tx, int32_t ty, int32_t wdt, int32_t hgt)
 
void RaiseTerrain (int32_t tx, int32_t ty, int32_t wdt)
 
void FindMatTop (int32_t mat, int32_t &x, int32_t &y, bool distant_first) const
 
BYTE GetMapIndex (int32_t iX, int32_t iY) const
 
BYTE GetBackMapIndex (int32_t iX, int32_t iY) const
 
bool Load (C4Group &hGroup, bool fLoadSky, bool fSavegame)
 
bool Save (C4Group &hGroup) const
 
bool SaveDiff (C4Group &hGroup, bool fSyncSave) const
 
bool SaveMap (C4Group &hGroup) const
 
bool SaveInitial ()
 
bool SaveTextures (C4Group &hGroup) const
 
bool Init (C4Group &hGroup, bool fOverloadCurrent, bool fLoadSky, bool &rfLoaded, bool fSavegame)
 
bool HasMap () const
 
bool MapToLandscape ()
 
bool ApplyDiff (C4Group &hGroup)
 
void SetMode (LandscapeMode iMode)
 
LandscapeMode GetMode () const
 
bool SetPix2 (int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
 
bool _SetPix2 (int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
 
void _SetPix2Tmp (int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
 
bool InsertMaterialOutsideLandscape (int32_t tx, int32_t ty, int32_t mdens)
 
bool InsertMaterial (int32_t mat, int32_t *tx, int32_t *ty, int32_t vx=0, int32_t vy=0, bool query_only=false)
 
bool InsertDeadMaterial (int32_t mat, int32_t tx, int32_t ty)
 
bool FindMatPath (int32_t &fx, int32_t &fy, int32_t ydir, int32_t mdens, int32_t mslide) const
 
bool FindMatSlide (int32_t &fx, int32_t &fy, int32_t ydir, int32_t mdens, int32_t mslide) const
 
bool FindMatPathPush (int32_t &fx, int32_t &fy, int32_t mdens, int32_t mslide, bool liquid) const
 
bool Incinerate (int32_t x, int32_t y, int32_t cause_player)
 
bool DrawBrush (int32_t iX, int32_t iY, int32_t iGrade, const char *szMaterial, const char *szTexture, const char *szBackMaterial, const char *szBackTexture)
 
bool DrawLine (int32_t iX1, int32_t iY1, int32_t iX2, int32_t iY2, int32_t iGrade, const char *szMaterial, const char *szTexture, const char *szBackMaterial, const char *szBackTexture)
 
bool DrawBox (int32_t iX1, int32_t iY1, int32_t iX2, int32_t iY2, int32_t iGrade, const char *szMaterial, const char *szTexture, const char *szBackMaterial, const char *szBackTexture)
 
bool DrawChunks (int32_t tx, int32_t ty, int32_t wdt, int32_t hgt, int32_t icntx, int32_t icnty, const char *szMaterial, const char *szTexture, bool bIFT)
 
bool DrawQuad (int32_t iX1, int32_t iY1, int32_t iX2, int32_t iY2, int32_t iX3, int32_t iY3, int32_t iX4, int32_t iY4, const char *szMaterial, const char *szBackMaterial, bool fDrawBridge)
 
bool DrawPolygon (int *vtcs, int length, const char *szMaterial, const char *szBackMaterial, bool fDrawBridge)
 
CStdPaletteGetPal () const
 
int32_t GetWidth () const
 
int32_t GetHeight () const
 
int32_t GetMapZoom () const
 
C4Real GetGravity () const
 
void SetGravity (C4Real g)
 
BYTE _GetPix (int32_t x, int32_t y) const
 
BYTE GetPix (int32_t x, int32_t y) const
 
int32_t _GetMat (int32_t x, int32_t y) const
 
int32_t _GetDensity (int32_t x, int32_t y) const
 
int32_t _GetPlacement (int32_t x, int32_t y) const
 
int32_t GetMat (int32_t x, int32_t y) const
 
int32_t GetDensity (int32_t x, int32_t y) const
 
int32_t GetPlacement (int32_t x, int32_t y) const
 
BYTE _GetBackPix (int32_t x, int32_t y) const
 
BYTE GetBackPix (int32_t x, int32_t y) const
 
int32_t _GetBackMat (int32_t x, int32_t y) const
 
int32_t _GetBackDensity (int32_t x, int32_t y) const
 
int32_t _GetBackPlacement (int32_t x, int32_t y) const
 
int32_t GetBackMat (int32_t x, int32_t y) const
 
int32_t GetBackDensity (int32_t x, int32_t y) const
 
int32_t GetBackPlacement (int32_t x, int32_t y) const
 
bool GetLight (int32_t x, int32_t y)
 
bool _GetLight (int32_t x, int32_t y)
 
bool _FastSolidCheck (int32_t x, int32_t y) const
 
int32_t GetPixMat (BYTE byPix) const
 
int32_t GetPixDensity (BYTE byPix) const
 
bool _PathFree (int32_t x, int32_t y, int32_t x2, int32_t y2) const
 
int32_t GetMatHeight (int32_t x, int32_t y, int32_t iYDir, int32_t iMat, int32_t iMax) const
 
int32_t AreaSolidCount (int32_t x, int32_t y, int32_t wdt, int32_t hgt) const
 
int32_t ExtractMaterial (int32_t fx, int32_t fy, bool distant_first)
 
bool DrawMap (int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, const char *szMapDef, bool ignoreSky=false)
 
bool ClipRect (int32_t &rX, int32_t &rY, int32_t &rWdt, int32_t &rHgt) const
 
bool DrawDefMap (int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, const char *szMapDef, bool ignoreSky=false)
 
bool SetModulation (DWORD dwWithClr)
 
DWORD GetModulation () const
 
bool PostInitMap ()
 
bool ReplaceMapColor (BYTE iOldIndex, BYTE iNewIndex)
 
bool SetTextureIndex (const char *szMatTex, BYTE iNewIndex, bool fInsert)
 
void SetMapChanged ()
 
void HandleTexMapUpdate ()
 
void UpdatePixMaps ()
 
bool DoRelights ()
 
void RemoveUnusedTexMapEntries ()
 
class C4SkyGetSky ()
 
bool HasFoW () const
 
class C4FoWGetFoW ()
 
int32_t GetMatCount (int material) const
 
int32_t GetEffectiveMatCount (int material) const
 
int32_t DigFreeShape (int *vtcs, int length, C4Object *by_object=nullptr, bool no_dig2objects=false, bool no_instability_check=false)
 
void BlastFreeShape (int *vtcs, int length, C4Object *by_object=nullptr, int32_t by_player=NO_OWNER, int32_t iMaxDensity=C4M_Vehicle)
 
void ClearFreeRect (int32_t tx, int32_t ty, int32_t wdt, int32_t hgt)
 
int32_t DigFreeRect (int32_t tx, int32_t ty, int32_t wdt, int32_t hgt, C4Object *by_object=nullptr, bool no_dig2objects=false, bool no_instability_check=false)
 
int32_t DigFree (int32_t tx, int32_t ty, int32_t rad, C4Object *by_object=nullptr, bool no_dig2objects=false, bool no_instability_check=false)
 
void ShakeFree (int32_t tx, int32_t ty, int32_t rad)
 
void BlastFree (int32_t tx, int32_t ty, int32_t rad, int32_t caused_by=NO_OWNER, C4Object *by_object=nullptr, int32_t iMaxDensity=C4M_Vehicle)
 
void CheckInstabilityRange (int32_t tx, int32_t ty)
 
bool CheckInstability (int32_t tx, int32_t ty, int32_t recursion_count=0)
 
bool ClearPix (int32_t tx, int32_t ty)
 
void ClearPointers (C4Object *pObj)
 
void CompileFunc (StdCompiler *pComp)
 

Static Public Member Functions

static int32_t FastSolidCheckNextX (int32_t x)
 

Static Public Attributes

static const uint8_t Transparent = C4M_MaxTexIndex
 

Detailed Description

Definition at line 37 of file C4Landscape.h.

Constructor & Destructor Documentation

◆ C4Landscape()

C4Landscape::C4Landscape ( )

Definition at line 185 of file C4Landscape.cpp.

References Default().

186  : p(new P)
187 {
188  Default();
189 }
Here is the call graph for this function:

◆ ~C4Landscape()

C4Landscape::~C4Landscape ( )

Definition at line 191 of file C4Landscape.cpp.

References Clear().

192 {
193  Clear();
194 }
void Clear(bool fClearMapCreator=true, bool fClearSky=true, bool fClearRenderer=true)
Here is the call graph for this function:

Member Function Documentation

◆ _FastSolidCheck()

bool C4Landscape::_FastSolidCheck ( int32_t  x,
int32_t  y 
) const

Definition at line 3817 of file C4Landscape.cpp.

Referenced by C4FoWLightSection::Update().

3818 {
3819  return p->PixCnt[(x / 17) * p->PixCntPitch + (y / 15)] > 0;
3820 }
Here is the caller graph for this function:

◆ _GetBackDensity()

int32_t C4Landscape::_GetBackDensity ( int32_t  x,
int32_t  y 
) const

Definition at line 3782 of file C4Landscape.cpp.

References _GetBackPix().

3783 {
3784  return p->Pix2Dens[_GetBackPix(x, y)];
3785 }
BYTE _GetBackPix(int32_t x, int32_t y) const
Here is the call graph for this function:

◆ _GetBackMat()

int32_t C4Landscape::_GetBackMat ( int32_t  x,
int32_t  y 
) const

Definition at line 3777 of file C4Landscape.cpp.

References _GetBackPix().

3778 {
3779  return p->Pix2Mat[_GetBackPix(x, y)];
3780 }
BYTE _GetBackPix(int32_t x, int32_t y) const
Here is the call graph for this function:

◆ _GetBackPix()

BYTE C4Landscape::_GetBackPix ( int32_t  x,
int32_t  y 
) const

Definition at line 3746 of file C4Landscape.cpp.

References BREAKPOINT_HERE.

Referenced by _GetBackDensity(), _GetBackMat(), _GetBackPlacement(), and _GetLight().

3747 {
3748 #ifdef _DEBUG
3749  if (x < 0 || y < 0 || x >= p->Width || y >= p->Height) { BREAKPOINT_HERE; }
3750 #endif
3751  return p->Surface8Bkg->_GetPix(x, y);
3752 }
#define BREAKPOINT_HERE
Here is the caller graph for this function:

◆ _GetBackPlacement()

int32_t C4Landscape::_GetBackPlacement ( int32_t  x,
int32_t  y 
) const

Definition at line 3787 of file C4Landscape.cpp.

References _GetBackPix().

3788 {
3789  return p->Pix2Place[_GetBackPix(x, y)];
3790 }
BYTE _GetBackPix(int32_t x, int32_t y) const
Here is the call graph for this function:

◆ _GetDensity()

int32_t C4Landscape::_GetDensity ( int32_t  x,
int32_t  y 
) const

Definition at line 3721 of file C4Landscape.cpp.

References _GetPix().

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

3722 {
3723  return p->Pix2Dens[_GetPix(x, y)];
3724 }
BYTE _GetPix(int32_t x, int32_t y) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _GetLight()

bool C4Landscape::_GetLight ( int32_t  x,
int32_t  y 
)

Definition at line 3812 of file C4Landscape.cpp.

References _GetBackPix(), and _GetPix().

3813 {
3814  return _GetBackPix(x, y) == 0 || p->Pix2Light[_GetPix(x, y)];
3815 }
BYTE _GetBackPix(int32_t x, int32_t y) const
BYTE _GetPix(int32_t x, int32_t y) const
Here is the call graph for this function:

◆ _GetMat()

int32_t C4Landscape::_GetMat ( int32_t  x,
int32_t  y 
) const

Definition at line 3716 of file C4Landscape.cpp.

References _GetPix().

Referenced by C4Landscape::P::DoScan(), C4Landscape::P::ExecuteScan(), GetMatHeight(), InsertDeadMaterial(), and C4Landscape::P::UpdateMatCnt().

3717 {
3718  return p->Pix2Mat[_GetPix(x, y)];
3719 }
BYTE _GetPix(int32_t x, int32_t y) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _GetPix()

BYTE C4Landscape::_GetPix ( int32_t  x,
int32_t  y 
) const

Definition at line 3685 of file C4Landscape.cpp.

References BREAKPOINT_HERE.

Referenced by _GetDensity(), _GetLight(), _GetMat(), _GetPlacement(), _SetPix2(), C4Landscape::P::DoScan(), InsertDeadMaterial(), C4SolidMask::Put(), C4SolidMask::Remove(), SetPix2(), and C4LandscapeRenderGL::Update().

3686 {
3687 #ifdef _DEBUG
3688  if (x < 0 || y < 0 || x >= p->Width || y >= p->Height) { BREAKPOINT_HERE; }
3689 #endif
3690  return p->Surface8->_GetPix(x, y);
3691 }
#define BREAKPOINT_HERE
Here is the caller graph for this function:

◆ _GetPlacement()

int32_t C4Landscape::_GetPlacement ( int32_t  x,
int32_t  y 
) const

Definition at line 3726 of file C4Landscape.cpp.

References _GetPix().

Referenced by C4LandscapeRenderGL::Update().

3727 {
3728  return p->Pix2Place[_GetPix(x, y)];
3729 }
BYTE _GetPix(int32_t x, int32_t y) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _PathFree()

bool C4Landscape::_PathFree ( int32_t  x,
int32_t  y,
int32_t  x2,
int32_t  y2 
) const

Definition at line 3831 of file C4Landscape.cpp.

References CPolyEdge::y.

3832 {
3833  x /= 17; y /= 15; x2 /= 17; y2 /= 15;
3834  while (x != x2 && y != y2)
3835  {
3836  if (p->PixCnt[x * p->PixCntPitch + y])
3837  return false;
3838  if (x > x2) x--; else x++;
3839  if (y > y2) y--; else y++;
3840  }
3841  if (x != x2)
3842  do
3843  {
3844  if (p->PixCnt[x * p->PixCntPitch + y])
3845  return false;
3846  if (x > x2) x--; else x++;
3847  } while (x != x2);
3848  else
3849  while (y != y2)
3850  {
3851  if (p->PixCnt[x * p->PixCntPitch + y])
3852  return false;
3853  if (y > y2) y--; else y++;
3854  }
3855  return !p->PixCnt[x * p->PixCntPitch + y];
3856 }

◆ _SetPix2()

bool C4Landscape::_SetPix2 ( int32_t  x,
int32_t  y,
BYTE  fgPix,
BYTE  bgPix 
)

Definition at line 794 of file C4Landscape.cpp.

References _GetPix(), C4Rect::Add(), AddDbgRec(), C4RCSetPix::bgClr, C4LS_MaxRelights, C4RCSetPix::clr, Config, C4ConfigGeneral::DebugRec, C4Config::General, GetHeight(), GetMatHeight(), GetWidth(), C4MaterialMap::Map, MaterialMap, MatValid(), C4MaterialCore::MinHeightCount, RCT_SetPix, Transparent, C4RCSetPix::x, and C4RCSetPix::y.

Referenced by C4TextureShape::Draw(), C4SolidMask::Remove(), and SetPix2().

795 {
796  if (Config.General.DebugRec)
797  {
798  C4RCSetPix rc;
799  rc.x = x; rc.y = y; rc.clr = fgPix; rc.bgClr = fgPix;
800  AddDbgRec(RCT_SetPix, &rc, sizeof(rc));
801  }
802  assert(x >= 0 && y >= 0 && x < GetWidth() && y < GetHeight());
803  // get pixel and resolve transparency to already existing pixel
804  BYTE opix = _GetPix(x, y);
805  if (fgPix == Transparent) fgPix = opix;
806  if (bgPix == Transparent) bgPix = p->Surface8Bkg->_GetPix(x, y);
807  // check pixel
808  if (fgPix == opix && bgPix == p->Surface8Bkg->_GetPix(x, y)) return true;
809  // count pixels
810  if (p->Pix2Dens[fgPix])
811  {
812  if (!p->Pix2Dens[opix]) p->PixCnt[(y / 15) + (x / 17) * p->PixCntPitch]++;
813  }
814  else
815  {
816  if (p->Pix2Dens[opix]) p->PixCnt[(y / 15) + (x / 17) * p->PixCntPitch]--;
817  }
818  // count material
819  assert(!fgPix || MatValid(p->Pix2Mat[fgPix]));
820  int32_t omat = p->Pix2Mat[opix], nmat = p->Pix2Mat[fgPix];
821  if (opix) p->MatCount[omat]--;
822  if (fgPix) p->MatCount[nmat]++;
823  // count effective material
824  if (omat != nmat)
825  {
826  if (fgPix && ::MaterialMap.Map[nmat].MinHeightCount)
827  {
828  // Check for material above & below
829  int iMinHeight = ::MaterialMap.Map[nmat].MinHeightCount,
830  iBelow = GetMatHeight(x, y + 1, +1, nmat, iMinHeight),
831  iAbove = GetMatHeight(x, y - 1, -1, nmat, iMinHeight);
832  // Will be above treshold?
833  if (iBelow + iAbove + 1 >= iMinHeight)
834  {
835  int iChange = 1;
836  // Check for heights below threshold
837  if (iBelow < iMinHeight) iChange += iBelow;
838  if (iAbove < iMinHeight) iChange += iAbove;
839  // Change
840  p->EffectiveMatCount[nmat] += iChange;
841  }
842  }
843  if (opix && ::MaterialMap.Map[omat].MinHeightCount)
844  {
845  // Check for material above & below
846  int iMinHeight = ::MaterialMap.Map[omat].MinHeightCount,
847  iBelow = GetMatHeight(x, y + 1, +1, omat, iMinHeight),
848  iAbove = GetMatHeight(x, y - 1, -1, omat, iMinHeight);
849  // Not already below threshold?
850  if (iBelow + iAbove + 1 >= iMinHeight)
851  {
852  int iChange = 1;
853  // Check for heights that will get below threshold
854  if (iBelow < iMinHeight) iChange += iBelow;
855  if (iAbove < iMinHeight) iChange += iAbove;
856  // Change
857  p->EffectiveMatCount[omat] -= iChange;
858  }
859  }
860  }
861  // set 8bpp-surface only!
862  p->Surface8->SetPix(x, y, fgPix);
863  p->Surface8Bkg->SetPix(x, y, bgPix);
864  // note for relight
865  if (p->pLandscapeRender)
866  {
867  C4Rect CheckRect = p->pLandscapeRender->GetAffectedRect(C4Rect(x, y, 1, 1));
868  for (int32_t i = 0; i < C4LS_MaxRelights; i++)
869  if (!p->Relights[i].Wdt || p->Relights[i].Overlap(CheckRect) || i + 1 >= C4LS_MaxRelights)
870  {
871  p->Relights[i].Add(CheckRect);
872  break;
873  }
874  // Invalidate FoW
875  if (p->pFoW)
876  p->pFoW->Invalidate(CheckRect);
877  }
878  // success
879  return true;
880 }
int32_t GetMatHeight(int32_t x, int32_t y, int32_t iYDir, int32_t iMat, int32_t iMax) const
C4Config Config
Definition: C4Config.cpp:833
C4ConfigGeneral General
Definition: C4Config.h:251
const int32_t C4LS_MaxRelights
Definition: C4Landscape.h:27
C4Material * Map
Definition: C4Material.h:169
Definition: C4Rect.h:27
uint8_t BYTE
void AddDbgRec(C4RecordChunkType eType, const void *pData, int iSize)
Definition: C4Record.cpp:32
int32_t MinHeightCount
Definition: C4Material.h:130
int32_t GetHeight() const
int32_t GetWidth() const
C4MaterialMap MaterialMap
Definition: C4Material.cpp:974
BYTE bgClr
Definition: C4Record.h:126
BYTE _GetPix(int32_t x, int32_t y) const
int32_t DebugRec
Definition: C4Config.h:60
static const uint8_t Transparent
Definition: C4Landscape.h:50
bool MatValid(int32_t mat)
Definition: C4Material.h:210
BYTE clr
Definition: C4Record.h:125
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _SetPix2Tmp()

void C4Landscape::_SetPix2Tmp ( int32_t  x,
int32_t  y,
BYTE  fgPix,
BYTE  bgPix 
)

Definition at line 882 of file C4Landscape.cpp.

References GetHeight(), GetWidth(), and Transparent.

Referenced by C4SolidMask::PutTemporary(), and C4SolidMask::RemoveTemporary().

883 {
884  // set 8bpp-surface only!
885  assert(x >= 0 && y >= 0 && x < GetWidth() && y < GetHeight());
886  if (fgPix != Transparent) p->Surface8->SetPix(x, y, fgPix);
887  if (bgPix != Transparent) p->Surface8Bkg->SetPix(x, y, bgPix);
888 }
int32_t GetHeight() const
int32_t GetWidth() const
static const uint8_t Transparent
Definition: C4Landscape.h:50
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ApplyDiff()

bool C4Landscape::ApplyDiff ( C4Group hGroup)

Definition at line 1897 of file C4Landscape.cpp.

1898 {
1899  std::unique_ptr<CSurface8> pDiff, pDiffBkg;
1900  // Load diff landscape from group
1901  pDiff = GroupReadSurface8(hGroup, C4CFN_DiffLandscape);
1902  pDiffBkg = GroupReadSurface8(hGroup, C4CFN_DiffLandscapeBkg);
1903  if (pDiff == nullptr && pDiffBkg == nullptr) return false;
1904 
1905  // convert all pixels: keep if same material; re-set if different material
1906  BYTE byPix;
1907  for (int32_t y = 0; y < GetHeight(); ++y) for (int32_t x = 0; x < GetWidth(); ++x)
1908  {
1909  if (pDiff && pDiff->GetPix(x, y) != C4M_MaxTexIndex)
1910  if (p->Surface8->_GetPix(x, y) != (byPix = pDiff->_GetPix(x, y)))
1911  // material has changed here: readjust with new texture
1912  p->Surface8->SetPix(x, y, byPix);
1913  if (pDiffBkg && pDiffBkg->GetPix(x, y) != C4M_MaxTexIndex)
1914  if (p->Surface8Bkg->_GetPix(x, y) != (byPix = pDiffBkg->_GetPix(x, y)))
1915  p->Surface8Bkg->_SetPix(x, y, byPix);
1916  }
1917 
1918  // done
1919  return true;
1920 }
#define C4CFN_DiffLandscapeBkg
Definition: C4Components.h:64
uint8_t BYTE
#define C4CFN_DiffLandscape
Definition: C4Components.h:63
const int C4M_MaxTexIndex
Definition: C4Constants.h:51
int32_t GetHeight() const
int32_t GetWidth() const

◆ AreaSolidCount()

int32_t C4Landscape::AreaSolidCount ( int32_t  x,
int32_t  y,
int32_t  wdt,
int32_t  hgt 
) const

Definition at line 3322 of file C4Landscape.cpp.

References GBackSolid().

Referenced by ConstructionCheck().

3323 {
3324  int32_t cx, cy, ascnt = 0;
3325  for (cy = y; cy < y + hgt; cy++)
3326  for (cx = x; cx < x + wdt; cx++)
3327  if (GBackSolid(cx, cy))
3328  ascnt++;
3329  return ascnt;
3330 }
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:

◆ BlastFree()

void C4Landscape::BlastFree ( int32_t  tx,
int32_t  ty,
int32_t  rad,
int32_t  caused_by = NO_OWNER,
C4Object by_object = nullptr,
int32_t  iMaxDensity = C4M_Vehicle 
)

Definition at line 503 of file C4Landscape.cpp.

504 {
505  std::vector<int32_t> vertices(GetRoundPolygon(tx, ty, rad, 30));
506  BlastFreeShape(&vertices[0], vertices.size(), by_object, caused_by, iMaxDensity);
507 }
void BlastFreeShape(int *vtcs, int length, C4Object *by_object=nullptr, int32_t by_player=NO_OWNER, int32_t iMaxDensity=C4M_Vehicle)

◆ BlastFreeShape()

void C4Landscape::BlastFreeShape ( int *  vtcs,
int  length,
C4Object by_object = nullptr,
int32_t  by_player = NO_OWNER,
int32_t  iMaxDensity = C4M_Vehicle 
)

Definition at line 593 of file C4Landscape.cpp.

594 {
595  C4MaterialList *MaterialContents = nullptr;
596 
597  C4Rect BoundingBox = getBoundingBox(vtcs, length);
598 
599  // Remember any collectible objects in area
600  std::unique_ptr<C4ValueArray> dig_objects(p->PrepareFreeShape(BoundingBox, by_object));
601 
602  uint8_t *pblast_tbl = nullptr, blast_tbl[C4M_MaxTexIndex];
603  if (iMaxDensity < C4M_Vehicle)
604  {
605  for (int32_t i = 0; i < C4M_MaxTexIndex; ++i) blast_tbl[i] = (GetPixDensity(i) <= iMaxDensity);
606  pblast_tbl = blast_tbl;
607  }
608 
609  if (by_object)
610  {
611  if (!by_object->MaterialContents)
612  by_object->MaterialContents = new C4MaterialList;
613  p->ForPolygon(this, vtcs, length / 2, [this](int32_t x, int32_t y) { return p->BlastFreePix(this, x, y); }, by_object->MaterialContents, 0, 0, pblast_tbl);
614  }
615  else
616  {
617  MaterialContents = new C4MaterialList;
618  p->ForPolygon(this, vtcs, length / 2, [this](int32_t x, int32_t y) { return p->BlastFreePix(this, x, y); }, MaterialContents, iMaxDensity);
619  }
620 
621  // create objects from the material
622  C4MaterialList *mat_list = nullptr;
623  if (by_object)
624  mat_list = by_object->MaterialContents;
625  else
626  mat_list = MaterialContents;
627 
628  int32_t tx = BoundingBox.GetMiddleX(), ty = BoundingBox.GetMiddleY();
629  p->BlastMaterial2Objects(tx, ty, mat_list, by_player, (BoundingBox.Wdt + BoundingBox.Hgt) / 4, dig_objects.get());
630 
631  if (MaterialContents) delete MaterialContents;
632 
633  // Do callbacks to digger for objects that are now dug free
634  p->PostFreeShape(dig_objects.get(), by_object);
635 }
const int32_t C4M_Vehicle
Definition: C4Constants.h:171
int32_t GetMiddleY() const
Definition: C4Rect.h:57
int32_t GetPixDensity(BYTE byPix) const
C4MaterialList * MaterialContents
Definition: C4Object.h:154
Definition: C4Rect.h:27
int32_t Wdt
Definition: C4Rect.h:30
const int C4M_MaxTexIndex
Definition: C4Constants.h:51
int32_t GetMiddleX() const
Definition: C4Rect.h:56
int32_t Hgt
Definition: C4Rect.h:30

◆ CheckInstability()

bool C4Landscape::CheckInstability ( int32_t  tx,
int32_t  ty,
int32_t  recursion_count = 0 
)

Definition at line 890 of file C4Landscape.cpp.

References ClearPix(), C4PXSSystem::Create(), C4MassMoverSet::Create(), C4MaterialCore::Density, DensitySolid(), C4MaterialCore::DigFree, GBackSolid(), GetMat(), C4MaterialCore::Instable, itofix(), C4MaterialCore::KeepSinglePixels, C4MaterialMap::Map, MassMover, MaterialMap, MatValid(), and PXS.

Referenced by CheckInstabilityRange().

891 {
892  int32_t mat = GetMat(tx, ty);
893  if (MatValid(mat)) {
894  const C4Material &material = MaterialMap.Map[mat];
895  if (material.Instable)
896  return ::MassMover.Create(tx, ty);
897  // Get rid of single pixels
898  else if (DensitySolid(material.Density) && !material.KeepSinglePixels && recursion_count < 10)
899  if ((!::GBackSolid(tx, ty + 1)) + (!::GBackSolid(tx, ty - 1)) + (!::GBackSolid(tx + 1, ty)) + (!::GBackSolid(tx - 1, ty)) >= 3)
900  {
901  if (!ClearPix(tx, ty)) return false;
902  // Diggable material drops; other material just gets removed
903  if (material.DigFree) ::PXS.Create(mat, itofix(tx), itofix(ty));
904  // check other pixels around this
905  // Note this cannot lead to an endless recursion (unless you do funny stuff like e.g. set DigFree=1 in material Tunnel).
906  // Check recursion anyway, because very large strips of single pixel width might cause sufficient recursion to crash
907  CheckInstability(tx + 1, ty, ++recursion_count);
908  CheckInstability(tx - 1, ty, recursion_count);
909  CheckInstability(tx, ty - 1, recursion_count);
910  CheckInstability(tx, ty + 1, recursion_count);
911  return true;
912  }
913  }
914  return false;
915 }
int32_t Instable
Definition: C4Material.h:102
C4Material * Map
Definition: C4Material.h:169
bool CheckInstability(int32_t tx, int32_t ty, int32_t recursion_count=0)
bool Create(int32_t mat, C4Real ix, C4Real iy, C4Real ixdir=Fix0, C4Real iydir=Fix0)
Definition: C4PXS.cpp:175
bool Create(int32_t x, int32_t y, bool fExecute=false)
Definition: C4MassMover.cpp:70
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
C4PXSSystem PXS
Definition: C4PXS.cpp:423
int32_t GetMat(int32_t x, int32_t y) const
int32_t Density
Definition: C4Material.h:92
C4MassMoverSet MassMover
bool KeepSinglePixels
Definition: C4Material.h:132
C4MaterialMap MaterialMap
Definition: C4Material.cpp:974
bool ClearPix(int32_t tx, int32_t ty)
bool MatValid(int32_t mat)
Definition: C4Material.h:210
int32_t DigFree
Definition: C4Material.h:94
bool DensitySolid(int32_t dens)
Definition: C4Landscape.h:196
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:

◆ CheckInstabilityRange()

void C4Landscape::CheckInstabilityRange ( int32_t  tx,
int32_t  ty 
)

Definition at line 917 of file C4Landscape.cpp.

References CheckInstability().

Referenced by C4Landscape::P::BlastFreePix(), C4Landscape::P::DigFreePix(), C4Landscape::P::DoScan(), ExtractMaterial(), C4SolidMask::Remove(), and C4Landscape::P::ShakeFreePix().

918 {
919  if (!CheckInstability(tx, ty))
920  {
921  CheckInstability(tx, ty - 1);
922  CheckInstability(tx, ty - 2);
923  CheckInstability(tx - 1, ty);
924  CheckInstability(tx + 1, ty);
925  }
926 }
bool CheckInstability(int32_t tx, int32_t ty, int32_t recursion_count=0)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clear()

void C4Landscape::Clear ( bool  fClearMapCreator = true,
bool  fClearSky = true,
bool  fClearRenderer = true 
)

Definition at line 1353 of file C4Landscape.cpp.

References Undefined.

Referenced by C4Game::Clear(), and ~C4Landscape().

1354 {
1355  if (fClearMapCreator) { p->pMapCreator.reset(); }
1356  // clear sky
1357  if (fClearSky) p->Sky.Clear();
1358  // clear surfaces, if assigned
1359  if (fClearRenderer) { p->pLandscapeRender.reset(); }
1360  p->TopRowPix.clear();
1361  p->BottomRowPix.clear();
1362  p->LeftColPix.clear();
1363  p->RightColPix.clear();
1364  p->Surface8.reset();
1365  p->Surface8Bkg.reset();
1366  p->Map.reset();
1367  p->MapBkg.reset();
1368  // clear initial landscape
1369  p->pInitial.reset();
1370  p->pInitialBkg.reset();
1371  p->pFoW.reset();
1372  // clear relight array
1373  for (auto &relight : p->Relights)
1374  relight.Default();
1375  // clear scan
1376  p->ScanX = 0;
1377  p->mode = LandscapeMode::Undefined;
1378  // clear pixel count
1379  p->PixCnt.clear();
1380  p->PixCntPitch = 0;
1381  // clear bridge material conversion temp buffers
1382  for (auto &conv : p->BridgeMatConversion)
1383  conv.reset();
1384 }
Here is the caller graph for this function:

◆ ClearFreeRect()

void C4Landscape::ClearFreeRect ( int32_t  tx,
int32_t  ty,
int32_t  wdt,
int32_t  hgt 
)

Definition at line 482 of file C4Landscape.cpp.

483 {
484  std::vector<int32_t> vertices(GetRectangle(tx, ty, wdt, hgt));
485  C4Rect r(tx, ty, wdt, hgt);
486  p->PrepareChange(this, r);
487  p->ForPolygon(this, &vertices[0], vertices.size() / 2, [this](int32_t x, int32_t y) { return ClearPix(x, y); });
488  p->FinishChange(this, r);
489 }
Definition: C4Rect.h:27
bool ClearPix(int32_t tx, int32_t ty)

◆ ClearPix()

bool C4Landscape::ClearPix ( int32_t  tx,
int32_t  ty 
)

Definition at line 770 of file C4Landscape.cpp.

References SetPix2().

Referenced by C4Landscape::P::BlastFreePix(), CheckInstability(), C4Landscape::P::DigFreePix(), C4Landscape::P::DigFreePixNoInstability(), ExtractMaterial(), C4MaterialMap::mrfCorrode(), and C4Landscape::P::ShakeFreePix().

771 {
772  // Replace pixel with background pixel
773  BYTE bkgPix = p->Surface8Bkg->GetPix(tx, ty);
774  return SetPix2(tx, ty, bkgPix, bkgPix);
775 }
uint8_t BYTE
bool SetPix2(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ClearPointers()

void C4Landscape::ClearPointers ( C4Object pObj)

Definition at line 777 of file C4Landscape.cpp.

Referenced by C4Game::ClearPointers().

778 {
779  if (p->pFoW) p->pFoW->Remove(pObj);
780 }
Here is the caller graph for this function:

◆ ClipRect()

bool C4Landscape::ClipRect ( int32_t &  rX,
int32_t &  rY,
int32_t &  rWdt,
int32_t &  rHgt 
) const

Definition at line 4021 of file C4Landscape.cpp.

References GetHeight(), and GetWidth().

Referenced by DrawDefMap(), and DrawMap().

4022 {
4023  // clip by bounds
4024  if (rX < 0) { rWdt += rX; rX = 0; }
4025  if (rY < 0) { rHgt += rY; rY = 0; }
4026  int32_t iOver;
4027 
4028  iOver = rX + rWdt - GetWidth();
4029  if (iOver > 0)
4030  rWdt -= iOver;
4031 
4032  iOver = rY + rHgt - GetHeight();
4033  if (iOver > 0)
4034  rHgt -= iOver;
4035 
4036  // anything left inside the bounds?
4037  return rWdt > 0 && rHgt > 0;
4038 }
int32_t GetHeight() const
int32_t GetWidth() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CompileFunc()

void C4Landscape::CompileFunc ( StdCompiler pComp)

Definition at line 1386 of file C4Landscape.cpp.

References DefaultGravAccel, StdCompiler::isDeserializer(), mkCastIntAdapt(), mkNamingAdapt(), Undefined, and StdCompiler::Value().

1387 {
1388  pComp->Value(mkNamingAdapt(p->MapSeed, "MapSeed", 0));
1389  pComp->Value(mkNamingAdapt(mkCastIntAdapt(p->Gravity), "Gravity", DefaultGravAccel));
1390  pComp->Value(mkNamingAdapt(p->Modulation, "MatModulation", 0U));
1391  pComp->Value(mkNamingAdapt(mkCastIntAdapt(p->mode), "Mode", LandscapeMode::Undefined));
1392 
1393  if (pComp->isDeserializer())
1394  {
1395  int32_t ambient_brightness;
1396  pComp->Value(mkNamingAdapt(ambient_brightness, "AmbientBrightness", 255));
1397  if (p->pFoW) p->pFoW->Ambient.SetBrightness(ambient_brightness / static_cast<double>(255));
1398  }
1399  else
1400  {
1401  if (p->pFoW)
1402  {
1403  int32_t ambient_brightness = static_cast<int32_t>(p->pFoW->Ambient.GetBrightness() * 255 + 0.5);
1404  pComp->Value(mkNamingAdapt(ambient_brightness, "AmbientBrightness", 255));
1405  }
1406  }
1407 }
StdCastAdapt< T, int32_t > mkCastIntAdapt(T &rValue)
Definition: StdAdaptors.h:273
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
const C4Real DefaultGravAccel
Definition: C4Movement.cpp:40
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
Here is the call graph for this function:

◆ Default()

void C4Landscape::Default ( )

Definition at line 1922 of file C4Landscape.cpp.

Referenced by C4Landscape(), C4Game::Default(), and C4Scenario::Default().

1923 {
1924  p = std::make_unique<P>();
1925 }
Here is the caller graph for this function:

◆ DigFree()

int32_t C4Landscape::DigFree ( int32_t  tx,
int32_t  ty,
int32_t  rad,
C4Object by_object = nullptr,
bool  no_dig2objects = false,
bool  no_instability_check = false 
)

Definition at line 497 of file C4Landscape.cpp.

Referenced by C4Object::DoMovement().

498 {
499  std::vector<int32_t> vertices(GetRoundPolygon(tx, ty, rad, 80));
500  return DigFreeShape(&vertices[0], vertices.size(), by_object, no_dig2objects, no_instability_check);
501 }
int32_t DigFreeShape(int *vtcs, int length, C4Object *by_object=nullptr, bool no_dig2objects=false, bool no_instability_check=false)
Here is the caller graph for this function:

◆ DigFreeRect()

int32_t C4Landscape::DigFreeRect ( int32_t  tx,
int32_t  ty,
int32_t  wdt,
int32_t  hgt,
C4Object by_object = nullptr,
bool  no_dig2objects = false,
bool  no_instability_check = false 
)

Definition at line 491 of file C4Landscape.cpp.

Referenced by C4Game::CreateObjectConstruction(), and C4Object::DoMovement().

492 {
493  std::vector<int32_t> vertices(GetRectangle(tx, ty, wdt, hgt));
494  return DigFreeShape(&vertices[0], vertices.size(), by_object, no_dig2objects, no_instability_check);
495 }
int32_t DigFreeShape(int *vtcs, int length, C4Object *by_object=nullptr, bool no_dig2objects=false, bool no_instability_check=false)
Here is the caller graph for this function:

◆ DigFreeShape()

int32_t C4Landscape::DigFreeShape ( int *  vtcs,
int  length,
C4Object by_object = nullptr,
bool  no_dig2objects = false,
bool  no_instability_check = false 
)

Definition at line 550 of file C4Landscape.cpp.

551 {
552  using namespace std::placeholders;
553 
554  C4Rect BoundingBox = getBoundingBox(vtcs, length);
555  int32_t amount;
556 
557  // Remember any collectible objects in area
558  std::unique_ptr<C4ValueArray> dig_objects(p->PrepareFreeShape(BoundingBox, by_object));
559 
560  std::function<bool(int32_t, int32_t)> callback;
561  if (no_instability_check)
562  callback = [this](int32_t x, int32_t y) { return p->DigFreePixNoInstability(this, x, y); };
563  else
564  callback = [this](int32_t x, int32_t y) { return p->DigFreePix(this, x, y); };
565 
566  if (by_object)
567  {
568  if (!by_object->MaterialContents)
569  by_object->MaterialContents = new C4MaterialList;
570  amount = p->ForPolygon(this, vtcs, length / 2, callback, by_object->MaterialContents);
571  }
572  else
573  amount = p->ForPolygon(this, vtcs, length / 2, callback, nullptr);
574 
575  // create objects from the material
576  if (!::Game.iTick5)
577  {
578  if (!no_dig2objects)
579  if (by_object)
580  if (by_object->MaterialContents)
581  {
582  int32_t tx = BoundingBox.GetMiddleX(), ty = BoundingBox.GetBottom();
583  p->DigMaterial2Objects(tx, ty, by_object->MaterialContents, by_object);
584  }
585  }
586 
587  // Do callbacks to digger for objects that are now dug free
588  p->PostFreeShape(dig_objects.get(), by_object);
589 
590  return amount;
591 }
int32_t iTick5
Definition: C4Game.h:130
C4Game Game
Definition: C4Globals.cpp:52
int32_t GetBottom() const
Definition: C4Rect.h:58
C4MaterialList * MaterialContents
Definition: C4Object.h:154
Definition: C4Rect.h:27
int32_t GetMiddleX() const
Definition: C4Rect.h:56

◆ DoRelights()

bool C4Landscape::DoRelights ( )

Definition at line 386 of file C4Landscape.cpp.

References C4LS_MaxRelights, C4SolidMask::CheckConsistency(), C4SolidMask::First, C4SolidMask::Last, C4SolidMask::Next, C4SolidMask::Prev, C4SolidMask::PutTemporary(), and C4SolidMask::RemoveTemporary().

Referenced by Draw(), Execute(), and C4Game::Execute().

387 {
388  if (!p->pLandscapeRender) return true;
389  for (int32_t i = 0; i < C4LS_MaxRelights; i++)
390  {
391  if (!p->Relights[i].Wdt)
392  break;
393  // Remove all solid masks in the (twice!) extended region around the change
394  C4Rect SolidMaskRect = p->pLandscapeRender->GetAffectedRect(p->Relights[i]);
395  C4SolidMask * pSolid;
396  for (pSolid = C4SolidMask::Last; pSolid; pSolid = pSolid->Prev)
397  pSolid->RemoveTemporary(SolidMaskRect);
398  // Perform the update
399  p->pLandscapeRender->Update(p->Relights[i], this);
400  if (p->pFoW) p->pFoW->Ambient.UpdateFromLandscape(*this, p->Relights[i]);
401  // Restore Solidmasks
402  for (pSolid = C4SolidMask::First; pSolid; pSolid = pSolid->Next)
403  pSolid->PutTemporary(SolidMaskRect);
405  // Clear slot
406  p->Relights[i].Default();
407  }
408  return true;
409 }
static bool CheckConsistency()
const int32_t C4LS_MaxRelights
Definition: C4Landscape.h:27
void PutTemporary(C4Rect where)
Definition: C4Rect.h:27
void RemoveTemporary(C4Rect where)
static C4SolidMask * First
Definition: C4SolidMask.h:72
C4SolidMask * Prev
Definition: C4SolidMask.h:74
static C4SolidMask * Last
Definition: C4SolidMask.h:73
C4SolidMask * Next
Definition: C4SolidMask.h:75
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Draw()

void C4Landscape::Draw ( C4TargetFacet cgo,
class C4FoWRegion pLight = nullptr 
)

Definition at line 365 of file C4Landscape.cpp.

References C4Draw::ActivateBlitModulation(), C4Draw::Blit8Fast(), C4Draw::DeactivateBlitModulation(), DoRelights(), GraphicsSystem, C4Facet::Hgt, pDraw, C4GraphicsSystem::Show8BitSurface, C4Facet::Surface, C4TargetFacet::TargetX, C4TargetFacet::TargetY, C4Facet::Wdt, C4Facet::X, and C4Facet::Y.

Referenced by C4Viewport::Draw().

366 {
367  uint32_t clrMod = 0xffffffff;
368  if (p->Modulation)
369  {
370  pDraw->ActivateBlitModulation(p->Modulation);
371  clrMod = p->Modulation;
372  }
373  // blit landscape
374  if (::GraphicsSystem.Show8BitSurface == 1)
375  pDraw->Blit8Fast(p->Surface8.get(), cgo.TargetX, cgo.TargetY, cgo.Surface, cgo.X, cgo.Y, cgo.Wdt, cgo.Hgt);
376  else if (::GraphicsSystem.Show8BitSurface == 2)
377  pDraw->Blit8Fast(p->Surface8Bkg.get(), cgo.TargetX, cgo.TargetY, cgo.Surface, cgo.X, cgo.Y, cgo.Wdt, cgo.Hgt);
378  else if (p->pLandscapeRender)
379  {
380  DoRelights();
381  p->pLandscapeRender->Draw(cgo, pLight, clrMod);
382  }
383  if (p->Modulation) pDraw->DeactivateBlitModulation();
384 }
void Blit8Fast(CSurface8 *sfcSource, int fx, int fy, C4Surface *sfcTarget, int tx, int ty, int wdt, int hgt)
Definition: C4Draw.cpp:251
float Y
Definition: C4Facet.h:118
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
C4Draw * pDraw
Definition: C4Draw.cpp:42
float TargetX
Definition: C4Facet.h:165
float Hgt
Definition: C4Facet.h:118
void DeactivateBlitModulation()
Definition: C4Draw.h:189
bool DoRelights()
void ActivateBlitModulation(DWORD dwWithClr)
Definition: C4Draw.h:188
C4Surface * Surface
Definition: C4Facet.h:117
float TargetY
Definition: C4Facet.h:165
float Wdt
Definition: C4Facet.h:118
float X
Definition: C4Facet.h:118
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawBox()

bool C4Landscape::DrawBox ( int32_t  iX1,
int32_t  iY1,
int32_t  iX2,
int32_t  iY2,
int32_t  iGrade,
const char *  szMaterial,
const char *  szTexture,
const char *  szBackMaterial,
const char *  szBackTexture 
)

Definition at line 3539 of file C4Landscape.cpp.

References Dynamic, Exact, C4Texture::GetMaterialShape(), C4TextureShape::GetMaxPolyHeight(), C4TextureShape::GetMaxPolyWidth(), C4TextureMap::GetTexture(), SetMapChanged(), Static, TextureMap, and Undefined.

Referenced by C4ControlEMDrawTool::C4ControlEMDrawTool().

3540 {
3541  // get upper-left/lower-right - corners
3542  int32_t iX0 = std::min(iX1, iX2); int32_t iY0 = std::min(iY1, iY2);
3543  iX2 = std::max(iX1, iX2); iY2 = std::max(iY1, iY2); iX1 = iX0; iY1 = iY0;
3544  BYTE byCol, byColBkg;
3545  // Get map color index by material-texture
3546  if (!p->GetMapColorIndex(szMaterial, szTexture, byCol)) return false;
3547  if (!p->GetMapColorIndex(szBackMaterial, szBackTexture, byColBkg)) return false;
3548  // Get material shape size
3549  C4Texture *texture = ::TextureMap.GetTexture(szTexture);
3550  int32_t shape_wdt = 0, shape_hgt = 0;
3551  if (texture && texture->GetMaterialShape())
3552  {
3553  shape_wdt = texture->GetMaterialShape()->GetMaxPolyWidth() / p->MapZoom;
3554  shape_hgt = texture->GetMaterialShape()->GetMaxPolyHeight() / p->MapZoom;
3555  }
3556  // Draw
3557  switch (p->mode)
3558  {
3559  // Dynamic: ignore
3561  break;
3562  // Static: draw to map by material-texture-index, chunk-o-zoom to landscape
3563  case LandscapeMode::Static:
3564  // Draw to map
3565  iX1 /= p->MapZoom; iY1 /= p->MapZoom; iX2 /= p->MapZoom; iY2 /= p->MapZoom;
3566  p->Map->Box(iX1, iY1, iX2, iY2, byCol);
3567  p->MapBkg->Box(iX1, iY1, iX2, iY2, byColBkg);
3568  // Update landscape
3569  p->MapToLandscape(this, *p->Map, *p->MapBkg, iX1 - 1 - shape_wdt, iY1 - 1 - shape_hgt, iX2 - iX1 + 3 + shape_wdt * 2, iY2 - iY1 + 3 + shape_hgt * 2);
3570  SetMapChanged();
3571  break;
3572  // Exact: draw directly to landscape by color & pattern
3573  case LandscapeMode::Exact:
3574  {
3575  C4Rect BoundingBox(iX1, iY1, iX2 - iX1 + 1, iY2 - iY1 + 1);
3576  // Draw to landscape
3577  p->PrepareChange(this, BoundingBox);
3578  p->Surface8->Box(iX1, iY1, iX2, iY2, byCol);
3579  p->Surface8Bkg->Box(iX1, iY1, iX2, iY2, byColBkg);
3580  p->FinishChange(this, BoundingBox);
3581  break;
3582  }
3583  case LandscapeMode::Undefined: assert(false); break;
3584  }
3585  return true;
3586 }
class C4TextureShape * GetMaterialShape() const
Definition: C4Texture.h:40
Definition: C4Rect.h:27
uint8_t BYTE
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
int32_t GetMaxPolyHeight() const
int32_t GetMaxPolyWidth() const
const char * GetTexture(int32_t iIndex)
Definition: C4Texture.cpp:494
void SetMapChanged()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawBrush()

bool C4Landscape::DrawBrush ( int32_t  iX,
int32_t  iY,
int32_t  iGrade,
const char *  szMaterial,
const char *  szTexture,
const char *  szBackMaterial,
const char *  szBackTexture 
)

Definition at line 3409 of file C4Landscape.cpp.

References Dynamic, Exact, C4Texture::GetMaterialShape(), C4TextureShape::GetMaxPolyHeight(), C4TextureShape::GetMaxPolyWidth(), C4TextureMap::GetTexture(), SetMapChanged(), Static, TextureMap, and Undefined.

Referenced by C4ControlEMDrawTool::C4ControlEMDrawTool().

3410 {
3411  BYTE byCol, byColBkg;
3412  // Get map color index by material-texture
3413  if (!p->GetMapColorIndex(szMaterial, szTexture, byCol)) return false;
3414  if (!p->GetMapColorIndex(szBackMaterial, szBackTexture, byColBkg)) return false;
3415  // Get material shape size
3416  C4Texture *texture = ::TextureMap.GetTexture(szTexture);
3417  int32_t shape_wdt = 0, shape_hgt = 0;
3418  if (texture && texture->GetMaterialShape())
3419  {
3420  shape_wdt = texture->GetMaterialShape()->GetMaxPolyWidth() / p->MapZoom;
3421  shape_hgt = texture->GetMaterialShape()->GetMaxPolyHeight() / p->MapZoom;
3422  }
3423  // Draw
3424  switch (p->mode)
3425  {
3426  // Dynamic: ignore
3428  break;
3429  // Static: draw to map by material-texture-index, chunk-o-zoom to landscape
3430  case LandscapeMode::Static:
3431  {
3432  // Draw to map
3433  int32_t iRadius = std::max<int32_t>(2 * iGrade / p->MapZoom, 1);
3434  if (iRadius == 1)
3435  {
3436  p->Map->SetPix(iX / p->MapZoom, iY / p->MapZoom, byCol);
3437  p->MapBkg->SetPix(iX / p->MapZoom, iY / p->MapZoom, byColBkg);
3438  }
3439  else
3440  {
3441  p->Map->Circle(iX / p->MapZoom, iY / p->MapZoom, iRadius, byCol);
3442  p->MapBkg->Circle(iX / p->MapZoom, iY / p->MapZoom, iRadius, byColBkg);
3443  }
3444  // Update landscape
3445  p->MapToLandscape(this, *p->Map, *p->MapBkg, iX / p->MapZoom - iRadius - 1 - shape_wdt, iY / p->MapZoom - iRadius - 1 - shape_hgt, 2 * iRadius + 2 + shape_wdt * 2, 2 * iRadius + 2 + shape_hgt * 2);
3446  SetMapChanged();
3447  }
3448  break;
3449  // Exact: draw directly to landscape by color & pattern
3450  case LandscapeMode::Exact:
3451  {
3452  C4Rect BoundingBox(iX - iGrade - 1, iY - iGrade - 1, iGrade * 2 + 2, iGrade * 2 + 2);
3453  // Draw to landscape
3454  p->PrepareChange(this, BoundingBox);
3455  p->Surface8->Circle(iX, iY, iGrade, byCol);
3456  p->Surface8Bkg->Circle(iX, iY, iGrade, byColBkg);
3457  p->FinishChange(this, BoundingBox);
3458  break;
3459  }
3460  case LandscapeMode::Undefined: assert(false); break;
3461  }
3462  return true;
3463 }
class C4TextureShape * GetMaterialShape() const
Definition: C4Texture.h:40
Definition: C4Rect.h:27
uint8_t BYTE
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
int32_t GetMaxPolyHeight() const
int32_t GetMaxPolyWidth() const
const char * GetTexture(int32_t iIndex)
Definition: C4Texture.cpp:494
void SetMapChanged()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawChunks()

bool C4Landscape::DrawChunks ( int32_t  tx,
int32_t  ty,
int32_t  wdt,
int32_t  hgt,
int32_t  icntx,
int32_t  icnty,
const char *  szMaterial,
const char *  szTexture,
bool  bIFT 
)

Definition at line 3588 of file C4Landscape.cpp.

References C4M_Flat, C4Game::C4S, C4SLandscape::FlatChunkShapes, Game, C4MaterialMap::Get(), C4Rect::Hgt, C4Scenario::Landscape, C4MaterialMap::Map, C4MaterialCore::MapChunkType, MaterialMap, MatValid(), C4Draw::NoPrimaryClipper(), pDraw, Random(), C4Rect::Wdt, C4Rect::x, CPolyEdge::x, C4Rect::y, and CPolyEdge::y.

3589 {
3590  BYTE byColor;
3591  if (!p->GetMapColorIndex(szMaterial, szTexture, byColor)) return false;
3592 
3593  int32_t iMaterial = ::MaterialMap.Get(szMaterial);
3594  if (!MatValid(iMaterial))
3595  return false;
3596 
3598 
3599  C4Rect BoundingBox(tx - 5, ty - 5, wdt + 10, hgt + 10);
3600  p->PrepareChange(this, BoundingBox);
3601 
3602  // assign clipper
3603  p->Surface8->Clip(BoundingBox.x, BoundingBox.y, BoundingBox.x + BoundingBox.Wdt, BoundingBox.y + BoundingBox.Hgt);
3604  p->Surface8Bkg->Clip(BoundingBox.x, BoundingBox.y, BoundingBox.x + BoundingBox.Wdt, BoundingBox.y + BoundingBox.Hgt);
3606 
3607  // draw all chunks
3608  int32_t x, y;
3609  for (x = 0; x < icntx; x++)
3610  for (y = 0; y < icnty; y++)
3611  p->DrawChunk(this, tx + wdt*x / icntx, ty + hgt*y / icnty, wdt / icntx, hgt / icnty, byColor, bIFT ? p->DefaultBkgMat(byColor) : 0, shape, Random(1000));
3612 
3613  // remove clipper
3614  p->Surface8->NoClip();
3615  p->Surface8Bkg->NoClip();
3616 
3617  p->FinishChange(this, BoundingBox);
3618 
3619  // success
3620  return true;
3621 }
uint32_t Random()
Definition: C4Random.cpp:43
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
C4SLandscape Landscape
Definition: C4Scenario.h:236
C4Material * Map
Definition: C4Material.h:169
C4MaterialCoreShape
Definition: C4Material.h:71
Definition: C4Rect.h:27
uint8_t BYTE
C4Draw * pDraw
Definition: C4Draw.cpp:42
bool FlatChunkShapes
Definition: C4Scenario.h:188
int32_t Get(const char *szMaterial)
Definition: C4Material.cpp:365
C4MaterialCoreShape MapChunkType
Definition: C4Material.h:91
C4MaterialMap MaterialMap
Definition: C4Material.cpp:974
bool NoPrimaryClipper()
Definition: C4Draw.cpp:237
bool MatValid(int32_t mat)
Definition: C4Material.h:210
Here is the call graph for this function:

◆ DrawDefMap()

bool C4Landscape::DrawDefMap ( int32_t  iX,
int32_t  iY,
int32_t  iWdt,
int32_t  iHgt,
const char *  szMapDef,
bool  ignoreSky = false 
)

Definition at line 3983 of file C4Landscape.cpp.

References ClipRect(), and C4MCMap::SetSize().

3984 {
3985  // safety
3986  if (!szMapDef || !p->pMapCreator) return false;
3987  // clip to landscape size
3988  if (!ClipRect(iX, iY, iWdt, iHgt)) return false;
3989  // get needed map size
3990  int32_t iMapWdt = (iWdt - 1) / p->MapZoom + 1;
3991  int32_t iMapHgt = (iHgt - 1) / p->MapZoom + 1;
3992  bool fSuccess = false;
3993  // render map
3994  C4MCMap *pMap = p->pMapCreator->GetMap(szMapDef);
3995  if (!pMap) return false;
3996  pMap->SetSize(iMapWdt, iMapHgt);
3997  CSurface8* sfcMap = nullptr;
3998  CSurface8* sfcMapBkg = nullptr;
3999  if (p->pMapCreator->Render(szMapDef, sfcMap, sfcMapBkg))
4000  {
4001  // map to landscape
4002  fSuccess = p->MapToLandscape(this, *sfcMap, *sfcMapBkg, 0, 0, iMapWdt, iMapHgt, iX, iY, ignoreSky);
4003  // cleanup
4004  delete sfcMap;
4005  delete sfcMapBkg;
4006  }
4007  // done
4008  return fSuccess;
4009 }
bool ClipRect(int32_t &rX, int32_t &rY, int32_t &rWdt, int32_t &rHgt) const
void SetSize(int32_t iWdt, int32_t iHgt)
Here is the call graph for this function:

◆ DrawLine()

bool C4Landscape::DrawLine ( int32_t  iX1,
int32_t  iY1,
int32_t  iX2,
int32_t  iY2,
int32_t  iGrade,
const char *  szMaterial,
const char *  szTexture,
const char *  szBackMaterial,
const char *  szBackTexture 
)

Definition at line 3486 of file C4Landscape.cpp.

References Abs(), C4Rect::Add(), Dynamic, Exact, C4Texture::GetMaterialShape(), C4TextureShape::GetMaxPolyHeight(), C4TextureShape::GetMaxPolyWidth(), C4TextureMap::GetTexture(), SetMapChanged(), Static, TextureMap, and Undefined.

Referenced by C4ControlEMDrawTool::C4ControlEMDrawTool().

3487 {
3488  // Get map color index by material-texture
3489  uint8_t line_color, line_color_bkg;
3490  if (!p->GetMapColorIndex(szMaterial, szTexture, line_color)) return false;
3491  if (!p->GetMapColorIndex(szBackMaterial, szBackTexture, line_color_bkg)) return false;
3492  // Get material shape size
3493  C4Texture *texture = ::TextureMap.GetTexture(szTexture);
3494  int32_t shape_wdt = 0, shape_hgt = 0;
3495  if (texture && texture->GetMaterialShape())
3496  {
3497  shape_wdt = texture->GetMaterialShape()->GetMaxPolyWidth() / p->MapZoom;
3498  shape_hgt = texture->GetMaterialShape()->GetMaxPolyHeight() / p->MapZoom;
3499  }
3500  // Draw
3501  switch (p->mode)
3502  {
3503  // Dynamic: ignore
3505  break;
3506  // Static: draw to map by material-texture-index, chunk-o-zoom to landscape
3507  case LandscapeMode::Static:
3508  {
3509  // Draw to map
3510  int32_t iRadius = std::max<int32_t>(2 * iGrade / p->MapZoom, 1);
3511  iX1 /= p->MapZoom; iY1 /= p->MapZoom; iX2 /= p->MapZoom; iY2 /= p->MapZoom;
3512  ForLine(iX1, iY1, iX2, iY2, [this, line_color, line_color_bkg, iRadius](int32_t x, int32_t y) { return p->DrawLineMap(x, y, iRadius, line_color, line_color_bkg); });
3513  // Update landscape
3514  int iUpX = std::min(iX1, iX2) - iRadius - 1;
3515  int iUpY = std::min(iY1, iY2) - iRadius - 1;
3516  int iUpWdt = Abs(iX2 - iX1) + 2 * iRadius + 2;
3517  int iUpHgt = Abs(iY2 - iY1) + 2 * iRadius + 2;
3518  p->MapToLandscape(this, *p->Map, *p->MapBkg, iUpX - shape_wdt, iUpY - shape_hgt, iUpWdt + shape_wdt * 2, iUpHgt + shape_hgt * 2);
3519  SetMapChanged();
3520  }
3521  break;
3522  // Exact: draw directly to landscape by color & pattern
3523  case LandscapeMode::Exact:
3524  {
3525  // Set texture pattern & get material color
3526  C4Rect BoundingBox(iX1 - iGrade, iY1 - iGrade, iGrade * 2 + 1, iGrade * 2 + 1);
3527  BoundingBox.Add(C4Rect(iX2 - iGrade, iY2 - iGrade, iGrade * 2 + 1, iGrade * 2 + 1));
3528  // Draw to landscape
3529  p->PrepareChange(this, BoundingBox);
3530  ForLine(iX1, iY1, iX2, iY2, [this, line_color, line_color_bkg, iGrade](int32_t x, int32_t y) { return p->DrawLineLandscape(x, y, iGrade, line_color, line_color_bkg); });
3531  p->FinishChange(this, BoundingBox);
3532  break;
3533  }
3534  case LandscapeMode::Undefined: assert(false); break;
3535  }
3536  return true;
3537 }
class C4TextureShape * GetMaterialShape() const
Definition: C4Texture.h:40
Definition: C4Rect.h:27
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
int32_t GetMaxPolyHeight() const
int32_t GetMaxPolyWidth() const
const char * GetTexture(int32_t iIndex)
Definition: C4Texture.cpp:494
T Abs(T val)
Definition: Standard.h:42
void SetMapChanged()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawMap()

bool C4Landscape::DrawMap ( int32_t  iX,
int32_t  iY,
int32_t  iWdt,
int32_t  iHgt,
const char *  szMapDef,
bool  ignoreSky = false 
)

Definition at line 3953 of file C4Landscape.cpp.

References C4Game::C4S, ClipRect(), Game, C4Scenario::Landscape, C4SLandscape::MapHgt, C4SLandscape::MapWdt, MaterialMap, C4MapCreatorS2::ReadScript(), C4MapCreatorS2::Render(), C4SVal::Set(), C4Game::StartupPlayerCount, and TextureMap.

3954 {
3955  // safety
3956  if (!szMapDef) return false;
3957  // clip to landscape size
3958  if (!ClipRect(iX, iY, iWdt, iHgt)) return false;
3959  // get needed map size
3960  int32_t iMapWdt = (iWdt - 1) / p->MapZoom + 1;
3961  int32_t iMapHgt = (iHgt - 1) / p->MapZoom + 1;
3962  C4SLandscape FakeLS = Game.C4S.Landscape;
3963  FakeLS.MapWdt.Set(iMapWdt, 0, iMapWdt, iMapWdt);
3964  FakeLS.MapHgt.Set(iMapHgt, 0, iMapHgt, iMapHgt);
3965  // create map creator
3966  C4MapCreatorS2 MapCreator(&FakeLS, &::TextureMap, &::MaterialMap, Game.StartupPlayerCount);
3967  // read file
3968  MapCreator.ReadScript(szMapDef);
3969  // render map
3970  CSurface8* sfcMap = nullptr;
3971  CSurface8* sfcMapBkg = nullptr;
3972  if (!MapCreator.Render(nullptr, sfcMap, sfcMapBkg))
3973  return false;
3974  // map it to the landscape
3975  bool fSuccess = p->MapToLandscape(this, *sfcMap, *sfcMapBkg, 0, 0, iMapWdt, iMapHgt, iX, iY, ignoreSky);
3976  // cleanup
3977  delete sfcMap;
3978  delete sfcMapBkg;
3979  // return whether successful
3980  return fSuccess;
3981 }
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
C4SLandscape Landscape
Definition: C4Scenario.h:236
void Set(int32_t std=0, int32_t rnd=0, int32_t min=0, int32_t max=100)
Definition: C4Scenario.cpp:36
C4SVal MapWdt
Definition: C4Scenario.h:178
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
bool ClipRect(int32_t &rX, int32_t &rY, int32_t &rWdt, int32_t &rHgt) const
int32_t StartupPlayerCount
Definition: C4Game.h:109
C4SVal MapHgt
Definition: C4Scenario.h:178
C4MaterialMap MaterialMap
Definition: C4Material.cpp:974
Here is the call graph for this function:

◆ DrawMaterialRect()

void C4Landscape::DrawMaterialRect ( int32_t  mat,
int32_t  tx,
int32_t  ty,
int32_t  wdt,
int32_t  hgt 
)

Definition at line 927 of file C4Landscape.cpp.

References GetDensity(), Mat2PixColDefault(), MatDensity(), and SetPix2().

Referenced by DoBridge().

928 {
929  int32_t cx, cy;
930  for (cy = ty; cy < ty + hgt; cy++)
931  for (cx = tx; cx < tx + wdt; cx++)
932  if ((MatDensity(mat) >= GetDensity(cx, cy)))
933  SetPix2(cx, cy, Mat2PixColDefault(mat), p->Surface8Bkg->GetPix(cx, cy));
934 }
int32_t GetDensity(int32_t x, int32_t y) const
int32_t MatDensity(int32_t mat)
Definition: C4Material.h:240
bool SetPix2(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
BYTE Mat2PixColDefault(int32_t mat)
Definition: C4Material.h:235
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawPolygon()

bool C4Landscape::DrawPolygon ( int *  vtcs,
int  length,
const char *  szMaterial,
const char *  szBackMaterial,
bool  fDrawBridge 
)

Definition at line 3623 of file C4Landscape.cpp.

References C4TextureMap::GetIndexMatTex(), MatTex2PixCol(), TextureMap, and Transparent.

Referenced by DrawQuad().

3624 {
3625  if (length < 6) return false;
3626  if (length % 2 == 1) return false;
3627  // get texture
3628  int32_t iMatTex = ::TextureMap.GetIndexMatTex(szMaterial);
3629  if (!iMatTex) return false;
3630  uint8_t mcol = MatTex2PixCol(iMatTex);
3631  // get background texture
3632  uint8_t mcolBkg = 0;
3633  if (szBackMaterial != nullptr)
3634  {
3635  const int32_t iBackMatTex = ::TextureMap.GetIndexMatTex(szBackMaterial);
3636  if (!iBackMatTex) return false;
3637  mcolBkg = MatTex2PixCol(iBackMatTex);
3638  }
3639  // do bridging?
3640  uint8_t *conversion_map = nullptr;
3641  if (fDrawBridge)
3642  {
3643  conversion_map = p->GetBridgeMatConversion(this, MatTex2PixCol(iMatTex));
3644  mcolBkg = Transparent;
3645  }
3646  // prepare pixel count update
3647  C4Rect BoundingBox = getBoundingBox(vtcs, length);
3648  // draw polygon
3649  p->PrepareChange(this, BoundingBox);
3650  p->ForPolygon(this, vtcs, length / 2, nullptr, nullptr, mcol, mcolBkg, conversion_map);
3651  p->FinishChange(this, BoundingBox);
3652  return true;
3653 }
Definition: C4Rect.h:27
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
BYTE MatTex2PixCol(int32_t tex)
Definition: C4Material.h:230
int32_t GetIndexMatTex(const char *szMaterialTexture, const char *szDefaultTexture=nullptr, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr)
Definition: C4Texture.cpp:441
static const uint8_t Transparent
Definition: C4Landscape.h:50
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawQuad()

bool C4Landscape::DrawQuad ( int32_t  iX1,
int32_t  iY1,
int32_t  iX2,
int32_t  iY2,
int32_t  iX3,
int32_t  iY3,
int32_t  iX4,
int32_t  iY4,
const char *  szMaterial,
const char *  szBackMaterial,
bool  fDrawBridge 
)

Definition at line 3885 of file C4Landscape.cpp.

References DrawPolygon().

3886 {
3887  // set vertices
3888  int32_t vtcs[8];
3889  vtcs[0] = iX1; vtcs[1] = iY1;
3890  vtcs[2] = iX2; vtcs[3] = iY2;
3891  vtcs[4] = iX3; vtcs[5] = iY3;
3892  vtcs[6] = iX4; vtcs[7] = iY4;
3893  return DrawPolygon(vtcs, 8, szMaterial, szBackMaterial, fDrawBridge);
3894 }
bool DrawPolygon(int *vtcs, int length, const char *szMaterial, const char *szBackMaterial, bool fDrawBridge)
Here is the call graph for this function:

◆ Execute()

void C4Landscape::Execute ( )

Definition at line 200 of file C4Landscape.cpp.

References DoRelights(), Game, and C4Game::iTick35.

Referenced by C4Game::Execute().

201 {
202  // Landscape scan
203  if (!p->NoScan)
204  p->ExecuteScan(this);
205  // move sky
206  p->Sky.Execute();
207 
208  // Queued Relights -- note that normally we process them before drawing every frame;
209  // this just makes sure relights don't accumulate over a long period of time if no
210  // viewport is open (developer mode).
211  if (!::Game.iTick35)
212  DoRelights();
213 }
C4Game Game
Definition: C4Globals.cpp:52
int32_t iTick35
Definition: C4Game.h:130
bool DoRelights()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExtractMaterial()

int32_t C4Landscape::ExtractMaterial ( int32_t  fx,
int32_t  fy,
bool  distant_first 
)

Definition at line 953 of file C4Landscape.cpp.

References CheckInstabilityRange(), ClearPix(), FindMatTop(), GetMat(), and MNone.

Referenced by C4MassMover::Execute(), and C4MaterialMap::mrfPoof().

954 {
955  int32_t mat = GetMat(fx, fy);
956  if (mat == MNone) return MNone;
957  FindMatTop(mat, fx, fy, distant_first);
958  ClearPix(fx, fy);
959  CheckInstabilityRange(fx, fy);
960  return mat;
961 }
const int32_t MNone
Definition: C4Constants.h:177
void CheckInstabilityRange(int32_t tx, int32_t ty)
int32_t GetMat(int32_t x, int32_t y) const
bool ClearPix(int32_t tx, int32_t ty)
void FindMatTop(int32_t mat, int32_t &x, int32_t &y, bool distant_first) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FastSolidCheckNextX()

int32_t C4Landscape::FastSolidCheckNextX ( int32_t  x)
static

Definition at line 3822 of file C4Landscape.cpp.

Referenced by C4FoWLightSection::Update().

3823 {
3824  return (x / 17) * 17 + 17;
3825 }
Here is the caller graph for this function:

◆ FindMatPath()

bool C4Landscape::FindMatPath ( int32_t &  fx,
int32_t &  fy,
int32_t  ydir,
int32_t  mdens,
int32_t  mslide 
) const

Definition at line 3105 of file C4Landscape.cpp.

References C4M_Solid, and GetDensity().

Referenced by C4MassMover::Execute().

3106 {
3107  assert(mdens <= C4M_Solid); // mdens normalized in InsertMaterial
3108 
3109  int32_t cslide;
3110  bool fLeft = true, fRight = true;
3111 
3112  // One downwards
3113  if (GetDensity(fx, fy + ydir) < mdens) { fy += ydir; return true; }
3114 
3115  // Find downwards slide path
3116  for (cslide = 1; (cslide <= mslide) && (fLeft || fRight); cslide++)
3117  {
3118  // Check left
3119  if (fLeft)
3120  {
3121  if (GetDensity(fx - cslide, fy) >= mdens) // Left clogged
3122  fLeft = false;
3123  else if (GetDensity(fx - cslide, fy + ydir) < mdens) // Left slide okay
3124  {
3125  fx--; return true;
3126  }
3127  }
3128  // Check right
3129  if (fRight)
3130  {
3131  if (GetDensity(fx + cslide, fy) >= mdens) // Right clogged
3132  fRight = false;
3133  else if (GetDensity(fx + cslide, fy + ydir) < mdens) // Right slide okay
3134  {
3135  fx++; return true;
3136  }
3137  }
3138  }
3139 
3140  return false;
3141 }
int32_t GetDensity(int32_t x, int32_t y) const
const int32_t C4M_Solid
Definition: C4Constants.h:172
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindMatPathPush()

bool C4Landscape::FindMatPathPush ( int32_t &  fx,
int32_t &  fy,
int32_t  mdens,
int32_t  mslide,
bool  liquid 
) const

Definition at line 3184 of file C4Landscape.cpp.

References Abs(), C4ScriptGuiWindowPropertyName::bottom, GetDensity(), GetHeight(), GetWidth(), C4ScriptGuiWindowPropertyName::left, C4ScriptGuiWindowPropertyName::right, C4ScriptGuiWindowPropertyName::top, CPolyEdge::x, and CPolyEdge::y.

Referenced by InsertMaterial().

3185 {
3186  // Startpoint must be inside landscape
3187  fx = Clamp<int32_t>(fx, 0, GetWidth() - 1);
3188  fy = Clamp<int32_t>(fy, 0, GetHeight() - 1);
3189  // Range to search, calculate bounds
3190  const int32_t iPushRange = 500;
3191  int32_t left = std::max<int32_t>(0, fx - iPushRange), right = std::min<int32_t>(GetWidth() - 1, fx + iPushRange),
3192  top = std::max<int32_t>(0, fy - iPushRange), bottom = std::min<int32_t>(GetHeight() - 1, fy + iPushRange);
3193  // Direction constants
3194  const int8_t R = 0, D = 1, L = 2, U = 3;
3195  int8_t dir = 0;
3196  int32_t x = fx, y = fy;
3197  // Get startpoint density
3198  int32_t dens = GetDensity(fx, fy);
3199  // Smaller density? We're done.
3200  if (dens < mdens)
3201  return true;
3202  // Right density?
3203  else if (dens == mdens)
3204  {
3205  // Find start point for border search
3206  for (int32_t i = 0; ; i++)
3207  if (x - i - 1 < left || GetDensity(x - i - 1, y) != mdens)
3208  {
3209  x -= i; dir = L; break;
3210  }
3211  else if (y - i - 1 < top || GetDensity(x, y - i - 1) != mdens)
3212  {
3213  y -= i; dir = U; break;
3214  }
3215  else if (x + i + 1 > right || GetDensity(x + i + 1, y) != mdens)
3216  {
3217  x += i; dir = R; break;
3218  }
3219  else if (y + i + 1 > bottom || GetDensity(x, y + i + 1) != mdens)
3220  {
3221  y += i; dir = D; break;
3222  }
3223  }
3224  // Greater density
3225  else
3226  {
3227  // Try to find a way out
3228  int i = 1;
3229  for (; i < iPushRange; i++)
3230  if (GetDensity(x - i, y) <= mdens)
3231  {
3232  x -= i; dir = R; break;
3233  }
3234  else if (GetDensity(x, y - i) <= mdens)
3235  {
3236  y -= i; dir = D; break;
3237  }
3238  else if (GetDensity(x + i, y) <= mdens)
3239  {
3240  x += i; dir = L; break;
3241  }
3242  else if (GetDensity(x, y + i) <= mdens)
3243  {
3244  y += i; dir = U; break;
3245  }
3246  // Not found?
3247  if (i >= iPushRange) return false;
3248  // Done?
3249  if (GetDensity(x, y) < mdens)
3250  {
3251  fx = x; fy = y;
3252  return true;
3253  }
3254  }
3255  // Save startpoint of search
3256  int32_t sx = x, sy = y, sdir = dir;
3257  // Best point so far
3258  bool fGotBest = false; int32_t bx = 0, by = 0, bdist = 0;
3259  // Start searching
3260  do
3261  {
3262  // We should always be in a material of same density
3263  assert(x >= left && y >= top && x <= right && y <= bottom && GetDensity(x, y) == mdens);
3264  // Calc new position
3265  int nx = x, ny = y;
3266  switch (dir)
3267  {
3268  case R: nx++; break;
3269  case D: ny++; break;
3270  case L: nx--; break;
3271  case U: ny--; break;
3272  default: assert(false);
3273  }
3274  // In bounds?
3275  bool fInBounds = (nx >= left && ny >= top && nx <= right && ny <= bottom);
3276  // Get density. Not this performs an SideOpen-check if outside landscape bounds.
3277  int32_t dens = GetDensity(nx, ny);
3278  // Flow possible?
3279  if (dens < mdens)
3280  {
3281  // Calculate "distance".
3282  int32_t dist = Abs(nx - fx) + mslide * (liquid ? fy - ny : Abs(fy - ny));
3283  // New best point?
3284  if (!fGotBest || dist < bdist)
3285  {
3286  // Save it
3287  bx = nx; by = ny; bdist = dist; fGotBest = true;
3288  // Adjust borders: We can obviously safely ignore anything at greater distance
3289  top = std::max<int32_t>(top, fy - dist / mslide - 1);
3290  if (!liquid)
3291  {
3292  bottom = std::min<int32_t>(bottom, fy + dist / mslide + 1);
3293  left = std::max<int32_t>(left, fx - dist - 1);
3294  right = std::min<int32_t>(right, fx + dist + 1);
3295  }
3296  // Set new startpoint
3297  sx = x; sy = y; sdir = dir;
3298  }
3299  }
3300  // Step?
3301  if (fInBounds && dens == mdens)
3302  {
3303  // New point
3304  x = nx; y = ny;
3305  // Turn left
3306  (dir += 3) %= 4;
3307  }
3308  // Otherwise: Turn right
3309  else
3310  {
3311  ++dir;
3312  dir %= 4;
3313  }
3314  } while (x != sx || y != sy || dir != sdir);
3315  // Nothing found?
3316  if (!fGotBest) return false;
3317  // Return it
3318  fx = bx; fy = by;
3319  return true;
3320 }
int32_t GetDensity(int32_t x, int32_t y) const
int32_t GetHeight() const
int32_t GetWidth() const
T Abs(T val)
Definition: Standard.h:42
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindMatSlide()

bool C4Landscape::FindMatSlide ( int32_t &  fx,
int32_t &  fy,
int32_t  ydir,
int32_t  mdens,
int32_t  mslide 
) const

Definition at line 3144 of file C4Landscape.cpp.

References C4M_Solid, and GetDensity().

Referenced by InsertMaterial().

3145 {
3146  assert(mdens <= C4M_Solid); // mdens normalized in InsertMaterial and mrfInsertCheck
3147  int32_t cslide;
3148  bool fLeft = true, fRight = true;
3149 
3150  // One downwards
3151  if (GetDensity(fx, fy + ydir) < mdens) { fy += ydir; return true; }
3152 
3153  // Find downwards slide path
3154  for (cslide = 1; (cslide <= mslide) && (fLeft || fRight); cslide++)
3155  {
3156  // Check left
3157  if (fLeft)
3158  {
3159  if (GetDensity(fx - cslide, fy) >= mdens && GetDensity(fx - cslide, fy + ydir) >= mdens) // Left clogged
3160  fLeft = false;
3161  else if (GetDensity(fx - cslide, fy + ydir) < mdens) // Left slide okay
3162  {
3163  fx -= cslide; fy += ydir; return true;
3164  }
3165  }
3166  // Check right
3167  if (fRight)
3168  {
3169  if (GetDensity(fx + cslide, fy) >= mdens && GetDensity(fx + cslide, fy + ydir) >= mdens) // Right clogged
3170  fRight = false;
3171  else if (GetDensity(fx + cslide, fy + ydir) < mdens) // Right slide okay
3172  {
3173  fx += cslide; fy += ydir; return true;
3174  }
3175  }
3176  }
3177 
3178  return false;
3179 }
int32_t GetDensity(int32_t x, int32_t y) const
const int32_t C4M_Solid
Definition: C4Constants.h:172
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindMatTop()

void C4Landscape::FindMatTop ( int32_t  mat,
int32_t &  x,
int32_t &  y,
bool  distant_first 
) const

Definition at line 3332 of file C4Landscape.cpp.

References GetMat(), C4MaterialMap::Map, MaterialMap, MatValid(), C4MaterialCore::MaxSlide, CPolyEdge::x, and CPolyEdge::y.

Referenced by ExtractMaterial().

3333 {
3334  int32_t mslide, cslide, tslide, distant_x = 0;
3335  bool fLeft, fRight;
3336 
3337  if (!MatValid(mat)) return;
3338  mslide = ::MaterialMap.Map[mat].MaxSlide;
3339 
3340  do
3341  {
3342  // Catch most common case: Walk upwards until material changes
3343  while (GetMat(x, y - 1) == mat) --y;
3344 
3345  // Find upwards slide
3346  fLeft = true; fRight = true; tslide = 0; distant_x = x;
3347  for (cslide = 1; (cslide <= mslide) && (fLeft || fRight); cslide++)
3348  {
3349  // Left
3350  if (fLeft)
3351  {
3352  if (GetMat(x - cslide, y) != mat) fLeft = false;
3353  else
3354  {
3355  distant_x = x - cslide;
3356  if (GetMat(distant_x, y - 1) == mat) { tslide = -cslide; break; }
3357  }
3358  }
3359  // Right
3360  if (fRight)
3361  {
3362  if (GetMat(x + cslide, y) != mat) fRight = false;
3363  else
3364  {
3365  distant_x = x + cslide;
3366  if (GetMat(distant_x, y - 1) == mat) { tslide = +cslide; break; }
3367  }
3368  }
3369  }
3370 
3371  // Slide
3372  if (tslide) { x += tslide; y--; }
3373 
3374  } while (tslide);
3375 
3376  // return top pixel max slide away from center if desired
3377  if (distant_first) x = distant_x;
3378 
3379 }
int32_t MaxSlide
Definition: C4Material.h:104
C4Material * Map
Definition: C4Material.h:169
int32_t GetMat(int32_t x, int32_t y) const
C4MaterialMap MaterialMap
Definition: C4Material.cpp:974
bool MatValid(int32_t mat)
Definition: C4Material.h:210
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBackDensity()

int32_t C4Landscape::GetBackDensity ( int32_t  x,
int32_t  y 
) const

Definition at line 3797 of file C4Landscape.cpp.

References GetBackPix().

3798 {
3799  return p->Pix2Dens[GetBackPix(x, y)];
3800 }
BYTE GetBackPix(int32_t x, int32_t y) const
Here is the call graph for this function:

◆ GetBackMapIndex()

BYTE C4Landscape::GetBackMapIndex ( int32_t  iX,
int32_t  iY 
) const

Definition at line 3902 of file C4Landscape.cpp.

Referenced by C4EditCursor::ApplyToolPicker().

3903 {
3904  if (!p->MapBkg) return 0;
3905  return p->MapBkg->GetPix(iX, iY);
3906 }
Here is the caller graph for this function:

◆ GetBackMat()

int32_t C4Landscape::GetBackMat ( int32_t  x,
int32_t  y 
) const

Definition at line 3792 of file C4Landscape.cpp.

References GetBackPix().

Referenced by C4EditCursor::UpdateStatusBar().

3793 {
3794  return p->Pix2Mat[GetBackPix(x, y)];
3795 }
BYTE GetBackPix(int32_t x, int32_t y) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBackPix()

BYTE C4Landscape::GetBackPix ( int32_t  x,
int32_t  y 
) const

Definition at line 3754 of file C4Landscape.cpp.

References Clamp(), GetHeight(), and GetWidth().

Referenced by C4EditCursor::ApplyToolPicker(), FindTunnelHeight(), GetBackDensity(), GetBackMat(), GetBackPlacement(), GetLight(), C4Weather::GetWind(), and RaiseTerrain().

3755 {
3756  // Border checks
3757  if (x < 0)
3758  {
3759  return p->DefaultBkgMat(p->LeftColPix[Clamp(y, 0, GetHeight()-1)]);
3760  }
3761  if (static_cast<uint32_t>(x) >= static_cast<uint32_t>(GetWidth()))
3762  {
3763  return p->DefaultBkgMat(p->RightColPix[Clamp(y, 0, GetHeight()-1)]);
3764  }
3765  if (y < 0)
3766  {
3767  return p->DefaultBkgMat(p->TopRowPix[x]);
3768  }
3769  if (static_cast<uint32_t>(y) >= static_cast<uint32_t>(GetHeight()))
3770  {
3771  return p->DefaultBkgMat(p->BottomRowPix[x]);
3772  }
3773 
3774  return p->Surface8Bkg->_GetPix(x, y);
3775 }
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44
int32_t GetHeight() const
int32_t GetWidth() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBackPlacement()

int32_t C4Landscape::GetBackPlacement ( int32_t  x,
int32_t  y 
) const

Definition at line 3802 of file C4Landscape.cpp.

References GetBackPix().

3803 {
3804  return p->Pix2Place[GetBackPix(x, y)];
3805 }
BYTE GetBackPix(int32_t x, int32_t y) const
Here is the call graph for this function:

◆ GetDensity()

int32_t C4Landscape::GetDensity ( int32_t  x,
int32_t  y 
) const

Definition at line 3736 of file C4Landscape.cpp.

References GetPix().

Referenced by DrawMaterialRect(), FindMatPath(), FindMatPathPush(), FindMatSlide(), GBackDensity(), InsertMaterial(), InsertMaterialOutsideLandscape(), and mrfInsertCheck().

3737 {
3738  return p->Pix2Dens[GetPix(x, y)];
3739 }
BYTE GetPix(int32_t x, int32_t y) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetEffectiveMatCount()

int32_t C4Landscape::GetEffectiveMatCount ( int  material) const

Definition at line 4202 of file C4Landscape.cpp.

4203 {
4204  assert(material >= 0 && (unsigned) material < p->EffectiveMatCount.size());
4205  return p->EffectiveMatCount[material];
4206 }

◆ GetFoW()

C4FoW * C4Landscape::GetFoW ( )

Definition at line 4191 of file C4Landscape.cpp.

Referenced by C4Viewport::EnableFoW(), C4Object::StatusDeactivate(), and C4Object::UpdateLight().

4192 {
4193  return p->pFoW.get();
4194 }
Here is the caller graph for this function:

◆ GetGravity()

C4Real C4Landscape::GetGravity ( ) const

Definition at line 3675 of file C4Landscape.cpp.

Referenced by C4ParticleValueProvider::GetValue().

3676 {
3677  return p->Gravity;
3678 }
Here is the caller graph for this function:

◆ GetHeight()

◆ GetLight()

bool C4Landscape::GetLight ( int32_t  x,
int32_t  y 
)

Definition at line 3807 of file C4Landscape.cpp.

References GetBackPix(), and GetPix().

3808 {
3809  return GetBackPix(x, y) == 0 || p->Pix2Light[GetPix(x, y)];
3810 }
BYTE GetBackPix(int32_t x, int32_t y) const
BYTE GetPix(int32_t x, int32_t y) const
Here is the call graph for this function:

◆ GetMapIndex()

BYTE C4Landscape::GetMapIndex ( int32_t  iX,
int32_t  iY 
) const

Definition at line 3896 of file C4Landscape.cpp.

Referenced by C4EditCursor::ApplyToolPicker().

3897 {
3898  if (!p->Map) return 0;
3899  return p->Map->GetPix(iX, iY);
3900 }
Here is the caller graph for this function:

◆ GetMapZoom()

int32_t C4Landscape::GetMapZoom ( ) const

Definition at line 3670 of file C4Landscape.cpp.

Referenced by C4EditCursor::ApplyToolPicker(), and C4Player::Execute().

3671 {
3672  return p->MapZoom;
3673 }
Here is the caller graph for this function:

◆ GetMat()

int32_t C4Landscape::GetMat ( int32_t  x,
int32_t  y 
) const

Definition at line 3731 of file C4Landscape.cpp.

References GetPix().

Referenced by C4Landscape::P::BlastFreePix(), CheckInstability(), C4Landscape::P::DigFreePix(), C4Landscape::P::DigFreePixNoInstability(), ExtractMaterial(), FindMatTop(), GBackMat(), Incinerate(), InsertDeadMaterial(), InsertMaterial(), C4Landscape::P::ShakeFreePix(), and C4EditCursor::UpdateStatusBar().

3732 {
3733  return p->Pix2Mat[GetPix(x, y)];
3734 }
BYTE GetPix(int32_t x, int32_t y) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetMatCount()

int32_t C4Landscape::GetMatCount ( int  material) const

Definition at line 4196 of file C4Landscape.cpp.

Referenced by C4SolidMask::CheckConsistency().

4197 {
4198  assert(material >= 0 && (unsigned) material < p->MatCount.size());
4199  return p->MatCount[material];
4200 }
Here is the caller graph for this function:

◆ GetMatHeight()

int32_t C4Landscape::GetMatHeight ( int32_t  x,
int32_t  y,
int32_t  iYDir,
int32_t  iMat,
int32_t  iMax 
) const

Definition at line 2457 of file C4Landscape.cpp.

References _GetMat(), GetHeight(), and CPolyEdge::y.

Referenced by _SetPix2(), and C4Landscape::P::UpdateMatCnt().

2458 {
2459  if (iYDir > 0)
2460  {
2461  iMax = std::min<int32_t>(iMax, GetHeight() - y);
2462  for (int32_t i = 0; i < iMax; i++)
2463  if (_GetMat(x, y + i) != iMat)
2464  return i;
2465  }
2466  else
2467  {
2468  iMax = std::min<int32_t>(iMax, y + 1);
2469  for (int32_t i = 0; i < iMax; i++)
2470  if (_GetMat(x, y - i) != iMat)
2471  return i;
2472  }
2473  return iMax;
2474 }
int32_t GetHeight() const
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:

◆ GetMode()

LandscapeMode C4Landscape::GetMode ( ) const

◆ GetModulation()

DWORD C4Landscape::GetModulation ( ) const

Definition at line 4019 of file C4Landscape.cpp.

4019 { return p->Modulation; }

◆ GetPal()

CStdPalette * C4Landscape::GetPal ( ) const

Definition at line 3655 of file C4Landscape.cpp.

Referenced by C4ConsoleGUIPreviewWindow::Close(), and C4PXSSystem::Draw().

3656 {
3657  return p->Surface8 ? p->Surface8->pPal : nullptr;
3658 }
Here is the caller graph for this function:

◆ GetPix()

BYTE C4Landscape::GetPix ( int32_t  x,
int32_t  y 
) const

Definition at line 3693 of file C4Landscape.cpp.

References Clamp(), GetHeight(), MCVehic, and CPolyEdge::x.

Referenced by GetDensity(), GetLight(), GetMat(), GetPlacement(), C4Shape::GetVertexOutline(), PathFreeIgnoreVehiclePix(), C4SolidMask::Put(), C4SolidMask::PutTemporary(), RaiseTerrain(), C4SolidMask::RemoveTemporary(), and C4SolidMask::Repair().

3694 {
3695  extern BYTE MCVehic;
3696  // Border checks
3697  if (x < 0)
3698  {
3699  return p->LeftColPix[Clamp(y, 0, GetHeight()-1)];
3700  }
3701  if (static_cast<uint32_t>(x) >= static_cast<uint32_t>(p->Width))
3702  {
3703  return p->RightColPix[Clamp(y, 0, GetHeight()-1)];
3704  }
3705  if (y < 0)
3706  {
3707  return p->TopRowPix[x];
3708  }
3709  if (static_cast<uint32_t>(y) >= static_cast<uint32_t>(p->Height))
3710  {
3711  return p->BottomRowPix[x];
3712  }
3713  return p->Surface8->_GetPix(x, y);
3714 }
uint8_t BYTE
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44
BYTE MCVehic
Definition: C4Material.cpp:37
int32_t GetHeight() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPixDensity()

int32_t C4Landscape::GetPixDensity ( BYTE  byPix) const

Definition at line 3829 of file C4Landscape.cpp.

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

3829 { return p->Pix2Dens[byPix]; }
Here is the caller graph for this function:

◆ GetPixMat()

int32_t C4Landscape::GetPixMat ( BYTE  byPix) const

Definition at line 3827 of file C4Landscape.cpp.

Referenced by C4Landscape::P::GetBridgeMatConversion(), and PathFreeIgnoreVehiclePix().

3827 { return p->Pix2Mat[byPix]; }
Here is the caller graph for this function:

◆ GetPlacement()

int32_t C4Landscape::GetPlacement ( int32_t  x,
int32_t  y 
) const

Definition at line 3741 of file C4Landscape.cpp.

References GetPix().

3742 {
3743  return p->Pix2Place[GetPix(x, y)];
3744 }
BYTE GetPix(int32_t x, int32_t y) const
Here is the call graph for this function:

◆ GetSky()

C4Sky & C4Landscape::GetSky ( )

Definition at line 4181 of file C4Landscape.cpp.

Referenced by C4ConsoleGUIPreviewWindow::Close(), C4Game::CompileFunc(), C4GraphicsSystem::DoSaveScreenshot(), and C4Viewport::Draw().

4182 {
4183  return p->Sky;
4184 }
Here is the caller graph for this function:

◆ GetWidth()

◆ HandleTexMapUpdate()

void C4Landscape::HandleTexMapUpdate ( )

Definition at line 4212 of file C4Landscape.cpp.

References UpdatePixMaps().

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

4213 {
4214  // Pixel maps must be update
4215  UpdatePixMaps();
4216  // Update landscape palette
4217  p->Mat2Pal();
4218 }
void UpdatePixMaps()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ HasFoW()

bool C4Landscape::HasFoW ( ) const

Definition at line 4186 of file C4Landscape.cpp.

Referenced by C4Viewport::EnableFoW(), C4Object::StatusDeactivate(), and C4Object::UpdateLight().

4187 {
4188  return p->pFoW != nullptr;
4189 }
Here is the caller graph for this function:

◆ HasMap()

bool C4Landscape::HasMap ( ) const

Definition at line 1684 of file C4Landscape.cpp.

Referenced by C4ConsoleGUIPreviewWindow::Close().

1685 {
1686  return p->Map != nullptr && p->MapBkg != nullptr;
1687 }
Here is the caller graph for this function:

◆ Incinerate()

bool C4Landscape::Incinerate ( int32_t  x,
int32_t  y,
int32_t  cause_player 
)

Definition at line 1080 of file C4Landscape.cpp.

References C4VInt(), C4PropList::Call(), GetMat(), C4AulScriptEngine::GetPropList(), C4MaterialCore::Inflammable, C4MaterialMap::Map, MaterialMap, MatValid(), P_InflameLandscape, and ScriptEngine.

Referenced by C4MaterialMap::mrfIncinerate().

1081 {
1082  int32_t mat = GetMat(x, y);
1083  if (MatValid(mat))
1084  if (::MaterialMap.Map[mat].Inflammable)
1085  {
1086  C4AulParSet pars(C4VInt(x), C4VInt(y), C4VInt(cause_player));
1088  }
1089  return false;
1090 }
C4PropListStatic * GetPropList()
Definition: C4Aul.h:151
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
C4Material * Map
Definition: C4Material.h:169
C4Value C4VInt(int32_t i)
Definition: C4Value.h:242
int32_t GetMat(int32_t x, int32_t y) const
C4MaterialMap MaterialMap
Definition: C4Material.cpp:974
bool MatValid(int32_t mat)
Definition: C4Material.h:210
int32_t Inflammable
Definition: C4Material.h:106
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4PropList.h:110
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Init()

bool C4Landscape::Init ( C4Group hGroup,
bool  fOverloadCurrent,
bool  fLoadSky,
bool &  rfLoaded,
bool  fSavegame 
)

Definition at line 1422 of file C4Landscape.cpp.

References C4Game::C4S, C4SLandscape::ExactLandscape, C4Game::FixRandom(), Game, C4Scenario::Landscape, C4SLandscape::MapHgt, C4SLandscape::MapWdt, C4SVal::Max, Random(), C4Game::RandomSeed, C4Game::SetInitProgress(), Undefined, and UpdatePixMaps().

1423 {
1424  // set map seed, if not pre-assigned
1425  if (!p->MapSeed) p->MapSeed = Random(3133700);
1426 
1427  // increase max map size, since developers might set a greater one here
1428  Game.C4S.Landscape.MapWdt.Max = 10000;
1429  Game.C4S.Landscape.MapHgt.Max = 10000;
1430 
1431  // map and landscape must be initialized with fixed random, so runtime joining clients may recreate it
1432  // with same seed
1433  // after map/landscape creation, the seed must be fixed again, so there's no difference between clients creating
1434  // and not creating the map
1435  // this, however, would cause syncloss to DebugRecs
1437 
1439 
1440  // map is like it's loaded for regular gamestart
1441  // but it's changed and would have to be saved if a new section is loaded
1442  p->fMapChanged = fOverloadCurrent;
1443 
1444  // don't change landscape mode in runtime joins
1445  bool fLandscapeModeSet = (p->mode != LandscapeMode::Undefined);
1446 
1447  // Make pixel maps
1448  // Pixel maps only depend on loaded materials and textures
1449  // They might be accessed in map scripts, so they should be ready before map creation
1450  UpdatePixMaps();
1451 
1452  Game.SetInitProgress(60);
1453  // create map if necessary
1455  {
1456  std::unique_ptr<CSurface8> sfcMap, sfcMapBkg;
1457 
1458  // Static map from scenario: Old-style Map.bmp with highest bit IFT
1459  if ((sfcMap = GroupReadSurface8(hGroup, C4CFN_Map)))
1460  {
1461  if (!fLandscapeModeSet) p->mode = LandscapeMode::Static;
1462  sfcMapBkg = p->CreateDefaultBkgSurface(*sfcMap, true);
1463  if (!sfcMapBkg) return false;
1464  }
1465 
1466  // Static map from scenario: New-style MapFg.bmp and MapBg.bmp with
1467  // full 255 mat-tex combinations. Background map is optional, if not
1468  // given default will be created with tunnel background for all
1469  // semisolid pixels.
1470  if (!sfcMap)
1471  {
1472  if ((sfcMap = GroupReadSurface8(hGroup, C4CFN_MapFg)))
1473  {
1474  if (!fLandscapeModeSet) p->mode = LandscapeMode::Static;
1475  sfcMapBkg = GroupReadSurface8(hGroup, C4CFN_MapBg);
1476  if (!sfcMapBkg) sfcMapBkg = p->CreateDefaultBkgSurface(*sfcMap, false);
1477  if (!sfcMapBkg) return false;
1478  }
1479  }
1480 
1481  // dynamic map from Landscape.txt
1482  CSurface8 *rendered_map = nullptr, *rendered_bkg = nullptr;
1483  if (!sfcMap)
1484  {
1485  if (p->CreateMapS2(hGroup, rendered_map, rendered_bkg))
1486  {
1487  sfcMap.reset(rendered_map);
1488  sfcMapBkg.reset(rendered_bkg);
1489  if (!fLandscapeModeSet) p->mode = LandscapeMode::Dynamic;
1490  }
1491  }
1492 
1493  // script may create or edit map
1495  {
1496  if (!fLandscapeModeSet) p->mode = LandscapeMode::Dynamic;
1497  }
1498 
1499  // Dynamic map by scenario
1500  if (!sfcMap && !fOverloadCurrent)
1501  {
1502  if (p->CreateMap(rendered_map, rendered_bkg))
1503  {
1504  sfcMap.reset(rendered_map);
1505  sfcMapBkg.reset(rendered_bkg);
1506  // Although this is a dynamic map, it's probably just the empty default map.
1507  // Set the mode to static so people can start drawing directly in the editor.
1508  if (!fLandscapeModeSet) p->mode = LandscapeMode::Static;
1509  }
1510  }
1511 
1512  // No map failure
1513  if (!sfcMap)
1514  {
1515  // no problem if only overloading
1516  if (!fOverloadCurrent) return false;
1517  if (fLoadSky) if (!p->Sky.Init(fSavegame)) return false;
1518  return true;
1519  }
1520 
1521  assert(sfcMapBkg != nullptr);
1522 
1523  if (Config.General.DebugRec)
1524  {
1525  AddDbgRec(RCT_Block, "|---MAP---|", 12);
1526  AddDbgRec(RCT_Map, sfcMap->Bits, sfcMap->Pitch*sfcMap->Hgt);
1527  }
1528 
1529  // Store map size and calculate map zoom
1530  int iWdt, iHgt;
1531  sfcMap->GetSurfaceSize(iWdt, iHgt);
1532  p->MapWidth = iWdt; p->MapHeight = iHgt;
1533  p->MapZoom = Game.C4S.Landscape.MapZoom.Evaluate();
1534 
1535  // Calculate landscape size
1536  p->Width = p->MapZoom * p->MapWidth;
1537  p->Height = p->MapZoom * p->MapHeight;
1538  p->Width = std::max<int32_t>(p->Width, 100);
1539  p->Height = std::max<int32_t>(p->Height, 100);
1540 
1541  // if overloading, clear current landscape (and sections, etc.)
1542  // must clear, of course, before new sky is eventually read
1543  if (fOverloadCurrent) Clear(!Game.C4S.Landscape.KeepMapCreator, fLoadSky, false);
1544 
1545  // assign new map
1546  assert(p->Map == nullptr);
1547  assert(p->MapBkg == nullptr);
1548  p->Map = std::move(sfcMap);
1549  p->MapBkg = std::move(sfcMapBkg);
1550 
1551  // Sky (might need to know landscape height)
1552  if (fLoadSky)
1553  {
1554  Game.SetInitProgress(70);
1555  if (!p->Sky.Init(fSavegame)) return false;
1556  }
1557  }
1558 
1559  // Exact landscape from scenario (no map or exact recreation)
1560  else /* if (Game.C4S.Landscape.ExactLandscape) */
1561  {
1562  C4DebugRecOff DBGRECOFF;
1563  // if overloading, clear current
1564  if (fOverloadCurrent) Clear(!Game.C4S.Landscape.KeepMapCreator, fLoadSky, false);
1565  // load it
1566  if (!fLandscapeModeSet) p->mode = LandscapeMode::Exact;
1567  rfLoaded = true;
1568  if (!Load(hGroup, fLoadSky, fSavegame)) return false;
1569  }
1570 
1571  // progress
1572  Game.SetInitProgress(75);
1573 
1574  // copy noscan-var
1575  p->NoScan = Game.C4S.Landscape.NoScan != 0;
1576 
1577  // Scan settings
1578  p->ScanSpeed = Clamp(GetWidth() / 500, 2, 15);
1579 
1580  // Create pixel count array before any SetPix operations may take place
1581  // Proper pixel counts will be done later, but needs to have the arrays redy to avoid dead pointer access.
1582  // We will use 15x17 blocks so the pixel count can't get over 255.
1583  int32_t PixCntWidth = (GetWidth() + 16) / 17;
1584  p->PixCntPitch = (GetHeight() + 14) / 15;
1585  p->PixCnt.resize(PixCntWidth * p->PixCntPitch);
1586 
1587  // map to big surface and sectionize it
1588  // (not for shaders though - they require continous textures)
1590  {
1591  assert(p->Surface8 == nullptr);
1592  assert(p->Surface8Bkg == nullptr);
1593 
1594  // Create landscape surfaces
1595  {
1596  auto sf8 = std::make_unique<CSurface8>();
1597  auto sfb8 = std::make_unique<CSurface8>();
1598  if (!sf8->Create(GetWidth(), GetHeight()) || !sfb8->Create(GetWidth(), GetHeight()))
1599  return false;
1600  p->Surface8 = std::move(sf8);
1601  p->Surface8Bkg = std::move(sfb8);
1602  if (!p->Mat2Pal())
1603  return false;
1604  }
1605 
1606  // Map to landscape
1607  // Landscape render disabled during initial landscape zoom (will be updated later)
1608  std::unique_ptr<C4LandscapeRender> lsrender_backup;
1609  lsrender_backup.swap(p->pLandscapeRender);
1610  bool map2landscape_success = MapToLandscape();
1611  lsrender_backup.swap(p->pLandscapeRender);
1612  if (!map2landscape_success) return false;
1613  }
1614 
1615  // Init out-of-landscape pixels for bottom
1616  p->InitBorderPix();
1617 
1618  Game.SetInitProgress(80);
1619 
1620  if (Config.General.DebugRec)
1621  {
1622  AddDbgRec(RCT_Block, "|---LANDSCAPE---|", 18);
1623  AddDbgRec(RCT_Map, p->Surface8->Bits, p->Surface8->Pitch * p->Surface8->Hgt);
1624 
1625  AddDbgRec(RCT_Block, "|---LANDSCAPE BKG---|", 22);
1626  AddDbgRec(RCT_Map, p->Surface8Bkg->Bits, p->Surface8Bkg->Pitch * p->Surface8Bkg->Hgt);
1627  }
1628 
1629  // Create FoW
1630  assert(p->pFoW == nullptr);
1631  if (Game.C4S.Game.FoWEnabled)
1632  p->pFoW = std::make_unique<C4FoW>();
1633 
1634  // Create renderer
1635 #ifndef USE_CONSOLE
1636  if (!p->pLandscapeRender)
1637  p->pLandscapeRender = std::make_unique<C4LandscapeRenderGL>();
1638 #endif
1639 
1640  if (p->pLandscapeRender)
1641  {
1642  // Initialize renderer
1643  if (fOverloadCurrent)
1644  {
1645  if (!p->pLandscapeRender->ReInit(GetWidth(), GetHeight()))
1646  return false;
1647  }
1648  else
1649  {
1650  if (!p->pLandscapeRender->Init(GetWidth(), GetHeight(), &::TextureMap, &::GraphicsResource.Files))
1651  return false;
1652  }
1653  }
1654 
1655  // Save initial landscape
1656  if (!SaveInitial())
1657  return false;
1658 
1659  // Load diff, if existant
1660  ApplyDiff(hGroup);
1661 
1662  // Pixel count tracking from landscape zoom is incomplete, so recalculate it.
1663  p->UpdatePixCnt(this, C4Rect(0, 0, GetWidth(), GetHeight()));
1664  p->ClearMatCount();
1665  p->UpdateMatCnt(this, C4Rect(0, 0, GetWidth(), GetHeight()), true);
1666 
1667  // Create initial landscape render data (after applying diff so landscape is complete)
1668  if (p->pLandscapeRender) p->pLandscapeRender->Update(C4Rect(0, 0, GetWidth(), GetHeight()), this);
1669  Game.SetInitProgress(87);
1670 
1671  // after map/landscape creation, the seed must be fixed again, so there's no difference between clients creating
1672  // and not creating the map
1674 
1675  // Create ambient light map after landscape creation
1676  if (p->pFoW) p->pFoW->Ambient.CreateFromLandscape(*this, 10., 50., 0.25);
1677  Game.SetInitProgress(84);
1678 
1679  // Success
1680  rfLoaded = true;
1681  return true;
1682 }
void SetInitProgress(float fToProgress)
Definition: C4Game.cpp:3386
int32_t Max
Definition: C4Scenario.h:31
C4Config Config
Definition: C4Config.cpp:833
int32_t RandomSeed
Definition: C4Game.h:135
uint32_t Random()
Definition: C4Random.cpp:43
bool ApplyDiff(C4Group &hGroup)
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
C4ConfigGeneral General
Definition: C4Config.h:251
#define C4CFN_MapFg
Definition: C4Components.h:58
#define C4CFN_Map
Definition: C4Components.h:57
C4SLandscape Landscape
Definition: C4Scenario.h:236
Definition: C4Rect.h:27
C4SVal MapWdt
Definition: C4Scenario.h:178
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
bool InitializeMap(C4SLandscape *pLandscape, C4TextureMap *pTexMap, C4MaterialMap *pMatMap, uint32_t iPlayerCount, std::unique_ptr< CSurface8 > *pmap_fg_surface, std::unique_ptr< CSurface8 > *pmap_bg_surface)
C4GraphicsResource GraphicsResource
bool ExactLandscape
Definition: C4Scenario.h:165
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44
bool Load(C4Group &hGroup, bool fLoadSky, bool fSavegame)
void FixRandom(uint64_t iSeed)
Definition: C4Game.cpp:3093
C4MapScriptHost MapScript
C4SVal MapZoom
Definition: C4Scenario.h:178
bool MapToLandscape()
void AddDbgRec(C4RecordChunkType eType, const void *pData, int iSize)
Definition: C4Record.cpp:32
void UpdatePixMaps()
#define C4CFN_MapBg
Definition: C4Components.h:59
int32_t GetHeight() const
int32_t StartupPlayerCount
Definition: C4Game.h:109
bool SaveInitial()
C4SVal MapHgt
Definition: C4Scenario.h:178
int32_t GetWidth() const
C4MaterialMap MaterialMap
Definition: C4Material.cpp:974
C4SGame Game
Definition: C4Scenario.h:234
void Clear(bool fClearMapCreator=true, bool fClearSky=true, bool fClearRenderer=true)
int32_t DebugRec
Definition: C4Config.h:60
bool KeepMapCreator
Definition: C4Scenario.h:185
int32_t Evaluate()
Definition: C4Scenario.cpp:50
bool FoWEnabled
Definition: C4Scenario.h:125
Here is the call graph for this function:

◆ InsertDeadMaterial()

bool C4Landscape::InsertDeadMaterial ( int32_t  mat,
int32_t  tx,
int32_t  ty 
)

Definition at line 1043 of file C4Landscape.cpp.

References _GetMat(), _GetPix(), C4M_Solid, C4Game::C4S, Game, C4Scenario::Game, GetHeight(), GetMat(), GetWidth(), InsertMaterial(), InsertMaterialOutsideLandscape(), C4SRealism::LandscapeInsertThrust, Mat2PixColDefault(), MatDensity(), MatValid(), Random(), C4SGame::Realism, SetPix2(), and Transparent.

Referenced by C4MassMover::Execute(), and InsertMaterial().

1044 {
1045  // Check bounds
1046  if (tx < 0 || ty < 0 || tx >= GetWidth() || ty >= GetHeight())
1047  return InsertMaterialOutsideLandscape(tx, ty, std::min(MatDensity(mat), C4M_Solid));
1048 
1049  // Save back original material so we can insert it later
1050  int omat = 0;
1052  omat = GetMat(tx, ty);
1053 
1054  // Check surroundings for inspiration for texture to use
1055  int n = 0; int pix = -1;
1056  if (tx > 0 && _GetMat(tx - 1, ty) == mat)
1057  if (!Random(++n)) pix = _GetPix(tx - 1, ty);
1058  if (ty > 0 && _GetMat(tx, ty - 1) == mat)
1059  if (!Random(++n)) pix = _GetPix(tx, ty - 1);
1060  if (tx + 1 < GetWidth() && _GetMat(tx + 1, ty) == mat)
1061  if (!Random(++n)) pix = _GetPix(tx + 1, ty);
1062  if (ty + 1 < GetHeight() && _GetMat(tx, ty + 1) == mat)
1063  if (!Random(++n)) pix = _GetPix(tx, ty + 1);
1064  if (pix < 0)
1065  pix = Mat2PixColDefault(mat);
1066 
1067  // Insert dead material
1068  SetPix2(tx, ty, pix, Transparent);
1069 
1070  // Search a position for the old material pixel
1072  {
1073  int32_t tyo = ty - 1;
1074  InsertMaterial(omat, &tx, &tyo);
1075  }
1076 
1077  return true;
1078 }
uint32_t Random()
Definition: C4Random.cpp:43
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
bool InsertMaterialOutsideLandscape(int32_t tx, int32_t ty, int32_t mdens)
bool InsertMaterial(int32_t mat, int32_t *tx, int32_t *ty, int32_t vx=0, int32_t vy=0, bool query_only=false)
int32_t MatDensity(int32_t mat)
Definition: C4Material.h:240
C4SRealism Realism
Definition: C4Scenario.h:127
int32_t GetMat(int32_t x, int32_t y) const
bool SetPix2(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
const int32_t C4M_Solid
Definition: C4Constants.h:172
int32_t GetHeight() const
bool LandscapeInsertThrust
Definition: C4Scenario.h:111
int32_t GetWidth() const
C4SGame Game
Definition: C4Scenario.h:234
BYTE Mat2PixColDefault(int32_t mat)
Definition: C4Material.h:235
BYTE _GetPix(int32_t x, int32_t y) const
int32_t _GetMat(int32_t x, int32_t y) const
static const uint8_t Transparent
Definition: C4Landscape.h:50
bool MatValid(int32_t mat)
Definition: C4Material.h:210
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InsertMaterial()

bool C4Landscape::InsertMaterial ( int32_t  mat,
int32_t *  tx,
int32_t *  ty,
int32_t  vx = 0,
int32_t  vy = 0,
bool  query_only = false 
)

Definition at line 971 of file C4Landscape.cpp.

References C4M_Solid, C4REAL10(), C4Game::C4S, C4PXSSystem::Create(), FindMatPathPush(), FindMatSlide(), Game, C4Scenario::Game, GetDensity(), GetHeight(), GetMat(), C4MaterialMap::GetReactionUnsafe(), GetWidth(), GravAccel, InsertDeadMaterial(), InsertMaterialOutsideLandscape(), C4MaterialCore::Instable, itofix(), C4SRealism::LandscapePushPull, C4MaterialMap::Map, MatDensity(), MaterialMap, MatValid(), C4MaterialCore::MaxSlide, meePXSPos, C4MaterialReaction::pFunc, PXS, C4SGame::Realism, and Sign().

Referenced by C4ControlEMDrawTool::C4ControlEMDrawTool(), C4MassMover::Execute(), InsertDeadMaterial(), C4MaterialMap::mrfIncinerate(), and C4MaterialMap::mrfInsert().

972 {
973  assert(tx); assert(ty);
974  int32_t mdens;
975  if (!MatValid(mat)) return false;
976  mdens = std::min(MatDensity(mat), C4M_Solid);
977  if (!mdens) return true;
978 
979  // Bounds
980  if (!Inside<int32_t>(*tx, 0, GetWidth() - 1) || !Inside<int32_t>(*ty, 0, GetHeight())) return InsertMaterialOutsideLandscape(*tx, *ty, mdens);
981 
983  {
984  // Same or higher density?
985  if (GetDensity(*tx, *ty) >= mdens)
986  // Push
987  if (!FindMatPathPush(*tx, *ty, mdens, ::MaterialMap.Map[mat].MaxSlide, !!::MaterialMap.Map[mat].Instable))
988  // Or die
989  return false;
990  }
991  else
992  {
993  // Move up above same density
994  while (mdens == std::min(GetDensity(*tx, *ty), C4M_Solid))
995  {
996  (*ty)--; if (*ty < 0) return false;
997  // Primitive slide (1)
998  if (GetDensity(*tx - 1, *ty) < mdens) (*tx)--;
999  if (GetDensity(*tx + 1, *ty) < mdens) (*tx)++;
1000  }
1001  // Stuck in higher density
1002  if (GetDensity(*tx, *ty) > mdens) return false;
1003  }
1004 
1005  // Try slide
1006  while (FindMatSlide(*tx, *ty, +1, mdens, ::MaterialMap.Map[mat].MaxSlide))
1007  if (GetDensity(*tx, *ty + 1) < mdens)
1008  {
1009  if (!query_only)
1010  return ::PXS.Create(mat, itofix(*tx), itofix(*ty), C4REAL10(vx), C4REAL10(vy));
1011  return true;
1012  }
1013 
1014  if (query_only)
1015  {
1016  // since tx and ty changed, we need to re-check the bounds here
1017  // if we really inserted it, the check is made again in InsertDeadMaterial
1018  if (!Inside<int32_t>(*tx, 0, GetWidth() - 1) || !Inside<int32_t>(*ty, 0, GetHeight())) return InsertMaterialOutsideLandscape(*tx, *ty, mdens);
1019  return true;
1020  }
1021 
1022  // Try reaction with material below and at insertion position
1023  C4MaterialReaction *pReact; int32_t tmat;
1024  int32_t check_dir = 0;
1025  for (int32_t i = 0; i < 2; ++i)
1026  {
1027  if ((pReact = ::MaterialMap.GetReactionUnsafe(mat, tmat = GetMat(*tx, *ty + check_dir))))
1028  {
1029  C4Real fvx = C4REAL10(vx), fvy = C4REAL10(vy);
1030  if ((*pReact->pFunc)(pReact, *tx, *ty, *tx, *ty + check_dir, fvx, fvy, mat, tmat, meePXSPos, nullptr))
1031  {
1032  // the material to be inserted killed itself in some material reaction below
1033  return true;
1034  }
1035  }
1036  if (!(check_dir = Sign(GravAccel))) break;
1037  }
1038 
1039  // Insert as dead material
1040  return InsertDeadMaterial(mat, *tx, *ty);
1041 }
bool FindMatPathPush(int32_t &fx, int32_t &fy, int32_t mdens, int32_t mslide, bool liquid) const
C4MaterialReaction * GetReactionUnsafe(int32_t iPXSMat, int32_t iLandscapeMat)
Definition: C4Material.h:191
int32_t MaxSlide
Definition: C4Material.h:104
int32_t GetDensity(int32_t x, int32_t y) const
C4Game Game
Definition: C4Globals.cpp:52
bool LandscapePushPull
Definition: C4Scenario.h:110
C4Scenario C4S
Definition: C4Game.h:74
bool InsertDeadMaterial(int32_t mat, int32_t tx, int32_t ty)
int32_t Instable
Definition: C4Material.h:102
C4Material * Map
Definition: C4Material.h:169
#define GravAccel
Definition: C4Physics.h:27
bool InsertMaterialOutsideLandscape(int32_t tx, int32_t ty, int32_t mdens)
int Sign(T val)
Definition: Standard.h:45
bool Create(int32_t mat, C4Real ix, C4Real iy, C4Real ixdir=Fix0, C4Real iydir=Fix0)
Definition: C4PXS.cpp:175
Definition: C4Real.h:58
C4MaterialReactionFunc pFunc
Definition: C4Material.h:47
int32_t MatDensity(int32_t mat)
Definition: C4Material.h:240
C4Real C4REAL10(int x)
Definition: C4Real.h:269
C4SRealism Realism
Definition: C4Scenario.h:127
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
C4PXSSystem PXS
Definition: C4PXS.cpp:423
int32_t GetMat(int32_t x, int32_t y) const
const int32_t C4M_Solid
Definition: C4Constants.h:172
int32_t GetHeight() const
int32_t GetWidth() const
C4MaterialMap MaterialMap
Definition: C4Material.cpp:974
C4SGame Game
Definition: C4Scenario.h:234
bool FindMatSlide(int32_t &fx, int32_t &fy, int32_t ydir, int32_t mdens, int32_t mslide) const
bool MatValid(int32_t mat)
Definition: C4Material.h:210
Here is the call graph for this function:
Here is the caller graph for this function:

◆ InsertMaterialOutsideLandscape()

bool C4Landscape::InsertMaterialOutsideLandscape ( int32_t  tx,
int32_t  ty,
int32_t  mdens 
)

Definition at line 963 of file C4Landscape.cpp.

References GetDensity().

Referenced by InsertDeadMaterial(), and InsertMaterial().

964 {
965  // Out-of-bounds insertion considered successful if inserted into same or lower density
966  // This ensures pumping out of map works
967  // Do allow insertion into same density because it covers the case of e.g. pumping water into the upper ocean of an underwater scenario
968  return GetDensity(tx, ty) <= mdens;
969 }
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:

◆ Load()

bool C4Landscape::Load ( C4Group hGroup,
bool  fLoadSky,
bool  fSavegame 
)

Definition at line 1827 of file C4Landscape.cpp.

1828 {
1829  assert(!p->Surface8 && !p->Surface8Bkg);
1830 
1831  // Load exact landscape from group
1832  if ((p->Surface8 = GroupReadSurface8(hGroup, C4CFN_Landscape)) == nullptr)
1833  {
1834  if ((p->Surface8 = GroupReadSurface8(hGroup, C4CFN_LandscapeFg)) == nullptr) return false;
1835  p->Surface8Bkg = GroupReadSurface8(hGroup, C4CFN_LandscapeBg);
1836 
1837  if (p->Surface8Bkg)
1838  {
1839  if (p->Surface8->Wdt != p->Surface8Bkg->Wdt || p->Surface8->Hgt != p->Surface8Bkg->Hgt)
1840  {
1841  LogFatal(FormatString("Landscape has different dimensions than background landscape (%dx%d vs. %dx%d)", p->Surface8->Wdt, p->Surface8->Hgt, p->Surface8Bkg->Wdt, p->Surface8Bkg->Hgt).getData());
1842  return false;
1843  }
1844  }
1845  else
1846  {
1847  // LandscapeFg.bmp loaded: Assume full 8bit mat-tex values
1848  // when creating background surface.
1849  p->Surface8Bkg = p->CreateDefaultBkgSurface(*p->Surface8, false);
1850  }
1851  }
1852  else
1853  {
1854  // Landscape.bmp loaded: Assume msb is IFT flag when creating
1855  // background surface.
1856  p->Surface8Bkg = p->CreateDefaultBkgSurface(*p->Surface8, true);
1857  }
1858 
1859  int iWidth, iHeight;
1860  p->Surface8->GetSurfaceSize(iWidth, iHeight);
1861  p->Width = iWidth; p->Height = iHeight;
1862 
1863  // adjust pal
1864  if (!p->Mat2Pal()) return false;
1865  // Landscape should be in correct format: Make sure it is!
1866  for (int32_t y = 0; y < GetHeight(); ++y)
1867  for (int32_t x = 0; x < GetWidth(); ++x)
1868  {
1869  BYTE byPix = p->Surface8->_GetPix(x, y);
1870  int32_t iMat = PixCol2Mat(byPix);
1871 
1872  if (byPix && !MatValid(iMat))
1873  {
1874  LogFatal(FormatString("Landscape loading error at (%d/%d): Pixel value %d not a valid material!", (int)x, (int)y, (int)byPix).getData());
1875  return false;
1876  }
1877 
1878  BYTE byPixBkg = p->Surface8Bkg->_GetPix(x, y);
1879  int32_t iMatBkg = PixCol2Mat(byPixBkg);
1880 
1881  if (byPixBkg && !MatValid(iMatBkg))
1882  {
1883  LogFatal(FormatString("Background Landscape loading error at (%d/%d): Pixel value %d not a valid material!", (int)x, (int)y, (int)byPixBkg).getData());
1884  return false;
1885  }
1886  }
1887 
1888  // Init sky
1889  if (fLoadSky)
1890  {
1891  Game.SetInitProgress(70);
1892  if (p->Sky.Init(fSavegame)) return false;
1893  }
1894  // Success
1895  return true;
1896 }
void SetInitProgress(float fToProgress)
Definition: C4Game.cpp:3386
C4Game Game
Definition: C4Globals.cpp:52
uint8_t BYTE
int32_t PixCol2Mat(BYTE pixc)
#define C4CFN_Landscape
Definition: C4Components.h:60
#define C4CFN_LandscapeFg
Definition: C4Components.h:61
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:237
const char * getData() const
Definition: StdBuf.h:442
int32_t GetHeight() const
int32_t GetWidth() const
bool MatValid(int32_t mat)
Definition: C4Material.h:210
#define C4CFN_LandscapeBg
Definition: C4Components.h:62
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

◆ MapToLandscape()

bool C4Landscape::MapToLandscape ( )

Definition at line 2106 of file C4Landscape.cpp.

Referenced by C4ToolsDlg::SetLandscapeMode().

2107 {
2108  // zoom map to landscape
2109  return p->MapToLandscape(this, *p->Map, *p->MapBkg, 0, 0, p->MapWidth, p->MapHeight);
2110 }
Here is the caller graph for this function:

◆ PostInitMap()

bool C4Landscape::PostInitMap ( )

Definition at line 2442 of file C4Landscape.cpp.

References C4Game::C4S, Game, C4SLandscape::KeepMapCreator, and C4Scenario::Landscape.

2443 {
2444  // map creator present?
2445  if (!p->pMapCreator) return true;
2446  // call scripts
2447  p->pMapCreator->ExecuteCallbacks(p->MapZoom);
2448  // destroy map creator, if not needed later
2449  if (!Game.C4S.Landscape.KeepMapCreator) { p->pMapCreator.reset(); }
2450  // done, success
2451  return true;
2452 }
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
C4SLandscape Landscape
Definition: C4Scenario.h:236
bool KeepMapCreator
Definition: C4Scenario.h:185

◆ RaiseTerrain()

void C4Landscape::RaiseTerrain ( int32_t  tx,
int32_t  ty,
int32_t  wdt 
)

Definition at line 936 of file C4Landscape.cpp.

References GBackSolid(), GetBackPix(), GetHeight(), GetPix(), Landscape, MatVehicle(), PixCol2Mat(), and SetPix2().

Referenced by C4Game::CreateObjectConstruction().

937 {
938  int32_t cx, cy;
939  BYTE cpix;
940  for (cx = tx; cx < tx + wdt; cx++)
941  {
942  for (cy = ty; (cy + 1 < ::Landscape.GetHeight()) && !GBackSolid(cx, cy + 1); cy++) {}
943  if (cy + 1 < ::Landscape.GetHeight()) if (cy - ty < 20)
944  {
945  cpix = GetPix(cx, cy + 1);
946  if (!MatVehicle(PixCol2Mat(cpix)))
947  while (cy >= ty) { SetPix2(cx, cy, cpix, GetBackPix(cx, cy + 1)); cy--; }
948  }
949  }
950 }
bool MatVehicle(int32_t iMat)
Definition: C4Material.h:215
BYTE GetBackPix(int32_t x, int32_t y) const
uint8_t BYTE
int32_t PixCol2Mat(BYTE pixc)
C4Landscape Landscape
bool SetPix2(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
int32_t GetHeight() const
BYTE GetPix(int32_t x, int32_t y) 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:

◆ RemoveUnusedTexMapEntries()

void C4Landscape::RemoveUnusedTexMapEntries ( )

Definition at line 4145 of file C4Landscape.cpp.

References C4Material::AboveTempConvertTo, C4Material::BelowTempConvertTo, C4Material::BlastShiftTo, C4M_MaxTexIndex, C4Material::DefaultMatTex, C4TextureMap::fEntriesAdded, GetHeight(), GetWidth(), C4MaterialMap::Map, MaterialMap, C4MaterialMap::Num, C4TextureMap::RemoveEntry(), TextureMap, CPolyEdge::x, and CPolyEdge::y.

4146 {
4147  // check usage in landscape
4148  bool fTexUsage[C4M_MaxTexIndex];
4149  int32_t iMatTex;
4150  for (iMatTex = 0; iMatTex < C4M_MaxTexIndex; ++iMatTex)
4151  fTexUsage[iMatTex] = false;
4152  for (int32_t y = 0; y < GetHeight(); ++y)
4153  for (int32_t x = 0; x < GetWidth(); ++x)
4154  {
4155  const BYTE pix = p->Surface8->GetPix(x, y);
4156  const BYTE backPix = p->Surface8Bkg->GetPix(x, y);
4157  assert(pix < C4M_MaxTexIndex);
4158  assert(backPix < C4M_MaxTexIndex);
4159 
4160  fTexUsage[pix] = true;
4161  fTexUsage[backPix] = true;
4162  }
4163 
4164  // check usage by materials
4165  for (int32_t iMat = 0; iMat < ::MaterialMap.Num; ++iMat)
4166  {
4167  C4Material *pMat = ::MaterialMap.Map + iMat;
4168  if (pMat->BlastShiftTo >= 0) fTexUsage[pMat->BlastShiftTo] = true;
4169  if (pMat->BelowTempConvertTo >= 0) fTexUsage[pMat->BelowTempConvertTo] = true;
4170  if (pMat->AboveTempConvertTo >= 0) fTexUsage[pMat->AboveTempConvertTo] = true;
4171  if (pMat->DefaultMatTex >= 0) fTexUsage[pMat->DefaultMatTex] = true;
4172  }
4173  // remove unused
4174  for (iMatTex = 1; iMatTex < C4M_MaxTexIndex; ++iMatTex)
4175  if (!fTexUsage[iMatTex])
4176  ::TextureMap.RemoveEntry(iMatTex);
4177  // flag rewrite
4178  ::TextureMap.fEntriesAdded = true;
4179 }
int32_t BlastShiftTo
Definition: C4Material.h:151
int32_t DefaultMatTex
Definition: C4Material.h:155
C4Material * Map
Definition: C4Material.h:169
uint8_t BYTE
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
void RemoveEntry(int32_t iIndex)
Definition: C4Texture.cpp:525
const int C4M_MaxTexIndex
Definition: C4Constants.h:51
int32_t AboveTempConvertTo
Definition: C4Material.h:154
int32_t Num
Definition: C4Material.h:168
int32_t GetHeight() const
int32_t BelowTempConvertTo
Definition: C4Material.h:153
int32_t GetWidth() const
C4MaterialMap MaterialMap
Definition: C4Material.cpp:974
bool fEntriesAdded
Definition: C4Texture.h:83
Here is the call graph for this function:

◆ ReplaceMapColor()

bool C4Landscape::ReplaceMapColor ( BYTE  iOldIndex,
BYTE  iNewIndex 
)

Definition at line 4040 of file C4Landscape.cpp.

References CPolyEdge::x, and CPolyEdge::y.

Referenced by SetTextureIndex().

4041 {
4042  // find every occurance of iOldIndex in map; replace it by new index
4043  if (!p->Map) return false;
4044  int iPitch, iMapWdt, iMapHgt;
4045  BYTE *pMap = p->Map->Bits;
4046  iMapWdt = p->Map->Wdt;
4047  iMapHgt = p->Map->Hgt;
4048  iPitch = p->Map->Pitch;
4049  if (!pMap) return false;
4050  for (int32_t y = 0; y < iMapHgt; ++y)
4051  {
4052  for (int32_t x = 0; x < iMapWdt; ++x)
4053  {
4054  if (*pMap == iOldIndex)
4055  *pMap = iNewIndex;
4056  ++pMap;
4057  }
4058  pMap += iPitch - iMapWdt;
4059  }
4060  return true;
4061 }
uint8_t BYTE
Here is the caller graph for this function:

◆ Save()

bool C4Landscape::Save ( C4Group hGroup) const

Definition at line 1689 of file C4Landscape.cpp.

References C4SolidMask::PutSolidMasks(), and C4SolidMask::RemoveSolidMasks().

Referenced by C4Game::LoadScenarioSection().

1690 {
1692  bool r = p->SaveInternal(this, hGroup);
1694  return r;
1695 }
static void RemoveSolidMasks()
static void PutSolidMasks()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SaveDiff()

bool C4Landscape::SaveDiff ( C4Group hGroup,
bool  fSyncSave 
) const

Definition at line 1730 of file C4Landscape.cpp.

References C4SolidMask::PutSolidMasks(), and C4SolidMask::RemoveSolidMasks().

1731 {
1733  bool r = p->SaveDiffInternal(this, hGroup, fSyncSave);
1735  return r;
1736 }
static void RemoveSolidMasks()
static void PutSolidMasks()
Here is the call graph for this function:

◆ SaveInitial()

bool C4Landscape::SaveInitial ( )

Definition at line 1806 of file C4Landscape.cpp.

References GetHeight(), GetWidth(), and CPolyEdge::x.

1807 {
1808 
1809  // Create array
1810  p->pInitial = std::make_unique<BYTE[]>(GetWidth() * GetHeight());
1811  p->pInitialBkg = std::make_unique<BYTE[]>(GetWidth() * GetHeight());
1812 
1813  // Save material data
1814  for (int y = 0; y < GetHeight(); y++)
1815  {
1816  const int pitch = y * GetWidth();
1817  for (int x = 0; x < GetWidth(); x++)
1818  {
1819  p->pInitial[pitch + x] = p->Surface8->_GetPix(x, y);
1820  p->pInitialBkg[pitch + x] = p->Surface8Bkg->_GetPix(x, y);
1821  }
1822  }
1823 
1824  return true;
1825 }
int32_t GetHeight() const
int32_t GetWidth() const
Here is the call graph for this function:

◆ SaveMap()

bool C4Landscape::SaveMap ( C4Group hGroup) const

Definition at line 1950 of file C4Landscape.cpp.

References C4Config::AtTempPath(), C4CFN_MapBg, C4CFN_MapFg, C4CFN_TempMapBg, C4CFN_TempMapFg, Config, MaterialMap, C4Group::Move(), C4TextureMap::StoreMapPalette(), and TextureMap.

Referenced by C4Landscape::P::SaveDiffInternal(), and C4Landscape::P::SaveInternal().

1951 {
1952  // No map
1953  if (!p->Map) return false;
1954  assert(p->MapBkg != nullptr);
1955 
1956  // Create map palette
1957  CStdPalette Palette;
1959 
1960  // Save map surface
1961  if (!p->Map->Save(Config.AtTempPath(C4CFN_TempMapFg), &Palette))
1962  return false;
1963 
1964  // Move temp file to group
1965  if (!hGroup.Move(Config.AtTempPath(C4CFN_TempMapFg),
1966  C4CFN_MapFg))
1967  return false;
1968 
1969  // Save background map surface
1970  if (!p->MapBkg->Save(Config.AtTempPath(C4CFN_TempMapBg), &Palette))
1971  return false;
1972 
1973  // Move temp file to group
1974  if (!hGroup.Move(Config.AtTempPath(C4CFN_TempMapBg),
1975  C4CFN_MapBg))
1976  return false;
1977 
1978  // Success
1979  return true;
1980 }
C4Config Config
Definition: C4Config.cpp:833
#define C4CFN_MapFg
Definition: C4Components.h:58
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
bool Move(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1325
#define C4CFN_TempMapFg
Definition: C4Components.h:154
#define C4CFN_MapBg
Definition: C4Components.h:59
void StoreMapPalette(CStdPalette *, C4MaterialMap &rMaterials)
Definition: C4Texture.cpp:537
C4MaterialMap MaterialMap
Definition: C4Material.cpp:974
const char * AtTempPath(const char *szFilename)
Definition: C4Config.cpp:540
#define C4CFN_TempMapBg
Definition: C4Components.h:155
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SaveTextures()

bool C4Landscape::SaveTextures ( C4Group hGroup) const

Definition at line 1982 of file C4Landscape.cpp.

References C4Config::AtTempPath(), C4CFN_Material, C4CFN_TexMap, C4Group::Close(), Config, EraseItem(), C4TextureMap::fEntriesAdded, C4Group::FindEntry(), C4Group::IsOpen(), C4Group::Move(), C4Group::Open(), C4Group::OpenAsChild(), C4TextureMap::SaveMap(), and TextureMap.

Referenced by C4Landscape::P::SaveDiffInternal(), and C4Landscape::P::SaveInternal().

1983 {
1984  // if material-texture-combinations have been added, write the texture map
1985  if (::TextureMap.fEntriesAdded)
1986  {
1987  C4Group *pMatGroup = new C4Group();
1988  bool fSuccess = false;
1989  // create local material group
1990  if (!hGroup.FindEntry(C4CFN_Material))
1991  {
1992  // delete previous item at temp path
1994  // create at temp path
1995  if (pMatGroup->Open(Config.AtTempPath(C4CFN_Material), true))
1996  // write to it
1997  if (::TextureMap.SaveMap(*pMatGroup, C4CFN_TexMap))
1998  // close (flush)
1999  if (pMatGroup->Close())
2000  // add it
2002  fSuccess = true;
2003  // temp group must remain for scenario file closure
2004  // it will be deleted when the group is closed
2005  }
2006  else
2007  // simply write it to the local material file
2008  if (pMatGroup->OpenAsChild(&hGroup, C4CFN_Material))
2009  fSuccess = ::TextureMap.SaveMap(*pMatGroup, C4CFN_TexMap);
2010  // close material group again
2011  if (pMatGroup->IsOpen()) pMatGroup->Close();
2012  delete pMatGroup;
2013  // fail if unsuccessful
2014  if (!fSuccess) return false;
2015  }
2016  // done, success
2017  return true;
2018 }
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
C4Config Config
Definition: C4Config.cpp:833
#define C4CFN_Material
Definition: C4Components.h:25
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
bool SaveMap(C4Group &hGroup, const char *szEntryName)
Definition: C4Texture.cpp:309
bool Move(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1325
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
#define C4CFN_TexMap
Definition: C4Components.h:80
bool Close()
Definition: C4Group.cpp:755
bool EraseItem(const char *szItemName)
Definition: StdFile.cpp:809
const char * AtTempPath(const char *szFilename)
Definition: C4Config.cpp:540
bool fEntriesAdded
Definition: C4Texture.h:83
bool IsOpen() const
Definition: C4Group.cpp:1891
bool OpenAsChild(C4Group *pMother, const char *szEntryName, bool fExclusive=false, bool fCreate=false)
Definition: C4Group.cpp:1585
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ScenarioInit()

void C4Landscape::ScenarioInit ( )

Definition at line 1347 of file C4Landscape.cpp.

References C4REAL100(), C4Game::C4S, DefaultGravAccel, C4SVal::Evaluate(), Game, C4SLandscape::Gravity, and C4Scenario::Landscape.

1348 {
1349  // Gravity
1351 }
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
C4SLandscape Landscape
Definition: C4Scenario.h:236
C4SVal Gravity
Definition: C4Scenario.h:176
C4Real C4REAL100(int x)
Definition: C4Real.h:267
const C4Real DefaultGravAccel
Definition: C4Movement.cpp:40
int32_t Evaluate()
Definition: C4Scenario.cpp:50
Here is the call graph for this function:

◆ SetGravity()

void C4Landscape::SetGravity ( C4Real  g)

Definition at line 3680 of file C4Landscape.cpp.

3681 {
3682  p->Gravity = g;
3683 }

◆ SetMapChanged()

void C4Landscape::SetMapChanged ( )

Definition at line 4143 of file C4Landscape.cpp.

Referenced by DrawBox(), DrawBrush(), and DrawLine().

4143 { p->fMapChanged = true; }
Here is the caller graph for this function:

◆ SetMode()

void C4Landscape::SetMode ( LandscapeMode  iMode)

Definition at line 3384 of file C4Landscape.cpp.

Referenced by C4ToolsDlg::SetLandscapeMode().

3385 {
3386  p->mode = mode;
3387 }
Here is the caller graph for this function:

◆ SetModulation()

bool C4Landscape::SetModulation ( DWORD  dwWithClr)

Definition at line 4013 of file C4Landscape.cpp.

4014 {
4015  p->Modulation = dwWithClr;
4016  return true;
4017 }

◆ SetPix2()

bool C4Landscape::SetPix2 ( int32_t  x,
int32_t  y,
BYTE  fgPix,
BYTE  bgPix 
)

Definition at line 782 of file C4Landscape.cpp.

References _GetPix(), _SetPix2(), GetHeight(), GetWidth(), and Transparent.

Referenced by C4Landscape::P::BlastFreePix(), ClearPix(), C4Landscape::P::DoScan(), DrawMaterialRect(), InsertDeadMaterial(), C4SolidMask::Put(), RaiseTerrain(), and C4SolidMask::Repair().

783 {
784  // check bounds
785  if (x < 0 || y < 0 || x >= GetWidth() || y >= GetHeight())
786  return false;
787  // no change?
788  if ((fgPix == Transparent || fgPix == _GetPix(x, y)) && (bgPix == Transparent || bgPix == p->Surface8Bkg->_GetPix(x, y)))
789  return true;
790  // set pixel
791  return _SetPix2(x, y, fgPix, bgPix);
792 }
int32_t GetHeight() const
int32_t GetWidth() const
BYTE _GetPix(int32_t x, int32_t y) const
static const uint8_t Transparent
Definition: C4Landscape.h:50
bool _SetPix2(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetTextureIndex()

bool C4Landscape::SetTextureIndex ( const char *  szMatTex,
BYTE  iNewIndex,
bool  fInsert 
)

Definition at line 4063 of file C4Landscape.cpp.

References C4TextureMap::AddEntry(), C4M_MaxTexIndex, StdStrBuf::Copy(), StdStrBuf::CopyUntil(), DebugLogF(), StdStrBuf::getData(), C4TextureMap::GetEntry(), C4TextureMap::GetIndex(), C4TexMapEntry::GetMaterialName(), C4TexMapEntry::GetTextureName(), C4TexMapEntry::isNull(), LogF(), C4TextureMap::MoveIndex(), ReplaceMapColor(), SSearch(), and TextureMap.

4064 {
4065  if (((!szMatTex || !*szMatTex) && !fInsert) || !Inside<int>(iNewIndex, 1, C4M_MaxTexIndex - 1))
4066  {
4067  DebugLogF("Cannot insert new texture %s to index %d: Invalid parameters.", (const char *)szMatTex, (int)iNewIndex);
4068  return false;
4069  }
4070  // get last mat index - returns zero for not found (valid for insertion mode)
4071  StdStrBuf Material, Texture;
4072  Material.CopyUntil(szMatTex, '-'); Texture.Copy(SSearch(szMatTex, "-"));
4073  BYTE iOldIndex = (szMatTex && *szMatTex) ? ::TextureMap.GetIndex(Material.getData(), Texture.getData(), false) : 0;
4074  // insertion mode?
4075  if (fInsert)
4076  {
4077  // there must be room to move up to
4078  BYTE byLastMoveIndex = C4M_MaxTexIndex - 1;
4079  while (::TextureMap.GetEntry(byLastMoveIndex))
4080  if (--byLastMoveIndex == iNewIndex)
4081  {
4082  DebugLogF("Cannot insert new texture %s to index %d: No room for insertion.", (const char *)szMatTex, (int)iNewIndex);
4083  return false;
4084  }
4085  // then move up all other textures first
4086  // could do this in one loop, but it's just a developement call anyway, so move one index at a time
4087  while (--byLastMoveIndex >= iNewIndex)
4088  if (::TextureMap.GetEntry(byLastMoveIndex))
4089  {
4090  ReplaceMapColor(byLastMoveIndex, byLastMoveIndex + 1);
4091  ::TextureMap.MoveIndex(byLastMoveIndex, byLastMoveIndex + 1);
4092  }
4093  // new insertion desired?
4094  if (szMatTex && *szMatTex)
4095  {
4096  // move from old or create new
4097  if (iOldIndex)
4098  {
4099  ReplaceMapColor(iOldIndex, iNewIndex);
4100  ::TextureMap.MoveIndex(iOldIndex, iNewIndex);
4101  }
4102  else
4103  {
4104  StdStrBuf Material, Texture;
4105  Material.CopyUntil(szMatTex, '-'); Texture.Copy(SSearch(szMatTex, "-"));
4106  // new insertion
4107  if (!::TextureMap.AddEntry(iNewIndex, Material.getData(), Texture.getData()))
4108  {
4109  LogF("Cannot insert new texture %s to index %d: Texture map entry error", (const char *)szMatTex, (int)iNewIndex);
4110  return false;
4111  }
4112  }
4113  }
4114  // done, success
4115  return true;
4116  }
4117  else
4118  {
4119  // new index must not be occupied
4120  const C4TexMapEntry *pOld;
4121  if ((pOld = ::TextureMap.GetEntry(iNewIndex)) && !pOld->isNull())
4122  {
4123  DebugLogF("Cannot move texture %s to index %d: Index occupied by %s-%s.", (const char *)szMatTex, (int)iNewIndex, pOld->GetMaterialName(), pOld->GetTextureName());
4124  return false;
4125  }
4126  // must only move existing textures
4127  if (!iOldIndex)
4128  {
4129  DebugLogF("Cannot move texture %s to index %d: Texture not found.", (const char *)szMatTex, (int)iNewIndex);
4130  return false;
4131  }
4132  // update map
4133  ReplaceMapColor(iOldIndex, iNewIndex);
4134  // change to new index in texmap
4135  ::TextureMap.MoveIndex(iOldIndex, iNewIndex);
4136  // done, success
4137  return true;
4138  }
4139 }
bool AddEntry(BYTE byIndex, const char *szMaterial, const char *szTexture)
Definition: C4Texture.cpp:103
const char * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:363
uint8_t BYTE
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
Definition: C4Texture.h:48
const C4TexMapEntry * GetEntry(int32_t iIndex) const
Definition: C4Texture.h:85
int32_t GetIndex(const char *szMaterial, const char *szTexture, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr)
Definition: C4Texture.cpp:414
const char * GetTextureName() const
Definition: C4Texture.h:61
const char * GetMaterialName() const
Definition: C4Texture.h:60
const int C4M_MaxTexIndex
Definition: C4Constants.h:51
void MoveIndex(BYTE byOldIndex, BYTE byNewIndex)
Definition: C4Texture.cpp:403
const char * getData() const
Definition: StdBuf.h:442
void CopyUntil(const char *szString, char cUntil)
Definition: StdBuf.h:613
bool isNull() const
Definition: C4Texture.h:59
bool ReplaceMapColor(BYTE iOldIndex, BYTE iNewIndex)
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:260
void Copy()
Definition: StdBuf.h:467
bool DebugLogF(const char *strMessage ...)
Definition: C4Log.cpp:288
Here is the call graph for this function:

◆ ShakeFree()

void C4Landscape::ShakeFree ( int32_t  tx,
int32_t  ty,
int32_t  rad 
)

Definition at line 509 of file C4Landscape.cpp.

510 {
511  std::vector<int32_t> vertices(GetRoundPolygon(tx, ty, rad, 50));
512  p->ForPolygon(this, &vertices[0], vertices.size() / 2, [this](int32_t x, int32_t y) { return p->ShakeFreePix(this, x, y); });
513 }

◆ Synchronize()

void C4Landscape::Synchronize ( )

Definition at line 1933 of file C4Landscape.cpp.

Referenced by C4Game::Synchronize().

1934 {
1935  p->ScanX = 0;
1936 }
Here is the caller graph for this function:

◆ UpdatePixMaps()

void C4Landscape::UpdatePixMaps ( )

Definition at line 4220 of file C4Landscape.cpp.

References C4M_MaxTexIndex, C4MaterialCore::Light, C4MaterialMap::Map, MatDensity(), MaterialMap, MatValid(), PixCol2Mat(), and C4MaterialCore::Placement.

Referenced by HandleTexMapUpdate(), Init(), and PixCol2Mat().

4221 {
4222  int32_t i;
4223  for (i = 0; i < C4M_MaxTexIndex; i++) p->Pix2Mat[i] = PixCol2Mat(i);
4224  for (i = 0; i < C4M_MaxTexIndex; i++) p->Pix2Dens[i] = MatDensity(p->Pix2Mat[i]);
4225  for (i = 0; i < C4M_MaxTexIndex; i++) p->Pix2Place[i] = MatValid(p->Pix2Mat[i]) ? ::MaterialMap.Map[p->Pix2Mat[i]].Placement : 0;
4226  for (i = 0; i < C4M_MaxTexIndex; i++) p->Pix2Light[i] = MatValid(p->Pix2Mat[i]) && (::MaterialMap.Map[p->Pix2Mat[i]].Light>0);
4227  p->Pix2Place[0] = 0;
4228  // clear bridge mat conversion buffers
4229  std::fill(p->BridgeMatConversion.begin(), p->BridgeMatConversion.end(), nullptr);
4230 }
C4Material * Map
Definition: C4Material.h:169
int32_t PixCol2Mat(BYTE pixc)
int32_t MatDensity(int32_t mat)
Definition: C4Material.h:240
int32_t Light
Definition: C4Material.h:113
const int C4M_MaxTexIndex
Definition: C4Constants.h:51
int32_t Placement
Definition: C4Material.h:112
C4MaterialMap MaterialMap
Definition: C4Material.cpp:974
bool MatValid(int32_t mat)
Definition: C4Material.h:210
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ Transparent


The documentation for this class was generated from the following files: