OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4MaterialMap Class Reference

#include <C4Material.h>

Collaboration diagram for C4MaterialMap:
[legend]

Public Member Functions

 C4MaterialMap ()
 
 ~C4MaterialMap ()
 
void Default ()
 
void Clear ()
 
int32_t Load (C4Group &hGroup)
 
bool HasMaterials (C4Group &hGroup) const
 
int32_t Get (const char *szMaterial)
 
bool SaveEnumeration (C4Group &hGroup)
 
bool LoadEnumeration (C4Group &hGroup)
 
C4MaterialReactionGetReactionUnsafe (int32_t iPXSMat, int32_t iLandscapeMat)
 
C4MaterialReactionGetReaction (int32_t iPXSMat, int32_t iLandscapeMat)
 
void UpdateScriptPointers ()
 
bool CrossMapMaterials (const char *szEarthMaterial)
 

Static Public Member Functions

static bool mrfConvert (C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
 
static bool mrfPoof (C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
 
static bool mrfCorrode (C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
 
static bool mrfIncinerate (C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
 
static bool mrfInsert (C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
 
static bool mrfScript (C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
 

Public Attributes

int32_t Num
 
C4MaterialMap
 
C4MaterialReaction ** ppReactionMap
 
int32_t max_shape_width
 
int32_t max_shape_height
 
C4MaterialReaction DefReactConvert
 
C4MaterialReaction DefReactPoof
 
C4MaterialReaction DefReactCorrode
 
C4MaterialReaction DefReactIncinerate
 
C4MaterialReaction DefReactInsert
 

Protected Member Functions

void SetMatReaction (int32_t iPXSMat, int32_t iLSMat, C4MaterialReaction *pReact)
 
bool SortEnumeration (int32_t iMat, const char *szMatName)
 

Detailed Description

Definition at line 162 of file C4Material.h.

Constructor & Destructor Documentation

C4MaterialMap::C4MaterialMap ( )

Definition at line 302 of file C4Material.cpp.

References Default().

303 {
304  Default();
305 }
C4MaterialReaction DefReactInsert
Definition: C4Material.h:173
static bool mrfPoof(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
Definition: C4Material.cpp:786
C4MaterialReaction DefReactIncinerate
Definition: C4Material.h:173
C4MaterialReaction DefReactPoof
Definition: C4Material.h:173
static bool mrfIncinerate(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
Definition: C4Material.cpp:878
C4MaterialReaction DefReactConvert
Definition: C4Material.h:173
C4MaterialReaction DefReactCorrode
Definition: C4Material.h:173
static bool mrfCorrode(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
Definition: C4Material.cpp:815
static bool mrfInsert(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
Definition: C4Material.cpp:904
static bool mrfConvert(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
Definition: C4Material.cpp:749

Here is the call graph for this function:

C4MaterialMap::~C4MaterialMap ( )

Definition at line 308 of file C4Material.cpp.

References Clear().

309 {
310  Clear();
311 }

Here is the call graph for this function:

Member Function Documentation

void C4MaterialMap::Clear ( )

Definition at line 313 of file C4Material.cpp.

References Map, Num, and ppReactionMap.

Referenced by c4_material_map_handle_new(), C4Game::Clear(), C4Game::InitMaterialTexture(), and ~C4MaterialMap().

314 {
315  if (Map) delete [] Map; Map=nullptr; Num=0;
316  delete [] ppReactionMap; ppReactionMap = nullptr;
317 }
C4Material * Map
Definition: C4Material.h:169
C4MaterialReaction ** ppReactionMap
Definition: C4Material.h:170
int32_t Num
Definition: C4Material.h:168

Here is the caller graph for this function:

bool C4MaterialMap::CrossMapMaterials ( const char *  szEarthMaterial)

Definition at line 371 of file C4Material.cpp.

References C4MatOv_None, C4MaxMaterial, C4TLS_MatSky, C4MaterialCore::Corrode, C4MaterialCore::Corrosive, C4MaterialCore::CustomReactionList, DebugLogF(), C4Material::DefaultMatTex, DefReactConvert, DefReactCorrode, DefReactIncinerate, DefReactInsert, DefReactPoof, DensityLiquid(), DensitySemiSolid(), DensitySolid(), C4MaterialCore::Extinguisher, C4MaterialReaction::fInverseSpec, FormatString(), Get(), StdStrBuf::getData(), C4TextureMap::GetEntry(), C4TextureMap::GetIndex(), C4TextureMap::GetIndexMatTex(), StdStrBuf::getLength(), C4TexMapEntry::GetMaterialName(), C4TextureMap::GetTexture(), C4TexMapEntry::GetTextureName(), C4Rect::Hgt, C4MaterialReaction::iConvertMat, C4MaterialCore::Incendiary, C4MaterialCore::Inflammable, LoadResStr(), LogFatal(), Map, Mat2PixColDefault(), MatDensity(), MaterialMap, MatValid(), max_shape_height, max_shape_width, MCHalfVehic, MCVehic, MEarth, MHalfVehic, MNone, MTunnel, MVehic, MWater, C4MaterialCore::Name, Num, C4MaterialCore::OverlayType, ppReactionMap, C4MaterialCore::PXSGfxRt, C4MaterialCore::sAboveTempConvertTo, C4MaterialCore::sBelowTempConvertTo, C4MaterialCore::sBlastShiftTo, C4MaterialReaction::sConvertMat, SEqualNoCase(), SetMatReaction(), C4MaterialCore::sInMatConvert, C4MaterialCore::sPXSGfx, C4MaterialCore::sTextureOverlay, C4Texture::Surface32, C4MaterialReaction::TargetSpec, TextureMap, C4Rect::Wdt, C4Rect::x, and C4Rect::y.

Referenced by C4Game::InitMaterialTexture().

372 {
373  // Check material number
375  { LogFatal(LoadResStr("IDS_PRC_TOOMANYMATS")); return false; }
376  // build reaction function map
377  delete [] ppReactionMap;
378  typedef C4MaterialReaction * C4MaterialReactionPtr;
379  ppReactionMap = new C4MaterialReactionPtr[(Num+1)*(Num+1)];
380  for (int32_t iMatPXS=-1; iMatPXS<Num; iMatPXS++)
381  {
382  C4Material *pMatPXS = (iMatPXS+1) ? Map+iMatPXS : nullptr;
383  for (int32_t iMatLS=-1; iMatLS<Num; iMatLS++)
384  {
385  C4MaterialReaction *pReaction = nullptr;
386  C4Material *pMatLS = ( iMatLS+1) ? Map+ iMatLS : nullptr;
387  // natural stuff: material conversion here?
388  if (pMatPXS && pMatPXS->sInMatConvert.getLength() && SEqualNoCase(pMatPXS->sInMatConvert.getData(), pMatLS ? pMatLS->Name : C4TLS_MatSky))
389  pReaction = &DefReactConvert;
390  // non-sky reactions
391  else if (pMatPXS && pMatLS)
392  {
393  // incindiary vs extinguisher
394  if ((pMatPXS->Incendiary && pMatLS->Extinguisher) || (pMatPXS->Extinguisher && pMatLS->Incendiary))
395  pReaction = &DefReactPoof;
396  // incindiary vs inflammable
397  else if ((pMatPXS->Incendiary && pMatLS->Inflammable) || (pMatPXS->Inflammable && pMatLS->Incendiary))
398  pReaction = &DefReactIncinerate;
399  // corrosive vs corrode
400  else if (pMatPXS->Corrosive && pMatLS->Corrode)
401  pReaction = &DefReactCorrode;
402  // liquid hitting liquid or solid: Material insertion
403  else if (DensityLiquid(MatDensity(iMatPXS)) && DensitySemiSolid(MatDensity(iMatLS)))
404  pReaction = &DefReactInsert;
405  // solid hitting solid: Material insertion
406  else if (DensitySolid(MatDensity(iMatPXS)) && DensitySolid(MatDensity(iMatLS)))
407  pReaction = &DefReactInsert;
408  }
409  // assign the function; or nullptr for no reaction
410  SetMatReaction(iMatPXS, iMatLS, pReaction);
411  }
412  }
413  // reset max shape size
415  // material-specific initialization
416  int32_t cnt;
417  for (cnt=0; cnt<Num; cnt++)
418  {
419  C4Material *pMat = Map+cnt;
420  const char *szTextureOverlay = nullptr;
421  // newgfx: init pattern
422  if (Map[cnt].sTextureOverlay.getLength())
424  {
425  szTextureOverlay = Map[cnt].sTextureOverlay.getData();
426  // backwards compatibility: if a pattern was specified although the no-pattern flag was set, overwrite that flag
427  if (Map[cnt].OverlayType & C4MatOv_None)
428  {
429  DebugLogF("Error in overlay of material %s: Flag C4MatOv_None ignored because a custom overlay (%s) was specified!", Map[cnt].Name, szTextureOverlay);
430  Map[cnt].OverlayType &= ~C4MatOv_None;
431  }
432  }
433  // default to first texture in texture map
434  int iTexMapIx;
435  if (!szTextureOverlay && (iTexMapIx = ::TextureMap.GetIndex(Map[cnt].Name, nullptr, false)))
436  szTextureOverlay = TextureMap.GetEntry(iTexMapIx)->GetTextureName();
437  // default to smooth
438  if (!szTextureOverlay)
439  szTextureOverlay = "none";
440  // search/create entry in texmap
441  Map[cnt].DefaultMatTex = ::TextureMap.GetIndex(Map[cnt].Name, szTextureOverlay, true,
442  FormatString("DefaultMatTex of mat %s", Map[cnt].Name).getData());
443  // init PXS facet
444  C4Surface * sfcTexture;
445  C4Texture * Texture;
446  if (Map[cnt].sPXSGfx.getLength())
447  if ((Texture=::TextureMap.GetTexture(Map[cnt].sPXSGfx.getData())))
448  if ((sfcTexture=Texture->Surface32))
449  Map[cnt].PXSFace.Set(sfcTexture, Map[cnt].PXSGfxRt.x, Map[cnt].PXSGfxRt.y, Map[cnt].PXSGfxRt.Wdt, Map[cnt].PXSGfxRt.Hgt);
450  // evaluate reactions for that material
451  for (auto & iRCnt : pMat->CustomReactionList)
452  {
453  C4MaterialReaction *pReact = &iRCnt;
454  if (pReact->sConvertMat.getLength()) pReact->iConvertMat = Get(pReact->sConvertMat.getData()); else pReact->iConvertMat = -1;
455  // evaluate target spec
456  int32_t tmat;
457  if (MatValid(tmat=Get(pReact->TargetSpec.getData())))
458  {
459  // single material target
460  if (pReact->fInverseSpec)
461  for (int32_t cnt2=-1; cnt2<Num; cnt2++) {
462  if (cnt2!=tmat)
463  SetMatReaction(cnt, cnt2, pReact);
464  else
465  SetMatReaction(cnt, tmat, pReact);
466  }
467  }
468  else if (SEqualNoCase(pReact->TargetSpec.getData(), "All"))
469  {
470  // add to all materials, including sky
471  if (!pReact->fInverseSpec) for (int32_t cnt2=-1; cnt2<Num; cnt2++) SetMatReaction(cnt, cnt2, pReact);
472  }
473  else if (SEqualNoCase(pReact->TargetSpec.getData(), "Solid"))
474  {
475  // add to all solid materials
476  if (pReact->fInverseSpec) SetMatReaction(cnt, -1, pReact);
477  for (int32_t cnt2=0; cnt2<Num; cnt2++) if (DensitySolid(Map[cnt2].Density) != pReact->fInverseSpec) SetMatReaction(cnt, cnt2, pReact);
478  }
479  else if (SEqualNoCase(pReact->TargetSpec.getData(), "SemiSolid"))
480  {
481  // add to all semisolid materials
482  if (pReact->fInverseSpec) SetMatReaction(cnt, -1, pReact);
483  for (int32_t cnt2=0; cnt2<Num; cnt2++) if (DensitySemiSolid(Map[cnt2].Density) != pReact->fInverseSpec) SetMatReaction(cnt, cnt2, pReact);
484  }
485  else if (SEqualNoCase(pReact->TargetSpec.getData(), "Background"))
486  {
487  // add to all BG materials, including sky
488  if (!pReact->fInverseSpec) SetMatReaction(cnt, -1, pReact);
489  for (int32_t cnt2=0; cnt2<Num; cnt2++) if (!Map[cnt2].Density != pReact->fInverseSpec) SetMatReaction(cnt, cnt2, pReact);
490  }
491  else if (SEqualNoCase(pReact->TargetSpec.getData(), "Sky"))
492  {
493  // add to sky
494  if (!pReact->fInverseSpec)
495  SetMatReaction(cnt, -1, pReact);
496  else
497  for (int32_t cnt2=0; cnt2<Num; cnt2++) SetMatReaction(cnt, cnt2, pReact);
498  }
499  else if (SEqualNoCase(pReact->TargetSpec.getData(), "Incendiary") || SEqualNoCase(pReact->TargetSpec.getData(), "Incindiary"))
500  {
501  // add to all incendiary materials
502  if (pReact->fInverseSpec) SetMatReaction(cnt, -1, pReact);
503  for (int32_t cnt2=0; cnt2<Num; cnt2++) if (!Map[cnt2].Incendiary == pReact->fInverseSpec) SetMatReaction(cnt, cnt2, pReact);
504  }
505  else if (SEqualNoCase(pReact->TargetSpec.getData(), "Extinguisher"))
506  {
507  // add to all incendiary materials
508  if (pReact->fInverseSpec) SetMatReaction(cnt, -1, pReact);
509  for (int32_t cnt2=0; cnt2<Num; cnt2++) if (!Map[cnt2].Extinguisher == pReact->fInverseSpec) SetMatReaction(cnt, cnt2, pReact);
510  }
511  else if (SEqualNoCase(pReact->TargetSpec.getData(), "Inflammable"))
512  {
513  // add to all incendiary materials
514  if (pReact->fInverseSpec) SetMatReaction(cnt, -1, pReact);
515  for (int32_t cnt2=0; cnt2<Num; cnt2++) if (!Map[cnt2].Inflammable == pReact->fInverseSpec) SetMatReaction(cnt, cnt2, pReact);
516  }
517  else if (SEqualNoCase(pReact->TargetSpec.getData(), "Corrosive"))
518  {
519  // add to all incendiary materials
520  if (pReact->fInverseSpec) SetMatReaction(cnt, -1, pReact);
521  for (int32_t cnt2=0; cnt2<Num; cnt2++) if (!Map[cnt2].Corrosive == pReact->fInverseSpec) SetMatReaction(cnt, cnt2, pReact);
522  }
523  else if (SEqualNoCase(pReact->TargetSpec.getData(), "Corrode"))
524  {
525  // add to all incendiary materials
526  if (pReact->fInverseSpec) SetMatReaction(cnt, -1, pReact);
527  for (int32_t cnt2=0; cnt2<Num; cnt2++) if (!Map[cnt2].Corrode == pReact->fInverseSpec) SetMatReaction(cnt, cnt2, pReact);
528  }
529  }
530  }
531  // second loop (DefaultMatTex is needed by GetIndexMatTex)
532  for (cnt=0; cnt<Num; cnt++)
533  {
534  if (Map[cnt].sBlastShiftTo.getLength())
535  Map[cnt].BlastShiftTo=::TextureMap.GetIndexMatTex(Map[cnt].sBlastShiftTo.getData(), nullptr, true, FormatString("BlastShiftTo of mat %s", Map[cnt].Name).getData());
536  if (Map[cnt].sInMatConvertTo.getLength())
537  Map[cnt].InMatConvertTo=Get(Map[cnt].sInMatConvertTo.getData());
538  if (Map[cnt].sBelowTempConvertTo.getLength())
539  Map[cnt].BelowTempConvertTo=::TextureMap.GetIndexMatTex(Map[cnt].sBelowTempConvertTo.getData(), nullptr, true, FormatString("BelowTempConvertTo of mat %s", Map[cnt].Name).getData());
540  if (Map[cnt].sAboveTempConvertTo.getLength())
541  Map[cnt].AboveTempConvertTo=::TextureMap.GetIndexMatTex(Map[cnt].sAboveTempConvertTo.getData(), nullptr, true, FormatString("AboveTempConvertTo of mat %s", Map[cnt].Name).getData());
542  }
543 
544  // Get hardcoded system material indices
545  const C4TexMapEntry* earth_entry = ::TextureMap.GetEntry(::TextureMap.GetIndexMatTex(szEarthMaterial));
546  if(!earth_entry)
547  { LogFatal(FormatString(R"(Earth material "%s" not found!)", szEarthMaterial).getData()); return false; }
548 
549  MVehic = Get("Vehicle"); MCVehic = Mat2PixColDefault(MVehic);
551  MTunnel = Get("Tunnel");
552  MWater = Get("Water");
553  MEarth = Get(earth_entry->GetMaterialName());
554 
555  if ((MVehic==MNone) || (MTunnel==MNone))
556  { LogFatal(LoadResStr("IDS_PRC_NOSYSMATS")); return false; }
557 
558  return true;
559 }
const char * getData() const
Definition: StdBuf.h:442
StdCopyStrBuf TargetSpec
Definition: C4Material.h:49
int32_t MHalfVehic
Definition: C4Material.cpp:36
int32_t Extinguisher
Definition: C4Material.h:108
int32_t DefaultMatTex
Definition: C4Material.h:155
StdCopyStrBuf sTextureOverlay
Definition: C4Material.h:114
C4TargetRect PXSGfxRt
Definition: C4Material.h:117
int32_t Corrode
Definition: C4Material.h:110
BYTE MCHalfVehic
Definition: C4Material.cpp:38
C4Material * Map
Definition: C4Material.h:169
C4MaterialReaction DefReactInsert
Definition: C4Material.h:173
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:207
int32_t OverlayType
Definition: C4Material.h:115
C4Surface * Surface32
Definition: C4Texture.h:35
int32_t max_shape_height
Definition: C4Material.h:171
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
bool DensitySemiSolid(int32_t dens)
Definition: C4Landscape.h:203
Definition: C4Texture.h:48
const C4TexMapEntry * GetEntry(int32_t iIndex) const
Definition: C4Texture.h:85
StdCopyStrBuf sConvertMat
Definition: C4Material.h:57
int32_t MTunnel
Definition: C4Material.cpp:36
int32_t MEarth
Definition: C4Material.cpp:36
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
int32_t GetIndex(const char *szMaterial, const char *szTexture, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr)
Definition: C4Texture.cpp:414
C4MaterialReaction DefReactIncinerate
Definition: C4Material.h:173
StdCopyStrBuf sPXSGfx
Definition: C4Material.h:116
C4MaterialReaction DefReactPoof
Definition: C4Material.h:173
int32_t Wdt
Definition: C4Rect.h:30
void SetMatReaction(int32_t iPXSMat, int32_t iLSMat, C4MaterialReaction *pReact)
Definition: C4Material.cpp:562
int32_t MWater
Definition: C4Material.cpp:36
StdCopyStrBuf sBlastShiftTo
Definition: C4Material.h:119
int32_t MatDensity(int32_t mat)
Definition: C4Material.h:240
const int32_t MNone
Definition: C4Constants.h:177
bool DebugLogF(const char *strMessage...)
Definition: C4Log.cpp:288
const char * GetMaterialName() const
Definition: C4Texture.h:60
char Name[C4M_MaxName+1]
Definition: C4Material.h:89
int32_t y
Definition: C4Rect.h:30
bool DensityLiquid(int32_t dens)
Definition: C4Landscape.h:208
const char * GetTextureName() const
Definition: C4Texture.h:61
int32_t MVehic
Definition: C4Material.cpp:36
BYTE MCVehic
Definition: C4Material.cpp:37
C4MaterialReaction DefReactConvert
Definition: C4Material.h:173
C4MaterialReaction ** ppReactionMap
Definition: C4Material.h:170
StdCopyStrBuf sAboveTempConvertTo
Definition: C4Material.h:128
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:237
int32_t Num
Definition: C4Material.h:168
C4MaterialReaction DefReactCorrode
Definition: C4Material.h:173
#define C4MatOv_None
Definition: C4Material.h:31
int32_t x
Definition: C4Rect.h:30
int32_t Get(const char *szMaterial)
Definition: C4Material.cpp:361
const char * GetTexture(int32_t iIndex)
Definition: C4Texture.cpp:494
int32_t Corrosive
Definition: C4Material.h:109
C4MaterialMap MaterialMap
Definition: C4Material.cpp:970
BYTE Mat2PixColDefault(int32_t mat)
Definition: C4Material.h:235
const int32_t C4MaxMaterial
Definition: C4Landscape.h:25
int32_t max_shape_width
Definition: C4Material.h:171
int32_t Incendiary
Definition: C4Material.h:107
size_t getLength() const
Definition: StdBuf.h:445
#define C4TLS_MatSky
Definition: C4ToolsDlg.h:39
int32_t iConvertMat
Definition: C4Material.h:58
int32_t Hgt
Definition: C4Rect.h:30
StdCopyStrBuf sInMatConvert
Definition: C4Material.h:120
std::vector< C4MaterialReaction > CustomReactionList
Definition: C4Material.h:87
int32_t GetIndexMatTex(const char *szMaterialTexture, const char *szDefaultTexture=nullptr, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr)
Definition: C4Texture.cpp:441
StdCopyStrBuf sBelowTempConvertTo
Definition: C4Material.h:125
bool MatValid(int32_t mat)
Definition: C4Material.h:210
bool DensitySolid(int32_t dens)
Definition: C4Landscape.h:198
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
int32_t Inflammable
Definition: C4Material.h:106

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MaterialMap::Default ( )

Definition at line 637 of file C4Material.cpp.

References Map, max_shape_height, max_shape_width, Num, and ppReactionMap.

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

638 {
639  Num=0;
640  Map=nullptr;
641  ppReactionMap=nullptr;
643 }
C4Material * Map
Definition: C4Material.h:169
int32_t max_shape_height
Definition: C4Material.h:171
C4MaterialReaction ** ppReactionMap
Definition: C4Material.h:170
int32_t Num
Definition: C4Material.h:168
int32_t max_shape_width
Definition: C4Material.h:171

Here is the caller graph for this function:

int32_t C4MaterialMap::Get ( const char *  szMaterial)

Definition at line 361 of file C4Material.cpp.

References Map, MNone, Num, and SEqualNoCase().

Referenced by CrossMapMaterials(), C4Landscape::DrawChunks(), C4TextureMap::GetIndexMatTex(), C4TexMapEntry::Init(), Load(), C4MCOverlay::SetField(), and C4ToolsDlg::SetTexture().

362 {
363  int32_t cnt;
364  for (cnt=0; cnt<Num; cnt++)
365  if (SEqualNoCase(szMaterial,Map[cnt].Name))
366  return cnt;
367  return MNone;
368 }
C4Material * Map
Definition: C4Material.h:169
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:207
const int32_t MNone
Definition: C4Constants.h:177
int32_t Num
Definition: C4Material.h:168

Here is the call graph for this function:

Here is the caller graph for this function:

C4MaterialReaction * C4MaterialMap::GetReaction ( int32_t  iPXSMat,
int32_t  iLandscapeMat 
)

Definition at line 645 of file C4Material.cpp.

References GetReactionUnsafe(), Num, and ppReactionMap.

646 {
647  // safety
648  if (!ppReactionMap) return nullptr;
649  if (!Inside<int32_t>(iPXSMat, -1, Num-1)) return nullptr;
650  if (!Inside<int32_t>(iLandscapeMat, -1, Num-1)) return nullptr;
651  // values OK; get func!
652  return GetReactionUnsafe(iPXSMat, iLandscapeMat);
653 }
C4MaterialReaction * GetReactionUnsafe(int32_t iPXSMat, int32_t iLandscapeMat)
Definition: C4Material.h:191
C4MaterialReaction ** ppReactionMap
Definition: C4Material.h:170
int32_t Num
Definition: C4Material.h:168

Here is the call graph for this function:

C4MaterialReaction* C4MaterialMap::GetReactionUnsafe ( int32_t  iPXSMat,
int32_t  iLandscapeMat 
)
inline

Definition at line 191 of file C4Material.h.

Referenced by C4MassMover::Corrosion(), C4PXS::Execute(), GetReaction(), and C4Landscape::InsertMaterial().

192  {
193  assert(ppReactionMap); assert(Inside<int32_t>(iPXSMat,-1,Num-1)); assert(Inside<int32_t>(iLandscapeMat,-1,Num-1));
194  return ppReactionMap[(iLandscapeMat+1)*(Num+1) + iPXSMat+1];
195  }
C4MaterialReaction ** ppReactionMap
Definition: C4Material.h:170
int32_t Num
Definition: C4Material.h:168

Here is the caller graph for this function:

bool C4MaterialMap::HasMaterials ( C4Group hGroup) const

Definition at line 356 of file C4Material.cpp.

References C4CFN_MaterialFiles, and C4Group::EntryCount().

357 {
358  return !!hGroup.EntryCount(C4CFN_MaterialFiles);
359 }
int EntryCount(const char *szWildCard=nullptr)
Definition: C4Group.cpp:1850
#define C4CFN_MaterialFiles
Definition: C4Components.h:169

Here is the call graph for this function:

int32_t C4MaterialMap::Load ( C4Group hGroup)

Definition at line 319 of file C4Material.cpp.

References C4CFN_MaterialFiles, C4Group::EntryCount(), C4Group::FindNextEntry(), Get(), Map, MNone, Num, and C4Group::ResetSearch().

Referenced by C4Game::InitMaterialTexture().

320 {
321  char entryname[256+1];
322 
323  // Determine number of materials in files
324  int32_t mat_num=hGroup.EntryCount(C4CFN_MaterialFiles);
325 
326  // Allocate new map
327  C4Material *pNewMap = new C4Material [mat_num + Num];
328  if (!pNewMap) return 0;
329 
330  // Load material cores to map
331  hGroup.ResetSearch(); int32_t cnt=0;
332  while (hGroup.FindNextEntry(C4CFN_MaterialFiles,entryname))
333  {
334  // Load mat
335  if (!pNewMap[cnt].Load(hGroup,entryname))
336  { delete [] pNewMap; return 0; }
337  // A new material?
338  if (Get(pNewMap[cnt].Name) == MNone)
339  cnt++;
340  }
341 
342  // Take over old materials.
343  for (int32_t i = 0; i < Num; i++)
344  {
345  pNewMap[cnt+i] = Map[i];
346  }
347  delete [] Map;
348  Map = pNewMap;
349 
350  // set material number
351  Num+=cnt;
352 
353  return cnt;
354 }
int EntryCount(const char *szWildCard=nullptr)
Definition: C4Group.cpp:1850
C4Material * Map
Definition: C4Material.h:169
const int32_t MNone
Definition: C4Constants.h:177
int32_t Num
Definition: C4Material.h:168
int32_t Get(const char *szMaterial)
Definition: C4Material.cpp:361
bool FindNextEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr, bool fStartAtFilename=false)
Definition: C4Group.cpp:1780
int32_t Load(C4Group &hGroup)
Definition: C4Material.cpp:319
void ResetSearch(bool reload_contents=false)
Definition: C4Group.cpp:1013
#define C4CFN_MaterialFiles
Definition: C4Components.h:169

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MaterialMap::LoadEnumeration ( C4Group hGroup)

Definition at line 583 of file C4Material.cpp.

References C4CFN_MatMap, C4M_MaxName, StdStrBuf::getData(), IsIdentifier(), C4Group::LoadEntryString(), SAdvanceSpace(), SCopyIdentifier(), SLen(), SortEnumeration(), and SSearch().

Referenced by C4Game::InitMaterialTexture().

584 {
585  // Load enumeration map (from savegame), succeed if not present
586  StdStrBuf mapbuf;
587  if (!hGroup.LoadEntryString(C4CFN_MatMap, &mapbuf)) return true;
588 
589  // Sort material array by enumeration map, fail if some missing
590  const char *csearch;
591  char cmatname[C4M_MaxName+1];
592  int32_t cmat=0;
593  if (!(csearch = SSearch(mapbuf.getData(),"[Enumeration]"))) { return false; }
594  csearch=SAdvanceSpace(csearch);
595  while (IsIdentifier(*csearch))
596  {
597  SCopyIdentifier(csearch,cmatname,C4M_MaxName);
598  if (!SortEnumeration(cmat,cmatname))
599  {
600  // Output error message!
601  return false;
602  }
603  cmat++;
604  csearch+=SLen(cmatname);
605  csearch=SAdvanceSpace(csearch);
606  }
607 
608  return true;
609 }
const char * getData() const
Definition: StdBuf.h:442
#define C4CFN_MatMap
Definition: C4Components.h:81
const char * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:363
const char * SAdvanceSpace(const char *szSPos)
Definition: Standard.cpp:414
size_t SLen(const char *sptr)
Definition: Standard.h:74
bool SortEnumeration(int32_t iMat, const char *szMatName)
Definition: C4Material.cpp:611
const int C4M_MaxName
Definition: C4Constants.h:49
bool LoadEntryString(const char *szEntryName, StdStrBuf *Buf)
Definition: C4Group.cpp:1932
bool IsIdentifier(char cChar)
Definition: Standard.cpp:90
void SCopyIdentifier(const char *szSource, char *sTarget, int iMaxL)
Definition: Standard.cpp:443

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MaterialMap::mrfConvert ( C4MaterialReaction pReaction,
int32_t &  iX,
int32_t &  iY,
int32_t  iLSPosX,
int32_t  iLSPosY,
C4Real fXDir,
C4Real fYDir,
int32_t &  iPxsMat,
int32_t  iLsMat,
MaterialInteractionEvent  evEvent,
bool *  pfPosChanged 
)
static

Definition at line 749 of file C4Material.cpp.

References C4PXSSystem::Create(), C4MaterialReaction::fUserDefined, GBackMat(), C4MaterialReaction::iConvertMat, C4MaterialReaction::iDepth, C4MaterialCore::InMatConvertDepth, C4Material::InMatConvertTo, itofix(), Map, MaterialMap, MatValid(), meeMassMove, meePXSMove, meePXSPos, mrfUserCheck(), and PXS.

750 {
751  if (pReaction->fUserDefined) if (!mrfUserCheck(pReaction, iX, iY, iLSPosX, iLSPosY, fXDir, fYDir, iPxsMat, iLsMat, evEvent, pfPosChanged)) return false;
752  switch (evEvent)
753  {
754  case meePXSMove: // PXS movement
755  // for hardcoded stuff: only InMatConvert is Snow in Water, which does not have any collision proc
756  if (!pReaction->fUserDefined) break;
757  // user-defined conversions may also convert upon hitting materials
758 
759  case meePXSPos: // PXS check before movement
760  {
761  // Check depth
762  int32_t iDepth = pReaction->fUserDefined ? pReaction->iDepth : ::MaterialMap.Map[iPxsMat].InMatConvertDepth;
763  if (!iDepth || GBackMat(iX, iY - iDepth) == iLsMat)
764  {
765  // Convert
766  iPxsMat = pReaction->fUserDefined ? pReaction->iConvertMat : ::MaterialMap.Map[iPxsMat].InMatConvertTo;
767  if (!MatValid(iPxsMat))
768  // Convert failure (target mat not be loaded, or target may be C4TLS_MatSky): Kill Pix
769  return true;
770  // stop movement after conversion
771  fXDir = fYDir = 0;
772  if (pfPosChanged) *pfPosChanged = true;
773  }
774  }
775  break;
776 
777  case meeMassMove: // MassMover-movement
778  // Conversion-transfer to PXS
779  ::PXS.Create(iPxsMat,itofix(iX),itofix(iY));
780  return true;
781  }
782  // not handled
783  return false;
784 }
int32_t InMatConvertTo
Definition: C4Material.h:152
C4Material * Map
Definition: C4Material.h:169
bool Create(int32_t mat, C4Real ix, C4Real iy, C4Real ixdir=Fix0, C4Real iydir=Fix0)
Definition: C4PXS.cpp:174
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
C4PXSSystem PXS
Definition: C4PXS.cpp:422
int32_t InMatConvertDepth
Definition: C4Material.h:122
C4MaterialMap MaterialMap
Definition: C4Material.cpp:970
int32_t iConvertMat
Definition: C4Material.h:58
bool MatValid(int32_t mat)
Definition: C4Material.h:210
int32_t GBackMat(int32_t x, int32_t y)
Definition: C4Landscape.h:221
bool mrfUserCheck(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
Definition: C4Material.cpp:737

Here is the call graph for this function:

bool C4MaterialMap::mrfCorrode ( C4MaterialReaction pReaction,
int32_t &  iX,
int32_t &  iY,
int32_t  iLSPosX,
int32_t  iLSPosY,
C4Real fXDir,
C4Real fYDir,
int32_t &  iPxsMat,
int32_t  iLsMat,
MaterialInteractionEvent  evEvent,
bool *  pfPosChanged 
)
static

Definition at line 815 of file C4Material.cpp.

References C4Landscape::CheckInstabilityRange(), C4Landscape::ClearPix(), C4MaterialCore::Corrode, C4MaterialCore::Corrosive, C4MaterialReaction::fUserDefined, C4MaterialReaction::iCorrosionRate, C4Landscape::InsertMaterial(), Landscape, Map, MaterialMap, meeMassMove, meePXSMove, meePXSPos, mrfInsertCheck(), mrfUserCheck(), Random(), and StartSoundEffectAt().

816 {
817  if (pReaction->fUserDefined) if (!mrfUserCheck(pReaction, iX, iY, iLSPosX, iLSPosY, fXDir, fYDir, iPxsMat, iLsMat, evEvent, pfPosChanged)) return false;
818  switch (evEvent)
819  {
820  case meePXSPos: // PXS check before movement
821  // No corrosion - it would make acid incredibly effective
822  break;
823  case meeMassMove: // MassMover-movement
824  {
825  // evaluate corrosion percentage
826  bool fDoCorrode; int d100 = Random(100);
827  if (pReaction->fUserDefined)
828  fDoCorrode = (d100 < pReaction->iCorrosionRate);
829  else
830  fDoCorrode = (d100 < ::MaterialMap.Map[iPxsMat].Corrosive) && (d100 < ::MaterialMap.Map[iLsMat].Corrode);
831  if (fDoCorrode)
832  {
833  ::Landscape.ClearPix(iLSPosX,iLSPosY);
834  //::Landscape.CheckInstabilityRange(iLSPosX,iLSPosY); - more correct, but makes acid too effective as well
835  if (!Random(5))
836  {
837  Smoke(iX, iY, 3 + Random(3));
838  }
839  if (!Random(20)) StartSoundEffectAt("Liquids::Corrode", iX, iY);
840  return true;
841  }
842  }
843  break;
844 
845  case meePXSMove: // PXS movement
846  {
847  // corrodes to corrosives are always same density proc; so do insertion check first
848  if (!pReaction->fUserDefined)
849  if (!mrfInsertCheck(iX, iY, fXDir, fYDir, iPxsMat, iLsMat, pfPosChanged))
850  // either splash or slide prevented interaction
851  return false;
852  // evaluate corrosion percentage
853  bool fDoCorrode; int d100 = Random(100);
854  if (pReaction->fUserDefined)
855  fDoCorrode = (d100 < pReaction->iCorrosionRate);
856  else
857  fDoCorrode = (d100 < ::MaterialMap.Map[iPxsMat].Corrosive) && (d100 < ::MaterialMap.Map[iLsMat].Corrode);
858  if (fDoCorrode)
859  {
860  ::Landscape.ClearPix(iLSPosX,iLSPosY);
861  ::Landscape.CheckInstabilityRange(iLSPosX,iLSPosY);
862  if (!Random(5))
863  {
864  Smoke(iX,iY,3+Random(3));
865  }
866  if (!Random(20)) StartSoundEffectAt("Liquids::Corrode", iX, iY);
867  return true;
868  }
869  // Else: dead. Insert material here
870  ::Landscape.InsertMaterial(iPxsMat,&iX,&iY);
871  return true;
872  }
873  }
874  // not handled
875  return false;
876 }
uint32_t Random()
Definition: C4Random.cpp:43
int32_t Corrode
Definition: C4Material.h:110
C4Material * Map
Definition: C4Material.h:169
bool InsertMaterial(int32_t mat, int32_t *tx, int32_t *ty, int32_t vx=0, int32_t vy=0, bool query_only=false)
C4Landscape Landscape
void CheckInstabilityRange(int32_t tx, int32_t ty)
int32_t Corrosive
Definition: C4Material.h:109
C4MaterialMap MaterialMap
Definition: C4Material.cpp:970
bool ClearPix(int32_t tx, int32_t ty)
bool mrfInsertCheck(int32_t &iX, int32_t &iY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, bool *pfPosChanged, bool no_slide=false)
Definition: C4Material.cpp:663
class C4SoundInstance * StartSoundEffectAt(const char *, int32_t, int32_t, int32_t, int32_t, int32_t, class C4SoundModifier *)
Definition: stub-handle.cpp:41
int32_t iCorrosionRate
Definition: C4Material.h:59
bool mrfUserCheck(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
Definition: C4Material.cpp:737

Here is the call graph for this function:

bool C4MaterialMap::mrfIncinerate ( C4MaterialReaction pReaction,
int32_t &  iX,
int32_t &  iY,
int32_t  iLSPosX,
int32_t  iLSPosY,
C4Real fXDir,
C4Real fYDir,
int32_t &  iPxsMat,
int32_t  iLsMat,
MaterialInteractionEvent  evEvent,
bool *  pfPosChanged 
)
static

Definition at line 878 of file C4Material.cpp.

References C4MaterialReaction::fUserDefined, C4Landscape::Incinerate(), C4Landscape::InsertMaterial(), Landscape, meeMassMove, meePXSMove, meePXSPos, mrfInsertCheck(), and NO_OWNER.

879 {
880  // not available as user reaction
881  assert(!pReaction->fUserDefined);
882  switch (evEvent)
883  {
884  case meeMassMove: // MassMover-movement
885  case meePXSPos: // PXS check before movement
886  if (::Landscape.Incinerate(iX, iY, NO_OWNER)) return true;
887  break;
888 
889  case meePXSMove: // PXS movement
890  // incinerate to inflammables are always same density proc; so do insertion check first
891  if (!mrfInsertCheck(iX, iY, fXDir, fYDir, iPxsMat, iLsMat, pfPosChanged))
892  // either splash or slide prevented interaction
893  return false;
894  // evaluate inflammation (should always succeed)
895  if (::Landscape.Incinerate(iX, iY, NO_OWNER)) return true;
896  // Else: dead. Insert material here
897  ::Landscape.InsertMaterial(iPxsMat,&iX,&iY);
898  return true;
899  }
900  // not handled
901  return false;
902 }
bool Incinerate(int32_t x, int32_t y, int32_t cause_player)
bool InsertMaterial(int32_t mat, int32_t *tx, int32_t *ty, int32_t vx=0, int32_t vy=0, bool query_only=false)
C4Landscape Landscape
const int NO_OWNER
Definition: C4Constants.h:137
bool mrfInsertCheck(int32_t &iX, int32_t &iY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, bool *pfPosChanged, bool no_slide=false)
Definition: C4Material.cpp:663

Here is the call graph for this function:

bool C4MaterialMap::mrfInsert ( C4MaterialReaction pReaction,
int32_t &  iX,
int32_t &  iY,
int32_t  iLSPosX,
int32_t  iLSPosY,
C4Real fXDir,
C4Real fYDir,
int32_t &  iPxsMat,
int32_t  iLsMat,
MaterialInteractionEvent  evEvent,
bool *  pfPosChanged 
)
static

Definition at line 904 of file C4Material.cpp.

References C4MaterialReaction::fUserDefined, C4Landscape::InsertMaterial(), Landscape, meeMassMove, meePXSMove, meePXSPos, mrfInsertCheck(), and mrfUserCheck().

905 {
906  if (pReaction->fUserDefined) if (!mrfUserCheck(pReaction, iX, iY, iLSPosX, iLSPosY, fXDir, fYDir, iPxsMat, iLsMat, evEvent, pfPosChanged)) return false;
907  switch (evEvent)
908  {
909  case meePXSPos: // PXS check before movement
910  break;
911 
912  case meePXSMove: // PXS movement
913  {
914  // check for bounce/slide
915  if (!pReaction->fUserDefined)
916  if (!mrfInsertCheck(iX, iY, fXDir, fYDir, iPxsMat, iLsMat, pfPosChanged))
917  // continue existing
918  return false;
919  // Else: dead. Insert material here
920  ::Landscape.InsertMaterial(iPxsMat,&iX,&iY);
921  return true;
922  }
923 
924  case meeMassMove: // MassMover-movement
925  break;
926  }
927  // not handled
928  return false;
929 }
bool InsertMaterial(int32_t mat, int32_t *tx, int32_t *ty, int32_t vx=0, int32_t vy=0, bool query_only=false)
C4Landscape Landscape
bool mrfInsertCheck(int32_t &iX, int32_t &iY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, bool *pfPosChanged, bool no_slide=false)
Definition: C4Material.cpp:663
bool mrfUserCheck(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
Definition: C4Material.cpp:737

Here is the call graph for this function:

bool C4MaterialMap::mrfPoof ( C4MaterialReaction pReaction,
int32_t &  iX,
int32_t &  iY,
int32_t  iLSPosX,
int32_t  iLSPosY,
C4Real fXDir,
C4Real fYDir,
int32_t &  iPxsMat,
int32_t  iLsMat,
MaterialInteractionEvent  evEvent,
bool *  pfPosChanged 
)
static

Definition at line 786 of file C4Material.cpp.

References C4Landscape::ExtractMaterial(), C4MaterialReaction::fUserDefined, Landscape, meeMassMove, meePXSMove, meePXSPos, mrfInsertCheck(), mrfUserCheck(), Random(), and StartSoundEffectAt().

787 {
788  if (pReaction->fUserDefined) if (!mrfUserCheck(pReaction, iX, iY, iLSPosX, iLSPosY, fXDir, fYDir, iPxsMat, iLsMat, evEvent, pfPosChanged)) return false;
789  switch (evEvent)
790  {
791  case meeMassMove: // MassMover-movement
792  case meePXSPos: // PXS check before movement: Kill both landscape and PXS mat
793  ::Landscape.ExtractMaterial(iLSPosX,iLSPosY,false);
794  if (!Random(3)) Smoke(iX,iY,3);
795  if (!Random(3)) StartSoundEffectAt("Liquids::Pshshsh", iX, iY);
796  return true;
797 
798  case meePXSMove: // PXS movement
799  // incindiary/extinguisher/corrosives are always same density proc; so do insertion check first
800  // Do not allow sliding though (e.g. water on lava).
801  if (!pReaction->fUserDefined)
802  if (!mrfInsertCheck(iX, iY, fXDir, fYDir, iPxsMat, iLsMat, pfPosChanged, true))
803  // either splash or slide prevented interaction
804  return false;
805  // Always kill both landscape and PXS mat
806  ::Landscape.ExtractMaterial(iLSPosX,iLSPosY,false);
807  if (!Random(3)) Smoke(iX,iY,3);
808  if (!Random(3)) StartSoundEffectAt("Liquids::Pshshsh", iX, iY);
809  return true;
810  }
811  // not handled
812  return false;
813 }
uint32_t Random()
Definition: C4Random.cpp:43
C4Landscape Landscape
int32_t ExtractMaterial(int32_t fx, int32_t fy, bool distant_first)
bool mrfInsertCheck(int32_t &iX, int32_t &iY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, bool *pfPosChanged, bool no_slide=false)
Definition: C4Material.cpp:663
class C4SoundInstance * StartSoundEffectAt(const char *, int32_t, int32_t, int32_t, int32_t, int32_t, class C4SoundModifier *)
Definition: stub-handle.cpp:41
bool mrfUserCheck(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
Definition: C4Material.cpp:737

Here is the call graph for this function:

bool C4MaterialMap::mrfScript ( C4MaterialReaction pReaction,
int32_t &  iX,
int32_t &  iY,
int32_t  iLSPosX,
int32_t  iLSPosY,
C4Real fXDir,
C4Real fYDir,
int32_t &  iPxsMat,
int32_t  iLsMat,
MaterialInteractionEvent  evEvent,
bool *  pfPosChanged 
)
static

Definition at line 931 of file C4Material.cpp.

References C4REAL100(), C4AulFunc::Exec(), fixtoi(), mrfUserCheck(), and C4MaterialReaction::pScriptFunc.

Referenced by C4MaterialReaction::ResolveScriptFuncs().

932 {
933  // do generic checks for user-defined reactions
934  if (!mrfUserCheck(pReaction, iX, iY, iLSPosX, iLSPosY, fXDir, fYDir, iPxsMat, iLsMat, evEvent, pfPosChanged))
935  return false;
936 
937  // check script func
938  if (!pReaction->pScriptFunc) return false;
939  // OK - let's call it!
940  // 0 1 2 3 4 5 6 7 8
941  int32_t iXDir1, iYDir1, iXDir2, iYDir2;
942  C4AulParSet pars(iX, iY, iLSPosX, iLSPosY, iXDir1 = fixtoi(fXDir, 100), iYDir1 = fixtoi(fYDir, 100), iPxsMat, iLsMat, int(evEvent));
943  if (!!pReaction->pScriptFunc->Exec(nullptr, &pars, false))
944  {
945  // PXS shall be killed!
946  return true;
947  }
948  // PXS shall exist further: write back parameters
949  iPxsMat = pars[6].getInt();
950  int32_t iX2 = pars[0].getInt(), iY2 = pars[1].getInt();
951  iXDir2 = pars[4].getInt(); iYDir2 = pars[5].getInt();
952  if (iX!=iX2 || iY!=iY2 || iXDir1!=iXDir2 || iYDir1!=iYDir2)
953  {
954  // changes to pos/speed detected
955  if (pfPosChanged) *pfPosChanged = true;
956  iX=iX2; iY=iY2;
957  fXDir = C4REAL100(iXDir2);
958  fYDir = C4REAL100(iYDir2);
959  }
960  // OK; done
961  return false;
962 }
C4Real C4REAL100(int x)
Definition: C4Real.h:267
C4Value Exec(C4PropList *p=nullptr, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4AulFunc.h:72
C4AulFunc * pScriptFunc
Definition: C4Material.h:51
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259
bool mrfUserCheck(C4MaterialReaction *pReaction, int32_t &iX, int32_t &iY, int32_t iLSPosX, int32_t iLSPosY, C4Real &fXDir, C4Real &fYDir, int32_t &iPxsMat, int32_t iLsMat, MaterialInteractionEvent evEvent, bool *pfPosChanged)
Definition: C4Material.cpp:737

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MaterialMap::SaveEnumeration ( C4Group hGroup)

Definition at line 570 of file C4Material.cpp.

References C4Group::Add(), C4CFN_MatMap, LineFeed, Map, Num, SAppend(), and SLen().

571 {
572  char *mapbuf = new char [1000];
573  mapbuf[0]=0;
574  SAppend("[Enumeration]",mapbuf); SAppend(LineFeed,mapbuf);
575  for (int32_t cnt=0; cnt<Num; cnt++)
576  {
577  SAppend(Map[cnt].Name,mapbuf);
578  SAppend(LineFeed,mapbuf);
579  }
580  return hGroup.Add(C4CFN_MatMap,mapbuf,SLen(mapbuf),false,true);
581 }
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:257
#define C4CFN_MatMap
Definition: C4Components.h:81
C4Material * Map
Definition: C4Material.h:169
size_t SLen(const char *sptr)
Definition: Standard.h:74
int32_t Num
Definition: C4Material.h:168
#define LineFeed
Definition: Standard.h:147
bool Add(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1316

Here is the call graph for this function:

void C4MaterialMap::SetMatReaction ( int32_t  iPXSMat,
int32_t  iLSMat,
C4MaterialReaction pReact 
)
protected

Definition at line 562 of file C4Material.cpp.

References C4MaterialReaction::fReverse, Num, and ppReactionMap.

Referenced by CrossMapMaterials().

563 {
564  // evaluate reaction swap
565  if (pReact && pReact->fReverse) std::swap(iPXSMat, iLSMat);
566  // set it
567  ppReactionMap[(iLSMat+1)*(Num+1) + iPXSMat+1] = pReact;
568 }
C4MaterialReaction ** ppReactionMap
Definition: C4Material.h:170
int32_t Num
Definition: C4Material.h:168

Here is the caller graph for this function:

bool C4MaterialMap::SortEnumeration ( int32_t  iMat,
const char *  szMatName 
)
protected

Definition at line 611 of file C4Material.cpp.

References Map, Num, and SEqual().

Referenced by LoadEnumeration().

612 {
613 
614  // Not enough materials loaded
615  if (iMat>=Num) return false;
616 
617  // Find requested mat
618  int32_t cmat;
619  for (cmat=iMat; cmat<Num; cmat++)
620  if (SEqual(szMatName,Map[cmat].Name))
621  break;
622  // Not found
623  if (cmat>=Num) return false;
624 
625  // already the same?
626  if (cmat == iMat) return true;
627 
628  // Move requested mat to indexed position
629  C4Material mswap;
630  mswap = Map[iMat];
631  Map[iMat] = Map[cmat];
632  Map[cmat] = mswap;
633 
634  return true;
635 }
C4Material * Map
Definition: C4Material.h:169
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
int32_t Num
Definition: C4Material.h:168

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MaterialMap::UpdateScriptPointers ( )

Definition at line 964 of file C4Material.cpp.

References Map, and Num.

Referenced by C4Game::InitMaterialTexture(), C4Game::LinkScriptEngine(), and C4Game::ReLinkScriptEngine().

965 {
966  // update in all materials
967  for (int32_t i=0; i<Num; ++i) Map[i].UpdateScriptPointers();
968 }
C4Material * Map
Definition: C4Material.h:169
int32_t Num
Definition: C4Material.h:168
void UpdateScriptPointers()
Definition: C4Material.cpp:964

Here is the caller graph for this function:

Member Data Documentation

C4MaterialReaction C4MaterialMap::DefReactConvert

Definition at line 173 of file C4Material.h.

Referenced by CrossMapMaterials().

C4MaterialReaction C4MaterialMap::DefReactCorrode

Definition at line 173 of file C4Material.h.

Referenced by CrossMapMaterials().

C4MaterialReaction C4MaterialMap::DefReactIncinerate

Definition at line 173 of file C4Material.h.

Referenced by CrossMapMaterials().

C4MaterialReaction C4MaterialMap::DefReactInsert

Definition at line 173 of file C4Material.h.

Referenced by CrossMapMaterials().

C4MaterialReaction C4MaterialMap::DefReactPoof

Definition at line 173 of file C4Material.h.

Referenced by CrossMapMaterials().

int32_t C4MaterialMap::max_shape_height

Definition at line 171 of file C4Material.h.

Referenced by CrossMapMaterials(), Default(), and C4Landscape::P::MapToSurface().

int32_t C4MaterialMap::max_shape_width

Definition at line 171 of file C4Material.h.

Referenced by CrossMapMaterials(), Default(), and C4Landscape::P::MapToSurface().

C4MaterialReaction** C4MaterialMap::ppReactionMap

Definition at line 170 of file C4Material.h.

Referenced by Clear(), CrossMapMaterials(), Default(), GetReaction(), and SetMatReaction().


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