OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 ScanSideOpen ()
 
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 ( )

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

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

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

Definition at line 3798 of file C4Landscape.cpp.

Referenced by C4FoWLightSection::Update().

3799 {
3800  return p->PixCnt[(x / 17) * p->PixCntPitch + (y / 15)] > 0;
3801 }

Here is the caller graph for this function:

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

Definition at line 3763 of file C4Landscape.cpp.

References _GetBackPix().

3764 {
3765  return p->Pix2Dens[_GetBackPix(x, y)];
3766 }
BYTE _GetBackPix(int32_t x, int32_t y) const

Here is the call graph for this function:

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

Definition at line 3758 of file C4Landscape.cpp.

References _GetBackPix().

3759 {
3760  return p->Pix2Mat[_GetBackPix(x, y)];
3761 }
BYTE _GetBackPix(int32_t x, int32_t y) const

Here is the call graph for this function:

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

Definition at line 3725 of file C4Landscape.cpp.

References BREAKPOINT_HERE.

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

3726 {
3727 #ifdef _DEBUG
3728  if (x < 0 || y < 0 || x >= p->Width || y >= p->Height) { BREAKPOINT_HERE; }
3729 #endif
3730  return p->Surface8Bkg->_GetPix(x, y);
3731 }
#define BREAKPOINT_HERE

Here is the caller graph for this function:

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

Definition at line 3768 of file C4Landscape.cpp.

References _GetBackPix().

3769 {
3770  return p->Pix2Place[_GetBackPix(x, y)];
3771 }
BYTE _GetBackPix(int32_t x, int32_t y) const

Here is the call graph for this function:

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

Definition at line 3700 of file C4Landscape.cpp.

References _GetPix().

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

3701 {
3702  return p->Pix2Dens[_GetPix(x, y)];
3703 }
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:

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

Definition at line 3793 of file C4Landscape.cpp.

References _GetBackPix(), and _GetPix().

3794 {
3795  return _GetBackPix(x, y) == 0 || p->Pix2Light[_GetPix(x, y)];
3796 }
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:

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

Definition at line 3695 of file C4Landscape.cpp.

References _GetPix().

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

3696 {
3697  return p->Pix2Mat[_GetPix(x, y)];
3698 }
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:

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

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

3663 {
3664 #ifdef _DEBUG
3665  if (x < 0 || y < 0 || x >= p->Width || y >= p->Height) { BREAKPOINT_HERE; }
3666 #endif
3667  return p->Surface8->_GetPix(x, y);
3668 }
#define BREAKPOINT_HERE

Here is the caller graph for this function:

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

Definition at line 3705 of file C4Landscape.cpp.

References _GetPix().

Referenced by C4LandscapeRenderGL::Update().

3706 {
3707  return p->Pix2Place[_GetPix(x, y)];
3708 }
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:

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

Definition at line 3812 of file C4Landscape.cpp.

References CPolyEdge::y.

Referenced by C4PXS::Execute().

3813 {
3814  x /= 17; y /= 15; x2 /= 17; y2 /= 15;
3815  while (x != x2 && y != y2)
3816  {
3817  if (p->PixCnt[x * p->PixCntPitch + y])
3818  return false;
3819  if (x > x2) x--; else x++;
3820  if (y > y2) y--; else y++;
3821  }
3822  if (x != x2)
3823  do
3824  {
3825  if (p->PixCnt[x * p->PixCntPitch + y])
3826  return false;
3827  if (x > x2) x--; else x++;
3828  } while (x != x2);
3829  else
3830  while (y != y2)
3831  {
3832  if (p->PixCnt[x * p->PixCntPitch + y])
3833  return false;
3834  if (y > y2) y--; else y++;
3835  }
3836  return !p->PixCnt[x * p->PixCntPitch + y];
3837 }

Here is the caller graph for this function:

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

Definition at line 805 of file C4Landscape.cpp.

References _GetPix(), 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().

806 {
807  if (Config.General.DebugRec)
808  {
809  C4RCSetPix rc;
810  rc.x = x; rc.y = y; rc.clr = fgPix; rc.bgClr = fgPix;
811  AddDbgRec(RCT_SetPix, &rc, sizeof(rc));
812  }
813  assert(x >= 0 && y >= 0 && x < GetWidth() && y < GetHeight());
814  // get pixel and resolve transparency to already existing pixel
815  BYTE opix = _GetPix(x, y);
816  if (fgPix == Transparent) fgPix = opix;
817  if (bgPix == Transparent) bgPix = p->Surface8Bkg->_GetPix(x, y);
818  // check pixel
819  if (fgPix == opix && bgPix == p->Surface8Bkg->_GetPix(x, y)) return true;
820  // count pixels
821  if (p->Pix2Dens[fgPix])
822  {
823  if (!p->Pix2Dens[opix]) p->PixCnt[(y / 15) + (x / 17) * p->PixCntPitch]++;
824  }
825  else
826  {
827  if (p->Pix2Dens[opix]) p->PixCnt[(y / 15) + (x / 17) * p->PixCntPitch]--;
828  }
829  // count material
830  assert(!fgPix || MatValid(p->Pix2Mat[fgPix]));
831  int32_t omat = p->Pix2Mat[opix], nmat = p->Pix2Mat[fgPix];
832  if (opix) p->MatCount[omat]--;
833  if (fgPix) p->MatCount[nmat]++;
834  // count effective material
835  if (omat != nmat)
836  {
837  if (fgPix && ::MaterialMap.Map[nmat].MinHeightCount)
838  {
839  // Check for material above & below
840  int iMinHeight = ::MaterialMap.Map[nmat].MinHeightCount,
841  iBelow = GetMatHeight(x, y + 1, +1, nmat, iMinHeight),
842  iAbove = GetMatHeight(x, y - 1, -1, nmat, iMinHeight);
843  // Will be above treshold?
844  if (iBelow + iAbove + 1 >= iMinHeight)
845  {
846  int iChange = 1;
847  // Check for heights below threshold
848  if (iBelow < iMinHeight) iChange += iBelow;
849  if (iAbove < iMinHeight) iChange += iAbove;
850  // Change
851  p->EffectiveMatCount[nmat] += iChange;
852  }
853  }
854  if (opix && ::MaterialMap.Map[omat].MinHeightCount)
855  {
856  // Check for material above & below
857  int iMinHeight = ::MaterialMap.Map[omat].MinHeightCount,
858  iBelow = GetMatHeight(x, y + 1, +1, omat, iMinHeight),
859  iAbove = GetMatHeight(x, y - 1, -1, omat, iMinHeight);
860  // Not already below threshold?
861  if (iBelow + iAbove + 1 >= iMinHeight)
862  {
863  int iChange = 1;
864  // Check for heights that will get below threshold
865  if (iBelow < iMinHeight) iChange += iBelow;
866  if (iAbove < iMinHeight) iChange += iAbove;
867  // Change
868  p->EffectiveMatCount[omat] -= iChange;
869  }
870  }
871  }
872  // set 8bpp-surface only!
873  p->Surface8->SetPix(x, y, fgPix);
874  p->Surface8Bkg->SetPix(x, y, bgPix);
875  // note for relight
876  if (p->pLandscapeRender)
877  {
878  C4Rect CheckRect = p->pLandscapeRender->GetAffectedRect(C4Rect(x, y, 1, 1));
879  for (int32_t i = 0; i < C4LS_MaxRelights; i++)
880  if (!p->Relights[i].Wdt || p->Relights[i].Overlap(CheckRect) || i + 1 >= C4LS_MaxRelights)
881  {
882  p->Relights[i].Add(CheckRect);
883  break;
884  }
885  // Invalidate FoW
886  if (p->pFoW)
887  p->pFoW->Invalidate(CheckRect);
888  }
889  // success
890  return true;
891 }
BYTE _GetPix(int32_t x, int32_t y) const
C4Config Config
Definition: C4Config.cpp:833
int32_t GetMatHeight(int32_t x, int32_t y, int32_t iYDir, int32_t iMat, int32_t iMax) const
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
C4MaterialMap MaterialMap
Definition: C4Material.cpp:969
BYTE bgClr
Definition: C4Record.h:126
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
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 893 of file C4Landscape.cpp.

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

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

894 {
895  // set 8bpp-surface only!
896  assert(x >= 0 && y >= 0 && x < GetWidth() && y < GetHeight());
897  if (fgPix != Transparent) p->Surface8->SetPix(x, y, fgPix);
898  if (bgPix != Transparent) p->Surface8Bkg->SetPix(x, y, bgPix);
899 }
int32_t GetHeight() const
static const uint8_t Transparent
Definition: C4Landscape.h:50
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Landscape::ApplyDiff ( C4Group hGroup)

Definition at line 1917 of file C4Landscape.cpp.

References C4CFN_DiffLandscape, C4CFN_DiffLandscapeBkg, C4M_MaxTexIndex, GetHeight(), GetWidth(), CPolyEdge::x, and CPolyEdge::y.

Referenced by Init().

1918 {
1919  std::unique_ptr<CSurface8> pDiff, pDiffBkg;
1920  // Load diff landscape from group
1921  if ((pDiff = GroupReadSurface8(hGroup, C4CFN_DiffLandscape)) == nullptr) return false;
1922  if ((pDiffBkg = GroupReadSurface8(hGroup, C4CFN_DiffLandscapeBkg)) == nullptr) return false;
1923 
1924  // convert all pixels: keep if same material; re-set if different material
1925  BYTE byPix;
1926  for (int32_t y = 0; y < GetHeight(); ++y) for (int32_t x = 0; x < GetWidth(); ++x)
1927  {
1928  if (pDiff->GetPix(x, y) != C4M_MaxTexIndex)
1929  if (p->Surface8->_GetPix(x, y) != (byPix = pDiff->_GetPix(x, y)))
1930  // material has changed here: readjust with new texture
1931  p->Surface8->SetPix(x, y, byPix);
1932  if (pDiffBkg->GetPix(x, y) != C4M_MaxTexIndex)
1933  if (p->Surface8Bkg->_GetPix(x, y) != (byPix = pDiffBkg->_GetPix(x, y)))
1934  p->Surface8Bkg->_SetPix(x, y, byPix);
1935  }
1936 
1937  // done
1938  return true;
1939 }
#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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 3308 of file C4Landscape.cpp.

References GBackSolid().

Referenced by ConstructionCheck().

