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 "graphics/C4Facet.h"
25 #include "graphics/CSurface8.h"
26 #include "object/C4Id.h"
27 #include "object/C4Shape.h"
28 
29 #define C4MatOv_Default 0
30 #define C4MatOv_Exact 1
31 #define C4MatOv_None 2
32 #define C4MatOv_HugeZoom 4
33 
35 {
36  meePXSPos=0, // PXS check before movement
37  meePXSMove=1, // PXS movement
38  meeMassMove=2 // MassMover-movement
39 };
40 
41 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);
42 
44 {
45  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; }
46 
47  C4MaterialReactionFunc pFunc; // Guarantueed to be non-nullptr
48  bool fUserDefined{true}; // false for internal reactions generated by material parameters
49  StdCopyStrBuf TargetSpec; // target material specification
50  StdCopyStrBuf ScriptFunc; // for reaction func 'script': Script func to be called for reaction evaluation
51  C4AulFunc *pScriptFunc{nullptr}; // resolved script function
52  uint32_t iExecMask; // execution mask: Bit mask with indices into MaterialInteractionEvent
53  bool fReverse{false}; // if set, spec will be handled as if specified in target mat def
54  bool fInverseSpec{false}; // if set, all mats except the given are used
55  bool fInsertionCheck{true}; // if set, splash/slide checks are done prior to reaction execution
56  int32_t iDepth{0}; // in mat conversion depth
57  StdCopyStrBuf sConvertMat;// in mat conversion material (string)
58  int32_t iConvertMat{-1}; // in mat conversion material; evaluated in CrossMapMaterials
59  int32_t iCorrosionRate{100}; // chance of doing a corrosion
60 
61  C4MaterialReaction(C4MaterialReactionFunc pFunc) : pFunc(pFunc), fUserDefined(false), pScriptFunc(nullptr), iExecMask(~0u) {}
62  C4MaterialReaction() : pFunc(&NoReaction), iExecMask(~0u) { }
63 
64  void CompileFunc(StdCompiler *pComp);
65 
66  void ResolveScriptFuncs(const char *szMatName);
67 
68  bool operator ==(const C4MaterialReaction &rCmp) const { return false; } // never actually called; only comparing with empty vector of C4MaterialReactions
69 };
70 
72 {
73  C4M_Flat = 0,
76  C4M_Rough = 3,
79 };
80 
82 {
83 public:
86 
87  std::vector<C4MaterialReaction> CustomReactionList;
88 
89  char Name[C4M_MaxName+1];
90 
92  int32_t Density;
93  int32_t Friction;
94  int32_t DigFree;
95  int32_t BlastFree;
97  int32_t Dig2ObjectRatio;
101  int32_t Blast2PXSRatio;
102  int32_t Instable;
103  int32_t MaxAirSpeed;
104  int32_t MaxSlide;
105  int32_t WindDrift;
106  int32_t Inflammable;
107  int32_t Incendiary;
108  int32_t Extinguisher;
109  int32_t Corrosive;
110  int32_t Corrode;
111  int32_t Soil;
112  int32_t Placement; // placement order for landscape shading
113  int32_t Light; // ambient light range for underground materials. currently only 1/0 for ambient light on/off
114  StdCopyStrBuf sTextureOverlay; // overlayed texture for this material
115  int32_t OverlayType; // defines the way in which the overlay texture is applied
116  StdCopyStrBuf sPXSGfx; // newgfx: picture used for loose pxs
117  C4TargetRect PXSGfxRt; // newgfx: facet rect of pixture used for loose pixels
118  int32_t PXSGfxSize;
122  int32_t InMatConvertDepth; // material converts only if it finds the same material above
130  int32_t MinHeightCount; // minimum material thickness in order for it to be counted
131  int32_t SplashRate;
132  bool KeepSinglePixels; // if true, single pixels are not destroyed (for vehicle)
133  int32_t AnimationSpeed; // frames per animation phase
134  int32_t LightAngle; // light angle at which we have maximum reflection
135  int32_t LightEmit[3]; // amount the material lights up itself
136  int32_t LightSpot[3]; // spot strength
137  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
138 
139  void Clear();
140  void Default();
141  bool Load(C4Group &hGroup, const char *szEntryName);
142  void CompileFunc(StdCompiler *pComp);
143 };
144 
146 {
147 public:
148  C4Material();
149 public:
150  // Cross-mapped material values
151  int32_t BlastShiftTo; // MatTex
152  int32_t InMatConvertTo; // Mat
153  int32_t BelowTempConvertTo; // MatTex
154  int32_t AboveTempConvertTo; // MatTex
155  int32_t DefaultMatTex; // texture used for single pixel values
156 
157  C4Facet PXSFace; // loose pixel facet
158 
159  void UpdateScriptPointers(); // set all material script pointers
160 };
161 
163 {
164 public:
165  C4MaterialMap();
166  ~C4MaterialMap();
167 public:
168  int32_t Num;
171  int32_t max_shape_width,max_shape_height; // maximum size of the largest polygon in any of the used shapes
172 
174 public:
175  // default reactions
176  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);
177  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);
178  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);
179  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);
180  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);
181  // user-defined actions
182  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);
183 public:
184  void Default();
185  void Clear();
186  int32_t Load(C4Group &hGroup);
187  bool HasMaterials(C4Group &hGroup) const;
188  int32_t Get(const char *szMaterial);
189  bool SaveEnumeration(C4Group &hGroup);
190  bool LoadEnumeration(C4Group &hGroup);
191  C4MaterialReaction *GetReactionUnsafe(int32_t iPXSMat, int32_t iLandscapeMat)
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  }
196  C4MaterialReaction *GetReaction(int32_t iPXSMat, int32_t iLandscapeMat);
197  void UpdateScriptPointers(); // set all material script pointers
198  bool CrossMapMaterials(const char* szEarthMaterial);
199 protected:
200  void SetMatReaction(int32_t iPXSMat, int32_t iLSMat, C4MaterialReaction *pReact);
201  bool SortEnumeration(int32_t iMat, const char *szMatName);
202 };
203 
205 
206 extern int32_t MVehic,MTunnel,MWater,MEarth; // presearched materials
207 extern BYTE MCVehic; // precalculated material color
208 extern BYTE MCHalfVehic; // precalculated material color
209 
210 inline bool MatValid(int32_t mat)
211 {
212  return Inside<int32_t>(mat,0,::MaterialMap.Num-1);
213 }
214 
215 inline bool MatVehicle(int32_t iMat)
216 {
217  return iMat == MVehic;
218 }
219 
220 inline bool IsMCVehicle(BYTE mat) {
221  return mat == MCVehic;
222 }
223 inline bool IsMCHalfVehicle(BYTE mat) {
224  return mat == MCHalfVehic;
225 }
226 inline bool IsSomeVehicle(BYTE mat) {
227  return IsMCVehicle(mat) || IsMCHalfVehicle(mat);
228 }
229 
230 inline BYTE MatTex2PixCol(int32_t tex)
231 {
232  return BYTE(tex);
233 }
234 
235 inline BYTE Mat2PixColDefault(int32_t mat)
236 {
238 }
239 
240 inline int32_t MatDensity(int32_t mat)
241 {
242  if (!MatValid(mat)) return 0;
244 }
245 
246 inline int32_t MatPlacement(int32_t mat)
247 {
248  if (!MatValid(mat)) return 0;
250 }
251 
252 inline int32_t MatDigFree(int32_t mat)
253 {
254  if (!MatValid(mat)) return 1;
256 }
257 
258 #endif
C4MaterialReaction * GetReactionUnsafe(int32_t iPXSMat, int32_t iLandscapeMat)
Definition: C4Material.h:191
int32_t BlastShiftTo
Definition: C4Material.h:151
StdCopyStrBuf TargetSpec
Definition: C4Material.h:49
int32_t Extinguisher
Definition: C4Material.h:108
uint32_t iExecMask
Definition: C4Material.h:52
int32_t DefaultMatTex
Definition: C4Material.h:155
int32_t InMatConvertTo
Definition: C4Material.h:152
int32_t MWater
Definition: C4Material.cpp:36
int32_t MaxSlide
Definition: C4Material.h:104
StdCopyStrBuf sTextureOverlay
Definition: C4Material.h:114
C4TargetRect PXSGfxRt
Definition: C4Material.h:117
bool LoadEnumeration(C4Group &hGroup)
Definition: C4Material.cpp:587
int32_t Corrode
Definition: C4Material.h:110
int32_t Instable
Definition: C4Material.h:102
bool MatVehicle(int32_t iMat)
Definition: C4Material.h:215
int32_t Friction
Definition: C4Material.h:93
C4Material * Map
Definition: C4Material.h:169
C4MaterialReaction DefReactInsert
Definition: C4Material.h:173
C4MaterialCoreShape
Definition: C4Material.h:71
int32_t OverlayType
Definition: C4Material.h:115
int32_t AnimationSpeed
Definition: C4Material.h:133
int32_t max_shape_height
Definition: C4Material.h:171
int32_t MEarth
Definition: C4Material.cpp:36
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:41
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:45
int32_t BlastFree
Definition: C4Material.h:95
int32_t MinShapeOverlap
Definition: C4Material.h:137
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:790
StdCopyStrBuf sConvertMat
Definition: C4Material.h:57
int32_t MaxAirSpeed
Definition: C4Material.h:103
int32_t Dig2ObjectCollect
Definition: C4Material.h:98
Definition: C4Real.h:58
C4MaterialReactionFunc pFunc
Definition: C4Material.h:47
C4MaterialReaction DefReactIncinerate
Definition: C4Material.h:173
int32_t LightAngle
Definition: C4Material.h:134
StdCopyStrBuf sPXSGfx
Definition: C4Material.h:116
bool SaveEnumeration(C4Group &hGroup)
Definition: C4Material.cpp:574
bool SortEnumeration(int32_t iMat, const char *szMatName)
Definition: C4Material.cpp:615
const int C4M_MaxName
Definition: C4Constants.h:49
C4MaterialReaction DefReactPoof
Definition: C4Material.h:173
int32_t MatDigFree(int32_t mat)
Definition: C4Material.h:252
void SetMatReaction(int32_t iPXSMat, int32_t iLSMat, C4MaterialReaction *pReact)
Definition: C4Material.cpp:566
StdCopyStrBuf sBlastShiftTo
Definition: C4Material.h:119
int32_t MatDensity(int32_t mat)
Definition: C4Material.h:240
bool IsMCHalfVehicle(BYTE mat)
Definition: C4Material.h:223
bool operator==(const C4MaterialReaction &rCmp) const
Definition: C4Material.h:68
char Name[C4M_MaxName+1]
Definition: C4Material.h:89
int32_t Light
Definition: C4Material.h:113
int32_t AboveTempConvert
Definition: C4Material.h:126
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:935
int32_t MTunnel
Definition: C4Material.cpp:36
bool IsMCVehicle(BYTE mat)
Definition: C4Material.h:220
void UpdateScriptPointers()
Definition: C4Material.cpp:292
int32_t AboveTempConvertDir
Definition: C4Material.h:127
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:882
StdCopyStrBuf ScriptFunc
Definition: C4Material.h:50
int32_t Blast2PXSRatio
Definition: C4Material.h:101
void CompileFunc(StdCompiler *pComp)
Definition: C4Material.cpp:183
C4MaterialReaction DefReactConvert
Definition: C4Material.h:173
C4MaterialReaction * GetReaction(int32_t iPXSMat, int32_t iLandscapeMat)
Definition: C4Material.cpp:649
int32_t Blast2ObjectRatio
Definition: C4Material.h:100
int32_t AboveTempConvertTo
Definition: C4Material.h:154
C4MaterialReaction ** ppReactionMap
Definition: C4Material.h:170
StdCopyStrBuf sAboveTempConvertTo
Definition: C4Material.h:128
bool Load(C4Group &hGroup, const char *szEntryName)
Definition: C4Material.cpp:158
int32_t Num
Definition: C4Material.h:168
int32_t MinHeightCount
Definition: C4Material.h:130
Definition: C4Id.h:25
C4AulFunc * pScriptFunc
Definition: C4Material.h:51
C4MaterialReaction DefReactCorrode
Definition: C4Material.h:173
C4ID Blast2Object
Definition: C4Material.h:99
BYTE MCVehic
Definition: C4Material.cpp:37
StdCopyStrBuf sInMatConvertTo
Definition: C4Material.h:121
int32_t MatPlacement(int32_t mat)
Definition: C4Material.h:246
int32_t Dig2ObjectRatio
Definition: C4Material.h:97
int32_t Density
Definition: C4Material.h:92
C4MaterialReaction(C4MaterialReactionFunc pFunc)
Definition: C4Material.h:61
int32_t Soil
Definition: C4Material.h:111
int32_t PXSGfxSize
Definition: C4Material.h:118
int32_t Get(const char *szMaterial)
Definition: C4Material.cpp:365
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:819
int32_t BelowTempConvertTo
Definition: C4Material.h:153
int32_t SplashRate
Definition: C4Material.h:131
int32_t BelowTempConvert
Definition: C4Material.h:123
int32_t WindDrift
Definition: C4Material.h:105
int32_t InMatConvertDepth
Definition: C4Material.h:122
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:908
int32_t Corrosive
Definition: C4Material.h:109
C4MaterialCoreShape MapChunkType
Definition: C4Material.h:91
int32_t Placement
Definition: C4Material.h:112
C4MaterialMap MaterialMap
Definition: C4Material.cpp:974
bool KeepSinglePixels
Definition: C4Material.h:132
bool HasMaterials(C4Group &hGroup) const
Definition: C4Material.cpp:360
BYTE Mat2PixColDefault(int32_t mat)
Definition: C4Material.h:235
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:753
int32_t Load(C4Group &hGroup)
Definition: C4Material.cpp:319
int32_t max_shape_width
Definition: C4Material.h:171
void UpdateScriptPointers()
Definition: C4Material.cpp:968
int32_t Incendiary
Definition: C4Material.h:107
int32_t LightEmit[3]
Definition: C4Material.h:135
int32_t TempConvStrength
Definition: C4Material.h:129
int32_t LightSpot[3]
Definition: C4Material.h:136
int32_t iConvertMat
Definition: C4Material.h:58
bool IsSomeVehicle(BYTE mat)
Definition: C4Material.h:226
BYTE MatTex2PixCol(int32_t tex)
Definition: C4Material.h:230
StdCopyStrBuf sInMatConvert
Definition: C4Material.h:120
MaterialInteractionEvent
Definition: C4Material.h:34
std::vector< C4MaterialReaction > CustomReactionList
Definition: C4Material.h:87
void CompileFunc(StdCompiler *pComp)
Definition: C4Material.cpp:55
StdCopyStrBuf sBelowTempConvertTo
Definition: C4Material.h:125
bool MatValid(int32_t mat)
Definition: C4Material.h:210
C4Facet PXSFace
Definition: C4Material.h:157
int32_t iCorrosionRate
Definition: C4Material.h:59
BYTE MCHalfVehic
Definition: C4Material.cpp:38
int32_t DigFree
Definition: C4Material.h:94
int32_t BelowTempConvertDir
Definition: C4Material.h:124
int32_t Inflammable
Definition: C4Material.h:106
int32_t MVehic
Definition: C4Material.cpp:36
bool CrossMapMaterials(const char *szEarthMaterial)
Definition: C4Material.cpp:375
void ResolveScriptFuncs(const char *szMatName)
Definition: C4Material.cpp:78