CrateSystem.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: CrateSystem.h /////////////////////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood Feb 2002
  25. // Desc: System responsible for Crates as code objects - ini, new/delete etc
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef CRATE_SYSTEM_H
  29. #define CRATE_SYSTEM_H
  30. #include "Common/Ini.h"
  31. #include "Common/Overridable.h"
  32. #include "Common/Override.h"
  33. enum ScienceType;
  34. struct crateCreationEntry
  35. {
  36. AsciiString crateName;
  37. Real crateChance;
  38. };
  39. typedef std::list< crateCreationEntry > crateCreationEntryList;
  40. typedef std::list< crateCreationEntry >::iterator crateCreationEntryIterator;
  41. typedef std::list< crateCreationEntry >::const_iterator crateCreationEntryConstIterator;
  42. /**
  43. A CrateTemplate is a ini defined set of conditions plus a ThingTemplate that is the Object
  44. containing the correct CrateCollide module.
  45. */
  46. class CrateTemplate : public Overridable
  47. {
  48. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( CrateTemplate, "CrateTemplate" )
  49. public:
  50. CrateTemplate();
  51. // virtual destructor declared by memory pool
  52. void setName( AsciiString name ) { m_name = name; }
  53. AsciiString getName(){ return m_name; }
  54. inline const FieldParse *getFieldParse() const { return TheCrateTemplateFieldParseTable; }
  55. static const FieldParse TheCrateTemplateFieldParseTable[]; ///< the parse table for INI definition
  56. static void parseCrateCreationEntry( INI* ini, void *instance, void *store, const void* /*userData*/ );
  57. AsciiString m_name; ///< name for this CrateTemplate
  58. Real m_creationChance; ///< Condition for random percentage chance of creating
  59. VeterancyLevel m_veterancyLevel; ///< Condition specifing level of killed unit
  60. KindOfMaskType m_killedByTypeKindof; ///< Must be killed by something with all these bits set
  61. ScienceType m_killerScience; ///< Must be killed by something posessing this science
  62. crateCreationEntryList m_possibleCrates; ///< CreationChance is for this CrateData to succeed, this list controls one-of-n crates created on success
  63. Bool m_isOwnedByMaker; ///< Design needs crates to be owned sometimes.
  64. private:
  65. };
  66. typedef OVERRIDE<CrateTemplate> CrateTemplateOverride;
  67. /**
  68. System responsible for Crates as code objects - ini, new/delete etc
  69. */
  70. class CrateSystem : public SubsystemInterface
  71. {
  72. public:
  73. CrateSystem();
  74. ~CrateSystem();
  75. void init();
  76. void reset();
  77. void update(){}
  78. const CrateTemplate *findCrateTemplate(AsciiString name) const;
  79. CrateTemplate *friend_findCrateTemplate(AsciiString name);
  80. CrateTemplate *newCrateTemplate( AsciiString name );
  81. CrateTemplate *newCrateTemplateOverride( CrateTemplate *crateToOverride );
  82. static void parseCrateTemplateDefinition(INI* ini);
  83. private:
  84. std::vector<CrateTemplate *> m_crateTemplateVector;
  85. };
  86. extern CrateSystem *TheCrateSystem;
  87. #endif