CnC_Remastered_Collection

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

CREDITS.CPP (12089B)


      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/CREDITS.CPP 1     3/03/97 10:24a 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 : CREDITS.CPP                                                  *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : April 17, 1994                                               *
     28  *                                                                                             *
     29  *                  Last Update : March 13, 1995 [JLB]                                         *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  *   CreditClass::AI -- Handles updating the credit display.                                   *
     34  *   CreditClass::CreditClass -- Default constructor for the credit class object.              *
     35  *   CreditClass::Graphic_Logic -- Handles the credit redraw logic.                            *
     36  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     37 
     38 #include	"function.h"
     39 
     40 
     41 /***********************************************************************************************
     42  * CreditClass::CreditClass -- Default constructor for the credit class object.                *
     43  *                                                                                             *
     44  *    This is the constructor for the credit class object. It merely sets the credit display   *
     45  *    state to null.                                                                           *
     46  *                                                                                             *
     47  * INPUT:   none                                                                               *
     48  *                                                                                             *
     49  * OUTPUT:  none                                                                               *
     50  *                                                                                             *
     51  * WARNINGS:   none                                                                            *
     52  *                                                                                             *
     53  * HISTORY:                                                                                    *
     54  *   03/13/1995 JLB : Created.                                                                 *
     55  *=============================================================================================*/
     56 CreditClass::CreditClass(void) :
     57 	Credits(0),
     58 	Current(0),
     59 	IsToRedraw(false),
     60 	IsUp(false),
     61 	IsAudible(false),
     62 	Countdown(0)
     63 {
     64 }
     65 
     66 
     67 /***********************************************************************************************
     68  * CreditClass::Graphic_Logic -- Handles the credit redraw logic.                              *
     69  *                                                                                             *
     70  *    This routine should be called whenever the main game screen is to be updated. It will    *
     71  *    check to see if the credit display should be redrawn. If so, it will redraw it.          *
     72  *                                                                                             *
     73  * INPUT:   forced   -- Should the credit display be redrawn regardless of whether the redraw  *
     74  *                      flag is set? This is typically the case when the screen needs to be    *
     75  *                      redrawn from scratch.                                                  *
     76  *                                                                                             *
     77  * OUTPUT:  none                                                                               *
     78  *                                                                                             *
     79  * WARNINGS:   none                                                                            *
     80  *                                                                                             *
     81  * HISTORY:                                                                                    *
     82  *   03/13/1995 JLB : Created.                                                                 *
     83  *=============================================================================================*/
     84 //#define	XX (320-120)
     85 //#define	WW	50
     86 void CreditClass::Graphic_Logic(bool forced)
     87 {
     88 	if (forced || IsToRedraw) {
     89 		BStart(BENCH_TABS);
     90 
     91 		int xx = SeenBuff.Get_Width() - (120 * RESFACTOR);
     92 
     93 		/*
     94 		** Adjust the credits display to be above the sidebar for 640x400
     95 		*/
     96 #ifdef WIN32
     97 		xx += 80 * RESFACTOR;
     98 #endif
     99 
    100 		/*
    101 		**	Play a sound effect when the money display changes, but only if a sound
    102 		**	effect was requested.
    103 		*/
    104 		if (IsAudible) {
    105 			if (IsUp) {
    106 				Sound_Effect(VOC_MONEY_UP, fixed(1, 2));
    107 			} else  {
    108 				Sound_Effect(VOC_MONEY_DOWN, fixed(1, 2));
    109 			}
    110 		}
    111 
    112 		/*
    113 		**	Display the new current value.
    114 		*/
    115 		// PG TabClass::Draw_Credits_Tab();
    116 #ifdef WIN32
    117 		//PG Fancy_Text_Print("%ld", xx, 0, &MetalScheme, TBLACK, TPF_METAL12 | TPF_CENTER | TPF_USE_GRAD_PAL, Current);
    118 #else
    119 		Fancy_Text_Print("%ld", xx, 0, &ColorRemaps[PCOLOR_GREY], TBLACK, TPF_NOSHADOW|TPF_6PT_GRAD|TPF_CENTER|TPF_BRIGHT_COLOR, Current);
    120 #endif	//WIN32
    121 
    122 		if (Scen.MissionTimer.Is_Active()) {
    123 			long secs = Scen.MissionTimer / TICKS_PER_SECOND;
    124 			long mins = secs / 60;
    125 			long hours = mins / 60;
    126 			secs %= 60;
    127 			mins %= 60;
    128 #if (0) //Moved to LOGIC.CPP
    129 			/*
    130 			**	Speak mission timer reminders.
    131 			*/
    132 			VoxType vox = VOX_NONE;
    133 			if (Scen.MissionTimer == (1 * TICKS_PER_MINUTE)) vox = VOX_TIME_1;
    134 			if (Scen.MissionTimer == (2 * TICKS_PER_MINUTE)) vox = VOX_TIME_2;
    135 			if (Scen.MissionTimer == (3 * TICKS_PER_MINUTE)) vox = VOX_TIME_3;
    136 			if (Scen.MissionTimer == (4 * TICKS_PER_MINUTE)) vox = VOX_TIME_4;
    137 			if (Scen.MissionTimer == (5 * TICKS_PER_MINUTE)) vox = VOX_TIME_5;
    138 			if (Scen.MissionTimer == (10 * TICKS_PER_MINUTE)) vox = VOX_TIME_10;
    139 			if (Scen.MissionTimer == (20 * TICKS_PER_MINUTE)) vox = VOX_TIME_20;
    140 			if (Scen.MissionTimer == (30 * TICKS_PER_MINUTE)) vox = VOX_TIME_30;
    141 			if (Scen.MissionTimer == (40 * TICKS_PER_MINUTE)) vox = VOX_TIME_40;
    142 			if (vox != VOX_NONE) {
    143 				Speak(vox);
    144 				Map.FlasherTimer = 7;
    145 			}
    146 #endif
    147 #ifdef WIN32
    148 #if (0) //PG
    149 			if (hours) {
    150 				Fancy_Text_Print(TXT_TIME_FORMAT_HOURS, 200 * RESFACTOR, 0, &MetalScheme, TBLACK, TPF_METAL12|TPF_CENTER|TPF_USE_GRAD_PAL, hours, mins, secs);
    151 			} else {
    152 				Fancy_Text_Print(TXT_TIME_FORMAT_NO_HOURS, 200 * RESFACTOR, 0, &MetalScheme, TBLACK, TPF_METAL12|TPF_CENTER|TPF_USE_GRAD_PAL, mins, secs);
    153 			}
    154 #endif
    155 #else
    156 			if (hours) {
    157 				Fancy_Text_Print("%02d:%02d:%02d", 120 * RESFACTOR, 0, &ColorRemaps[PCOLOR_GREY], TBLACK, TPF_NOSHADOW|TPF_6PT_GRAD|TPF_CENTER|TPF_BRIGHT_COLOR, hours, mins, secs);
    158 			} else {
    159 				Fancy_Text_Print("%02d:%02d", 120 * RESFACTOR, 0, &ColorRemaps[PCOLOR_GREY], TBLACK, TPF_NOSHADOW|TPF_6PT_GRAD|TPF_CENTER|TPF_BRIGHT_COLOR, mins, secs);
    160 			}
    161 #endif	//WIN32
    162 		}
    163 
    164 		IsToRedraw = false;
    165 		IsAudible = false;
    166 		BEnd(BENCH_TABS);
    167 	}
    168 }
    169 
    170 
    171 /***********************************************************************************************
    172  * CreditClass::AI -- Handles updating the credit display.                                     *
    173  *                                                                                             *
    174  *    This routine handles the logic that controls the rate of credit change in the credit     *
    175  *    display. It doesn't actually redraw the credit display, but will flag it to be redrawn   *
    176  *    if it detects that a change is to occur.                                                 *
    177  *                                                                                             *
    178  * INPUT:   forced   -- Should the credit display immediately reflect the current credit       *
    179  *                      total for the player? This is usually desired when initially loading   *
    180  *                      a scenario or saved game.                                              *
    181  *          player_ptr -- Player to calculate visible credits for                              *
    182  *          logic_only -- If true, don't flag map for redraw                                   *
    183  *                                                                                             *
    184  * OUTPUT:  none                                                                               *
    185  *                                                                                             *
    186  * WARNINGS:   none                                                                            *
    187  *                                                                                             *
    188  * HISTORY:                                                                                    *
    189  *   03/13/1995 JLB : Created.                                                                 *
    190  *   10/16/2019  ST : Added house and logic parameters so we can call this from HouseClass::AI *
    191  *=============================================================================================*/
    192 void CreditClass::AI(bool forced, HouseClass *player_ptr, bool logic_only)
    193 {
    194 	static int _last = 0;
    195 
    196 	if (!forced && !logic_only && Frame == _last) return;
    197 	if (!logic_only) {
    198 		_last = Frame;
    199 	}
    200 
    201 	if (player_ptr == NULL) {
    202 		return;
    203 	}
    204 
    205 	Credits = player_ptr->Available_Money();
    206 
    207 	/*
    208 	**	Make sure that the credit counter doesn't drop below zero.
    209 	*/
    210 	Credits = max(Credits, 0L);
    211 
    212 	if (Scen.MissionTimer.Is_Active() || Scen.MissionTimer) {
    213 		IsToRedraw = true;
    214 		Map.Flag_To_Redraw(false);
    215 	}
    216 
    217 	if (Current == Credits) return;
    218 
    219 	if (forced) {
    220 		IsAudible = false;
    221 		Current = Credits;
    222 	} else {
    223 
    224 		if (Countdown) Countdown--;
    225 		if (Countdown) return;
    226 
    227 		/*
    228 		**	Determine the amount to change the display toward the
    229 		**	desired value.
    230 		*/
    231 		int adder = Credits - Current;
    232 
    233 		if (adder > 0) {
    234 			Countdown = 1;
    235 		} else {
    236 			Countdown = 3;
    237 		}
    238 
    239 		adder = ABS(adder);
    240 		adder >>= 3;
    241 //		adder >>= 4;
    242 //		adder >>= 5;
    243 		adder = Bound(adder, 1, 71+72);
    244 		if (Current > Credits) adder = -adder;
    245 		Current += adder;
    246 		if (Current-adder != Current) {
    247 			IsAudible = true;
    248 			IsUp = (adder > 0);
    249 		}
    250 	}
    251 	IsToRedraw = true;
    252 
    253 	if (!logic_only) {
    254 		Map.Flag_To_Redraw(false);
    255 	}
    256 }