SUPER.CPP 22 KB

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