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

Referenced by C4FoWLightSection::Update().

3803 {
3804  return p->PixCnt[(x / 17) * p->PixCntPitch + (y / 15)] > 0;
3805 }

Here is the caller graph for this function:

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

Definition at line 3767 of file C4Landscape.cpp.

References _GetBackPix().

3768 {
3769  return p->Pix2Dens[_GetBackPix(x, y)];
3770 }
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 3762 of file C4Landscape.cpp.

References _GetBackPix().

3763 {
3764  return p->Pix2Mat[_GetBackPix(x, y)];
3765 }
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 3729 of file C4Landscape.cpp.

References BREAKPOINT_HERE.

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

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

References _GetBackPix().

3773 {
3774  return p->Pix2Place[_GetBackPix(x, y)];
3775 }
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 3704 of file C4Landscape.cpp.

References _GetPix().

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

3705 {
3706  return p->Pix2Dens[_GetPix(x, y)];
3707 }
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 3797 of file C4Landscape.cpp.

References _GetBackPix(), and _GetPix().

3798 {
3799  return _GetBackPix(x, y) == 0 || p->Pix2Light[_GetPix(x, y)];
3800 }
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 3699 of file C4Landscape.cpp.

References _GetPix().

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

3700 {
3701  return p->Pix2Mat[_GetPix(x, y)];
3702 }
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 3666 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().

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

References _GetPix().

Referenced by C4LandscapeRenderGL::Update().

3710 {
3711  return p->Pix2Place[_GetPix(x, y)];
3712 }
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 3816 of file C4Landscape.cpp.

References CPolyEdge::y.

Referenced by C4PXS::Execute().

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

Here is the caller graph for this function:

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

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

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

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

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

898 {
899  // set 8bpp-surface only!
900  assert(x >= 0 && y >= 0 && x < GetWidth() && y < GetHeight());
901  if (fgPix != Transparent) p->Surface8->SetPix(x, y, fgPix);
902  if (bgPix != Transparent) p->Surface8Bkg->SetPix(x, y, bgPix);
903 }
int32_t GetHeight() const
static const uint8_t Transparent
Definition: C4Landscape.h:51
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 1921 of file C4Landscape.cpp.

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

Referenced by Init().

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

References GBackSolid().

Referenced by ConstructionCheck().

3313 {
3314  int32_t cx, cy, ascnt = 0;
3315  for (cy = y; cy < y + hgt; cy++)
3316  for (cx = x; cx < x + wdt; cx++)
3317  if (GBackSolid(cx, cy))
3318  ascnt++;
3319  return ascnt;
3320 }
bool GBackSolid(int32_t x, int32_t y)
Definition: C4Landscape.h:232

Here is the call graph for this function:

Here is the caller graph for this function:

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

References BlastFreeShape().

519 {
520  std::vector<int32_t> vertices(GetRoundPolygon(tx, ty, rad, 30));
521  BlastFreeShape(&vertices[0], vertices.size(), by_object, caused_by, iMaxDensity);
522 }
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 608 of file C4Landscape.cpp.

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

Referenced by BlastFree().

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

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

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

Referenced by CheckInstabilityRange().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

933 {
934  if (!CheckInstability(tx, ty))
935  {
936  CheckInstability(tx, ty - 1);
937  CheckInstability(tx, ty - 2);
938  CheckInstability(tx - 1, ty);
939  CheckInstability(tx + 1, ty);
940  }
941 }
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 1375 of file C4Landscape.cpp.

References Undefined.

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

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

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

References ClearPix().

498 {
499  std::vector<int32_t> vertices(GetRectangle(tx, ty, wdt, hgt));
500  C4Rect r(tx, ty, wdt, hgt);
501  p->PrepareChange(this, r);
502  p->ForPolygon(this, &vertices[0], vertices.size() / 2, [this](int32_t x, int32_t y) { return ClearPix(x, y); });
503  p->FinishChange(this, r);
504 }
Definition: C4Rect.h:29
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 785 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().

786 {
787  // Replace pixel with background pixel
788  BYTE bkgPix = p->Surface8Bkg->GetPix(tx, ty);
789  return SetPix2(tx, ty, bkgPix, bkgPix);
790 }
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 792 of file C4Landscape.cpp.

Referenced by C4Game::ClearPointers().

793 {
794  if (p->pFoW) p->pFoW->Remove(pObj);
795 }

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

References GetHeight(), and GetWidth().

Referenced by DrawDefMap(), and DrawMap().

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

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