3309 {
3310  int32_t cx, cy, ascnt = 0;
3311  for (cy = y; cy < y + hgt; cy++)
3312  for (cx = x; cx < x + wdt; cx++)
3313  if (GBackSolid(cx, cy))
3314  ascnt++;
3315  return ascnt;
3316 }
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:231

Here is the call graph for this function:

Here is the caller graph for this function:

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

References BlastFreeShape().

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

Here is the call graph for this function:

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

References C4M_MaxTexIndex, C4M_Vehicle, C4Rect::GetMiddleX(), C4Rect::GetMiddleY(), GetPixDensity(), C4Rect::Hgt, C4Object::MaterialContents, and C4Rect::Wdt.

Referenced by BlastFree().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 901 of file C4Landscape.cpp.

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

Referenced by CheckInstabilityRange().

902 {
903  int32_t mat = GetMat(tx, ty);
904  if (MatValid(mat)) {
905  const C4Material &material = MaterialMap.Map[mat];
906  if (material.Instable)
907  return ::MassMover.Create(tx, ty);
908  // Get rid of single pixels
909  else if (DensitySolid(material.Density) && !material.KeepSinglePixels && recursion_count < 10)
910  if ((!::GBackSolid(tx, ty + 1)) + (!::GBackSolid(tx, ty - 1)) + (!::GBackSolid(tx + 1, ty)) + (!::GBackSolid(tx - 1, ty)) >= 3)
911  {
912  if (!ClearPix(tx, ty)) return false;
913  // Diggable material drops; other material just gets removed
914  if (material.DigFree) ::PXS.Create(mat, itofix(tx), itofix(ty));
915  // check other pixels around this
916  // Note this cannot lead to an endless recursion (unless you do funny stuff like e.g. set DigFree=1 in material Tunnel).
917  // Check recursion anyway, because very large strips of single pixel width might cause sufficient recursion to crash
918  CheckInstability(tx + 1, ty, ++recursion_count);
919  CheckInstability(tx - 1, ty, recursion_count);
920  CheckInstability(tx, ty - 1, recursion_count);
921  CheckInstability(tx, ty + 1, recursion_count);
922  return true;
923  }
924  }
925  return false;
926 }
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:205
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:525
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:969
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:198
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:231

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 928 of file C4Landscape.cpp.

References CheckInstability().

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

929 {
930  if (!CheckInstability(tx, ty))
931  {
932  CheckInstability(tx, ty - 1);
933  CheckInstability(tx, ty - 2);
934  CheckInstability(tx - 1, ty);
935  CheckInstability(tx + 1, ty);
936  }
937 }
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:

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

Definition at line 1371 of file C4Landscape.cpp.

References Undefined.

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

1372 {
1373  if (fClearMapCreator) { p->pMapCreator.reset(); }
1374  // clear sky
1375  if (fClearSky) p->Sky.Clear();
1376  // clear surfaces, if assigned
1377  if (fClearRenderer) { p->pLandscapeRender.reset(); }
1378  p->TopRowPix.clear();
1379  p->BottomRowPix.clear();
1380  p->Surface8.reset();
1381  p->Surface8Bkg.reset();
1382  p->Map.reset();
1383  p->MapBkg.reset();
1384  // clear initial landscape
1385  p->pInitial.reset();
1386  p->pInitialBkg.reset();
1387  p->pFoW.reset();
1388  // clear relight array
1389  for (auto &relight : p->Relights)
1390  relight.Default();
1391  // clear scan
1392  p->ScanX = 0;
1393  p->mode = LandscapeMode::Undefined;
1394  // clear pixel count
1395  p->PixCnt.clear();
1396  p->PixCntPitch = 0;
1397  // clear bridge material conversion temp buffers
1398  for (auto &conv : p->BridgeMatConversion)
1399  conv.reset();
1400 }

Here is the caller graph for this function:

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

Definition at line 493 of file C4Landscape.cpp.

References ClearPix().

494 {
495  std::vector<int32_t> vertices(GetRectangle(tx, ty, wdt, hgt));
496  C4Rect r(tx, ty, wdt, hgt);
497  p->PrepareChange(this, r);
498  p->ForPolygon(this, &vertices[0], vertices.size() / 2, [this](int32_t x, int32_t y) { return ClearPix(x, y); });
499  p->FinishChange(this, r);
500 }
Definition: C4Rect.h:27
bool ClearPix(int32_t tx, int32_t ty)

Here is the call graph for this function:

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

Definition at line 781 of file C4Landscape.cpp.

References SetPix2().

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

782 {
783  // Replace pixel with background pixel
784  BYTE bkgPix = p->Surface8Bkg->GetPix(tx, ty);
785  return SetPix2(tx, ty, bkgPix, bkgPix);
786 }
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:

void C4Landscape::ClearPointers ( C4Object pObj)

Definition at line 788 of file C4Landscape.cpp.

Referenced by C4Game::ClearPointers().

789 {
790  if (p->pFoW) p->pFoW->Remove(pObj);
791 }

Here is the caller graph for this function:

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

Definition at line 4002 of file C4Landscape.cpp.

References GetHeight(), and GetWidth().

Referenced by DrawDefMap(), and DrawMap().

4003 {
4004  // clip by bounds
4005  if (rX < 0) { rWdt += rX; rX = 0; }
4006  if (rY < 0) { rHgt += rY; rY = 0; }
4007  int32_t iOver;
4008 
4009  iOver = rX + rWdt - GetWidth();
4010  if (iOver > 0)
4011  rWdt -= iOver;
4012 
4013  iOver = rY + rHgt - GetHeight();
4014  if (iOver > 0)
4015  rHgt -= iOver;
4016 
4017  // anything left inside the bounds?
4018  return rWdt > 0 && rHgt > 0;
4019 }
int32_t GetHeight() const
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Landscape::CompileFunc ( StdCompiler pComp)

Definition at line 1402 of file C4Landscape.cpp.

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

1403 {
1404  pComp->Value(mkNamingAdapt(p->MapSeed, "MapSeed", 0));
1405  pComp->Value(mkNamingAdapt(p->LeftOpen, "LeftOpen", 0));
1406  pComp->Value(mkNamingAdapt(p->RightOpen, "RightOpen", 0));
1407  pComp->Value(mkNamingAdapt(p->TopOpen, "TopOpen", 0));
1408  pComp->Value(mkNamingAdapt(p->BottomOpen, "BottomOpen", 0));
1409  pComp->Value(mkNamingAdapt(mkCastIntAdapt(p->Gravity), "Gravity", DefaultGravAccel));
1410  pComp->Value(mkNamingAdapt(p->Modulation, "MatModulation", 0U));
1411  pComp->Value(mkNamingAdapt(mkCastIntAdapt(p->mode), "Mode", LandscapeMode::Undefined));
1412 
1413  if (pComp->isDeserializer())
1414  {
1415  int32_t ambient_brightness;
1416  pComp->Value(mkNamingAdapt(ambient_brightness, "AmbientBrightness", 255));
1417  if (p->pFoW) p->pFoW->Ambient.SetBrightness(ambient_brightness / static_cast<double>(255));
1418  }
1419  else
1420  {
1421  if (p->pFoW)
1422  {
1423  int32_t ambient_brightness = static_cast<int32_t>(p->pFoW->Ambient.GetBrightness() * 255 + 0.5);
1424  pComp->Value(mkNamingAdapt(ambient_brightness, "AmbientBrightness", 255));
1425  }
1426  }
1427 }
StdCastAdapt< T, int32_t > mkCastIntAdapt(T &rValue)
Definition: StdAdaptors.h:255
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:

void C4Landscape::Default ( )

Definition at line 1941 of file C4Landscape.cpp.

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

1942 {
1943  p = std::make_unique<P>();
1944 }

Here is the caller graph for this function:

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

References DigFreeShape().

Referenced by C4Object::DoMovement().

509 {
510  std::vector<int32_t> vertices(GetRoundPolygon(tx, ty, rad, 80));
511  return DigFreeShape(&vertices[0], vertices.size(), by_object, no_dig2objects, no_instability_check);
512 }
int32_t DigFreeShape(int *vtcs, int length, C4Object *by_object=nullptr, bool no_dig2objects=false, bool no_instability_check=false)

Here is the call graph for this function:

Here is the caller graph for this function:

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

References DigFreeShape().

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

503 {
504  std::vector<int32_t> vertices(GetRectangle(tx, ty, wdt, hgt));
505  return DigFreeShape(&vertices[0], vertices.size(), by_object, no_dig2objects, no_instability_check);
506 }
int32_t DigFreeShape(int *vtcs, int length, C4Object *by_object=nullptr, bool no_dig2objects=false, bool no_instability_check=false)

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 561 of file C4Landscape.cpp.

References Game, C4Rect::GetBottom(), C4Rect::GetMiddleX(), C4Game::iTick5, and C4Object::MaterialContents.

Referenced by DigFree(), and DigFreeRect().

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

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Landscape::DoRelights ( )

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

398 {
399  if (!p->pLandscapeRender) return true;
400  for (int32_t i = 0; i < C4LS_MaxRelights; i++)
401  {
402  if (!p->Relights[i].Wdt)
403  break;
404  // Remove all solid masks in the (twice!) extended region around the change
405  C4Rect SolidMaskRect = p->pLandscapeRender->GetAffectedRect(p->Relights[i]);
406  C4SolidMask * pSolid;
407  for (pSolid = C4SolidMask::Last; pSolid; pSolid = pSolid->Prev)
408  pSolid->RemoveTemporary(SolidMaskRect);
409  // Perform the update
410  p->pLandscapeRender->Update(p->Relights[i], this);
411  if (p->pFoW) p->pFoW->Ambient.UpdateFromLandscape(*this, p->Relights[i]);
412  // Restore Solidmasks
413  for (pSolid = C4SolidMask::First; pSolid; pSolid = pSolid->Next)
414  pSolid->PutTemporary(SolidMaskRect);
416  // Clear slot
417  p->Relights[i].Default();
418  }
419  return true;
420 }
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:

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

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

