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

Referenced by C4FoWLightSection::Update().

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

Here is the caller graph for this function:

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

Definition at line 3764 of file C4Landscape.cpp.

References _GetBackPix().

3765 {
3766  return p->Pix2Dens[_GetBackPix(x, y)];
3767 }
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 3759 of file C4Landscape.cpp.

References _GetBackPix().

3760 {
3761  return p->Pix2Mat[_GetBackPix(x, y)];
3762 }
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 3726 of file C4Landscape.cpp.

References BREAKPOINT_HERE.

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

3727 {
3728 #ifdef _DEBUG
3729  if (x < 0 || y < 0 || x >= p->Width || y >= p->Height) { BREAKPOINT_HERE; }
3730 #endif
3731  return p->Surface8Bkg->_GetPix(x, y);
3732 }
#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 3769 of file C4Landscape.cpp.

References _GetBackPix().

3770 {
3771  return p->Pix2Place[_GetBackPix(x, y)];
3772 }
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 3701 of file C4Landscape.cpp.

References _GetPix().

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

3702 {
3703  return p->Pix2Dens[_GetPix(x, y)];
3704 }
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 3794 of file C4Landscape.cpp.

References _GetBackPix(), and _GetPix().

3795 {
3796  return _GetBackPix(x, y) == 0 || p->Pix2Light[_GetPix(x, y)];
3797 }
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 3696 of file C4Landscape.cpp.

References _GetPix().

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

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

3664 {
3665 #ifdef _DEBUG
3666  if (x < 0 || y < 0 || x >= p->Width || y >= p->Height) { BREAKPOINT_HERE; }
3667 #endif
3668  return p->Surface8->_GetPix(x, y);
3669 }
#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 3706 of file C4Landscape.cpp.

References _GetPix().

Referenced by C4LandscapeRenderGL::Update().

3707 {
3708  return p->Pix2Place[_GetPix(x, y)];
3709 }
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 3813 of file C4Landscape.cpp.

References CPolyEdge::y.

Referenced by C4PXS::Execute().

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

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:970
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  pDiff = GroupReadSurface8(hGroup, C4CFN_DiffLandscape);
1922  pDiffBkg = GroupReadSurface8(hGroup, C4CFN_DiffLandscapeBkg);
1923  if (pDiff == nullptr && pDiffBkg == nullptr) return false;
1924 
1925  // convert all pixels: keep if same material; re-set if different material
1926  BYTE byPix;
1927  for (int32_t y = 0; y < GetHeight(); ++y) for (int32_t x = 0; x < GetWidth(); ++x)
1928  {
1929  if (pDiff && pDiff->GetPix(x, y) != C4M_MaxTexIndex)
1930  if (p->Surface8->_GetPix(x, y) != (byPix = pDiff->_GetPix(x, y)))
1931  // material has changed here: readjust with new texture
1932  p->Surface8->SetPix(x, y, byPix);
1933  if (pDiffBkg && pDiffBkg->GetPix(x, y) != C4M_MaxTexIndex)
1934  if (p->Surface8Bkg->_GetPix(x, y) != (byPix = pDiffBkg->_GetPix(x, y)))
1935  p->Surface8Bkg->_SetPix(x, y, byPix);
1936  }
1937 
1938  // done
1939  return true;
1940 }
#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 3309 of file C4Landscape.cpp.

References GBackSolid().

Referenced by ConstructionCheck().

3310 {
3311  int32_t cx, cy, ascnt = 0;
3312  for (cy = y; cy < y + hgt; cy++)
3313  for (cx = x; cx < x + wdt; cx++)
3314  if (GBackSolid(cx, cy))
3315  ascnt++;
3316  return ascnt;
3317 }
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(), C4PXSSystem::Create(), C4MassMoverSet::Create(), C4MaterialCore::Density, DensitySolid(), C4MaterialCore::DigFree, GBackSolid(), GetMat(), C4MaterialCore::Instable, itofix(), C4MaterialCore::KeepSinglePixels, C4MaterialMap::Map, MassMover, MaterialMap, MatValid(), and PXS.

Referenced by CheckInstabilityRange().

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:174
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:422
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:970
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 4003 of file C4Landscape.cpp.

References GetHeight(), and GetWidth().

Referenced by DrawDefMap(), and DrawMap().

4004 {
4005  // clip by bounds
4006  if (rX < 0) { rWdt += rX; rX = 0; }
4007  if (rY < 0) { rHgt += rY; rY = 0; }
4008  int32_t iOver;
4009 
4010  iOver = rX + rWdt - GetWidth();
4011  if (iOver > 0)
4012  rWdt -= iOver;
4013 
4014  iOver = rY + rHgt - GetHeight();
4015  if (iOver > 0)
4016  rHgt -= iOver;
4017 
4018  // anything left inside the bounds?
4019  return rWdt > 0 && rHgt > 0;
4020 }
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 1942 of file C4Landscape.cpp.

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

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

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

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

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

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

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

