FUSE.CPP 12 KB

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