SUPER.CPP 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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\super.cpv 1.5 16 Oct 1995 16:49:04 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 : SUPER.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 07/28/95 *
  26. * *
  27. * Last Update : July 29, 1995 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * SuperClass::AI -- Process the super weapon AI. *
  32. * SuperClass::Anim_Stage -- Fetches the animation stage for this super weapon. *
  33. * SuperClass::Discharged -- Handles discharged action for special super weapon. *
  34. * SuperClass::Enable -- Enable this super special weapon. *
  35. * SuperClass::Forced_Charge -- Force the super weapon to full charge state. *
  36. * SuperClass::Impatient_Click -- Called when player clicks on unfinished super weapon. *
  37. * SuperClass::Recharge -- Starts the special super weapon recharging. *
  38. * SuperClass::Remove -- Removes super weapon availability. *
  39. * SuperClass::SuperClass -- Constructor for special super weapon objects. *
  40. * SuperClass::Suspend -- Suspend the charging of the super weapon. *
  41. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  42. #include "function.h"
  43. /***********************************************************************************************
  44. * SuperClass::SuperClass -- Constructor for special super weapon objects. *
  45. * *
  46. * This is the constructor for the super weapons. *
  47. * *
  48. * INPUT: recharge -- The recharge delay time (in game frames). *
  49. * *
  50. * charging -- Voice to announce that the weapon is charging. *
  51. * *
  52. * ready -- Voice to announce that the weapon is fully charged. *
  53. * *
  54. * impatient -- Voice to announce current charging state. *
  55. * *
  56. * OUTPUT: none *
  57. * *
  58. * WARNINGS: none *
  59. * *
  60. * HISTORY: *
  61. * 07/28/1995 JLB : Created. *
  62. *=============================================================================================*/
  63. SuperClass::SuperClass(int recharge, VoxType ready, VoxType charging, VoxType impatient, VoxType suspend)
  64. {
  65. IsPresent = false;
  66. IsOneTime = false;
  67. IsReady = false;
  68. IsSuspended = false;
  69. OldStage = -1;
  70. Control = 0;
  71. RechargeTime = recharge;
  72. SuspendTime = 0;
  73. VoxRecharge = ready;
  74. VoxCharging = charging;
  75. VoxImpatient = impatient;
  76. VoxSuspend = suspend;
  77. }
  78. /***********************************************************************************************
  79. * SuperClass::Suspend -- Suspend the charging of the super weapon. *
  80. * *
  81. * This will temporarily put on hold the charging of the special weapon. This might be the *
  82. * result of insufficient power. *
  83. * *
  84. * INPUT: on -- Should the weapon charging be suspended? Else, it will unsuspend. *
  85. * *
  86. * OUTPUT: Was the weapon suspend state changed? *
  87. * *
  88. * WARNINGS: none *
  89. * *
  90. * HISTORY: *
  91. * 07/28/1995 JLB : Created. *
  92. *=============================================================================================*/
  93. bool SuperClass::Suspend(bool on)
  94. {
  95. if (IsPresent && !IsReady && !IsOneTime) {
  96. if (on != IsSuspended) {
  97. if (on) {
  98. SuspendTime = Control;
  99. } else {
  100. Control = SuspendTime;
  101. }
  102. IsSuspended = on;
  103. return(true);
  104. }
  105. }
  106. return(false);
  107. }
  108. /***********************************************************************************************
  109. * SuperClass::Enable -- Enable this super special weapon. *
  110. * *
  111. * This routine is called when the special weapon needs to be activated. This is used for *
  112. * both the normal super weapons and the speicial one-time super weapons (from crates). *
  113. * *
  114. * INPUT: onetime -- Is this a special one time super weapon? *
  115. * *
  116. * player -- Is this weapon for the player? If true, then there might be a voice *
  117. * announcement of this weapon's availability. *
  118. * *
  119. * quiet -- Request that the weapon start in suspended state (quiet mode). *
  120. * *
  121. * OUTPUT: Was the special super weapon enabled? Failure might indicate that the weapon was *
  122. * already available. *
  123. * *
  124. * WARNINGS: none *
  125. * *
  126. * HISTORY: *
  127. * 07/28/1995 JLB : Created. *
  128. *=============================================================================================*/
  129. bool SuperClass::Enable(bool onetime, bool player, bool quiet)
  130. {
  131. if (!IsPresent) {
  132. IsPresent = true;
  133. IsOneTime = onetime;
  134. bool retval = Recharge(player && !quiet);
  135. if (quiet) Suspend(true);
  136. return(retval);
  137. }
  138. return(false);
  139. }
  140. /***********************************************************************************************
  141. * SuperClass::Remove -- Removes super weapon availability. *
  142. * *
  143. * Call this routine when the super weapon should be removed because of some outside *
  144. * force. For one time special super weapons, they can never be removed except as the *
  145. * result of discharging them. *
  146. * *
  147. * INPUT: none *
  148. * *
  149. * OUTPUT: Was the special weapon removed and disabled? *
  150. * *
  151. * WARNINGS: none *
  152. * *
  153. * HISTORY: *
  154. * 07/28/1995 JLB : Created. *
  155. *=============================================================================================*/
  156. bool SuperClass::Remove(bool forced)
  157. {
  158. if (IsPresent && (!IsOneTime || forced)) {
  159. IsReady = false;
  160. IsPresent = false;
  161. return(true);
  162. }
  163. return(false);
  164. }
  165. /***********************************************************************************************
  166. * SuperClass::Recharge -- Starts the special super weapon recharging. *
  167. * *
  168. * This routine is called when the special weapon is allowed to recharge. Suspension will *
  169. * be disabled and the animation process will begin. *
  170. * *
  171. * INPUT: player -- Is this for a player owned super weapon? If so, then a voice *
  172. * announcement might be in order. *
  173. * *
  174. * OUTPUT: Was the super weapon begun charging up? *
  175. * *
  176. * WARNINGS: none *
  177. * *
  178. * HISTORY: *
  179. * 07/28/1995 JLB : Created. *
  180. *=============================================================================================*/
  181. bool SuperClass::Recharge(bool player)
  182. {
  183. if (IsPresent && !IsReady) {
  184. IsSuspended = false;
  185. OldStage = -1;
  186. #ifdef CHEAT_KEYS
  187. if (Special.IsSpeedBuild) {
  188. Control = 1;
  189. } else {
  190. Control = RechargeTime;
  191. }
  192. #else
  193. Control = RechargeTime;
  194. #endif
  195. if (player && VoxCharging != VOX_NONE) {
  196. Speak(VoxCharging);
  197. }
  198. return(true);
  199. }
  200. return(false);
  201. }
  202. /***********************************************************************************************
  203. * Superclass::Discharged -- Handles discharged action for special super weapon. *
  204. * *
  205. * This routine should be called when the special super weapon has been discharged. The *
  206. * weapon will either begin charging anew or will be removed entirely -- depends on the *
  207. * one time flag for the weapon. *
  208. * *
  209. * INPUT: player -- Is this special weapon for the player? If so, then there might be a *
  210. * voice announcement. *
  211. * *
  212. * OUTPUT: Should the sidebar be reprocessed because the special weapon has been eliminated? *
  213. * *
  214. * WARNINGS: none *
  215. * *
  216. * HISTORY: *
  217. * 07/28/1995 JLB : Created. *
  218. *=============================================================================================*/
  219. bool SuperClass::Discharged(bool player)
  220. {
  221. if (!IsSuspended && IsPresent && IsReady) {
  222. IsReady = false;
  223. if (IsOneTime) {
  224. IsOneTime = false;
  225. return(Remove());
  226. } else {
  227. Recharge(player);
  228. }
  229. }
  230. return(false);
  231. }
  232. /***********************************************************************************************
  233. * SuperClass::AI -- Process the super weapon AI. *
  234. * *
  235. * This routine will process the charge up AI for this super weapon object. If the weapon *
  236. * has advanced far enough to change any sidebar graphic that might represent it, then *
  237. * "true" will be returned. Use this return value to intelligenly update the sidebar. *
  238. * *
  239. * INPUT: player -- Is this for the player? If it is and the weapon is now fully charged, *
  240. * then this fully charged state will be announced to the player. *
  241. * *
  242. * OUTPUT: Was the weapon's state changed such that a sidebar graphic update will be *
  243. * necessary? *
  244. * *
  245. * WARNINGS: none *
  246. * *
  247. * HISTORY: *
  248. * 07/28/1995 JLB : Created. *
  249. *=============================================================================================*/
  250. bool SuperClass::AI(bool player)
  251. {
  252. if (IsPresent && !IsReady) {
  253. if (IsSuspended) {
  254. if (OldStage != -1) {
  255. OldStage = -1;
  256. return(true);
  257. }
  258. } else {
  259. if (Control.Expired()) {
  260. IsReady = true;
  261. if (player && VoxRecharge != VOX_NONE) {
  262. Speak(VoxRecharge);
  263. }
  264. return(true);
  265. } else {
  266. if (Anim_Stage() != OldStage) {
  267. OldStage = Anim_Stage();
  268. return(true);
  269. }
  270. }
  271. }
  272. }
  273. return(false);
  274. }
  275. /***********************************************************************************************
  276. * SuperClass::Anim_Stage -- Fetches the animation stage for this super weapon. *
  277. * *
  278. * This will return the current animation stage for this super weapon. The value will be *
  279. * between zero (uncharged) to ANIMATION_STAGES (fully charged). Use this value to render *
  280. * the appropriate graphic on the sidebar. *
  281. * *
  282. * INPUT: none *
  283. * *
  284. * OUTPUT: Returns with the current animation stage for this special super weapon powerup. *
  285. * *
  286. * WARNINGS: none *
  287. * *
  288. * HISTORY: *
  289. * 07/28/1995 JLB : Created. *
  290. *=============================================================================================*/
  291. int SuperClass::Anim_Stage(void) const
  292. {
  293. if (IsPresent) {
  294. if (IsReady) {
  295. return(ANIMATION_STAGES);
  296. }
  297. int time = Control.Time();
  298. if (IsSuspended) {
  299. time = SuspendTime;
  300. }
  301. return(Fixed_To_Cardinal(ANIMATION_STAGES, Cardinal_To_Fixed(RechargeTime, RechargeTime-time)));
  302. }
  303. return(0);
  304. }
  305. /***********************************************************************************************
  306. * SuperClass::Impatient_Click -- Called when player clicks on unfinished super weapon. *
  307. * *
  308. * This routine is called when the player clicks on the super weapon icon on the sidebar *
  309. * when the super weapon is not ready yet. This results in a voice message feedback to the *
  310. * player. *
  311. * *
  312. * INPUT: none *
  313. * *
  314. * OUTPUT: none *
  315. * *
  316. * WARNINGS: none *
  317. * *
  318. * HISTORY: *
  319. * 07/28/1995 JLB : Created. *
  320. *=============================================================================================*/
  321. void SuperClass::Impatient_Click(void) const
  322. {
  323. if (IsSuspended) {
  324. if (VoxSuspend != VOX_NONE) {
  325. Speak(VoxSuspend);
  326. }
  327. } else {
  328. if (VoxImpatient != VOX_NONE) {
  329. Speak(VoxImpatient);
  330. }
  331. }
  332. }
  333. /***********************************************************************************************
  334. * SuperClass::Forced_Charge -- Force the super weapon to full charge state. *
  335. * *
  336. * This routine will force the special weapon to full charge state. Call it when the weapon *
  337. * needs to be instantly charged. The airstrike (when it first becomes available) is a *
  338. * good example. *
  339. * *
  340. * INPUT: player -- Is this for the player? If true, then the full charge state will be *
  341. * announced. *
  342. * *
  343. * OUTPUT: none *
  344. * *
  345. * WARNINGS: none *
  346. * *
  347. * HISTORY: *
  348. * 07/29/1995 JLB : Created. *
  349. *=============================================================================================*/
  350. void SuperClass::Forced_Charge(bool player)
  351. {
  352. if (IsPresent) {
  353. IsReady = true;
  354. IsSuspended = false;
  355. if (player && VoxRecharge != VOX_NONE) {
  356. Speak(VoxRecharge);
  357. }
  358. }
  359. }