SUPER.CPP 23 KB

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