CnC_Remastered_Collection

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

MAPSEL.CPP (12892B)


      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/MAPSEL.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 : MAPSEL.CPP                                                   *
     24  *                                                                                             *
     25  *                   Programmer : Barry W. Green                                               *
     26  *                                                                                             *
     27  *                   Start Date : April 17, 1995                                               *
     28  *                                                                                             *
     29  *                  Last Update : April 27, 1995   [BWG]                                       *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  *   Bit_It_In -- Pixel fade graphic copy.                                                     *
     34  *   Map_Selection -- Starts the whole process of selecting next map to go to                  *
     35  *   Print_Statistics -- Prints statistics on country selected                                 *
     36  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     37 
     38 #include	"function.h"
     39 
     40 void Cycle_Call_Back_Delay(int time, PaletteClass &pal);
     41 extern int ControlQ;
     42 
     43 int Mouse_Over_Spot(int house, int scenario);
     44 void Set_Mouse(MouseType shape, int &start, int &count, int &delay, int &xspot, int &yspot);
     45 //VG for ant mission progression
     46 const char* antmission[] = {NULL, "SCA01EA.INI", "SCA02EA.INI", "SCA03EA.INI", "SCA04EA.INI"};
     47 
     48 struct point {
     49 	int x;
     50 	int y;
     51 } const MapCoords[2][14][3] = {
     52  {
     53  {{185,123},{ -1, -1},{ -1, -1}},
     54  {{173,112},{ -1, -1},{ -1, -1}},
     55  {{196,100},{200,112},{ -1, -1}},
     56  {{175,113},{ -1, -1},{ -1, -1}},
     57  {{187, 91},{202, 93},{206,105}},
     58  {{207,161},{212,172},{ -1, -1}},
     59  {{172, 92},{ -1, -1},{ -1, -1}},
     60  {{132,119},{146,125},{ -1, -1}},
     61  {{199, 73},{205, 86},{ -1, -1}},
     62  {{236,114},{ -1, -1},{ -1, -1}},
     63  {{219, 64},{225, 76},{ -1, -1}},
     64  {{256, 69},{ -1, -1},{ -1, -1}},
     65  {{262, 77},{ -1, -1},{ -1, -1}},
     66  {{249, 97},{ -1, -1},{ -1, -1}}
     67  },
     68 // Soviet coords
     69  {
     70  {{178,105},{ -1, -1},{ -1, -1}},
     71  {{163,101},{163,113},{ -1, -1}},
     72  {{160, 89},{ -1, -1},{ -1, -1}},
     73  {{142,101},{142,117},{ -1, -1}},
     74  {{212,163},{ -1, -1},{ -1, -1}},
     75  {{155,133},{171,144},{ -1, -1}},
     76  {{216,103},{ -1, -1},{ -1, -1}},
     77  {{132,145},{154,154},{ -1, -1}},
     78  {{122,117},{ -1, -1},{ -1, -1}},
     79  {{117,130},{ -1, -1},{ -1, -1}},
     80  {{ 99,107},{109,146},{ -1, -1}},
     81  {{134,125},{ -1, -1},{ -1, -1}},
     82  {{ 32,156},{ 46,171},{ -1, -1}},
     83  {{108, 97},{ -1, -1},{ -1, -1}}
     84  }
     85 };
     86 
     87 #ifndef WIN32
     88 extern short StreamLowImpact;
     89 #endif  //WIN32
     90 
     91 /***********************************************************************************************
     92  * Map_Selection -- Starts the whole process of selecting next map to go to                    *
     93  *                                                                                             *
     94  *                                                                                             *
     95  * INPUT:                                                                                      *
     96  *                                                                                             *
     97  * OUTPUT:  none                                                                               *
     98  *                                                                                             *
     99  * WARNINGS:   none                                                                            *
    100  *                                                                                             *
    101  * HISTORY:                                                                                    *
    102  *   07/18/1996 BWG : Created.                                                                 *
    103  *=============================================================================================*/
    104 extern int CopyType;
    105 #ifndef WIN32
    106 extern short StreamLowImpact;
    107 #endif
    108 char const * Map_Selection(void)
    109 {
    110 	return NULL;
    111 #if (0)//PG
    112 	static char scenarioname[_MAX_FNAME+_MAX_EXT];
    113 
    114 #ifdef FIXIT_ANTS
    115 	if (AntsEnabled)  {
    116 		strcpy(scenarioname, Scen.ScenarioName);
    117 		char buf[10];
    118 		sprintf(buf, "%02d", Scen.Scenario+1);
    119 		memcpy(&scenarioname[3], buf, 2);
    120 		return(scenarioname);
    121 	}
    122 
    123 #endif
    124 	char _filename[]="MSAA.WSA";
    125 	int house = (PlayerPtr->Class->House == HOUSE_USSR || PlayerPtr->Class->House == HOUSE_UKRAINE);
    126 
    127 	_filename[2] = house ? 'S' : 'A';
    128 	_filename[3] = Scen.Scenario + 'A';
    129 	PaletteClass mappalette;
    130 
    131 	int scenario = Scen.Scenario;
    132 	int selection;
    133 	static CDTimerClass<SystemTimerClass> timer;
    134 	int start = 0;
    135 	int count = 0;
    136 	int delay = 0;
    137 	int xspot = 0;
    138 	int yspot = 0;
    139 
    140 	void const * appear1 =  MFCD::Retrieve("MAPWIPE2.AUD");
    141 	void const * bleep11  = MFCD::Retrieve("BLEEP11.AUD");
    142 	void const * country4 = MFCD::Retrieve("MAPWIPE5.AUD");
    143 	void const * toney7 =   MFCD::Retrieve("TONEY7.AUD");
    144 	void const * bleep17  = MFCD::Retrieve("BLEEP17.AUD");
    145 
    146 	void const * scold1 =   MFCD::Retrieve("TONEY4.AUD");
    147 	void const * country1 = MFCD::Retrieve("TONEY10.AUD");
    148 
    149 #ifdef WIN32
    150 	GraphicBufferClass *pseudoseenbuff = new GraphicBufferClass(320, 200, (void*)NULL);
    151 #endif
    152 
    153 //	fixed oldvolume = Options.ScoreVolume;
    154 //	Options.Set_Score_Volume(fixed(4, 10));
    155 	Theme.Queue_Song(THEME_MAP);
    156 
    157 	void *anim = Open_Animation(_filename, NULL, 0L, (WSAOpenType)(WSA_OPEN_FROM_MEM | WSA_OPEN_TO_PAGE), mappalette);
    158 
    159 	Keyboard->Clear();
    160 	SeenPage.Clear();
    161 	mappalette.Set(FADE_PALETTE_FAST, Call_Back);
    162 
    163 #ifdef WIN32
    164 	pseudoseenbuff->Clear();
    165 	Animate_Frame(anim, *pseudoseenbuff, 1);
    166 	for(int x=0; x<256; x++) memset(&PaletteInterpolationTable[x][0],x,256);
    167 	CopyType = 1;
    168 	Interpolate_2X_Scale(pseudoseenbuff , &SeenBuff , 0);
    169 #else
    170 	HidPage.Clear();
    171 	Animate_Frame(anim, HidPage, 1);
    172 	HidPage.Blit(SeenPage);
    173 #endif
    174 
    175 
    176 	int frame = 1;
    177 	StreamLowImpact = true;
    178 #ifdef WIN32
    179 	Play_Sample(appear1, 255, Options.Normalize_Volume(170));
    180 #else
    181 	Play_Sample(appear1, 255, Options.Normalize_Volume(55));
    182 #endif
    183 	while (frame < Get_Animation_Frame_Count(anim)) {
    184 #ifdef WIN32
    185 		CopyType = 1;
    186 		Animate_Frame(anim, *pseudoseenbuff, frame++);
    187 		Interpolate_2X_Scale(pseudoseenbuff , &SeenBuff , NULL);
    188 		CopyType = 0;
    189 #else
    190 		Animate_Frame(anim, SeenPage, frame++);
    191 #endif
    192 		Call_Back_Delay(2);
    193 		switch(frame) {
    194 			case 16:
    195 #ifdef WIN32
    196 				Play_Sample(bleep11, 255, Options.Normalize_Volume(170));
    197 #else
    198 				Play_Sample(bleep11, 255, Options.Normalize_Volume(55));
    199 #endif
    200 				break;
    201 			case 30:
    202 #ifdef WIN32
    203 				Play_Sample(country4, 255, Options.Normalize_Volume(170));
    204 #else
    205 				Play_Sample(country4, 255, Options.Normalize_Volume(55));
    206 #endif
    207 				break;
    208 			case 51:
    209 #ifdef WIN32
    210 				Play_Sample(toney7, 255, Options.Normalize_Volume(170));
    211 #else
    212 				Play_Sample(toney7, 255, Options.Normalize_Volume(55));
    213 #endif
    214 				break;
    215 			case 61:
    216 #ifdef WIN32
    217 				Play_Sample(bleep17, 255, Options.Normalize_Volume(170));
    218 #else
    219 				Play_Sample(bleep17, 255, Options.Normalize_Volume(55));
    220 #endif
    221 				break;
    222 		}
    223 	}
    224 	StreamLowImpact = false;
    225 	Call_Back();
    226 	Close_Animation(anim);
    227 	Show_Mouse();
    228 	Keyboard->Clear();
    229 
    230 	bool done = 0;
    231 	MouseType shape = MOUSE_NORMAL;
    232 	while (!done) {
    233 #ifdef WIN32
    234 		/*
    235 		** If we have just received input focus again after running in the background then
    236 		** we need to redraw.
    237 		*/
    238 		if (AllSurfaces.SurfacesRestored) {
    239 			AllSurfaces.SurfacesRestored=FALSE;
    240 			CopyType = 1;
    241 			Interpolate_2X_Scale(pseudoseenbuff , &SeenBuff , NULL);
    242 			CopyType = 0;
    243 		}
    244 #endif
    245 		Cycle_Call_Back_Delay(1, mappalette);
    246 		int choice = Mouse_Over_Spot(house, scenario);
    247 		if (choice == -1) {
    248 			shape = MOUSE_NORMAL;
    249 		} else {
    250 			shape = MOUSE_CAN_ATTACK;
    251 		}
    252 
    253 		Set_Mouse(shape, start, count, delay, xspot, yspot);
    254 		if (timer == 0) {
    255 			frame++;
    256 			frame %= count;
    257 			timer = delay;
    258 			Set_Mouse_Cursor(xspot, yspot, Extract_Shape(MouseClass::MouseShapes, start + frame));
    259 		}
    260 		if (Keyboard->Check()) {
    261 			if ((Keyboard->Get() & 0x10FF) == KN_LMOUSE) {
    262 				if (choice != -1) {
    263 					done = 1;
    264 					selection = choice;
    265 #ifdef WIN32
    266 					Play_Sample(country1, 255, Options.Normalize_Volume(170));
    267 #else
    268 					Play_Sample(country1, 255, Options.Normalize_Volume(50));
    269 #endif
    270 				} else {
    271 #ifdef WIN32
    272 					Play_Sample(scold1, 255, Options.Normalize_Volume(170));
    273 #else
    274 					Play_Sample(scold1, 255, Options.Normalize_Volume(50));
    275 #endif
    276 				}
    277 			}
    278 		}
    279 	}
    280 
    281 	Hide_Mouse();
    282 
    283 	/*
    284 	** Restore the mouse to normal shape before leaving this routine.
    285 	*/
    286 	Set_Mouse(MOUSE_NORMAL, start, count, delay, xspot, yspot);
    287 	Set_Mouse_Cursor(xspot, yspot, Extract_Shape(MouseClass::MouseShapes, start));
    288 
    289 	Keyboard->Clear();
    290 //	BlackPalette.Set(FADE_PALETTE_SLOW, Call_Back);
    291 //	SeenPage.Clear();
    292 
    293 	Fancy_Text_Print(TXT_STAND_BY, 160 * RESFACTOR, 190 * RESFACTOR, GadgetClass::Get_Color_Scheme(), TBLACK, TPF_CENTER|TPF_6PT_GRAD|TPF_DROPSHADOW);
    294 
    295 	/*
    296 	**	Create the new scenario filename from the selection. The filename is
    297 	**	derived from the previous filename but it has the scenario number
    298 	**	incremented and the chosen variation set.
    299 	*/
    300 
    301 	//V.G. added so Ant Missions would progress
    302 	if(Scen.ScenarioName[2] == 'A'){
    303 	   int antnum = Scen.Scenario++;	
    304 	   if(antnum > 4) antnum = 1;	
    305 	   strcpy(scenarioname, antmission[antnum]);
    306 	}
    307 	else{
    308 		strcpy(scenarioname, Scen.ScenarioName);
    309 		char buf[10];
    310 		sprintf(buf, "%02d", Scen.Scenario+1);
    311 		memcpy(&scenarioname[3], buf, 2);
    312 		scenarioname[6] = 'A' + selection;
    313 	}
    314 	Theme.Fade_Out();
    315 //	Options.Set_Score_Volume(oldvolume);
    316 
    317 //	Scen.ScenVar = (ScenarioVarType)selection;
    318 //Mono_Printf("Chose variant %d  \n", selection);
    319 	return(scenarioname);
    320 #endif
    321 }
    322 
    323 int Mouse_Over_Spot(int house, int scenario)
    324 {
    325 	int retval = -1;
    326 	for (int selection = 0; selection < 3 && MapCoords[house][scenario][selection].x != -1; selection++) {
    327 		int mousex = Get_Mouse_X() / RESFACTOR;
    328 		int mousey = Get_Mouse_Y() / RESFACTOR;
    329 		if (mousex >= MapCoords[house][scenario][selection].x &&
    330 			 mousey >= MapCoords[house][scenario][selection].y &&
    331 			 mousex <= MapCoords[house][scenario][selection].x+11 &&
    332 			 mousey <= MapCoords[house][scenario][selection].y+9) {
    333 
    334 			retval = selection;
    335 			break;
    336 		}
    337 	}
    338 	return(retval);
    339 }
    340 void Cycle_Call_Back_Delay(int time, PaletteClass &pal)
    341 {
    342 	static CDTimerClass<SystemTimerClass> _ftimer;
    343 	static bool _up = false;
    344 	static int val = 255;
    345 
    346 	while(time--) {
    347 		/*
    348 		**	Process the fading white color.
    349 		*/
    350 		if (!_ftimer) {
    351 			_ftimer = TIMER_SECOND/6;
    352 
    353 			#define	STEP_RATE	20
    354 			if (_up) {
    355 				val += STEP_RATE;
    356 				if (val > 150) {
    357 					val = 150;
    358 					_up = false;
    359 				}
    360 			} else {
    361 				val -= STEP_RATE;
    362 				if (val < 0x20) {
    363 					val = 0x20;
    364 					_up = true;
    365 				}
    366 			}
    367 
    368 			/*
    369 			**	Set the pulse color as the proportional value between white and the
    370 			**	minimum value for pulsing.
    371 			*/
    372 			pal[254] = GamePalette[WHITE];
    373 			pal[254].Adjust(val, BlackColor);
    374 
    375 			pal.Set();
    376 		}
    377 		Call_Back_Delay(1);
    378 	}
    379 }
    380 
    381 void Set_Mouse(MouseType shape, int &start, int &count, int &delay, int &xspot, int &yspot)
    382 {
    383 	switch(shape) {
    384 		case MOUSE_NORMAL:
    385 			start = 0;
    386 			count = 1;
    387 			delay = 0;
    388 			xspot = 0;
    389 			yspot = 0;
    390 			break;
    391 		default:
    392 			start = 21;
    393 			count = 8;
    394 			delay = 4;
    395 			xspot = 14;
    396 			yspot = 11;
    397 			break;
    398 	}
    399 }