377 {
378  uint32_t clrMod = 0xffffffff;
379  if (p->Modulation)
380  {
381  pDraw->ActivateBlitModulation(p->Modulation);
382  clrMod = p->Modulation;
383  }
384  // blit landscape
385  if (::GraphicsSystem.Show8BitSurface == 1)
386  pDraw->Blit8Fast(p->Surface8.get(), cgo.TargetX, cgo.TargetY, cgo.Surface, cgo.X, cgo.Y, cgo.Wdt, cgo.Hgt);
387  else if (::GraphicsSystem.Show8BitSurface == 2)
388  pDraw->Blit8Fast(p->Surface8Bkg.get(), cgo.TargetX, cgo.TargetY, cgo.Surface, cgo.X, cgo.Y, cgo.Wdt, cgo.Hgt);
389  else if (p->pLandscapeRender)
390  {
391  DoRelights();
392  p->pLandscapeRender->Draw(cgo, pLight, clrMod);
393  }
394  if (p->Modulation) pDraw->DeactivateBlitModulation();
395 }
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:

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

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

3520 {
3521  // get upper-left/lower-right - corners
3522  int32_t iX0 = std::min(iX1, iX2); int32_t iY0 = std::min(iY1, iY2);
3523  iX2 = std::max(iX1, iX2); iY2 = std::max(iY1, iY2); iX1 = iX0; iY1 = iY0;
3524  BYTE byCol, byColBkg;
3525  // Get map color index by material-texture
3526  if (!p->GetMapColorIndex(szMaterial, szTexture, byCol)) return false;
3527  if (!p->GetMapColorIndex(szBackMaterial, szBackTexture, byColBkg)) return false;
3528  // Get material shape size
3529  C4Texture *texture = ::TextureMap.GetTexture(szTexture);
3530  int32_t shape_wdt = 0, shape_hgt = 0;
3531  if (texture && texture->GetMaterialShape())
3532  {
3533  shape_wdt = texture->GetMaterialShape()->GetMaxPolyWidth() / p->MapZoom;
3534  shape_hgt = texture->GetMaterialShape()->GetMaxPolyHeight() / p->MapZoom;
3535  }
3536  // Draw
3537  switch (p->mode)
3538  {
3539  // Dynamic: ignore
3541  break;
3542  // Static: draw to map by material-texture-index, chunk-o-zoom to landscape
3543  case LandscapeMode::Static:
3544  // Draw to map
3545  iX1 /= p->MapZoom; iY1 /= p->MapZoom; iX2 /= p->MapZoom; iY2 /= p->MapZoom;
3546  p->Map->Box(iX1, iY1, iX2, iY2, byCol);
3547  p->MapBkg->Box(iX1, iY1, iX2, iY2, byColBkg);
3548  // Update landscape
3549  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);
3550  SetMapChanged();
3551  break;
3552  // Exact: draw directly to landscape by color & pattern
3553  case LandscapeMode::Exact:
3554  C4Rect BoundingBox(iX1, iY1, iX2 - iX1 + 1, iY2 - iY1 + 1);
3555  // Draw to landscape
3556  p->PrepareChange(this, BoundingBox);
3557  p->Surface8->Box(iX1, iY1, iX2, iY2, byCol);
3558  p->Surface8Bkg->Box(iX1, iY1, iX2, iY2, byColBkg);
3559  p->FinishChange(this, BoundingBox);
3560  break;
3561  }
3562  return true;
3563 }
Definition: C4Rect.h:27
uint8_t BYTE
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
class C4TextureShape * GetMaterialShape() const
Definition: C4Texture.h:40
int32_t GetMaxPolyHeight() const
const char * GetTexture(int32_t iIndex)
Definition: C4Texture.cpp:494
int32_t GetMaxPolyWidth() const
void SetMapChanged()

Here is the call graph for this function:

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

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

3396 {
3397  BYTE byCol, byColBkg;
3398  // Get map color index by material-texture
3399  if (!p->GetMapColorIndex(szMaterial, szTexture, byCol)) return false;
3400  if (!p->GetMapColorIndex(szBackMaterial, szBackTexture, byColBkg)) return false;
3401  // Get material shape size
3402  C4Texture *texture = ::TextureMap.GetTexture(szTexture);
3403  int32_t shape_wdt = 0, shape_hgt = 0;
3404  if (texture && texture->GetMaterialShape())
3405  {
3406  shape_wdt = texture->GetMaterialShape()->GetMaxPolyWidth() / p->MapZoom;
3407  shape_hgt = texture->GetMaterialShape()->GetMaxPolyHeight() / p->MapZoom;
3408  }
3409  // Draw
3410  switch (p->mode)
3411  {
3412  // Dynamic: ignore
3414  break;
3415  // Static: draw to map by material-texture-index, chunk-o-zoom to landscape
3416  case LandscapeMode::Static:
3417  {
3418  // Draw to map
3419  int32_t iRadius = std::max<int32_t>(2 * iGrade / p->MapZoom, 1);
3420  if (iRadius == 1)
3421  {
3422  p->Map->SetPix(iX / p->MapZoom, iY / p->MapZoom, byCol);
3423  p->MapBkg->SetPix(iX / p->MapZoom, iY / p->MapZoom, byColBkg);
3424  }
3425  else
3426  {
3427  p->Map->Circle(iX / p->MapZoom, iY / p->MapZoom, iRadius, byCol);
3428  p->MapBkg->Circle(iX / p->MapZoom, iY / p->MapZoom, iRadius, byColBkg);
3429  }
3430  // Update landscape
3431  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);
3432  SetMapChanged();
3433  }
3434  break;
3435  // Exact: draw directly to landscape by color & pattern
3436  case LandscapeMode::Exact:
3437  C4Rect BoundingBox(iX - iGrade - 1, iY - iGrade - 1, iGrade * 2 + 2, iGrade * 2 + 2);
3438  // Draw to landscape
3439  p->PrepareChange(this, BoundingBox);
3440  p->Surface8->Circle(iX, iY, iGrade, byCol);
3441  p->Surface8Bkg->Circle(iX, iY, iGrade, byColBkg);
3442  p->FinishChange(this, BoundingBox);
3443  break;
3444  }
3445  return true;
3446 }
Definition: C4Rect.h:27
uint8_t BYTE
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
class C4TextureShape * GetMaterialShape() const
Definition: C4Texture.h:40
int32_t GetMaxPolyHeight() const
const char * GetTexture(int32_t iIndex)
Definition: C4Texture.cpp:494
int32_t GetMaxPolyWidth() const
void SetMapChanged()

Here is the call graph for this function:

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

3566 {
3567  BYTE byColor;
3568  if (!p->GetMapColorIndex(szMaterial, szTexture, byColor)) return false;
3569 
3570  int32_t iMaterial = ::MaterialMap.Get(szMaterial);
3571  if (!MatValid(iMaterial))
3572  return false;
3573 
3575 
3576  C4Rect BoundingBox(tx - 5, ty - 5, wdt + 10, hgt + 10);
3577  p->PrepareChange(this, BoundingBox);
3578 
3579  // assign clipper
3580  p->Surface8->Clip(BoundingBox.x, BoundingBox.y, BoundingBox.x + BoundingBox.Wdt, BoundingBox.y + BoundingBox.Hgt);
3581  p->Surface8Bkg->Clip(BoundingBox.x, BoundingBox.y, BoundingBox.x + BoundingBox.Wdt, BoundingBox.y + BoundingBox.Hgt);
3583 
3584  // draw all chunks
3585  int32_t x, y;
3586  for (x = 0; x < icntx; x++)
3587  for (y = 0; y < icnty; y++)
3588  p->DrawChunk(this, tx + wdt*x / icntx, ty + hgt*y / icnty, wdt / icntx, hgt / icnty, byColor, bIFT ? p->DefaultBkgMat(byColor) : 0, shape, Random(1000));
3589 
3590  // remove clipper
3591  p->Surface8->NoClip();
3592  p->Surface8Bkg->NoClip();
3593 
3594  p->FinishChange(this, BoundingBox);
3595 
3596  // success
3597  return true;
3598 }
uint32_t Random()
Definition: C4Random.cpp:43
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
C4SLandscape Landscape
Definition: C4Scenario.h:234
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:186
int32_t Get(const char *szMaterial)
Definition: C4Material.cpp:361
C4MaterialCoreShape MapChunkType
Definition: C4Material.h:91
C4MaterialMap MaterialMap
Definition: C4Material.cpp:969
bool NoPrimaryClipper()
Definition: C4Draw.cpp:237
bool MatValid(int32_t mat)
Definition: C4Material.h:210

Here is the call graph for this function:

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

Definition at line 3964 of file C4Landscape.cpp.

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

3965 {
3966  // safety
3967  if (!szMapDef || !p->pMapCreator) return false;
3968  // clip to landscape size
3969  if (!ClipRect(iX, iY, iWdt, iHgt)) return false;
3970  // get needed map size
3971  int32_t iMapWdt = (iWdt - 1) / p->MapZoom + 1;
3972  int32_t iMapHgt = (iHgt - 1) / p->MapZoom + 1;
3973  bool fSuccess = false;
3974  // render map
3975  C4MCMap *pMap = p->pMapCreator->GetMap(szMapDef);
3976  if (!pMap) return false;
3977  pMap->SetSize(iMapWdt, iMapHgt);
3978  CSurface8* sfcMap = nullptr;
3979  CSurface8* sfcMapBkg = nullptr;
3980  if (p->pMapCreator->Render(szMapDef, sfcMap, sfcMapBkg))
3981  {
3982  // map to landscape
3983  fSuccess = p->MapToLandscape(this, *sfcMap, *sfcMapBkg, 0, 0, iMapWdt, iMapHgt, iX, iY, ignoreSky);
3984  // cleanup
3985  delete sfcMap;
3986  delete sfcMapBkg;
3987  }
3988  // done
3989  return fSuccess;
3990 }
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:

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

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

