CnC_Remastered_Collection

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

MOUSE.CPP (21783B)


      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/MOUSE.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 : MOUSE.CPP                                                    *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : 12/15/94                                                     *
     28  *                                                                                             *
     29  *                  Last Update : September 21, 1995 [JLB]                                     *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  *   MouseClass::AI -- Process player input as it relates to the mouse                         *
     34  *   MouseClass::Init_Clear -- Sets the mouse system to a known state                          *
     35  *   MouseClass::MouseClass -- Default constructor for the mouse handler class.                *
     36  *   MouseClass::Mouse_Small -- Controls the sizing of the mouse.                              *
     37  *   MouseClass::One_Time -- Performs the one time initialization of the mouse system.         *
     38  *   MouseClass::Override_Mouse_Shape -- Alters the shape of the mouse.                        *
     39  *   MouseClass::Revert_Mouse_Shape -- Reverts the mouse shape to the non overridden shape.    *
     40  *   MouseClass::Set_Default_Mouse -- Sets the mouse to match the shape specified.             *
     41  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     42 
     43 #include	"function.h"
     44 
     45 
     46 /*
     47 **	This points to the loaded mouse shapes.
     48 */
     49 void const * MouseClass::MouseShapes;
     50 
     51 /*
     52 **	This is the timer that controls the mouse animation. It is always at a fixed
     53 **	rate so it uses the constant system timer.
     54 */
     55 CDTimerClass<SystemTimerClass> MouseClass::Timer = 0;
     56 
     57 
     58 /***********************************************************************************************
     59  * MouseClass::MouseClass -- Default constructor for the mouse handler class.                  *
     60  *                                                                                             *
     61  *    This is the default constructor for the mouse handling class. It merely sets up the      *
     62  *    mouse system to its default state.                                                       *
     63  *                                                                                             *
     64  * INPUT:   none                                                                               *
     65  *                                                                                             *
     66  * OUTPUT:  none                                                                               *
     67  *                                                                                             *
     68  * WARNINGS:   none                                                                            *
     69  *                                                                                             *
     70  * HISTORY:                                                                                    *
     71  *   12/24/1994 JLB : Created.                                                                 *
     72  *=============================================================================================*/
     73 MouseClass::MouseClass(void) :
     74 	IsSmall(false),
     75 	CurrentMouseShape(MOUSE_NORMAL),
     76 	NormalMouseShape(MOUSE_NORMAL),
     77 	Frame(0)
     78 {
     79 }
     80 
     81 
     82 /***********************************************************************************************
     83  * MouseClass::Set_Default_Mouse -- Sets the mouse to match the shape specified.               *
     84  *                                                                                             *
     85  *    This routine is used to inform the display system as to which mouse shape is desired.    *
     86  *                                                                                             *
     87  * INPUT:   mouse -- The mouse shape number to set the mouse to.                               *
     88  *                                                                                             *
     89  * OUTPUT:  none                                                                               *
     90  *                                                                                             *
     91  * WARNINGS:   none                                                                            *
     92  *                                                                                             *
     93  * HISTORY:                                                                                    *
     94  *   09/19/1994 JLB : Created.                                                                 *
     95  *=============================================================================================*/
     96 void MouseClass::Set_Default_Mouse(MouseType mouse, bool size)
     97 {
     98 	assert((unsigned)mouse < MOUSE_COUNT);
     99 
    100 	NormalMouseShape = mouse;
    101 	Override_Mouse_Shape(mouse, size);
    102 }
    103 
    104 
    105 /***********************************************************************************************
    106  * MouseClass::Revert_Mouse_Shape -- Reverts the mouse shape to the non overridden shape.      *
    107  *                                                                                             *
    108  *    Use this routine to cancel the effects of Override_Mouse_Shape(). It will revert the     *
    109  *    mouse back to the original shape.                                                        *
    110  *                                                                                             *
    111  * INPUT:   none                                                                               *
    112  *                                                                                             *
    113  * OUTPUT:  none                                                                               *
    114  *                                                                                             *
    115  * WARNINGS:   none                                                                            *
    116  *                                                                                             *
    117  * HISTORY:                                                                                    *
    118  *   03/27/1995 JLB : Created.                                                                 *
    119  *=============================================================================================*/
    120 void MouseClass::Revert_Mouse_Shape(void)
    121 {
    122 	Override_Mouse_Shape(NormalMouseShape, false);
    123 }
    124 
    125 
    126 /***********************************************************************************************
    127  * MouseClass::Mouse_Small -- Controls the sizing of the mouse.                                *
    128  *                                                                                             *
    129  *    This routine is called to change the mouse sizing override. If the mouse can change      *
    130  *    size to that specified, then the mouse imagery will be changed. If a change of imagery   *
    131  *    cannot occur (due to lack of appropriate artwork), then no action will be performed.     *
    132  *                                                                                             *
    133  * INPUT:   small -- Should the mouse be made small? If not, then it will be made large.       *
    134  *                                                                                             *
    135  * OUTPUT:  none                                                                               *
    136  *                                                                                             *
    137  * WARNINGS:   none                                                                            *
    138  *                                                                                             *
    139  * HISTORY:                                                                                    *
    140  *   09/21/1995 JLB : Created.                                                                 *
    141  *=============================================================================================*/
    142 void MouseClass::Mouse_Small(bool wsmall)
    143 {
    144 	MouseStruct const * control = &MouseControl[CurrentMouseShape];
    145 
    146 	if (IsSmall == wsmall) {
    147 		return;
    148 	}
    149 
    150 	IsSmall	= wsmall;
    151 
    152 	if (wsmall) {
    153 		if (control->SmallFrame != -1) {
    154 			Set_Mouse_Cursor(control->X, control->Y, Extract_Shape(MouseShapes, control->SmallFrame + Frame/4));
    155 		} else {
    156 			Set_Mouse_Cursor(MouseControl[MOUSE_NORMAL].X, MouseControl[MOUSE_NORMAL].Y, Extract_Shape(MouseShapes, MOUSE_NORMAL));
    157 		}
    158 	} else {
    159 		Set_Mouse_Cursor(control->X, control->Y, Extract_Shape(MouseShapes, control->StartFrame + Frame/4));
    160 	}
    161 }
    162 
    163 
    164 /***********************************************************************************************
    165  * MouseClass::Override_Mouse_Shape -- Alters the shape of the mouse.                          *
    166  *                                                                                             *
    167  *    This routine is used to alter the shape of the mouse as needed.                          *
    168  *    Typical mouse shape change occurs when scrolling the map or                              *
    169  *    selecting targets.                                                                       *
    170  *                                                                                             *
    171  * INPUT:   mouse -- The mouse shape number to use.                                            *
    172  *                                                                                             *
    173  * OUTPUT:  bool; Was the mouse shape changed?                                                 *
    174  *                                                                                             *
    175  * WARNINGS:   This is not intended to be used as a means to hide the                          *
    176  *             mouse. Nor will it work correctly if the mouse shape                            *
    177  *             file hasn't been loaded.                                                        *
    178  *                                                                                             *
    179  * HISTORY:                                                                                    *
    180  *   03/10/1994 JLB : Created.                                                                 *
    181  *   06/03/1994 JLB : Made into member function.                                               *
    182  *   12/24/1994 JLB : Added small control parameter.                                           *
    183  *=============================================================================================*/
    184 #ifdef WIN32
    185 void Block_Mouse(GraphicBufferClass *buffer);
    186 void Unblock_Mouse(GraphicBufferClass *buffer);
    187 #endif
    188 
    189 bool MouseClass::Override_Mouse_Shape(MouseType mouse, bool wsmall)
    190 {
    191 	assert((unsigned)mouse < MOUSE_COUNT);
    192 
    193 	MouseStruct const * control = &MouseControl[mouse];
    194 	static bool startup = false;
    195 	int baseshp;
    196 
    197 	/*
    198 	**	Only certain mouse shapes have a small counterpart. If the requested mouse
    199 	**	shape is not one of these, then force the small size override flag to false.
    200 	*/
    201 	if (control->SmallFrame == -1) {
    202 		wsmall = false;
    203 	}
    204 
    205 	/*
    206 	**	If the mouse shape is going to change, then inform the mouse driver of the
    207 	**	change.
    208 	*/
    209 	if (!startup || (MouseShapes && ((mouse != CurrentMouseShape) || (wsmall != IsSmall)))) {
    210 		startup = true;
    211 
    212 		Timer = control->FrameRate;
    213 		Frame = 0;
    214 
    215 		baseshp = (wsmall) ? control->SmallFrame : control->StartFrame;
    216 		if (baseshp == -1) {
    217 			baseshp = control->StartFrame;
    218 		}
    219 
    220 		Set_Mouse_Cursor(control->X, control->Y, Extract_Shape(MouseShapes, baseshp));
    221 		CurrentMouseShape = mouse;
    222 		IsSmall = wsmall;
    223 		return(true);
    224 	}
    225 	return(false);
    226 }
    227 
    228 
    229 /***********************************************************************************************
    230  * MouseClass::AI -- Process player input as it relates to the mouse                           *
    231  *                                                                                             *
    232  *    This routine will is to be called once per game tick and is passed the player keyboard   *
    233  *    or mouse input code. It processes this code and updates the mouse shape as appropriate.  *
    234  *                                                                                             *
    235  * INPUT:   input -- The player input code as returned from Keyboard->Get().                   *
    236  *                                                                                             *
    237  *          x,y   -- The mouse coordinate values to use.                                       *
    238  *                                                                                             *
    239  * OUTPUT:  none                                                                               *
    240  *                                                                                             *
    241  * WARNINGS:   none                                                                            *
    242  *                                                                                             *
    243  * HISTORY:                                                                                    *
    244  *   12/24/1994 JLB : Created.                                                                 *
    245  *   12/31/1994 JLB : Uses mouse coordinate parameters.                                        *
    246  *   03/27/1995 JLB : New animation control.                                                   *
    247  *   05/28/1995 JLB : Moderates animation so is more steady regardless of speed.               *
    248  *   06/30/1995 JLB : Uses constant timer system.                                              *
    249  *=============================================================================================*/
    250 void MouseClass::AI(KeyNumType &input, int x, int y)
    251 {
    252 	MouseStruct const * control = &MouseControl[CurrentMouseShape];
    253 
    254 	if (control->FrameRate && Timer == 0) {
    255 
    256 		Frame++;
    257 		Frame %= control->FrameCount;
    258 		Timer = control->FrameRate;
    259 
    260 		if (!IsSmall || control->SmallFrame != -1) {
    261 			int baseframe = (IsSmall) ? control->SmallFrame : control->StartFrame;
    262 			if (baseframe == -1) baseframe = control->StartFrame;
    263 			Set_Mouse_Cursor(control->X, control->Y, Extract_Shape(MouseShapes, baseframe + Frame));
    264 		}
    265 	}
    266 
    267 	ScrollClass::AI(input, x, y);
    268 }
    269 
    270 
    271 /***********************************************************************************************
    272  * MouseClass::One_Time -- Performs the one time initialization of the mouse system.           *
    273  *                                                                                             *
    274  *    Use this routine to load the mouse data file and perform any other necessary one time    *
    275  *    preparations for the game.                                                               *
    276  *                                                                                             *
    277  * INPUT:   none                                                                               *
    278  *                                                                                             *
    279  * OUTPUT:  none                                                                               *
    280  *                                                                                             *
    281  * WARNINGS:   Only call this routine ONCE.                                                    *
    282  *                                                                                             *
    283  * HISTORY:                                                                                    *
    284  *   12/24/1994 JLB : Created.                                                                 *
    285  *=============================================================================================*/
    286 void MouseClass::One_Time(void)
    287 {
    288 	ScrollClass::One_Time();
    289 
    290 	/*
    291 	**	Override the mouse shape file with the one in the current directory, but only if there
    292 	**	is an override file available.
    293 	*/
    294 	#ifndef NDEBUG
    295 		RawFileClass file("MOUSE.SHP");
    296 		if (file.Is_Available()) {
    297 			MouseShapes = Load_Alloc_Data(file);
    298 		} else {
    299 			MouseShapes = MFCD::Retrieve("MOUSE.SHP");
    300 		}
    301 	#else
    302 		MouseShapes = MFCD::Retrieve("MOUSE.SHP");
    303 	#endif
    304 }
    305 
    306 
    307 /***********************************************************************************************
    308  * MouseClass::Init_Clear -- Sets the mouse system to a known state                            *
    309  *                                                                                             *
    310  *    This routine will reset the mouse handling system. Typically, this routine is called     *
    311  *    when preparing for the beginning of a new scenario.                                      *
    312  *                                                                                             *
    313  * INPUT:   theater  -- The theater that the scenario will take place.                         *
    314  *                                                                                             *
    315  * OUTPUT:  none                                                                               *
    316  *                                                                                             *
    317  * WARNINGS:   none                                                                            *
    318  *                                                                                             *
    319  * HISTORY:                                                                                    *
    320  *   12/24/1994 JLB : Created.                                                                 *
    321  *=============================================================================================*/
    322 void MouseClass::Init_Clear(void)
    323 {
    324 	ScrollClass::Init_Clear();
    325 	IsSmall = false;
    326 	NormalMouseShape = MOUSE_NORMAL;
    327 }
    328 
    329 
    330 /*
    331 **	This array of structures is used to control the mouse animation
    332 **	sequences.
    333 */
    334 //#ifdef WIN32
    335 //#define	WD	45
    336 //#define	HT	36
    337 //#else
    338 #define	WD	29
    339 #define	HT	23
    340 //#endif
    341 
    342 MouseClass::MouseStruct MouseClass::MouseControl[MOUSE_COUNT] = {
    343 	{0, 	1,		0,		80,	0,		0},		//	MOUSE_NORMAL
    344 	{1, 	1,		0,		-1,	WD/2,	0},		//	MOUSE_N
    345 	{2, 	1,		0,		-1,	WD,	0},		//	MOUSE_NE
    346 	{3, 	1,		0,		-1,	WD,	HT/2},	//	MOUSE_E
    347 	{4,	1,		0,		-1,	WD,	HT},		//	MOUSE_SE
    348 	{5,	1,		0,		-1,	WD/2,	HT},		//	MOUSE_S
    349 	{6,	1,		0,		-1,	0, 	HT},		//	MOUSE_SW
    350 	{7,	1,		0,		-1,	0, 	HT/2},	//	MOUSE_W
    351 	{8,	1,		0,		-1,	0, 	0},		//	MOUSE_NW
    352 
    353 	{124, 1,		0,		-1,	WD/2,	0},		//	MOUSE_NO_N
    354 	{125, 1,		0,		-1,	WD,	0},		//	MOUSE_NO_NE
    355 	{126, 1,		0,		-1,	WD,	HT/2},	//	MOUSE_NO_E
    356 	{127,	1,		0,		-1,	WD,	HT},		//	MOUSE_NO_SE
    357 	{128,	1,		0,		-1,	WD/2,	HT},		//	MOUSE_NO_S
    358 	{129,	1,		0,		-1,	0, 	HT},		//	MOUSE_NO_SW
    359 	{130,	1,		0,		-1,	0, 	HT/2},	//	MOUSE_NO_W
    360 	{131,	1,		0,		-1,	0, 	0},		//	MOUSE_NO_NW
    361 
    362 	{14,	1,		0,		33,	WD/2,	HT/2},	//	MOUSE_NO_MOVE
    363 	{10,	4,		4,		29,	WD/2,	HT/2},	//	MOUSE_CAN_MOVE
    364 	{113,	3,		4,		142,	WD/2,	HT/2},	//	MOUSE_ENTER
    365 	{59,	9,		4,		-1,	WD/2,	HT/2},	//	MOUSE_DEPLOY
    366 	{15,	6,		4,		-1,	WD/2,	HT/2},	//	MOUSE_CAN_SELECT
    367 	{21,	8,		4,		134,	WD/2,	HT/2},	//	MOUSE_CAN_ATTACK
    368 	{68,	12,	2,		-1,	WD/2,	HT/2},	//	MOUSE_SELL_BACK
    369 	{148,	12,	2,		-1,	WD/2,	HT/2},	//	MOUSE_SELL_UNIT
    370 	{35,	24,	2,		-1,	WD/2,	HT/2},	//	MOUSE_REPAIR
    371 	{120,	1,		0,		-1,	WD/2,	HT/2},	//	MOUSE_NO_REPAIR
    372 	{119,	1,		0,		-1,	WD/2,	HT/2},	//	MOUSE_NO_SELL_BACK
    373 	{81,	1,		0,		145,	WD/2, HT/2},	//	MOUSE_RADAR_CURSOR
    374 	{90,	7,		4,		-1,	WD/2,	HT/2},	//	MOUSE_NUCLEAR_BOMB
    375 	{82,	8,		2,		213,	WD/2,	HT/2},	//	MOUSE_AIR_STRIKE
    376 	{116,	3,		4,		121,	WD/2,	HT/2},	//	MOUSE_DEMOLITIONS
    377 	{147,	1,		0,		146,	WD/2,	HT/2},	//	MOUSE_AREA_GUARD
    378 	{160,	4,		4,		194,	WD/2,	HT/2},	//	MOUSE_HEAL
    379 	{164,	3,		4,		167,	WD/2,	HT/2},	//	MOUSE_DAMAGE
    380 	{170,	24,	2,		-1,	WD/2,	HT/2},	//	MOUSE_GREPAIR
    381 	{195,	8,		4,		203,	WD/2,	HT/2},	// MOUSE_STAY_ATTACK
    382 	{211,	1,		0,		-1,	WD/2,	HT/2},	// MOUSE_NO_DEPLOY
    383 	{212,	1,		0,		-1,	WD/2,	HT/2},	// MOUSE_NO_ENTER
    384 	{213,	1,		0,		-1,	WD/2,	HT/2},	// MOUSE_NO_REPAIR
    385 
    386 	{97,	8,		3,		-1,	WD/2,	HT/2},	//	MOUSE_CHRONO_SELECT
    387 	{105,	8,		2,		-1,	WD/2,	HT/2},	//	MOUSE_CHRONO_DEST
    388 
    389 };