2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
19 #include "win\xtapi.h"
57 #define MIN_COMM_GAP 8000
58 #define INIT_STRING_LEN 20
59 #define LEN_PHONE_NUM_OLD 15
60 #define LEN_PHONE_NUM 30
61 #define LEN_PHONE_NAME 12
62 #define NUM_PHONE_NUM 8
69 // How many times to repeat 'reliable' messages
73 #define COM_PROCESS_NORMAL 0
74 #define COM_PROCESS_ENDLEVEL 1
75 #define COM_PROCESS_SYNC 2
76 #define COM_PROCESS_MENU 3
78 #define SELECTION_STARTGAME 1
79 #define SELECTION_NO_START 2
80 #define SELECTION_YES_START 3
81 #define SELECTION_STARTGAME_ABORT 4
82 #define SELECTION_CLOSE_LINK 5
85 // Code to support modem/null-modem play
86 // Program determined variables for serial play
88 typedef struct com_sync_pack {
95 char callsign[CALLSIGN_LEN+1];
108 short DoAfterburner:1;
109 short DoInvulnerability:1;
115 short DoSuperLaser:1;
121 short DoEarthShaker:1;
123 short Allow_marker_view:1;
124 short RefusePlayers:1;
125 short AlwaysLighting:1;
130 char dummy[3]; // Extra space for checksum & sequence number
134 int default_base[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
135 int default_irq[4] = { 4, 3, 4, 3 };
139 BOOL ModemDetect = FALSE;
144 int com_baud_rate = 0;
145 //--unused-- int sync_time = 0;
148 int other_got_sync = 0;
150 long com_type = -1; /* What type of UART is available */
152 static ubyte rx_seqnum = 0xff;
153 static ubyte tx_seqnum = 0;
154 int OtherPlayer; // Player num for modem opponent
155 int com_process_mode = COM_PROCESS_NORMAL;
156 int master = -1; // Am I the master or is the other guy the master?
157 com_sync_pack my_sync, other_sync;
160 int com_custom_port = -1;
161 int com_custom_irq = -1;
162 int com_custom_base = -1;
164 int other_menu_choice = 0;
170 static char syncbuffer[MAX_MULTI_MESSAGE_LEN+4];
171 static char sendbuf[MAX_MULTI_MESSAGE_LEN+4]; // +4 because of +1 for null and +3 for checksum/sequence
173 // Serial setup variables
175 int com_port_num = -1;
177 char modem_init_string[INIT_STRING_LEN+1];
178 char phone_num[NUM_PHONE_NUM+1][LEN_PHONE_NUM+1];
179 char phone_name[NUM_PHONE_NUM][LEN_PHONE_NAME+1];
181 #define MAX_MODEMS 200
182 #define MODEM_NAME_LEN 22
184 char ModemNames[MAX_MODEMS][MODEM_NAME_LEN+1],ModemStrings[MAX_MODEMS][INIT_STRING_LEN+1]; // for init strings
185 char ModemInitString[INIT_STRING_LEN+1];
188 fix SerialLastMessage = 0;
191 /* Function prototypes for functions not exported through modem.h */
193 void modem_main_menu(int modem);
194 void modem_dialout(int modem);
196 void modem_answer(int modem);
197 void modem_wait_for_connect(int nitems, newmenu_item *menus, int *key, int citem);
198 void modem_wait_for_ring(int nitems, newmenu_item *menus, int *key, int citem);
200 int serial_link_menu(int port);
201 void serial_link_start();
203 int com_game_menu(void);
204 void com_start_game(void);
205 void com_menu_poll(int nitems, newmenu_item *menus, int *key, int citem);
206 int com_sync(int id);
207 void com_sync_poll(int nitem, newmenu_item *menus, int *key, int citem);
209 int GetModemList(void);
216 #if !defined(NDEBUG) && !defined(NMONO)
218 com_dump_string(char *string)
220 mprintf((0, "%s\n", string));
223 #define com_dump_string()
236 Comm.baud = com_speed;
238 if (!comm_open_connection(&Comm)) {
239 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Failed to open COM port.");
240 comm_close_connection(&Comm);
244 comm_set_dtr(&Comm, 1);
246 if ( FindArg( "-ctsrts" ) || FindArg( "-rtscts" ) )
247 comm_set_rtscts(&Comm, 1); // Now used for null-modem as well
249 comm_set_rtscts(&Comm, 0);
255 mprintf((0, "Comm object created.\n"));
257 comm_dump_info(&Comm);
265 // close the com port and free associated structures.
270 comm_close_connection(&Comm);
277 mprintf((0, "Comm object released.\n"));
285 // this is the safest way to get out of some modem/serial negotiation
286 // and back to the main menu. Use this whenever this have gone too far
293 change_playernum_to(0);
295 Viewer = ConsoleObject = &Objects[0];
296 Game_mode = GM_GAME_OVER; // Force main menu selection
302 // Close the serial link
304 com_send_choice(SELECTION_CLOSE_LINK);
310 com_carrier_lost(void)
312 // Carrier lost, inform and abort
314 if (multi_in_menu > 0)
316 multi_leave_menu = 1;
320 Function_mode = FMODE_MENU;
323 nm_messagebox(NULL, 1, TXT_OK, TXT_CARRIER_LOST);
329 extern ubyte Cockpit_mode_save; // From object.c
335 // Reset various parameters before starting a new game
339 for (i = 0; i < N_players; i++)
341 Players[i].connected = 1;
346 multi_new_game(); // Reset kill list, among other things
347 Control_center_destroyed = 0;
348 Endlevel_sequence = 0;
350 // Yes, this really IS as ugly as it gets, kids...
352 if (Cockpit_mode == CM_LETTERBOX || Cockpit_mode == CM_REAR_VIEW)
354 select_cockpit(Cockpit_mode_save);
359 // WE SHOULD CHANGE THIS TO BE MORE WINDOW LIKE?
362 com_save_settings(void)
368 if ( (settings = fopen("serial.cfg", "wb")) == NULL)
371 if (fwrite(&com_speed, sizeof(int), 1, settings) != 1)
374 if (fwrite(&com_port_num, sizeof(int), 1, settings) != 1)
377 if (fwrite(modem_init_string, 1, INIT_STRING_LEN+1, settings) != INIT_STRING_LEN+1)
380 for (i = 0; i < NUM_PHONE_NUM; i++)
382 if (fwrite(phone_num[i], 1, LEN_PHONE_NUM+1, settings) != LEN_PHONE_NUM+1)
384 if (fwrite(phone_name[i], 1, LEN_PHONE_NAME+1, settings) != LEN_PHONE_NAME+1)
388 if (fwrite(&com_custom_port, sizeof(int), 1, settings) != 1)
390 if (fwrite(&com_custom_irq, sizeof(int), 1, settings) != 1)
392 if (fwrite(&com_custom_base, sizeof(int), 1, settings) != 1)
400 nm_messagebox(NULL, 1, TXT_OK, TXT_ERROR_SERIAL_CFG);
404 unlink("serial.cfg");
412 com_load_settings(void)
418 if ((settings = fopen("serial.cfg", "rb")) == NULL)
421 cfg_size = filelength(fileno(settings));
423 // Read the data from the file
425 if (fread(&com_speed, sizeof(int), 1, settings) != 1)
427 if (! ((com_speed == 9600) || (com_speed == 19200) || (com_speed == 38400)) )
430 mprintf((0, "Here?"));
432 /* Not really used for Windows version */
433 if (fread(&com_port_num, sizeof(int), 1, settings) != 1)
435 if ( (com_port_num < COM1) || (com_port_num > COM4) )
438 mprintf((0, "Here?"));
441 /* Not really used for Windows version */
442 if (fread(modem_init_string, 1, INIT_STRING_LEN+1, settings) != INIT_STRING_LEN+1)
444 modem_init_string[INIT_STRING_LEN] = '\0';
446 mprintf((0, "Here?"));
449 /* Used in Windows version */
450 if (cfg_size <= 273 ) { // Old 15 char LEN_PHONE_NUM's
451 mprintf(( 1, "Reading old pre 1.1 phone.cfg\n" ));
452 for (i = 0; i < NUM_PHONE_NUM; i++)
454 if (fread(phone_num[i], 1, LEN_PHONE_NUM_OLD+1, settings) != LEN_PHONE_NUM_OLD+1)
456 phone_num[i][LEN_PHONE_NUM_OLD] = '\0';
457 if (fread(phone_name[i], 1, LEN_PHONE_NAME+1, settings) != LEN_PHONE_NAME+1)
459 phone_name[i][LEN_PHONE_NAME] = '\0';
461 } else { // Normal Phone nums
462 for (i = 0; i < NUM_PHONE_NUM; i++)
464 if (fread(phone_num[i], 1, LEN_PHONE_NUM+1, settings) != LEN_PHONE_NUM+1)
466 phone_num[i][LEN_PHONE_NUM] = '\0';
467 if (fread(phone_name[i], 1, LEN_PHONE_NAME+1, settings) != LEN_PHONE_NAME+1)
469 phone_name[i][LEN_PHONE_NAME] = '\0';
473 mprintf((0, "Here?"));
476 /* Not really used in Windows version */
477 if (fread(&com_custom_port, sizeof(int), 1, settings) != 1) {
478 mprintf((0, "Reading old file format for serial.cfg.\n"));
482 if ( (com_custom_port < -1) || (com_custom_port > COM4) )
485 if (fread(&com_custom_irq, sizeof(int), 1, settings) != 1)
488 //!! if ( (com_custom_port < -1) || (com_custom_port > IRQ15) )
491 if (fread(&com_custom_base, sizeof(int), 1, settings) != 1)
493 if (com_custom_base < -1)
497 mprintf((0, "Here?"));
498 //Everything was A-Ok!
507 nm_messagebox(NULL, 1, TXT_OK, TXT_ERR_SER_SETTINGS);
510 // Return some defaults
511 com_speed = CBR_19200;
513 /* Here so we can save them back to config file. */
514 strcpy(modem_init_string, "ATZ");
516 com_custom_port = -1;
518 for (i = 0; i < NUM_PHONE_NUM; i++)
520 phone_num[i][0] = '\0';
521 strcpy(phone_name[i], TXT_EMPTY);
531 serial_leave_game(void)
534 mprintf((0, "Called serial_leave_game.\n"));
537 serial_sync_abort(0); // Just in case the other guy is in sync mode
538 Game_mode |= GM_GAME_OVER;
539 Function_mode = FMODE_MENU;
544 com_send_data(char *ptr, int len, int repeat)
548 // Take the raw packet data specified by ptr and append the sequence
549 // number and checksum, and pass it to com_send_ptr
554 if (Game_mode & GM_MODEM)
556 i = comm_get_cd(&Comm);
558 mprintf((0, "CARRIER LOST!\n"));
564 len += 3; // Checksum data is 3 bytes
566 *(ubyte *)(ptr+(len-3)) = (tx_seqnum+1)%256;
567 tx_seqnum = (tx_seqnum+1)%256;
569 *(ushort *)(ptr+(len-2)) = netmisc_calc_checksum(ptr, len-2);
571 com_send_ptr(ptr, len);
573 for (i = 0; i < repeat; i++)
574 com_send_ptr(ptr, len);
577 com_send_ptr(char *ptr, int len)
582 for (count = 0, dat=ptr[0]; count < len; dat=ptr[++count])
584 comm_write_char(&Comm, dat);
586 comm_write_char(&Comm, EOR_MARK); // double in-band endmarkers
588 comm_write_char(&Comm, EOR_MARK);
589 comm_write_char(&Comm, 0);
597 // Get rid of all waiting data in the serial buffer
604 mprintf((0, "COM FLUSH:"));
606 while (comm_read_char_timed(&Comm, 100) >= 0)
608 mprintf((0, "%d characters.\n", i));
615 static int eor_recv = 0;
618 // -1 = Nothing in buffer
619 // -2 = End of record
624 i = comm_read_char(&Comm);;
626 // mprintf((0, "%d", i));
628 if (i == COMM_BUF_EMPTY)
631 if ((i == EOR_MARK) || eor_recv)
634 i = comm_read_char(&Comm);
636 if (i == COMM_BUF_EMPTY)
638 // Assert(eor_recv == 0);
642 else if (i == EOR_MARK)
645 return(EOR_MARK); // Doubled EOR returns the character
651 mprintf((0, "EOR followed by unexpected value %d.\n", i));
661 #define SERIAL_IDLE_TIMEOUT F1_0*10
667 static fix last_comm_time = 0;
668 static int last_pos_skipped = 0;
671 if (Endlevel_sequence || (com_process_mode==COM_PROCESS_ENDLEVEL)) { // Only recieve during endlevel
672 int old_Endlevel_sequence = Endlevel_sequence;
673 Endlevel_sequence = 1;
675 Endlevel_sequence = old_Endlevel_sequence;
679 last_comm_time += FrameTime;
681 if ((last_comm_time > MIN_COMM_GAP) || Network_laser_fired)
684 if ((Game_mode & GM_MULTI_ROBOTS) && !last_pos_skipped) {
685 rval = multi_send_robot_frame(0);
687 if (rval && !Network_laser_fired)
689 last_pos_skipped = 1;
693 last_pos_skipped = 0;
694 multi_send_position(Players[Player_num].objnum);
695 multi_send_fire(); // Will return w/o sending if we haven't fired
698 // mprintf((0, "%d chars sent, %f cps.\n", chars_sent, f2fl(fixdiv((chars_sent*F1_0),last_comm_time)) ));
705 if (!Control_center_destroyed && (Function_mode == FMODE_GAME) && (SerialLastMessage+SERIAL_IDLE_TIMEOUT < GameTime))
707 SerialLastMessage = 0x7fffffff-SERIAL_IDLE_TIMEOUT; // Give no further warnings until next message arrives!
708 nm_messagebox(TXT_WARNING, 1, TXT_OK, TXT_CONNECT_LOST, Players[OtherPlayer].callsign);
715 com_check_message(char *checkbuf, int len)
720 //mprintf ((0,"TYPE=%d!\n",checkbuf[0]));
724 mprintf((0, "message type %d too short to be a real message!\n", checkbuf[0]));
728 if (checkbuf[0] > MULTI_MAX_TYPE)
730 mprintf((0, "message type %d out of range.\n", checkbuf[0]));
734 if ( (len-3) != message_length[checkbuf[0]])
736 mprintf((0, "id:%d message length %d != %d.\n",checkbuf[0], len-3, message_length[checkbuf[0]]));
740 check = netmisc_calc_checksum(checkbuf, len-2);
741 if (check != *(ushort *)(checkbuf+(len-2)))
744 mprintf((0, "error in message type %d, length %d, checksum %d != %d\n", checkbuf[0], len, check, *(ushort *)(checkbuf+(len-2))));
749 seqnum = checkbuf[(len-3)];
751 if (seqnum == rx_seqnum)
753 // mprintf ((0,"returning due to bad checksum! type=%d seq=%d rx=%d\n",checkbuf[0],seqnum,rx_seqnum));
757 if (seqnum != (rx_seqnum+1)%256)
760 mprintf((0, "Warning, missed 1 or more messages.\n"));
764 //mprintf((0, "message type %d len %d OK!\n", checkbuf[0], len));
768 mprintf((1,"Line status: %d.\n", comm_get_line_status(&Comm)));
769 comm_clear_line_status(&Comm);
776 com_process_menu(char *buf, int len)
782 mprintf((0, "com_process_menu: type %d.\n", buf[0]));
787 sprintf(text, "%s %s\n'%s'", Players[OtherPlayer].callsign, TXT_SAYS, buf+2);
788 nm_messagebox(NULL, 1, TXT_OK, text);
790 case MULTI_MENU_CHOICE:
791 other_menu_choice = buf[1];
792 mprintf((0, "Other menu choice = %d.\n", other_menu_choice));
794 case MULTI_BEGIN_SYNC:
795 // If we get a sync at the menu, send an abort sync, we're not ready yet!
796 serial_sync_abort(0);
802 com_process_input(void)
804 // Read all complete messages from the serial buffer and process
805 // the contents. Messages are read into global array snycbuffer.
808 int entry_com_mode = com_process_mode;
815 if (Game_mode & GM_MODEM)
817 if (!comm_get_cd(&Comm))
822 if (!multi_in_menu) {
826 multi_leave_menu = 1;
830 if (com_process_mode != entry_com_mode)
832 mprintf((0, "Exiting com_process_input due to mode switch.\n"));
836 while ( (len <= MAX_MULTI_MESSAGE_LEN) && (dat = com_getchar()) > -1) // Returns -1 when serial pipe empty
838 syncbuffer[len++] = dat;
841 if ((dat == -2) || (len > MAX_MULTI_MESSAGE_LEN)) // Returns -2 when end of message reached
844 SerialLastMessage = GameTime;
846 if (!com_check_message(syncbuffer, len))
848 switch(com_process_mode)
850 case COM_PROCESS_NORMAL:
851 case COM_PROCESS_ENDLEVEL:
852 multi_process_data(syncbuffer, len); break;
853 case COM_PROCESS_MENU:
854 if (!Endlevel_sequence) com_process_menu(syncbuffer, len); break;
855 case COM_PROCESS_SYNC:
856 if (!Endlevel_sequence) com_process_sync(syncbuffer, len); break;
858 Int3(); // Bad com_process_mode switch set!
861 else mprintf ((0,"Huh?\n"));
866 if (dat == -3) // Returns -3 when carrier lost
879 my_sync.type = MULTI_BEGIN_SYNC;
880 my_sync.difficulty = 0;
881 memcpy(my_sync.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
882 my_sync.seg_checksum = 0;
883 my_sync.game_mode = Game_mode;
884 my_sync.level_num = 0;
887 mprintf((0, "com_connect()\n"));
891 return(-1); // Failure in sync
896 mprintf((0, "My rand = %d, other rand = %d.\n", my_sync.sync_time, other_sync.sync_time));
899 // Figure out who is the master
900 if (my_sync.sync_time > other_sync.sync_time)
902 mprintf((0, "Swtiching player to master.\n"));
904 change_playernum_to(0);
906 else if (my_sync.sync_time < other_sync.sync_time)
908 mprintf((0, "Switching player to slave.\n"));
910 change_playernum_to(1);
913 return(-1); // Didn't sync properly, try again
916 // Copy the remote sync data into local variables
918 OtherPlayer = (Player_num+1)%2;
919 mprintf((0, "Other player is #%d.\n", OtherPlayer));
920 memcpy(Players[OtherPlayer].callsign, other_sync.callsign, CALLSIGN_LEN+1);
927 // ----------------------------------------------------------------------------
929 // ----------------------------------------------------------------------------
931 #define ADD_ITEM(t,value,key) do { m[num_options].type=NM_TYPE_MENU; menu_choice[num_options]=value; m[num_options].text=t; num_options++; } while (0)
932 #define SUBTITLE_LEN 192
934 #define MENU_XTAPI_DEVICE 0
935 #define MENU_COMM_DEVICE 2
937 #define MENU_SERIAL_GAME_START 5
938 #define MENU_SEND_MESSAGE 6
939 #define MENU_SERIAL_CLOSE 7
940 #define MENU_MODEM_HANGUP 8
943 static TapiDevice *tapiDevices=NULL;
944 static int xtapiCurrentModem = -1;
945 static int numTapiDevs = 0;
947 extern void nm_draw_background1(char * filename);
950 void com_main_menu(void)
954 int device_type[6]; // 0 = serial, 1 = modem
956 int i, num_options=0, choice;
963 // setjmp(LeaveGame);
965 nm_draw_background1(Menu_pcx_name);
966 com_process_mode = COM_PROCESS_MENU;
968 if (Game_mode & GM_SERIAL) { // HACK to get menu system working
969 Assert(Comm.port >= 1 && Comm.port <= 4);
970 mprintf((0, "WINMODEM: Going to serial link menu!\n"));
971 sel = MENU_COMM_DEVICE + (Comm.port-1);
972 goto skip_to_com_submenus;
974 else if (Game_mode & GM_MODEM) {
975 Assert(xtapiCurrentModem != -1);
976 mprintf((0, "WINMODEM: Going to modem menu!\n"));
977 sel = xtapiCurrentModem;
978 goto skip_to_com_submenus;
981 // Get devices for TAPI.
982 retval = xtapi_init(WINAPP_NAME, &numTapiDevs);
983 if (retval == XTAPI_NODEVICES) {
986 else if (retval == XTAPI_APPCONFLICT) {
989 else if (retval == XTAPI_INCOMPATIBLE_VERSION) {
993 if (numTapiDevs > 2) numTapiDevs = 2;
994 if (numTapiDevs == 0) tapiDevices = NULL;
996 tapiDevices = (TapiDevice *)malloc(numTapiDevs*sizeof(TapiDevice));
998 Error("Unable to allocate memory for com_main_menu.");
1000 retval = xtapi_enumdevices(tapiDevices, numTapiDevs);
1001 if (retval != XTAPI_SUCCESS) {
1008 for (i = 0; i < numTapiDevs; i++)
1010 if (tapiDevices[i].type == XTAPI_MODEM_DEVICE) {
1011 sprintf(buf, "Modem (%d baud)", tapiDevices[i].max_baud);
1015 sprintf(buf, "Unsupported device (%d baud)", tapiDevices[i].max_baud);
1019 m[i].type=NM_TYPE_MENU; menu_choice[i]=MENU_XTAPI_DEVICE+i;
1020 m[i].text=buf; num_options++;
1023 device_type[num_options] = 0;
1024 m[num_options].type=NM_TYPE_MENU; menu_choice[num_options]=MENU_COMM_DEVICE;
1025 m[num_options].text="Direct to Com 1"; num_options++;
1027 device_type[num_options] = 0;
1028 m[num_options].type=NM_TYPE_MENU; menu_choice[num_options]=MENU_COMM_DEVICE+1;
1029 m[num_options].text="Direct to Com 2"; num_options++;
1031 device_type[num_options] = 0;
1032 m[num_options].type=NM_TYPE_MENU; menu_choice[num_options]=MENU_COMM_DEVICE+2;
1033 m[num_options].text="Direct to Com 3"; num_options++;
1035 device_type[num_options] = 0;
1036 m[num_options].type=NM_TYPE_MENU; menu_choice[num_options]=MENU_COMM_DEVICE+3;
1037 m[num_options].text="Direct to Com 4"; num_options++;
1039 choice = newmenu_do1(NULL, "Select Serial Device", num_options, m, NULL, 0);
1042 if (tapiDevices) free(tapiDevices);
1046 else if (choice < -1) {
1051 sel = menu_choice[choice];
1053 skip_to_com_submenus:
1057 case MENU_XTAPI_DEVICE:
1058 case MENU_XTAPI_DEVICE+1:
1059 // start a xtapi game
1060 modem_main_menu(sel);
1061 if (Function_mode == FMODE_GAME) return;
1064 case MENU_COMM_DEVICE:
1065 case MENU_COMM_DEVICE+1:
1066 case MENU_COMM_DEVICE+2:
1067 case MENU_COMM_DEVICE+3:
1068 // start a serial game
1069 mprintf((0, "Selected a null-modem game.\n"));
1070 if (!serial_link_menu(sel-MENU_COMM_DEVICE+1))
1071 goto com_menu_redraw;
1072 mprintf((0, "WINMODEM: starting game...\n"));
1077 if (tapiDevices) free(tapiDevices);
1079 nm_draw_background1(Menu_pcx_name);
1083 // if 1, then we are starting a game
1085 int com_game_menu(void)
1088 int menu_choice[12];
1089 int num_options = 0;
1091 char subtitle[SUBTITLE_LEN];
1096 com_game_menu_redraw:
1099 ADD_ITEM(TXT_START_GAME, MENU_SERIAL_GAME_START, KEY_S);
1100 ADD_ITEM(TXT_SEND_MESSAGEP, MENU_SEND_MESSAGE, KEY_S);
1101 if (Game_mode & GM_MODEM)
1102 ADD_ITEM(TXT_HANGUP_MODEM, MENU_MODEM_HANGUP, KEY_H);
1104 if (Game_mode & GM_SERIAL)
1105 ADD_ITEM(TXT_CLOSE_LINK, MENU_MODEM_HANGUP, KEY_C);
1107 m[num_options].type=NM_TYPE_TEXT; m[num_options].text=""; num_options++;
1109 if (Game_mode & GM_SERIAL)
1110 sprintf(subtitle, "%s\n\n%s %s\n%s", TXT_SERIAL_GAME, TXT_SERIAL, TXT_LINK_ACTIVE, Players[OtherPlayer].callsign);
1111 else if (Game_mode & GM_MODEM)
1112 sprintf(subtitle, "%s\n\n%d %s %s\n%s", TXT_SERIAL_GAME, com_baud_rate, TXT_BAUD, TXT_LINK_ACTIVE, Players[OtherPlayer].callsign);
1114 mprintf((1, "Game mode isn't set correctly.\n"));
1118 multi_leave_menu = 0;
1120 Assert(strlen(subtitle) < SUBTITLE_LEN);
1122 choice = newmenu_do1(NULL, subtitle, num_options, m, com_menu_poll, 0);
1126 m[0].text = TXT_YES; m[1].text = TXT_NO;
1127 m[0].type = m[1].type = NM_TYPE_MENU;
1129 choice = newmenu_do1(NULL, TXT_EXIT_WILL_CLOSE, 2, m, com_menu_poll, 0);
1132 com_send_choice(SELECTION_CLOSE_LINK);
1136 if ((choice == -2) && (other_menu_choice))
1137 com_process_other_menu_choice();
1139 goto com_game_menu_redraw;
1144 // Menu poll loop caused a re-draw
1145 if (other_menu_choice == SELECTION_STARTGAME)
1146 com_ready_to_start();
1147 else if (other_menu_choice == SELECTION_CLOSE_LINK)
1149 nm_messagebox(NULL, 1, TXT_OK, TXT_CLOSED_LINK);
1151 mprintf((0, "Leaving modem game (hanging up)...\n"));
1154 if (Function_mode == FMODE_GAME) {
1155 mprintf((0, "We think we're still in a modem game!.\n"));
1160 mprintf((0, "At this point we're taking off..\n"));
1161 Game_mode = GM_GAME_OVER;
1165 goto com_game_menu_redraw;
1168 comm_dump_info(&Comm);
1172 // old_game_mode=Game_mode;
1173 switch (menu_choice[choice])
1175 case MENU_SERIAL_GAME_START:
1177 if (Function_mode != FMODE_GAME)
1178 goto com_game_menu_redraw;
1181 case MENU_SEND_MESSAGE:
1182 multi_send_message_dialog();
1183 if (Network_message_reciever != -1)
1184 multi_send_message();
1185 multi_sending_message = 0;
1186 goto com_game_menu_redraw;
1189 case MENU_MODEM_HANGUP:
1194 mprintf((1, "Bad com_game_menu choice\n"));
1205 * Serial Link/Null Modem Functions
1208 // 1 = starting game
1210 int serial_link_menu(int port)
1212 /* This menu will give a listing of possible com_speeds. The default will
1213 be given, but the user should be given the option to change to a lower
1217 int com_max_setting, loc, i, mmn, menu_link;
1218 int com_speed_setting;
1219 int com_speeds[5] = {
1220 CBR_9600, CBR_19200, CBR_38400, CBR_57600, CBR_115200
1222 char *com_speeds_text[5] = {
1223 "9600", "19200", "38400", "57600", "115200"
1226 // HACK to get menu system working when leaving serial game to
1227 // get to correct modem.
1228 if (Game_mode & GM_SERIAL) {
1229 mprintf((0, "WINMODEM:Go directly to com_game menu.\n"));
1230 goto skip_to_game_menu;
1232 else mprintf((0, "WINMODEM:Not going directly to com_game menu.\n"));
1234 /* First check what speed the selected port is set to */
1235 if (com_open) com_disable();
1237 memset(&Comm, 0, sizeof(COMM_OBJ));
1239 Comm.baud = com_speed;
1241 if (!comm_open_connection(&Comm)) {
1242 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Unable to open selected COM port");
1248 case CBR_9600: com_max_setting = 1; break;
1249 case CBR_19200: com_max_setting = 2; break;
1250 case CBR_38400: com_max_setting = 3; break;
1252 mprintf((0, "COM%d baud = %d\n", Comm.port, Comm.baud));
1253 if (Comm.baud > CBR_38400) com_max_setting = 3;
1255 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Your serial system must be\n capable of at least 9600 baud.");
1256 com_max_setting = -1;
1259 comm_close_connection(&Comm);
1261 if (com_max_setting == -1) return 0;
1266 mm[0].type=NM_TYPE_TEXT; mm[0].text = TXT_BAUD_RATE; loc++;
1268 for (i = 0; i < 3; i++) // Limit to 38.4K
1270 mm[i+1].type=NM_TYPE_RADIO; mm[i+1].value=(i==(com_max_setting-1));
1271 mm[i+1].text=com_speeds_text[i]; mm[i+1].group=1; loc++;
1273 mm[loc].type=NM_TYPE_TEXT; mm[loc].text = ""; loc++;
1276 mm[loc].type=NM_TYPE_MENU; mm[loc].text = "Establish Link"; loc++;
1278 mmn = newmenu_do1(NULL, TXT_SERIAL_SETTINGS, loc, mm, NULL, menu_link);
1280 /* Take care of selection */
1282 for (i = 0; i < 3; i++)
1283 if (mm[i+1].value) {
1284 com_speed_setting = com_speeds[i];
1288 if(menu_link != mmn) goto setup_serial_menu;
1292 com_speed = com_speed_setting;
1295 serial_link_start(); // We should be in GM_SERIAL after this
1297 com_save_settings();
1300 if (Game_mode & GM_SERIAL) {
1301 if (com_game_menu()) return 1;
1308 void serial_link_start(void)
1312 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_NO_SERIAL_OPT);
1316 com_enable(); // Open COM port as configured
1326 my_sync.sync_time = rand();
1327 mprintf((0, "My rand set to %d.\n", my_sync.sync_time));
1331 Game_mode |= GM_SERIAL;
1332 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1336 nm_messagebox(NULL, 1, TXT_OK, "%s\n%s", TXT_ERROR, TXT_FAILED_TO_NEGOT);
1344 * modem class functions
1347 void modem_main_menu(int modem)
1353 if (Game_mode & GM_MODEM) {
1354 mprintf((0, "WINMODEM:Going directly to com_game_menu.\n"));
1361 m[num_options].type=NM_TYPE_MENU; m[num_options].text="Dial"; num_options++;
1362 m[num_options].type=NM_TYPE_MENU; m[num_options].text="Answer"; num_options++;
1363 m[num_options].type=NM_TYPE_TEXT; m[num_options].text=""; num_options++;
1365 choice = newmenu_do1(NULL, "Modem Options", num_options, m, NULL, 0);
1370 modem_dialout(modem);
1371 if (Game_mode & GM_MODEM) com_game_menu();
1372 if (Function_mode == FMODE_GAME) return;
1376 modem_answer(modem);
1377 if (Game_mode & GM_MODEM) com_game_menu();
1378 if (Function_mode == FMODE_GAME) return;
1383 else if (choice == -1) return;
1385 goto modem_menu_redraw;
1391 if (xtapiCurrentModem > -1) {
1392 mprintf((0, "WINMODEM: Hanging up..\n"));
1394 xtapi_device_hangup();
1395 xtapi_unlock(&tapiDevices[xtapiCurrentModem]);
1396 xtapiCurrentModem = -1;
1397 mprintf((0, "WINMODEM: Complete!\n"));
1402 void modem_dialout(int modem)
1407 // At this point, xtapi is initialized, so we just need to get a number
1412 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_NO_SERIAL_OPT);
1416 retval = xtapi_lock(&tapiDevices[modem]);
1417 if (retval != XTAPI_SUCCESS) {
1418 mprintf((1, "Failed to lock down an XTAPI device.\n"));
1425 xtapiCurrentModem = modem; // Modem controls com functions
1428 // Select a number to dial
1429 if ((choice = modem_dial_menu()) == -1) {
1434 if (strlen(phone_num[choice]) == 0)
1436 nm_messagebox(NULL, 1, TXT_OK, TXT_NO_PHONENUM);
1441 show_boxed_message(TXT_RESET_MODEM);
1442 retval = xtapi_device_dialout(phone_num[choice]);
1443 if (retval != XTAPI_SUCCESS) {
1444 clear_boxed_message();
1445 nm_messagebox(NULL, 1, TXT_OK, "Unable to initiate dialing!");
1446 mprintf((1, "XTAPI: err %d\n", retval));
1450 clear_boxed_message();
1452 m[0].type=NM_TYPE_TEXT; m[0].text="Initializing\n";
1453 m[1].type=NM_TYPE_TEXT; m[1].text=TXT_ESC_ABORT;
1456 choice = newmenu_do(NULL, TXT_WAITING_FOR_ANS, 2, m, modem_wait_for_connect);
1462 // We are now connected to the other modem
1465 my_sync.sync_time=32000;
1466 // -- commented out by mk, 2/21/96 -- master = 1; // The person who dialed is the master of the connection
1467 change_playernum_to(0);
1471 Game_mode |= GM_MODEM;
1472 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1481 void modem_answer(int modem)
1486 // At this point, xtapi is initialized, so we just need to get a number
1491 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_NO_SERIAL_OPT);
1495 retval = xtapi_lock(&tapiDevices[modem]);
1496 if (retval != XTAPI_SUCCESS) {
1497 mprintf((1, "Failed to lock down an XTAPI device.\n"));
1504 xtapiCurrentModem = modem; // Modem controls com functions
1506 // start up modem and wait for connect
1507 show_boxed_message(TXT_RESET_MODEM);
1508 retval = xtapi_device_dialin();
1509 if (retval != XTAPI_SUCCESS) {
1510 clear_boxed_message();
1511 nm_messagebox(NULL, 1, TXT_OK, "Unable to initialize modem.");
1512 mprintf((1, "XTAPI: err %d\n", retval));
1516 clear_boxed_message();
1518 // wait for a ring first.
1519 modem_answer_redraw:
1520 m[0].type=NM_TYPE_TEXT; m[0].text=TXT_ESC_ABORT;
1522 choice = newmenu_do(NULL, TXT_WAITING_FOR_CALL, 1, m, modem_wait_for_ring);
1528 goto modem_answer_redraw;
1530 // Now answer the phone and wait for carrier
1531 retval = xtapi_device_answer();
1535 choice = newmenu_do(NULL, TXT_WAITING_FOR_CARR, 1, m, modem_wait_for_connect);
1541 // We are now connected to the other modem
1542 // We are now connected to the other modem
1545 my_sync.sync_time=0;
1547 change_playernum_to(1);
1551 Game_mode |= GM_MODEM;
1552 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1560 void modem_wait_for_connect(int nitems, newmenu_item *menus, int *key, int citem)
1569 retval = xtapi_device_poll_callstate(&modem_state);
1570 if (retval != XTAPI_SUCCESS) {
1574 switch (modem_state)
1576 case XTAPI_LINE_DIALING:
1577 menus[0].text = "Dialing\n";
1578 menus[0].redraw = 1;
1581 case XTAPI_LINE_PROCEEDING:
1582 case XTAPI_LINE_RINGBACK:
1583 menus[0].text = "Calling\n";
1584 menus[0].redraw = 1;
1587 case XTAPI_LINE_BUSY:
1588 nm_messagebox(NULL, 1, TXT_OK, "Got a busy signal.");
1592 case XTAPI_LINE_FEEDBACK:
1593 nm_messagebox(NULL, 1, TXT_OK, "Unable to connect.");
1597 case XTAPI_LINE_DISCONNECTED:
1598 nm_messagebox(NULL, 1, TXT_OK, "Disconnected!");
1602 case XTAPI_LINE_CONNECTED:
1603 // perform connection scheme: we should create a comm object!
1604 xtapi_device_create_comm_object(&Comm);
1608 mprintf((0, "Connect at %d baud.\n", Comm.baud));
1609 if (Comm.baud < CBR_9600) {
1610 nm_messagebox(NULL, 1, TXT_OK, TXT_BAUD_GREATER_9600);
1615 com_baud_rate = Comm.baud;
1621 case XTAPI_LINE_IDLE:
1622 menus[0].text = "Idle\n";
1623 menus[0].redraw = 1;
1627 case XTAPI_LINE_DIALTONE:
1628 menus[0].text = "Dialtone\n";
1629 menus[0].redraw = 1;
1635 mprintf((0, "xtapi undefined call state.\n"));
1642 void modem_wait_for_ring(int nitems, newmenu_item *menus, int *key, int citem)
1651 result = xtapi_device_poll_callstate(&modem_state);
1653 if (modem_state == XTAPI_LINE_RINGING) {
1654 mprintf((0, "Line is ringing. Answering...\n"));
1655 result = xtapi_device_answer();
1656 if (result != XTAPI_SUCCESS) return;
1662 void modem_edit_phonebook(newmenu_item *m)
1664 int choice, choice2;
1665 newmenu_item menu[5];
1667 int default_choice = 0;
1669 m[NUM_PHONE_NUM].text = TXT_SAVE;
1671 menu[0].text = TXT_NAME; menu[0].type = NM_TYPE_TEXT;
1672 menu[1].type = NM_TYPE_INPUT; menu[1].text = text[0]; menu[1].text_len = LEN_PHONE_NAME;
1673 menu[2].text = TXT_PHONE_NUM; menu[2].type = NM_TYPE_TEXT;
1674 menu[3].type = NM_TYPE_INPUT; menu[3].text = text[1]; menu[3].text_len = LEN_PHONE_NUM;
1675 menu[4].text = TXT_ACCEPT; menu[4].type = NM_TYPE_MENU;
1678 choice = newmenu_do1(NULL, TXT_SEL_NUMBER_EDIT, NUM_PHONE_NUM+1, m, NULL, default_choice);
1681 com_load_settings();
1684 if (choice == NUM_PHONE_NUM)
1687 com_save_settings();
1694 strcpy(menu[1].text, phone_name[choice]);
1695 strcpy(menu[3].text, phone_num[choice]);
1697 choice2 = newmenu_do1(NULL, TXT_EDIT_PHONE_ENTRY, 5, menu, NULL, default_choice);
1700 strcpy(phone_name[choice], menu[1].text);
1701 strcpy(phone_num[choice], menu[3].text);
1702 sprintf(m[choice].text, "%d. %s \t", choice+1, phone_name[choice]);
1703 add_phone_number(m[choice].text, phone_num[choice] );
1707 default_choice += 2; if (default_choice > 4) default_choice = 4;
1711 default_choice = NUM_PHONE_NUM;
1717 void add_phone_number( char * src, char * num )
1730 strcat( src, "..." );
1734 int modem_dial_menu(void)
1736 newmenu_item m[NUM_PHONE_NUM+2];
1737 char menu_text[NUM_PHONE_NUM][80];
1742 for (i = 0; i < NUM_PHONE_NUM; i++)
1744 m[i].text = menu_text[i];
1745 sprintf(m[i].text, "%d. %s \t", i+1, phone_name[i]);
1746 add_phone_number(m[i].text, phone_num[i] );
1747 m[i].type = NM_TYPE_MENU;
1750 strcat(m[i-1].text, "\n");
1752 m[NUM_PHONE_NUM].type = NM_TYPE_MENU;
1753 m[NUM_PHONE_NUM].text = TXT_MANUAL_ENTRY;
1754 m[NUM_PHONE_NUM+1].text = TXT_EDIT_PHONEBOOK;
1755 m[NUM_PHONE_NUM+1].type = NM_TYPE_MENU;
1757 choice = newmenu_do1(NULL, TXT_SEL_NUMBER_DIAL, NUM_PHONE_NUM+2, m, NULL, 0);
1759 return -1; // user abort
1761 if (choice == NUM_PHONE_NUM+1)
1764 modem_edit_phonebook(m);
1768 if (choice == NUM_PHONE_NUM)
1772 m2[0].type = NM_TYPE_INPUT; m2[0].text = phone_num[NUM_PHONE_NUM]; m2[0].text_len = LEN_PHONE_NUM;
1773 choice = newmenu_do(NULL, TXT_ENTER_NUMBER_DIAL, 1, m2, NULL);
1777 return NUM_PHONE_NUM;
1780 // A phone number was chosen
1791 com_menu_poll(int nitems, newmenu_item *menus, int *key, int citem)
1793 // Watch the serial stream if we are connected and take appropriate actions
1801 com_process_mode = COM_PROCESS_MENU;
1802 old_game_mode = Game_mode;
1803 other_menu_choice = 0;
1805 com_process_input();
1807 if ((old_game_mode != Game_mode) || other_menu_choice || (com_process_mode != COM_PROCESS_MENU))
1809 if (multi_leave_menu)
1814 com_send_choice(int choice)
1816 sendbuf[0] = (char)MULTI_MENU_CHOICE;
1817 sendbuf[1] = (char)choice;
1819 com_send_data(sendbuf, 2, 1);
1823 com_ready_to_start(void)
1828 m[0].type = m[1].type = NM_TYPE_MENU;
1829 m[0].text = TXT_YES;
1832 choice = newmenu_do1(NULL, TXT_READY_DESCENT, 2, m, com_menu_poll, 0 );
1836 com_send_choice(SELECTION_YES_START);
1837 other_menu_choice = SELECTION_STARTGAME;
1842 com_send_choice(SELECTION_NO_START);
1847 com_process_other_menu_choice(void)
1849 if (other_menu_choice == SELECTION_STARTGAME)
1850 com_ready_to_start();
1851 else if (other_menu_choice == SELECTION_CLOSE_LINK)
1853 nm_messagebox(NULL, 1, TXT_OK, TXT_CLOSED_LINK);
1859 // Handshaking to start a serial game, 2 players only
1861 int com_start_game_menu(void)
1866 int opt, diff_opt, mode_opt, options_opt,allow_opt,extraopts_opt;
1867 char level_text[32];
1870 int new_mission_num, anarchy_only = 0;
1872 new_mission_num = multi_choose_mission(&anarchy_only);
1874 if (new_mission_num < 0)
1877 strcpy(my_sync.mission_name, Mission_list[new_mission_num].filename);
1880 sprintf(level, "1");
1882 Game_mode &= ~GM_MULTI_COOP;
1883 Game_mode &= ~GM_MULTI_ROBOTS;
1884 Game_mode &= ~GM_CAPTURE;
1887 Netgame.game_flags = 0;
1888 SetAllAllowablesTo(1);
1890 sprintf(level_text, "%s (1-%d)", TXT_LEVEL_, Last_level);
1891 // if (Last_secret_level < -1)
1892 // sprintf(level_text+strlen(level_text)-1, ", S1-S%d)", -Last_secret_level);
1893 // else if (Last_secret_level == -1)
1894 // sprintf(level_text+strlen(level_text)-1, ", S1)");
1896 Assert(strlen(level_text) < 32);
1898 // Put up menu for user choices controlling gameplay
1902 m[opt].type = NM_TYPE_TEXT; m[opt].text = level_text; opt++;
1903 m[opt].type = NM_TYPE_INPUT; m[opt].text_len = 4; m[opt].text = level; opt++;
1904 m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_MODE;
1906 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY; m[opt].value=!(Game_mode & GM_MULTI_ROBOTS); m[opt].group = 0; opt++;
1907 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY_W_ROBOTS; m[opt].value=(!(Game_mode & GM_MULTI_COOP) && (Game_mode & GM_MULTI_ROBOTS)); m[opt].group = 0; opt++;
1908 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_COOPERATIVE; m[opt].value=(Game_mode & GM_MULTI_COOP);m[opt].group = 0; opt++;
1909 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Capture the Flag"; m[opt].value=(Game_mode & GM_CAPTURE); m[opt].group = 0; opt++;
1911 m[opt].type = NM_TYPE_SLIDER; m[opt].text = TXT_DIFFICULTY; m[opt].value = Player_default_difficulty; m[opt].min_value = 0; m[opt].max_value = (NDL-1); opt++;
1912 m[opt].type = NM_TYPE_TEXT; m[opt].text = " "; opt ++;
1916 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Marker camera views"; m[opt].value=Netgame.Allow_marker_view; opt++;
1917 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Indestructable lights"; m[opt].value=Netgame.AlwaysLighting; opt++;
1920 m[opt].type = NM_TYPE_MENU; m[opt].text = "Choose objects allowed"; opt++;
1925 // m[opt].type = NM_TYPE_CHECK; m[opt].text = TXT_SHOW_IDS; m[opt].value=0; opt++;
1926 m[opt].type = NM_TYPE_CHECK; m[opt].text = TXT_SHOW_ON_MAP; m[opt].value=0; opt++;
1933 choice = newmenu_do1(NULL, TXT_SERIAL_GAME_SETUP, opt, m, NULL, 1);
1938 if (choice==allow_opt)
1940 network_set_power();
1943 Netgame.Allow_marker_view=m[extraopts_opt].value;
1944 Netgame.AlwaysLighting=m[extraopts_opt+1].value;
1946 if (m[mode_opt].value)
1947 Game_mode &= ~(GM_MULTI_COOP | GM_MULTI_ROBOTS);
1950 nm_messagebox(NULL, 1, TXT_OK, TXT_ONLY_ANARCHY);
1954 else if (anarchy_only) {
1955 if (m[mode_opt+3].value)
1956 Game_mode |= (GM_CAPTURE);
1959 nm_messagebox(NULL, 1, TXT_OK, TXT_ANARCHY_ONLY_MISSION);
1963 else if (m[mode_opt+1].value)
1965 Game_mode &= ~GM_MULTI_COOP;
1966 Game_mode |= GM_MULTI_ROBOTS;
1968 else if (m[mode_opt+2].value)
1969 Game_mode |= (GM_MULTI_COOP | GM_MULTI_ROBOTS);
1970 else if (m[mode_opt+3].value)
1971 Game_mode |= (GM_CAPTURE);
1974 // if (m[options_opt].value)
1975 // Netgame.game_flags |= NETGAME_FLAG_SHOW_ID;
1976 if (m[options_opt].value)
1977 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
1978 if (!strnicmp(level, "s", 1))
1979 start_level_num = -atoi(level+1);
1982 start_level_num = atoi(level);
1984 if ((start_level_num < 1) || (start_level_num > Last_level))
1986 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_LEVEL_OUT_RANGE);
1987 sprintf(level, "1");
1991 Difficulty_level = m[diff_opt].value;
1993 return(1); // Go for game!
1995 return 0; // No game
2001 // Ask the other player if its OK to start now
2006 com_send_choice(SELECTION_STARTGAME);
2008 m[0].type = NM_TYPE_TEXT; m[0].text = TXT_ESC_ABORT;
2010 choice = newmenu_do(NULL, TXT_WAIT_FOR_OK, 1, m, com_menu_poll);
2014 com_send_choice(SELECTION_STARTGAME_ABORT);
2019 if (other_menu_choice == SELECTION_YES_START)
2021 else if (other_menu_choice == SELECTION_STARTGAME)
2023 com_send_choice(SELECTION_YES_START);
2036 // Start a serial game after being linked
2038 mprintf((0, "Entered com_start_game\n"));
2042 if (! ( (Game_mode & GM_MODEM) || (Game_mode & GM_SERIAL) ) )
2045 Assert (master != -1);
2047 if (other_menu_choice != SELECTION_STARTGAME)
2049 if (!com_ask_to_start())
2053 if (master == 1) // Master chooses options
2055 if (com_start_game_menu())
2058 change_playernum_to(0);
2059 my_sync.level_num = start_level_num;
2060 my_sync.difficulty = Difficulty_level;
2061 my_sync.game_mode = Game_mode;
2062 if (Game_mode & GM_CAPTURE)
2063 my_sync.game_mode |=GM_UNKNOWN;
2064 memcpy(my_sync.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
2065 my_sync.sync_time = control_invul_time;
2066 my_sync.game_flags = Netgame.game_flags;
2067 Netgame.control_invul_time = control_invul_time;
2068 memcpy ((&my_sync.game_flags)+1,(&Netgame.team_vector)+1,4);
2071 if (Game_mode & GM_CAPTURE)
2072 my_sync.game_mode &=GM_UNKNOWN;
2078 change_playernum_to(1);
2079 memcpy(my_sync.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
2081 my_sync.level_num = 1;
2084 if (com_process_mode == COM_PROCESS_NORMAL)
2086 Difficulty_level = other_sync.difficulty;
2087 start_level_num = other_sync.level_num;
2088 Game_mode = other_sync.game_mode;
2089 if (Game_mode & GM_UNKNOWN) // Super HACK! Out of bit fields, doubling up
2091 Game_mode &=~GM_UNKNOWN;
2092 Game_mode |=GM_CAPTURE;
2095 memcpy ((&Netgame.team_vector)+1,(&other_sync.game_flags)+1,4);
2098 Netgame.game_flags = other_sync.game_flags;
2099 Netgame.control_invul_time = other_sync.sync_time;
2100 if (!load_mission_by_name(other_sync.mission_name))
2102 mprintf((0, "Mission not found: %s!\n", other_sync.mission_name));
2103 nm_messagebox(NULL, 1, TXT_OK, TXT_MISSION_NOT_FOUND);
2104 my_sync.sync_id = start_level_num;
2105 serial_sync_abort(0);
2111 if (com_process_mode != COM_PROCESS_NORMAL)
2114 memcpy(Players[OtherPlayer].callsign, other_sync.callsign, CALLSIGN_LEN+1);
2115 Function_mode = FMODE_GAME;
2116 Game_mode &= ~GM_GAME_OVER;
2118 init_player_stats_game();
2119 init_player_stats_level(0);
2120 // Assert(start_level_num > 0);
2121 Assert((start_level_num >= Last_secret_level) && (start_level_num <= Last_level));
2122 StartNewLevel(start_level_num, 0);
2128 // Syncronization functions
2132 serial_sync_abort(int val)
2134 // Send "I got Sync but it was no good!" packet
2136 sendbuf[0] = (char)MULTI_END_SYNC;
2137 sendbuf[1] = Player_num;
2138 sendbuf[2] = (char)val; // Indicated failure
2140 sendbuf[3] = my_sync.sync_id;
2141 com_send_data(sendbuf, 4, 1);
2143 // com_send_data(sendbuf, 3, 1);
2148 com_level_sync(void)
2150 // Send between-level sync stuff
2152 mprintf((0, "entered com_level_sync()\n"));
2154 Function_mode = FMODE_MENU; // Prevent the game loop from running during the menus!
2156 // At this point, the new level is loaded but the extra objects or players have not
2159 my_sync.level_num = Current_level_num;
2160 my_sync.seg_checksum = netmisc_calc_checksum(Segments, (Highest_segment_index+1) * sizeof(segment));
2161 my_sync.kills[0] = kill_matrix[Player_num][0];
2162 my_sync.kills[1] = kill_matrix[Player_num][1];
2163 my_sync.proto_version = MULTI_PROTO_VERSION;
2165 my_sync.killed = Players[Player_num].net_killed_total;
2169 if (Game_mode & GM_MULTI_COOP)
2170 my_sync.difficulty = Player_num;
2172 my_sync.difficulty = rand()%MAX_NUM_NET_PLAYERS; // My starting position
2174 if (com_sync(Current_level_num))
2176 com_process_mode = COM_PROCESS_MENU;
2177 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_NEGOTIATION_FAIL );
2178 longjmp(LeaveGame, 0);
2181 if (my_sync.level_num != other_sync.level_num)
2184 nm_messagebox(TXT_ERROR, 1, TXT_OK, "%s %d\n%s %d", TXT_FATAL_ERROR_LEVEL, my_sync.level_num, TXT_OTHER_LEVEL, other_sync.level_num);
2185 longjmp(LeaveGame, 0);
2188 if (my_sync.seg_checksum != other_sync.seg_checksum)
2191 mprintf((1, "My check %d, other check %d.\n", my_sync.seg_checksum, other_sync.seg_checksum));
2192 nm_messagebox(TXT_ERROR, 1, TXT_OK, "%s %d %s %s%s", TXT_YOUR_LEVEL, my_sync.level_num, TXT_LVL_NO_MATCH, other_sync.callsign, TXT_CHECK_VERSION);
2193 longjmp(LeaveGame, 0);
2196 if (my_sync.proto_version != other_sync.proto_version)
2199 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_DESCENT_NO_MATCH);
2200 longjmp(LeaveGame, 0);
2203 mprintf((0, "My pos = %d, other pos = %d.\n", my_sync.difficulty, other_sync.difficulty));
2205 if ((other_sync.difficulty == my_sync.difficulty) && !master)
2207 // If we chose the same position and I am the slave, choose another
2208 my_sync.difficulty = (my_sync.difficulty+1) % MAX_NUM_NET_PLAYERS;
2211 Objects[Players[OtherPlayer].objnum].pos = Player_init[other_sync.difficulty].pos;
2212 Objects[Players[OtherPlayer].objnum].orient = Player_init[other_sync.difficulty].orient;
2213 obj_relink(Players[OtherPlayer].objnum,Player_init[other_sync.difficulty].segnum);
2214 Objects[Players[OtherPlayer].objnum].type = OBJ_PLAYER;
2216 Objects[Players[Player_num].objnum].pos = Player_init[my_sync.difficulty].pos;
2217 Objects[Players[Player_num].objnum].orient = Player_init[my_sync.difficulty].orient;
2218 obj_relink(Players[Player_num].objnum, Player_init[my_sync.difficulty].segnum);
2219 Objects[Players[Player_num].objnum].type = OBJ_PLAYER;
2221 SerialLastMessage = GameTime;
2223 kill_matrix[OtherPlayer][0] = other_sync.kills[0];
2224 kill_matrix[OtherPlayer][1] = other_sync.kills[1];
2225 Players[Player_num].net_kills_total = kill_matrix[Player_num][OtherPlayer] - kill_matrix[Player_num][Player_num];
2226 Players[OtherPlayer].net_kills_total = kill_matrix[OtherPlayer][Player_num] - kill_matrix[OtherPlayer][OtherPlayer];
2227 // Players[Player_num].net_killed_total = kill_matrix[0][Player_num] + kill_matrix[1][Player_num];
2228 // Players[OtherPlayer].net_killed_total = kill_matrix[0][OtherPlayer] + kill_matrix[1][OtherPlayer];
2229 Players[OtherPlayer].net_killed_total = other_sync.killed;
2230 Players[OtherPlayer].connected = Players[Player_num].connected = 1;
2232 Assert(N_players == 2);
2233 Assert(Player_num != OtherPlayer);
2235 gr_palette_fade_out(gr_palette, 32, 0);
2237 Function_mode = FMODE_GAME;
2238 com_process_mode = COM_PROCESS_NORMAL;
2239 multi_sort_kill_list();
2245 com_send_end_sync(void)
2247 // Send "I got Sync" packet
2249 sendbuf[0] = (char)MULTI_END_SYNC;
2250 sendbuf[1] = Player_num;
2251 sendbuf[2] = 1; // Indicates success
2253 sendbuf[3] = my_sync.sync_id;
2254 com_send_data(sendbuf, 4, 2);
2256 // com_send_data(sendbuf, 3, 2);
2261 com_send_begin_sync(void)
2263 mprintf((0, "Sending my sync.\n"));
2264 com_send_data((char *)&my_sync, sizeof(com_sync_pack)-3, 1);
2268 com_process_end_sync(byte *buf)
2270 // Process incoming end-sync packet
2273 com_process_mode = COM_PROCESS_MENU;
2278 if (buf[3] == my_sync.sync_id)
2284 com_process_sync(char *buf, int len)
2286 mprintf ((0,"Processing sync!"));
2291 case MULTI_END_SYNC:
2293 com_process_end_sync(buf);
2296 case MULTI_BEGIN_SYNC:
2298 mprintf((0, "Incoming begin_sync message.\n"));
2302 memcpy(&other_sync, buf, sizeof(com_sync_pack)-3);
2304 if (other_sync.sync_id != my_sync.sync_id)
2306 mprintf((0, "Other sync invalid id, %d != %d.\n", other_sync.sync_id, my_sync.sync_id));
2311 mprintf((0, "got other sync size %d.\n", sizeof(com_sync_pack)-3));
2313 com_send_end_sync();
2319 if (got_sync && other_got_sync)
2322 mprintf((1, "Starting game.\n"));
2325 com_process_mode = COM_PROCESS_NORMAL;
2332 // Send sync information, depending on the situation
2334 if (!other_got_sync)
2336 com_send_begin_sync();
2340 com_send_end_sync();
2345 void com_sync_poll(int nitems, newmenu_item *menus, int *key, int citem)
2359 if (timer_get_approx_seconds() > t1+F1_0)
2362 t1 = timer_get_approx_seconds();
2365 Assert(com_process_mode == COM_PROCESS_SYNC);
2367 com_process_input();
2369 if (com_process_mode == COM_PROCESS_NORMAL)
2373 mprintf((0, "Sync finished.\n"));
2376 if (com_process_mode == COM_PROCESS_MENU)
2379 mprintf((0, "Sync denied by other side.\n"));
2388 // How to handle the end of the level and start of the next level
2389 // returns 0 for success or 1 for failure
2395 mprintf((0, "Entered com_sync\n"));
2397 //@@gr_set_current_canvas(NULL);
2398 //@@pcx_error = pcx_read_bitmap(Menu_pcx_name, &grd_curcanv->cv_bitmap,grd_curcanv->cv_bitmap.bm_type,NULL);
2399 //@@Assert(pcx_error == PCX_ERROR_NONE);
2401 com_process_mode = COM_PROCESS_SYNC;
2402 got_sync = other_got_sync = 0;
2408 my_sync.sync_id = id;
2411 m[0].type=NM_TYPE_TEXT; m[0].text=TXT_ESC_ABORT;
2412 m[1].type = m[2].type = NM_TYPE_MENU;
2413 m[1].text = TXT_YES;
2417 choice = newmenu_do(NULL, TXT_WAIT_OPPONENT, 1, m, com_sync_poll);
2421 choice = newmenu_do1(NULL, TXT_SURE_ABORT_SYNC, 2, m+1, com_sync_poll, 1);
2428 if ((choice == -1) || (choice == -3)) {
2431 else if (choice != -2)
2438 com_endlevel(int *secret)
2440 // What do we do between levels?
2442 Function_mode = FMODE_MENU;
2444 gr_palette_fade_out(gr_palette, 32, 0);
2446 my_sync.level_num = multi_goto_secret;
2450 com_process_mode = COM_PROCESS_MENU;
2451 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_NEGOTIATION_FAIL);
2452 longjmp(LeaveGame, 0);
2455 com_process_mode = COM_PROCESS_ENDLEVEL;
2457 if ((multi_goto_secret == 1) || (other_sync.level_num == 1))
2462 multi_goto_secret = 0;
2470 int ReadModemList ()
2472 int num=0,i=0,namemode=1;
2476 if ((MyFile=fopen ("modem.lst","rb"))==NULL)
2479 ModemNames[num][0] = ModemStrings[num][0] = 0;
2481 while (!feof(MyFile))
2485 mprintf ((0,"%c",c));
2496 ModemStrings[num][i]=0;
2499 if (strlen(ModemNames[num]) && strlen(ModemStrings[num]))
2501 if (num >= MAX_MODEMS)
2502 break; //too many! abort!
2503 ModemNames[num][0] = ModemStrings[num][0] = 0;
2507 while (fgetc(MyFile)!=10)
2512 else if (c=='=' && namemode)
2514 ModemNames[num][i]=0;
2522 if (i<MODEM_NAME_LEN)
2523 ModemNames[num][i++]=c;
2527 if (i<INIT_STRING_LEN)
2528 ModemStrings[num][i++]=c;
2533 ModemStrings[num][i]=0; //terminate in case no final newline
2539 void com_choose_string ()
2542 newmenu_item m[MAX_MODEMS];
2544 if ((num=ReadModemList())==0)
2546 nm_messagebox ("Error",1,TXT_OK,"No valid modem file found!");
2550 mprintf ((0,"Number of strings=%d\n",num));
2555 m[i].type = NM_TYPE_MENU; m[i].text = &ModemNames[i];
2556 mprintf ((0,"Text(%d)=%s\n",i,ModemNames[i]));
2558 choice = newmenu_do(NULL, "Choose a modem", num, m, NULL);
2563 strcpy (ModemInitString,ModemStrings[choice]);