WARHEAD.CPP 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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/WARHEAD.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 : WARHEAD.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : 05/20/96 *
  30. * *
  31. * Last Update : July 19, 1996 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * WarheadTypeClass::As_Pointer -- Convert a warhead type number into a pointer. *
  36. * WarheadTypeClass::Read_INI -- Fetches the warhead data from the INI database. *
  37. * WarheadTypeClass::WarheadTypeClass -- Default constructor for warhead objects. *
  38. * WarheadTypeClass::operator delete -- Returns warhead object back to special memory pool. *
  39. * WarheadTypeClass::operator new -- Allocate a warhead object from the special heap. *
  40. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  41. #include "function.h"
  42. /***************************************************************************
  43. ** This is the warhead data object array.
  44. */
  45. TFixedIHeapClass<WarheadTypeClass> Warheads;
  46. /***********************************************************************************************
  47. * WarheadTypeClass::WarheadTypeClass -- Default constructor for warhead objects. *
  48. * *
  49. * This default constructor for a warhead object will fill in all the default values *
  50. * for a warhead. It is presumed that these values will be normal unless specifically *
  51. * overridden by the INI database. *
  52. * *
  53. * INPUT: none *
  54. * *
  55. * OUTPUT: none *
  56. * *
  57. * WARNINGS: none *
  58. * *
  59. * HISTORY: *
  60. * 07/19/1996 JLB : Created. *
  61. *=============================================================================================*/
  62. WarheadTypeClass::WarheadTypeClass(char const * name) :
  63. ID(Warheads.ID(this)),
  64. IniName(name),
  65. SpreadFactor(1),
  66. IsWallDestroyer(false),
  67. IsWoodDestroyer(false),
  68. IsTiberiumDestroyer(false),
  69. IsOrganic(false),
  70. ExplosionSet(0),
  71. InfantryDeath(0)
  72. {
  73. for (ArmorType armor = ARMOR_FIRST; armor < ARMOR_COUNT; armor++) {
  74. Modifier[armor] = 1;
  75. }
  76. }
  77. /***********************************************************************************************
  78. * WarheadTypeClass::operator new -- Allocate a warhead object from the special heap. *
  79. * *
  80. * This will allocate a warhead object from the special heap that is maintained for *
  81. * this purpose. *
  82. * *
  83. * INPUT: none *
  84. * *
  85. * OUTPUT: Returns with a pointer to the newly allocated warhead type object. If there is *
  86. * insufficient memory for the allocation, then NULL is returned. *
  87. * *
  88. * WARNINGS: none *
  89. * *
  90. * HISTORY: *
  91. * 07/19/1996 JLB : Created. *
  92. *=============================================================================================*/
  93. void * WarheadTypeClass::operator new(size_t)
  94. {
  95. return(Warheads.Alloc());
  96. }
  97. /***********************************************************************************************
  98. * WarheadTypeClass::operator delete -- Returns warhead object back to special memory pool. *
  99. * *
  100. * This routine will return the warhead object to the memory pool from whence it came. *
  101. * *
  102. * INPUT: pointer -- Pointer to the warhead object to return to the memory pool. *
  103. * *
  104. * OUTPUT: none *
  105. * *
  106. * WARNINGS: none *
  107. * *
  108. * HISTORY: *
  109. * 07/19/1996 JLB : Created. *
  110. *=============================================================================================*/
  111. void WarheadTypeClass::operator delete(void * pointer)
  112. {
  113. Warheads.Free((WarheadTypeClass *)pointer);
  114. }
  115. /***********************************************************************************************
  116. * WarheadTypeClass::As_Pointer -- Convert a warhead type number into a pointer. *
  117. * *
  118. * This will locate the warhead type specified and return a pointer to it. *
  119. * *
  120. * INPUT: warhead -- The warhead to convert into a pointer. *
  121. * *
  122. * OUTPUT: Returns with a pointer to the warhead type object that is represented by the *
  123. * warhead type number specified. *
  124. * *
  125. * WARNINGS: none *
  126. * *
  127. * HISTORY: *
  128. * 07/19/1996 JLB : Created. *
  129. *=============================================================================================*/
  130. WarheadTypeClass * WarheadTypeClass::As_Pointer(WarheadType warhead)
  131. {
  132. if (warhead != WARHEAD_NONE) {
  133. return(Warheads.Ptr(warhead));
  134. }
  135. return(NULL);
  136. }
  137. /***********************************************************************************************
  138. * WarheadTypeClass::Read_INI -- Fetches the warhead data from the INI database. *
  139. * *
  140. * Use this routine to retrieve the data specific to this warhead type class object from *
  141. * the INI database specified. Typical use of this is when processing the rules.ini *
  142. * file. *
  143. * *
  144. * INPUT: ini -- Reference to the INI database to fetch the values from. *
  145. * *
  146. * OUTPUT: bool; Was the warhead entry found and the data retrieved? *
  147. * *
  148. * WARNINGS: none *
  149. * *
  150. * HISTORY: *
  151. * 07/19/1996 JLB : Created. *
  152. *=============================================================================================*/
  153. bool WarheadTypeClass::Read_INI(CCINIClass & ini)
  154. {
  155. if (ini.Is_Present(Name())) {
  156. SpreadFactor = ini.Get_Int(Name(), "Spread", SpreadFactor);
  157. IsWallDestroyer = ini.Get_Bool(Name(), "Wall", IsWallDestroyer);
  158. IsWoodDestroyer = ini.Get_Bool(Name(), "Wood", IsWoodDestroyer);
  159. IsTiberiumDestroyer = ini.Get_Bool(Name(), "Ore", IsTiberiumDestroyer);
  160. ExplosionSet = ini.Get_Int(Name(), "Explosion", ExplosionSet);
  161. InfantryDeath = ini.Get_Int(Name(), "InfDeath", InfantryDeath);
  162. char buffer[128];
  163. if (ini.Get_String(Name(), "Verses", "100%%,100%%,100%%,100%%,100%%", buffer, sizeof(buffer))) {
  164. char * aval = strtok(buffer, ",");
  165. for (ArmorType armor = ARMOR_FIRST; armor < ARMOR_COUNT; armor++) {
  166. Modifier[armor] = fixed(aval);
  167. aval = strtok(NULL, ",");
  168. }
  169. }
  170. IsOrganic = (Modifier[ARMOR_STEEL] == 0);
  171. return(true);
  172. }
  173. return(false);
  174. }