3470 {
3471  // Get map color index by material-texture
3472  uint8_t line_color, line_color_bkg;
3473  if (!p->GetMapColorIndex(szMaterial, szTexture, line_color)) return false;
3474  if (!p->GetMapColorIndex(szBackMaterial, szBackTexture, line_color_bkg)) return false;
3475  // Get material shape size
3476  C4Texture *texture = ::TextureMap.GetTexture(szTexture);
3477  int32_t shape_wdt = 0, shape_hgt = 0;
3478  if (texture && texture->GetMaterialShape())
3479  {
3480  shape_wdt = texture->GetMaterialShape()->GetMaxPolyWidth() / p->MapZoom;
3481  shape_hgt = texture->GetMaterialShape()->GetMaxPolyHeight() / p->MapZoom;
3482  }
3483  // Draw
3484  switch (p->mode)
3485  {
3486  // Dynamic: ignore
3488  break;
3489  // Static: draw to map by material-texture-index, chunk-o-zoom to landscape
3490  case LandscapeMode::Static:
3491  {
3492  // Draw to map
3493  int32_t iRadius = std::max<int32_t>(2 * iGrade / p->MapZoom, 1);
3494  iX1 /= p->MapZoom; iY1 /= p->MapZoom; iX2 /= p->MapZoom; iY2 /= p->MapZoom;
3495  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); });
3496  // Update landscape
3497  int iUpX = std::min(iX1, iX2) - iRadius - 1;
3498  int iUpY = std::min(iY1, iY2) - iRadius - 1;
3499  int iUpWdt = Abs(iX2 - iX1) + 2 * iRadius + 2;
3500  int iUpHgt = Abs(iY2 - iY1) + 2 * iRadius + 2;
3501  p->MapToLandscape(this, *p->Map, *p->MapBkg, iUpX - shape_wdt, iUpY - shape_hgt, iUpWdt + shape_wdt * 2, iUpHgt + shape_hgt * 2);
3502  SetMapChanged();
3503  }
3504  break;
3505  // Exact: draw directly to landscape by color & pattern
3506  case LandscapeMode::Exact:
3507  // Set texture pattern & get material color
3508  C4Rect BoundingBox(iX1 - iGrade, iY1 - iGrade, iGrade * 2 + 1, iGrade * 2 + 1);
3509  BoundingBox.Add(C4Rect(iX2 - iGrade, iY2 - iGrade, iGrade * 2 + 1, iGrade * 2 + 1));
3510  // Draw to landscape
3511  p->PrepareChange(this, BoundingBox);
3512  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); });
3513  p->FinishChange(this, BoundingBox);
3514  break;
3515  }
3516  return true;
3517 }
Definition: C4Rect.h:27
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
class C4TextureShape * GetMaterialShape() const
Definition: C4Texture.h:40
int32_t GetMaxPolyHeight() const
const char * GetTexture(int32_t iIndex)
Definition: C4Texture.cpp:494
T Abs(T val)
Definition: Standard.h:42
int32_t GetMaxPolyWidth() const
void SetMapChanged()

Here is the call graph for this function:

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

Definition at line 3934 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.

3935 {
3936  // safety
3937  if (!szMapDef) return false;
3938  // clip to landscape size
3939  if (!ClipRect(iX, iY, iWdt, iHgt)) return false;
3940  // get needed map size
3941  int32_t iMapWdt = (iWdt - 1) / p->MapZoom + 1;
3942  int32_t iMapHgt = (iHgt - 1) / p->MapZoom + 1;
3943  C4SLandscape FakeLS = Game.C4S.Landscape;
3944  FakeLS.MapWdt.Set(iMapWdt, 0, iMapWdt, iMapWdt);
3945  FakeLS.MapHgt.Set(iMapHgt, 0, iMapHgt, iMapHgt);
3946  // create map creator
3947  C4MapCreatorS2 MapCreator(&FakeLS, &::TextureMap, &::MaterialMap, Game.StartupPlayerCount);
3948  // read file
3949  MapCreator.ReadScript(szMapDef);
3950  // render map
3951  CSurface8* sfcMap = nullptr;
3952  CSurface8* sfcMapBkg = nullptr;
3953  if (!MapCreator.Render(nullptr, sfcMap, sfcMapBkg))
3954  return false;
3955  // map it to the landscape
3956  bool fSuccess = p->MapToLandscape(this, *sfcMap, *sfcMapBkg, 0, 0, iMapWdt, iMapHgt, iX, iY, ignoreSky);
3957  // cleanup
3958  delete sfcMap;
3959  delete sfcMapBkg;
3960  // return whether successful
3961  return fSuccess;
3962 }
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
C4SLandscape Landscape
Definition: C4Scenario.h:234
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:176
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:176
C4MaterialMap MaterialMap
Definition: C4Material.cpp:969

Here is the call graph for this function:

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

Definition at line 938 of file C4Landscape.cpp.

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

Referenced by DoBridge().

939 {
940  int32_t cx, cy;
941  for (cy = ty; cy < ty + hgt; cy++)
942  for (cx = tx; cx < tx + wdt; cx++)
943  if ((MatDensity(mat) >= GetDensity(cx, cy)))
944  SetPix2(cx, cy, Mat2PixColDefault(mat), p->Surface8Bkg->GetPix(cx, cy));
945 }
int32_t MatDensity(int32_t mat)
Definition: C4Material.h:240
int32_t GetDensity(int32_t x, int32_t y) const
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:

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

Definition at line 3600 of file C4Landscape.cpp.

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

Referenced by DrawQuad().

3601 {
3602  if (length < 6) return false;
3603  if (length % 2 == 1) return false;
3604  // get texture
3605  int32_t iMatTex = ::TextureMap.GetIndexMatTex(szMaterial);
3606  if (!iMatTex) return false;
3607  uint8_t mcol = MatTex2PixCol(iMatTex);
3608  // get background texture
3609  uint8_t mcolBkg = 0;
3610  if (szBackMaterial != nullptr)
3611  {
3612  const int32_t iBackMatTex = ::TextureMap.GetIndexMatTex(szBackMaterial);
3613  if (!iBackMatTex) return false;
3614  mcolBkg = MatTex2PixCol(iBackMatTex);
3615  }
3616  // do bridging?
3617  uint8_t *conversion_map = nullptr;
3618  if (fDrawBridge)
3619  {
3620  conversion_map = p->GetBridgeMatConversion(this, MatTex2PixCol(iMatTex));
3621  mcolBkg = Transparent;
3622  }
3623  // prepare pixel count update
3624  C4Rect BoundingBox = getBoundingBox(vtcs, length);
3625  // draw polygon
3626  p->PrepareChange(this, BoundingBox);
3627  p->ForPolygon(this, vtcs, length / 2, nullptr, nullptr, mcol, mcolBkg, conversion_map);
3628  p->FinishChange(this, BoundingBox);
3629  return true;
3630 }
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:

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

References DrawPolygon().

3867 {
3868  // set vertices
3869  int32_t vtcs[8];
3870  vtcs[0] = iX1; vtcs[1] = iY1;
3871  vtcs[2] = iX2; vtcs[3] = iY2;
3872  vtcs[4] = iX3; vtcs[5] = iY3;
3873  vtcs[6] = iX4; vtcs[7] = iY4;
3874  return DrawPolygon(vtcs, 8, szMaterial, szBackMaterial, fDrawBridge);
3875 }
bool DrawPolygon(int *vtcs, int length, const char *szMaterial, const char *szBackMaterial, bool fDrawBridge)

Here is the call graph for this function:

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:129
bool DoRelights()

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 964 of file C4Landscape.cpp.

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

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

965 {
966  int32_t mat = GetMat(fx, fy);
967  if (mat == MNone) return MNone;
968  FindMatTop(mat, fx, fy, distant_first);
969  ClearPix(fx, fy);
970  CheckInstabilityRange(fx, fy);
971  return mat;
972 }
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:

int32_t C4Landscape::FastSolidCheckNextX ( int32_t  x)
static

Definition at line 3803 of file C4Landscape.cpp.

Referenced by C4FoWLightSection::Update().

3804 {
3805  return (x / 17) * 17 + 17;
3806 }

Here is the caller graph for this function:

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

Definition at line 3091 of file C4Landscape.cpp.

References C4M_Solid, and GetDensity().

Referenced by C4MassMover::Execute().

3092 {
3093  assert(mdens <= C4M_Solid); // mdens normalized in InsertMaterial
3094 
3095  int32_t cslide;
3096  bool fLeft = true, fRight = true;
3097 
3098  // One downwards
3099  if (GetDensity(fx, fy + ydir) < mdens) { fy += ydir; return true; }
3100 
3101  // Find downwards slide path
3102  for (cslide = 1; (cslide <= mslide) && (fLeft || fRight); cslide++)
3103  {
3104  // Check left
3105  if (fLeft)
3106  {
3107  if (GetDensity(fx - cslide, fy) >= mdens) // Left clogged
3108  fLeft = false;
3109  else if (GetDensity(fx - cslide, fy + ydir) < mdens) // Left slide okay
3110  {
3111  fx--; return true;
3112  }
3113  }
3114  // Check right
3115  if (fRight)
3116  {
3117  if (GetDensity(fx + cslide, fy) >= mdens) // Right clogged
3118  fRight = false;
3119  else if (GetDensity(fx + cslide, fy + ydir) < mdens) // Right slide okay
3120  {
3121  fx++; return true;
3122  }
3123  }
3124  }
3125 
3126  return false;
3127 }
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:

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

Definition at line 3170 of file C4Landscape.cpp.

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

Referenced by InsertMaterial().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 3130 of file C4Landscape.cpp.

References C4M_Solid, and GetDensity().

Referenced by InsertMaterial(), and mrfInsertCheck().

3131 {
3132  assert(mdens <= C4M_Solid); // mdens normalized in InsertMaterial and mrfInsertCheck
3133  int32_t cslide;
3134  bool fLeft = true, fRight = true;
3135 
3136  // One downwards
3137  if (GetDensity(fx, fy + ydir) < mdens) { fy += ydir; return true; }
3138 
3139  // Find downwards slide path
3140  for (cslide = 1; (cslide <= mslide) && (fLeft || fRight); cslide++)
3141  {
3142  // Check left
3143  if (fLeft)
3144  {
3145  if (GetDensity(fx - cslide, fy) >= mdens && GetDensity(fx - cslide, fy + ydir) >= mdens) // Left clogged
3146  fLeft = false;
3147  else if (GetDensity(fx - cslide, fy + ydir) < mdens) // Left slide okay
3148  {
3149  fx -= cslide; fy += ydir; return true;
3150  }
3151  }
3152  // Check right
3153  if (fRight)
3154  {
3155  if (GetDensity(fx + cslide, fy) >= mdens && GetDensity(fx + cslide, fy + ydir) >= mdens) // Right clogged
3156  fRight = false;
3157  else if (GetDensity(fx + cslide, fy + ydir) < mdens) // Right slide okay
3158  {
3159  fx += cslide; fy += ydir; return true;
3160  }
3161  }
3162  }
3163 
3164  return false;
3165 }
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:

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

Definition at line 3318 of file C4Landscape.cpp.

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

Referenced by ExtractMaterial().

