home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / titles.c < prev    next >
Text File  |  1998-06-08  |  35KB  |  1,228 lines

  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-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/main/rcs/titles.c $
  15.  * $Revision: 2.10 $
  16.  * $Author: john $
  17.  * $Date: 1995/06/15 12:14:16 $
  18.  * 
  19.  * Routines to display title screens...
  20.  * 
  21.  * $Log: titles.c $
  22.  * Revision 2.10  1995/06/15  12:14:16  john
  23.  * Made end game, win game and title sequences all go
  24.  * on after 5 minutes automatically.
  25.  * 
  26.  * Revision 2.9  1995/06/14  17:25:48  john
  27.  * Fixed bug with VFX palette not getting loaded for credits, titles.
  28.  * 
  29.  * Revision 2.8  1995/05/26  16:16:30  john
  30.  * Split SATURN into define's for requiring cd, using cd, etc.
  31.  * Also started adding all the Rockwell stuff.
  32.  * 
  33.  * Revision 2.7  1995/03/24  13:11:36  john
  34.  * Added save game during briefing screens.
  35.  * 
  36.  * Revision 2.6  1995/03/21  14:41:17  john
  37.  * Ifdef'd out the NETWORK code.
  38.  * 
  39.  * Revision 2.5  1995/03/15  14:33:45  john
  40.  * Added code to force the Descent CD-rom in the drive.
  41.  * 
  42.  * Revision 2.4  1995/03/14  18:24:50  john
  43.  * Force Destination Saturn to use CD-ROM drive.
  44.  * 
  45.  * Revision 2.3  1995/03/10  13:05:52  john
  46.  * Added code so that palette is correct for VFX1 helmets.
  47.  * 
  48.  * Revision 2.2  1995/03/07  14:19:28  mike
  49.  * More destination saturn stuff.
  50.  * 
  51.  * Revision 2.1  1995/03/06  15:24:16  john
  52.  * New screen techniques.
  53.  * 
  54.  * Revision 2.0  1995/02/27  11:32:50  john
  55.  * New version 2.0, which has no anonymous unions, builds with
  56.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  57.  * 
  58.  * Revision 1.95  1995/02/12  04:07:19  matt
  59.  * After freeing Robot_canv, set ptr to NULL
  60.  * 
  61.  * Revision 1.94  1995/02/11  12:41:57  john
  62.  * Added new song method, with FM bank switching..
  63.  * 
  64.  * Revision 1.93  1995/02/11  09:51:59  john
  65.  * Stripped out all SVGA references.
  66.  * 
  67.  * Revision 1.92  1995/02/07  09:56:10  john
  68.  * Fixed bug with wrong title screen drawing during save btwn lvls.
  69.  * 
  70.  * Revision 1.91  1995/02/04  13:53:16  john
  71.  * Added code to display the correct titles between levels
  72.  * that have robot maps..
  73.  * 
  74.  * Revision 1.90  1995/02/02  16:36:33  adam
  75.  * *** empty log message ***
  76.  * 
  77.  * Revision 1.89  1995/02/02  12:23:30  john
  78.  * Made between level saves have picture.
  79.  * 
  80.  * Revision 1.88  1995/02/02  01:50:16  adam
  81.  * rearranged robot briefings.
  82.  * 
  83.  * Revision 1.87  1995/02/01  22:28:54  mike
  84.  * *** empty log message ***
  85.  * 
  86.  * Revision 1.86  1995/02/01  17:12:21  mike
  87.  * Make score come after endgame screens.
  88.  * 
  89.  * Revision 1.85  1995/02/01  14:04:17  adam
  90.  * mucked with screens
  91.  * 
  92.  * Revision 1.84  1995/01/28  16:59:30  adam
  93.  * added hook for special first briefing music
  94.  * 
  95.  * Revision 1.83  1995/01/21  17:04:35  mike
  96.  * fix endgame text bogosity.
  97.  * 
  98.  * Revision 1.82  1995/01/21  16:26:29  matt
  99.  * Made endlevel briefing work with missions
  100.  * 
  101.  * Revision 1.81  1995/01/21  13:15:20  adam
  102.  * added new robot briefings.
  103.  * 
  104.  * Revision 1.80  1995/01/20  22:47:33  matt
  105.  * Mission system implemented, though imcompletely
  106.  * 
  107.  * Revision 1.79  1995/01/20  14:57:52  mike
  108.  * support arbitrary number of screens/level.
  109.  * 
  110.  * Revision 1.78  1995/01/15  14:29:12  john
  111.  * Made the exit door page in.
  112.  * 
  113.  * Revision 1.77  1995/01/15  14:27:09  adam
  114.  * messed with endgame stuff
  115.  * 
  116.  * Revision 1.76  1995/01/14  15:42:49  mike
  117.  * Make endgame for registered support 3 screens.
  118.  * 
  119.  * Revision 1.75  1995/01/14  14:00:59  adam
  120.  * *** empty log message ***
  121.  * 
  122.  * Revision 1.74  1995/01/09  11:28:53  mike
  123.  * Support new $O thingy for bitmaps which cycle and are not the exit door.
  124.  * 
  125.  * Revision 1.73  1995/01/02  12:39:13  mike
  126.  * fix secret level sequencing.
  127.  * 
  128.  * Revision 1.72  1994/12/12  19:44:14  rob
  129.  * Added kill matrix to end of game sequence.
  130.  * 
  131.  * Revision 1.71  1994/12/09  22:32:57  adam
  132.  * messed with text positioning
  133.  * 
  134.  * Revision 1.70  1994/12/09  14:08:37  mike
  135.  * make briefing text work with hog files.
  136.  * 
  137.  * Revision 1.69  1994/12/09  00:41:47  mike
  138.  * fix hang in automap print screen.
  139.  * 
  140.  * Revision 1.68  1994/12/08  20:56:36  john
  141.  * More cfile stuff.
  142.  * 
  143.  * Revision 1.67  1994/12/08  17:19:11  yuan
  144.  * Cfiling stuff.
  145.  * 
  146.  * Revision 1.66  1994/12/07  11:28:00  matt
  147.  * Did a localization suppport
  148.  * 
  149.  * Revision 1.65  1994/12/06  17:10:23  yuan
  150.  * Fixed missing )
  151.  * 
  152.  * Revision 1.64  1994/12/06  17:00:45  rob
  153.  * Fixed problem with finishing the game in modem/serial mode.
  154.  * 
  155.  * Revision 1.63  1994/12/06  16:58:37  matt
  156.  * Killed warnings
  157.  * 
  158.  * Revision 1.62  1994/12/06  15:54:28  mike
  159.  * fix guy at end...
  160.  * 
  161.  */
  162.  
  163. #pragma off (unreferenced)
  164. static char rcsid[] = "$Id: titles.c 2.10 1995/06/15 12:14:16 john Exp $";
  165. #pragma on (unreferenced)
  166.  
  167. #include <stdlib.h>
  168. #include <stdio.h>
  169. #include <string.h>
  170. #include <process.h>
  171. #include <io.h>
  172.  
  173. #include "types.h"
  174. #include "timer.h"
  175. #include "key.h"
  176. #include "gr.h"
  177. #include "palette.h"
  178. #include "iff.h"
  179. #include "pcx.h"
  180. #include "mem.h"
  181. #include "joy.h"
  182. #include "arcade.h"
  183. #include "coindev.h"
  184. #include "mono.h"
  185. #include "gamefont.h"
  186. #include "cfile.h"
  187. #include "mem.h"
  188. #include "error.h"
  189. #include "polyobj.h"
  190. #include "textures.h"
  191. #include "screens.h"
  192. #include "multi.h"
  193. #include "player.h"
  194. #include "digi.h"
  195. #include "compbit.h"
  196. #include "text.h"
  197. #include "kmatrix.h"
  198. #include "piggy.h"
  199. #include "songs.h"
  200. #include "vfx.h"
  201. #include "newmenu.h"
  202. #include "state.h"
  203.  
  204. ubyte New_pal[768];
  205. int    New_pal_254_bash;
  206.  
  207. char    * Briefing_text;
  208.  
  209. #define    MAX_BRIEFING_COLORS    2
  210.  
  211. char Ending_text_filename[13] = "endreg.tex";
  212. char Briefing_text_filename[13] = "briefing.tex";
  213.  
  214. #define    SHAREWARE_ENDING_FILENAME    "ending.tex"
  215.  
  216. //    Can be set by -noscreens command line option.  Causes bypassing of all briefing screens.
  217. int    Skip_briefing_screens=0;
  218. int    Briefing_foreground_colors[MAX_BRIEFING_COLORS], Briefing_background_colors[MAX_BRIEFING_COLORS];
  219. int    Current_color = 0;
  220. int    Erase_color;
  221.  
  222. int local_key_inkey(void)
  223. {
  224.     int    rval;
  225.  
  226.     rval = key_inkey();
  227.  
  228.     if ( rval==KEY_ALTED+KEY_F2 )    {
  229.          title_save_game();
  230.         return 0;
  231.     }
  232.  
  233.     if (rval == KEY_PRINT_SCREEN) {
  234.         save_screen_shot(0);
  235.         return 0;                //say no key pressed
  236.     }
  237.  
  238.     return rval;
  239. }
  240.  
  241. int show_title_screen( char * filename, int allow_keys )    
  242. {
  243.     fix timer;
  244.     int pcx_error;
  245.     grs_bitmap title_bm;
  246.  
  247.     title_bm.bm_data=NULL;
  248.     if ((pcx_error=pcx_read_bitmap( filename, &title_bm, BM_LINEAR, New_pal ))!=PCX_ERROR_NONE)    {
  249.         printf( "File '%s', PCX load error: %s (%i)\n  (No big deal, just no title screen.)\n",filename, pcx_errormsg(pcx_error), pcx_error);
  250.         mprintf((0, "File '%s', PCX load error: %s (%i)\n  (No big deal, just no title screen.)\n",filename, pcx_errormsg(pcx_error), pcx_error));
  251.         Int3();
  252.         return 0;
  253.     }
  254.  
  255.     vfx_set_palette_sub( New_pal );
  256.     gr_palette_clear();    
  257.     gr_set_current_canvas( NULL );
  258.     gr_bitmap( 0, 0, &title_bm );
  259.     if (gr_palette_fade_in( New_pal, 32, allow_keys ))    
  260.         return 1;
  261.  
  262.     gr_palette_load( New_pal );
  263.     timer    = timer_get_fixed_seconds() + i2f(3);
  264.     while (1)    {
  265.         if ( local_key_inkey() && allow_keys ) break;
  266.         if ( timer_get_fixed_seconds() > timer ) break;
  267.  
  268.         #ifdef ARCADE
  269.         {
  270.             int coins;
  271.             coins = coindev_count(0);
  272.             if (coins>0)    {
  273.                 Arcade_timer = F1_0 * ARCADE_FIRST_SECONDS;        // Two minutes to play...
  274.                 if (coins>1)
  275.                     Arcade_timer += F1_0 * ARCADE_CONTINUE_SECONDS*(coins-1);        // Two minutes to play...
  276.                 break;
  277.             }
  278.         }
  279.         #endif
  280.     }            
  281.     if (gr_palette_fade_out( New_pal, 32, allow_keys ))
  282.         return 1;
  283.     free(title_bm.bm_data);
  284.     return 0;
  285. }
  286.  
  287. typedef struct {
  288.     char    bs_name[14];                        //    filename, eg merc01.  Assumes .lbm suffix.
  289.     byte    level_num;
  290.     byte    message_num;
  291.     short    text_ulx, text_uly;             //    upper left x,y of text window
  292.     short    text_width, text_height;     //    width and height of text window
  293. } briefing_screen;
  294.  
  295. #define BRIEFING_SECRET_NUM    31            //    This must correspond to the first secret level which must come at the end of the list.
  296. #define BRIEFING_OFFSET_NUM    4            // This must correspond to the first level screen (ie, past the bald guy briefing screens)
  297.  
  298. //#ifdef SHAREWARE
  299. //#define SHAREWARE_ENDGAME_NUM    11            //    Shareware briefing screen name.
  300. //#else
  301. //#define SHAREWARE_ENDGAME_NUM    34            //    Shareware briefing screen name.
  302. //#define REGISTERED_ENDGAME_NUM    35                    //    Registered briefing screen name.
  303. //#define NUM_REGISTERED_ENDGAME_SCREENS    3            //    Number of registered endgame screens
  304. //#endif
  305.  
  306. #define    SHAREWARE_ENDING_LEVEL_NUM        0x7f
  307. #define    REGISTERED_ENDING_LEVEL_NUM    0x7e
  308.  
  309. briefing_screen Briefing_screens[] = {
  310.     {    "brief01.pcx",   0,  1,  13, 140, 290,  59 },
  311.     {    "brief02.pcx",   0,  2,  27,  34, 257, 177 },
  312.     {    "brief03.pcx",   0,  3,  20,  22, 257, 177 },
  313.     {    "brief02.pcx",   0,  4,  27,  34, 257, 177 },
  314.  
  315.     {    "moon01.pcx",    1,  5,  10,  10, 300, 170 },    // level 1
  316.     {    "moon01.pcx",    2,  6,  10,  10, 300, 170 },    // level 2
  317.     {    "moon01.pcx",    3,  7,  10,  10, 300, 170 },    // level 3
  318.  
  319.     {    "venus01.pcx",   4,  8,  15, 15, 300,  200 },    // level 4
  320.     {    "venus01.pcx",   5,  9,  15, 15, 300,  200 },    // level 5
  321.  
  322.     {    "brief03.pcx",   6, 10,  20,  22, 257, 177 },
  323.     {    "merc01.pcx",    6, 11,  10, 15, 300, 200 },    // level 6
  324.     {    "merc01.pcx",    7, 12,  10, 15, 300, 200 },    // level 7
  325.  
  326. #ifndef SHAREWARE
  327.     {    "brief03.pcx",   8, 13,  20,  22, 257, 177 },
  328.     {    "mars01.pcx",    8, 14,  10, 100, 300,  200 },    // level 8
  329.     {    "mars01.pcx",    9, 15,  10, 100, 300,  200 },    // level 9
  330.     {    "brief03.pcx",  10, 16,  20,  22, 257, 177 },
  331.     {    "mars01.pcx",   10, 17,  10, 100, 300,  200 },    // level 10
  332.  
  333.     {    "jup01.pcx",    11, 18,  10, 40, 300,  200 },    // level 11
  334.     {    "jup01.pcx",    12, 19,  10, 40, 300,  200 },    // level 12
  335.     {    "brief03.pcx",  13, 20,  20,  22, 257, 177 },
  336.     {    "jup01.pcx",    13, 21,  10, 40, 300,  200 },    // level 13
  337.     {    "jup01.pcx",    14, 22,  10, 40, 300,  200 },    // level 14
  338.  
  339.     {    "saturn01.pcx", 15, 23,  10, 40, 300,  200 },    // level 15
  340.     {    "brief03.pcx",  16, 24,  20,  22, 257, 177 },
  341.     {    "saturn01.pcx", 16, 25,  10, 40, 300,  200 },    // level 16
  342.     {    "brief03.pcx",  17, 26,  20,  22, 257, 177 },
  343.     {    "saturn01.pcx", 17, 27,  10, 40, 300,  200 },    // level 17
  344.  
  345.     {    "uranus01.pcx", 18, 28,  100, 100, 300,  200 },    // level 18
  346.     {    "uranus01.pcx", 19, 29,  100, 100, 300,  200 },    // level 19
  347.     {    "uranus01.pcx", 20, 30,  100, 100, 300,  200 },    // level 20
  348.     {    "uranus01.pcx", 21, 31,  100, 100, 300,  200 },    // level 21
  349.  
  350.     {    "neptun01.pcx", 22, 32,  10, 20, 300,  200 },    // level 22
  351.     {    "neptun01.pcx", 23, 33,  10, 20, 300,  200 },    // level 23
  352.     {    "neptun01.pcx", 24, 34,  10, 20, 300,  200 },    // level 24
  353.  
  354.     {    "pluto01.pcx",  25, 35,  10, 20, 300,  200 },    // level 25
  355.     {    "pluto01.pcx",  26, 36,  10, 20, 300,  200 },    // level 26
  356.     {    "pluto01.pcx",  27, 37,  10, 20, 300,  200 },    // level 27
  357.  
  358.     {    "aster01.pcx",  -1, 38,  10, 90, 300,  200 },    // secret level -1
  359.     {    "aster01.pcx",  -2, 39,  10, 90, 300,  200 },    // secret level -2
  360.     {    "aster01.pcx",  -3, 40,  10, 90, 300,  200 },     // secret level -3
  361. #endif
  362.  
  363.     {    "end01.pcx",   SHAREWARE_ENDING_LEVEL_NUM,  1,  23, 40, 320, 200 },     // shareware end
  364. #ifndef SHAREWARE
  365.     {    "end02.pcx",   REGISTERED_ENDING_LEVEL_NUM,  1,  5, 5, 300, 200 },         // registered end
  366.     {    "end01.pcx",   REGISTERED_ENDING_LEVEL_NUM,  2,  23, 40, 320, 200 },         // registered end
  367.     {    "end03.pcx",   REGISTERED_ENDING_LEVEL_NUM,  3,  5, 5, 300, 200 },         // registered end
  368. #endif
  369.  
  370. };
  371.  
  372. #define    MAX_BRIEFING_SCREEN    (sizeof(Briefing_screens) / sizeof(Briefing_screens[0]))
  373.  
  374.  
  375. char * get_briefing_screen( int level_num )
  376. {
  377.     int i, found_level=0, last_level=0;
  378.  
  379.     for (i = 0; i < MAX_BRIEFING_SCREEN; i++)    {
  380.         if ( found_level && Briefing_screens[i].level_num != level_num )
  381.             return Briefing_screens[last_level].bs_name;
  382.         if (Briefing_screens[i].level_num == level_num )    {
  383.             found_level=1;
  384.             last_level = i;
  385.         }
  386.     }
  387.     return NULL;
  388. }
  389.  
  390.  
  391.  
  392.  
  393. int    Briefing_text_x, Briefing_text_y;
  394.  
  395. void init_char_pos(int x, int y)
  396. {
  397.     Briefing_text_x = x;
  398.     Briefing_text_y = y;
  399. }
  400.  
  401. grs_canvas    *Robot_canv = NULL;
  402. vms_angvec    Robot_angles;
  403.  
  404. char    Bitmap_name[32] = "";
  405. #define    EXIT_DOOR_MAX    14
  406. #define    OTHER_THING_MAX    10        //    Adam: This is the number of frames in your new animating thing.
  407. #define    DOOR_DIV_INIT    6
  408. byte    Door_dir=1, Door_div_count=0, Animating_bitmap_type=0;
  409.  
  410. //    -----------------------------------------------------------------------------
  411. void show_bitmap_frame(void)
  412. {
  413.     grs_canvas    *curcanv_save, *bitmap_canv;
  414.     grs_bitmap    *bitmap_ptr;
  415.  
  416.     //    Only plot every nth frame.
  417.     if (Door_div_count) {
  418.         Door_div_count--;
  419.         return;
  420.     }
  421.  
  422.     Door_div_count = DOOR_DIV_INIT;
  423.  
  424.     if (Bitmap_name[0] != 0) {
  425.         char        *pound_signp;
  426.         int        num, dig1, dig2;
  427.  
  428.         //    Set supertransparency color to black
  429.         if (!New_pal_254_bash) {
  430.             New_pal_254_bash = 1;
  431.             New_pal[254*3] = 0;
  432.             New_pal[254*3+1] = 0;
  433.             New_pal[254*3+2] = 0;
  434.             gr_palette_load( New_pal );
  435.             vfx_set_palette_sub( New_pal );
  436.         }
  437.  
  438.         switch (Animating_bitmap_type) {
  439.             case 0:    bitmap_canv = gr_create_sub_canvas(grd_curcanv, 220, 45, 64, 64);    break;
  440.             case 1:    bitmap_canv = gr_create_sub_canvas(grd_curcanv, 220, 45, 94, 94);    break;    //    Adam: Change here for your new animating bitmap thing. 94, 94 are bitmap size.
  441.             default:    Int3();    //    Impossible, illegal value for Animating_bitmap_type
  442.         }
  443.  
  444.         curcanv_save = grd_curcanv;
  445.         grd_curcanv = bitmap_canv;
  446.  
  447.         pound_signp = strchr(Bitmap_name, '#');
  448.         Assert(pound_signp != NULL);
  449.  
  450.         dig1 = *(pound_signp+1);
  451.         dig2 = *(pound_signp+2);
  452.         if (dig2 == 0)
  453.             num = dig1-'0';
  454.         else
  455.             num = (dig1-'0')*10 + (dig2-'0');
  456.  
  457.         switch (Animating_bitmap_type) {
  458.             case 0:
  459.                 num += Door_dir;
  460.                 if (num > EXIT_DOOR_MAX) {
  461.                     num = EXIT_DOOR_MAX;
  462.                     Door_dir = -1;
  463.                 } else if (num < 0) {
  464.                     num = 0;
  465.                     Door_dir = 1;
  466.                 }
  467.                 break;
  468.             case 1:
  469.                 num++;
  470.                 if (num > OTHER_THING_MAX)
  471.                     num = 0;
  472.                 break;
  473.         }
  474.  
  475.         Assert(num < 100);
  476.         if (num >= 10) {
  477.             *(pound_signp+1) = (num / 10) + '0';
  478.             *(pound_signp+2) = (num % 10) + '0';
  479.             *(pound_signp+3) = 0;
  480.         } else {
  481.             *(pound_signp+1) = (num % 10) + '0';
  482.             *(pound_signp+2) = 0;
  483.         }
  484.  
  485.         {
  486.             bitmap_index bi;
  487.             bi = piggy_find_bitmap(Bitmap_name);
  488.             bitmap_ptr = &GameBitmaps[bi.index];
  489.             PIGGY_PAGE_IN( bi );
  490.         }
  491.  
  492.         gr_bitmapm(0, 0, bitmap_ptr);
  493.         grd_curcanv = curcanv_save;
  494.         free(bitmap_canv);
  495.  
  496.         switch (Animating_bitmap_type) {
  497.             case 0:
  498.                 if (num == EXIT_DOOR_MAX) {
  499.                     Door_dir = -1;
  500.                     Door_div_count = 64;
  501.                 } else if (num == 0) {
  502.                     Door_dir = 1;
  503.                     Door_div_count = 64;
  504.                 }
  505.                 break;
  506.             case 1:
  507.                 break;
  508.         }
  509.     }
  510.  
  511. }
  512.  
  513. //    -----------------------------------------------------------------------------
  514. void show_briefing_bitmap(grs_bitmap *bmp)
  515. {
  516.     grs_canvas    *curcanv_save, *bitmap_canv;
  517.  
  518.     bitmap_canv = gr_create_sub_canvas(grd_curcanv, 220, 45, 166, 138);
  519.     curcanv_save = grd_curcanv;
  520.     grd_curcanv = bitmap_canv;
  521.     gr_bitmapm(0, 0, bmp);
  522.     grd_curcanv = curcanv_save;
  523.     free(bitmap_canv);
  524. }
  525.  
  526. //    -----------------------------------------------------------------------------
  527. void show_spinning_robot_frame(int robot_num)
  528. {
  529.     grs_canvas    *curcanv_save;
  530.  
  531.     if (robot_num != -1) {
  532.         Robot_angles.h += 150;
  533.  
  534.         curcanv_save = grd_curcanv;
  535.         grd_curcanv = Robot_canv;
  536.         Assert(Robot_info[robot_num].model_num != -1);
  537.         draw_model_picture(Robot_info[robot_num].model_num, &Robot_angles);
  538.         grd_curcanv = curcanv_save;
  539.     }
  540.  
  541. }
  542.  
  543. //    -----------------------------------------------------------------------------
  544. void init_spinning_robot(void)
  545. {
  546.     Robot_angles.p += 0;
  547.     Robot_angles.b += 0;
  548.     Robot_angles.h += 0;
  549.  
  550.     Robot_canv = gr_create_sub_canvas(grd_curcanv, 138, 55, 166, 138);
  551. }
  552.  
  553. //    -----------------------------------------------------------------------------
  554. void init_briefing_bitmap(void)
  555. {
  556.     Robot_canv = gr_create_sub_canvas(grd_curcanv, 138, 55, 166, 138);
  557. }
  558.  
  559. //    -----------------------------------------------------------------------------
  560. //    Returns char width.
  561. //    If show_robot_flag set, then show a frame of the spinning robot.
  562. int show_char_delay(char the_char, int delay, int robot_num, int cursor_flag)
  563. {
  564.     int    w, h, aw;
  565.     char    message[2];
  566.     fix    start_time;
  567.     int    i;
  568.  
  569.     start_time = timer_get_fixed_seconds();
  570.  
  571.     message[0] = the_char;
  572.     message[1] = 0;
  573.  
  574.     gr_get_string_size(message, &w, &h, &aw );
  575.  
  576.     Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
  577.  
  578.     //    Draw cursor if there is some delay and caller says to draw cursor
  579.     if (cursor_flag && delay) {
  580.         gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
  581.         gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
  582.     }
  583.  
  584.     for (i=0; i<2; i++) {
  585.         if ((robot_num != -1) && (delay != 0))
  586.             show_spinning_robot_frame(robot_num);
  587.         if (delay != 0)
  588.             show_bitmap_frame();
  589.  
  590.         while (timer_get_fixed_seconds() < start_time + delay/2)
  591.             ;
  592.  
  593.         start_time = timer_get_fixed_seconds();
  594.     }
  595.  
  596.     //    Erase cursor
  597.     if (cursor_flag && delay) {
  598.         gr_set_fontcolor(Erase_color, -1);
  599.         gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
  600.     }
  601.  
  602.     //    Draw the character
  603.     gr_set_fontcolor(Briefing_background_colors[Current_color], -1);
  604.     gr_printf(Briefing_text_x, Briefing_text_y, message );
  605.  
  606.     gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
  607.     gr_printf(Briefing_text_x+1, Briefing_text_y, message );
  608.  
  609. //    if (the_char != ' ')
  610. //        if (!digi_is_sound_playing(231))
  611. //            digi_play_sample( 231, F1_0 );
  612.  
  613.     return w;
  614. }
  615.  
  616. //    -----------------------------------------------------------------------------
  617. int load_briefing_screen( int screen_num )
  618. {
  619.     int    pcx_error;
  620.  
  621.     if ((pcx_error=pcx_read_bitmap( &Briefing_screens[screen_num].bs_name, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, New_pal ))!=PCX_ERROR_NONE)    {
  622.         printf( "File '%s', PCX load error: %s\n  (It's a briefing screen.  Does this cause you pain?)\n",Briefing_screens[screen_num].bs_name, pcx_errormsg(pcx_error));
  623.         printf(0, "File '%s', PCX load error: %s (%i)\n  (It's a briefing screen.  Does this cause you pain?)\n",Briefing_screens[screen_num].bs_name, pcx_errormsg(pcx_error), pcx_error);
  624.         Int3();
  625.         return 0;
  626.     }
  627.  
  628.     return 0;
  629. }
  630.  
  631. #define    KEY_DELAY_DEFAULT    ((F1_0*28)/1000)
  632.  
  633. //    -----------------------------------------------------------------------------
  634. int get_message_num(char **message)
  635. {
  636.     int    num=0;
  637.  
  638.     while (**message == ' ')
  639.         (*message)++;
  640.  
  641.     while ((**message >= '0') && (**message <= '9')) {
  642.         num = 10*num + **message-'0';
  643.         (*message)++;
  644.     }
  645.  
  646.     while (*(*message)++ != 10)        //    Get and drop eoln
  647.         ;
  648.  
  649.     return num;
  650. }
  651.  
  652. void title_save_game()
  653. {
  654.     grs_canvas * save_canv;
  655.     grs_canvas * save_canv_data;
  656.     grs_font * save_font;
  657.     ubyte palette[768];
  658.  
  659.     if ( Next_level_num == 0 ) return;
  660.     
  661.     save_canv = grd_curcanv;
  662.     save_font = grd_curcanv->cv_font;
  663.  
  664.     save_canv_data = gr_create_canvas( grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h );
  665.     gr_set_current_canvas(save_canv_data);
  666.     gr_ubitmap(0,0,&save_canv->cv_bitmap);
  667.     gr_set_current_canvas(save_canv);
  668.     gr_clear_canvas(gr_find_closest_color_current( 0, 0, 0));
  669.     gr_palette_read( palette );
  670.     gr_palette_load( gr_palette );
  671.     state_save_all(1);
  672.     gr_palette_clear();
  673.     
  674.     gr_set_current_canvas(save_canv);
  675.     gr_ubitmap(0,0,&save_canv_data->cv_bitmap);
  676.     gr_palette_load( palette );
  677.     gr_set_curfont(save_font);
  678. }
  679.  
  680.  
  681. //    -----------------------------------------------------------------------------
  682. void get_message_name(char **message, char *result)
  683. {
  684.     while (**message == ' ')
  685.         (*message)++;
  686.  
  687.     while ((**message != ' ') && (**message != 10)) {
  688.         if (**message != 13)
  689.             *result++ = **message;
  690.         (*message)++;
  691.     }
  692.  
  693.     if (**message != 10)
  694.         while (*(*message)++ != 10)        //    Get and drop eoln
  695.             ;
  696.  
  697.     *result = 0;
  698. }
  699.  
  700. //    -----------------------------------------------------------------------------
  701. void flash_cursor(int cursor_flag)
  702. {
  703.     if (cursor_flag == 0)
  704.         return;
  705.  
  706.     if ((timer_get_fixed_seconds() % (F1_0/2) ) > (F1_0/4))
  707.         gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
  708.     else
  709.         gr_set_fontcolor(Erase_color, -1);
  710.  
  711.     gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
  712.  
  713. }
  714.  
  715. //    -----------------------------------------------------------------------------
  716. //    Return true if message got aborted by user (pressed ESC), else return false.
  717. int show_briefing_message(int screen_num, char *message)
  718. {
  719.     int    prev_ch=-1;
  720.     int    ch, done=0;
  721.     briefing_screen    *bsp = &Briefing_screens[screen_num];
  722.     int    delay_count = KEY_DELAY_DEFAULT;
  723.     int    key_check;
  724.     int    robot_num=-1;
  725.     int    rval=0;
  726.     int    tab_stop=0;
  727.     int    flashing_cursor=0;
  728.     int    new_page=0;
  729.  
  730.     Bitmap_name[0] = 0;
  731.  
  732.     Current_color = 0;
  733.  
  734.     // mprintf((0, "Going to print message [%s] at x=%i, y=%i\n", message, x, y));
  735.     gr_set_curfont( GAME_FONT );    
  736.  
  737.     init_char_pos(bsp->text_ulx, bsp->text_uly);
  738.  
  739.     while (!done) {
  740.         ch = *message++;
  741.         if (ch == '$') {
  742.             ch = *message++;
  743.             if (ch == 'C') {
  744.                 Current_color = get_message_num(&message)-1;
  745.                 Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
  746.                 prev_ch = 10;
  747.             } else if (ch == 'F') {        //    toggle flashing cursor
  748.                 flashing_cursor = !flashing_cursor;
  749.                 prev_ch = 10;
  750.                 while (*message++ != 10)
  751.                     ;
  752.             } else if (ch == 'T') {
  753.                 tab_stop = get_message_num(&message);
  754.                 prev_ch = 10;                            //    read to eoln
  755.             } else if (ch == 'R') {
  756.                 if (Robot_canv != NULL)
  757.                     {free(Robot_canv); Robot_canv=NULL;}
  758.  
  759.                 init_spinning_robot();
  760.                 robot_num = get_message_num(&message);
  761.                 prev_ch = 10;                            //    read to eoln
  762.             } else if (ch == 'N') {
  763.                 //--grs_bitmap    *bitmap_ptr;
  764.                 if (Robot_canv != NULL)
  765.                     {free(Robot_canv); Robot_canv=NULL;}
  766.  
  767.                 get_message_name(&message, Bitmap_name);
  768.                 strcat(Bitmap_name, "#0");
  769.                 Animating_bitmap_type = 0;
  770.                 prev_ch = 10;
  771.             } else if (ch == 'O') {
  772.                 if (Robot_canv != NULL)
  773.                     {free(Robot_canv); Robot_canv=NULL;}
  774.  
  775.                 get_message_name(&message, Bitmap_name);
  776.                 strcat(Bitmap_name, "#0");
  777.                 Animating_bitmap_type = 1;
  778.                 prev_ch = 10;
  779.             } else if (ch == 'B') {
  780.                 char            bitmap_name[32];
  781.                 grs_bitmap    guy_bitmap;
  782.                 ubyte            temp_palette[768];
  783.                 int            iff_error;
  784.  
  785.                 if (Robot_canv != NULL)
  786.                     {free(Robot_canv); Robot_canv=NULL;}
  787.  
  788.                 get_message_name(&message, bitmap_name);
  789.                 strcat(bitmap_name, ".bbm");
  790.                 guy_bitmap.bm_data = NULL;
  791.                 iff_error = iff_read_bitmap(bitmap_name, &guy_bitmap, BM_LINEAR, temp_palette);
  792.                 Assert(iff_error == IFF_NO_ERROR);
  793.  
  794.                 show_briefing_bitmap(&guy_bitmap);
  795.                 free(guy_bitmap.bm_data);
  796.                 prev_ch = 10;
  797. //            } else if (ch == 'B') {
  798. //                if (Robot_canv != NULL)
  799. //                    {free(Robot_canv); Robot_canv=NULL;}
  800. //
  801. //                bitmap_num = get_message_num(&message);
  802. //                if (bitmap_num != -1)
  803. //                    show_briefing_bitmap(Textures[bitmap_num]);
  804. //                prev_ch = 10;                            //    read to eoln
  805.             } else if (ch == 'S') {
  806.                 int    keypress;
  807.                 fix    start_time;
  808.                 fix     time_out_value;
  809.  
  810.                 start_time = timer_get_fixed_seconds();
  811.                 start_time = timer_get_approx_seconds();
  812.                 time_out_value = start_time + i2f(60*5);        // Wait 1 minute...
  813.  
  814.                 while ( (keypress = local_key_inkey()) == 0 ) {        //    Wait for a key
  815.                     if ( timer_get_approx_seconds() > time_out_value ) {
  816.                         keypress = 0;
  817.                         break;                    // Time out after 1 minute..
  818.                     }
  819.                     while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
  820.                         ;
  821.                     flash_cursor(flashing_cursor);
  822.                     show_spinning_robot_frame(robot_num);
  823.                     show_bitmap_frame();
  824.                     start_time += KEY_DELAY_DEFAULT/2;
  825.                 }
  826.  
  827. #ifndef NDEBUG
  828.                 if (keypress == KEY_BACKSP)
  829.                     Int3();
  830. #endif
  831.                 if (keypress == KEY_ESC)
  832.                     rval = 1;
  833.  
  834.                 flashing_cursor = 0;
  835.                 done = 1;
  836.             } else if (ch == 'P') {        //    New page.
  837.                 new_page = 1;
  838.                 while (*message != 10) {
  839.                     message++;    //    drop carriage return after special escape sequence
  840.                 }
  841.                 message++;
  842.                 prev_ch = 10;
  843.             }
  844.         } else if (ch == '\t') {        //    Tab
  845.             if (Briefing_text_x - bsp->text_ulx < tab_stop)
  846.                 Briefing_text_x = bsp->text_ulx + tab_stop;
  847.         } else if ((ch == ';') && (prev_ch == 10)) {
  848.             while (*message++ != 10)
  849.                 ;
  850.             prev_ch = 10;
  851.         } else if (ch == '\\') {
  852.             prev_ch = ch;
  853.         } else if (ch == 10) {
  854.             if (prev_ch != '\\') {
  855.                 prev_ch = ch;
  856.                 Briefing_text_y += 8;
  857.                 Briefing_text_x = bsp->text_ulx;
  858.                 if (Briefing_text_y > bsp->text_uly + bsp->text_height) {
  859.                     load_briefing_screen(screen_num);
  860.                     Briefing_text_x = bsp->text_ulx;
  861.                     Briefing_text_y = bsp->text_uly;
  862.                 }
  863.             } else {
  864.                 if (ch == 13)
  865.                     Int3();
  866.                 prev_ch = ch;
  867.             }
  868.         } else {
  869.             prev_ch = ch;
  870.             Briefing_text_x += show_char_delay(ch, delay_count, robot_num, flashing_cursor);
  871.         }
  872.  
  873.         //    Check for Esc -> abort.
  874.         key_check = local_key_inkey();
  875.         if ( key_check == KEY_ESC ) {
  876.             rval = 1;
  877.             done = 1;
  878.         }
  879.  
  880.         if ( key_check == KEY_ALTED+KEY_F2 )    
  881.             title_save_game();
  882.  
  883.         if ((key_check == KEY_SPACEBAR) || (key_check == KEY_ENTER))
  884.             delay_count = 0;
  885.  
  886.         if (Briefing_text_x > bsp->text_ulx + bsp->text_width) {
  887.             Briefing_text_x = bsp->text_ulx;
  888.             Briefing_text_y += 8;
  889.         }
  890.  
  891.         if ((new_page) || (Briefing_text_y > bsp->text_uly + bsp->text_height)) {
  892.             fix    start_time = 0;
  893.             fix    time_out_value = 0;
  894.             int    keypress;
  895.  
  896.             new_page = 0;
  897.             start_time = timer_get_approx_seconds();
  898.             time_out_value = start_time + i2f(60*5);        // Wait 1 minute...
  899.             while ( (keypress = local_key_inkey()) == 0 ) {        //    Wait for a key
  900.                 if ( timer_get_approx_seconds() > time_out_value ) {
  901.                     keypress = 0;
  902.                     break;                    // Time out after 1 minute..
  903.                 }
  904.                 while (timer_get_approx_seconds() < start_time + KEY_DELAY_DEFAULT/2)
  905.                     ;
  906.                 flash_cursor(flashing_cursor);
  907.                 show_spinning_robot_frame(robot_num);
  908.                 show_bitmap_frame();
  909.                 start_time += KEY_DELAY_DEFAULT/2;
  910.             }
  911.  
  912.             robot_num = -1;
  913.  
  914. #ifndef NDEBUG
  915.             if (keypress == KEY_BACKSP)
  916.                 Int3();
  917. #endif
  918.             if (keypress == KEY_ESC) {
  919.                 rval = 1;
  920.                 done = 1;
  921.             }
  922.  
  923.             load_briefing_screen(screen_num);
  924.             Briefing_text_x = bsp->text_ulx;
  925.             Briefing_text_y = bsp->text_uly;
  926.             delay_count = KEY_DELAY_DEFAULT;
  927.         }
  928.     }
  929.  
  930.     if (Robot_canv != NULL)
  931.         {free(Robot_canv); Robot_canv=NULL;}
  932.  
  933.     return rval;
  934. }
  935.  
  936. //    -----------------------------------------------------------------------------
  937. //    Return a pointer to the start of text for screen #screen_num.
  938. char * get_briefing_message(int screen_num)
  939. {
  940.     char    *tptr = Briefing_text;
  941.     int    cur_screen=0;
  942.     int    ch;
  943.  
  944.     Assert(screen_num >= 0);
  945.  
  946.     while ( (*tptr != 0 ) && (screen_num != cur_screen)) {
  947.         ch = *tptr++;
  948.         if (ch == '$') {
  949.             ch = *tptr++;
  950.             if (ch == 'S')
  951.                 cur_screen = get_message_num(&tptr);
  952.         }
  953.     }
  954.  
  955.     return tptr;
  956. }
  957.  
  958. // -----------------------------------------------------------------------------
  959. //    Load Descent briefing text.
  960. void load_screen_text(char *filename, char **buf)
  961. {
  962.     CFILE    *tfile;
  963.     CFILE *ifile;
  964.     int    len, i;
  965.     int    have_binary = 0;
  966.  
  967.     if ((tfile = cfopen(filename,"rb")) == NULL) {
  968.         char nfilename[30], *ptr;
  969.  
  970.         strcpy(nfilename, filename);
  971.         ptr = strrchr(nfilename, '.');
  972.         *ptr = '\0';
  973.         strcat(nfilename, ".txb");
  974.         if ((ifile = cfopen(nfilename, "rb")) == NULL)
  975.             Error("Cannot open file %s or %s", filename, nfilename);
  976.         have_binary = 1;
  977.  
  978.         len = cfilelength(ifile);
  979.         //MALLOC(*buf,char, len);//Unable to get this to compile...is it a case issue? -KRB
  980.         *buf=(char *)malloc(len*sizeof(char));//My hack -KRB
  981.         cfread(*buf, 1, len, ifile);
  982.         cfclose(ifile);
  983.     } else {
  984.         len = cfilelength(tfile);
  985.         //MALLOC(*buf, char, len);-KRB
  986.         *buf=(char *)malloc(len*sizeof(char));//-KRB
  987.         cfread(*buf, 1, len, tfile);
  988.         cfclose(tfile);
  989.     }
  990.  
  991.     if (have_binary) {
  992.         char *ptr;
  993.  
  994.         for (i = 0, ptr = *buf; i < len; i++, ptr++) {
  995.             if (*ptr != '\n') {
  996.                 encode_rotate_left(ptr);
  997.                 *ptr = *ptr ^ BITMAP_TBL_XOR;
  998.                 encode_rotate_left(ptr);
  999.             }
  1000.         }
  1001.     }
  1002.  
  1003. }
  1004.  
  1005. //    -----------------------------------------------------------------------------
  1006. //    Return true if message got aborted, else return false.
  1007. int show_briefing_text(int screen_num)
  1008. {
  1009.     char    *message_ptr;
  1010.  
  1011.     // briefing_screen    *bsp = &Briefing_screens[screen_num];
  1012.  
  1013.     Briefing_foreground_colors[0] = gr_find_closest_color_current( 0, 54, 0);
  1014.     Briefing_background_colors[0] = gr_find_closest_color_current( 0, 19, 0);
  1015.  
  1016.     Briefing_foreground_colors[1] = gr_find_closest_color_current( 42, 38, 32);
  1017.     Briefing_background_colors[1] = gr_find_closest_color_current( 14, 14, 14);
  1018.  
  1019.     Erase_color = gr_find_closest_color_current(0, 0, 0);
  1020.  
  1021.     message_ptr = get_briefing_message(Briefing_screens[screen_num].message_num);
  1022.  
  1023.     return show_briefing_message(screen_num, message_ptr);
  1024. }
  1025.  
  1026. //    -----------------------------------------------------------------------------
  1027. //    Return true if screen got aborted by user, else return false.
  1028. int show_briefing_screen( int screen_num, int allow_keys)
  1029. {
  1030.     int    rval=0;
  1031.     int    pcx_error;
  1032.     grs_bitmap briefing_bm;
  1033.  
  1034.     New_pal_254_bash = 0;
  1035.  
  1036.     if (Skip_briefing_screens) {
  1037.         mprintf((0, "Skipping briefing screen [%s]\n", &Briefing_screens[screen_num].bs_name));
  1038.         return 0;
  1039.     }
  1040.  
  1041.     briefing_bm.bm_data=NULL;    
  1042.     if ((pcx_error=pcx_read_bitmap( &Briefing_screens[screen_num].bs_name, &briefing_bm, BM_LINEAR, New_pal ))!=PCX_ERROR_NONE)    {
  1043.         printf( "PCX load error: %s.  File '%s'\n\n", pcx_errormsg(pcx_error), Briefing_screens[screen_num].bs_name);
  1044.         mprintf((0, "File '%s', PCX load error: %s (%i)\n  (It's a briefing screen.  Does this cause you pain?)\n",Briefing_screens[screen_num].bs_name, pcx_errormsg(pcx_error), pcx_error));
  1045.         Int3();
  1046.         return 0;
  1047.     }
  1048.  
  1049.     vfx_set_palette_sub( New_pal );
  1050.     gr_palette_clear();
  1051.     gr_bitmap( 0, 0, &briefing_bm );
  1052.  
  1053.     if (gr_palette_fade_in( New_pal, 32, allow_keys ))    
  1054.         return 1;
  1055.  
  1056.     rval = show_briefing_text(screen_num);
  1057.  
  1058.     if (gr_palette_fade_out( New_pal, 32, allow_keys ))
  1059.         return 1;
  1060.  
  1061.     free(briefing_bm.bm_data);
  1062.  
  1063.     return rval;
  1064. }
  1065.  
  1066.  
  1067. //    -----------------------------------------------------------------------------
  1068. void do_briefing_screens(int level_num)
  1069. {
  1070.     int    abort_briefing_screens = 0;
  1071.     int    cur_briefing_screen = 0;
  1072.  
  1073.     if (Skip_briefing_screens) {
  1074.         mprintf((0, "Skipping all briefing screens.\n"));
  1075.         return;
  1076.     }
  1077.  
  1078.     if (!Briefing_text_filename[0])        //no filename?
  1079.         return;
  1080.  
  1081.     songs_play_song( SONG_BRIEFING, 1 );
  1082.  
  1083.     set_screen_mode( SCREEN_MENU );
  1084.     gr_set_current_canvas(NULL);
  1085.  
  1086.     key_flush();
  1087.  
  1088.     load_screen_text(Briefing_text_filename, &Briefing_text);
  1089.  
  1090.     if (level_num == 1) {
  1091.         while ((!abort_briefing_screens) && (Briefing_screens[cur_briefing_screen].level_num == 0)) {
  1092.             abort_briefing_screens = show_briefing_screen(cur_briefing_screen, 0);
  1093.             cur_briefing_screen++;
  1094.         }
  1095.     }
  1096.  
  1097.     if (!abort_briefing_screens) {
  1098.         for (cur_briefing_screen = 0; cur_briefing_screen < MAX_BRIEFING_SCREEN; cur_briefing_screen++)
  1099.             if (Briefing_screens[cur_briefing_screen].level_num == level_num)
  1100.                 if (show_briefing_screen(cur_briefing_screen, 0))
  1101.                     break;
  1102.     }
  1103.  
  1104.  
  1105.     free(Briefing_text);
  1106.  
  1107.     key_flush();
  1108. }
  1109.  
  1110. #ifndef SHAREWARE
  1111. void do_registered_end_game(void)
  1112. {
  1113.     int    cur_briefing_screen;
  1114.  
  1115.     if (!Ending_text_filename[0])        //no filename?
  1116.         return;
  1117.  
  1118.     if ((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP))
  1119.     {
  1120.         // Special ending for deathmatch!!
  1121.         int len = 40;
  1122.         
  1123.         //MALLOC(Briefing_text, char, len);//Unable to compile -KRB
  1124.         Briefing_text=(char *)malloc(len*sizeof(char));//my hack -KRB
  1125.         sprintf(Briefing_text, "Test");
  1126.     }
  1127.         
  1128.     load_screen_text(Ending_text_filename, &Briefing_text);
  1129.  
  1130.     for (cur_briefing_screen = 0; cur_briefing_screen < MAX_BRIEFING_SCREEN; cur_briefing_screen++)
  1131.         if (Briefing_screens[cur_briefing_screen].level_num == REGISTERED_ENDING_LEVEL_NUM)
  1132.             if (show_briefing_screen(cur_briefing_screen, 0))
  1133.                 break;
  1134.  
  1135. }
  1136. #endif
  1137.  
  1138. void do_shareware_end_game(void)
  1139. {
  1140.     int    cur_briefing_screen;
  1141.  
  1142. #ifdef NETWORK
  1143.     if ((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP))
  1144.     {
  1145. //        // Special ending for deathmatch!!
  1146. //        int len = 120;
  1147. //        int i;
  1148. //        int max_kills = Players[0].net_kills_total;        
  1149. //        int winner = 0;
  1150. //
  1151. //        for (i=1; i < N_players; i++)
  1152. //        {
  1153. //            if (Players[i].net_kills_total > max_kills)
  1154. //            {    
  1155. //                winner = i;
  1156. //                max_kills = Players[i].net_kills_total;
  1157. //            }
  1158. //        }
  1159. //
  1160.         //MALLOC(Briefing_text, char, 4); // Dummy //Can't compile -KRB
  1161.         Briefing_text=(char *)malloc(4*sizeof(char));//my hack -KRB
  1162. //        sprintf(Briefing_text, "$S1\n$C1\n\n%s!\n\n%s has won with %d kills.\n\n$S2\n", TXT_SHAREWARE_DONE,Players[winner].callsign, Players[winner].net_kills_total);
  1163.  
  1164.         kmatrix_view();
  1165.         return;
  1166.     }
  1167.     else 
  1168. #endif
  1169.     {
  1170. #ifdef DEST_SAT
  1171.             load_screen_text(Ending_text_filename, &Briefing_text);
  1172. #else
  1173.             load_screen_text(SHAREWARE_ENDING_FILENAME, &Briefing_text);
  1174. #endif
  1175.     }
  1176.  
  1177.     for (cur_briefing_screen = 0; cur_briefing_screen < MAX_BRIEFING_SCREEN; cur_briefing_screen++)
  1178.         if (Briefing_screens[cur_briefing_screen].level_num == SHAREWARE_ENDING_LEVEL_NUM)
  1179.             if (show_briefing_screen(cur_briefing_screen, 0))
  1180.                 break;
  1181.  
  1182. }
  1183.  
  1184. extern void show_order_form(void);
  1185.  
  1186. void do_end_game(void)
  1187. {
  1188.     set_screen_mode( SCREEN_MENU );
  1189.     gr_set_current_canvas(NULL);
  1190.  
  1191.     key_flush();
  1192.  
  1193.     #ifdef SHAREWARE
  1194.     do_shareware_end_game();        //hurrah! you win!
  1195.     #else
  1196.         #ifdef DEST_SAT
  1197.             do_shareware_end_game();        //hurrah! you win!
  1198.         #else
  1199.             do_registered_end_game();        //hurrah! you win!
  1200.         #endif
  1201.     #endif
  1202.  
  1203.     if (Briefing_text) {
  1204.         free(Briefing_text);
  1205.         Briefing_text = NULL;
  1206.     }
  1207.  
  1208.     key_flush();
  1209.  
  1210.     Function_mode = FMODE_MENU;
  1211.  
  1212.     if ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM))
  1213.         Game_mode |= GM_GAME_OVER;
  1214.     else
  1215.         Game_mode = GM_GAME_OVER;
  1216.  
  1217. #ifdef DEST_SAT
  1218.         show_order_form();
  1219. #endif
  1220.  
  1221. #ifdef SHAREWARE
  1222.     show_order_form();
  1223. #endif
  1224.  
  1225. }
  1226.  
  1227. 
  1228.