WEAPON.CPP 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/WEAPON.CPP 1 3/03/97 10:26a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : WEAPON.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 05/20/96 *
  26. * *
  27. * Last Update : September 9, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * Armor_From_Name -- Convert ASCII name into armor type number. *
  32. * WeaponTypeClass::As_Pointer -- Give a weapon type ID, fetch pointer to weapon type object.*
  33. * WeaponTypeClass::Read_INI -- Fetch the weapon data from the INI database. *
  34. * WeaponTypeClass::WeaponTypeClass -- Default constructor for weapon type objects. *
  35. * WeaponTypeClass::operator delete -- Returns weapon type object back to special heap. *
  36. * WeaponTypeClass::operator new -- Allocates a weapon type object form the special heap. *
  37. * WeaponTypeClass::~WeaponTypeClass -- Destructor for weapon type class objects. *
  38. * Weapon_From_Name -- Conver ASCII name to weapon type ID number. *
  39. * WeaponTypeClass::Allowed_Threats -- Determine what threats this weapon can address. *
  40. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  41. #include "function.h"
  42. /***************************************************************************
  43. ** These are the various weapons and their characteristics.
  44. */
  45. TFixedIHeapClass<WeaponTypeClass> Weapons;
  46. /***********************************************************************************************
  47. * WeaponTypeClass::WeaponTypeClass -- Default constructor for weapon type objects. *
  48. * *
  49. * This default constructor will initialize all the values of the weapon to the default *
  50. * state. Thus, if any of these settings are not specifically overridden by the rules.ini *
  51. * file, they will remain this value in the game. *
  52. * *
  53. * INPUT: none *
  54. * *
  55. * OUTPUT: none *
  56. * *
  57. * WARNINGS: none *
  58. * *
  59. * HISTORY: *
  60. * 07/17/1996 JLB : Created. *
  61. *=============================================================================================*/
  62. WeaponTypeClass::WeaponTypeClass(char const * name) :
  63. ID(Weapons.ID(this)),
  64. IniName(name),
  65. IsSupressed(false),
  66. IsCamera(false),
  67. IsElectric(false),
  68. Burst(1),
  69. Bullet(NULL),
  70. Attack(0),
  71. MaxSpeed(MPH_IMMOBILE),
  72. WarheadPtr(NULL),
  73. ROF(0),
  74. Range(0),
  75. Sound(VOC_NONE),
  76. Anim(ANIM_NONE)
  77. {
  78. }
  79. /***********************************************************************************************
  80. * WeaponTypeClass::~WeaponTypeClass -- Destructor for weapon type class objects. *
  81. * *
  82. * This destructor really doesn't do anything but set the pointers to NULL. This is a *
  83. * general purposes safety tactic but is otherwise useless. *
  84. * *
  85. * INPUT: none *
  86. * *
  87. * OUTPUT: none *
  88. * *
  89. * WARNINGS: none *
  90. * *
  91. * HISTORY: *
  92. * 07/17/1996 JLB : Created. *
  93. *=============================================================================================*/
  94. WeaponTypeClass::~WeaponTypeClass(void)
  95. {
  96. IniName = NULL;
  97. Bullet = NULL;
  98. WarheadPtr = NULL;
  99. }
  100. /***********************************************************************************************
  101. * WeaponTypeClass::operator new -- Allocates a weapon type object form the special heap. *
  102. * *
  103. * This will allocate a weapon type object from a special heap that has been set up for *
  104. * that purpose. *
  105. * *
  106. * INPUT: none *
  107. * *
  108. * OUTPUT: Returns with a pointer to the weapon type object allocated. If there was *
  109. * insufficient memory available, NULL is returned. *
  110. * *
  111. * WARNINGS: none *
  112. * *
  113. * HISTORY: *
  114. * 07/17/1996 JLB : Created. *
  115. *=============================================================================================*/
  116. void * WeaponTypeClass::operator new(size_t)
  117. {
  118. return(Weapons.Alloc());
  119. }
  120. /***********************************************************************************************
  121. * WeaponTypeClass::operator delete -- Returns weapon type object back to special heap. *
  122. * *
  123. * This routine will return the weapon type object back to the heap so that the memory *
  124. * can be reused for subsiquent allocations of weapon type objects. *
  125. * *
  126. * INPUT: pointer -- Pointer to the weapon type object to return to the special heap. *
  127. * *
  128. * OUTPUT: none *
  129. * *
  130. * WARNINGS: none *
  131. * *
  132. * HISTORY: *
  133. * 07/17/1996 JLB : Created. *
  134. *=============================================================================================*/
  135. void WeaponTypeClass::operator delete(void * pointer)
  136. {
  137. Weapons.Free((WeaponTypeClass *)pointer);
  138. }
  139. /***********************************************************************************************
  140. * WeaponTypeClass::As_Pointer -- Give a weapon type ID, fetch pointer to weapon type object. *
  141. * *
  142. * This routine will conver the weapon type ID specified into a pointer to the weapon type *
  143. * object it represents. *
  144. * *
  145. * INPUT: weapon -- The weapon type object ID to convert to a pointer. *
  146. * *
  147. * OUTPUT: Returns with a pointer to the weapon type class object that is represented by the *
  148. * weapon ID number specified. If no match could be found, then NULL is returned. *
  149. * *
  150. * WARNINGS: none *
  151. * *
  152. * HISTORY: *
  153. * 07/17/1996 JLB : Created. *
  154. *=============================================================================================*/
  155. WeaponTypeClass * WeaponTypeClass::As_Pointer(WeaponType weapon)
  156. {
  157. if (weapon != WEAPON_NONE) {
  158. return(Weapons.Ptr(weapon));
  159. // for (int index = 0; index < Weapons.Count(); index++) {
  160. // WeaponTypeClass * ptr = Weapons.Ptr(index);
  161. // if (ptr->ID == weapon) {
  162. // return(ptr);
  163. // }
  164. // }
  165. }
  166. return(NULL);
  167. }
  168. /***********************************************************************************************
  169. * WeaponTypeClass::Read_INI -- Fetch the weapon data from the INI database. *
  170. * *
  171. * This routine will fetch the weapon data for this weapon type object from the INI *
  172. * database specified. *
  173. * *
  174. * INPUT: ini -- Reference to the INI database that the weapon data will be fetched *
  175. * from. *
  176. * *
  177. * OUTPUT: bool; Was this weapon type described in the database and the values retrieved? *
  178. * *
  179. * WARNINGS: none *
  180. * *
  181. * HISTORY: *
  182. * 07/19/1996 JLB : Created. *
  183. *=============================================================================================*/
  184. bool WeaponTypeClass::Read_INI(CCINIClass & ini)
  185. {
  186. if (ini.Is_Present(Name())) {
  187. IsSupressed = ini.Get_Bool(Name(), "Supress", IsSupressed);
  188. Burst = ini.Get_Int(Name(), "Burst", Burst);
  189. Attack = ini.Get_Int(Name(), "Damage", Attack);
  190. MaxSpeed = ini.Get_MPHType(Name(), "Speed", MaxSpeed);
  191. ROF = ini.Get_Int(Name(), "ROF", ROF);
  192. Range = ini.Get_Lepton(Name(), "Range", Range);
  193. Sound = ini.Get_VocType(Name(), "Report", Sound);
  194. Anim = ini.Get_AnimType(Name(), "Anim", Anim);
  195. IsCamera = ini.Get_Bool(Name(), "Camera", IsCamera);
  196. IsElectric = ini.Get_Bool(Name(), "Charges", IsElectric);
  197. IsTurboBoosted = ini.Get_Bool(Name(), "TurboBoost", IsTurboBoosted);
  198. WarheadType wtype = (WarheadPtr != NULL) ? WarheadType(WarheadPtr->ID) : WARHEAD_NONE;
  199. wtype = ini.Get_WarheadType(Name(), "Warhead", wtype);
  200. if (wtype != WARHEAD_NONE) {
  201. WarheadPtr = WarheadTypeClass::As_Pointer(wtype);
  202. // WarheadPtr = &Warheads[wtype];
  203. } else {
  204. WarheadPtr = NULL;
  205. }
  206. BulletType btype = (Bullet != NULL) ? BulletType(Bullet->ID) : BULLET_NONE;
  207. btype = ini.Get_BulletType(Name(), "Projectile", btype);
  208. if (btype != BULLET_NONE) {
  209. Bullet = &BulletTypeClass::As_Reference(btype);
  210. } else {
  211. Bullet = NULL;
  212. }
  213. return(true);
  214. }
  215. return(false);
  216. }
  217. /***********************************************************************************************
  218. * Weapon_From_Name -- Conver ASCII name to weapon type ID number. *
  219. * *
  220. * This will find the weapon whos name matches that specified and then it will return the *
  221. * weapon ID number associated with it. *
  222. * *
  223. * INPUT: name -- Pointer to the ASCII name of the weapon type. *
  224. * *
  225. * OUTPUT: Returns with the weapon type ID number that matches the name specified. If no *
  226. * match could be found, then WEAPON_NONE is returned. *
  227. * *
  228. * WARNINGS: none *
  229. * *
  230. * HISTORY: *
  231. * 07/17/1996 JLB : Created. *
  232. *=============================================================================================*/
  233. WeaponType Weapon_From_Name(char const * name)
  234. {
  235. if (!name) return(WEAPON_NONE);
  236. for (int index = 0; index < Weapons.Count(); index++) {
  237. if (stricmp(Weapons.Ptr(index)->Name(), name) == 0) {
  238. return(WeaponType(Weapons.Ptr(index)->ID));
  239. }
  240. }
  241. return(WEAPON_NONE);
  242. }
  243. /***********************************************************************************************
  244. * Armor_From_Name -- Convert ASCII name into armor type number. *
  245. * *
  246. * This will find the armor type that matches the ASCII name specified and then will return *
  247. * the armor ID number of it. *
  248. * *
  249. * INPUT: name -- Pointer to the ASCII name of the armor to find. *
  250. * *
  251. * OUTPUT: Returns with the armor ID number of the armor that matches the name specified. If *
  252. * no match could be found, then ARMOR_NONE is returned. *
  253. * *
  254. * WARNINGS: none *
  255. * *
  256. * HISTORY: *
  257. * 07/17/1996 JLB : Created. *
  258. *=============================================================================================*/
  259. ArmorType Armor_From_Name(char const * name)
  260. {
  261. if (!name) return(ARMOR_NONE);
  262. for (ArmorType index = ARMOR_FIRST; index < ARMOR_COUNT; index++) {
  263. if (stricmp(ArmorName[index], name) == 0) {
  264. return(index);
  265. }
  266. }
  267. return(ARMOR_NONE);
  268. }
  269. /***********************************************************************************************
  270. * WeaponTypeClass::Allowed_Threats -- Determine what threats this weapon can address. *
  271. * *
  272. * This routine will examine the capabilities of this weapon and return with the threat *
  273. * types that it can address. *
  274. * *
  275. * INPUT: none *
  276. * *
  277. * OUTPUT: Returns with the threat types that this weapon can address. *
  278. * *
  279. * WARNINGS: none *
  280. * *
  281. * HISTORY: *
  282. * 09/09/1996 JLB : Created. *
  283. *=============================================================================================*/
  284. ThreatType WeaponTypeClass::Allowed_Threats(void) const
  285. {
  286. ThreatType threat = THREAT_NORMAL;
  287. if (Bullet->IsAntiAircraft) {
  288. threat = threat | THREAT_AIR;
  289. }
  290. if (Bullet->IsAntiGround) {
  291. threat = threat | THREAT_INFANTRY|THREAT_VEHICLES|THREAT_BOATS|THREAT_BUILDINGS;
  292. }
  293. return(threat);
  294. }
  295. bool WeaponTypeClass::Is_Wall_Destroyer(void) const
  296. {
  297. if (WarheadPtr != NULL && WarheadPtr->IsWallDestroyer) {
  298. return(true);
  299. }
  300. return(false);
  301. }