ObjectInfo.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * ObjectInfo.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "ObjectInfo.h"
  12. #include "../VCMI_Lib.h"
  13. #include "../mapObjectConstructors/CObjectClassesHandler.h"
  14. #include "../mapObjectConstructors/AObjectTypeHandler.h"
  15. #include "../serializer/JsonSerializeFormat.h"
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. ObjectInfo::ObjectInfo(si32 ID, si32 subID):
  18. primaryID(ID),
  19. secondaryID(subID),
  20. destroyObject([](CGObjectInstance * obj){}),
  21. maxPerZone(std::numeric_limits<ui32>::max())
  22. {
  23. }
  24. ObjectInfo::ObjectInfo(CompoundMapObjectID id):
  25. ObjectInfo(id.primaryID, id.secondaryID)
  26. {
  27. }
  28. ObjectInfo::ObjectInfo(const ObjectInfo & other)
  29. {
  30. templates = other.templates;
  31. primaryID = other.primaryID;
  32. secondaryID = other.secondaryID;
  33. value = other.value;
  34. probability = other.probability;
  35. maxPerZone = other.maxPerZone;
  36. generateObject = other.generateObject;
  37. destroyObject = other.destroyObject;
  38. }
  39. ObjectInfo & ObjectInfo::operator=(const ObjectInfo & other)
  40. {
  41. if (this == &other)
  42. return *this;
  43. templates = other.templates;
  44. primaryID = other.primaryID;
  45. secondaryID = other.secondaryID;
  46. value = other.value;
  47. probability = other.probability;
  48. maxPerZone = other.maxPerZone;
  49. generateObject = other.generateObject;
  50. destroyObject = other.destroyObject;
  51. return *this;
  52. }
  53. void ObjectInfo::setAllTemplates(MapObjectID type, MapObjectSubID subtype)
  54. {
  55. auto templHandler = VLC->objtypeh->getHandlerFor(type, subtype);
  56. if(!templHandler)
  57. return;
  58. templates = templHandler->getTemplates();
  59. }
  60. void ObjectInfo::setTemplates(MapObjectID type, MapObjectSubID subtype, TerrainId terrainType)
  61. {
  62. auto templHandler = VLC->objtypeh->getHandlerFor(type, subtype);
  63. if(!templHandler)
  64. return;
  65. templates = templHandler->getTemplates(terrainType);
  66. }
  67. CompoundMapObjectID ObjectInfo::getCompoundID() const
  68. {
  69. return CompoundMapObjectID(primaryID, secondaryID);
  70. }
  71. VCMI_LIB_NAMESPACE_END