OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Def.cpp
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 /* Object definition */
19 
20 #include "C4Include.h"
22 #include "object/C4Def.h"
23 
24 #include "c4group/C4Components.h"
25 #include "graphics/C4Draw.h"
26 #include "graphics/C4DrawGL.h"
28 #include "graphics/CSurface8.h"
29 #include "landscape/C4Particles.h"
30 #include "landscape/C4SolidMask.h"
31 #include "lib/StdColors.h"
32 #include "lib/StdMeshLoader.h"
33 #include "object/C4Object.h"
34 #include "platform/C4FileMonitor.h"
35 #include "platform/C4SoundSystem.h"
36 #include "player/C4RankSystem.h"
37 
38 // Helper class to load additional resources required for meshes from
39 // a C4Group.
41 {
42 public:
43  C4DefAdditionalResourcesLoader(C4Group& hGroup): Group(hGroup) {}
44 
45  C4Surface* LoadTexture(const char* filename) override
46  {
47  if (!Group.AccessEntry(filename)) return nullptr;
48  C4Surface* surface = new C4Surface;
49  // Suppress error message here, StdMeshMaterial loader
50  // will show one.
51  if (!surface->Read(Group, GetExtension(filename), C4SF_MipMap))
52  { delete surface; surface = nullptr; }
53  return surface;
54  }
55 
56  StdStrBuf LoadShaderCode(const char* filename) override
57  {
58  StdStrBuf ret;
59  if (!Group.LoadEntryString(filename, &ret)) return StdStrBuf();
60  return ret;
61  }
62 
63  void AddShaderSlices(C4Shader& shader, int ssc) override
64  {
65 #ifndef USE_CONSOLE
66  // Add mesh-independent slices
67  shader.AddDefine("OPENCLONK");
68  shader.AddDefine("OC_MESH");
69 
70  if (ssc & C4SSC_MOD2) shader.AddDefine("OC_CLRMOD_MOD2");
71  if (ssc & C4SSC_LIGHT) shader.AddDefine("OC_DYNAMIC_LIGHT");
72 
73  // Note these are never set for meshes at the moment:
74  if (ssc & C4SSC_BASE) shader.AddDefine("OC_HAVE_BASE");
75  if (ssc & C4SSC_OVERLAY) shader.AddDefine("OC_HAVE_OVERLAY");
76 
77  shader.LoadFragmentSlices(&::GraphicsResource.Files, "CommonShader.glsl");
78  shader.LoadFragmentSlices(&::GraphicsResource.Files, "ObjectShader.glsl");
79 
80  // Categories for script shaders.
81  shader.SetScriptCategories({"Common", "Object"});
82 #endif
83  }
84 
85 private:
86  C4Group& Group;
87 };
88 
89 
90 
92 {
93  rC4XVer[0]=rC4XVer[1]=0;
94  RequireDef.Clear();
95  Shape.Default();
96  Entrance.Default();
100  TopFace.Default();
102  GrowthType=0;
103  CrewMember=0;
104  NativeCrew=0;
105  Mass=0;
106  Value=0;
107  Exclusive=0;
108  Category=0;
109  Constructable=0;
110  Rotateable=0;
111  RotatedEntrance=0;
112  Float=0;
113  ColorByOwner=0;
115  LiftTop=0;
116  GrabPutGet=0;
117  UprightAttach=0;
118  Line=0;
119  LineIntersect=0;
122  Oversize=0;
123  Fragile=0;
124  NoPushEnter=0;
125  Projectile=0;
126  VehicleControl=0;
127  Pathfinder=0;
129  MoveToRange=0;
130  NoStabilize=0;
131  ClosedContainer=0;
132  SilentCommands=0;
133  TemporaryCrew=0;
135  NoBreath=0;
136  ConSizeOff=0;
137  NoGet=0;
138  NoTransferZones=0;
139  HideInCreator = false;
140 }
141 
143 {
144  StdStrBuf Source;
145  if (hGroup.LoadEntryString(C4CFN_DefCore,&Source))
146  {
147  StdStrBuf Name = hGroup.GetFullName() + (const StdStrBuf &)FormatString("%cDefCore.txt", DirectorySeparator);
148  if (!Compile(Source.getData(), Name.getData()))
149  return false;
150  Source.Clear();
151 
152  // Check mass
153  if (Mass < 0)
154  {
155  DebugLogF("WARNING: Def %s (%s) at %s has invalid mass!", GetName(), id.ToString(), hGroup.GetFullName().getData());
156  Mass = 0;
157  }
158 
159  return true;
160  }
161  return false;
162 }
163 
164 bool C4Def::Save(C4Group &hGroup)
165 {
166  StdStrBuf Out;
167  if (! Decompile(&Out, FormatString("%s::DefCore.txt", id.ToString()).getData()) )
168  return false;
169  return hGroup.Add(C4CFN_DefCore,Out,false,true);
170 }
171 
172 bool C4Def::Compile(const char *szSource, const char *szName)
173 {
174  return CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(*this, "DefCore"), StdStrBuf(szSource), szName);
175 }
176 
177 bool C4Def::Decompile(StdStrBuf *pOut, const char *szName)
178 {
179  return DecompileToBuf_Log<StdCompilerINIWrite>(mkNamingAdapt(*this, "DefCore"), pOut, szName);
180 }
181 
183 {
184 
185  pComp->Value(mkNamingAdapt(id, "id", C4ID::None ));
186  pComp->Value(mkNamingAdapt(toC4CArr(rC4XVer), "Version" ));
187  pComp->Value(mkNamingAdapt(mkParAdapt(RequireDef, false), "RequireDef", C4IDList() ));
188 
189  const StdBitfieldEntry<int32_t> Categories[] =
190  {
191 
192  { "C4D_None", C4D_None },
193  { "C4D_StaticBack", C4D_StaticBack },
194  { "C4D_Structure", C4D_Structure },
195  { "C4D_Vehicle", C4D_Vehicle },
196  { "C4D_Living", C4D_Living },
197  { "C4D_Object", C4D_Object },
198 
199  { "C4D_Goal", C4D_Goal },
200  { "C4D_Rule", C4D_Rule },
201  { "C4D_Environment", C4D_Environment },
202 
203  { "C4D_Background", C4D_Background },
204  { "C4D_Parallax", C4D_Parallax },
205  { "C4D_MouseSelect", C4D_MouseSelect },
206  { "C4D_Foreground", C4D_Foreground },
207  { "C4D_MouseIgnore", C4D_MouseIgnore },
208  { "C4D_IgnoreFoW", C4D_IgnoreFoW },
209 
210  { nullptr, 0 }
211  };
212 
213  pComp->Value(mkNamingAdapt(mkBitfieldAdapt<int32_t>(Category, Categories),
214  "Category", 0 ));
215 
216  pComp->Value(mkParAdapt(Shape, static_cast<C4Shape*>(nullptr)));
217  pComp->Value(mkNamingAdapt(Value, "Value", 0 ));
218  pComp->Value(mkNamingAdapt(Mass, "Mass", 0 ));
219  pComp->Value(mkNamingAdapt(SolidMask, "SolidMask", TargetRect0 ));
220  pComp->Value(mkNamingAdapt(TopFace, "TopFace", TargetRect0 ));
221  pComp->Value(mkNamingAdapt(PictureRect, "Picture", Rect0 ));
222  pComp->Value(mkNamingAdapt(Entrance, "Entrance", Rect0 ));
223  pComp->Value(mkNamingAdapt(Collection, "Collection", Rect0 ));
224  pComp->Value(mkNamingAdapt(Exclusive, "Exclusive", 0 ));
225  pComp->Value(mkNamingAdapt(Line, "Line", 0 ));
226  // <Newton> undocumented, but obsolete? I don't understand the sense of this value.
227  pComp->Value(mkNamingAdapt(LineIntersect, "LineIntersect", 0 ));
228  pComp->Value(mkNamingAdapt(CrewMember, "CrewMember", 0 ));
229  pComp->Value(mkNamingAdapt(NativeCrew, "NoStandardCrew", 0 ));
230  pComp->Value(mkNamingAdapt(Constructable, "Construction", 0 ));
231 
232  const StdBitfieldEntry<int32_t> GrabPutGetTypes[] =
233  {
234 
235  { "C4D_GrabGet" ,C4D_Grab_Get},
236  { "C4D_GrabPut" ,C4D_Grab_Put},
237 
238  { nullptr, 0}
239  };
240 
241  pComp->Value(mkNamingAdapt(mkBitfieldAdapt(GrabPutGet, GrabPutGetTypes),
242  "GrabPutGet", 0 ));
243 
244  pComp->Value(mkNamingAdapt(Rotateable, "Rotate", 0 ));
245  pComp->Value(mkNamingAdapt(RotatedEntrance, "RotatedEntrance", 0 ));
246  pComp->Value(mkNamingAdapt(Float, "Float", 0 ));
247  pComp->Value(mkNamingAdapt(ColorByOwner, "ColorByOwner", 0 ));
248  pComp->Value(mkNamingAdapt(NoHorizontalMove, "HorizontalFix", 0 ));
249  pComp->Value(mkNamingAdapt(LiftTop, "LiftTop", 0 ));
250  pComp->Value(mkNamingAdapt(UprightAttach, "UprightAttach", 0 ));
251  pComp->Value(mkNamingAdapt(GrowthType, "StretchGrowth", 0 ));
252  pComp->Value(mkNamingAdapt(IncompleteActivity, "IncompleteActivity", 0 ));
253  pComp->Value(mkNamingAdapt(AttractLightning, "AttractLightning", 0 ));
254  pComp->Value(mkNamingAdapt(Oversize, "Oversize", 0 ));
255  // <Newton> Fragile and Projectile are kinda obsolete.
256  // Only used at one point in the command system. Should rather be solved with properties if at all
257  pComp->Value(mkNamingAdapt(Fragile, "Fragile", 0 ));
258  pComp->Value(mkNamingAdapt(Projectile, "Projectile", 0 ));
259 
260  pComp->Value(mkNamingAdapt(NoPushEnter, "NoPushEnter", 0 ));
261  pComp->Value(mkNamingAdapt(VehicleControl, "VehicleControl", 0 ));
262  pComp->Value(mkNamingAdapt(Pathfinder, "Pathfinder", 0 ));
263  pComp->Value(mkNamingAdapt(MoveToRange, "MoveToRange", 0 ));
264  pComp->Value(mkNamingAdapt(NoMassFromContents, "NoMassFromContents", 0 ));
265  pComp->Value(mkNamingAdapt(NoStabilize, "NoStabilize", 0 ));
266  pComp->Value(mkNamingAdapt(ClosedContainer, "ClosedContainer", 0 ));
267  pComp->Value(mkNamingAdapt(SilentCommands, "SilentCommands", 0 ));
268  pComp->Value(mkNamingAdapt(TemporaryCrew, "TemporaryCrew", 0 ));
269  pComp->Value(mkNamingAdapt(BlitMode, "BlitMode", C4D_Blit_Normal ));
270  pComp->Value(mkNamingAdapt(NoBreath, "NoBreath", 0 ));
271  pComp->Value(mkNamingAdapt(ConSizeOff, "ConSizeOff", 0 ));
272  pComp->Value(mkNamingAdapt(NoGet, "NoGet", 0 ));
273  pComp->Value(mkNamingAdapt(NoTransferZones, "NoTransferZones", 0 ));
274 
275  const StdBitfieldEntry<int32_t> AllowPictureStackModes[] =
276  {
277 
278  { "APS_Color", APS_Color },
279  { "APS_Graphics", APS_Graphics },
280  { "APS_Name", APS_Name },
281  { "APS_Overlay", APS_Overlay },
282  { nullptr, 0 }
283  };
284 
285  pComp->Value(mkNamingAdapt(mkBitfieldAdapt<int32_t>(AllowPictureStack, AllowPictureStackModes), //undocumented
286  "AllowPictureStack", 0 ));
287  pComp->Value(mkNamingAdapt(HideInCreator, "HideInCreator", false));
288 }
289 
290 //-------------------------------- C4Def -------------------------------------------------------
291 
292 C4Def::C4Def(): Script(), C4PropListStatic(ScriptEngine.GetPropList(), nullptr, nullptr)
293 {
294  Script.SetDef(this);
295  assert(ScriptEngine.GetPropList());
296  Graphics.pDef = this;
297  Default();
298 }
299 
301 {
302  DefaultDefCore();
303  Next=nullptr;
304  Temporary=false;
305  Filename[0]=0;
306  Creation=0;
307  Count=0;
308  MainFace.Set(nullptr,0,0,0,0);
309  Script.Clear();
310  StringTable.Clear();
311  pClonkNames=nullptr;
312  pRankNames=nullptr;
313  pRankSymbols=nullptr;
315  iNumRankSymbols=1;
316  pSolidMask = nullptr;
317 }
318 
320 {
321  Clear();
322 }
323 
325 {
326  Script.Clear();
328 
329  Graphics.Clear();
330 
331  StringTable.Clear();
332  if (pClonkNames && fClonkNamesOwned) delete pClonkNames; pClonkNames=nullptr;
333  if (pRankNames && fRankNamesOwned) delete pRankNames; pRankNames=nullptr;
336  delete pSolidMask; pSolidMask = nullptr;
337 }
338 
339 bool C4Def::Load(C4Group &hGroup,
340  StdMeshSkeletonLoader &loader,
341  DWORD dwLoadWhat,
342  const char *szLanguage,
343  C4SoundSystem *pSoundSystem,
344  C4DefGraphicsPtrBackup *gfx_backup
345  )
346 {
347  bool AddFileMonitoring = false;
348  if (Game.pFileMonitor && !SEqual(hGroup.GetFullName().getData(),Filename) && !hGroup.IsPacked())
349  AddFileMonitoring = true;
350 
351  // Store filename
352  SCopy(hGroup.GetFullName().getData(),Filename);
353 
354  // Verbose log filename
356  Log(hGroup.GetFullName().getData());
357 
358  if (AddFileMonitoring) Game.pFileMonitor->AddDirectory(Filename);
359 
360  // Pre-read all images and shader stuff because they ar eaccessed in unpredictable order during loading
363 
364  LoadMeshMaterials(hGroup, gfx_backup);
365  bool fSuccess = LoadParticleDef(hGroup);
366 
367  // Read DefCore
368  if (fSuccess) fSuccess = LoadDefCore(hGroup);
369 
370  // Skip def: don't even read sounds!
371  if (fSuccess && Game.C4S.Definitions.SkipDefs.GetIDCount(id, 1)) return false;
372 
373  // Read sounds, even if not a valid def (for pure ocd sound folders)
374  if (dwLoadWhat & C4D_Load_Sounds) LoadSounds(hGroup, pSoundSystem);
375 
376  // cancel if not a valid definition
377  if (!fSuccess) return false;
378 
379  // Read and parse SolidMask bitmap
380  if (!LoadSolidMask(hGroup)) return false;
381 
382  // Read surface bitmap, meshes, skeletons
383  if ((dwLoadWhat & C4D_Load_Bitmap) && !LoadGraphics(hGroup, loader)) return false;
384 
385  // Read string table
387 
388  // Register ID with script engine
389  ::ScriptEngine.RegisterGlobalConstant(id.ToString(), C4VPropList(this));
390  ParentKeyName = ::Strings.RegString(id.ToString());
391 
392  // Read script
393  if (dwLoadWhat & C4D_Load_Script) LoadScript(hGroup, szLanguage);
394 
395  // Read clonknames
396  if (dwLoadWhat & C4D_Load_ClonkNames) LoadClonkNames(hGroup, pClonkNames, szLanguage);
397 
398  // Read clonkranks
399  if (dwLoadWhat & C4D_Load_RankNames) LoadRankNames(hGroup, szLanguage);
400 
401  // Read rankfaces
402  if (dwLoadWhat & C4D_Load_RankFaces) LoadRankFaces(hGroup);
403 
404  // Temporary flag
405  if (dwLoadWhat & C4D_Load_Temporary) Temporary=true;
406 
407  return true;
408 }
409 
410 void C4Def::LoadMeshMaterials(C4Group &hGroup, C4DefGraphicsPtrBackup *gfx_backup)
411 {
412  // Load all mesh materials from this folder
413  C4DefAdditionalResourcesLoader loader(hGroup);
414  hGroup.ResetSearch();
415  char MaterialFilename[_MAX_PATH + 1]; *MaterialFilename = 0;
416 
417  for (const auto &mat : mesh_materials)
418  {
419  ::MeshMaterialManager.Remove(mat, &gfx_backup->GetUpdater());
420  }
421  mesh_materials.clear();
422  while (hGroup.FindNextEntry(C4CFN_DefMaterials, MaterialFilename, nullptr, !!*MaterialFilename))
423  {
424  StdStrBuf material;
425  if (hGroup.LoadEntryString(MaterialFilename, &material))
426  {
427  try
428  {
429  StdStrBuf buf;
430  buf.Copy(hGroup.GetName());
431  buf.Append("/"); buf.Append(MaterialFilename);
432  auto new_materials = ::MeshMaterialManager.Parse(material.getData(), buf.getData(), loader);
433  mesh_materials.insert(new_materials.begin(), new_materials.end());
434  }
435  catch (const StdMeshMaterialError& ex)
436  {
437  DebugLogF("Failed to read material script: %s", ex.what());
438  }
439  }
440  }
441 }
442 
443 bool C4Def::LoadParticleDef(C4Group &hGroup)
444 {
445  bool fSuccess = true;
446  // particle def?
447  if (hGroup.AccessEntry(C4CFN_ParticleCore))
448  {
449  // def loading not successful; abort after reading sounds
450  fSuccess = false;
451  // create new particle def
452  C4ParticleDef *pParticleDef = new C4ParticleDef();
453  // load it
454  if (!pParticleDef->Load(hGroup))
455  {
456  // not successful :( - destroy it again
457  delete pParticleDef;
458  }
459  // done
460  }
461  return fSuccess;
462 }
463 
464 bool C4Def::LoadSolidMask(C4Group &hGroup)
465 {
466  if (hGroup.FindEntry(C4CFN_SolidMask))
467  {
469  if (!pSolidMask)
470  {
471  DebugLogF(" Error loading SolidMask of %s (%s)", hGroup.GetFullName().getData(), id.ToString());
472  return false;
473  }
474  // check SolidMask size
476  }
477  else if (SolidMask.Wdt)
478  {
479  // Warning in case someone wants to define SolidMasks the old way (in the main graphics file)
480  DebugLogF("WARNING: Definition %s (%s) defines SolidMask in DefCore but has no SolidMask file!", hGroup.GetFullName().getData(), id.ToString());
481  SolidMask.Default();
482  }
483 
484  return true;
485 }
486 
487 bool C4Def::LoadGraphics(C4Group &hGroup, StdMeshSkeletonLoader &loader)
488 {
489  // Try to load graphics
490  // No fail on error - just have an object without graphics.
491  Graphics.Load(hGroup, loader, !!ColorByOwner);
492 
494  {
495  // Bitmap post-load settings
496  if (Graphics.GetBitmap())
497  {
498  // Set MainFace (unassigned bitmap: will be set by GetMainFace())
499  MainFace.Set(nullptr, 0, 0, Shape.Wdt, Shape.Hgt);
500  }
501 
502  // Adjust picture rect
503  if ((PictureRect.Wdt == 0) || (PictureRect.Hgt == 0))
504  PictureRect.Set(0, 0, Shape.Wdt*Graphics.Bmp.Bitmap->Scale, Shape.Hgt*Graphics.Bmp.Bitmap->Scale);
505 
506  // validate TopFace
507  if (TopFace.x<0 || TopFace.y<0 || TopFace.x + TopFace.Wdt>Graphics.Bmp.Bitmap->Wdt || TopFace.y + TopFace.Hgt>Graphics.Bmp.Bitmap->Hgt)
508  {
509  TopFace.Default();
510  // warn in debug mode
511  DebugLogF("invalid TopFace in %s (%s)", GetName(), id.ToString());
512  }
513  }
514  else
515  {
516  TopFace.Default();
517  }
518 
519  return true;
520 }
521 
522 void C4Def::LoadScript(C4Group &hGroup, const char* szLanguage)
523 {
524  // reg script to engine
526  // Load script
527  Script.Load(hGroup, C4CFN_Script, szLanguage, &StringTable);
528 }
529 
530 void C4Def::LoadClonkNames(C4Group &hGroup, C4ComponentHost* pClonkNames, const char* szLanguage)
531 {
532  // clear any previous
533  if (pClonkNames) delete pClonkNames; pClonkNames = nullptr;
534  if (hGroup.FindEntry(C4CFN_ClonkNameFiles))
535  {
536  // create new
537  pClonkNames = new C4ComponentHost();
538  if (!C4Language::LoadComponentHost(pClonkNames, hGroup, C4CFN_ClonkNames, szLanguage))
539  {
540  delete pClonkNames; pClonkNames = nullptr;
541  }
542  else
543  fClonkNamesOwned = true;
544  }
545 }
546 
547 void C4Def::LoadRankNames(C4Group &hGroup, const char* szLanguage)
548 {
549  // clear any previous
550  if (pRankNames) delete pRankNames; pRankNames = nullptr;
551  if (hGroup.FindEntry(C4CFN_RankNameFiles))
552  {
553  // create new
554  pRankNames = new C4RankSystem();
555  // load from group
556  if (!pRankNames->Load(hGroup, C4CFN_RankNames, 1000, szLanguage))
557  {
558  delete pRankNames; pRankNames = nullptr;
559  }
560  else
561  fRankNamesOwned = true;
562  }
563 }
564 
565 void C4Def::LoadRankFaces(C4Group &hGroup)
566 {
567  // clear any previous
568  if (pRankSymbols) delete pRankSymbols; pRankSymbols = nullptr;
569  // load new
570  if (hGroup.AccessEntry(C4CFN_RankFacesPNG))
571  {
573  if (!pRankSymbols->GetFace().ReadPNG(hGroup, false)) { delete pRankSymbols; pRankSymbols = nullptr; }
574  }
575  // set size
576  if (pRankSymbols)
577  {
579  int32_t Q; pRankSymbols->GetPhaseNum(iNumRankSymbols, Q);
580  if (!iNumRankSymbols) { delete pRankSymbols; pRankSymbols = nullptr; }
581  else
582  {
583  if (pRankNames)
584  {
585  // if extended rank names are defined, subtract those from the symbol count. The last symbols are used as overlay
586  iNumRankSymbols = std::max<int32_t>(1, iNumRankSymbols - pRankNames->GetExtendedRankNum());
587  }
588  fRankSymbolsOwned = true;
589  }
590  }
591 }
592 
593 void C4Def::LoadSounds(C4Group &hGroup, C4SoundSystem* pSoundSystem)
594 {
595  if (pSoundSystem)
596  pSoundSystem->LoadEffects(hGroup, (id == C4ID::None) ? nullptr : id.ToString(), true);
597 }
598 
599 void C4Def::Draw(C4Facet &cgo, bool fSelected, DWORD iColor, C4Object *pObj, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform* trans, const char *graphicsName)
600 {
601  if(fSelected)
602  pDraw->DrawBoxDw(cgo.Surface, cgo.X, cgo.Y, cgo.X + cgo.Wdt - 1, cgo.Y + cgo.Hgt - 1, C4RGB(0xca, 0, 0));
603 
604  C4DefGraphics* graphics = pObj ? pObj->GetGraphics() : &Graphics;
605  if (graphicsName)
606  {
607  C4DefGraphics *other = graphics->Get(graphicsName);
608  if (other) graphics = other;
609  }
610  graphics->Draw(cgo, iColor, pObj, iPhaseX, iPhaseY, trans);
611 }
612 
613 int32_t C4Def::GetValue(C4Object *pInBase, int32_t iBuyPlayer)
614 {
615  C4Value r = Call(PSF_CalcDefValue, &C4AulParSet(pInBase, iBuyPlayer));
616  int32_t iValue = Value;
617  if (r != C4VNull)
618  iValue = r.getInt();
619  // do any adjustments based on where the item is bought
620  if (pInBase)
621  {
622  r = pInBase->Call(PSF_CalcBuyValue, &C4AulParSet(this, iValue));
623  if (r != C4VNull)
624  iValue = r.getInt();
625  }
626  return iValue;
627 }
628 
630 {
631 }
632 
633 void C4Def::IncludeDefinition(C4Def *pIncludeDef)
634 {
635  // inherited rank infos and clonk names, if this definition doesn't have its own
636  if (!fClonkNamesOwned) pClonkNames = pIncludeDef->pClonkNames;
637  if (!fRankNamesOwned) pRankNames = pIncludeDef->pRankNames;
638  if (!fRankSymbolsOwned) { pRankSymbols = pIncludeDef->pRankSymbols; iNumRankSymbols = pIncludeDef->iNumRankSymbols; }
639 }
640 
642 {
643  // clear all pointers into foreign defs
644  if (!fClonkNamesOwned) pClonkNames = nullptr;
645  if (!fRankNamesOwned) pRankNames = nullptr;
646  if (!fRankSymbolsOwned) { pRankSymbols = nullptr; iNumRankSymbols = 0; }
647 }
648 
649 C4PropList *C4Def::GetActionByName(const char *actname)
650 {
651  if (!actname) return nullptr;
652  C4String * actname_str = Strings.RegString(actname);
653  actname_str->IncRef();
654  C4PropList *r = GetActionByName(actname_str);
655  actname_str->DecRef();
656  return r;
657 }
658 
660 {
661  assert(actname);
662  // If we get the null string or ActIdle by name, return nullptr action
663  if (!actname || actname == &Strings.P[P_Idle]) return nullptr;
664  // otherwise, query actmap
665  C4Value ActMap; GetProperty(P_ActMap, &ActMap);
666  if (!ActMap.getPropList()) return nullptr;
667  C4Value Action; ActMap.getPropList()->GetPropertyByS(actname, &Action);
668  if (!Action.getPropList()) return nullptr;
669  return Action.getPropList();
670 }
const char * getData() const
Definition: StdBuf.h:442
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
#define C4CFN_DefCore
Definition: C4Components.h:46
int32_t Pathfinder
Definition: C4Def.h:135
C4String P[P_LAST]
int32_t GetIDCount(C4ID c_id, int32_t iZeroDefVal=0) const
Definition: stub-handle.cpp:67
#define toC4CArr(rArr)
Definition: StdAdaptors.h:28
bool Load(C4Group &hGroup, StdMeshSkeletonLoader &loader, DWORD dwLoadWhat, const char *szLanguage, class C4SoundSystem *pSoundSystem=nullptr, C4DefGraphicsPtrBackup *gfx_backup=nullptr)
void RegisterGlobalConstant(const char *szName, const C4Value &rValue)
void DefaultDefCore()
Definition: C4Def.cpp:91
int32_t Line
Definition: C4Def.h:126
int32_t Exclusive
Definition: C4Def.h:116
void Clear()
Definition: stub-handle.cpp:64
Definition: StdAdaptors.h:850
C4Config Config
Definition: C4Config.cpp:833
int32_t iNumRankSymbols
Definition: C4Def.h:191
int32_t UprightAttach
Definition: C4Def.h:125
int32_t Creation
Definition: C4Def.h:179
float Y
Definition: C4Facet.h:118
const int32_t C4D_Environment
Definition: C4Def.h:48
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
C4SDefinitions Definitions
Definition: C4Scenario.h:231
int32_t AttractLightning
Definition: C4Def.h:129
const int32_t C4D_Vehicle
Definition: C4Def.h:42
int32_t NoTransferZones
Definition: C4Def.h:147
C4PropListStatic * GetPropList()
Definition: C4Aul.h:151
void SetScriptCategories(const std::vector< std::string > &categories)
Definition: C4Shader.cpp:100
int32_t VerboseObjectLoading
Definition: C4Config.h:99
int Hgt
Definition: CSurface8.h:28
bool Load(C4Group &hGroup, const char *szFilenames, int DefRankBase, const char *szLanguage)
bool GetProperty(C4PropertyName k, C4Value *pResult) const
Definition: C4PropList.h:101
C4Game Game
Definition: C4Globals.cpp:52
const DWORD C4D_Load_RankNames
Definition: C4Def.h:88
void IncRef()
Definition: C4StringTable.h:27
bool Decompile(StdStrBuf *pOut, const char *szName)
Definition: C4Def.cpp:177
int32_t Float
Definition: C4Def.h:120
C4Rect PictureRect
Definition: C4Def.h:107
bool AccessEntry(const char *szWildCard, size_t *iSize=nullptr, char *sFileName=nullptr, bool NeedsToBeAGroup=false)
Definition: C4Group.cpp:1695
int32_t LineIntersect
Definition: C4Def.h:127
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
#define C4D_Blit_Normal
Definition: C4Def.h:94
C4Scenario C4S
Definition: C4Game.h:74
#define C4CFN_ClonkNameFiles
Definition: C4Components.h:117
bool Compile(const char *szSource, const char *szName)
Definition: C4Def.cpp:172
void Clear()
Definition: StdBuf.h:466
int32_t Projectile
Definition: C4Def.h:132
CSurface8 * pSolidMask
Definition: C4Def.h:193
bool GetPhaseNum(int32_t &rX, int32_t &rY)
Definition: C4Facet.cpp:472
#define C4CFN_Script
Definition: C4Components.h:66
int32_t LoadEffects(C4Group &hGroup, const char *namespace_prefix, bool group_is_root)
bool Load(C4Group &hGroup, StdMeshSkeletonLoader &loader, bool fColorByOwner)
C4String * RegString(StdStrBuf String)
void CompileFunc(StdCompiler *pComp)
Definition: C4Def.cpp:182
bool LoadFragmentSlices(C4GroupSet *pGroupSet, const char *szFile)
Definition: C4Shader.cpp:90
void AddDefine(const char *name)
Definition: C4Shader.cpp:63
int32_t NativeCrew
Definition: C4Def.h:113
void Default()
Definition: C4Shape.cpp:36
bool Save(C4Group &hGroup)
Definition: C4Def.cpp:164
C4Def * Next
Definition: C4Def.h:199
#define _MAX_PATH
#define C4CFN_ImageFiles
Definition: C4Components.h:180
const DWORD C4D_Load_Script
Definition: C4Def.h:83
C4ComponentHost * pClonkNames
Definition: C4Def.h:186
void Set(C4Surface &rSfc)
Definition: C4Facet.cpp:459
int Hgt
Definition: C4Surface.h:65
void IncludeDefinition(C4Def *pIncludeDef)
Definition: C4Def.cpp:633
C4GraphicsResource GraphicsResource
bool fRankSymbolsOwned
Definition: C4Def.h:190
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:93
int32_t Mass
Definition: C4Def.h:114
void Default()
Definition: C4Def.cpp:300
int32_t SilentCommands
Definition: C4Def.h:140
int32_t NoHorizontalMove
Definition: C4Def.h:122
const DWORD C4D_Load_RankFaces
Definition: C4Def.h:89
void Set(const C4Facet &cpy)
Definition: C4FacetEx.h:46
bool fRankNamesOwned
Definition: C4Def.h:189
void Clear()
Definition: C4PropList.h:66
const C4TargetRect TargetRect0(0, 0, 0, 0, 0, 0)
const int32_t C4D_Grab_Get
Definition: C4Def.h:63
const char * GetName() const override
Definition: C4PropList.cpp:267
bool LoadDefCore(C4Group &hGroup)
Definition: C4Def.cpp:142
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
void Reg2List(C4AulScriptEngine *pEngine)
int32_t Rotateable
Definition: C4Def.h:119
bool Temporary
Definition: C4Def.h:200
C4ConfigGraphics Graphics
Definition: C4Config.h:253
#define C4CFN_ScriptStringTbl
Definition: C4Components.h:68
int32_t Wdt
Definition: C4Rect.h:30
int32_t NoPushEnter
Definition: C4Def.h:133
C4DefGraphics * Get(const char *szGrpName)
static bool LoadComponentHost(C4ComponentHost *host, C4Group &hGroup, const char *szFilename, const char *szLanguage)
Definition: C4Language.cpp:232
C4IDList SkipDefs
Definition: C4Scenario.h:94
C4ID BurnTurnTo
Definition: C4Def.h:110
const int32_t C4D_IgnoreFoW
Definition: C4Def.h:55
const int32_t C4D_MouseSelect
Definition: C4Def.h:52
#define C4CFN_ShaderFiles
Definition: C4Components.h:182
void ResetIncludeDependencies()
Definition: C4Def.cpp:641
const int32_t C4D_Grab_Put
Definition: C4Def.h:62
const int32_t C4D_Object
Definition: C4Def.h:44
#define PSF_CalcBuyValue
Definition: C4GameScript.h:91
void Clear()
Definition: C4Def.cpp:324
bool DebugLogF(const char *strMessage...)
Definition: C4Log.cpp:278
std::unique_ptr< C4FileMonitor > pFileMonitor
Definition: C4Game.h:97
int32_t GrowthType
Definition: C4Def.h:111
C4Shape Shape
Definition: C4Def.h:104
#define PSF_CalcDefValue
Definition: C4GameScript.h:81
bool Load(C4Group &group)
Definition: C4Particles.cpp:89
#define C4CFN_DefMaterials
Definition: C4Components.h:89
int32_t y
Definition: C4Rect.h:30
int32_t VehicleControl
Definition: C4Def.h:134
C4StringTable Strings
Definition: C4Globals.cpp:42
bool HideInCreator
Definition: C4Def.h:149
const char * GetName() const
Definition: C4Group.cpp:1845
virtual bool GetPropertyByS(const C4String *k, C4Value *pResult) const
Definition: C4PropList.cpp:753
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
C4DefAdditionalResourcesLoader(C4Group &hGroup)
Definition: C4Def.cpp:43
C4Value C4VPropList(C4PropList *p)
Definition: C4Value.h:245
int32_t Count
Definition: C4Def.h:180
StdBitfieldAdapt< T > mkBitfieldAdapt(T &rVal, const StdBitfieldEntry< T > *pNames)
Definition: StdAdaptors.h:953
C4Surface * GetBitmap(DWORD dwClr=0)
C4Rect Collection
Definition: C4Def.h:106
C4DefGraphics * GetGraphics() const
Definition: C4Object.h:340
#define C4CFN_ClonkNames
Definition: C4Components.h:116
void DrawBoxDw(C4Surface *sfcDest, int iX1, int iY1, int iX2, int iY2, DWORD dwClr)
Definition: C4Draw.cpp:846
int32_t Constructable
Definition: C4Def.h:118
static const C4ID None
Definition: C4Id.h:39
C4Facet MainFace
Definition: C4Def.h:196
int32_t NoMassFromContents
Definition: C4Def.h:137
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
int32_t ClosedContainer
Definition: C4Def.h:139
std::set< StdCopyStrBuf > Parse(const char *mat_script, const char *filename, StdMeshMaterialLoader &loader)
bool ReadPNG(CStdStream &hGroup, int iFlags)
const int C4SF_MipMap
Definition: C4Surface.h:50
int32_t Value
Definition: C4Def.h:115
void Draw(C4Facet &cgo, bool fSelected=false, DWORD iColor=0, C4Object *pObj=nullptr, int32_t iPhaseX=0, int32_t iPhaseY=0, C4DrawTransform *trans=nullptr, const char *graphicsName=nullptr)
Definition: C4Def.cpp:599
const C4Rect Rect0(0, 0, 0, 0)
Definition: C4Def.h:98
const int32_t C4D_Background
Definition: C4Def.h:50
C4Draw * pDraw
Definition: C4Draw.cpp:42
C4Surface * LoadTexture(const char *filename) override
Definition: C4Def.cpp:45
#define C4RGB(r, g, b)
Definition: StdColors.h:26
void Default()
Definition: C4Rect.cpp:26
const int32_t C4D_StaticBack
Definition: C4Def.h:40
int32_t LiftTop
Definition: C4Def.h:123
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:121
int32_t rC4XVer[2]
Definition: C4Def.h:102
void Value(const T &rStruct)
Definition: StdCompiler.h:161
const int32_t C4D_Rule
Definition: C4Def.h:47
const char * what() const override
C4TargetRect SolidMask
Definition: C4Def.h:108
void Draw(C4Facet &cgo, DWORD iColor, C4Object *pObj, int32_t iPhaseX, int32_t iPhaseY, C4DrawTransform *trans)
int32_t Oversize
Definition: C4Def.h:130
void Synchronize()
Definition: C4Def.cpp:629
int32_t CrewMember
Definition: C4Def.h:112
void SetDef(C4Def *to_def)
Definition: C4ScriptHost.h:143
C4TargetRect TopFace
Definition: C4Def.h:109
int32_t getInt() const
Definition: C4Value.h:112
C4PropList * GetActionByName(const char *actname)
Definition: C4Def.cpp:649
int32_t x
Definition: C4Rect.h:30
int PreCacheEntries(const char *szSearchPattern, bool cache_previous=false)
Definition: C4Group.cpp:2222
void Set(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt)
Definition: C4Rect.cpp:86
C4FacetSurface * pRankSymbols
Definition: C4Def.h:190
const int32_t C4D_Structure
Definition: C4Def.h:41
int32_t GetValue(C4Object *pInBase, int32_t iBuyPlayer)
Definition: C4Def.cpp:613
const C4Value C4VNull
Definition: C4Value.cpp:30
C4IDList RequireDef
Definition: C4Def.h:103
int32_t ColorByOwner
Definition: C4Def.h:121
StdStrBuf LoadShaderCode(const char *filename) override
Definition: C4Def.cpp:56
int Wdt
Definition: CSurface8.h:28
bool LoadEntryString(const char *szEntryName, StdStrBuf *Buf)
Definition: C4Group.cpp:1932
bool FindNextEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr, bool fStartAtFilename=false)
Definition: C4Group.cpp:1780
int32_t IncompleteActivity
Definition: C4Def.h:128
float Hgt
Definition: C4Facet.h:118
#define C4CFN_RankNames
Definition: C4Components.h:118
#define C4CFN_RankNameFiles
Definition: C4Components.h:119
const int32_t C4D_MouseIgnore
Definition: C4Def.h:54
GraphicsType Type
Definition: C4DefGraphics.h:48
const DWORD C4D_Load_Bitmap
Definition: C4Def.h:82
const int32_t C4D_Living
Definition: C4Def.h:43
C4LangStringTable StringTable
Definition: C4Def.h:183
bool Read(CStdStream &hGroup, const char *extension, int iFlags)
#define C4CFN_SolidMask
Definition: C4Components.h:122
void AddShaderSlices(C4Shader &shader, int ssc) override
Definition: C4Def.cpp:63
int32_t NoStabilize
Definition: C4Def.h:138
StdMeshMaterialUpdate & GetUpdater()
#define C4CFN_ParticleCore
Definition: C4Components.h:48
int32_t NoBreath
Definition: C4Def.h:143
const DWORD C4D_Load_ClonkNames
Definition: C4Def.h:87
C4DefScriptHost Script
Definition: C4Def.h:182
int32_t MoveToRange
Definition: C4Def.h:136
~C4Def() override
bool Log(const char *szMessage)
Definition: C4Log.cpp:192
int32_t GrabPutGet
Definition: C4Def.h:124
int32_t Category
Definition: C4Def.h:117
bool Add(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1316
int32_t AllowPictureStack
Definition: C4Def.h:148
int32_t BlitMode
Definition: C4Def.h:142
const int32_t C4D_Goal
Definition: C4Def.h:46
int32_t NoGet
Definition: C4Def.h:145
int32_t GetExtendedRankNum() const
Definition: C4RankSystem.h:51
#define C4CFN_RankFacesPNG
Definition: C4Components.h:120
char Filename[_MAX_FNAME+1]
Definition: C4Def.h:177
bool IsPacked() const
Definition: C4Group.cpp:2009
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:458
void ResetSearch(bool reload_contents=false)
Definition: C4Group.cpp:1013
const int32_t C4D_Parallax
Definition: C4Def.h:51
C4Rect Entrance
Definition: C4Def.h:105
int32_t Hgt
Definition: C4Rect.h:30
int32_t TemporaryCrew
Definition: C4Def.h:141
int32_t Fragile
Definition: C4Def.h:131
C4RankSystem * pRankNames
Definition: C4Def.h:189
const int32_t C4D_None
Definition: C4Def.h:38
const DWORD C4D_Load_Temporary
Definition: C4Def.h:92
C4Surface * Surface
Definition: C4Facet.h:117
void DecRef()
Definition: C4StringTable.h:28
int32_t RotatedEntrance
Definition: C4Def.h:146
void Default()
Definition: C4Rect.cpp:39
static CSurface8 * LoadMaskFromFile(class C4Group &hGroup, const char *szFilename)
const DWORD C4D_Load_Sounds
Definition: C4Def.h:86
uint32_t DWORD
virtual bool Load(C4Group &hGroup, const char *szFilename, const char *szLanguage, C4LangStringTable *pLocalTable)
#define DirectorySeparator
int32_t ConSizeOff
Definition: C4Def.h:144
void Copy()
Definition: StdBuf.h:467
float Wdt
Definition: C4Facet.h:118
StdMeshMatManager MeshMaterialManager
C4DefGraphics Graphics
Definition: C4Def.h:192
C4RefCntPointer< C4String > ParentKeyName
Definition: C4PropList.h:274
float X
Definition: C4Facet.h:118
C4Surface & GetFace()
Definition: C4FacetEx.h:52
const int32_t C4D_Foreground
Definition: C4Def.h:53
void Remove(const StdStrBuf &name, class StdMeshMaterialUpdate *update)
bool fClonkNamesOwned
Definition: C4Def.h:186
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4PropList.h:110
C4PropList * getPropList() const
Definition: C4Value.h:116