FUSE.CPP 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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/FUSE.CPP 1 3/03/97 10:24a 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 : FUSE.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : April 24, 1994 *
  30. * *
  31. * Last Update : October 17, 1994 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * FuseClass::Arm_Fuse -- Sets up fuse for detonation check. *
  36. * FuseClass::Fuse_Checkup -- Determines if the fuse triggers. *
  37. * FuseClass::Fuse_Read -- Reads the fuse class data from the save game file. *
  38. * FuseClass::Fuse_Write -- Writes the fuse data to the save game file. *
  39. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  40. #include "function.h"
  41. /***********************************************************************************************
  42. * FuseClass::FuseClass -- Constructor. *
  43. * *
  44. * INPUT: none *
  45. * *
  46. * OUTPUT: none *
  47. * *
  48. * WARNINGS: none *
  49. * *
  50. * HISTORY: *
  51. * 06/27/1995 BRR : Created. Gosh, what a lotta work. *
  52. *=============================================================================================*/
  53. FuseClass::FuseClass(void)
  54. {
  55. Timer = 0;
  56. Arming = 0;
  57. HeadTo = 0;
  58. Proximity = 0;
  59. }
  60. /***********************************************************************************************
  61. * FuseClass::Arm_Fuse -- Sets up fuse for detonation check. *
  62. * *
  63. * This starts a fuse. Fuses are proximity detonation variety but *
  64. * can be modified to have a minimum time to elapse before detonation *
  65. * and a maximum time to exist before detonation. Typically, the *
  66. * timing values are used for missiles that have a minimum arming *
  67. * distance and a limited amount of fuel. *
  68. * *
  69. * INPUT: location -- The coordinate where the projectile start. This *
  70. * is needed for proper proximity tracking. *
  71. * *
  72. * target -- The actual impact point. Fuses are based on real *
  73. * word coordinates. *
  74. * *
  75. * time -- The maximum time that the fuse may work before *
  76. * explosion is forced. *
  77. * *
  78. * arming -- The minimum time that must elapse before the *
  79. * fuse may explode. *
  80. * *
  81. * OUTPUT: none *
  82. * *
  83. * WARNINGS: none *
  84. * *
  85. * HISTORY: *
  86. * 04/24/1994 JLB : Created. *
  87. *=============================================================================================*/
  88. void FuseClass::Arm_Fuse(COORDINATE location, COORDINATE target, int timeto, int arming)
  89. {
  90. timeto = max(timeto, arming);
  91. Timer = min(timeto, 0xFF);
  92. Arming = min(arming, 0xFF);
  93. HeadTo = target;
  94. Proximity = Distance(location, target);
  95. }
  96. /***********************************************************************************************
  97. * FuseClass::Fuse_Checkup -- Determines if the fuse triggers. *
  98. * *
  99. * This will process the fuse and update the internal clocks as well *
  100. * as check to see if the fuse should trigger (explode) or not. *
  101. * *
  102. * INPUT: newlocation -- The new location of the fuse. This is needed *
  103. * to determine proximity explosions. *
  104. * *
  105. * OUTPUT: bool; Was the fuse triggered to explode now? *
  106. * *
  107. * WARNINGS: none *
  108. * *
  109. * HISTORY: *
  110. * 04/24/1994 JLB : Created. *
  111. *=============================================================================================*/
  112. bool FuseClass::Fuse_Checkup(COORDINATE newlocation)
  113. {
  114. int proximity;
  115. /*
  116. ** Always decrement the fuse timer.
  117. */
  118. if (Timer) Timer--;
  119. /*
  120. ** If the arming countdown has not expired, then do nothing.
  121. */
  122. if (Arming) {
  123. Arming--;
  124. } else {
  125. /*
  126. ** If the timer has run out, then the warhead explodes.
  127. */
  128. if (!Timer) return(true);
  129. proximity = Distance(newlocation, HeadTo);
  130. if (proximity < 0x0010) return(true);
  131. if (proximity < ICON_LEPTON_W && proximity > Proximity) {
  132. return(true);
  133. }
  134. Proximity = proximity;
  135. }
  136. return(false);
  137. }
  138. /***********************************************************************************************
  139. * FuseClass::Fuse_Write -- Writes the fuse data to the save game file. *
  140. * *
  141. * Use this routine to output the fuse class data to the save game file specified. *
  142. * *
  143. * INPUT: file -- The file to output the data to. *
  144. * *
  145. * OUTPUT: none *
  146. * *
  147. * WARNINGS: none *
  148. * *
  149. * HISTORY: *
  150. * 10/17/1994 JLB : Created. *
  151. *=============================================================================================*/
  152. void FuseClass::Fuse_Write(FileClass & file)
  153. {
  154. file.Write(&Timer, sizeof(Timer));
  155. file.Write(&Arming, sizeof(Arming));
  156. file.Write(&HeadTo, sizeof(HeadTo));
  157. file.Write(&Proximity, sizeof(Proximity));
  158. }
  159. /***********************************************************************************************
  160. * FuseClass::Fuse_Read -- Reads the fuse class data from the save game file. *
  161. * *
  162. * Use this routine to input the fuse class data from the save game file specified. *
  163. * *
  164. * INPUT: file -- The file to input the data from. *
  165. * *
  166. * OUTPUT: none *
  167. * *
  168. * WARNINGS: none *
  169. * *
  170. * HISTORY: *
  171. * 10/17/1994 JLB : Created. *
  172. *=============================================================================================*/
  173. void FuseClass::Fuse_Read(FileClass & file)
  174. {
  175. file.Read(&Timer, sizeof(Timer));
  176. file.Read(&Arming, sizeof(Arming));
  177. file.Read(&HeadTo, sizeof(HeadTo));
  178. file.Read(&Proximity, sizeof(Proximity));
  179. }