3319 {
3320  int32_t mslide, cslide, tslide, distant_x = 0;
3321  bool fLeft, fRight;
3322 
3323  if (!MatValid(mat)) return;
3324  mslide = ::MaterialMap.Map[mat].MaxSlide;
3325 
3326  do
3327  {
3328  // Catch most common case: Walk upwards until material changes
3329  while (GetMat(x, y - 1) == mat) --y;
3330 
3331  // Find upwards slide
3332  fLeft = true; fRight = true; tslide = 0; distant_x = x;
3333  for (cslide = 1; (cslide <= mslide) && (fLeft || fRight); cslide++)
3334  {
3335  // Left
3336  if (fLeft)
3337  {
3338  if (GetMat(x - cslide, y) != mat) fLeft = false;
3339  else
3340  {
3341  distant_x = x - cslide;
3342  if (GetMat(distant_x, y - 1) == mat) { tslide = -cslide; break; }
3343  }
3344  }
3345  // Right
3346  if (fRight)
3347  {
3348  if (GetMat(x + cslide, y) != mat) fRight = false;
3349  else
3350  {
3351  distant_x = x + cslide;
3352  if (GetMat(distant_x, y - 1) == mat) { tslide = +cslide; break; }
3353  }
3354  }
3355  }
3356 
3357  // Slide
3358  if (tslide) { x += tslide; y--; }
3359 
3360  } while (tslide);
3361 
3362  // return top pixel max slide away from center if desired
3363  if (distant_first) x = distant_x;
3364 
3365 }
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:969
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:

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

Definition at line 3778 of file C4Landscape.cpp.

References GetBackPix().

3779 {
3780  return p->Pix2Dens[GetBackPix(x, y)];
3781 }
BYTE GetBackPix(int32_t x, int32_t y) const

Here is the call graph for this function:

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

Definition at line 3883 of file C4Landscape.cpp.

Referenced by C4EditCursor::ApplyToolPicker().

3884 {
3885  if (!p->MapBkg) return 0;
3886  return p->MapBkg->GetPix(iX, iY);
3887 }

Here is the caller graph for this function:

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

Definition at line 3773 of file C4Landscape.cpp.

References GetBackPix().

Referenced by C4EditCursor::UpdateStatusBar().

3774 {
3775  return p->Pix2Mat[GetBackPix(x, y)];
3776 }
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:

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

Definition at line 3733 of file C4Landscape.cpp.

References GetHeight(), GetWidth(), Mat2PixColDefault(), and MTunnel.

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

3734 {
3735  // Border checks
3736  if (x < 0)
3737  {
3738  if (y < p->LeftOpen) return 0;
3739  else return Mat2PixColDefault(MTunnel);
3740  }
3741  if (static_cast<uint32_t>(x) >= static_cast<uint32_t>(GetWidth()))
3742  {
3743  if (y < p->RightOpen) return 0;
3744  else return Mat2PixColDefault(MTunnel);
3745  }
3746  if (y < 0)
3747  {
3748  return p->DefaultBkgMat(p->TopRowPix[x]);
3749  }
3750  if (static_cast<uint32_t>(y) >= static_cast<uint32_t>(GetHeight()))
3751  {
3752  return p->DefaultBkgMat(p->BottomRowPix[x]);
3753  }
3754 
3755  return p->Surface8Bkg->_GetPix(x, y);
3756 }
int32_t MTunnel
Definition: C4Material.cpp:36
int32_t GetHeight() const
BYTE Mat2PixColDefault(int32_t mat)
Definition: C4Material.h:235
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 3783 of file C4Landscape.cpp.

References GetBackPix().

3784 {
3785  return p->Pix2Place[GetBackPix(x, y)];
3786 }
BYTE GetBackPix(int32_t x, int32_t y) const

Here is the call graph for this function:

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

Definition at line 3715 of file C4Landscape.cpp.

References GetPix().

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

3716 {
3717  return p->Pix2Dens[GetPix(x, y)];
3718 }
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:

int32_t C4Landscape::GetEffectiveMatCount ( int  material) const

Definition at line 4183 of file C4Landscape.cpp.

4184 {
4185  assert(material >= 0 && material < p->EffectiveMatCount.size());
4186  return p->EffectiveMatCount[material];
4187 }
C4FoW * C4Landscape::GetFoW ( )

Definition at line 4172 of file C4Landscape.cpp.

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

4173 {
4174  return p->pFoW.get();
4175 }

Here is the caller graph for this function:

C4Real C4Landscape::GetGravity ( ) const

Definition at line 3652 of file C4Landscape.cpp.

3653 {
3654  return p->Gravity;
3655 }
bool C4Landscape::GetLight ( int32_t  x,
int32_t  y 
)

Definition at line 3788 of file C4Landscape.cpp.

References GetBackPix(), and GetPix().

3789 {
3790  return GetBackPix(x, y) == 0 || p->Pix2Light[GetPix(x, y)];
3791 }
BYTE GetPix(int32_t x, int32_t y) const
BYTE GetBackPix(int32_t x, int32_t y) const

Here is the call graph for this function:

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

Definition at line 3877 of file C4Landscape.cpp.

Referenced by C4EditCursor::ApplyToolPicker().

3878 {
3879  if (!p->Map) return 0;
3880  return p->Map->GetPix(iX, iY);
3881 }

Here is the caller graph for this function:

int32_t C4Landscape::GetMapZoom ( ) const

Definition at line 3647 of file C4Landscape.cpp.

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

3648 {
3649  return p->MapZoom;
3650 }

Here is the caller graph for this function:

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

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

3711 {
3712  return p->Pix2Mat[GetPix(x, y)];
3713 }
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:

int32_t C4Landscape::GetMatCount ( int  material) const

Definition at line 4177 of file C4Landscape.cpp.

Referenced by C4SolidMask::CheckConsistency().

4178 {
4179  assert(material >= 0 && material < p->MatCount.size());
4180  return p->MatCount[material];
4181 }

Here is the caller graph for this function:

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

Definition at line 2443 of file C4Landscape.cpp.

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

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

2444 {
2445  if (iYDir > 0)
2446  {
2447  iMax = std::min<int32_t>(iMax, GetHeight() - y);
2448  for (int32_t i = 0; i < iMax; i++)
2449  if (_GetMat(x, y + i) != iMat)
2450  return i;
2451  }
2452  else
2453  {
2454  iMax = std::min<int32_t>(iMax, y + 1);
2455  for (int32_t i = 0; i < iMax; i++)
2456  if (_GetMat(x, y - i) != iMat)
2457  return i;
2458  }
2459  return iMax;
2460 }
int32_t _GetMat(int32_t x, int32_t y) const
int32_t GetHeight() const

Here is the call graph for this function:

Here is the caller graph for this function:

LandscapeMode C4Landscape::GetMode ( ) const

Definition at line 3375 of file C4Landscape.cpp.

Referenced by C4EditCursor::ApplyToolBrush(), C4EditCursor::ApplyToolFill(), C4EditCursor::ApplyToolLine(), C4EditCursor::ApplyToolPicker(), C4EditCursor::ApplyToolRect(), C4ToolsDlg::AssertValidBackTexture(), C4ToolsDlg::AssertValidTexture(), C4Console::SaveScenario(), C4ToolsDlg::SetBackMaterial(), C4ToolsDlg::SetLandscapeMode(), and C4ToolsDlg::SetMaterial().

3376 {
3377  return p->mode;
3378 }

Here is the caller graph for this function:

DWORD C4Landscape::GetModulation ( ) const

Definition at line 4000 of file C4Landscape.cpp.

4000 { return p->Modulation; }
CStdPalette * C4Landscape::GetPal ( ) const

Definition at line 3632 of file C4Landscape.cpp.

Referenced by C4PXSSystem::Draw().

3633 {
3634  return p->Surface8 ? p->Surface8->pPal : nullptr;
3635 }

Here is the caller graph for this function:

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

Definition at line 3670 of file C4Landscape.cpp.

References MCVehic, and CPolyEdge::x.

Referenced by C4Landscape::P::ForPolygon(), GetDensity(), GetLight(), GetMat(), GetPlacement(), PathFreeIgnoreVehiclePix(), C4SolidMask::Put(), C4SolidMask::PutTemporary(), RaiseTerrain(), C4SolidMask::RemoveTemporary(), C4SolidMask::Repair(), and ScanSideOpen().

3671 {
3672  extern BYTE MCVehic;
3673  // Border checks
3674  if (x < 0)
3675  {
3676  if (y < p->LeftOpen) return 0;
3677  else return MCVehic;
3678  }
3679  if (static_cast<uint32_t>(x) >= static_cast<uint32_t>(p->Width))
3680  {
3681  if (y < p->RightOpen) return 0;
3682  else return MCVehic;
3683  }
3684  if (y < 0)
3685  {
3686  return p->TopRowPix[x];
3687  }
3688  if (static_cast<uint32_t>(y) >= static_cast<uint32_t>(p->Height))
3689  {
3690  return p->BottomRowPix[x];
3691  }
3692  return p->Surface8->_GetPix(x, y);
3693 }
uint8_t BYTE
BYTE MCVehic
Definition: C4Material.cpp:37

Here is the caller graph for this function:

int32_t C4Landscape::GetPixDensity ( BYTE  byPix) const

Definition at line 3810 of file C4Landscape.cpp.

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

3810 { return p->Pix2Dens[byPix]; }

Here is the caller graph for this function:

int32_t C4Landscape::GetPixMat ( BYTE  byPix) const

Definition at line 3808 of file C4Landscape.cpp.

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

3808 { return p->Pix2Mat[byPix]; }

Here is the caller graph for this function:

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

Definition at line 3720 of file C4Landscape.cpp.

References GetPix().

3721 {
3722  return p->Pix2Place[GetPix(x, y)];
3723 }
BYTE GetPix(int32_t x, int32_t y) const

Here is the call graph for this function:

C4Sky & C4Landscape::GetSky ( )

Definition at line 4162 of file C4Landscape.cpp.

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

4163 {
4164  return p->Sky;
4165 }

Here is the caller graph for this function:

void C4Landscape::HandleTexMapUpdate ( )

Definition at line 4193 of file C4Landscape.cpp.

References UpdatePixMaps().

Referenced by C4TextureMap::AddEntry().

4194 {
4195  // Pixel maps must be update
4196  UpdatePixMaps();
4197  // Update landscape palette
4198  p->Mat2Pal();
4199 }
void UpdatePixMaps()

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Landscape::HasFoW ( ) const

Definition at line 4167 of file C4Landscape.cpp.

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

4168 {
4169  return p->pFoW != nullptr;
4170 }

