ObjectCreationList.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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: ObjectCreationList.h /////////////////////////////////////////////////////////////////////////////////
  24. // Author: Steven Johnson, December 2001
  25. // Desc: General Effects Descriptions
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // Kris: August 23, 2003
  28. // All OCLs return the first object that is created (or NULL if not applicable).
  29. #pragma once
  30. #ifndef _ObjectCreationList_H_
  31. #define _ObjectCreationList_H_
  32. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  33. #include "Common/GameMemory.h"
  34. // FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
  35. class ObjectCreationNugget;
  36. class ObjectCreationList;
  37. class ObjectCreationListStore;
  38. class INI;
  39. class Object;
  40. //-------------------------------------------------------------------------------------------------
  41. /**
  42. An ObjectCreationNugget encapsulates the creation of an Object. ObjectCreationNuggets are virtually
  43. never used on their own, but rather, as a component of an ObjectCreationList (see below).
  44. Important notes:
  45. -- ObjectCreationNugget is an ABC; all the implementations are (currently) located in ObjectCreationList.cpp,
  46. thought they will probably be spread out more as we add more implementations.
  47. -- As part of an ObjectCreationList, an ObjectCreationNugget is shared between multiple units. The implication is that
  48. an ObjectCreationNugget should not require private data storage to do what it needs to do, aside from stuff
  49. initialized at ObjectCreationNugget instantiation time (eg, parameters from an INI file). To help
  50. enforce this, all it's methods are declared 'const'. If you can't implement what you
  51. need within this framework, please *don't* simply de-const things, because it could lead to very
  52. strange side-effects. Instead, the system will have to be enhanced to allow for multiple instances
  53. of each ObjectCreationNugget.
  54. -- an individual ObjectCreationNugget is generally not directly accessible to anyone outside of the
  55. ObjectCreationList system; in fact, it could probably be a private class, but isn't, mainly for coding convenience.
  56. -- Unlike most other game systems, ObjectCreationNuggets can't be overridden by subsequent INI file
  57. loads. This isn't really a problem, because all you really need to do to "override" one is to
  58. specify a different one.
  59. */
  60. class ObjectCreationNugget : public MemoryPoolObject
  61. {
  62. MEMORY_POOL_GLUE_ABC(ObjectCreationNugget)
  63. public:
  64. ObjectCreationNugget() { }
  65. //virtual ~ObjectCreationNugget() { }
  66. /**
  67. The main guts of the system: actually perform the sound and/or video effects
  68. needed. Note that primary can be null, so you must check for this.
  69. Bool useOwner determines whether we are creating the the master object or not (for deliverpayload)
  70. */
  71. virtual Object* create( const Object* primaryObj, const Coord3D *primary, const Coord3D* secondary, Real angle, UnsignedInt lifetimeFrames = 0 ) const = 0;
  72. /**
  73. the object-based version... by default, just call the location-based implementation.
  74. Note that primary can be null, so you must check for this.
  75. */
  76. virtual Object* create( const Object* primary, const Object* secondary, UnsignedInt lifetimeFrames = 0 ) const;
  77. /**
  78. A variation used by DeliverPayload -- the createOwner Bool specifies whether we are creating the transport
  79. object, or using the existing one.
  80. */
  81. virtual Object* create( const Object* primaryObj, const Coord3D *primary, const Coord3D *secondary, Bool createOwner, UnsignedInt lifetimeFrames = 0 ) const;
  82. };
  83. EMPTY_DTOR(ObjectCreationNugget)
  84. //-------------------------------------------------------------------------------------------------
  85. /**
  86. An ObjectCreationList is a way of creating a particular set of Objects.
  87. Important notes:
  88. -- an ObjectCreationList is specified solely by name, and the only parameters it receives when performing
  89. its AV effects are a primary (and optional secondary) object position.
  90. -- There is no inheritance or overriding of ObjectCreationLists; if you need an ObjectCreationList that is nearly-but-not-quite
  91. identical to an existing one, you must simply make an entirely new ObjectCreationList. Realistically, this shouldn't
  92. be a problem, since they are pretty simple to specify, and don't consume a lot of memory.
  93. -- an ObjectCreationList is shared between multiple units. To help
  94. enforce this, all it's methods are declared 'const'. If you can't implement the stuff you
  95. need within this framework, please *don't* simply de-const things, because it could lead to very
  96. strange side-effects. Instead, the system will have to be enhanced to allow for multiple instances
  97. of each ObjectCreationNugget.
  98. -- Unlike most other game systems, ObjectCreationList can't be overridden by subsequent INI file
  99. loads. This isn't really a problem, because all you really need to do to "override" one is to
  100. specify a different one.
  101. */
  102. class ObjectCreationList
  103. {
  104. public:
  105. /**
  106. Toss the contents.
  107. */
  108. void clear();
  109. void addObjectCreationNugget(ObjectCreationNugget* nugget);
  110. // Kris: August 23, 2003
  111. // All OCLs return the first object that is created (or NULL if not applicable).
  112. inline static Object* create( const ObjectCreationList* ocl, const Object* primaryObj, const Coord3D *primary, const Coord3D *secondary, Bool createOwner, UnsignedInt lifetimeFrames = 0 )
  113. {
  114. if( ocl )
  115. return ocl->createInternal( primaryObj, primary, secondary, createOwner, lifetimeFrames );
  116. return NULL;
  117. }
  118. // Kris: August 23, 2003
  119. // All OCLs return the first object that is created (or NULL if not applicable).
  120. /// inline convenience method to avoid having to check for null.
  121. inline static Object* create(const ObjectCreationList* ocl, const Object* primaryObj, const Coord3D *primary, const Coord3D *secondary, Real angle, UnsignedInt lifetimeFrames = 0 )
  122. {
  123. if (ocl)
  124. return ocl->createInternal( primaryObj, primary, secondary, angle, lifetimeFrames );
  125. return NULL;
  126. }
  127. // Kris: August 23, 2003
  128. // All OCLs return the first object that is created (or NULL if not applicable).
  129. /// inline convenience method to avoid having to check for null.
  130. inline static Object* create( const ObjectCreationList* ocl, const Object* primary, const Object* secondary, UnsignedInt lifetimeFrames = 0 )
  131. {
  132. if (ocl)
  133. return ocl->createInternal( primary, secondary, lifetimeFrames );
  134. return NULL;
  135. }
  136. protected:
  137. private:
  138. // Kris: August 23, 2003
  139. // All OCLs return the first object that is created (or NULL if not applicable).
  140. Object* createInternal(const Object* primaryObj, const Coord3D *primary, const Coord3D *secondary, Bool createOwner, UnsignedInt lifetimeFrames = 0 ) const;
  141. Object* createInternal(const Object* primaryObj, const Coord3D *primary, const Coord3D* secondary, Real angle, UnsignedInt lifetimeFrames = 0 ) const;
  142. Object* createInternal(const Object* primary, const Object* secondary, UnsignedInt lifetimeFrames = 0 ) const;
  143. // note, this list doesn't own the nuggets; all nuggets are owned by the Store.
  144. typedef std::vector<ObjectCreationNugget*> ObjectCreationNuggetVector;
  145. ObjectCreationNuggetVector m_nuggets;
  146. };
  147. //-------------------------------------------------------------------------------------------------
  148. /**
  149. The "store" used to hold all the ObjectCreationLists in existence.
  150. */
  151. class ObjectCreationListStore : public SubsystemInterface
  152. {
  153. public:
  154. ObjectCreationListStore();
  155. ~ObjectCreationListStore();
  156. void init() { }
  157. void reset() { }
  158. void update() { }
  159. /**
  160. return the ObjectCreationList with the given namekey.
  161. return NULL if no such ObjectCreationList exists.
  162. */
  163. const ObjectCreationList *findObjectCreationList(const char* name) const;
  164. static void parseObjectCreationListDefinition(INI* ini);
  165. void addObjectCreationNugget(ObjectCreationNugget* nugget);
  166. private:
  167. typedef std::map< NameKeyType, ObjectCreationList, std::less<NameKeyType> > ObjectCreationListMap;
  168. ObjectCreationListMap m_ocls;
  169. // note, this list doesn't own the nuggets; all nuggets are owned by the Store.
  170. typedef std::vector<ObjectCreationNugget*> ObjectCreationNuggetVector;
  171. ObjectCreationNuggetVector m_nuggets;
  172. };
  173. // EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
  174. extern ObjectCreationListStore *TheObjectCreationListStore;
  175. #endif // _ObjectCreationList_H_