1407 {
1408  pComp->Value(mkNamingAdapt(p->MapSeed, "MapSeed", 0));
1409  pComp->Value(mkNamingAdapt(p->LeftOpen, "LeftOpen", 0));
1410  pComp->Value(mkNamingAdapt(p->RightOpen, "RightOpen", 0));
1411  pComp->Value(mkNamingAdapt(p->TopOpen, "TopOpen", 0));
1412  pComp->Value(mkNamingAdapt(p->BottomOpen, "BottomOpen", 0));
1413  pComp->Value(mkNamingAdapt(mkCastIntAdapt(p->Gravity), "Gravity", DefaultGravAccel));
1414  pComp->Value(mkNamingAdapt(p->Modulation, "MatModulation", 0U));
1415  pComp->Value(mkNamingAdapt(mkCastIntAdapt(p->mode), "Mode", LandscapeMode::Undefined));
1416 
1417  if (pComp->isDeserializer())
1418  {
1419  int32_t ambient_brightness;
1420  pComp->Value(mkNamingAdapt(ambient_brightness, "AmbientBrightness", 255));
1421  if (p->pFoW) p->pFoW->Ambient.SetBrightness(ambient_brightness / static_cast<double>(255));
1422  }
1423  else
1424  {
1425  if (p->pFoW)
1426  {
1427  int32_t ambient_brightness = static_cast<int32_t>(p->pFoW->Ambient.GetBrightness() * 255 + 0.5);
1428  pComp->Value(mkNamingAdapt(ambient_brightness, "AmbientBrightness", 255));
1429  }
1430  }
1431 }
StdCastAdapt< T, int32_t > mkCastIntAdapt(T &rValue)
Definition: StdAdaptors.h:253
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
const C4Real DefaultGravAccel
Definition: C4Movement.cpp:41
void Value(const T &rStruct)
Definition: StdCompiler.h:171
virtual bool isDeserializer()
Definition: StdCompiler.h:63

Here is the call graph for this function:

void C4Landscape::Default ( )

Definition at line 1945 of file C4Landscape.cpp.

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

1946 {
1947  p = std::make_unique<P>();
1948 }

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

References DigFreeShape().

Referenced by C4Object::DoMovement().

513 {
514  std::vector<int32_t> vertices(GetRoundPolygon(tx, ty, rad, 80));
515  return DigFreeShape(&vertices[0], vertices.size(), by_object, no_dig2objects, no_instability_check);
516 }
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 506 of file C4Landscape.cpp.

References DigFreeShape().

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

507 {
508  std::vector<int32_t> vertices(GetRectangle(tx, ty, wdt, hgt));
509  return DigFreeShape(&vertices[0], vertices.size(), by_object, no_dig2objects, no_instability_check);
510 }
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 565 of file C4Landscape.cpp.

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

Referenced by DigFree(), and DigFreeRect().

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

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Landscape::DoRelights ( )

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

402 {
403  if (!p->pLandscapeRender) return true;
404  for (int32_t i = 0; i < C4LS_MaxRelights; i++)
405  {
406  if (!p->Relights[i].Wdt)
407  break;
408  // Remove all solid masks in the (twice!) extended region around the change
409  C4Rect SolidMaskRect = p->pLandscapeRender->GetAffectedRect(p->Relights[i]);
410  C4SolidMask * pSolid;
411  for (pSolid = C4SolidMask::Last; pSolid; pSolid = pSolid->Prev)
412  pSolid->RemoveTemporary(SolidMaskRect);
413  // Perform the update
414  p->pLandscapeRender->Update(p->Relights[i], this);
415  if (p->pFoW) p->pFoW->Ambient.UpdateFromLandscape(*this, p->Relights[i]);
416  // Restore Solidmasks
417  for (pSolid = C4SolidMask::First; pSolid; pSolid = pSolid->Next)
418  pSolid->PutTemporary(SolidMaskRect);
420  // Clear slot
421  p->Relights[i].Default();
422  }
423  return true;
424 }
const int32_t C4LS_MaxRelights
Definition: C4Landscape.h:28
void PutTemporary(C4Rect where)
Definition: C4Rect.h:29
void RemoveTemporary(C4Rect where)
static bool CheckConsistency()
Definition: C4SolidMask.h:88
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 380 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().

381 {
382  uint32_t clrMod = 0xffffffff;
383  if (p->Modulation)
384  {
385  pDraw->ActivateBlitModulation(p->Modulation);
386  clrMod = p->Modulation;
387  }
388  // blit landscape
389  if (::GraphicsSystem.Show8BitSurface == 1)
390  pDraw->Blit8Fast(p->Surface8.get(), cgo.TargetX, cgo.TargetY, cgo.Surface, cgo.X, cgo.Y, cgo.Wdt, cgo.Hgt);
391  else if (::GraphicsSystem.Show8BitSurface == 2)
392  pDraw->Blit8Fast(p->Surface8Bkg.get(), cgo.TargetX, cgo.TargetY, cgo.Surface, cgo.X, cgo.Y, cgo.Wdt, cgo.Hgt);
393  else if (p->pLandscapeRender)
394  {
395  DoRelights();
396  p->pLandscapeRender->Draw(cgo, pLight, clrMod);
397  }
398  if (p->Modulation) pDraw->DeactivateBlitModulation();
399 }
void Blit8Fast(CSurface8 *sfcSource, int fx, int fy, C4Surface *sfcTarget, int tx, int ty, int wdt, int hgt)
Definition: C4Draw.cpp:254
float Y
Definition: C4Facet.h:120
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
C4Draw * pDraw
Definition: C4Draw.cpp:45
float TargetX
Definition: C4Facet.h:167
float Hgt
Definition: C4Facet.h:120
void DeactivateBlitModulation()
Definition: C4Draw.h:189
bool DoRelights()
void ActivateBlitModulation(DWORD dwWithClr)
Definition: C4Draw.h:188
C4Surface * Surface
Definition: C4Facet.h:119
float TargetY
Definition: C4Facet.h:167
float Wdt
Definition: C4Facet.h:120
float X
Definition: C4Facet.h:120

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

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

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

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

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

