SPECIAL.CPP 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  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. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/SPECIAL.CPP 1 3/03/97 10:25a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** 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 ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : SPECIAL.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 05/27/95 *
  26. * *
  27. * Last Update : August 20, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * Fetch_Difficulty -- Fetches the difficulty setting desired. *
  32. * Fetch_Password -- Prompts for a password entry from client. *
  33. * PWEditClass::Draw_Text -- Draws password style obscured text. *
  34. * Special_Dialog -- Handles the special options dialog. *
  35. * SpecialClass::Init -- Initialize the special class of options. *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #include "function.h"
  38. #ifdef WIN32
  39. #define OPTION_WIDTH 236*2
  40. #define OPTION_HEIGHT 162*2
  41. #define OPTION_X ((640 - OPTION_WIDTH) / 2)
  42. #define OPTION_Y (400 - OPTION_HEIGHT) / 2
  43. #else
  44. #define OPTION_WIDTH 236
  45. #define OPTION_HEIGHT 162
  46. #define OPTION_X ((320 - OPTION_WIDTH) / 2)
  47. #define OPTION_Y (200 - OPTION_HEIGHT) / 2
  48. #endif
  49. /***********************************************************************************************
  50. * SpecialClass::Init -- Initialize the special class of options. *
  51. * *
  52. * This initialization function is required (as opposed to using a constructor) because *
  53. * the SpecialClass is declared as part of a union. A union cannot have a member with a *
  54. * constructor. Other than this anomoly, the function serves the same purpose as a *
  55. * normal constructor. *
  56. * *
  57. * INPUT: none *
  58. * *
  59. * OUTPUT: none *
  60. * *
  61. * WARNINGS: none *
  62. * *
  63. * HISTORY: *
  64. * 08/20/1996 JLB : Created. *
  65. *=============================================================================================*/
  66. void SpecialClass::Init(void)
  67. {
  68. IsShadowGrow = false;
  69. IsSpeedBuild = false;
  70. IsFromInstall = false;
  71. IsCaptureTheFlag = false;
  72. IsInert = false;
  73. IsThreePoint = false;
  74. IsTGrowth = true;
  75. IsTSpread = true;
  76. UseMCVDeploy = false;
  77. IsMCVDeploy = false;
  78. IsEarlyWin = false;
  79. ModernBalance = false;
  80. }
  81. /***********************************************************************************************
  82. * Special_Dialog -- Handles the special options dialog. *
  83. * *
  84. * This dialog is used when setting the special game options. It does not appear in the *
  85. * final version of the game. *
  86. * *
  87. * INPUT: none *
  88. * *
  89. * OUTPUT: none *
  90. * *
  91. * WARNINGS: none *
  92. * *
  93. * HISTORY: *
  94. * 09/21/1995 JLB : Created. *
  95. *=============================================================================================*/
  96. void Special_Dialog(bool simple)
  97. {
  98. simple;
  99. #if (0)//PG
  100. SpecialClass oldspecial = Special;
  101. GadgetClass * buttons = NULL;
  102. static struct {
  103. int Description;
  104. int Setting;
  105. CheckBoxClass * Button;
  106. } _options[] = {
  107. {TXT_THREE_POINT, 0, 0},
  108. {TXT_SPEED_BUILD, 0, 0},
  109. };
  110. TextButtonClass ok(200, TXT_OK, TPF_BUTTON, OPTION_X+15*RESFACTOR, OPTION_Y+OPTION_HEIGHT-15*RESFACTOR);
  111. TextButtonClass cancel(201, TXT_CANCEL, TPF_BUTTON, OPTION_X+OPTION_WIDTH-60*RESFACTOR, OPTION_Y+OPTION_HEIGHT-15*RESFACTOR);
  112. buttons = &ok;
  113. cancel.Add(*buttons);
  114. for (int index = 0; index < sizeof(_options)/sizeof(_options[0]); index++) {
  115. _options[index].Button = new CheckBoxClass(100+index, OPTION_X+17*RESFACTOR, OPTION_Y+20*RESFACTOR+(index*10*RESFACTOR));
  116. if (_options[index].Button) {
  117. _options[index].Button->Add(*buttons);
  118. bool value = false;
  119. switch (_options[index].Description) {
  120. case TXT_THREE_POINT:
  121. value = Special.IsThreePoint;
  122. break;
  123. case TXT_SPEED_BUILD:
  124. value = Special.IsSpeedBuild;
  125. break;
  126. }
  127. _options[index].Setting = value;
  128. if (value) {
  129. _options[index].Button->Turn_On();
  130. } else {
  131. _options[index].Button->Turn_Off();
  132. }
  133. }
  134. }
  135. Map.Override_Mouse_Shape(MOUSE_NORMAL);
  136. Set_Logic_Page(SeenBuff);
  137. bool recalc = true;
  138. bool display = true;
  139. bool process = true;
  140. while (process) {
  141. if (Session.Type == GAME_NORMAL) {
  142. Call_Back();
  143. } else {
  144. if (Main_Loop()) {
  145. process = false;
  146. }
  147. }
  148. if (display) {
  149. display = false;
  150. Hide_Mouse();
  151. Dialog_Box(OPTION_X, OPTION_Y, OPTION_WIDTH, OPTION_HEIGHT);
  152. Draw_Caption(TXT_SPECIAL_OPTIONS, OPTION_X, OPTION_Y, OPTION_WIDTH);
  153. for (index = 0; index < sizeof(_options)/sizeof(_options[0]); index++) {
  154. Fancy_Text_Print(_options[index].Description, _options[index].Button->X+10*RESFACTOR, _options[index].Button->Y, GadgetClass::Get_Color_Scheme(), TBLACK, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_NOSHADOW);
  155. }
  156. buttons->Draw_All();
  157. Show_Mouse();
  158. }
  159. KeyNumType input = buttons->Input();
  160. switch (input) {
  161. case KN_ESC:
  162. case 200|KN_BUTTON:
  163. process = false;
  164. for (index = 0; index < sizeof(_options)/sizeof(_options[0]); index++) {
  165. bool setting = _options[index].Setting;
  166. switch (_options[index].Description) {
  167. case TXT_THREE_POINT:
  168. oldspecial.IsThreePoint = setting;
  169. break;
  170. case TXT_SPEED_BUILD:
  171. oldspecial.IsSpeedBuild = setting;
  172. break;
  173. }
  174. }
  175. if (!simple) {
  176. OutList.Add(EventClass(oldspecial));
  177. } else {
  178. Special = oldspecial;
  179. }
  180. break;
  181. case 201|KN_BUTTON:
  182. process = false;
  183. break;
  184. case KN_NONE:
  185. break;
  186. default:
  187. index = (input & ~KN_BUTTON) - 100;
  188. if ((unsigned)index < sizeof(_options)/sizeof(_options[0])) {
  189. _options[index].Setting = _options[index].Button->IsOn;
  190. }
  191. break;
  192. }
  193. }
  194. if (!simple) {
  195. Map.Revert_Mouse_Shape();
  196. HidPage.Clear();
  197. Map.Flag_To_Redraw(true);
  198. Map.Render();
  199. }
  200. #endif
  201. }
  202. /*
  203. ** Derived from the edit class, this class allows entry of passwords style text
  204. ** as an edit box. This style is characterized by "*" being displayed for every
  205. ** real character entered.
  206. */
  207. class PWEditClass : public EditClass
  208. {
  209. public:
  210. PWEditClass(int id, char * text, int max_len, TextPrintType flags, int x, int y, int w=-1, int h=-1) :
  211. EditClass(id, text, max_len, flags, x, y, w, h, ALPHANUMERIC) {};
  212. protected:
  213. virtual void Draw_Text(char const * text);
  214. };
  215. /***********************************************************************************************
  216. * PWEditClass::Draw_Text -- Draws password style obscured text. *
  217. * *
  218. * This routine is used by the password style edit box in order to display the entered *
  219. * text. The text will be displayed as asterisks instead of the actual characters the *
  220. * edit box may contain. This is necessary to obscure the password entry from glancing *
  221. * eyes. *
  222. * *
  223. * INPUT: text -- Pointer to the text that is to be rendered. *
  224. * *
  225. * OUTPUT: none *
  226. * *
  227. * WARNINGS: none *
  228. * *
  229. * HISTORY: *
  230. * 10/27/1995 JLB : Created. *
  231. *=============================================================================================*/
  232. void PWEditClass::Draw_Text(char const * text)
  233. {
  234. char buffer[80];
  235. memset(buffer, '\0', sizeof(buffer));
  236. memset(buffer, '*', strlen(text));
  237. if (FontPtr == GradFont6Ptr) {
  238. TextPrintType flags;
  239. if (Has_Focus()) {
  240. flags = TPF_BRIGHT_COLOR;
  241. } else {
  242. flags = (TextPrintType)0;
  243. }
  244. Conquer_Clip_Text_Print(buffer, X+1, Y+1, Color, TBLACK, TextFlags | flags, Width-2);
  245. if (Has_Focus() && (int)strlen(buffer) < MaxLength) {
  246. Conquer_Clip_Text_Print( "_", X+1+String_Pixel_Width(buffer), Y+1, Color, TBLACK, TextFlags | flags);
  247. }
  248. } else {
  249. Conquer_Clip_Text_Print(buffer, X+1, Y+1, Has_Focus() ?
  250. &ColorRemaps[PCOLOR_DIALOG_BLUE] : &ColorRemaps[PCOLOR_GREY],
  251. TBLACK, TextFlags, Width-2);
  252. if (Has_Focus() && (int)strlen(buffer) < MaxLength) {
  253. Conquer_Clip_Text_Print("_", X+1+String_Pixel_Width(buffer), Y+1,
  254. &ColorRemaps[PCOLOR_DIALOG_BLUE], TBLACK, TextFlags);
  255. }
  256. }
  257. }
  258. /***********************************************************************************************
  259. * Fetch_Password -- Prompts for a password entry from client. *
  260. * *
  261. * This routine will prompt for and return a password entry from the player. *
  262. * *
  263. * INPUT: caption -- The caption to use for the top of the prompt dialog. *
  264. * *
  265. * message -- The body of the message to display in the dialog. *
  266. * *
  267. * btext -- The button text to use to finish the dialog box entry. *
  268. * *
  269. * OUTPUT: Returns with a pointer to the password text entered. This pointer is valid *
  270. * only until the next time that this routine is called. *
  271. * *
  272. * WARNINGS: none *
  273. * *
  274. * HISTORY: *
  275. * 10/27/1995 JLB : Created. *
  276. *=============================================================================================*/
  277. #define BUFFSIZE (511)
  278. char const * Fetch_Password(int caption, int message, int btext)
  279. {
  280. char buffer[BUFFSIZE];
  281. bool process; // loop while true
  282. KeyNumType input; // user input
  283. bool pressed;
  284. int curbutton;
  285. TextButtonClass ok;
  286. if (btext == TXT_NONE) btext = TXT_OK;
  287. //PG_TO_FIX
  288. //Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, TPF_6PT_GRAD|TPF_NOSHADOW);
  289. /*
  290. ** Examine the optional button parameters. Fetch the width and starting
  291. ** characters for each.
  292. */
  293. int bwidth, bheight; // button width and height
  294. /*
  295. ** Build the button list.
  296. */
  297. bheight = FontHeight + FontYSpacing + 2*RESFACTOR;
  298. bwidth = max((String_Pixel_Width(Text_String(btext)) + 8*RESFACTOR), 30*RESFACTOR);
  299. /*
  300. ** Determine the dimensions of the text to be used for the dialog box.
  301. ** These dimensions will control how the dialog box looks.
  302. */
  303. buffer[BUFFSIZE-1] = 0;
  304. strncpy(buffer, Text_String(message), BUFFSIZE-1);
  305. //PG_TO_FIX
  306. //Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, TPF_6PT_GRAD|TPF_NOSHADOW);
  307. int width;
  308. int height;
  309. Format_Window_String(buffer, 255, width, height);
  310. width = max(width, 50*RESFACTOR);
  311. width += 40*RESFACTOR;
  312. height += (60+25)*RESFACTOR;
  313. int x = (SeenBuff.Get_Width() - width) / 2;
  314. int y = (SeenBuff.Get_Height() - height) / 2;
  315. /*
  316. ** Create the "ok" and password edit buttons.
  317. */
  318. TextButtonClass button1(1, btext, TPF_BUTTON,
  319. x + ((width - bwidth) >> 1), y + height - (bheight + 5*RESFACTOR), bwidth);
  320. static char pbuffer[45];
  321. memset(pbuffer, '\0', sizeof(pbuffer));
  322. int editx = x+26*RESFACTOR;
  323. int editwidth = (SeenBuff.Get_Width()/2 - editx) * 2;
  324. PWEditClass button2(2, &pbuffer[0], sizeof(pbuffer), TPF_6PT_GRAD|TPF_NOSHADOW, editx, (y+height)-35*RESFACTOR, editwidth, 10*RESFACTOR);
  325. TextButtonClass * buttonlist = 0;
  326. curbutton = 0;
  327. /*
  328. ** Add and initialize the buttons to the button list.
  329. */
  330. buttonlist = &button1;
  331. button2.Add(*buttonlist);
  332. /*
  333. ** Draw the background of the dialog.
  334. */
  335. Hide_Mouse();
  336. Set_Logic_Page(SeenBuff);
  337. Dialog_Box(x, y, width, height);
  338. Draw_Caption(caption, x, y, width);
  339. /*
  340. ** Draw the body of the message box.
  341. */
  342. Fancy_Text_Print(buffer, x + 20*RESFACTOR, y + 25*RESFACTOR, GadgetClass::Get_Color_Scheme(), TBLACK, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_NOSHADOW);
  343. /*
  344. ** Redraw the buttons.
  345. */
  346. if (buttonlist) {
  347. buttonlist->Draw_All();
  348. }
  349. Show_Mouse();
  350. /*
  351. ** Main Processing Loop.
  352. */
  353. process = true;
  354. pressed = false;
  355. bool first = true;
  356. while (process) {
  357. /*
  358. ** Invoke game callback.
  359. */
  360. Call_Back();
  361. #ifdef WIN32
  362. /*
  363. ** Handle possible surface loss due to a focus switch
  364. */
  365. if (AllSurfaces.SurfacesRestored) {
  366. AllSurfaces.SurfacesRestored=FALSE;
  367. process = false;
  368. break;
  369. }
  370. #endif //WIN32
  371. /*
  372. ** Fetch and process input.
  373. */
  374. input = buttonlist->Input();
  375. if (first) {
  376. button2.Set_Focus();
  377. button2.Flag_To_Redraw();
  378. first = false;
  379. }
  380. switch (input) {
  381. case (1|BUTTON_FLAG):
  382. process = false;
  383. break;
  384. case (KN_ESC):
  385. case (2|BUTTON_FLAG):
  386. process = false;
  387. break;
  388. case (KN_RETURN):
  389. process = false;
  390. break;
  391. default:
  392. break;
  393. }
  394. }
  395. return(pbuffer);
  396. }
  397. /***********************************************************************************************
  398. * Fetch_Difficulty -- Fetches the difficulty setting desired. *
  399. * *
  400. * This will display a dialog box that requests the player to specify a difficulty *
  401. * setting. *
  402. * *
  403. * INPUT: none *
  404. * *
  405. * OUTPUT: Returns with a difficulty setting of 0 for easiest and 4 for hardest. *
  406. * *
  407. * WARNINGS: none *
  408. * *
  409. * HISTORY: *
  410. * 08/13/1996 JLB : Created. *
  411. *=============================================================================================*/
  412. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  413. int Fetch_Difficulty(bool amath)
  414. #else
  415. int Fetch_Difficulty(void)
  416. #endif
  417. {
  418. int const w = 250 * RESFACTOR;
  419. int const h = 80 * RESFACTOR;
  420. int const x = ((320 * RESFACTOR)/2) - w/2;
  421. int const y = ((200 * RESFACTOR)/2) - h/2;
  422. int const bwidth = 30 * RESFACTOR;
  423. /*
  424. ** Fill the description buffer with the description text. Break
  425. ** the text into appropriate spacing.
  426. */
  427. char buffer[512];
  428. strncpy(buffer, Text_String(TXT_DIFFICULTY), sizeof(buffer)-1);
  429. buffer[sizeof(buffer)-1] = '\0';
  430. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  431. // If it's an aftermath mission, trim the sentence to get rid of the campaign stuff.
  432. if (amath) {
  433. int index=0;
  434. while (buffer[index] && buffer[index]!='.') index++;
  435. if (buffer[index]=='.') {
  436. buffer[index+1]=0;
  437. }
  438. }
  439. #endif
  440. //PG_TO_FIX
  441. //Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, TPF_6PT_GRAD|TPF_NOSHADOW);
  442. int width;
  443. int height;
  444. Format_Window_String(buffer, w-60*RESFACTOR, width, height);
  445. /*
  446. ** Create the OK button.
  447. */
  448. TextButtonClass okbutton(1, TXT_OK, TPF_BUTTON, (x+w) - (bwidth+20*RESFACTOR) , (y+h) - (18*RESFACTOR), bwidth);
  449. GadgetClass * buttonlist = &okbutton;
  450. /*
  451. ** Create the slider button.
  452. */
  453. SliderClass slider(2, x+20*RESFACTOR, y+h - 29*RESFACTOR, w - 40*RESFACTOR, 8*RESFACTOR, true);
  454. if (Rule.IsFineDifficulty) {
  455. slider.Set_Maximum(5);
  456. slider.Set_Value(2);
  457. } else {
  458. slider.Set_Maximum(3);
  459. slider.Set_Value(1);
  460. }
  461. slider.Add(*buttonlist);
  462. /*
  463. ** Main Processing Loop.
  464. */
  465. Set_Logic_Page(SeenBuff);
  466. bool redraw = true;
  467. bool process = true;
  468. while (process) {
  469. if (redraw) {
  470. redraw = false;
  471. /*
  472. ** Draw the background of the dialog.
  473. */
  474. Hide_Mouse();
  475. Dialog_Box(x, y, w, h);
  476. /*
  477. ** Draw the body of the message.
  478. */
  479. // Fancy_Text_Print(buffer, x + 20*RESFACTOR, y + 15*RESFACTOR, GadgetClass::Get_Color_Scheme(), TBLACK, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_NOSHADOW);
  480. Fancy_Text_Print(buffer, x + 20*RESFACTOR, y + 15*RESFACTOR, GadgetClass::Get_Color_Scheme(), TBLACK, TPF_6PT_GRAD|TPF_NOSHADOW);
  481. /*
  482. ** Display the descripton of the slider range.
  483. */
  484. Fancy_Text_Print(TXT_HARD, slider.X+slider.Width, slider.Y-9*RESFACTOR, GadgetClass::Get_Color_Scheme(), TBLACK, TPF_RIGHT|TPF_6PT_GRAD|TPF_DROPSHADOW);
  485. Fancy_Text_Print(TXT_EASY, slider.X, slider.Y-9*RESFACTOR, GadgetClass::Get_Color_Scheme(), TBLACK, TPF_6PT_GRAD|TPF_DROPSHADOW);
  486. Fancy_Text_Print(TXT_NORMAL, slider.X + (slider.Width/2), slider.Y-9*RESFACTOR, GadgetClass::Get_Color_Scheme(), TBLACK, TPF_CENTER|TPF_6PT_GRAD|TPF_DROPSHADOW);
  487. /*
  488. ** Redraw the buttons.
  489. */
  490. if (buttonlist) {
  491. buttonlist->Draw_All();
  492. }
  493. Show_Mouse();
  494. }
  495. /*
  496. ** Invoke game callback.
  497. */
  498. Call_Back();
  499. #ifdef WIN32
  500. /*
  501. ** Handle possible surface loss due to a focus switch
  502. */
  503. if (AllSurfaces.SurfacesRestored) {
  504. AllSurfaces.SurfacesRestored=FALSE;
  505. redraw = true;
  506. continue;
  507. }
  508. #endif //WIN32
  509. /*
  510. ** Fetch and process input.
  511. */
  512. KeyNumType input = buttonlist->Input();
  513. switch (input) {
  514. case KN_RETURN:
  515. case (1|BUTTON_FLAG):
  516. process = false;
  517. break;
  518. default:
  519. break;
  520. }
  521. }
  522. return(slider.Get_Value() * (Rule.IsFineDifficulty ? 1 : 2));
  523. }