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