3570 {
3571  BYTE byColor;
3572  if (!p->GetMapColorIndex(szMaterial, szTexture, byColor)) return false;
3573 
3574  int32_t iMaterial = ::MaterialMap.Get(szMaterial);
3575  if (!MatValid(iMaterial))
3576  return false;
3577 
3579 
3580  C4Rect BoundingBox(tx - 5, ty - 5, wdt + 10, hgt + 10);
3581  p->PrepareChange(this, BoundingBox);
3582 
3583  // assign clipper
3584  p->Surface8->Clip(BoundingBox.x, BoundingBox.y, BoundingBox.x + BoundingBox.Wdt, BoundingBox.y + BoundingBox.Hgt);
3585  p->Surface8Bkg->Clip(BoundingBox.x, BoundingBox.y, BoundingBox.x + BoundingBox.Wdt, BoundingBox.y + BoundingBox.Hgt);
3587 
3588  // draw all chunks
3589  int32_t x, y;
3590  for (x = 0; x < icntx; x++)
3591  for (y = 0; y < icnty; y++)
3592  p->DrawChunk(this, tx + wdt*x / icntx, ty + hgt*y / icnty, wdt / icntx, hgt / icnty, byColor, bIFT ? p->DefaultBkgMat(byColor) : 0, shape, Random(1000));
3593 
3594  // remove clipper
3595  p->Surface8->NoClip();
3596  p->Surface8Bkg->NoClip();
3597 
3598  p->FinishChange(this, BoundingBox);
3599 
3600  // success
3601  return true;
3602 }
uint32_t Random()
Definition: C4Random.cpp:43
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:76
C4SLandscape Landscape
Definition: C4Scenario.h:234
C4Material * Map
Definition: C4Material.h:171
C4MaterialCoreShape
Definition: C4Material.h:73
Definition: C4Rect.h:29
uint8_t BYTE
C4Draw * pDraw
Definition: C4Draw.cpp:45
bool FlatChunkShapes
Definition: C4Scenario.h:186
int32_t Get(const char *szMaterial)
Definition: C4Material.cpp:362
C4MaterialCoreShape MapChunkType
Definition: C4Material.h:93
C4MaterialMap MaterialMap
Definition: C4Material.cpp:970
bool NoPrimaryClipper()
Definition: C4Draw.cpp:240
bool MatValid(int32_t mat)
Definition: C4Material.h:212

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

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

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

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

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

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

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

Referenced by DoBridge().

943 {
944  int32_t cx, cy;
945  for (cy = ty; cy < ty + hgt; cy++)
946  for (cx = tx; cx < tx + wdt; cx++)
947  if ((MatDensity(mat) >= GetDensity(cx, cy)))
948  SetPix2(cx, cy, Mat2PixColDefault(mat), p->Surface8Bkg->GetPix(cx, cy));
949 }
int32_t MatDensity(int32_t mat)
Definition: C4Material.h:242
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:237

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

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

Referenced by DrawQuad().

3605 {
3606  if (length < 6) return false;
3607  if (length % 2 == 1) return false;
3608  // get texture
3609  int32_t iMatTex = ::TextureMap.GetIndexMatTex(szMaterial);
3610  if (!iMatTex) return false;
3611  uint8_t mcol = MatTex2PixCol(iMatTex);
3612  // get background texture
3613  uint8_t mcolBkg = 0;
3614  if (szBackMaterial != nullptr)
3615  {
3616  const int32_t iBackMatTex = ::TextureMap.GetIndexMatTex(szBackMaterial);
3617  if (!iBackMatTex) return false;
3618  mcolBkg = MatTex2PixCol(iBackMatTex);
3619  }
3620  // do bridging?
3621  uint8_t *conversion_map = nullptr;
3622  if (fDrawBridge)
3623  {
3624  conversion_map = p->GetBridgeMatConversion(this, MatTex2PixCol(iMatTex));
3625  mcolBkg = Transparent;
3626  }
3627  // prepare pixel count update
3628  C4Rect BoundingBox = getBoundingBox(vtcs, length);
3629  // draw polygon
3630  p->PrepareChange(this, BoundingBox);
3631  p->ForPolygon(this, vtcs, length / 2, nullptr, nullptr, mcol, mcolBkg, conversion_map);
3632  p->FinishChange(this, BoundingBox);
3633  return true;
3634 }
Definition: C4Rect.h:29
C4TextureMap TextureMap
Definition: C4Texture.cpp:580
BYTE MatTex2PixCol(int32_t tex)
Definition: C4Material.h:232
int32_t GetIndexMatTex(const char *szMaterialTexture, const char *szDefaultTexture=nullptr, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr)
Definition: C4Texture.cpp:450
static const uint8_t Transparent
Definition: C4Landscape.h:51

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

