WEAPON.CPP 20 KB

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