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