Here is the caller graph for this function:

bool C4Landscape::HasMap ( ) const

Definition at line 1704 of file C4Landscape.cpp.

1705 {
1706  return p->Map != nullptr && p->MapBkg != nullptr;
1707 }
bool C4Landscape::Incinerate ( int32_t  x,
int32_t  y,
int32_t  cause_player 
)

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

1092 {
1093  int32_t mat = GetMat(x, y);
1094  if (MatValid(mat))
1095  if (::MaterialMap.Map[mat].Inflammable)
1096  {
1097  C4AulParSet pars(C4VInt(x), C4VInt(y), C4VInt(cause_player));
1099  }
1100  return false;
1101 }
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:969
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:

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

Definition at line 1442 of file C4Landscape.cpp.

References AddDbgRec(), ApplyDiff(), C4CFN_Map, C4CFN_MapBg, C4CFN_MapFg, C4Game::C4S, Clamp(), Clear(), Config, C4ConfigGeneral::DebugRec, Dynamic, C4SVal::Evaluate(), Exact, C4SLandscape::ExactLandscape, C4GraphicsResource::Files, C4Game::FixRandom(), C4SGame::FoWEnabled, Game, C4Scenario::Game, C4Config::General, GetHeight(), GetWidth(), GraphicsResource, C4MapScriptHost::InitializeMap(), C4SLandscape::KeepMapCreator, C4Scenario::Landscape, Load(), C4SLandscape::MapHgt, MapScript, MapToLandscape(), C4SLandscape::MapWdt, C4SLandscape::MapZoom, MaterialMap, C4SVal::Max, C4SLandscape::NoScan, Random(), C4Game::RandomSeed, RCT_Block, RCT_Map, SaveInitial(), C4Game::SetInitProgress(), C4Game::StartupPlayerCount, Static, TextureMap, Undefined, and UpdatePixMaps().

Referenced by C4Game::InitGame().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

1055 {
1056  // Check bounds
1057  if (tx < 0 || ty < 0 || tx >= GetWidth() || ty >= GetHeight())
1058  return InsertMaterialOutsideLandscape(tx, ty, std::min(MatDensity(mat), C4M_Solid));
1059 
1060  // Save back original material so we can insert it later
1061  int omat = 0;
1063  omat = GetMat(tx, ty);
1064 
1065  // Check surroundings for inspiration for texture to use
1066  int n = 0; int pix = -1;
1067  if (tx > 0 && _GetMat(tx - 1, ty) == mat)
1068  if (!Random(++n)) pix = _GetPix(tx - 1, ty);
1069  if (ty > 0 && _GetMat(tx, ty - 1) == mat)
1070  if (!Random(++n)) pix = _GetPix(tx, ty - 1);
1071  if (tx + 1 < GetWidth() && _GetMat(tx + 1, ty) == mat)
1072  if (!Random(++n)) pix = _GetPix(tx + 1, ty);
1073  if (ty + 1 < GetHeight() && _GetMat(tx, ty + 1) == mat)
1074  if (!Random(++n)) pix = _GetPix(tx, ty + 1);
1075  if (pix < 0)
1076  pix = Mat2PixColDefault(mat);
1077 
1078  // Insert dead material
1079  SetPix2(tx, ty, pix, Transparent);
1080 
1081  // Search a position for the old material pixel
1083  {
1084  int32_t tyo = ty - 1;
1085  InsertMaterial(omat, &tx, &tyo);
1086  }
1087 
1088  return true;
1089 }
BYTE _GetPix(int32_t x, int32_t y) const
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
int32_t _GetMat(int32_t x, int32_t y) const
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
C4SGame Game
Definition: C4Scenario.h:232
BYTE Mat2PixColDefault(int32_t mat)
Definition: C4Material.h:235
static const uint8_t Transparent
Definition: C4Landscape.h:50
bool MatValid(int32_t mat)
Definition: C4Material.h:210
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

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 982 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 C4MassMover::Execute(), InsertDeadMaterial(), C4MaterialMap::mrfCorrode(), C4MaterialMap::mrfIncinerate(), and C4MaterialMap::mrfInsert().

983 {
984  assert(tx); assert(ty);
985  int32_t mdens;
986  if (!MatValid(mat)) return false;
987  mdens = std::min(MatDensity(mat), C4M_Solid);
988  if (!mdens) return true;
989 
990  // Bounds
991  if (!Inside<int32_t>(*tx, 0, GetWidth() - 1) || !Inside<int32_t>(*ty, 0, GetHeight())) return InsertMaterialOutsideLandscape(*tx, *ty, mdens);
992 
994  {
995  // Same or higher density?
996  if (GetDensity(*tx, *ty) >= mdens)
997  // Push
998  if (!FindMatPathPush(*tx, *ty, mdens, ::MaterialMap.Map[mat].MaxSlide, !!::MaterialMap.Map[mat].Instable))
999  // Or die
1000  return false;
1001  }
1002  else
1003  {
1004  // Move up above same density
1005  while (mdens == std::min(GetDensity(*tx, *ty), C4M_Solid))
1006  {
1007  (*ty)--; if (*ty < 0) return false;
1008  // Primitive slide (1)
1009  if (GetDensity(*tx - 1, *ty) < mdens) (*tx)--;
1010  if (GetDensity(*tx + 1, *ty) < mdens) (*tx)++;
1011  }
1012  // Stuck in higher density
1013  if (GetDensity(*tx, *ty) > mdens) return false;
1014  }
1015 
1016  // Try slide
1017  while (FindMatSlide(*tx, *ty, +1, mdens, ::MaterialMap.Map[mat].MaxSlide))
1018  if (GetDensity(*tx, *ty + 1) < mdens)
1019  {
1020  if (!query_only)
1021  return ::PXS.Create(mat, itofix(*tx), itofix(*ty), C4REAL10(vx), C4REAL10(vy));
1022  return true;
1023  }
1024 
1025  if (query_only)
1026  {
1027  // since tx and ty changed, we need to re-check the bounds here
1028  // if we really inserted it, the check is made again in InsertDeadMaterial
1029  if (!Inside<int32_t>(*tx, 0, GetWidth() - 1) || !Inside<int32_t>(*ty, 0, GetHeight())) return InsertMaterialOutsideLandscape(*tx, *ty, mdens);
1030  return true;
1031  }
1032 
1033  // Try reaction with material below and at insertion position
1034  C4MaterialReaction *pReact; int32_t tmat;
1035  int32_t check_dir = 0;
1036  for (int32_t i = 0; i < 2; ++i)
1037  {
1038  if ((pReact = ::MaterialMap.GetReactionUnsafe(mat, tmat = GetMat(*tx, *ty + check_dir))))
1039  {
1040  C4Real fvx = C4REAL10(vx), fvy = C4REAL10(vy);
1041  if ((*pReact->pFunc)(pReact, *tx, *ty, *tx, *ty + check_dir, fvx, fvy, mat, tmat, meePXSPos, nullptr))
1042  {
1043  // the material to be inserted killed itself in some material reaction below
1044  return true;
1045  }
1046  }
1047  if (!(check_dir = Sign(GravAccel))) break;
1048  }
1049 
1050  // Insert as dead material
1051  return InsertDeadMaterial(mat, *tx, *ty);
1052 }
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
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:205
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
int32_t GetDensity(int32_t x, int32_t y) const
C4SRealism Realism
Definition: C4Scenario.h:127
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
C4PXSSystem PXS
Definition: C4PXS.cpp:525
int32_t GetMat(int32_t x, int32_t y) const
bool FindMatSlide(int32_t &fx, int32_t &fy, int32_t ydir, int32_t mdens, int32_t mslide) const
const int32_t C4M_Solid
Definition: C4Constants.h:172
int32_t GetHeight() const
C4MaterialMap MaterialMap
Definition: C4Material.cpp:969
C4SGame Game
Definition: C4Scenario.h:232
bool MatValid(int32_t mat)
Definition: C4Material.h:210
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 974 of file C4Landscape.cpp.

References GetDensity().

Referenced by InsertDeadMaterial(), and InsertMaterial().

975 {
976  // Out-of-bounds insertion considered successful if inserted into same or lower density
977  // This ensures pumping out of map works
978  // Do allow insertion into same density because it covers the case of e.g. pumping water into the upper ocean of an underwater scenario
979  return GetDensity(tx, ty) <= mdens;
980 }
int32_t GetDensity(int32_t x, int32_t y) const

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1847 of file C4Landscape.cpp.

References C4CFN_Landscape, C4CFN_LandscapeBg, C4CFN_LandscapeFg, FormatString(), Game, StdStrBuf::getData(), GetHeight(), GetWidth(), LogFatal(), MatValid(), PixCol2Mat(), C4Game::SetInitProgress(), CPolyEdge::x, and CPolyEdge::y.

Referenced by Init().

