MPLAYER.CPP 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: /CounterStrike/MPLAYER.CPP 3 3/13/97 2:06p Steve_tall $ */
  19. /***********************************************************************************************
  20. *** 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 ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : MPLAYER.CPP *
  26. * *
  27. * Programmer : Bill Randolph *
  28. * *
  29. * Start Date : April 14, 1995 *
  30. * *
  31. * Last Update : November 30, 1995 [BRR] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * Select_MPlayer_Game -- prompts user for NULL-Modem, Modem, or Network game *
  36. * Clear_Listbox -- clears the given list box *
  37. * Clear_Vector -- clears the given NodeNameType vector *
  38. * Computer_Message -- "sends" a message from the computer *
  39. * Garble_Message -- "garbles" a message *
  40. * Surrender_Dialog -- Prompts user for surrendering *
  41. * Abort_Dialog -- Prompts user for confirmation on aborting the mission *
  42. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  43. #include "function.h"
  44. extern bool Is_Mission_Counterstrike (char *file_name);
  45. #ifdef WOLAPI_INTEGRATION
  46. #include "WolStrng.h"
  47. #endif
  48. /***********************************************************************************************
  49. * Select_MPlayer_Game -- prompts user for NULL-Modem, Modem, or Network game *
  50. * *
  51. * INPUT: *
  52. * none. *
  53. * *
  54. * OUTPUT: *
  55. * GAME_NORMAL, GAME_MODEM, etc. *
  56. * *
  57. * WARNINGS: *
  58. * none. *
  59. * *
  60. * HISTORY: *
  61. * 02/14/1995 BR : Created. *
  62. *=============================================================================================*/
  63. GameType Select_MPlayer_Game (void)
  64. {
  65. //------------------------------------------------------------------------
  66. // Dialog & button dimensions
  67. //------------------------------------------------------------------------
  68. int d_dialog_w = 190 *RESFACTOR;
  69. #ifdef WOLAPI_INTEGRATION
  70. int d_dialog_h = 89 * RESFACTOR; // ajw
  71. int d_dialog_y = (((255 * RESFACTOR) - d_dialog_h) / 2);
  72. #else
  73. int d_dialog_h = 78 *RESFACTOR;
  74. int d_dialog_y = 90 * RESFACTOR;
  75. #endif
  76. int d_dialog_x = (((320*RESFACTOR) - d_dialog_w) / 2);
  77. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2);
  78. int d_txt6_h = 7 *RESFACTOR;
  79. int d_margin = 7 *RESFACTOR;
  80. int d_modemserial_w = 80 *RESFACTOR;
  81. int d_modemserial_h = 9 *RESFACTOR;
  82. int d_modemserial_x = d_dialog_cx - d_modemserial_w / 2;
  83. int d_modemserial_y = d_dialog_y + d_margin + d_txt6_h + d_margin;
  84. int d_skirmish_w = 80 *RESFACTOR;
  85. int d_skirmish_h = 9 *RESFACTOR;
  86. int d_skirmish_x = d_dialog_cx - d_skirmish_w / 2;
  87. int d_skirmish_y = d_modemserial_y + d_modemserial_h + 2*RESFACTOR;
  88. int d_ipx_w = 80 *RESFACTOR;
  89. int d_ipx_h = 9 *RESFACTOR;
  90. int d_ipx_x = d_dialog_cx - d_ipx_w / 2;
  91. int d_ipx_y = d_skirmish_y + d_skirmish_h + 2*RESFACTOR;
  92. #ifdef WOLAPI_INTEGRATION
  93. // ajw 7/2/98 - added button
  94. int d_wol_w = 80 * RESFACTOR;
  95. int d_wol_h = 9 * RESFACTOR;
  96. int d_wol_x = d_dialog_cx - d_wol_w / 2;
  97. int d_wol_y = d_ipx_y + d_ipx_h + 2*RESFACTOR;
  98. #endif
  99. int d_cancel_w = 60 *RESFACTOR;
  100. int d_cancel_h = 9 *RESFACTOR;
  101. int d_cancel_x = d_dialog_cx - d_cancel_w / 2;
  102. #ifdef WOLAPI_INTEGRATION
  103. int d_cancel_y = d_wol_y + d_wol_h + d_margin;
  104. #else
  105. int d_cancel_y = d_ipx_y + d_ipx_h + d_margin;
  106. #endif
  107. #ifdef WIN32
  108. GraphicBufferClass seen_buff_save(VisiblePage.Get_Width(), VisiblePage.Get_Height(), (void*)NULL);
  109. #endif
  110. //------------------------------------------------------------------------
  111. // Button enumerations:
  112. //------------------------------------------------------------------------
  113. enum {
  114. BUTTON_MODEMSERIAL = 100,
  115. BUTTON_SKIRMISH,
  116. BUTTON_IPX,
  117. #ifdef WOLAPI_INTEGRATION
  118. BUTTON_WOL, // ajw
  119. #endif
  120. BUTTON_CANCEL,
  121. #ifdef WOLAPI_INTEGRATION
  122. NUM_OF_BUTTONS = 5, // ajw
  123. #else
  124. NUM_OF_BUTTONS = 4,
  125. #endif
  126. };
  127. int num_of_buttons = NUM_OF_BUTTONS - (Ipx.Is_IPX() ? 0 : 1);
  128. //------------------------------------------------------------------------
  129. // Redraw values: in order from "top" to "bottom" layer of the dialog
  130. //------------------------------------------------------------------------
  131. typedef enum {
  132. REDRAW_NONE = 0,
  133. REDRAW_BUTTONS, // includes map interior & coord values
  134. REDRAW_BACKGROUND, // includes box, map bord, key, coord labels, btns
  135. REDRAW_ALL = REDRAW_BACKGROUND
  136. } RedrawType;
  137. //------------------------------------------------------------------------
  138. // Dialog variables:
  139. //------------------------------------------------------------------------
  140. KeyNumType input; // input from user
  141. bool process; // loop while true
  142. RedrawType display; // true = re-draw everything
  143. GameType retval; // return value
  144. int selection;
  145. bool pressed;
  146. int curbutton;
  147. TextButtonClass * buttons[NUM_OF_BUTTONS];
  148. //------------------------------------------------------------------------
  149. // Buttons
  150. //------------------------------------------------------------------------
  151. ControlClass * commands = NULL; // the button list
  152. //------------------------------------------------------------------------
  153. // If IPX not active then do only the modem serial dialog
  154. //------------------------------------------------------------------------
  155. // if ( !Ipx.Is_IPX() ) {
  156. // return( Select_Serial_Dialog() );
  157. // }
  158. TextButtonClass modemserialbtn (BUTTON_MODEMSERIAL, TXT_MODEM_SERIAL, TPF_BUTTON,
  159. d_modemserial_x, d_modemserial_y, d_modemserial_w, d_modemserial_h);
  160. TextButtonClass skirmishbtn (BUTTON_SKIRMISH, TXT_SKIRMISH, TPF_BUTTON,
  161. d_skirmish_x, d_skirmish_y, d_skirmish_w, d_skirmish_h);
  162. TextButtonClass ipxbtn (BUTTON_IPX, TXT_NETWORK, TPF_BUTTON,
  163. d_ipx_x, d_ipx_y, d_ipx_w, d_ipx_h);
  164. #ifdef WOLAPI_INTEGRATION
  165. // ajw
  166. TextButtonClass wolbtn(BUTTON_WOL, TXT_WOL_INTERNETBUTTON, TPF_BUTTON,
  167. d_wol_x, d_wol_y, d_wol_w, d_wol_h);
  168. #endif
  169. if(!Ipx.Is_IPX()) {
  170. d_cancel_y = d_ipx_y;
  171. d_dialog_h -= d_cancel_h;
  172. }
  173. TextButtonClass cancelbtn (BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON,
  174. d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
  175. //------------------------------------------------------------------------
  176. // Initialize
  177. //------------------------------------------------------------------------
  178. Set_Logic_Page(SeenBuff);
  179. #ifdef WIN32
  180. VisiblePage.Blit(seen_buff_save);
  181. #endif
  182. //------------------------------------------------------------------------
  183. // Create the list
  184. //------------------------------------------------------------------------
  185. commands = &modemserialbtn;
  186. skirmishbtn.Add_Tail(*commands);
  187. if(Ipx.Is_IPX()) {
  188. ipxbtn.Add_Tail(*commands);
  189. }
  190. #ifdef WOLAPI_INTEGRATION
  191. wolbtn.Add_Tail(*commands); // ajw
  192. #endif
  193. cancelbtn.Add_Tail(*commands);
  194. //------------------------------------------------------------------------
  195. // Fill array of button ptrs
  196. //------------------------------------------------------------------------
  197. curbutton = 0;
  198. buttons[0] = &modemserialbtn;
  199. buttons[1] = &skirmishbtn;
  200. if(Ipx.Is_IPX()) {
  201. buttons[2] = &ipxbtn;
  202. #ifdef WOLAPI_INTEGRATION
  203. buttons[3] = &wolbtn; // ajw
  204. buttons[4] = &cancelbtn;
  205. #else
  206. buttons[3] = &cancelbtn;
  207. #endif
  208. } else {
  209. #ifdef WOLAPI_INTEGRATION
  210. buttons[2] = &wolbtn; // ajw
  211. buttons[3] = &cancelbtn;
  212. #else
  213. buttons[2] = &cancelbtn;
  214. #endif
  215. }
  216. buttons[curbutton]->Turn_On();
  217. Keyboard->Clear();
  218. Fancy_Text_Print(TXT_NONE, 0, 0, GadgetClass::Get_Color_Scheme(), TBLACK,
  219. TPF_CENTER | TPF_TEXT);
  220. //------------------------------------------------------------------------
  221. // Main Processing Loop
  222. //------------------------------------------------------------------------
  223. display = REDRAW_ALL;
  224. process = true;
  225. pressed = false;
  226. while (process) {
  227. #ifdef WIN32
  228. /*
  229. ** If we have just received input focus again after running in the background then
  230. ** we need to redraw.
  231. */
  232. if (AllSurfaces.SurfacesRestored) {
  233. AllSurfaces.SurfacesRestored=FALSE;
  234. seen_buff_save.Blit(VisiblePage);
  235. display = REDRAW_ALL;
  236. }
  237. #endif
  238. //.....................................................................
  239. // Invoke game callback
  240. //.....................................................................
  241. Call_Back();
  242. //.....................................................................
  243. // Refresh display if needed
  244. //.....................................................................
  245. if (display) {
  246. Hide_Mouse();
  247. if (display >= REDRAW_BACKGROUND) {
  248. //...............................................................
  249. // Refresh the backdrop
  250. //...............................................................
  251. Load_Title_Page(true);
  252. CCPalette.Set();
  253. //...............................................................
  254. // Draw the background
  255. //...............................................................
  256. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  257. Draw_Caption (TXT_SELECT_MPLAYER_GAME, d_dialog_x, d_dialog_y, d_dialog_w);
  258. }
  259. //..................................................................
  260. // Redraw buttons
  261. //..................................................................
  262. if (display >= REDRAW_BUTTONS) {
  263. commands->Flag_List_To_Redraw();
  264. }
  265. Show_Mouse();
  266. display = REDRAW_NONE;
  267. }
  268. //.....................................................................
  269. // Get user input
  270. //.....................................................................
  271. input = commands->Input();
  272. //.....................................................................
  273. // Process input
  274. //.....................................................................
  275. switch (input) {
  276. case (BUTTON_MODEMSERIAL | KN_BUTTON):
  277. selection = BUTTON_MODEMSERIAL;
  278. pressed = true;
  279. break;
  280. case (BUTTON_SKIRMISH | KN_BUTTON):
  281. selection = BUTTON_SKIRMISH;
  282. pressed = true;
  283. break;
  284. case (BUTTON_IPX | KN_BUTTON):
  285. selection = BUTTON_IPX;
  286. pressed = true;
  287. break;
  288. #ifdef WOLAPI_INTEGRATION
  289. case (BUTTON_WOL | KN_BUTTON): // ajw
  290. selection = BUTTON_WOL;
  291. pressed = true;
  292. break;
  293. #endif
  294. case (KN_ESC):
  295. case (BUTTON_CANCEL | KN_BUTTON):
  296. selection = BUTTON_CANCEL;
  297. pressed = true;
  298. break;
  299. case KN_UP:
  300. buttons[curbutton]->Turn_Off();
  301. buttons[curbutton]->Flag_To_Redraw();
  302. curbutton--;
  303. if (curbutton < 0)
  304. curbutton = (num_of_buttons - 1);
  305. buttons[curbutton]->Turn_On();
  306. buttons[curbutton]->Flag_To_Redraw();
  307. break;
  308. case KN_DOWN:
  309. buttons[curbutton]->Turn_Off();
  310. buttons[curbutton]->Flag_To_Redraw();
  311. curbutton++;
  312. if (curbutton > (num_of_buttons - 1) )
  313. curbutton = 0;
  314. buttons[curbutton]->Turn_On();
  315. buttons[curbutton]->Flag_To_Redraw();
  316. break;
  317. case KN_RETURN:
  318. selection = curbutton + BUTTON_MODEMSERIAL;
  319. pressed = true;
  320. break;
  321. default:
  322. break;
  323. }
  324. if (pressed) {
  325. //..................................................................
  326. // to make sure the selection is correct in case they used the mouse
  327. //..................................................................
  328. buttons[curbutton]->Turn_Off();
  329. buttons[curbutton]->Flag_To_Redraw();
  330. curbutton = selection - BUTTON_MODEMSERIAL;
  331. if(selection == BUTTON_CANCEL && !Ipx.Is_IPX()) curbutton--;
  332. buttons[curbutton]->Turn_On();
  333. buttons[curbutton]->IsPressed = true;
  334. buttons[curbutton]->Draw_Me(true);
  335. switch (selection) {
  336. case (BUTTON_MODEMSERIAL):
  337. //............................................................
  338. // Pop up the modem/serial/com port dialog
  339. //............................................................
  340. retval = Select_Serial_Dialog();
  341. if (retval != GAME_NORMAL) {
  342. process = false;
  343. } else {
  344. buttons[curbutton]->IsPressed = false;
  345. display = REDRAW_ALL;
  346. }
  347. break;
  348. case (BUTTON_SKIRMISH):
  349. Session.Type = GAME_SKIRMISH;
  350. if (Com_Scenario_Dialog(true)) {
  351. retval = GAME_SKIRMISH;
  352. process = false;
  353. #ifdef FIXIT_VERSION_3
  354. bAftermathMultiplayer = Is_Aftermath_Installed();
  355. // ajw I'll bet this was needed before also...
  356. Session.ScenarioIsOfficial = Session.Scenarios[Session.Options.ScenarioIndex]->Get_Official();
  357. #endif
  358. } else {
  359. buttons[curbutton]->IsPressed = false;
  360. Session.Type = GAME_NORMAL;
  361. display = REDRAW_ALL;
  362. }
  363. break;
  364. case (BUTTON_IPX):
  365. retval = GAME_IPX;
  366. process = false;
  367. break;
  368. #ifdef WOLAPI_INTEGRATION
  369. case (BUTTON_WOL): // ajw
  370. retval = GAME_INTERNET;
  371. process = false;
  372. break;
  373. #endif
  374. case (BUTTON_CANCEL):
  375. retval = GAME_NORMAL;
  376. process = false;
  377. break;
  378. }
  379. pressed = false;
  380. }
  381. }
  382. return(retval);
  383. } /* end of Select_MPlayer_Game */
  384. /***************************************************************************
  385. * Clear_Listbox -- clears the given list box *
  386. * *
  387. * This routine assumes the items in the given list box are character *
  388. * buffers; it deletes each item in the list, then clears the list. *
  389. * *
  390. * INPUT: *
  391. * list ptr to listbox *
  392. * *
  393. * OUTPUT: *
  394. * none. *
  395. * *
  396. * WARNINGS: *
  397. * none. *
  398. * *
  399. * HISTORY: *
  400. * 11/29/1995 BRR : Created. *
  401. *=========================================================================*/
  402. void Clear_Listbox(ListClass * list)
  403. {
  404. char * item;
  405. //------------------------------------------------------------------------
  406. // Clear the list box
  407. //------------------------------------------------------------------------
  408. while (list->Count()) {
  409. item = (char *)(list->Get_Item(0));
  410. list->Remove_Item(item);
  411. delete [] item;
  412. }
  413. list->Flag_To_Redraw();
  414. } // end of Clear_Listbox
  415. /***************************************************************************
  416. * Clear_Vector -- clears the given NodeNameType vector *
  417. * *
  418. * INPUT: *
  419. * vector ptr to vector to clear *
  420. * *
  421. * OUTPUT: *
  422. * none. *
  423. * *
  424. * WARNINGS: *
  425. * none. *
  426. * *
  427. * HISTORY: *
  428. * 11/29/1995 BRR : Created. *
  429. *=========================================================================*/
  430. void Clear_Vector(DynamicVectorClass <NodeNameType *> * vector)
  431. {
  432. int i;
  433. //------------------------------------------------------------------------
  434. // Clear the 'Players' Vector
  435. //------------------------------------------------------------------------
  436. for (i = 0; i < vector->Count(); i++) {
  437. delete (*vector)[i];
  438. }
  439. vector->Clear();
  440. } // end of Clear_Vector
  441. /***************************************************************************
  442. * Computer_Message -- "sends" a message from the computer *
  443. * *
  444. * INPUT: *
  445. * none. *
  446. * *
  447. * OUTPUT: *
  448. * none. *
  449. * *
  450. * WARNINGS: *
  451. * none. *
  452. * *
  453. * HISTORY: *
  454. * 06/06/1995 BRR : Created. *
  455. *=========================================================================*/
  456. void Computer_Message(void)
  457. {
  458. #ifdef NEVER
  459. int color;
  460. HousesType house;
  461. HouseClass * ptr;
  462. //------------------------------------------------------------------------
  463. // Find the computer house that the message will be from
  464. //------------------------------------------------------------------------
  465. for (house = HOUSE_MULTI1; house < (HOUSE_MULTI1 + Session.MaxPlayers); house++) {
  466. ptr = HouseClass::As_Pointer(house);
  467. if (!ptr || ptr->IsHuman || ptr->IsDefeated) {
  468. continue;
  469. }
  470. //.....................................................................
  471. // Decode this house's color
  472. //.....................................................................
  473. color = ptr->RemapColor;
  474. //.....................................................................
  475. // We now have a 1/4 chance of echoing one of the human players'
  476. // messages back.
  477. //.....................................................................
  478. if (Percent_Chance(25)) {
  479. //..................................................................
  480. // Now we have a 1/3 chance of garbling the human message.
  481. //..................................................................
  482. if (Percent_Chance(33)) {
  483. Garble_Message(Session.LastMessage);
  484. }
  485. //..................................................................
  486. // Only add the message if there is one to add.
  487. //..................................................................
  488. if (strlen(Session.LastMessage)) {
  489. Session.Messages.Add_Message(Text_String(TXT_COMPUTER), 0,
  490. Session.LastMessage,
  491. color, TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, Rule.MessageDelay * TICKS_PER_MINUTE);
  492. }
  493. }
  494. else {
  495. Session.Messages.Add_Message(Text_String(TXT_COMPUTER), 0,
  496. Text_String(TXT_COMP_MSG1 + Random_Pick(0, 12)),
  497. color, TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, Rule.MessageDelay * TICKS_PER_MINUTE);
  498. }
  499. return;
  500. }
  501. #endif
  502. } /* end of Computer_Message */
  503. #ifdef NEVER
  504. /***************************************************************************
  505. * Garble_Message -- "garbles" a message *
  506. * *
  507. * INPUT: *
  508. * buf buffer to garble; stores output message *
  509. * *
  510. * OUTPUT: *
  511. * none. *
  512. * *
  513. * WARNINGS: *
  514. * none. *
  515. * *
  516. * HISTORY: *
  517. * 06/06/1995 BRR : Created. *
  518. *=========================================================================*/
  519. static void Garble_Message(char * buf)
  520. {
  521. char txt[80];
  522. char punct[20]; // for punctuation
  523. char * p; // working ptr
  524. int numwords; // # words in the phrase
  525. char * words[40]; // ptrs to various words in the phrase
  526. int i,j;
  527. //------------------------------------------------------------------------
  528. // Pull off any trailing punctuation
  529. //------------------------------------------------------------------------
  530. p = buf + strlen(buf) - 1;
  531. while (1) {
  532. if (p < buf)
  533. break;
  534. if (p[0]=='!' || p[0]=='.' || p[0]=='?') {
  535. p--;
  536. }
  537. else {
  538. p++;
  539. break;
  540. }
  541. if (strlen(p) >= (sizeof(punct) - 1) ) {
  542. break;
  543. }
  544. }
  545. strcpy (punct, p);
  546. p[0] = 0;
  547. for (i = 0; i < 40; i++) {
  548. words[i] = NULL;
  549. }
  550. //------------------------------------------------------------------------
  551. // Copy the original buffer
  552. //------------------------------------------------------------------------
  553. strcpy(txt, buf);
  554. //------------------------------------------------------------------------
  555. // Split it up into words
  556. //------------------------------------------------------------------------
  557. p = strtok (txt, " ");
  558. numwords = 0;
  559. while (p) {
  560. words[numwords] = p;
  561. numwords++;
  562. p = strtok (NULL, " ");
  563. }
  564. //------------------------------------------------------------------------
  565. // Now randomly put the words back. Don't use the real random-number
  566. // generator, since different machines will have different LastMessage's,
  567. // and will go out of sync.
  568. //------------------------------------------------------------------------
  569. buf[0] = 0;
  570. for (i = 0; i < numwords; i++) {
  571. j = Sim_IRandom(0, numwords);
  572. if (words[j] == NULL) { // this word has been used already
  573. i--;
  574. continue;
  575. }
  576. strcat(buf, words[j]);
  577. words[j] = NULL;
  578. if (i < numwords-1)
  579. strcat(buf, " ");
  580. }
  581. strcat(buf, punct);
  582. } /* end of Garble_Message */
  583. #endif
  584. /***************************************************************************
  585. * Surrender_Dialog -- Prompts user for surrendering *
  586. * *
  587. * INPUT: *
  588. * none. *
  589. * *
  590. * OUTPUT: *
  591. * 0 = user cancels, 1 = user wants to surrender. *
  592. * *
  593. * WARNINGS: *
  594. * none. *
  595. * *
  596. * HISTORY: *
  597. * 07/05/1995 BRR : Created. *
  598. *=========================================================================*/
  599. #ifdef FIXIT_VERSION_3 // Stalemate games.
  600. int Surrender_Dialog(int text)
  601. {
  602. return Surrender_Dialog( Text_String( text ) );
  603. }
  604. #endif
  605. #ifdef FIXIT_VERSION_3 // Stalemate games.
  606. int Surrender_Dialog(const char* text)
  607. #else
  608. int Surrender_Dialog(int text)
  609. #endif
  610. {
  611. //------------------------------------------------------------------------
  612. // Dialog & button dimensions
  613. //------------------------------------------------------------------------
  614. enum {
  615. D_DIALOG_W = 240*RESFACTOR, // dialog width
  616. D_DIALOG_H = 63*RESFACTOR, // dialog height
  617. D_DIALOG_X = ((320*RESFACTOR - D_DIALOG_W) / 2),// centered x-coord
  618. D_DIALOG_Y = ((200*RESFACTOR - D_DIALOG_H) / 2),// centered y-coord
  619. D_DIALOG_CX = D_DIALOG_X + (D_DIALOG_W / 2), // coord of x-center
  620. D_TXT6_H = 7*RESFACTOR, // ht of 6-pt text
  621. D_MARGIN = 5*RESFACTOR, // margin width/height
  622. D_TOPMARGIN = 20*RESFACTOR, // top margin
  623. D_OK_W = 45*RESFACTOR, // OK width
  624. D_OK_H = 9*RESFACTOR, // OK height
  625. D_OK_X = D_DIALOG_CX - D_OK_W - 5*RESFACTOR, // OK x
  626. D_OK_Y = D_DIALOG_Y + D_DIALOG_H - D_OK_H - D_MARGIN*2, // OK y
  627. D_CANCEL_W = 45*RESFACTOR, // Cancel width
  628. D_CANCEL_H = 9*RESFACTOR, // Cancel height
  629. D_CANCEL_X = D_DIALOG_CX + 5*RESFACTOR, // Cancel x
  630. D_CANCEL_Y = D_DIALOG_Y + D_DIALOG_H - D_CANCEL_H - D_MARGIN*2, // Cancel y
  631. };
  632. //------------------------------------------------------------------------
  633. // Button enumerations
  634. //------------------------------------------------------------------------
  635. enum {
  636. BUTTON_OK = 100,
  637. BUTTON_CANCEL,
  638. };
  639. //------------------------------------------------------------------------
  640. // Buttons
  641. //------------------------------------------------------------------------
  642. ControlClass * commands = NULL; // the button list
  643. TextButtonClass okbtn(BUTTON_OK, TXT_OK, TPF_BUTTON, D_OK_X, D_OK_Y, D_OK_W, D_OK_H);
  644. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON, D_CANCEL_X, D_CANCEL_Y, D_CANCEL_W, D_CANCEL_H);
  645. int curbutton;
  646. TextButtonClass * buttons[2];
  647. curbutton = 0;
  648. //------------------------------------------------------------------------
  649. // Initialize
  650. //------------------------------------------------------------------------
  651. Set_Logic_Page(SeenBuff);
  652. //------------------------------------------------------------------------
  653. // Create the button list
  654. //------------------------------------------------------------------------
  655. commands = &okbtn;
  656. cancelbtn.Add_Tail(*commands);
  657. buttons[0] = &okbtn;
  658. buttons[1] = &cancelbtn;
  659. buttons[curbutton]->Turn_On();
  660. //------------------------------------------------------------------------
  661. // Main Processing Loop
  662. //------------------------------------------------------------------------
  663. int retcode = 0;
  664. bool display = true;
  665. bool process = true;
  666. while (process) {
  667. //.....................................................................
  668. // Invoke game callback
  669. //.....................................................................
  670. if (Session.Type != GAME_SKIRMISH) {
  671. if (Main_Loop()) {
  672. retcode = 0;
  673. process = false;
  674. }
  675. }
  676. //.....................................................................
  677. // Refresh display if needed
  678. //.....................................................................
  679. if (display) {
  680. display = false;
  681. //..................................................................
  682. // Display the dialog box
  683. //..................................................................
  684. Hide_Mouse();
  685. Dialog_Box(D_DIALOG_X, D_DIALOG_Y, D_DIALOG_W, D_DIALOG_H);
  686. Draw_Caption(TXT_NONE, D_DIALOG_X, D_DIALOG_Y, D_DIALOG_W);
  687. //...............................................................
  688. // Draw the captions
  689. //...............................................................
  690. #ifdef FIXIT_VERSION_3 // Stalemate games.
  691. Fancy_Text_Print(text,
  692. D_DIALOG_CX, D_DIALOG_Y + D_TOPMARGIN,
  693. GadgetClass::Get_Color_Scheme(), TBLACK,
  694. TPF_CENTER | TPF_TEXT);
  695. #else
  696. Fancy_Text_Print(Text_String(text),
  697. D_DIALOG_CX, D_DIALOG_Y + D_TOPMARGIN,
  698. GadgetClass::Get_Color_Scheme(), TBLACK,
  699. TPF_CENTER | TPF_TEXT);
  700. #endif
  701. //..................................................................
  702. // Redraw the buttons
  703. //..................................................................
  704. commands->Flag_List_To_Redraw();
  705. Show_Mouse();
  706. }
  707. //.....................................................................
  708. // Get user input
  709. //.....................................................................
  710. KeyNumType input = commands->Input();
  711. //.....................................................................
  712. // Process input
  713. //.....................................................................
  714. switch (input) {
  715. case (BUTTON_OK | KN_BUTTON):
  716. retcode = 1;
  717. process = false;
  718. break;
  719. case (BUTTON_CANCEL | KN_BUTTON):
  720. retcode = 0;
  721. process = false;
  722. break;
  723. case (KN_RETURN):
  724. if (curbutton == 0) {
  725. retcode = 1;
  726. } else {
  727. retcode = 0;
  728. }
  729. process = false;
  730. break;
  731. case (KN_ESC):
  732. retcode = 0;
  733. process = false;
  734. break;
  735. case (KN_RIGHT):
  736. buttons[curbutton]->Turn_Off();
  737. curbutton++;
  738. if (curbutton > 1) {
  739. curbutton = 0;
  740. }
  741. buttons[curbutton]->Turn_On();
  742. break;
  743. case (KN_LEFT):
  744. buttons[curbutton]->Turn_Off();
  745. curbutton--;
  746. if (curbutton < 0) {
  747. curbutton = 1;
  748. }
  749. buttons[curbutton]->Turn_On();
  750. break;
  751. default:
  752. break;
  753. }
  754. }
  755. //------------------------------------------------------------------------
  756. // Redraw the display
  757. //------------------------------------------------------------------------
  758. HidPage.Clear();
  759. Map.Flag_To_Redraw(true);
  760. Map.Render();
  761. return (retcode);
  762. }
  763. /***************************************************************************
  764. * Abort_Dialog -- Prompts user for confirmation on aborting the mission *
  765. * *
  766. * INPUT: *
  767. * none. *
  768. * *
  769. * OUTPUT: *
  770. * 1 = user confirms abort, 0 = user cancels *
  771. * *
  772. * WARNINGS: *
  773. * none. *
  774. * *
  775. * HISTORY: *
  776. * 07/05/1995 BRR : Created. *
  777. *=========================================================================*/
  778. int Abort_Dialog(void)
  779. {
  780. //------------------------------------------------------------------------
  781. // Dialog & button dimensions
  782. //------------------------------------------------------------------------
  783. enum {
  784. D_DIALOG_W = 170*RESFACTOR, // dialog width
  785. D_DIALOG_H = 63*RESFACTOR, // dialog height
  786. D_DIALOG_X = ((320*RESFACTOR - D_DIALOG_W) / 2),// centered x-coord
  787. D_DIALOG_Y = ((200*RESFACTOR - D_DIALOG_H) / 2),// centered y-coord
  788. D_DIALOG_CX = D_DIALOG_X + (D_DIALOG_W / 2), // coord of x-center
  789. D_TXT6_H = 7*RESFACTOR, // ht of 6-pt text
  790. D_MARGIN = 5*RESFACTOR, // margin width/height
  791. D_TOPMARGIN = 20*RESFACTOR, // top margin
  792. D_YES_W = 45*RESFACTOR, // YES width
  793. D_YES_H = 9*RESFACTOR, // YES height
  794. D_YES_X = D_DIALOG_CX - D_YES_W - 5*RESFACTOR, // YES x
  795. D_YES_Y = D_DIALOG_Y + D_DIALOG_H - D_YES_H - D_MARGIN*2, // YES y
  796. D_NO_W = 45*RESFACTOR, // Cancel width
  797. D_NO_H = 9*RESFACTOR, // Cancel height
  798. D_NO_X = D_DIALOG_CX + 5*RESFACTOR, // Cancel x
  799. D_NO_Y = D_DIALOG_Y + D_DIALOG_H - D_NO_H - D_MARGIN*2, // Cancel y
  800. };
  801. //------------------------------------------------------------------------
  802. // Button enumerations
  803. //------------------------------------------------------------------------
  804. enum {
  805. BUTTON_YES = 100,
  806. BUTTON_NO,
  807. };
  808. //------------------------------------------------------------------------
  809. // Buttons
  810. //------------------------------------------------------------------------
  811. ControlClass * commands = NULL; // the button list
  812. TextButtonClass yesbtn(BUTTON_YES, TXT_YES, TPF_BUTTON, D_YES_X, D_YES_Y, D_YES_W, D_YES_H);
  813. TextButtonClass nobtn(BUTTON_NO, TXT_NO, TPF_BUTTON, D_NO_X, D_NO_Y, D_NO_W, D_NO_H);
  814. int curbutton;
  815. TextButtonClass * buttons[2];
  816. curbutton = 0;
  817. //------------------------------------------------------------------------
  818. // Initialize
  819. //------------------------------------------------------------------------
  820. Set_Logic_Page(SeenBuff);
  821. //------------------------------------------------------------------------
  822. // Create the button list
  823. //------------------------------------------------------------------------
  824. commands = &yesbtn;
  825. nobtn.Add_Tail(*commands);
  826. buttons[0] = &yesbtn;
  827. buttons[1] = &nobtn;
  828. buttons[curbutton]->Turn_On();
  829. //------------------------------------------------------------------------
  830. // Main Processing Loop
  831. //------------------------------------------------------------------------
  832. int retcode = 0;
  833. bool display = true;
  834. bool process = true;
  835. while (process) {
  836. //.....................................................................
  837. // Invoke game callback
  838. //.....................................................................
  839. if (Session.Type != GAME_SKIRMISH) {
  840. if (Main_Loop()) {
  841. retcode = 0;
  842. process = false;
  843. }
  844. }
  845. //.....................................................................
  846. // Refresh display if needed
  847. //.....................................................................
  848. if (display) {
  849. display = false;
  850. //..................................................................
  851. // Display the dialog box
  852. //..................................................................
  853. Hide_Mouse();
  854. Dialog_Box(D_DIALOG_X, D_DIALOG_Y, D_DIALOG_W, D_DIALOG_H);
  855. Draw_Caption(TXT_NONE, D_DIALOG_X, D_DIALOG_Y, D_DIALOG_W);
  856. //...............................................................
  857. // Draw the captions
  858. //...............................................................
  859. Fancy_Text_Print(Text_String(TXT_CONFIRM_EXIT),
  860. D_DIALOG_CX, D_DIALOG_Y + D_TOPMARGIN,
  861. GadgetClass::Get_Color_Scheme(), TBLACK,
  862. TPF_CENTER | TPF_TEXT);
  863. //..................................................................
  864. // Redraw the buttons
  865. //..................................................................
  866. commands->Flag_List_To_Redraw();
  867. Show_Mouse();
  868. }
  869. //.....................................................................
  870. // Get user input
  871. //.....................................................................
  872. KeyNumType input = commands->Input();
  873. //.....................................................................
  874. // Process input
  875. //.....................................................................
  876. switch (input) {
  877. case (BUTTON_YES | KN_BUTTON):
  878. retcode = 1;
  879. process = false;
  880. break;
  881. case (BUTTON_NO | KN_BUTTON):
  882. retcode = 0;
  883. process = false;
  884. break;
  885. case (KN_RETURN):
  886. if (curbutton == 0) {
  887. retcode = 1;
  888. } else {
  889. retcode = 0;
  890. }
  891. process = false;
  892. break;
  893. case (KN_ESC):
  894. retcode = 0;
  895. process = false;
  896. break;
  897. case (KN_RIGHT):
  898. buttons[curbutton]->Turn_Off();
  899. curbutton++;
  900. if (curbutton > 1) {
  901. curbutton = 0;
  902. }
  903. buttons[curbutton]->Turn_On();
  904. break;
  905. case (KN_LEFT):
  906. buttons[curbutton]->Turn_Off();
  907. curbutton--;
  908. if (curbutton < 0) {
  909. curbutton = 1;
  910. }
  911. buttons[curbutton]->Turn_On();
  912. break;
  913. default:
  914. break;
  915. }
  916. }
  917. //------------------------------------------------------------------------
  918. // Redraw the display
  919. //------------------------------------------------------------------------
  920. HidPage.Clear();
  921. Map.Flag_To_Redraw(true);
  922. Map.Render();
  923. return (retcode);
  924. }
  925. #if(TEN)
  926. /***************************************************************************
  927. * Read_TEN_Game_Options -- reads multiplayer game options from disk *
  928. * *
  929. * This routine is used for multiplayer games which read the game options *
  930. * from disk, rather than through a connection dialog. *
  931. * *
  932. * INPUT: *
  933. * none. *
  934. * *
  935. * OUTPUT: *
  936. * 1 = OK, 0 = error *
  937. * *
  938. * WARNINGS: *
  939. * none. *
  940. * *
  941. * HISTORY: *
  942. * 01/11/1996 BRR : Created. *
  943. *=========================================================================*/
  944. int Read_TEN_Game_Options(void)
  945. {
  946. INIClass ini;
  947. if (!ini.Load(RawFileClass(Session.OptionsFile))) {
  948. return (0);
  949. }
  950. ini.Get_String("Options", "Handle", "Noname", Session.Handle,
  951. sizeof(Session.Handle));
  952. if (Session.TenPlayerID == -1) {
  953. return (0);
  954. }
  955. Session.ColorIdx = (PlayerColorType)Session.TenPlayerID;
  956. Session.House = (HousesType)
  957. ((int)HOUSE_USSR + ini.Get_Int("Options", "Side", 0));
  958. Session.Options.Credits = ini.Get_Int("Options", "Credits", 3000);
  959. Session.Options.Bases = ini.Get_Int("Options", "Bases", 1);
  960. Session.Options.Tiberium = ini.Get_Int("Options", "Tiberium", 1);
  961. Session.Options.Goodies = ini.Get_Int("Options", "Crates", 1);
  962. Special.IsShadowGrow = ini.Get_Int ("Options", "Shadow", 0);
  963. BuildLevel = ini.Get_Int("Options", "BuildLevel", 3);
  964. Session.Options.UnitCount = ini.Get_Int("Options", "UnitCount", 5);
  965. Seed = ini.Get_Int("Options", "Seed", 0);
  966. Special.IsCaptureTheFlag = ini.Get_Int("Options", "CapFlag", 0);
  967. Session.Options.AIPlayers = ini.Get_Int("Options", "AI", 0);
  968. Session.NumPlayers = ini.Get_Int("Options", "Players", 2);
  969. if (Session.Options.AIPlayers){
  970. Session.Options.Ghosts = 1;
  971. }
  972. if (Session.Options.Tiberium) {
  973. Special.IsTGrowth = 1;
  974. Special.IsTSpread = 1;
  975. } else {
  976. Special.IsTGrowth = 0;
  977. Special.IsTSpread = 0;
  978. }
  979. /*
  980. ** Read the scenario name from the .INI and try to match it with a scenario file in our list.
  981. */
  982. ini.Get_String("Options", "Scenario", "Black Acres",
  983. Session.Options.ScenarioDescription,
  984. sizeof (Session.Options.ScenarioDescription));
  985. Session.Options.ScenarioIndex = -1;
  986. for (int i = 0; i < Session.Scenarios.Count(); i++) {
  987. if (!strcmp (Session.Scenarios[i]->Description(),
  988. Session.Options.ScenarioDescription) ) {
  989. Session.Options.ScenarioIndex = i;
  990. strcpy(Session.ScenarioFileName, Session.Scenarios[i]->Get_Filename());
  991. strcpy(Scen.ScenarioName, Session.Scenarios[i]->Get_Filename());
  992. break;
  993. }
  994. }
  995. if (Session.Options.ScenarioIndex == -1) {
  996. WWMessageBox().Process("Scenario not found!");
  997. //Prog_End();
  998. Emergency_Exit(0);
  999. }
  1000. Options.GameSpeed = 0;
  1001. Session.MaxAhead = ini.Get_Int("Timing", "MaxAhead", 9);
  1002. Session.FrameSendRate = ini.Get_Int("Timing", "SendRate", 3);
  1003. Session.NetResponseTime = ini.Get_Int("Timing","Latency",600);
  1004. return (1);
  1005. }
  1006. #endif // TEN
  1007. #if(MPATH)
  1008. /***************************************************************************
  1009. * Read_MPATH_Game_Options -- reads multiplayer game options from disk *
  1010. * *
  1011. * This routine is used for multiplayer games which read the game options *
  1012. * from disk, rather than through a connection dialog. *
  1013. * *
  1014. * INPUT: *
  1015. * none. *
  1016. * *
  1017. * OUTPUT: *
  1018. * 1 = OK, 0 = error *
  1019. * *
  1020. * WARNINGS: *
  1021. * none. *
  1022. * *
  1023. * HISTORY: *
  1024. * 01/11/1996 BRR : Created. *
  1025. *=========================================================================*/
  1026. int Read_MPATH_Game_Options(void)
  1027. {
  1028. INIClass ini;
  1029. if (!ini.Load(RawFileClass(Session.OptionsFile))) {
  1030. return (0);
  1031. }
  1032. ini.Get_String("Options", "Handle", "Noname", Session.Handle,
  1033. sizeof(Session.Handle));
  1034. Session.ColorIdx = (PlayerColorType)ini.Get_Int("Options", "Color", 0);
  1035. Session.House = (HousesType)
  1036. ((int)HOUSE_USSR + ini.Get_Int("Options", "Side", 0));
  1037. Session.Options.Credits = ini.Get_Int("Options", "Credits", 3000);
  1038. Session.Options.Bases = ini.Get_Int("Options", "Bases", 1);
  1039. Session.Options.Tiberium = ini.Get_Int("Options", "Tiberium", 1);
  1040. Session.Options.Goodies = ini.Get_Int("Options", "Crates", 1);
  1041. Special.IsShadowGrow = ini.Get_Int ("Options", "Shadow", 0);
  1042. BuildLevel = ini.Get_Int("Options", "BuildLevel", 3);
  1043. Session.Options.UnitCount = ini.Get_Int("Options", "UnitCount", 5);
  1044. Seed = ini.Get_Int("Options", "Seed", 0);
  1045. Special.IsCaptureTheFlag = ini.Get_Int("Options", "CapFlag", 0);
  1046. Session.Options.AIPlayers = ini.Get_Int("Options", "AI", 0);
  1047. if (Session.Options.AIPlayers){
  1048. Session.Options.Ghosts = 1;
  1049. }
  1050. if (Session.Options.Tiberium) {
  1051. Special.IsTGrowth = 1;
  1052. Special.IsTSpread = 1;
  1053. } else {
  1054. Special.IsTGrowth = 0;
  1055. Special.IsTSpread = 0;
  1056. }
  1057. /*
  1058. ** Read the scenario name from the .INI and try to match it with a scenario file in our list.
  1059. */
  1060. ini.Get_String("Options", "Scenario", "Black Acres",
  1061. Session.Options.ScenarioDescription,
  1062. sizeof (Session.Options.ScenarioDescription));
  1063. Session.Options.ScenarioIndex = -1;
  1064. for (int i = 0; i < Session.Scenarios.Count(); i++) {
  1065. if (!strcmp (Session.Scenarios[i]->Description(),
  1066. Session.Options.ScenarioDescription) ) {
  1067. Session.Options.ScenarioIndex = i;
  1068. strcpy(Session.ScenarioFileName, Session.Scenarios[i]->Get_Filename());
  1069. strcpy(Scen.ScenarioName, Session.Scenarios[i]->Get_Filename());
  1070. break;
  1071. }
  1072. }
  1073. if (Session.Options.ScenarioIndex == -1) {
  1074. WWMessageBox().Process("Scenario not found!");
  1075. //Prog_End();
  1076. Emergency_Exit(0);
  1077. }
  1078. Options.GameSpeed = 0;
  1079. Session.MaxAhead = ini.Get_Int("Timing", "MaxAhead", 9);
  1080. Session.FrameSendRate = ini.Get_Int("Timing", "SendRate", 3);
  1081. Session.NetResponseTime = ini.Get_Int("Timing","Latency",600);
  1082. return (1);
  1083. }
  1084. #endif // MPATH
  1085. /************************** end of mplayer.cpp *****************************/