Module.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. ** Command & Conquer Generals(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: Module.cpp ///////////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, September 2001
  25. // Desc: Object and drawable modules and actions. These are simply just class
  26. // instances that we can assign to objects, drawables, and things to contain
  27. // data and code for specific events, or just to hold data
  28. ///////////////////////////////////////////////////////////////////////////////////////////////////
  29. #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
  30. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  31. #include "Common/Module.h"
  32. #include "Common/Thing.h"
  33. #include "Common/INI.h"
  34. #include "Common/ThingTemplate.h"
  35. #include "Common/Upgrade.h"
  36. #include "Common/Xfer.h"
  37. #include "GameLogic/Object.h"
  38. #include "GameLogic/GameLogic.h"
  39. #include "GameLogic/Module/BodyModule.h"
  40. #include "GameLogic/Module/CollideModule.h"
  41. #include "GameLogic/Module/ContainModule.h"
  42. #include "GameLogic/Module/DamageModule.h"
  43. #include "GameLogic/Module/DieModule.h"
  44. #include "GameLogic/Module/UpdateModule.h"
  45. #include "GameLogic/Module/UpgradeModule.h"
  46. ///////////////////////////////////////////////////////////////////////////////////////////////////
  47. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
  48. ///////////////////////////////////////////////////////////////////////////////////////////////////
  49. //-------------------------------------------------------------------------------------------------
  50. //-------------------------------------------------------------------------------------------------
  51. // this method should NEVER be overridden by user code, only via the MAKE_STANDARD_MODULE_xxx macros!
  52. // it should also NEVER be called directly; it's only for use by ModuleFactory!
  53. /*static*/ ModuleData* Module::friend_newModuleData(INI* ini)
  54. {
  55. ModuleData* data = MSGNEW("Module::friend_newModuleData") ModuleData; // no need to memorypool these since we never allocate more than one of each
  56. if (ini)
  57. ini->initFromINI(data, 0); // this is just so that an "end" token is required
  58. return data;
  59. }
  60. // ------------------------------------------------------------------------------------------------
  61. // ------------------------------------------------------------------------------------------------
  62. Module::~Module()
  63. {
  64. } // end ~Module
  65. // ------------------------------------------------------------------------------------------------
  66. /** CRC */
  67. // ------------------------------------------------------------------------------------------------
  68. void Module::crc( Xfer *xfer )
  69. {
  70. } // end crc
  71. // ------------------------------------------------------------------------------------------------
  72. /** Xfer method
  73. * Version Info:
  74. * 1: Initial version */
  75. // ------------------------------------------------------------------------------------------------
  76. void Module::xfer( Xfer *xfer )
  77. {
  78. // version
  79. XferVersion currentVersion = 1;
  80. XferVersion version = currentVersion;
  81. xfer->xferVersion( &version, currentVersion );
  82. } // end xfer
  83. // ------------------------------------------------------------------------------------------------
  84. /** load post process */
  85. // ------------------------------------------------------------------------------------------------
  86. void Module::loadPostProcess( void )
  87. {
  88. } // end loadPostProcess
  89. //-------------------------------------------------------------------------------------------------
  90. //-------------------------------------------------------------------------------------------------
  91. ObjectModule::ObjectModule( Thing *thing, const ModuleData* moduleData ) : Module(moduleData)
  92. {
  93. if (!moduleData)
  94. {
  95. DEBUG_CRASH(("module data may not be null\n"));
  96. throw INI_INVALID_DATA;
  97. }
  98. DEBUG_ASSERTCRASH( thing, ("Thing passed to ObjectModule is NULL!\n") );
  99. m_object = AsObject(thing);
  100. DEBUG_ASSERTCRASH( m_object, ("Thing passed to ObjectModule is not an Object!\n") );
  101. } // end ObjectModule
  102. //-------------------------------------------------------------------------------------------------
  103. //-------------------------------------------------------------------------------------------------
  104. ObjectModule::~ObjectModule( void )
  105. {
  106. } // end ~ObjectModule
  107. // ------------------------------------------------------------------------------------------------
  108. /** CRC */
  109. // ------------------------------------------------------------------------------------------------
  110. void ObjectModule::crc( Xfer *xfer )
  111. {
  112. // extend base class
  113. Module::crc( xfer );
  114. } // end crc
  115. // ------------------------------------------------------------------------------------------------
  116. /** Xfer method
  117. * Version Info:
  118. * 1: Initial version */
  119. // ------------------------------------------------------------------------------------------------
  120. void ObjectModule::xfer( Xfer *xfer )
  121. {
  122. // version
  123. XferVersion currentVersion = 1;
  124. XferVersion version = currentVersion;
  125. xfer->xferVersion( &version, currentVersion );
  126. // extend base class
  127. Module::xfer( xfer );
  128. } // end xfer
  129. // ------------------------------------------------------------------------------------------------
  130. /** load post process */
  131. // ------------------------------------------------------------------------------------------------
  132. void ObjectModule::loadPostProcess( void )
  133. {
  134. // extend base class
  135. Module::loadPostProcess();
  136. } // end loadPostProcess
  137. //-------------------------------------------------------------------------------------------------
  138. //-------------------------------------------------------------------------------------------------
  139. DrawableModule::DrawableModule( Thing *thing, const ModuleData* moduleData ) : Module(moduleData)
  140. {
  141. if (!moduleData)
  142. {
  143. DEBUG_CRASH(("module data may not be null\n"));
  144. throw INI_INVALID_DATA;
  145. }
  146. DEBUG_ASSERTCRASH( thing, ("Thing passed to DrawableModule is NULL!\n") );
  147. m_drawable = AsDrawable(thing);
  148. DEBUG_ASSERTCRASH( m_drawable, ("Thing passed to DrawableModule is not a Drawable!\n") );
  149. } // end ~DrawableModule
  150. //-------------------------------------------------------------------------------------------------
  151. //-------------------------------------------------------------------------------------------------
  152. DrawableModule::~DrawableModule( void )
  153. {
  154. } // end ~DrawableModule
  155. // ------------------------------------------------------------------------------------------------
  156. /** CRC */
  157. // ------------------------------------------------------------------------------------------------
  158. void DrawableModule::crc( Xfer *xfer )
  159. {
  160. // extend base class
  161. Module::crc( xfer );
  162. } // end crc
  163. // ------------------------------------------------------------------------------------------------
  164. /** Xfer method
  165. * Version Info:
  166. * 1: Initial version */
  167. // ------------------------------------------------------------------------------------------------
  168. void DrawableModule::xfer( Xfer *xfer )
  169. {
  170. // version
  171. XferVersion currentVersion = 1;
  172. XferVersion version = currentVersion;
  173. xfer->xferVersion( &version, currentVersion );
  174. // extend base class
  175. Module::xfer( xfer );
  176. } // end xfer
  177. // ------------------------------------------------------------------------------------------------
  178. /** load post process */
  179. // ------------------------------------------------------------------------------------------------
  180. void DrawableModule::loadPostProcess( void )
  181. {
  182. // extend base class
  183. Module::loadPostProcess();
  184. } // end loadPostProcess
  185. //-------------------------------------------------------------------------------------------------
  186. //-------------------------------------------------------------------------------------------------
  187. //-------------------------------------------------------------------------------------------------
  188. //-------------------------------------------------------------------------------------------------
  189. void UpgradeMuxData::performUpgradeFX(Object* obj) const
  190. {
  191. if (m_fxListUpgrade)
  192. {
  193. FXList::doFXObj(m_fxListUpgrade, obj);
  194. }
  195. }
  196. //-------------------------------------------------------------------------------------------------
  197. void UpgradeMuxData::getUpgradeActivationMasks(Int64& activation, Int64& conflicting) const
  198. {
  199. // already computed.
  200. if (!m_activationUpgradeNames.empty() || !m_conflictingUpgradeNames.empty())
  201. {
  202. m_activationMask = 0;
  203. m_conflictingMask = 0;
  204. std::vector<AsciiString>::const_iterator it;
  205. for( it = m_activationUpgradeNames.begin();
  206. it != m_activationUpgradeNames.end();
  207. it++)
  208. {
  209. const UpgradeTemplate* theTemplate = TheUpgradeCenter->findUpgrade( *it );
  210. if( !theTemplate && !it->isEmpty() && !it->isNone())
  211. {
  212. DEBUG_CRASH(("An upgrade module references %s, which is not an Upgrade", it->str()));
  213. throw INI_INVALID_DATA;
  214. }
  215. m_activationMask |= theTemplate->getUpgradeMask();
  216. }
  217. for( it = m_conflictingUpgradeNames.begin();
  218. it != m_conflictingUpgradeNames.end();
  219. it++)
  220. {
  221. const UpgradeTemplate* theTemplate = TheUpgradeCenter->findUpgrade( *it );
  222. if( !theTemplate && !it->isEmpty() && !it->isNone())
  223. {
  224. DEBUG_CRASH(("An upgrade module references %s, which is not an Upgrade", it->str()));
  225. throw INI_INVALID_DATA;
  226. }
  227. m_conflictingMask |= theTemplate->getUpgradeMask();
  228. }
  229. m_activationUpgradeNames.clear();
  230. m_conflictingUpgradeNames.clear();
  231. }
  232. activation = m_activationMask;
  233. conflicting = m_conflictingMask;
  234. }