References DrawPolygon().

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

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

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

969 {
970  int32_t mat = GetMat(fx, fy);
971  if (mat == MNone) return MNone;
972  FindMatTop(mat, fx, fy, distant_first);
973  ClearPix(fx, fy);
974  CheckInstabilityRange(fx, fy);
975  return mat;
976 }
const int32_t MNone
Definition: C4Constants.h:178
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 3807 of file C4Landscape.cpp.

Referenced by C4FoWLightSection::Update().

3808 {
3809  return (x / 17) * 17 + 17;
3810 }

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

References C4M_Solid, and GetDensity().

Referenced by C4MassMover::Execute().

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

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

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

Referenced by InsertMaterial().

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

References C4M_Solid, and GetDensity().

Referenced by InsertMaterial(), and mrfInsertCheck().

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

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

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

Referenced by ExtractMaterial().

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

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

References GetBackPix().

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

Here is the call graph for this function:

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

Definition at line 3887 of file C4Landscape.cpp.

Referenced by C4EditCursor::ApplyToolPicker().

3888 {
3889  if (!p->MapBkg) return 0;
3890  return p->MapBkg->GetPix(iX, iY);
3891 }

Here is the caller graph for this function:

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

Definition at line 3777 of file C4Landscape.cpp.

References GetBackPix().

Referenced by C4EditCursor::UpdateStatusBar().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

3738 {
3739  // Border checks
3740  if (x < 0)
3741  {
3742  if (y < p->LeftOpen) return 0;
3743  else return Mat2PixColDefault(MTunnel);
3744  }
3745  if (static_cast<uint32_t>(x) >= static_cast<uint32_t>(GetWidth()))
3746  {
3747  if (y < p->RightOpen) return 0;
3748  else return Mat2PixColDefault(MTunnel);
3749  }
3750  if (y < 0)
3751  {
3752  return p->DefaultBkgMat(p->TopRowPix[x]);
3753  }
3754  if (static_cast<uint32_t>(y) >= static_cast<uint32_t>(GetHeight()))
3755  {
3756  return p->DefaultBkgMat(p->BottomRowPix[x]);
3757  }
3758 
3759  return p->Surface8Bkg->_GetPix(x, y);
3760 }
int32_t MTunnel
Definition: C4Material.cpp:37
int32_t GetHeight() const
BYTE Mat2PixColDefault(int32_t mat)
Definition: C4Material.h:237
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 3787 of file C4Landscape.cpp.

References GetBackPix().

3788 {
3789  return p->Pix2Place[GetBackPix(x, y)];
3790 }
BYTE GetBackPix(int32_t x, int32_t y) const

Here is the call graph for this function:

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

Definition at line 3719 of file C4Landscape.cpp.

References GetPix().

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

3720 {
3721  return p->Pix2Dens[GetPix(x, y)];
3722 }
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 4187 of file C4Landscape.cpp.

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

Definition at line 4176 of file C4Landscape.cpp.

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

4177 {
4178  return p->pFoW.get();
4179 }

Here is the caller graph for this function:

C4Real C4Landscape::GetGravity ( ) const

Definition at line 3656 of file C4Landscape.cpp.

3657 {
3658  return p->Gravity;
3659 }
bool C4Landscape::GetLight ( int32_t  x,
int32_t  y 
)

Definition at line 3792 of file C4Landscape.cpp.

References GetBackPix(), and GetPix().

3793 {
3794  return GetBackPix(x, y) == 0 || p->Pix2Light[GetPix(x, y)];
3795 }
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 3881 of file C4Landscape.cpp.

Referenced by C4EditCursor::ApplyToolPicker().

3882 {
3883  if (!p->Map) return 0;
3884  return p->Map->GetPix(iX, iY);
3885 }

Here is the caller graph for this function:

int32_t C4Landscape::GetMapZoom ( ) const

Definition at line 3651 of file C4Landscape.cpp.

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

3652 {
3653  return p->MapZoom;
3654 }

Here is the caller graph for this function:

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

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

3715 {
3716  return p->Pix2Mat[GetPix(x, y)];
3717 }
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 4181 of file C4Landscape.cpp.

4182 {
4183  assert(material >= 0 && material < p->MatCount.size());
4184  return p->MatCount[material];
4185 }
int32_t C4Landscape::GetMatHeight ( int32_t  x,
int32_t  y,
int32_t  iYDir,
int32_t  iMat,
int32_t  iMax 
) const