3567 {
3568  BYTE byColor;
3569  if (!p->GetMapColorIndex(szMaterial, szTexture, byColor)) return false;
3570 
3571  int32_t iMaterial = ::MaterialMap.Get(szMaterial);
3572  if (!MatValid(iMaterial))
3573  return false;
3574 
3576 
3577  C4Rect BoundingBox(tx - 5, ty - 5, wdt + 10, hgt + 10);
3578  p->PrepareChange(this, BoundingBox);
3579 
3580  // assign clipper
3581  p->Surface8->Clip(BoundingBox.x, BoundingBox.y, BoundingBox.x + BoundingBox.Wdt, BoundingBox.y + BoundingBox.Hgt);
3582  p->Surface8Bkg->Clip(BoundingBox.x, BoundingBox.y, BoundingBox.x + BoundingBox.Wdt, BoundingBox.y + BoundingBox.Hgt);
3584 
3585  // draw all chunks
3586  int32_t x, y;
3587  for (x = 0; x < icntx; x++)
3588  for (y = 0; y < icnty; y++)
3589  p->DrawChunk(this, tx + wdt*x / icntx, ty + hgt*y / icnty, wdt / icntx, hgt / icnty, byColor, bIFT ? p->DefaultBkgMat(byColor) : 0, shape, Random(1000));
3590 
3591  // remove clipper
3592  p->Surface8->NoClip();
3593  p->Surface8Bkg->NoClip();
3594 
3595  p->FinishChange(this, BoundingBox);
3596 
3597  // success
3598  return true;
3599 }
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:970
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 3965 of file C4Landscape.cpp.

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

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

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

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

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

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

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

Referenced by DrawQuad().

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

References DrawPolygon().

3868 {
3869  // set vertices
3870  int32_t vtcs[8];
3871  vtcs[0] = iX1; vtcs[1] = iY1;
3872  vtcs[2] = iX2; vtcs[3] = iY2;
3873  vtcs[4] = iX3; vtcs[5] = iY3;
3874  vtcs[6] = iX4; vtcs[7] = iY4;
3875  return DrawPolygon(vtcs, 8, szMaterial, szBackMaterial, fDrawBridge);
3876 }
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 3804 of file C4Landscape.cpp.

Referenced by C4FoWLightSection::Update().

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

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

References C4M_Solid, and GetDensity().

Referenced by C4MassMover::Execute().

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

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

Referenced by InsertMaterial().

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

References C4M_Solid, and GetDensity().

Referenced by InsertMaterial(), and mrfInsertCheck().

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

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

Referenced by ExtractMaterial().

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

References GetBackPix().

3780 {
3781  return p->Pix2Dens[GetBackPix(x, y)];
3782 }
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 3884 of file C4Landscape.cpp.

Referenced by C4EditCursor::ApplyToolPicker().

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

Here is the caller graph for this function:

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

Definition at line 3774 of file C4Landscape.cpp.

References GetBackPix().

Referenced by C4EditCursor::UpdateStatusBar().

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

3735 {
3736  // Border checks
3737  if (x < 0)
3738  {
3739  if (y < p->LeftOpen) return 0;
3740  else return Mat2PixColDefault(MTunnel);
3741  }
3742  if (static_cast<uint32_t>(x) >= static_cast<uint32_t>(GetWidth()))
3743  {
3744  if (y < p->RightOpen) return 0;
3745  else return Mat2PixColDefault(MTunnel);
3746  }
3747  if (y < 0)
3748  {
3749  return p->DefaultBkgMat(p->TopRowPix[x]);
3750  }
3751  if (static_cast<uint32_t>(y) >= static_cast<uint32_t>(GetHeight()))
3752  {
3753  return p->DefaultBkgMat(p->BottomRowPix[x]);
3754  }
3755 
3756  return p->Surface8Bkg->_GetPix(x, y);
3757 }
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 3784 of file C4Landscape.cpp.

References GetBackPix().

3785 {
3786  return p->Pix2Place[GetBackPix(x, y)];
3787 }
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 3716 of file C4Landscape.cpp.

References GetPix().

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

3717 {
3718  return p->Pix2Dens[GetPix(x, y)];
3719 }
BYTE GetPix(int32_t x, int32_t y) const

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t C4Landscape::GetEffectiveMatCount ( int  material) const

Definition at line 4184 of file C4Landscape.cpp.

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

Definition at line 4173 of file C4Landscape.cpp.

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

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

Here is the caller graph for this function:

C4Real C4Landscape::GetGravity ( ) const

Definition at line 3653 of file C4Landscape.cpp.

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

Definition at line 3789 of file C4Landscape.cpp.

