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