Definition at line 2447 of file C4Landscape.cpp.

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

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

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

3380 {
3381  return p->mode;
3382 }

Here is the caller graph for this function:

DWORD C4Landscape::GetModulation ( ) const

Definition at line 4004 of file C4Landscape.cpp.

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

Definition at line 3636 of file C4Landscape.cpp.

Referenced by C4PXSSystem::Draw().

3637 {
3638  return p->Surface8 ? p->Surface8->pPal : nullptr;
3639 }

Here is the caller graph for this function:

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

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

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

Here is the caller graph for this function:

int32_t C4Landscape::GetPixDensity ( BYTE  byPix) const

Definition at line 3814 of file C4Landscape.cpp.

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

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

Here is the caller graph for this function:

int32_t C4Landscape::GetPixMat ( BYTE  byPix) const

Definition at line 3812 of file C4Landscape.cpp.

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

3812 { 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 3724 of file C4Landscape.cpp.

References GetPix().

3725 {
3726  return p->Pix2Place[GetPix(x, y)];
3727 }
BYTE GetPix(int32_t x, int32_t y) const

Here is the call graph for this function:

C4Sky & C4Landscape::GetSky ( )

Definition at line 4166 of file C4Landscape.cpp.

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

4167 {
4168  return p->Sky;
4169 }

Here is the caller graph for this function:

void C4Landscape::HandleTexMapUpdate ( )

Definition at line 4197 of file C4Landscape.cpp.

References UpdatePixMaps().

Referenced by C4TextureMap::AddEntry().

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

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

4172 {
4173  return p->pFoW != nullptr;
4174 }

Here is the caller graph for this function:

bool C4Landscape::HasMap ( ) const

Definition at line 1708 of file C4Landscape.cpp.

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

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

1096 {
1097  int32_t mat = GetMat(x, y);
1098  if (MatValid(mat))
1099  if (::MaterialMap.Map[mat].Inflammable)
1100  {
1101  C4AulParSet pars(C4VInt(x), C4VInt(y), C4VInt(cause_player));
1103  }
1104  return false;
1105 }
C4PropListStatic * GetPropList()
Definition: C4Aul.h:153
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
C4Material * Map
Definition: C4Material.h:171
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
C4Value Call(C4PropertyName k, C4AulParSet *pPars=0, bool fPassErrors=false)
Definition: C4PropList.h:112
bool MatValid(int32_t mat)
Definition: C4Material.h:212
int32_t Inflammable
Definition: C4Material.h:108

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

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

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

987 {
988  assert(tx); assert(ty);
989  int32_t mdens;
990  if (!MatValid(mat)) return false;
991  mdens = std::min(MatDensity(mat), C4M_Solid);
992  if (!mdens) return true;
993 
994  // Bounds
995  if (!Inside<int32_t>(*tx, 0, GetWidth() - 1) || !Inside<int32_t>(*ty, 0, GetHeight())) return InsertMaterialOutsideLandscape(*tx, *ty, mdens);
996 
998  {
999  // Same or higher density?
1000  if (GetDensity(*tx, *ty) >= mdens)
1001  // Push
1002  if (!FindMatPathPush(*tx, *ty, mdens, ::MaterialMap.Map[mat].MaxSlide, !!::MaterialMap.Map[mat].Instable))
1003  // Or die
1004  return false;
1005  }
1006  else
1007  {
1008  // Move up above same density
1009  while (mdens == std::min(GetDensity(*tx, *ty), C4M_Solid))
1010  {
1011  (*ty)--; if (*ty < 0) return false;
1012  // Primitive slide (1)
1013  if (GetDensity(*tx - 1, *ty) < mdens) (*tx)--;
1014  if (GetDensity(*tx + 1, *ty) < mdens) (*tx)++;
1015  }
1016  // Stuck in higher density
1017  if (GetDensity(*tx, *ty) > mdens) return false;
1018  }
1019 
1020  // Try slide
1021  while (FindMatSlide(*tx, *ty, +1, mdens, ::MaterialMap.Map[mat].MaxSlide))
1022  if (GetDensity(*tx, *ty + 1) < mdens)
1023  {
1024  if (!query_only)
1025  return ::PXS.Create(mat, itofix(*tx), itofix(*ty), C4REAL10(vx), C4REAL10(vy));
1026  return true;
1027  }
1028 
1029  if (query_only)
1030  {
1031  // since tx and ty changed, we need to re-check the bounds here
1032  // if we really inserted it, the check is made again in InsertDeadMaterial
1033  if (!Inside<int32_t>(*tx, 0, GetWidth() - 1) || !Inside<int32_t>(*ty, 0, GetHeight())) return InsertMaterialOutsideLandscape(*tx, *ty, mdens);
1034  return true;
1035  }
1036 
1037  // Try reaction with material below and at insertion position
1038  C4MaterialReaction *pReact; int32_t tmat;
1039  int32_t check_dir = 0;
1040  for (int32_t i = 0; i < 2; ++i)
1041  {
1042  if ((pReact = ::MaterialMap.GetReactionUnsafe(mat, tmat = GetMat(*tx, *ty + check_dir))))
1043  {
1044  C4Real fvx = C4REAL10(vx), fvy = C4REAL10(vy);
1045  if ((*pReact->pFunc)(pReact, *tx, *ty, *tx, *ty + check_dir, fvx, fvy, mat, tmat, meePXSPos, nullptr))
1046  {
1047  // the material to be inserted killed itself in some material reaction below
1048  return true;
1049  }
1050  }
1051  if (!(check_dir = Sign(GravAccel))) break;
1052  }
1053 
1054  // Insert as dead material
1055  return InsertDeadMaterial(mat, *tx, *ty);
1056 }
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:193
int32_t MaxSlide
Definition: C4Material.h:106
C4Game Game
Definition: C4Globals.cpp:52
bool LandscapePushPull
Definition: C4Scenario.h:110
C4Scenario C4S
Definition: C4Game.h:76
bool InsertDeadMaterial(int32_t mat, int32_t tx, int32_t ty)
int32_t Instable
Definition: C4Material.h:104
C4Material * Map
Definition: C4Material.h:171
#define GravAccel
Definition: C4Physics.h:29
bool InsertMaterialOutsideLandscape(int32_t tx, int32_t ty, int32_t mdens)
int Sign(T val)
Definition: Standard.h:47
bool Create(int32_t mat, C4Real ix, C4Real iy, C4Real ixdir=Fix0, C4Real iydir=Fix0)
Definition: C4PXS.cpp:212
Definition: C4Real.h:58
C4MaterialReactionFunc pFunc
Definition: C4Material.h:49
int32_t MatDensity(int32_t mat)
Definition: C4Material.h:242
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:532
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:173
int32_t GetHeight() const
C4MaterialMap MaterialMap
Definition: C4Material.cpp:970
C4SGame Game
Definition: C4Scenario.h:232
bool MatValid(int32_t mat)
Definition: C4Material.h:212
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 978 of file C4Landscape.cpp.

References GetDensity().

Referenced by InsertDeadMaterial(), and InsertMaterial().

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Landscape::MapToLandscape ( )

Definition at line 2096 of file C4Landscape.cpp.

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

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

Here is the caller graph for this function:

bool C4Landscape::PostInitMap ( )

Definition at line 2432 of file C4Landscape.cpp.

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

Referenced by C4Game::InitGame().

2433 {
2434  // map creator present?
2435  if (!p->pMapCreator) return true;
2436  // call scripts
2437  p->pMapCreator->ExecuteCallbacks(p->MapZoom);
2438  // destroy map creator, if not needed later
2439  if (!Game.C4S.Landscape.KeepMapCreator) { p->pMapCreator.reset(); }
2440  // done, success
2441  return true;
2442 }
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:76
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 951 of file C4Landscape.cpp.

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

Referenced by C4Game::CreateObjectConstruction().

952 {
953  int32_t cx, cy;
954  BYTE cpix;
955  for (cx = tx; cx < tx + wdt; cx++)
956  {
957  for (cy = ty; (cy + 1 < ::Landscape.GetHeight()) && !GBackSolid(cx, cy + 1); cy++) {}
958  if (cy + 1 < ::Landscape.GetHeight()) if (cy - ty < 20)
959  {
960  cpix = GetPix(cx, cy + 1);
961  if (!MatVehicle(PixCol2Mat(cpix)))
962  while (cy >= ty) { SetPix2(cx, cy, cpix, GetBackPix(cx, cy + 1)); cy--; }
963  }
964  }
965 }
bool MatVehicle(int32_t iMat)
Definition: C4Material.h:217
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:232

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Landscape::RemoveUnusedTexMapEntries ( )

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

4131 {
4132  // check usage in landscape
4133  bool fTexUsage[C4M_MaxTexIndex];
4134  int32_t iMatTex;
4135  for (iMatTex = 0; iMatTex < C4M_MaxTexIndex; ++iMatTex)
4136  fTexUsage[iMatTex] = false;
4137  for (int32_t y = 0; y < GetHeight(); ++y)
4138  for (int32_t x = 0; x < GetWidth(); ++x)
4139  {
4140  const BYTE pix = p->Surface8->GetPix(x, y);
4141  const BYTE backPix = p->Surface8Bkg->GetPix(x, y);
4142  assert(pix < C4M_MaxTexIndex);
4143  assert(backPix < C4M_MaxTexIndex);
4144 
4145  fTexUsage[pix] = true;
4146  fTexUsage[backPix] = true;
4147  }
4148 
4149  // check usage by materials
4150  for (int32_t iMat = 0; iMat < ::MaterialMap.Num; ++iMat)
4151  {
4152  C4Material *pMat = ::MaterialMap.Map + iMat;
4153  if (pMat->BlastShiftTo >= 0) fTexUsage[pMat->BlastShiftTo] = true;
4154  if (pMat->BelowTempConvertTo >= 0) fTexUsage[pMat->BelowTempConvertTo] = true;
4155  if (pMat->AboveTempConvertTo >= 0) fTexUsage[pMat->AboveTempConvertTo] = true;
4156  if (pMat->DefaultMatTex >= 0) fTexUsage[pMat->DefaultMatTex] = true;
4157  }
4158  // remove unused
4159  for (iMatTex = 1; iMatTex < C4M_MaxTexIndex; ++iMatTex)
4160  if (!fTexUsage[iMatTex])
4161  ::TextureMap.RemoveEntry(iMatTex);
4162  // flag rewrite
4163  ::TextureMap.fEntriesAdded = true;
4164 }
int32_t BlastShiftTo
Definition: C4Material.h:153
int32_t DefaultMatTex
Definition: C4Material.h:157
C4Material * Map
Definition: C4Material.h:171
uint8_t BYTE
C4TextureMap TextureMap
Definition: C4Texture.cpp:580
void RemoveEntry(int32_t iIndex)
Definition: C4Texture.cpp:534
const int C4M_MaxTexIndex
Definition: C4Constants.h:51
int32_t AboveTempConvertTo
Definition: C4Material.h:156
int32_t Num
Definition: C4Material.h:170
int32_t GetHeight() const
int32_t BelowTempConvertTo
Definition: C4Material.h:155
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 4025 of file C4Landscape.cpp.

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

Referenced by SetTextureIndex().

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

Here is the caller graph for this function:

bool C4Landscape::Save ( C4Group hGroup) const

Definition at line 1713 of file C4Landscape.cpp.

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

Referenced by C4Game::LoadScenarioSection().

1714 {
1716  bool r = p->SaveInternal(this, hGroup);
1718  return r;
1719 }
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 1754 of file C4Landscape.cpp.

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

1755 {
1757  bool r = p->SaveDiffInternal(this, hGroup, fSyncSave);
1759  return r;
1760 }
static void RemoveSolidMasks()
static void PutSolidMasks()

Here is the call graph for this function:

bool C4Landscape::SaveInitial ( )

Definition at line 1830 of file C4Landscape.cpp.

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

Referenced by Init().

1831 {
1832 
1833  // Create array
1834  p->pInitial = std::make_unique<BYTE[]>(GetWidth() * GetHeight());
1835  p->pInitialBkg = std::make_unique<BYTE[]>(GetWidth() * GetHeight());
1836 
1837  // Save material data
1838  for (int y = 0; y < GetHeight(); y++)
1839  {
1840  const int pitch = y * GetWidth();
1841  for (int x = 0; x < GetWidth(); x++)
1842  {
1843  p->pInitial[pitch + x] = p->Surface8->_GetPix(x, y);
1844  p->pInitialBkg[pitch + x] = p->Surface8Bkg->_GetPix(x, y);
1845  }
1846  }
1847 
1848  return true;
1849 }
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 1973 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().

1974 {
1975  // No map
1976  if (!p->Map) return false;
1977  assert(p->MapBkg != nullptr);
1978 
1979  // Create map palette
1980  CStdPalette Palette;
1982 
1983  // Save map surface
1984  if (!p->Map->Save(Config.AtTempPath(C4CFN_TempMapFg), &Palette))
1985  return false;
1986 
1987  // Move temp file to group
1988  if (!hGroup.Move(Config.AtTempPath(C4CFN_TempMapFg),
1989  C4CFN_MapFg))
1990  return false;
1991 
1992  // Save background map surface
1993  if (!p->MapBkg->Save(Config.AtTempPath(C4CFN_TempMapBg), &Palette))
1994  return false;
1995 
1996  // Move temp file to group
1997  if (!hGroup.Move(Config.AtTempPath(C4CFN_TempMapBg),
1998  C4CFN_MapBg))
1999  return false;
2000 
2001  // Success
2002  return true;
2003 }
C4Config Config
Definition: C4Config.cpp:837
#define C4CFN_MapFg
Definition: C4Components.h:58
C4TextureMap TextureMap
Definition: C4Texture.cpp:580
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:546
C4MaterialMap MaterialMap
Definition: C4Material.cpp:970
const char * AtTempPath(const char *szFilename)
Definition: C4Config.cpp:544
#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 2005 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().

2006 {
2007  // if material-texture-combinations have been added, write the texture map
2008  if (::TextureMap.fEntriesAdded)
2009  {
2010  C4Group *pMatGroup = new C4Group();
2011  bool fSuccess = false;
2012  // create local material group
2013  if (!hGroup.FindEntry(C4CFN_Material))
2014  {
2015  // delete previous item at temp path
2017  // create at temp path
2018  if (pMatGroup->Open(Config.AtTempPath(C4CFN_Material), true))
2019  // write to it
2020  if (::TextureMap.SaveMap(*pMatGroup, C4CFN_TexMap))
2021  // close (flush)
2022  if (pMatGroup->Close())
2023  // add it
2025  fSuccess = true;
2026  // temp group must remain for scenario file closure
2027  // it will be deleted when the group is closed
2028  }
2029  else
2030  // simply write it to the local material file
2031  if (pMatGroup->OpenAsChild(&hGroup, C4CFN_Material))
2032  fSuccess = ::TextureMap.SaveMap(*pMatGroup, C4CFN_TexMap);
2033  // close material group again
2034  if (pMatGroup->IsOpen()) pMatGroup->Close();
2035  delete pMatGroup;
2036  // fail if unsuccessful
2037  if (!fSuccess) return false;
2038  }
2039  // done, success
2040  return true;
2041 }
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
C4Config Config
Definition: C4Config.cpp:837
#define C4CFN_Material
Definition: C4Components.h:25
C4TextureMap TextureMap
Definition: C4Texture.cpp:580
bool SaveMap(C4Group &hGroup, const char *szEntryName)
Definition: C4Texture.cpp:317
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:819
const char * AtTempPath(const char *szFilename)
Definition: C4Config.cpp:544
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 369 of file C4Landscape.cpp.

References GetPix().

Referenced by ScenarioInit().

370 {
371  int32_t cy;
372  for (cy = 0; (cy < p->Height) && !GetPix(0, cy); cy++) {}
373  p->LeftOpen = cy;
374  for (cy = 0; (cy < p->Height) && !GetPix(p->Width - 1, cy); cy++) {}
375  p->RightOpen = cy;
376 }
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 1362 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().

1363 {
1364  // Gravity
1366  // Opens
1367  p->LeftOpen = Game.C4S.Landscape.LeftOpen;
1368  p->RightOpen = Game.C4S.Landscape.RightOpen;
1369  p->TopOpen = Game.C4S.Landscape.TopOpen;
1370  p->BottomOpen = Game.C4S.Landscape.BottomOpen;
1371  // Side open scan
1373 }
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:76
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:41
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 3661 of file C4Landscape.cpp.

3662 {
3663  p->Gravity = g;
3664 }
void C4Landscape::SetMapChanged ( )

Definition at line 4128 of file C4Landscape.cpp.

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

4128 { p->fMapChanged = true; }

Here is the caller graph for this function:

void C4Landscape::SetMode ( LandscapeMode  iMode)

Definition at line 3374 of file C4Landscape.cpp.

Referenced by C4ToolsDlg::SetLandscapeMode().

3375 {
3376  p->mode = mode;
3377 }

Here is the caller graph for this function:

bool C4Landscape::SetModulation ( DWORD  dwWithClr)

Definition at line 3998 of file C4Landscape.cpp.

3999 {
4000  p->Modulation = dwWithClr;
4001  return true;
4002 }
bool C4Landscape::SetPix2 ( int32_t  x,
int32_t  y,
BYTE  fgPix,
BYTE  bgPix 
)

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

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

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

Here is the call graph for this function:

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

Definition at line 524 of file C4Landscape.cpp.

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

Definition at line 1956 of file C4Landscape.cpp.

Referenced by C4Game::Synchronize().

1957 {
1958  p->ScanX = 0;
1959 }

Here is the caller graph for this function:

void C4Landscape::UpdatePixMaps ( )

Definition at line 4205 of file C4Landscape.cpp.

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

Referenced by HandleTexMapUpdate(), and Init().

4206 {
4207  int32_t i;
4208  for (i = 0; i < C4M_MaxTexIndex; i++) p->Pix2Mat[i] = PixCol2Mat(i);
4209  for (i = 0; i < C4M_MaxTexIndex; i++) p->Pix2Dens[i] = MatDensity(p->Pix2Mat[i]);
4210  for (i = 0; i < C4M_MaxTexIndex; i++) p->Pix2Place[i] = MatValid(p->Pix2Mat[i]) ? ::MaterialMap.Map[p->Pix2Mat[i]].Placement : 0;
4211  for (i = 0; i < C4M_MaxTexIndex; i++) p->Pix2Light[i] = MatValid(p->Pix2Mat[i]) && (::MaterialMap.Map[p->Pix2Mat[i]].Light>0);
4212  p->Pix2Place[0] = 0;
4213  // clear bridge mat conversion buffers
4214  std::fill(p->BridgeMatConversion.begin(), p->BridgeMatConversion.end(), nullptr);
4215 }
C4Material * Map
Definition: C4Material.h:171
int32_t PixCol2Mat(BYTE pixc)
int32_t MatDensity(int32_t mat)
Definition: C4Material.h:242
int32_t Light
Definition: C4Material.h:115
const int C4M_MaxTexIndex
Definition: C4Constants.h:51
int32_t Placement
Definition: C4Material.h:114
C4MaterialMap MaterialMap
Definition: C4Material.cpp:970
bool MatValid(int32_t mat)
Definition: C4Material.h:212

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: