CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

SUPER.CPP (23120B)


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