soldierfactorygameobj.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /*
  2. ** Command & Conquer Renegade(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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/soldierfactorygameobj.cpp $*
  25. * *
  26. * $Author:: Patrick $*
  27. * *
  28. * $Modtime:: 8/22/01 4:54p $*
  29. * *
  30. * $Revision:: 5 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "soldierfactorygameobj.h"
  36. #include "basecontroller.h"
  37. #include "wwhack.h"
  38. #include "simpledefinitionfactory.h"
  39. #include "persistfactory.h"
  40. #include "definitionmgr.h"
  41. #include "combatchunkid.h"
  42. #include "debug.h"
  43. #include "wwprofile.h"
  44. #include "basecontroller.h"
  45. #include "combat.h"
  46. ////////////////////////////////////////////////////////////////
  47. // Hacks
  48. ////////////////////////////////////////////////////////////////
  49. DECLARE_FORCE_LINK (SoldierFactory)
  50. ////////////////////////////////////////////////////////////////
  51. // Editable and persist factories
  52. ////////////////////////////////////////////////////////////////
  53. SimplePersistFactoryClass <SoldierFactoryGameObjDef, CHUNKID_GAME_OBJECT_DEF_SOLDIER_FACTORY> _SoldierFactoryGameObjDefPersistFactory;
  54. SimplePersistFactoryClass <SoldierFactoryGameObj, CHUNKID_GAME_OBJECT_SOLDIER_FACTORY> _SoldierFactoryGameObjPersistFactory;
  55. DECLARE_DEFINITION_FACTORY (SoldierFactoryGameObjDef, CLASSID_GAME_OBJECT_DEF_SOLDIER_FACTORY, "Soldier Factory") _SoldierFactoryGameObjDefDefFactory;
  56. ////////////////////////////////////////////////////////////////
  57. // Save/Load constants
  58. ////////////////////////////////////////////////////////////////
  59. enum
  60. {
  61. CHUNKID_DEF_PARENT = 0x02211153,
  62. CHUNKID_DEF_VARIABLES,
  63. MICROCHUNKID_DEF_UNUSED = 1,
  64. };
  65. enum
  66. {
  67. CHUNKID_PARENT = 0x02211154,
  68. CHUNKID_VARIABLES,
  69. MICROCHUNKID_UNUSED = 1,
  70. };
  71. ////////////////////////////////////////////////////////////////
  72. //
  73. // SoldierFactoryGameObjDef
  74. //
  75. ////////////////////////////////////////////////////////////////
  76. SoldierFactoryGameObjDef::SoldierFactoryGameObjDef (void)
  77. {
  78. return ;
  79. }
  80. ////////////////////////////////////////////////////////////////
  81. //
  82. // ~SoldierFactoryGameObjDef
  83. //
  84. ////////////////////////////////////////////////////////////////
  85. SoldierFactoryGameObjDef::~SoldierFactoryGameObjDef (void)
  86. {
  87. return ;
  88. }
  89. ////////////////////////////////////////////////////////////////
  90. //
  91. // Get_Class_ID
  92. //
  93. ////////////////////////////////////////////////////////////////
  94. uint32
  95. SoldierFactoryGameObjDef::Get_Class_ID (void) const
  96. {
  97. return CLASSID_GAME_OBJECT_DEF_SOLDIER_FACTORY;
  98. }
  99. ////////////////////////////////////////////////////////////////
  100. //
  101. // Create
  102. //
  103. ////////////////////////////////////////////////////////////////
  104. PersistClass *
  105. SoldierFactoryGameObjDef::Create (void) const
  106. {
  107. SoldierFactoryGameObj *building = new SoldierFactoryGameObj;
  108. building->Init (*this);
  109. return building;
  110. }
  111. ////////////////////////////////////////////////////////////////
  112. //
  113. // Create
  114. //
  115. ////////////////////////////////////////////////////////////////
  116. bool
  117. SoldierFactoryGameObjDef::Save (ChunkSaveClass &csave)
  118. {
  119. csave.Begin_Chunk (CHUNKID_DEF_PARENT);
  120. BuildingGameObjDef::Save (csave);
  121. csave.End_Chunk ();
  122. csave.Begin_Chunk (CHUNKID_DEF_VARIABLES);
  123. csave.End_Chunk ();
  124. return true;
  125. }
  126. ////////////////////////////////////////////////////////////////
  127. //
  128. // Load
  129. //
  130. ////////////////////////////////////////////////////////////////
  131. bool
  132. SoldierFactoryGameObjDef::Load (ChunkLoadClass &cload)
  133. {
  134. while (cload.Open_Chunk ())
  135. {
  136. switch (cload.Cur_Chunk_ID ())
  137. {
  138. case CHUNKID_DEF_PARENT:
  139. BuildingGameObjDef::Load (cload);
  140. break;
  141. case CHUNKID_DEF_VARIABLES:
  142. Load_Variables (cload);
  143. break;
  144. default:
  145. Debug_Say (("Unrecognized Com Center Def chunkID\n"));
  146. break;
  147. }
  148. cload.Close_Chunk ();
  149. }
  150. return true;
  151. }
  152. ////////////////////////////////////////////////////////////////
  153. //
  154. // Load_Variables
  155. //
  156. ////////////////////////////////////////////////////////////////
  157. void
  158. SoldierFactoryGameObjDef::Load_Variables (ChunkLoadClass &cload)
  159. {
  160. while (cload.Open_Micro_Chunk ()) {
  161. /*switch (cload.Cur_Micro_Chunk_ID ())
  162. {
  163. default:
  164. Debug_Say (("Unrecognized Com Center Def Variable chunkID\n"));
  165. break;
  166. }*/
  167. cload.Close_Micro_Chunk();
  168. }
  169. return ;
  170. }
  171. ////////////////////////////////////////////////////////////////
  172. //
  173. // Get_Factory
  174. //
  175. ////////////////////////////////////////////////////////////////
  176. const PersistFactoryClass &
  177. SoldierFactoryGameObjDef::Get_Factory (void) const
  178. {
  179. return _SoldierFactoryGameObjDefPersistFactory;
  180. }
  181. ////////////////////////////////////////////////////////////////
  182. //
  183. // SoldierFactoryGameObj
  184. //
  185. ////////////////////////////////////////////////////////////////
  186. SoldierFactoryGameObj::SoldierFactoryGameObj (void)
  187. {
  188. return ;
  189. }
  190. ////////////////////////////////////////////////////////////////
  191. //
  192. // ~SoldierFactoryGameObj
  193. //
  194. ////////////////////////////////////////////////////////////////
  195. SoldierFactoryGameObj::~SoldierFactoryGameObj (void)
  196. {
  197. return ;
  198. }
  199. ////////////////////////////////////////////////////////////////
  200. //
  201. // Get_Factory
  202. //
  203. ////////////////////////////////////////////////////////////////
  204. const PersistFactoryClass &
  205. SoldierFactoryGameObj::Get_Factory (void) const
  206. {
  207. return _SoldierFactoryGameObjPersistFactory;
  208. }
  209. ////////////////////////////////////////////////////////////////
  210. //
  211. // Init
  212. //
  213. ////////////////////////////////////////////////////////////////
  214. void SoldierFactoryGameObj::Init (void)
  215. {
  216. Init (Get_Definition ());
  217. return ;
  218. }
  219. ////////////////////////////////////////////////////////////////
  220. //
  221. // Init
  222. //
  223. ////////////////////////////////////////////////////////////////
  224. void
  225. SoldierFactoryGameObj::Init (const SoldierFactoryGameObjDef &definition)
  226. {
  227. BuildingGameObj::Init (definition);
  228. return ;
  229. }
  230. ////////////////////////////////////////////////////////////////
  231. //
  232. // Get_Definition
  233. //
  234. ////////////////////////////////////////////////////////////////
  235. const SoldierFactoryGameObjDef &
  236. SoldierFactoryGameObj::Get_Definition (void) const
  237. {
  238. return (const SoldierFactoryGameObjDef &)BaseGameObj::Get_Definition ();
  239. }
  240. ////////////////////////////////////////////////////////////////
  241. //
  242. // Save
  243. //
  244. ////////////////////////////////////////////////////////////////
  245. bool
  246. SoldierFactoryGameObj::Save (ChunkSaveClass &csave)
  247. {
  248. csave.Begin_Chunk (CHUNKID_PARENT);
  249. BuildingGameObj::Save (csave);
  250. csave.End_Chunk ();
  251. csave.Begin_Chunk (CHUNKID_VARIABLES);
  252. csave.End_Chunk ();
  253. return true;
  254. }
  255. ////////////////////////////////////////////////////////////////
  256. //
  257. // Load
  258. //
  259. ////////////////////////////////////////////////////////////////
  260. bool
  261. SoldierFactoryGameObj::Load (ChunkLoadClass &cload)
  262. {
  263. while (cload.Open_Chunk ()) {
  264. switch (cload.Cur_Chunk_ID ()) {
  265. case CHUNKID_PARENT:
  266. BuildingGameObj::Load (cload);
  267. break;
  268. case CHUNKID_VARIABLES:
  269. Load_Variables (cload);
  270. break;
  271. default:
  272. Debug_Say (("Unrecognized Com Center chunkID\n"));
  273. break;
  274. }
  275. cload.Close_Chunk();
  276. }
  277. return true;
  278. }
  279. ////////////////////////////////////////////////////////////////
  280. //
  281. // Load_Variables
  282. //
  283. ////////////////////////////////////////////////////////////////
  284. void
  285. SoldierFactoryGameObj::Load_Variables (ChunkLoadClass &cload)
  286. {
  287. while (cload.Open_Micro_Chunk ()) {
  288. /*switch (cload.Cur_Micro_Chunk_ID ())
  289. {
  290. default:
  291. Debug_Say (("Unrecognized Com Center Variable chunkID\n"));
  292. break;
  293. }*/
  294. cload.Close_Micro_Chunk();
  295. }
  296. return ;
  297. }
  298. ////////////////////////////////////////////////////////////////
  299. //
  300. // On_Destroyed
  301. //
  302. ////////////////////////////////////////////////////////////////
  303. void
  304. SoldierFactoryGameObj::On_Destroyed (void)
  305. {
  306. BuildingGameObj::On_Destroyed ();
  307. //
  308. // Switch off the radar for each player on this team
  309. //
  310. if (BaseController != NULL && CombatManager::I_Am_Server ()) {
  311. BaseController->Set_Can_Generate_Soldiers (false);
  312. }
  313. return ;
  314. }
  315. ////////////////////////////////////////////////////////////////
  316. //
  317. // CnC_Initialize
  318. //
  319. ////////////////////////////////////////////////////////////////
  320. void
  321. SoldierFactoryGameObj::CnC_Initialize (BaseControllerClass *base)
  322. {
  323. BuildingGameObj::CnC_Initialize (base);
  324. //
  325. // Let the base know it can generate soldiers
  326. //
  327. if (BaseController != NULL) {
  328. BaseController->Set_Can_Generate_Soldiers (true);
  329. }
  330. return ;
  331. }