1848 {
1849  assert(!p->Surface8 && !p->Surface8Bkg);
1850 
1851  // Load exact landscape from group
1852  if ((p->Surface8 = GroupReadSurface8(hGroup, C4CFN_Landscape)) == nullptr)
1853  {
1854  if ((p->Surface8 = GroupReadSurface8(hGroup, C4CFN_LandscapeFg)) == nullptr) return false;
1855  p->Surface8Bkg = GroupReadSurface8(hGroup, C4CFN_LandscapeBg);
1856 
1857  if (p->Surface8Bkg)
1858  {
1859  if (p->Surface8->Wdt != p->Surface8Bkg->Wdt || p->Surface8->Hgt != p->Surface8Bkg->Hgt)
1860  {
1861  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());
1862  return false;
1863  }
1864  }
1865  else
1866  {
1867  // LandscapeFg.bmp loaded: Assume full 8bit mat-tex values
1868  // when creating background surface.
1869  p->Surface8Bkg = p->CreateDefaultBkgSurface(*p->Surface8, false);
1870  }
1871  }
1872  else
1873  {
1874  // Landscape.bmp loaded: Assume msb is IFT flag when creating
1875  // background surface.
1876  p->Surface8Bkg = p->CreateDefaultBkgSurface(*p->Surface8, true);
1877  }
1878 
1879  int iWidth, iHeight;
1880  p->Surface8->GetSurfaceSize(iWidth, iHeight);
1881  p->Width = iWidth; p->Height = iHeight;
1882 
1883  // adjust pal
1884  if (!p->Mat2Pal()) return false;
1885  // Landscape should be in correct format: Make sure it is!
1886  for (int32_t y = 0; y < GetHeight(); ++y)
1887  for (int32_t x = 0; x < GetWidth(); ++x)
1888  {
1889  BYTE byPix = p->Surface8->_GetPix(x, y);
1890  int32_t iMat = PixCol2Mat(byPix);
1891 
1892  if (byPix && !MatValid(iMat))
1893  {
1894  LogFatal(FormatString("Landscape loading error at (%d/%d): Pixel value %d not a valid material!", (int)x, (int)y, (int)byPix).getData());
1895  return false;
1896  }
1897 
1898  BYTE byPixBkg = p->Surface8Bkg->_GetPix(x, y);
1899  int32_t iMatBkg = PixCol2Mat(byPixBkg);
1900 
1901  if (byPixBkg && !MatValid(iMatBkg))
1902  {
1903  LogFatal(FormatString("Background Landscape loading error at (%d/%d): Pixel value %d not a valid material!", (int)x, (int)y, (int)byPixBkg).getData());
1904  return false;
1905  }
1906  }
1907 
1908  // Init sky
1909  if (fLoadSky)
1910  {
1911  Game.SetInitProgress(70);
1912  if (p->Sky.Init(fSavegame)) return false;
1913  }
1914  // Success
1915  return true;
1916 }
const char * getData() const
Definition: StdBuf.h:442
void SetInitProgress(float fToProgress)
Definition: C4Game.cpp:3385
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:227
int32_t GetHeight() const
bool MatValid(int32_t mat)
Definition: C4Material.h:210
#define C4CFN_LandscapeBg
Definition: C4Components.h:62
int32_t GetWidth() const
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Landscape::MapToLandscape ( )

Definition at line 2092 of file C4Landscape.cpp.

Referenced by Init(), and C4ToolsDlg::SetLandscapeMode().

2093 {
2094  // zoom map to landscape
2095  return p->MapToLandscape(this, *p->Map, *p->MapBkg, 0, 0, p->MapWidth, p->MapHeight);
2096 }

Here is the caller graph for this function:

bool C4Landscape::PostInitMap ( )

Definition at line 2428 of file C4Landscape.cpp.

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

Referenced by C4Game::InitGame().

2429 {
2430  // map creator present?
2431  if (!p->pMapCreator) return true;
2432  // call scripts
2433  p->pMapCreator->ExecuteCallbacks(p->MapZoom);
2434  // destroy map creator, if not needed later
2435  if (!Game.C4S.Landscape.KeepMapCreator) { p->pMapCreator.reset(); }
2436  // done, success
2437  return true;
2438 }
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
C4SLandscape Landscape
Definition: C4Scenario.h:234
bool KeepMapCreator
Definition: C4Scenario.h:183

Here is the caller graph for this function:

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

Definition at line 947 of file C4Landscape.cpp.

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

Referenced by C4Game::CreateObjectConstruction().

948 {
949  int32_t cx, cy;
950  BYTE cpix;
951  for (cx = tx; cx < tx + wdt; cx++)
952  {
953  for (cy = ty; (cy + 1 < ::Landscape.GetHeight()) && !GBackSolid(cx, cy + 1); cy++) {}
954  if (cy + 1 < ::Landscape.GetHeight()) if (cy - ty < 20)
955  {
956  cpix = GetPix(cx, cy + 1);
957  if (!MatVehicle(PixCol2Mat(cpix)))
958  while (cy >= ty) { SetPix2(cx, cy, cpix, GetBackPix(cx, cy + 1)); cy--; }
959  }
960  }
961 }
bool MatVehicle(int32_t iMat)
Definition: C4Material.h:215
uint8_t BYTE
int32_t PixCol2Mat(BYTE pixc)
C4Landscape Landscape
BYTE GetPix(int32_t x, int32_t y) const
bool SetPix2(int32_t x, int32_t y, BYTE fgPix, BYTE bgPix)
int32_t GetHeight() const
BYTE GetBackPix(int32_t x, int32_t y) const
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:231

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Landscape::RemoveUnusedTexMapEntries ( )

Definition at line 4126 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.

4127 {
4128  // check usage in landscape
4129  bool fTexUsage[C4M_MaxTexIndex];
4130  int32_t iMatTex;
4131  for (iMatTex = 0; iMatTex < C4M_MaxTexIndex; ++iMatTex)
4132  fTexUsage[iMatTex] = false;
4133  for (int32_t y = 0; y < GetHeight(); ++y)
4134  for (int32_t x = 0; x < GetWidth(); ++x)
4135  {
4136  const BYTE pix = p->Surface8->GetPix(x, y);
4137  const BYTE backPix = p->Surface8Bkg->GetPix(x, y);
4138  assert(pix < C4M_MaxTexIndex);
4139  assert(backPix < C4M_MaxTexIndex);
4140 
4141  fTexUsage[pix] = true;
4142  fTexUsage[backPix] = true;
4143  }
4144 
4145  // check usage by materials
4146  for (int32_t iMat = 0; iMat < ::MaterialMap.Num; ++iMat)
4147  {
4148  C4Material *pMat = ::MaterialMap.Map + iMat;
4149  if (pMat->BlastShiftTo >= 0) fTexUsage[pMat->BlastShiftTo] = true;
4150  if (pMat->BelowTempConvertTo >= 0) fTexUsage[pMat->BelowTempConvertTo] = true;
4151  if (pMat->AboveTempConvertTo >= 0) fTexUsage[pMat->AboveTempConvertTo] = true;
4152  if (pMat->DefaultMatTex >= 0) fTexUsage[pMat->DefaultMatTex] = true;
4153  }
4154  // remove unused
4155  for (iMatTex = 1; iMatTex < C4M_MaxTexIndex; ++iMatTex)
4156  if (!fTexUsage[iMatTex])
4157  ::TextureMap.RemoveEntry(iMatTex);
4158  // flag rewrite
4159  ::TextureMap.fEntriesAdded = true;
4160 }
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
C4MaterialMap MaterialMap
Definition: C4Material.cpp:969
bool fEntriesAdded
Definition: C4Texture.h:83
int32_t GetWidth() const

Here is the call graph for this function:

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

Definition at line 4021 of file C4Landscape.cpp.

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

Referenced by SetTextureIndex().

4022 {
4023  // find every occurance of iOldIndex in map; replace it by new index
4024  if (!p->Map) return false;
4025  int iPitch, iMapWdt, iMapHgt;
4026  BYTE *pMap = p->Map->Bits;
4027  iMapWdt = p->Map->Wdt;
4028  iMapHgt = p->Map->Hgt;
4029  iPitch = p->Map->Pitch;
4030  if (!pMap) return false;
4031  for (int32_t y = 0; y < iMapHgt; ++y)
4032  {
4033  for (int32_t x = 0; x < iMapWdt; ++x)
4034  {
4035  if (*pMap == iOldIndex)
4036  *pMap = iNewIndex;
4037  ++pMap;
4038  }
4039  pMap += iPitch - iMapWdt;
4040  }
4041  return true;
4042 }
uint8_t BYTE

Here is the caller graph for this function:

bool C4Landscape::Save ( C4Group hGroup) const

Definition at line 1709 of file C4Landscape.cpp.

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

Referenced by C4Game::LoadScenarioSection().

1710 {
1712  bool r = p->SaveInternal(this, hGroup);
1714  return r;
1715 }
static void RemoveSolidMasks()
static void PutSolidMasks()

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1750 of file C4Landscape.cpp.

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

1751 {
1753  bool r = p->SaveDiffInternal(this, hGroup, fSyncSave);
1755  return r;
1756 }
static void RemoveSolidMasks()
static void PutSolidMasks()

Here is the call graph for this function:

bool C4Landscape::SaveInitial ( )

Definition at line 1826 of file C4Landscape.cpp.

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

Referenced by Init().

1827 {
1828 
1829  // Create array
1830  p->pInitial = std::make_unique<BYTE[]>(GetWidth() * GetHeight());
1831  p->pInitialBkg = std::make_unique<BYTE[]>(GetWidth() * GetHeight());
1832 
1833  // Save material data
1834  for (int y = 0; y < GetHeight(); y++)
1835  {
1836  const int pitch = y * GetWidth();
1837  for (int x = 0; x < GetWidth(); x++)
1838  {
1839  p->pInitial[pitch + x] = p->Surface8->_GetPix(x, y);
1840  p->pInitialBkg[pitch + x] = p->Surface8Bkg->_GetPix(x, y);
1841  }
1842  }
1843 
1844  return true;
1845 }
int32_t GetHeight() const
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Landscape::SaveMap ( C4Group hGroup) const

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

1970 {
1971  // No map
1972  if (!p->Map) return false;
1973  assert(p->MapBkg != nullptr);
1974 
1975  // Create map palette
1976  CStdPalette Palette;
1978 
1979  // Save map surface
1980  if (!p->Map->Save(Config.AtTempPath(C4CFN_TempMapFg), &Palette))
1981  return false;
1982 
1983  // Move temp file to group
1984  if (!hGroup.Move(Config.AtTempPath(C4CFN_TempMapFg),
1985  C4CFN_MapFg))
1986  return false;
1987 
1988  // Save background map surface
1989  if (!p->MapBkg->Save(Config.AtTempPath(C4CFN_TempMapBg), &Palette))
1990  return false;
1991 
1992  // Move temp file to group
1993  if (!hGroup.Move(Config.AtTempPath(C4CFN_TempMapBg),
1994  C4CFN_MapBg))
1995  return false;
1996 
1997  // Success
1998  return true;
1999 }
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:969
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:

bool C4Landscape::SaveTextures ( C4Group hGroup) const

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

2002 {
2003  // if material-texture-combinations have been added, write the texture map
2004  if (::TextureMap.fEntriesAdded)
2005  {
2006  C4Group *pMatGroup = new C4Group();
2007  bool fSuccess = false;
2008  // create local material group
2009  if (!hGroup.FindEntry(C4CFN_Material))
2010  {
2011  // delete previous item at temp path
2013  // create at temp path
2014  if (pMatGroup->Open(Config.AtTempPath(C4CFN_Material), true))
2015  // write to it
2016  if (::TextureMap.SaveMap(*pMatGroup, C4CFN_TexMap))
2017  // close (flush)
2018  if (pMatGroup->Close())
2019  // add it
2021  fSuccess = true;
2022  // temp group must remain for scenario file closure
2023  // it will be deleted when the group is closed
2024  }
2025  else
2026  // simply write it to the local material file
2027  if (pMatGroup->OpenAsChild(&hGroup, C4CFN_Material))
2028  fSuccess = ::TextureMap.SaveMap(*pMatGroup, C4CFN_TexMap);
2029  // close material group again
2030  if (pMatGroup->IsOpen()) pMatGroup->Close();
2031  delete pMatGroup;
2032  // fail if unsuccessful
2033  if (!fSuccess) return false;
2034  }
2035  // done, success
2036  return true;
2037 }
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 IsOpen() const
Definition: C4Group.cpp:1891
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 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:

