CnC_Remastered_Collection

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

SUPER.CPP (23220B)


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