References GetBackPix(), and GetPix().

3790 {
3791  return GetBackPix(x, y) == 0 || p->Pix2Light[GetPix(x, y)];
3792 }
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 3878 of file C4Landscape.cpp.

Referenced by C4EditCursor::ApplyToolPicker().

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

Here is the caller graph for this function:

int32_t C4Landscape::GetMapZoom ( ) const

Definition at line 3648 of file C4Landscape.cpp.

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

3649 {
3650  return p->MapZoom;
3651 }

Here is the caller graph for this function:

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

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

3712 {
3713  return p->Pix2Mat[GetPix(x, y)];
3714 }
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 4178 of file C4Landscape.cpp.

Referenced by C4SolidMask::CheckConsistency().

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

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

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

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

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

3377 {
3378  return p->mode;
3379 }

Here is the caller graph for this function:

DWORD C4Landscape::GetModulation ( ) const

Definition at line 4001 of file C4Landscape.cpp.

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

Definition at line 3633 of file C4Landscape.cpp.

Referenced by C4PXSSystem::Draw().

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

Here is the caller graph for this function:

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

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

3672 {
3673  extern BYTE MCVehic;
3674  // Border checks
3675  if (x < 0)
3676  {
3677  if (y < p->LeftOpen) return 0;
3678  else return MCVehic;
3679  }
3680  if (static_cast<uint32_t>(x) >= static_cast<uint32_t>(p->Width))
3681  {
3682  if (y < p->RightOpen) return 0;
3683  else return MCVehic;
3684  }
3685  if (y < 0)
3686  {
3687  return p->TopRowPix[x];
3688  }
3689  if (static_cast<uint32_t>(y) >= static_cast<uint32_t>(p->Height))
3690  {
3691  return p->BottomRowPix[x];
3692  }
3693  return p->Surface8->_GetPix(x, y);
3694 }
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 3811 of file C4Landscape.cpp.

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

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

Here is the caller graph for this function:

int32_t C4Landscape::GetPixMat ( BYTE  byPix) const

Definition at line 3809 of file C4Landscape.cpp.

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

3809 { 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 3721 of file C4Landscape.cpp.

References GetPix().

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

Here is the call graph for this function:

C4Sky & C4Landscape::GetSky ( )

Definition at line 4163 of file C4Landscape.cpp.

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

4164 {
4165  return p->Sky;
4166 }

Here is the caller graph for this function:

void C4Landscape::HandleTexMapUpdate ( )

Definition at line 4194 of file C4Landscape.cpp.

References UpdatePixMaps().

Referenced by C4TextureMap::AddEntry().

4195 {
4196  // Pixel maps must be update
4197  UpdatePixMaps();
4198  // Update landscape palette
4199  p->Mat2Pal();
4200 }
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 4168 of file C4Landscape.cpp.

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

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

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:970
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:3383
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:970
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:174
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:422
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:970
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:3383
C4Game Game
Definition: C4Globals.cpp:52
uint8_t BYTE
int32_t PixCol2Mat(BYTE pixc)
#define C4CFN_Landscape
Definition: C4Components.h:60
#define C4CFN_LandscapeFg
Definition: C4Components.h:61
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:237
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 2093 of file C4Landscape.cpp.

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

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

Here is the caller graph for this function:

bool C4Landscape::PostInitMap ( )

Definition at line 2429 of file C4Landscape.cpp.

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

Referenced by C4Game::InitGame().

2430 {
2431  // map creator present?
2432  if (!p->pMapCreator) return true;
2433  // call scripts
2434  p->pMapCreator->ExecuteCallbacks(p->MapZoom);
2435  // destroy map creator, if not needed later
2436  if (!Game.C4S.Landscape.KeepMapCreator) { p->pMapCreator.reset(); }
2437  // done, success
2438  return true;
2439 }
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 4127 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.

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

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

Referenced by SetTextureIndex().

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

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

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

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

Definition at line 4125 of file C4Landscape.cpp.

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

4125 { p->fMapChanged = true; }

Here is the caller graph for this function:

void C4Landscape::SetMode ( LandscapeMode  iMode)

Definition at line 3371 of file C4Landscape.cpp.

Referenced by C4ToolsDlg::SetLandscapeMode().

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

Here is the caller graph for this function:

bool C4Landscape::SetModulation ( DWORD  dwWithClr)

Definition at line 3995 of file C4Landscape.cpp.

3996 {
3997  p->Modulation = dwWithClr;
3998  return true;
3999 }
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 4045 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.

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

Referenced by C4Game::Synchronize().

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

Here is the caller graph for this function:

void C4Landscape::UpdatePixMaps ( )

Definition at line 4202 of file C4Landscape.cpp.

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

Referenced by HandleTexMapUpdate(), and Init().

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