void C4Landscape::ScanSideOpen ( )

Definition at line 365 of file C4Landscape.cpp.

References GetPix().

Referenced by ScenarioInit().

366 {
367  int32_t cy;
368  for (cy = 0; (cy < p->Height) && !GetPix(0, cy); cy++) {}
369  p->LeftOpen = cy;
370  for (cy = 0; (cy < p->Height) && !GetPix(p->Width - 1, cy); cy++) {}
371  p->RightOpen = cy;
372 }
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:

void C4Landscape::ScenarioInit ( )

Definition at line 1358 of file C4Landscape.cpp.

References C4SLandscape::AutoScanSideOpen, C4SLandscape::BottomOpen, C4REAL100(), C4Game::C4S, DefaultGravAccel, C4SVal::Evaluate(), Game, C4SLandscape::Gravity, C4Scenario::Landscape, C4SLandscape::LeftOpen, C4SLandscape::RightOpen, ScanSideOpen(), and C4SLandscape::TopOpen.

Referenced by C4Game::InitGame().

1359 {
1360  // Gravity
1362  // Opens
1363  p->LeftOpen = Game.C4S.Landscape.LeftOpen;
1364  p->RightOpen = Game.C4S.Landscape.RightOpen;
1365  p->TopOpen = Game.C4S.Landscape.TopOpen;
1366  p->BottomOpen = Game.C4S.Landscape.BottomOpen;
1367  // Side open scan
1369 }
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
C4SLandscape Landscape
Definition: C4Scenario.h:234
C4SVal Gravity
Definition: C4Scenario.h:174
C4Real C4REAL100(int x)
Definition: C4Real.h:267
int32_t TopOpen
Definition: C4Scenario.h:168
void ScanSideOpen()
const C4Real DefaultGravAccel
Definition: C4Movement.cpp:40
int32_t BottomOpen
Definition: C4Scenario.h:168
int32_t LeftOpen
Definition: C4Scenario.h:169
int32_t RightOpen
Definition: C4Scenario.h:169
int32_t Evaluate()
Definition: C4Scenario.cpp:50
bool AutoScanSideOpen
Definition: C4Scenario.h:170

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Landscape::SetGravity ( C4Real  g)

Definition at line 3657 of file C4Landscape.cpp.

3658 {
3659  p->Gravity = g;
3660 }
void C4Landscape::SetMapChanged ( )

Definition at line 4124 of file C4Landscape.cpp.

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

4124 { p->fMapChanged = true; }

Here is the caller graph for this function:

void C4Landscape::SetMode ( LandscapeMode  iMode)

Definition at line 3370 of file C4Landscape.cpp.

Referenced by C4ToolsDlg::SetLandscapeMode().

3371 {
3372  p->mode = mode;
3373 }

Here is the caller graph for this function:

bool C4Landscape::SetModulation ( DWORD  dwWithClr)

Definition at line 3994 of file C4Landscape.cpp.

3995 {
3996  p->Modulation = dwWithClr;
3997  return true;
3998 }
bool C4Landscape::SetPix2 ( int32_t  x,
int32_t  y,
BYTE  fgPix,
BYTE  bgPix 
)

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

794 {
795  // check bounds
796  if (x < 0 || y < 0 || x >= GetWidth() || y >= GetHeight())
797  return false;
798  // no change?
799  if ((fgPix == Transparent || fgPix == _GetPix(x, y)) && (bgPix == Transparent || bgPix == p->Surface8Bkg->_GetPix(x, y)))
800  return true;
801  // set pixel
802  return _SetPix2(x, y, fgPix, bgPix);
803 }
BYTE _GetPix(int32_t x, int32_t y) const
int32_t GetHeight() const
static const uint8_t Transparent
Definition: C4Landscape.h:50
int32_t GetWidth() const
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:

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

Definition at line 4044 of file C4Landscape.cpp.

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

4045 {
4046  if (((!szMatTex || !*szMatTex) && !fInsert) || !Inside<int>(iNewIndex, 1, C4M_MaxTexIndex - 1))
4047  {
4048  DebugLogF("Cannot insert new texture %s to index %d: Invalid parameters.", (const char *)szMatTex, (int)iNewIndex);
4049  return false;
4050  }
4051  // get last mat index - returns zero for not found (valid for insertion mode)
4052  StdStrBuf Material, Texture;
4053  Material.CopyUntil(szMatTex, '-'); Texture.Copy(SSearch(szMatTex, "-"));
4054  BYTE iOldIndex = (szMatTex && *szMatTex) ? ::TextureMap.GetIndex(Material.getData(), Texture.getData(), false) : 0;
4055  // insertion mode?
4056  if (fInsert)
4057  {
4058  // there must be room to move up to
4059  BYTE byLastMoveIndex = C4M_MaxTexIndex - 1;
4060  while (::TextureMap.GetEntry(byLastMoveIndex))
4061  if (--byLastMoveIndex == iNewIndex)
4062  {
4063  DebugLogF("Cannot insert new texture %s to index %d: No room for insertion.", (const char *)szMatTex, (int)iNewIndex);
4064  return false;
4065  }
4066  // then move up all other textures first
4067  // could do this in one loop, but it's just a developement call anyway, so move one index at a time
4068  while (--byLastMoveIndex >= iNewIndex)
4069  if (::TextureMap.GetEntry(byLastMoveIndex))
4070  {
4071  ReplaceMapColor(byLastMoveIndex, byLastMoveIndex + 1);
4072  ::TextureMap.MoveIndex(byLastMoveIndex, byLastMoveIndex + 1);
4073  }
4074  // new insertion desired?
4075  if (szMatTex && *szMatTex)
4076  {
4077  // move from old or create new
4078  if (iOldIndex)
4079  {
4080  ReplaceMapColor(iOldIndex, iNewIndex);
4081  ::TextureMap.MoveIndex(iOldIndex, iNewIndex);
4082  }
4083  else
4084  {
4085  StdStrBuf Material, Texture;
4086  Material.CopyUntil(szMatTex, '-'); Texture.Copy(SSearch(szMatTex, "-"));
4087  // new insertion
4088  if (!::TextureMap.AddEntry(iNewIndex, Material.getData(), Texture.getData()))
4089  {
4090  LogF("Cannot insert new texture %s to index %d: Texture map entry error", (const char *)szMatTex, (int)iNewIndex);
4091  return false;
4092  }
4093  }
4094  }
4095  // done, success
4096  return true;
4097  }
4098  else
4099  {
4100  // new index must not be occupied
4101  const C4TexMapEntry *pOld;
4102  if ((pOld = ::TextureMap.GetEntry(iNewIndex)) && !pOld->isNull())
4103  {
4104  DebugLogF("Cannot move texture %s to index %d: Index occupied by %s-%s.", (const char *)szMatTex, (int)iNewIndex, pOld->GetMaterialName(), pOld->GetTextureName());
4105  return false;
4106  }
4107  // must only move existing textures
4108  if (!iOldIndex)
4109  {
4110  DebugLogF("Cannot move texture %s to index %d: Texture not found.", (const char *)szMatTex, (int)iNewIndex);
4111  return false;
4112  }
4113  // update map
4114  ReplaceMapColor(iOldIndex, iNewIndex);
4115  // change to new index in texmap
4116  ::TextureMap.MoveIndex(iOldIndex, iNewIndex);
4117  // done, success
4118  return true;
4119  }
4120 }
const char * getData() const
Definition: StdBuf.h:442
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
bool DebugLogF(const char *strMessage...)
Definition: C4Log.cpp:278
const char * GetMaterialName() const
Definition: C4Texture.h:60
const char * GetTextureName() const
Definition: C4Texture.h:61
const int C4M_MaxTexIndex
Definition: C4Constants.h:51
void MoveIndex(BYTE byOldIndex, BYTE byNewIndex)
Definition: C4Texture.cpp:403
bool isNull() const
Definition: C4Texture.h:59
void CopyUntil(const char *szString, char cUntil)
Definition: StdBuf.h:613
bool ReplaceMapColor(BYTE iOldIndex, BYTE iNewIndex)
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:250
void Copy()
Definition: StdBuf.h:467

Here is the call graph for this function:

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

Definition at line 520 of file C4Landscape.cpp.

521 {
522  std::vector<int32_t> vertices(GetRoundPolygon(tx, ty, rad, 50));
523  p->ForPolygon(this, &vertices[0], vertices.size() / 2, [this](int32_t x, int32_t y) { return p->ShakeFreePix(this, x, y); });
524 }
void C4Landscape::Synchronize ( )

Definition at line 1952 of file C4Landscape.cpp.

Referenced by C4Game::Synchronize().

1953 {
1954  p->ScanX = 0;
1955 }

Here is the caller graph for this function:

void C4Landscape::UpdatePixMaps ( )

Definition at line 4201 of file C4Landscape.cpp.

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

Referenced by HandleTexMapUpdate(), and Init().

4202 {
4203  int32_t i;
4204  for (i = 0; i < C4M_MaxTexIndex; i++) p->Pix2Mat[i] = PixCol2Mat(i);
4205  for (i = 0; i < C4M_MaxTexIndex; i++) p->Pix2Dens[i] = MatDensity(p->Pix2Mat[i]);
4206  for (i = 0; i < C4M_MaxTexIndex; i++) p->Pix2Place[i] = MatValid(p->Pix2Mat[i]) ? ::MaterialMap.Map[p->Pix2Mat[i]].Placement : 0;
4207  for (i = 0; i < C4M_MaxTexIndex; i++) p->Pix2Light[i] = MatValid(p->Pix2Mat[i]) && (::MaterialMap.Map[p->Pix2Mat[i]].Light>0);
4208  p->Pix2Place[0] = 0;
4209  // clear bridge mat conversion buffers
4210  std::fill(p->BridgeMatConversion.begin(), p->BridgeMatConversion.end(), nullptr);
4211 }
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:969
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


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