CnC_Remastered_Collection

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

EXPAND.CPP (12887B)


      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$ */
     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 : EXPAND.CPP                                                   *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : 11/03/95                                                     *
     28  *                                                                                             *
     29  *                  Last Update : November 3, 1995 [JLB]                                       *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     34 
     35 #include "function.h"
     36 
     37 #ifdef NEWMENU
     38 
     39 bool Expansion_Present(void)
     40 {
     41 	CCFileClass file("EXPAND.DAT");
     42 
     43 	return(file.Is_Available());
     44 }
     45 
     46 
     47 
     48 
     49 class EListClass : public ListClass
     50 {
     51 	public:
     52 		EListClass(int id, int x, int y, int w, int h, TextPrintType flags, void const * up, void const * down) :
     53 			ListClass(id, x, y, w, h, flags, up, down) {};
     54 
     55 	protected:
     56 		virtual void Draw_Entry(int index, int x, int y, int width, int selected);
     57 };
     58 
     59 
     60 void EListClass::Draw_Entry(int index, int x, int y, int width, int selected)
     61 {
     62 	if (TextFlags & TPF_6PT_GRAD) {
     63 		TextPrintType flags = TextFlags;
     64 
     65 		if (selected) {
     66 			flags = flags | TPF_BRIGHT_COLOR;
     67 			LogicPage->Fill_Rect (x, y, x + width - 1, y + LineHeight - 1, CC_GREEN_SHADOW);
     68 		} else {
     69 			if (!(flags & TPF_USE_GRAD_PAL)) {
     70 				flags = flags | TPF_MEDIUM_COLOR;
     71 			}
     72 		}
     73 
     74 		Conquer_Clip_Text_Print(List[index]+sizeof(int), x, y, CC_GREEN, TBLACK, flags, width, Tabs);
     75 
     76 	} else {
     77 		Conquer_Clip_Text_Print(List[index]+sizeof(int), x, y, (selected ? BLUE : WHITE), TBLACK, TextFlags, width, Tabs);
     78 	}
     79 }
     80 
     81 bool Expansion_Dialog(void)
     82 {
     83 	int factor			= (SeenBuff.Get_Width() == 320) ? 1 : 2;
     84 
     85 	int	option_width 	= 236 * factor;
     86 	int	option_height	= 162 * factor;
     87 	int	option_x			= (320*factor - option_width) /2;
     88 	int	option_y			= (200*factor - option_height) /2;
     89 
     90 	GadgetClass * buttons = NULL;
     91 
     92 	void const *up_button;
     93 	void const *down_button;
     94 
     95 	if (InMainLoop){
     96 		up_button = Hires_Retrieve("BTN-UP.SHP");
     97 		down_button = Hires_Retrieve("BTN-DN.SHP");
     98 	}else{
     99 		up_button = Hires_Retrieve("BTN-UP2.SHP");
    100 		down_button = Hires_Retrieve("BTN-DN2.SHP");
    101 	}
    102 
    103 	TextButtonClass ok(200, TXT_OK, TPF_6PT_GRAD|TPF_NOSHADOW, option_x+25*factor, option_y+option_height-15*factor);
    104 	TextButtonClass cancel(201, TXT_CANCEL, TPF_6PT_GRAD|TPF_NOSHADOW, option_x+option_width-50*factor, option_y+option_height-15*factor);
    105 	EListClass list(202, option_x+10*factor, option_y+20*factor, option_width-20*factor, option_height-40*factor, TPF_6PT_GRAD|TPF_NOSHADOW, up_button, down_button);
    106 
    107 	buttons = &ok;
    108 	cancel.Add(*buttons);
    109 	list.Add(*buttons);
    110 
    111 
    112 	/*
    113 	**	Add in all the expansion scenarios.
    114 	*/
    115 	char * sbuffer = (char*)_ShapeBuffer;
    116 	int index;
    117 	for (index = 20; index < 60; index++) {
    118 		char buffer[128];
    119 		CCFileClass file;
    120 
    121 		Set_Scenario_Name(buffer, index, SCEN_PLAYER_GDI, SCEN_DIR_EAST, SCEN_VAR_A);
    122 		strcat(buffer, ".INI");
    123 		file.Set_Name(buffer);
    124 		if (file.Is_Available()) {
    125 			file.Read(sbuffer, 1000);
    126 			sbuffer[1000] = '\r';
    127 			sbuffer[1000+1] = '\n';
    128 			sbuffer[1000+2] = '\0';
    129 
    130 			WWGetPrivateProfileString("Basic", "Name", "x", buffer, sizeof(buffer), sbuffer);
    131 			char * data = new char [strlen(buffer)+1+sizeof(int)+25];
    132 			*((int*)&data[0]) = index;
    133 			strcpy(&data[sizeof(int)], "GDI: ");
    134 			strcat(&data[sizeof(int)], buffer);
    135 			list.Add_Item(data);
    136 		}
    137 	}
    138 
    139 	for (index = 20; index < 60; index++) {
    140 		char buffer[128];
    141 		CCFileClass file;
    142 
    143 		Set_Scenario_Name(buffer, index, SCEN_PLAYER_NOD, SCEN_DIR_EAST, SCEN_VAR_A);
    144 		strcat(buffer, ".INI");
    145 		file.Set_Name(buffer);
    146 		if (file.Is_Available()) {
    147 			file.Read(sbuffer, 1000);
    148 			sbuffer[1000] = '\r';
    149 			sbuffer[1000+1] = '\n';
    150 			sbuffer[1000+2] = '\0';
    151 
    152 			WWGetPrivateProfileString("Basic", "Name", "x", buffer, sizeof(buffer), sbuffer);
    153 			char * data = new char [strlen(buffer)+1+sizeof(int)+25];
    154 			*((int*)&data[0]) = index;
    155 			strcpy(&data[sizeof(int)], "NOD: ");
    156 			strcat(&data[sizeof(int)], buffer);
    157 			list.Add_Item(data);
    158 		}
    159 	}
    160 
    161 	Set_Logic_Page(SeenBuff);
    162 	bool recalc = true;
    163 	bool display = true;
    164 	bool process = true;
    165 	bool okval = true;
    166 	while (process) {
    167 
    168 		Call_Back();
    169 
    170 		/*
    171 		** If we have just received input focus again after running in the background then
    172 		** we need to redraw.
    173 		*/
    174 		if (AllSurfaces.SurfacesRestored){
    175 			AllSurfaces.SurfacesRestored=FALSE;
    176 			display=TRUE;
    177 		}
    178 
    179 		if (display) {
    180 			display = false;
    181 
    182 			Hide_Mouse();
    183 
    184 			/*
    185 			**	Load the background picture.
    186 			*/
    187 			Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
    188 			Blit_Hid_Page_To_Seen_Buff();
    189 
    190 			Dialog_Box(option_x, option_y, option_width, option_height);
    191 			Draw_Caption(TXT_MISSION_DESCRIPTION, option_x, option_y, option_width);
    192 			buttons->Draw_All();
    193 			Show_Mouse();
    194 		}
    195 
    196 		KeyNumType input = buttons->Input();
    197 		switch (input) {
    198 			case KN_RETURN:
    199 			case 200|KN_BUTTON:
    200 				if (list.Current_Item()[sizeof(int)] == 'G') {
    201 					ScenPlayer = SCEN_PLAYER_GDI;
    202 				} else {
    203 					ScenPlayer = SCEN_PLAYER_NOD;
    204 				}
    205 				ScenDir = SCEN_DIR_EAST;
    206 				Whom = HOUSE_GOOD;
    207 				Scenario = *(int *)list.Current_Item();
    208 				process = false;
    209 				okval = true;
    210 				break;
    211 
    212 			case KN_ESC:
    213 			case 201|KN_BUTTON:
    214 				ScenPlayer = SCEN_PLAYER_GDI;
    215 				ScenDir = SCEN_DIR_EAST;
    216 				Whom = HOUSE_GOOD;
    217 				Scenario = *(int *)list.Current_Item();
    218 				process = false;
    219 				okval = false;
    220 				break;
    221 
    222 			default:
    223 				break;
    224 		}
    225 	}
    226 
    227 	/*
    228 	**	Free up the allocations for the text lines in the list box.
    229 	*/
    230 	for (index = 0; index < list.Count(); index++) {
    231 		delete [] (char *)list.Get_Item(index);
    232 	}
    233 
    234 	return(okval);
    235 }
    236 
    237 
    238 
    239 
    240 
    241 
    242 
    243 
    244 
    245 
    246 
    247 
    248 /***********************************************************************************************
    249  * Bonus_Dialog -- Asks the user which bonus mission he wants to play                          *
    250  *                                                                                             *
    251  *                                                                                             *
    252  *                                                                                             *
    253  * INPUT:    Nothing                                                                           *
    254  *                                                                                             *
    255  * OUTPUT:   Nothing                                                                           *
    256  *                                                                                             *
    257  * WARNINGS: None                                                                              *
    258  *                                                                                             *
    259  * HISTORY:                                                                                    *
    260  *    3/26/97 11:07AM ST : Created                                                             *
    261  *=============================================================================================*/
    262 bool Bonus_Dialog(void)
    263 {
    264 	int factor			= (SeenBuff.Get_Width() == 320) ? 1 : 2;
    265 
    266 	int	option_width 	= 236 * factor;
    267 	int	option_height	= 162 * factor;
    268 	int	option_x			= (320*factor - option_width) /2;
    269 	int	option_y			= (200*factor - option_height) /2;
    270 
    271 	GadgetClass * buttons = NULL;
    272 
    273 	void const *up_button;
    274 	void const *down_button;
    275 
    276 	if (InMainLoop){
    277 		up_button = Hires_Retrieve("BTN-UP.SHP");
    278 		down_button = Hires_Retrieve("BTN-DN.SHP");
    279 	}else{
    280 		up_button = Hires_Retrieve("BTN-UP2.SHP");
    281 		down_button = Hires_Retrieve("BTN-DN2.SHP");
    282 	}
    283 
    284 	TextButtonClass ok(200, TXT_OK, TPF_6PT_GRAD|TPF_NOSHADOW, option_x+25*factor, option_y+option_height-15*factor);
    285 	TextButtonClass cancel(201, TXT_CANCEL, TPF_6PT_GRAD|TPF_NOSHADOW, option_x+option_width-50*factor, option_y+option_height-15*factor);
    286 	EListClass list(202, option_x+10*factor, option_y+20*factor, option_width-20*factor, option_height-40*factor, TPF_6PT_GRAD|TPF_NOSHADOW, up_button, down_button);
    287 
    288 	buttons = &ok;
    289 	cancel.Add(*buttons);
    290 	list.Add(*buttons);
    291 
    292 
    293 	/*
    294 	**	Add in all the expansion scenarios.
    295 	*/
    296 	char * sbuffer = (char*)_ShapeBuffer;
    297 	int gdi_scen_names[3]={
    298 		TXT_BONUS_MISSION_1,
    299 		TXT_BONUS_MISSION_2,
    300 		TXT_BONUS_MISSION_3
    301 	};
    302 
    303 	int nod_scen_names[2]={
    304 		TXT_BONUS_MISSION_4,
    305 		TXT_BONUS_MISSION_5
    306 	};
    307 
    308 	int index;
    309 	for (index = 60; index < 63; index++) {
    310 		char buffer[128];
    311 		CCFileClass file;
    312 
    313 		Set_Scenario_Name(buffer, index, SCEN_PLAYER_GDI, SCEN_DIR_EAST, SCEN_VAR_A);
    314 		strcat(buffer, ".INI");
    315 		file.Set_Name(buffer);
    316 		if (file.Is_Available()) {
    317 			memcpy (buffer, Text_String (gdi_scen_names[index-60]), 1+strlen(Text_String (gdi_scen_names[index-60])));
    318 			char * data = new char [strlen(buffer)+1+sizeof(int)+25];
    319 			*((int*)&data[0]) = index;
    320 			strcpy(&data[sizeof(int)], "GDI: ");
    321 			strcat(&data[sizeof(int)], buffer);
    322 			list.Add_Item(data);
    323 		}
    324 	}
    325 
    326 	for (index = 60; index < 62; index++) {
    327 		char buffer[128];
    328 		CCFileClass file;
    329 
    330 		Set_Scenario_Name(buffer, index, SCEN_PLAYER_NOD, SCEN_DIR_EAST, SCEN_VAR_A);
    331 		strcat(buffer, ".INI");
    332 		file.Set_Name(buffer);
    333 		if (file.Is_Available()) {
    334 			memcpy (buffer, Text_String (nod_scen_names[index-60]), 1+strlen(Text_String (nod_scen_names[index-60])));
    335 			char * data = new char [strlen(buffer)+1+sizeof(int)+25];
    336 			*((int*)&data[0]) = index;
    337 			strcpy(&data[sizeof(int)], "NOD: ");
    338 			strcat(&data[sizeof(int)], buffer);
    339 			list.Add_Item(data);
    340 		}
    341 	}
    342 
    343 	Set_Logic_Page(SeenBuff);
    344 	bool recalc = true;
    345 	bool display = true;
    346 	bool process = true;
    347 	bool okval = true;
    348 	while (process) {
    349 
    350 		Call_Back();
    351 
    352 		/*
    353 		** If we have just received input focus again after running in the background then
    354 		** we need to redraw.
    355 		*/
    356 		if (AllSurfaces.SurfacesRestored){
    357 			AllSurfaces.SurfacesRestored=FALSE;
    358 			display=TRUE;
    359 		}
    360 
    361 		if (display) {
    362 			display = false;
    363 
    364 			Hide_Mouse();
    365 
    366 			/*
    367 			**	Load the background picture.
    368 			*/
    369 			Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
    370 			Blit_Hid_Page_To_Seen_Buff();
    371 
    372 			Dialog_Box(option_x, option_y, option_width, option_height);
    373 			Draw_Caption(TXT_BONUS_MISSIONS, option_x, option_y, option_width);
    374 			buttons->Draw_All();
    375 			Show_Mouse();
    376 		}
    377 
    378 		KeyNumType input = buttons->Input();
    379 		switch (input) {
    380 			case KN_RETURN:
    381 			case 200|KN_BUTTON:
    382 				if (list.Current_Item()[sizeof(int)] == 'G') {
    383 					ScenPlayer = SCEN_PLAYER_GDI;
    384 				} else {
    385 					ScenPlayer = SCEN_PLAYER_NOD;
    386 				}
    387 				ScenDir = SCEN_DIR_EAST;
    388 				Whom = HOUSE_GOOD;
    389 				Scenario = *(int *)list.Current_Item();
    390 				process = false;
    391 				okval = true;
    392 				break;
    393 
    394 			case KN_ESC:
    395 			case 201|KN_BUTTON:
    396 				ScenPlayer = SCEN_PLAYER_GDI;
    397 				ScenDir = SCEN_DIR_EAST;
    398 				Whom = HOUSE_GOOD;
    399 				Scenario = *(int *)list.Current_Item();
    400 				process = false;
    401 				okval = false;
    402 				break;
    403 
    404 			default:
    405 				break;
    406 		}
    407 	}
    408 
    409 	/*
    410 	**	Free up the allocations for the text lines in the list box.
    411 	*/
    412 	for (index = 0; index < list.Count(); index++) {
    413 		delete [] (char *)list.Get_Item(index);
    414 	}
    415 
    416 	return(okval);
    417 }
    418 
    419 
    420 #endif