WARHEAD.CPP 12 KB

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