OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Material.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Material definitions used by the landscape */
19 
20 #ifndef INC_C4Material
21 #define INC_C4Material
22 
23 #include "config/C4Constants.h"
24 #include "lib/C4Real.h"
25 #include "object/C4Id.h"
26 #include "object/C4Shape.h"
27 #include "graphics/C4Facet.h"
28 #include "graphics/CSurface8.h"
29 #include <vector>
30 
31 #define C4MatOv_Default 0
32 #define C4MatOv_Exact 1
33 #define C4MatOv_None 2
34 #define C4MatOv_HugeZoom 4
35 
37 {
38  meePXSPos=0, // PXS check before movement
39  meePXSMove=1, // PXS movement
40  meeMassMove=2 // MassMover-movement
41 };
42 
43 typedef bool (*C4MaterialReactionFunc)(struct 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);
44 
46 {
47  static inline bool NoReaction(struct 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) { return false; }
48 
49  C4MaterialReactionFunc pFunc; // Guarantueed to be non-nullptr
50  bool fUserDefined; // false for internal reactions generated by material parameters
51  StdCopyStrBuf TargetSpec; // target material specification
52  StdCopyStrBuf ScriptFunc; // for reaction func 'script': Script func to be called for reaction evaluation
53  C4AulFunc *pScriptFunc; // resolved script function
54  uint32_t iExecMask; // execution mask: Bit mask with indices into MaterialInteractionEvent
55  bool fReverse; // if set, spec will be handled as if specified in target mat def
56  bool fInverseSpec; // if set, all mats except the given are used
57  bool fInsertionCheck; // if set, splash/slide checks are done prior to reaction execution
58  int32_t iDepth; // in mat conversion depth
59  StdCopyStrBuf sConvertMat;// in mat conversion material (string)
60  int32_t iConvertMat; // in mat conversion material; evaluated in CrossMapMaterials
61  int32_t iCorrosionRate; // chance of doing a corrosion
62 
63  C4MaterialReaction(C4MaterialReactionFunc pFunc) : pFunc(pFunc), fUserDefined(false), pScriptFunc(nullptr), iExecMask(~0u), fReverse(false), fInverseSpec(false), fInsertionCheck(true), iDepth(0), iConvertMat(-1), iCorrosionRate(100) {}
64  C4MaterialReaction() : pFunc(&NoReaction), fUserDefined(true), pScriptFunc(nullptr), iExecMask(~0u), fReverse(false), fInverseSpec(false), fInsertionCheck(true), iDepth(0), iConvertMat(-1), iCorrosionRate(100) { }
65 
66  void CompileFunc(StdCompiler *pComp);
67 
68  void ResolveScriptFuncs(const char *szMatName);
69 
70  bool operator ==(const C4MaterialReaction &rCmp) const { return false; } // never actually called; only comparing with empty vector of C4MaterialReactions
71 };
72 
74 {
75  C4M_Flat = 0,
78  C4M_Rough = 3,
81 };
82 
84 {
85 public:
88 
89  std::vector<C4MaterialReaction> CustomReactionList;
90 
91  char Name[C4M_MaxName+1];
92 
94  int32_t Density;
95  int32_t Friction;
96  int32_t DigFree;
97  int32_t BlastFree;
99  int32_t Dig2ObjectRatio;
103  int32_t Blast2PXSRatio;
104  int32_t Instable;
105  int32_t MaxAirSpeed;
106  int32_t MaxSlide;
107  int32_t WindDrift;
108  int32_t Inflammable;
109  int32_t Incendiary;
110  int32_t Extinguisher;
111  int32_t Corrosive;
112  int32_t Corrode;
113  int32_t Soil;
114  int32_t Placement; // placement order for landscape shading
115  int32_t Light; // ambient light range for underground materials. currently only 1/0 for ambient light on/off
116  StdCopyStrBuf sTextureOverlay; // overlayed texture for this material
117  int32_t OverlayType; // defines the way in which the overlay texture is applied
118  StdCopyStrBuf sPXSGfx; // newgfx: picture used for loose pxs
119  C4TargetRect PXSGfxRt; // newgfx: facet rect of pixture used for loose pixels
120  int32_t PXSGfxSize;
124  int32_t InMatConvertDepth; // material converts only if it finds the same material above
132  int32_t MinHeightCount; // minimum material thickness in order for it to be counted
133  int32_t SplashRate;
134  bool KeepSinglePixels; // if true, single pixels are not destroyed (for vehicle)
135  int32_t AnimationSpeed; // frames per animation phase
136  int32_t LightAngle; // light angle at which we have maximum reflection
137  int32_t LightEmit[3]; // amount the material lights up itself
138  int32_t LightSpot[3]; // spot strength
139  int32_t MinShapeOverlap; // if drawn with a texture with custom shapes, minimum overlap of map pixels over shape blocks in percent to force them being drawn
140 
141  void Clear();
142  void Default();
143  bool Load(C4Group &hGroup, const char *szEntryName);
144  void CompileFunc(StdCompiler *pComp);
145 };
146 
148 {
149 public:
150  C4Material();
151 public:
152  // Cross-mapped material values
153  int32_t BlastShiftTo; // MatTex
154  int32_t InMatConvertTo; // Mat
155  int32_t BelowTempConvertTo; // MatTex
156  int32_t AboveTempConvertTo; // MatTex
157  int32_t DefaultMatTex; // texture used for single pixel values
158 
159  C4Facet PXSFace; // loose pixel facet
160 
161  void UpdateScriptPointers(); // set all material script pointers
162 };
163 
165 {
166 public:
167  C4MaterialMap();
168  ~C4MaterialMap();
169 public:
170  int32_t Num;
173  int32_t max_shape_width,max_shape_height; // maximum size of the largest polygon in any of the used shapes
174 
176 public:
177  // default reactions
178  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);
179  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);
180  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);
181  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);
182  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);
183  // user-defined actions
184  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);
185 public:
186  void Default();
187  void Clear();
188  int32_t Load(C4Group &hGroup);
189  bool HasMaterials(C4Group &hGroup) const;
190  int32_t Get(const char *szMaterial);
191  bool SaveEnumeration(C4Group &hGroup);
192  bool LoadEnumeration(C4Group &hGroup);
193  C4MaterialReaction *GetReactionUnsafe(int32_t iPXSMat, int32_t iLandscapeMat)
194  {
195  assert(ppReactionMap); assert(Inside<int32_t>(iPXSMat,-1,Num-1)); assert(Inside<int32_t>(iLandscapeMat,-1,Num-1));
196  return ppReactionMap[(iLandscapeMat+1)*(Num+1) + iPXSMat+1];
197  }
198  C4MaterialReaction *GetReaction(int32_t iPXSMat, int32_t iLandscapeMat);
199  void UpdateScriptPointers(); // set all material script pointers
200  bool CrossMapMaterials(const char* szEarthMaterial);
201 protected:
202  void SetMatReaction(int32_t iPXSMat, int32_t iLSMat, C4MaterialReaction *pReact);
203  bool SortEnumeration(int32_t iMat, const char *szMatName);
204 };
205 
207 
208 extern int32_t MVehic,MTunnel,MWater,MEarth; // presearched materials
209 extern BYTE MCVehic; // precalculated material color
210 extern BYTE MCHalfVehic; // precalculated material color
211 
212 inline bool MatValid(int32_t mat)
213 {
214  return Inside<int32_t>(mat,0,::MaterialMap.Num-1);
215 }
216 
217 inline bool MatVehicle(int32_t iMat)
218 {
219  return iMat == MVehic;
220 }
221 
222 inline bool IsMCVehicle(BYTE mat) {
223  return mat == MCVehic;
224 }
225 inline bool IsMCHalfVehicle(BYTE mat) {
226  return mat == MCHalfVehic;
227 }
228 inline bool IsSomeVehicle(BYTE mat) {
229  return IsMCVehicle(mat) || IsMCHalfVehicle(mat);
230 }
231 
232 inline BYTE MatTex2PixCol(int32_t tex)
233 {
234  return BYTE(tex);
235 }
236 
237 inline BYTE Mat2PixColDefault(int32_t mat)
238 {
240 }
241 
242 inline int32_t MatDensity(int32_t mat)
243 {
244  if (!MatValid(mat)) return 0;
246 }
247 
248 inline int32_t MatPlacement(int32_t mat)
249 {
250  if (!MatValid(mat)) return 0;
252 }
253 
254 inline int32_t MatDigFree(int32_t mat)
255 {
256  if (!MatValid(mat)) return 1;
258 }
259 
260 #endif
C4MaterialReaction * GetReactionUnsafe(int32_t iPXSMat, int32_t iLandscapeMat)
Definition: C4Material.h:193
int32_t BlastShiftTo
Definition: C4Material.h:153
StdCopyStrBuf TargetSpec
Definition: C4Material.h:51
int32_t Extinguisher
Definition: C4Material.h:110
uint32_t iExecMask
Definition: C4Material.h:54
int32_t DefaultMatTex
Definition: C4Material.h:157
int32_t InMatConvertTo
Definition: C4Material.h:154
int32_t MWater
Definition: C4Material.cpp:37
int32_t MaxSlide
Definition: C4Material.h:106
StdCopyStrBuf sTextureOverlay
Definition: C4Material.h:116
C4TargetRect PXSGfxRt
Definition: C4Material.h:119
bool LoadEnumeration(C4Group &hGroup)
Definition: C4Material.cpp:584
int32_t Corrode
Definition: C4Material.h:112
int32_t Instable
Definition: C4Material.h:104
bool MatVehicle(int32_t iMat)
Definition: C4Material.h:217
int32_t Friction
Definition: C4Material.h:95
C4Material * Map
Definition: C4Material.h:171
C4MaterialReaction DefReactInsert
Definition: C4Material.h:175
C4MaterialCoreShape
Definition: C4Material.h:73
int32_t OverlayType
Definition: C4Material.h:117
int32_t AnimationSpeed
Definition: C4Material.h:135
int32_t max_shape_height
Definition: C4Material.h:173
int32_t MEarth
Definition: C4Material.cpp:37
uint8_t BYTE
bool(* C4MaterialReactionFunc)(struct 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.h:43
static bool NoReaction(struct 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.h:47
int32_t BlastFree
Definition: C4Material.h:97
int32_t MinShapeOverlap
Definition: C4Material.h:139
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:787
StdCopyStrBuf sConvertMat
Definition: C4Material.h:59
int32_t MaxAirSpeed
Definition: C4Material.h:105
int32_t Dig2ObjectCollect
Definition: C4Material.h:100
Definition: C4Real.h:58
C4MaterialReactionFunc pFunc
Definition: C4Material.h:49
C4MaterialReaction DefReactIncinerate
Definition: C4Material.h:175
int32_t LightAngle
Definition: C4Material.h:136
StdCopyStrBuf sPXSGfx
Definition: C4Material.h:118
bool SaveEnumeration(C4Group &hGroup)
Definition: C4Material.cpp:571
bool SortEnumeration(int32_t iMat, const char *szMatName)
Definition: C4Material.cpp:612
const int C4M_MaxName
Definition: C4Constants.h:49
C4MaterialReaction DefReactPoof
Definition: C4Material.h:175
int32_t MatDigFree(int32_t mat)
Definition: C4Material.h:254
void SetMatReaction(int32_t iPXSMat, int32_t iLSMat, C4MaterialReaction *pReact)
Definition: C4Material.cpp:563
StdCopyStrBuf sBlastShiftTo
Definition: C4Material.h:121
int32_t MatDensity(int32_t mat)
Definition: C4Material.h:242
bool IsMCHalfVehicle(BYTE mat)
Definition: C4Material.h:225
bool operator==(const C4MaterialReaction &rCmp) const
Definition: C4Material.h:70
char Name[C4M_MaxName+1]
Definition: C4Material.h:91
int32_t Light
Definition: C4Material.h:115
int32_t AboveTempConvert
Definition: C4Material.h:128
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)
Definition: C4Material.cpp:931
int32_t MTunnel
Definition: C4Material.cpp:37
bool IsMCVehicle(BYTE mat)
Definition: C4Material.h:222
void UpdateScriptPointers()
Definition: C4Material.cpp:293
int32_t AboveTempConvertDir
Definition: C4Material.h:129
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
StdCopyStrBuf ScriptFunc
Definition: C4Material.h:52
int32_t Blast2PXSRatio
Definition: C4Material.h:103
void CompileFunc(StdCompiler *pComp)
Definition: C4Material.cpp:184
C4MaterialReaction DefReactConvert
Definition: C4Material.h:175
C4MaterialReaction * GetReaction(int32_t iPXSMat, int32_t iLandscapeMat)
Definition: C4Material.cpp:646
int32_t Blast2ObjectRatio
Definition: C4Material.h:102
int32_t AboveTempConvertTo
Definition: C4Material.h:156
C4MaterialReaction ** ppReactionMap
Definition: C4Material.h:172
StdCopyStrBuf sAboveTempConvertTo
Definition: C4Material.h:130
bool Load(C4Group &hGroup, const char *szEntryName)
Definition: C4Material.cpp:159
int32_t Num
Definition: C4Material.h:170
int32_t MinHeightCount
Definition: C4Material.h:132
Definition: C4Id.h:28
C4AulFunc * pScriptFunc
Definition: C4Material.h:53
C4MaterialReaction DefReactCorrode
Definition: C4Material.h:175
BYTE MCVehic
Definition: C4Material.cpp:38
StdCopyStrBuf sInMatConvertTo
Definition: C4Material.h:123
int32_t MatPlacement(int32_t mat)
Definition: C4Material.h:248
int32_t Dig2ObjectRatio
Definition: C4Material.h:99
int32_t Density
Definition: C4Material.h:94
C4MaterialReaction(C4MaterialReactionFunc pFunc)
Definition: C4Material.h:63
int32_t Soil
Definition: C4Material.h:113
int32_t PXSGfxSize
Definition: C4Material.h:120
int32_t Get(const char *szMaterial)
Definition: C4Material.cpp:362
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
int32_t BelowTempConvertTo
Definition: C4Material.h:155
int32_t SplashRate
Definition: C4Material.h:133
int32_t BelowTempConvert
Definition: C4Material.h:125
int32_t WindDrift
Definition: C4Material.h:107
int32_t InMatConvertDepth
Definition: C4Material.h:124
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
int32_t Corrosive
Definition: C4Material.h:111
C4MaterialCoreShape MapChunkType
Definition: C4Material.h:93
int32_t Placement
Definition: C4Material.h:114
C4MaterialMap MaterialMap
Definition: C4Material.cpp:970
bool KeepSinglePixels
Definition: C4Material.h:134
bool HasMaterials(C4Group &hGroup) const
Definition: C4Material.cpp:357
BYTE Mat2PixColDefault(int32_t mat)
Definition: C4Material.h:237
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:750
int32_t Load(C4Group &hGroup)
Definition: C4Material.cpp:320
int32_t max_shape_width
Definition: C4Material.h:173
void UpdateScriptPointers()
Definition: C4Material.cpp:964
int32_t Incendiary
Definition: C4Material.h:109
int32_t LightEmit[3]
Definition: C4Material.h:137
int32_t TempConvStrength
Definition: C4Material.h:131
int32_t LightSpot[3]
Definition: C4Material.h:138
int32_t iConvertMat
Definition: C4Material.h:60
bool IsSomeVehicle(BYTE mat)
Definition: C4Material.h:228
BYTE MatTex2PixCol(int32_t tex)
Definition: C4Material.h:232
StdCopyStrBuf sInMatConvert
Definition: C4Material.h:122
MaterialInteractionEvent
Definition: C4Material.h:36
std::vector< C4MaterialReaction > CustomReactionList
Definition: C4Material.h:89
void CompileFunc(StdCompiler *pComp)
Definition: C4Material.cpp:56
StdCopyStrBuf sBelowTempConvertTo
Definition: C4Material.h:127
bool MatValid(int32_t mat)
Definition: C4Material.h:212
C4Facet PXSFace
Definition: C4Material.h:159
int32_t iCorrosionRate
Definition: C4Material.h:61
BYTE MCHalfVehic
Definition: C4Material.cpp:39
int32_t DigFree
Definition: C4Material.h:96
int32_t BelowTempConvertDir
Definition: C4Material.h:126
int32_t Inflammable
Definition: C4Material.h:108
int32_t MVehic
Definition: C4Material.cpp:37
bool CrossMapMaterials(const char *szEarthMaterial)
Definition: C4Material.cpp:372
void ResolveScriptFuncs(const char *szMatName)
Definition: C4Material.cpp:79