CnC_Remastered_Collection

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

CREDITS.CPP (9815B)


      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\credits.cpv   2.17   16 Oct 1995 16:51:28   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::Graphic_Logic -- Handles the credit redraw logic.                            *
     35  *   CreditClass::CreditClass -- Default constructor for the credit class object.              *
     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 {
     58 	IsToRedraw = false;
     59 	IsUp = false;
     60 	IsAudible = false;
     61 	Credits = 0;
     62 	Current = 0;
     63 	Countdown = 0;
     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 	int factor = Get_Resolution_Factor();
     89 	int xx = SeenBuff.Get_Width() - (120 << factor);
     90 	if (forced || IsToRedraw) {
     91 
     92 		/*
     93 		**	Play a sound effect when the money display changes, but only if a sound
     94 		**	effect was requested.
     95 		*/
     96 		if (IsAudible) {
     97 			if (IsUp) {
     98 				Sound_Effect(VOC_UP, VOL_1);
     99 			} else  {
    100 				Sound_Effect(VOC_DOWN, VOL_1);
    101 			}
    102 		}
    103 
    104 		/*
    105 		**	Display the new current value.
    106 		*/
    107 		//LogicPage->Fill_Rect(xx-(20 << factor), 1 << factor, xx+(20 << factor), 6 << factor, LTGREY);
    108 		TabClass::Draw_Credits_Tab();
    109 		Fancy_Text_Print("%ld", xx, 0, 11, TBLACK, TPF_GREEN12_GRAD|TPF_CENTER | TPF_USE_GRAD_PAL, Current);
    110 
    111 		IsToRedraw = false;
    112 		IsAudible = false;
    113 	}
    114 }
    115 
    116 
    117 /***********************************************************************************************
    118  * CreditClass::AI -- Handles updating the credit display.                                     *
    119  *                                                                                             *
    120  *    This routine handles the logic that controls the rate of credit change in the credit     *
    121  *    display. It doesn't actually redraw the credit display, but will flag it to be redrawn   *
    122  *    if it detects that a change is to occur.                                                 *
    123  *                                                                                             *
    124  * INPUT:   forced   -- Should the credit display immediately reflect the current credit       *
    125  *                      total for the player? This is usually desired when initially loading   *
    126  *                      a scenario or saved game.                                              *
    127  *          player_ptr -- Player to calculate visible credits for                              *
    128  *          logic_only -- If true, don't flag map for redraw                                   *
    129  *                                                                                             *
    130  * OUTPUT:  none                                                                               *
    131  *                                                                                             *
    132  * WARNINGS:   none                                                                            *
    133  *                                                                                             *
    134  * HISTORY:                                                                                    *
    135  *   03/13/1995 JLB : Created.                                                                 *
    136  *   10/16/2019  ST : Added house and logic parameters so we can call this from HouseClass::AI *
    137  *=============================================================================================*/
    138 void CreditClass::AI(bool forced, HouseClass *player_ptr, bool logic_only)
    139 {
    140 	if (player_ptr == NULL) {
    141 		return;
    142 	}
    143 
    144 	Credits = player_ptr->Available_Money();
    145 
    146 	/*
    147 	**	Make sure that the credit counter doesn't drop below zero.
    148 	*/
    149 	Credits = MAX(Credits, 0L);
    150 
    151 	if (Current == Credits) return;
    152 
    153 	if (forced) {
    154 		IsAudible = false;
    155 		Current = Credits;
    156 	} else {
    157 
    158 		if (Countdown) Countdown--;
    159 		if (Countdown) return;
    160 
    161 		/*
    162 		**	Determine the amount to change the display toward the
    163 		**	desired value.
    164 		*/
    165 		long adder = Credits - Current;
    166 		adder = ABS(adder);
    167 		adder >>= 5;
    168 		adder = Bound(adder, 1L, 71+72);
    169 		if (Current > Credits) adder = -adder;
    170 		Current += adder;
    171 		Countdown = 1;
    172 
    173 		if (Current-adder != Current) {
    174 			IsAudible = true;
    175 			IsUp = (adder > 0);
    176 		}
    177 	}
    178 	IsToRedraw = true;
    179 
    180 	if (!logic_only) {
    181 		Map.Flag_To_Redraw(false);
    182 	}
    183 }