configuration fixes
[btb/d2x.git] / main / kmatrix.c
1 /*
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.
12 */
13
14
15 #ifdef RCS
16 static char rcsid[] = "$Id: kmatrix.c,v 1.2 2001-01-20 13:49:16 bradleyb Exp $";
17 #endif
18
19 #include <conf.h>
20
21 #ifdef NETWORK
22
23 #ifdef WINDOWS
24 #include "desw.h"
25 #endif
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <ctype.h>
31 #include <stdarg.h>
32
33 #include "pa_enabl.h"       //$$POLY_ACC
34 #include "error.h"
35 #include "pstypes.h"
36 #include "gr.h"
37 #include "mono.h"
38 #include "key.h"
39 #include "palette.h"
40 #include "game.h"
41 #include "gamefont.h"
42 #include "u_mem.h"
43 #include "newmenu.h"
44 #include "menu.h"
45 #include "player.h"
46 #include "screens.h"
47 #include "gamefont.h"
48 #include "cntrlcen.h"
49 #include "mouse.h"
50 #include "joy.h"
51 #include "timer.h"
52 #include "text.h"
53 #include "songs.h"
54 #include "multi.h"
55 #include "kmatrix.h"
56 #include "gauges.h"
57 #include "pcx.h"
58 #include "network.h"
59
60 #if defined(POLY_ACC)
61 #include "poly_acc.h"
62 #endif
63
64 #define CENTERING_OFFSET(x) ((300 - (70 + (x)*25 ))/2)
65 #define CENTERSCREEN (MenuHires?320:160)
66
67 int kmatrix_kills_changed = 0;
68 char ConditionLetters[]={' ','P','E','D','E','E','V','W'};
69 char WaitingForOthers=0;
70
71 int Kmatrix_nomovie_message=0;
72
73 extern char MaxPowerupsAllowed[],PowerupsInMine[];
74
75 void kmatrix_reactor (char *message);
76 void kmatrix_phallic ();
77 void kmatrix_redraw_coop();
78
79 #define LHX(x)          ((x)*(MenuHires?2:1))
80 #define LHY(y)          ((y)*(MenuHires?2.4:1))
81  
82 void kmatrix_draw_item( int  i, int *sorted )
83 {
84         int j, x, y;
85         char temp[10];
86
87         y = LHY(50+i*9);
88
89         // Print player name.
90
91         gr_printf( LHX(CENTERING_OFFSET(N_players)), y, "%s", Players[sorted[i]].callsign );
92
93    if (!((Game_mode & GM_MODEM) || (Game_mode & GM_SERIAL)))
94            gr_printf (LHX(CENTERING_OFFSET(N_players)-15),y,"%c",ConditionLetters[Players[sorted[i]].connected]);
95     
96         for (j=0; j<N_players; j++) {
97
98                 x = LHX(70 + CENTERING_OFFSET(N_players) + j*25);
99
100                 if (sorted[i]==sorted[j]) {
101                         if (kill_matrix[sorted[i]][sorted[j]] == 0) {
102                                 gr_set_fontcolor( BM_XRGB(10,10,10),-1 );
103                                 gr_printf( x, y, "%d", kill_matrix[sorted[i]][sorted[j]] );
104                         } else {
105                                 gr_set_fontcolor( BM_XRGB(25,25,25),-1 );
106                                 gr_printf( x, y, "-%d", kill_matrix[sorted[i]][sorted[j]] );
107                         }
108                 } else {
109                         if (kill_matrix[sorted[i]][sorted[j]] <= 0) {
110                                 gr_set_fontcolor( BM_XRGB(10,10,10),-1 );
111                                 gr_printf( x, y, "%d", kill_matrix[sorted[i]][sorted[j]] );
112                         } else {
113                                 gr_set_fontcolor( BM_XRGB(25,25,25),-1 );
114                                 gr_printf( x, y, "%d", kill_matrix[sorted[i]][sorted[j]] );
115                         }
116                 }
117
118         }
119
120   if (Players[sorted[i]].net_killed_total+Players[sorted[i]].net_kills_total==0)
121         sprintf (temp,"NA");
122   else
123    sprintf (temp,"%d%%",(int)((float)((float)Players[sorted[i]].net_kills_total/((float)Players[sorted[i]].net_killed_total+(float)Players[sorted[i]].net_kills_total))*100.0));                
124                 
125         x = LHX(60 + CENTERING_OFFSET(N_players) + N_players*25);
126         gr_set_fontcolor( BM_XRGB(25,25,25),-1 );
127         gr_printf( x ,y,"%4d/%s",Players[sorted[i]].net_kills_total,temp);
128 }
129
130 void kmatrix_draw_coop_item( int  i, int *sorted )
131 {
132         int  x, y;
133
134         y = LHY(50+i*9);
135
136         // Print player name.
137
138         gr_printf( LHX(CENTERING_OFFSET(N_players)), y, "%s", Players[sorted[i]].callsign );
139    gr_printf (LHX(CENTERING_OFFSET(N_players)-15),y,"%c",ConditionLetters[Players[sorted[i]].connected]);
140     
141
142         x = CENTERSCREEN;
143
144         gr_set_fontcolor( BM_XRGB(60,40,10),-1 );
145         gr_printf( x, y, "%d", Players[sorted[i]].score );
146
147         x = CENTERSCREEN+LHX(50);
148
149         gr_set_fontcolor( BM_XRGB(60,40,10),-1 );
150         gr_printf( x, y, "%d", Players[sorted[i]].net_killed_total);
151 }
152
153
154 void kmatrix_draw_names(int *sorted)
155 {
156         int j, x;
157         
158         int color;
159
160    if (Kmatrix_nomovie_message)
161     {
162                 gr_set_fontcolor( BM_XRGB(63,0,0),-1 );
163                 gr_printf( CENTERSCREEN-LHX(40), LHY(20), "(Movie not played)");
164          }
165
166         for (j=0; j<N_players; j++) {
167                 if (Game_mode & GM_TEAM)
168                         color = get_team(sorted[j]);
169                 else
170                         color = sorted[j];
171
172                 x = LHX (70 + CENTERING_OFFSET(N_players) + j*25);
173
174       if (Players[sorted[j]].connected==0)
175         gr_set_fontcolor(gr_find_closest_color(31,31,31),-1);
176       else
177         gr_set_fontcolor(gr_getcolor(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b),-1 );
178
179                 gr_printf( x, LHY(40), "%c", Players[sorted[j]].callsign[0] );
180
181         }
182
183         x = LHX(72 + CENTERING_OFFSET(N_players) + N_players*25);
184         gr_set_fontcolor( BM_XRGB(31,31,31),-1 );
185         gr_printf( x, LHY(40), "K/E");
186                 
187 }
188 void kmatrix_draw_coop_names(int *sorted)
189 {
190         sorted=sorted;
191
192    if (Kmatrix_nomovie_message)
193     {
194                 gr_set_fontcolor( BM_XRGB(63,0,0),-1 );
195                 gr_printf( CENTERSCREEN-LHX(40), LHY(20), "(Movie not played)");
196          }
197
198         gr_set_fontcolor( BM_XRGB(63,31,31),-1 );
199         gr_printf( CENTERSCREEN, LHY(40), "SCORE");
200
201         gr_set_fontcolor( BM_XRGB(63,31,31),-1 );
202         gr_printf( CENTERSCREEN+LHX(50), LHY(40), "DEATHS");
203 }
204
205
206 void kmatrix_draw_deaths(int *sorted)
207 {
208         int y,x;
209         char reactor_message[50];
210
211    sorted=sorted;
212
213    y = LHY(55 + 72 + 35);
214         x = LHX(35);
215
216         {
217           
218                 int sw, sh, aw;
219                                         
220       gr_set_fontcolor(gr_find_closest_color(63,20,0),-1);
221       gr_get_string_size("P-Playing E-Escaped D-Died", &sw, &sh, &aw); 
222
223            if (!((Game_mode & GM_MODEM) || (Game_mode & GM_SERIAL)))
224                    gr_printf( CENTERSCREEN-(sw/2), y,"P-Playing E-Escaped D-Died");
225    
226       y+=(sh+5);
227            gr_get_string_size("V-Viewing scores W-Waiting", &sw, &sh, &aw); 
228
229            if (!((Game_mode & GM_MODEM) || (Game_mode & GM_SERIAL)))
230                    gr_printf( CENTERSCREEN-(sw/2), y,"V-Viewing scores W-Waiting");
231
232         }
233
234    y+=LHY(20);
235
236         {
237                 int sw, sh, aw;
238       gr_set_fontcolor(gr_find_closest_color(63,63,63),-1);
239
240       if (Players[Player_num].connected==7)
241        {
242         gr_get_string_size("Waiting for other players...",&sw, &sh, &aw); 
243         gr_printf( CENTERSCREEN-(sw/2), y,"Waiting for other players...");
244        }
245       else
246        {
247         gr_get_string_size(TXT_PRESS_ANY_KEY2, &sw, &sh, &aw); 
248         gr_printf( CENTERSCREEN-(sw/2), y, TXT_PRESS_ANY_KEY2);
249        }
250         }
251
252   if (Countdown_seconds_left <=0)
253    kmatrix_reactor(TXT_REACTOR_EXPLODED);
254   else
255    {
256      sprintf((char *)&reactor_message, "%s: %d %s  ", TXT_TIME_REMAINING, Countdown_seconds_left, TXT_SECONDS);
257      kmatrix_reactor ((char *)&reactor_message);
258    }
259   
260   if (Game_mode & GM_HOARD)  
261           kmatrix_phallic();
262
263 }
264 void kmatrix_draw_coop_deaths(int *sorted)
265 {
266         int j, x, y;
267         char reactor_message[50];
268         
269         y = LHY(55 + N_players * 9);
270
271 //      gr_set_fontcolor(gr_getcolor(player_rgb[j].r,player_rgb[j].g,player_rgb[j].b),-1 );
272         gr_set_fontcolor( BM_XRGB(31,31,31),-1 );
273
274         x = CENTERSCREEN+LHX(50);
275         gr_printf( x, y, TXT_DEATHS );
276
277         for (j=0; j<N_players; j++) {
278                 x = CENTERSCREEN+LHX(50);
279                 gr_printf( x, y, "%d", Players[sorted[j]].net_killed_total );
280         }
281
282    y = LHY(55 + 72 + 35);
283         x = LHX(35);
284
285         {
286           
287                 int sw, sh, aw;
288
289       gr_set_fontcolor(gr_find_closest_color(63,20,0),-1);
290       gr_get_string_size("P-Playing E-Escaped D-Died", &sw, &sh, &aw); 
291
292           if (!((Game_mode & GM_MODEM) || (Game_mode & GM_SERIAL)))
293               gr_printf( CENTERSCREEN-(sw/2), y,"P-Playing E-Escaped D-Died");
294            
295    
296       y+=(sh+5);
297            gr_get_string_size("V-Viewing scores W-Waiting", &sw, &sh, &aw); 
298
299            if (!((Game_mode & GM_MODEM) || (Game_mode & GM_SERIAL)))
300                gr_printf( CENTERSCREEN-(sw/2), y,"V-Viewing scores W-Waiting");
301
302         }
303
304    y+=LHY(20);
305
306         {
307                 int sw, sh, aw;
308       gr_set_fontcolor(gr_find_closest_color(63,63,63),-1);
309
310       if (Players[Player_num].connected==7)
311        {
312         gr_get_string_size("Waiting for other players...",&sw, &sh, &aw); 
313         gr_printf( CENTERSCREEN-(sw/2), y,"Waiting for other players...");
314        }
315       else
316        {
317         gr_get_string_size(TXT_PRESS_ANY_KEY2, &sw, &sh, &aw); 
318         gr_printf( CENTERSCREEN-(sw/2), y, TXT_PRESS_ANY_KEY2);
319        }
320         }
321
322   if (Countdown_seconds_left <=0)
323    kmatrix_reactor(TXT_REACTOR_EXPLODED);
324   else
325    {
326      sprintf((char *)&reactor_message, "%s: %d %s  ", TXT_TIME_REMAINING, Countdown_seconds_left, TXT_SECONDS);
327      kmatrix_reactor ((char *)&reactor_message);
328    }
329
330 }
331
332 void kmatrix_reactor (char *message)
333  {
334   static char oldmessage[50]={0};
335   int sw, sh, aw;
336
337   if ((Game_mode & GM_MODEM) || (Game_mode & GM_SERIAL))
338         return;
339
340   grd_curcanv->cv_font = SMALL_FONT;
341
342   if (oldmessage[0]!=0)
343    {
344     gr_set_fontcolor(gr_find_closest_color(0,0,0),-1);
345     gr_get_string_size(oldmessage, &sw, &sh, &aw); 
346    // gr_printf( CENTERSCREEN-(sw/2), LHY(55+72+12), oldmessage);
347    }
348   gr_set_fontcolor(gr_find_closest_color(0,32,63),-1);
349   gr_get_string_size(message, &sw, &sh, &aw); 
350   gr_printf( CENTERSCREEN-(sw/2), LHY(55+72+12), message);
351
352   strcpy ((char *)&oldmessage,message);
353  }
354
355 extern int PhallicLimit,PhallicMan;
356
357 void kmatrix_phallic ()
358  {
359   int sw, sh, aw;
360   char message[80];
361
362   if (!(Game_mode & GM_HOARD))
363         return;
364
365   if ((Game_mode & GM_MODEM) || (Game_mode & GM_SERIAL))
366         return;
367   
368   if (PhallicMan==-1)
369         strcpy (message,"There was no record set for this level.");
370   else
371         sprintf (message,"%s had the best record at %d points.",Players[PhallicMan].callsign,PhallicLimit);
372
373   grd_curcanv->cv_font = SMALL_FONT;
374   gr_set_fontcolor(gr_find_closest_color(63,63,63),-1);
375   gr_get_string_size(message, &sw, &sh, &aw); 
376   gr_printf( CENTERSCREEN-(sw/2), LHY(55+72+3), message);
377  }
378
379  
380 void load_stars(void);
381
382 WINDOS(dd_grs_canvas *StarBackCanvas,
383                         grs_canvas *StarBackCanvas
384 );              //,*SaveCanvas;
385
386
387 void kmatrix_redraw()
388 {
389         int i, color;
390         int sorted[MAX_NUM_NET_PLAYERS];
391 WINDOS(
392         dd_grs_canvas *tempcanvas,
393    grs_canvas *tempcanvas
394 );
395    
396    if (Game_mode & GM_MULTI_COOP)
397          {
398           kmatrix_redraw_coop();
399           return;
400          }
401          
402         multi_sort_kill_list();
403
404         WINDOS(
405            tempcanvas=dd_gr_create_canvas( grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h ),
406         tempcanvas=gr_create_canvas( grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h )
407         );
408
409    WINDOS(
410                 dd_gr_set_current_canvas(tempcanvas),
411                 gr_set_current_canvas (tempcanvas)
412         );
413
414         WINDOS (
415                 dd_gr_blt_notrans(StarBackCanvas, 0,0,0,0, tempcanvas,0,0,0,0),
416                 gr_bitmap (0,0,&StarBackCanvas->cv_bitmap)
417         );
418
419 WIN(DDGRLOCK(dd_grd_curcanv));
420         grd_curcanv->cv_font = MEDIUM3_FONT;
421
422         gr_string( 0x8000, LHY(10), TXT_KILL_MATRIX_TITLE       );
423
424         grd_curcanv->cv_font = SMALL_FONT;
425
426         multi_get_kill_list(sorted);
427
428         kmatrix_draw_names(sorted);
429
430         for (i=0; i<N_players; i++ )            {
431 //              mprintf((0, "Sorted kill list pos %d = %d.\n", i+1, sorted[i]));
432
433                 if (Game_mode & GM_TEAM)
434                         color = get_team(sorted[i]);
435                 else
436                         color = sorted[i];
437
438      if (Players[sorted[i]].connected==0)
439        gr_set_fontcolor(gr_find_closest_color(31,31,31),-1);
440      else
441        gr_set_fontcolor(gr_getcolor(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b),-1 );
442
443      kmatrix_draw_item( i, sorted );
444         }
445
446         kmatrix_draw_deaths(sorted);
447 WIN(DDGRUNLOCK(dd_grd_curcanv));
448
449 WINDOS(
450         dd_gr_set_current_canvas(NULL),
451         gr_set_current_canvas(NULL)
452 );
453
454 #if defined(POLY_ACC)
455     pa_save_clut();
456     pa_update_clut(gr_palette, 0, 256, 0);
457 #endif
458
459 PA_DFX (pa_set_frontbuffer_current());
460
461 WINDOS(
462         dd_gr_blt_notrans(tempcanvas, 0,0,0,0, dd_grd_curcanv, 0,0,0,0),
463         gr_bitmap (0,0,&tempcanvas->cv_bitmap)
464 );
465
466 PA_DFX (pa_set_backbuffer_current());
467
468 #if defined(POLY_ACC)
469     pa_restore_clut();
470 #endif
471
472         gr_palette_load(gr_palette);
473 WINDOS(
474         dd_gr_free_canvas(tempcanvas),
475         gr_free_canvas (tempcanvas)
476 );
477 }
478
479 void kmatrix_redraw_coop()
480 {
481         int i, color;
482         int sorted[MAX_NUM_NET_PLAYERS];
483
484 WINDOS(
485         dd_grs_canvas *tempcanvas,
486         grs_canvas *tempcanvas
487 );
488         
489         multi_sort_kill_list();
490
491 WINDOS(
492    tempcanvas=dd_gr_create_canvas( grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h ),
493    tempcanvas=gr_create_canvas( grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h )
494 );
495 WINDOS(
496         dd_gr_set_current_canvas(tempcanvas),
497    gr_set_current_canvas (tempcanvas)
498 );
499
500 WINDOS (
501         dd_gr_blt_notrans(StarBackCanvas, 0,0,0,0, tempcanvas,0,0,0,0),
502         gr_bitmap (0,0,&StarBackCanvas->cv_bitmap)
503 );
504
505
506
507 WIN(DDGRLOCK(dd_grd_curcanv));
508         grd_curcanv->cv_font = MEDIUM3_FONT;
509         gr_string( 0x8000, LHY(10), "COOPERATIVE SUMMARY"       );
510
511         grd_curcanv->cv_font = SMALL_FONT;
512
513         multi_get_kill_list(sorted);
514
515         kmatrix_draw_coop_names(sorted);
516
517         for (i=0; i<N_players; i++ )            {
518
519      color = sorted[i];
520
521      if (Players[sorted[i]].connected==0)
522        gr_set_fontcolor(gr_find_closest_color(31,31,31),-1);
523      else
524        gr_set_fontcolor(gr_getcolor(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b),-1 );
525
526      kmatrix_draw_coop_item( i, sorted );
527         }
528
529         kmatrix_draw_deaths(sorted);
530 WIN(DDGRUNLOCK(dd_grd_curcanv));
531
532 WINDOS(
533         dd_gr_set_current_canvas(NULL),
534         gr_set_current_canvas(NULL)
535 );
536
537 #if defined(POLY_ACC)
538     pa_save_clut();
539     pa_update_clut(gr_palette, 0, 256, 0);
540 #endif
541
542 PA_DFX (pa_set_frontbuffer_current());
543
544 WINDOS(
545         dd_gr_blt_notrans(tempcanvas, 0,0,0,0, dd_grd_curcanv, 0,0,0,0),
546         gr_bitmap (0,0,&tempcanvas->cv_bitmap)
547 );
548
549 PA_DFX (pa_set_backbuffer_current());
550
551 #if defined(POLY_ACC)
552     pa_restore_clut();
553 #endif
554
555         gr_palette_load(gr_palette);
556 WINDOS(
557         dd_gr_free_canvas(tempcanvas),
558         gr_free_canvas (tempcanvas)
559 );
560 }
561
562 #define MAX_VIEW_TIME   F1_0*15
563 #define ENDLEVEL_IDLE_TIME      F1_0*10
564
565 fix StartAbortMenuTime;
566
567
568 #ifdef MACINTOSH
569 extern void load_stars_palette();
570 #endif
571
572 extern void network_endlevel_poll3( int nitems, struct newmenu_item * menus, int * key, int citem );
573
574 void kmatrix_view(int network)
575 {                                                                                         
576    int i, k, done,choice;
577         fix entry_time = timer_get_approx_seconds();
578         int key;
579    int oldstates[MAX_PLAYERS];
580    int previous_seconds_left=-1;
581    int num_ready,num_escaped;
582
583         network=Game_mode & GM_NETWORK;
584  
585    for (i=0;i<MAX_NUM_NET_PLAYERS;i++)
586         digi_kill_sound_linked_to_object (Players[i].objnum);
587         
588    set_screen_mode( SCREEN_MENU );
589
590         WINDOS(
591                 StarBackCanvas=dd_gr_create_canvas( grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h ),
592                 StarBackCanvas=gr_create_canvas( grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h )
593         );
594         WINDOS(
595                 dd_gr_set_current_canvas(StarBackCanvas),
596            gr_set_current_canvas(StarBackCanvas)
597         );
598         #ifdef MACINTOSH
599         if (virtual_memory_on) {
600                 load_stars_palette();           // horrible hack to prevent too much paging when doing endlevel syncing
601                 gr_clear_canvas( BM_XRGB(0, 0, 0) );
602         } else
603         #endif                                                  // note link to above if/else pair
604                 load_stars();
605    
606    WaitingForOthers=0;
607    kmatrix_redraw();
608
609         //@@gr_palette_fade_in( gr_palette,32, 0);
610         game_flush_inputs();
611
612         done = 0;
613
614    for (i=0;i<N_players;i++)
615     oldstates[i]=Players[i].connected;
616
617         if (network)
618            network_endlevel(&key);
619
620         while(!done)    {
621         #ifdef WINDOWS
622                 MSG msg;
623
624                 DoMessageStuff(&msg);
625
626                 DDGRRESTORE;
627
628         #endif
629
630       kmatrix_kills_changed = 0;
631       for (i=0; i<4; i++ ) 
632           if (joy_get_button_down_cnt(i)>0) 
633                           {  
634                                   #if defined (D2_OEM)
635                                          if (Current_level_num==8)
636                                                 {
637                         Players[Player_num].connected=0;
638                                                  if (network)
639                                 network_send_endlevel_packet();
640                                                 WINDOS(
641                                                         dd_gr_free_canvas(StarBackCanvas),
642                                                    gr_free_canvas (StarBackCanvas)
643                                                 );
644                                             multi_leave_game();
645                                        Kmatrix_nomovie_message=0;
646                                        longjmp(LeaveGame, 0); 
647                         return;
648                                                 }
649                                   #endif
650                 
651             Players[Player_num].connected=7;
652                                 if (network)
653                  network_send_endlevel_packet();
654                                 break;
655                           }                     
656         for (i=0; i<3; i++ )    
657           if (mouse_button_down_count(i)>0) 
658                                 {
659                                   #if defined (D2_OEM)
660                                          if (Current_level_num==8)
661                                                 {
662                         Players[Player_num].connected=0;
663                                                  if (network)
664                                 network_send_endlevel_packet();
665                                                 WINDOS(
666                                                         dd_gr_free_canvas(StarBackCanvas),
667                                                    gr_free_canvas (StarBackCanvas)
668                                                 );
669                                             multi_leave_game();
670                                        Kmatrix_nomovie_message=0;
671                                        longjmp(LeaveGame, 0); 
672                         return;
673                                                 }
674                                   #endif
675                                         Players[Player_num].connected=7;
676                                    if (network)
677                        network_send_endlevel_packet();
678                                         break;
679                       }                 
680
681                 //see if redbook song needs to be restarted
682                 songs_check_redbook_repeat();
683
684                 k = key_inkey();
685                 switch( k )     {
686                         case KEY_ENTER:
687                         case KEY_SPACEBAR:
688                                   if ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM))                
689                                         {
690                                                 done=1;
691                                                 break;
692                                         }
693                                         
694                                   #if defined (D2_OEM)
695                                          if (Current_level_num==8)
696                                                 {
697                         Players[Player_num].connected=0;
698                                                  if (network)
699                                 network_send_endlevel_packet();
700                                                 WINDOS(
701                                                         dd_gr_free_canvas(StarBackCanvas),
702                                                    gr_free_canvas (StarBackCanvas)
703                                                 );
704                                             multi_leave_game();
705                                        Kmatrix_nomovie_message=0;
706                                        longjmp(LeaveGame, 0); 
707                         return;
708                                                 }
709                                   #endif
710                 
711               Players[Player_num].connected=7;
712                                   if (network)  
713                network_send_endlevel_packet();
714               break;
715                         case KEY_ESC:
716                                   if (Game_mode & GM_NETWORK)
717                                         {
718                                          StartAbortMenuTime=timer_get_approx_seconds();
719                                  choice=nm_messagebox1( NULL,network_endlevel_poll3, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
720                                         }
721                                   else
722                           choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
723               if (choice==0)
724                {
725                 Players[Player_num].connected=0;
726                                          if (network)
727                         network_send_endlevel_packet();
728                                                 WINDOS(
729                                                         dd_gr_free_canvas(StarBackCanvas),
730                                                    gr_free_canvas (StarBackCanvas)
731                                                 );
732                                     multi_leave_game();
733                                Kmatrix_nomovie_message=0;
734                                longjmp(LeaveGame, 0); 
735                 return;
736                }
737               else
738                kmatrix_kills_changed=1;
739            
740                                   break;
741
742                         case KEY_PRINT_SCREEN:
743                                 save_screen_shot(0);
744                                 break;
745                         case KEY_BACKSP:
746                                 Int3();
747                                 break;
748                         default:
749                                 break;
750                 }
751                 if (timer_get_approx_seconds() >= (entry_time+MAX_VIEW_TIME) && Players[Player_num].connected!=7)
752                         {
753                                   #if defined (D2_OEM)
754                                          if (Current_level_num==8)
755                                                 {
756                         Players[Player_num].connected=0;
757                                                  if (network)
758                                 network_send_endlevel_packet();
759                                                 WINDOS(
760                                                         dd_gr_free_canvas(StarBackCanvas),
761                                                    gr_free_canvas (StarBackCanvas)
762                                                 );
763                                             multi_leave_game();
764                                        Kmatrix_nomovie_message=0;
765                                        longjmp(LeaveGame, 0); 
766                         return;
767                                                 }
768                                   #endif
769                 
770                          if ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM))         
771                                 {
772                                         done=1;
773                                         break;
774                                 }
775           Players[Player_num].connected=7;
776                          if (network)
777                   network_send_endlevel_packet();
778                    }     
779
780                 if (network && (Game_mode & GM_NETWORK))
781                 {
782         network_endlevel_poll2(0, NULL, &key, 0);
783                        
784         for (num_escaped=0,num_ready=0,i=0;i<N_players;i++)
785           {
786             if (Players[i].connected && i!=Player_num)
787                {
788                 // Check timeout for idle players
789                 if (timer_get_approx_seconds() > LastPacketTime[i]+ENDLEVEL_IDLE_TIME)
790                    {
791                     mprintf((0, "idle timeout for player %d.\n", i));
792                                   Players[i].connected = 0;
793                     network_send_endlevel_sub(i);
794                    }                        
795                 }
796
797                if (Players[i].connected!=oldstates[i])
798                   {
799                    if (ConditionLetters[Players[i].connected]!=ConditionLetters[oldstates[i]])
800                      kmatrix_kills_changed=1;
801                    oldstates[i]=Players[i].connected;
802                                                  network_send_endlevel_packet();
803                   }
804                                         if (Players[i].connected==0 || Players[i].connected==7)
805                                           num_ready++;
806
807                if (Players[i].connected!=1)
808                    num_escaped++;
809           }
810
811          if (num_ready>=N_players)
812              done=1;
813          if (num_escaped>=N_players)
814              Countdown_seconds_left=-1;
815
816          if (previous_seconds_left != Countdown_seconds_left)
817             {
818              previous_seconds_left=Countdown_seconds_left;
819                                  kmatrix_kills_changed=1;
820                                 }
821                                                  
822          if ( kmatrix_kills_changed )    
823             {
824              kmatrix_redraw();
825              kmatrix_kills_changed=0;
826                         }
827
828                 }
829         }
830
831   Players[Player_num].connected=7;
832
833   if (network)  
834      network_send_endlevel_packet();  // make sure
835
836        
837 // Restore background and exit
838         gr_palette_fade_out( gr_palette, 32, 0 );
839
840         game_flush_inputs();
841
842         WINDOS(
843                 dd_gr_free_canvas(StarBackCanvas),
844                 gr_free_canvas (StarBackCanvas)
845         );
846
847    Kmatrix_nomovie_message=0;
848
849 }
850
851 #endif
852