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