home *** CD-ROM | disk | FTP | other *** search
/ Launch & Play / spustahrej2.iso / Egoboo / code / menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-12-08  |  37.4 KB  |  1,206 lines

  1. // menu.c
  2.  
  3. // Egoboo, Copyright (C) 2000 Aaron Bishop
  4.  
  5. #include "egoboo.h"
  6.  
  7. //--------------------------------------------------------------------------------------------
  8. void menu_service_select()
  9. {
  10.     // ZZ> This function lets the user choose a network service to use
  11.     char text[256];
  12.     int x, y;
  13.     float open;
  14.     int cnt;
  15.     int stillchoosing;
  16.  
  17.  
  18.     networkservice = NONETWORK;
  19.     if(numservice > 0)
  20.     {
  21.         // Open a big window
  22.         open = 0;
  23.         while(open < 1.0)
  24.         {
  25.             //clear_surface(lpDDSBack);
  26.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  27.                 glLoadIdentity();
  28.             draw_trim_box_opening(0, 0, scrx, scry, open);
  29.             draw_trim_box_opening(0, 0, 320, fontyspacing*(numservice+4), open);
  30.             flip_pages();
  31.             open += .030;
  32.         }
  33.         // Tell the user which ones we found ( in setup_network )
  34.         stillchoosing = TRUE;
  35.         while(stillchoosing)
  36.         {
  37.             //clear_surface(lpDDSBack);
  38.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  39.                 glLoadIdentity();
  40.             draw_trim_box(0, 0, scrx, scry);
  41.             draw_trim_box(0, 0, 320, fontyspacing*(numservice+4));
  42.             y = 8;
  43.             sprintf(text, "Network options...");
  44.             draw_string(text, 14, y);
  45.             y += fontyspacing;
  46.             cnt = 0;
  47.             while(cnt < numservice)
  48.             {
  49.                 sprintf(text, "%s", netservicename[cnt]);
  50.                 draw_string(text, 50, y);
  51.                 y += fontyspacing;
  52.                 cnt++;
  53.             }
  54.             sprintf(text, "No Network");
  55.             draw_string(text, 50, y);
  56.             do_cursor();
  57.             x = cursorx - 50;
  58.             y = (cursory - 8 - fontyspacing);
  59.             if(x > 0 && x < 300 && y >= 0)
  60.             {
  61.                 y = y/fontyspacing;
  62.                 if(y <= numservice)
  63.                 {
  64.                     if(mousebutton[0] || mousebutton[1])
  65.                     {
  66.                         stillchoosing = FALSE;
  67.                         networkservice = y;
  68.                     }
  69.                 }
  70.             }
  71.             flip_pages();
  72.         }
  73.     }
  74.     turn_on_service(networkservice);
  75. }
  76.  
  77. //--------------------------------------------------------------------------------------------
  78. void menu_start_or_join()
  79. {
  80.     // ZZ> This function lets the user start or join a game for a network game
  81.     char text[256];
  82.     int x, y;
  83.     float open;
  84.     int stillchoosing;
  85.  
  86.  
  87.     // Open another window
  88.     if(networkon)
  89.     {
  90.         open = 0;
  91.         while(open < 1.0)
  92.         {
  93.             //clear_surface(lpDDSBack);
  94.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  95.                 glLoadIdentity();
  96.             draw_trim_box_opening(0, 0, scrx, scry, open);
  97.             draw_trim_box_opening(0, 0, 280, 102, open);
  98.             flip_pages();
  99.             open += .030;
  100.         }
  101.         // Give the user some options
  102.         stillchoosing = TRUE;
  103.         while(stillchoosing)
  104.         {
  105.             //clear_surface(lpDDSBack);
  106.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  107.                 glLoadIdentity();
  108.             draw_trim_box(0, 0, scrx, scry);
  109.             draw_trim_box(0, 0, 280, 102);
  110.             y = 8;
  111.             sprintf(text, "Game options...");
  112.             draw_string(text, 14, y);
  113.             y += fontyspacing;
  114.             sprintf(text, "New Game");
  115.             draw_string(text, 50, y);
  116.             y += fontyspacing;
  117.             sprintf(text, "Join Game");
  118.             draw_string(text, 50, y);
  119.             y += fontyspacing;
  120.             sprintf(text, "Quit Game");
  121.             draw_string(text, 50, y);
  122.             do_cursor();
  123.             x = cursorx - 50;
  124.             y = (cursory - 8 - fontyspacing);
  125.             if(x > 0 && x < 280 && y >= 0)
  126.             {
  127.                 y = y/fontyspacing;
  128.                 if(y < 3)
  129.                 {
  130.                     if(mousebutton[0] || mousebutton[1])
  131.                     {
  132.                         if(y == 0)
  133.                         {
  134.                             if(host_session())
  135.                             {
  136.                                 hostactive = TRUE;
  137.                                 nextmenu = MENUD;
  138.                                 stillchoosing = FALSE;
  139.                             }
  140.                         }
  141.                         if(y == 1 && networkservice != NONETWORK)
  142.                         {
  143.                             nextmenu = MENUC;
  144.                             stillchoosing = FALSE;
  145.                         }
  146.                         if(y == 2)
  147.                         {
  148.                             nextmenu = MENUB;
  149.                             menuactive = FALSE;
  150.                             stillchoosing = FALSE;
  151.                             gameactive = FALSE;
  152.                         }
  153.                     }
  154.                 }
  155.             }
  156.             flip_pages();
  157.         }
  158.     }
  159.     else
  160.     {
  161.         hostactive = TRUE;
  162.         nextmenu = MENUD;
  163.     }
  164. }
  165.  
  166. //--------------------------------------------------------------------------------------------
  167. void draw_module_tag(int module, int y)
  168. {
  169.     // ZZ> This function draws a module tag
  170.     char text[256];
  171.     draw_trim_box(0, y, 136, y+136);
  172.     draw_trim_box(132, y, scrx, y+136);
  173.     if(module < globalnummodule)
  174.     {
  175.         draw_titleimage(module, 4, y+4);
  176.         y+=6;
  177.         sprintf(text, "%s", modlongname[module]);  draw_string(text, 150, y);  y+=fontyspacing;
  178.         sprintf(text, "%s", modrank[module]);  draw_string(text, 150, y);  y+=fontyspacing;
  179.         if(modmaxplayers[module] > 1)
  180.         {
  181.             if(modminplayers[module]==modmaxplayers[module])
  182.             {
  183.                 sprintf(text, "%d players", modminplayers[module]);
  184.             }
  185.             else
  186.             {
  187.                 sprintf(text, "%d-%d players", modminplayers[module], modmaxplayers[module]);
  188.             }
  189.         }
  190.         else
  191.         {
  192.             sprintf(text, "1 player");
  193.         }
  194.         draw_string(text, 150, y);  y+=fontyspacing;
  195.         if(modimportamount[module] == 0 && modallowexport[module]==FALSE)
  196.         {
  197.             sprintf(text, "No Import/Export");  draw_string(text, 150, y);  y+=fontyspacing;
  198.         }
  199.         else
  200.         {
  201.             if(modimportamount[module] == 0)
  202.             {
  203.                 sprintf(text, "No Import");  draw_string(text, 150, y);  y+=fontyspacing;
  204.             }
  205.             if(modallowexport[module]==FALSE)
  206.             {
  207.                 sprintf(text, "No Export");  draw_string(text, 150, y);  y+=fontyspacing;
  208.             }
  209.         }
  210.         if(modrespawnvalid[module] == FALSE)
  211.         {
  212.             sprintf(text, "No Respawn");  draw_string(text, 150, y);  y+=fontyspacing;
  213.         }
  214.         if(modrtscontrol[module] == TRUE)
  215.         {
  216.             sprintf(text, "RTS");  draw_string(text, 150, y);  y+=fontyspacing;
  217.         }
  218.         if(modrtscontrol[module] == ALLSELECT)
  219.         {
  220.             sprintf(text, "Diaboo RTS");  draw_string(text, 150, y);  y+=fontyspacing;
  221.         }
  222.     }
  223. }
  224.  
  225. //--------------------------------------------------------------------------------------------
  226. void menu_pick_player(int module)
  227. {
  228.     // ZZ> This function handles the display for picking players to import
  229.     int x, y;
  230.     float open;
  231.     int cnt, tnc, start, numshow;
  232.     int stillchoosing;
  233.     int import;
  234.     unsigned char control, sparkle;
  235.     char fromdir[128];
  236.     char todir[128];
  237.  
  238.     // Set the important flags
  239.     respawnvalid = FALSE;
  240.     respawnanytime = FALSE;
  241.     if(modrespawnvalid[module])  respawnvalid = TRUE;
  242.     if(modrespawnvalid[module]==ANYTIME)  respawnanytime = TRUE;
  243.     rtscontrol = FALSE;
  244.     if(modrtscontrol[module] != FALSE)
  245.     {
  246.         rtscontrol = TRUE;
  247.         allselect = FALSE;
  248.         if(modrtscontrol[module] == ALLSELECT)
  249.             allselect = TRUE;
  250.     }
  251.     exportvalid = modallowexport[module];
  252.     importvalid = (modimportamount[module] > 0);
  253.     importamount = modimportamount[module];
  254.     playeramount = modmaxplayers[module];
  255.     make_directory("import");  // Just in case...
  256.  
  257.  
  258.     start = 0;
  259.     if(importvalid)
  260.     {
  261.         // Figure out which characters are available
  262.         check_player_import("players");
  263.         numshow = (scry-80-fontyspacing-fontyspacing)>>5;
  264.  
  265.  
  266.         // Open some windows
  267.         y = fontyspacing + 8;
  268.         open = 0;
  269.         while(open < 1.0)
  270.         {
  271.             //clear_surface(lpDDSBack);
  272.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  273.                 glLoadIdentity();
  274.             draw_trim_box_opening(0, 0, scrx, scry, open);
  275.             draw_trim_box_opening(0, 0, scrx, 40, open);
  276.             draw_trim_box_opening(0, scry-40, scrx, scry, open);
  277.             flip_pages();
  278.             open += .030;
  279.         }
  280.  
  281.  
  282.         wldframe = 0;  // For sparkle
  283.         stillchoosing = TRUE;
  284.         while(stillchoosing)
  285.         {
  286.             // Draw the windows
  287.             //clear_surface(lpDDSBack);
  288.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  289.                 glLoadIdentity();
  290.             draw_trim_box(0, 0, scrx, scry);
  291.             draw_trim_box(0, 40, scrx, scry-40);
  292.  
  293.             // Draw the Up/Down buttons
  294.             if(start == 0)
  295.             {
  296.                 // Show the instructions
  297.                 x = (scrx-270)>>1;
  298.                 draw_string("Setup controls", x, 10);
  299.             }
  300.             else
  301.             {
  302.                 x = (scrx-40)>>1;
  303.                 draw_string("Up", x, 10);
  304.             }
  305.             x = (scrx-80)>>1;
  306.             draw_string("Down", x, scry-fontyspacing-20);
  307.  
  308.  
  309.             // Draw each import character
  310.             y = 40+fontyspacing;
  311.             cnt = 0;
  312.             while(cnt < numshow && cnt + start < numloadplayer)
  313.             {
  314.                 sparkle = NOSPARKLE;
  315.                 if(keybplayer == (cnt+start))
  316.                 {
  317.                     draw_one_icon(keybicon, 32, y, NOSPARKLE);
  318.                     sparkle = 0;  // White
  319.                 }
  320.                 else
  321.                     draw_one_icon(nullicon, 32, y, NOSPARKLE);
  322.                 if(mousplayer == (cnt+start))
  323.                 {
  324.                     draw_one_icon(mousicon, 64, y, NOSPARKLE);
  325.                     sparkle = 0;  // White
  326.                 }
  327.                 else
  328.                     draw_one_icon(nullicon, 64, y, NOSPARKLE);
  329.                 if(joyaplayer == (cnt+start) && joyaon)
  330.                 {
  331.                     draw_one_icon(joyaicon, 128, y, NOSPARKLE);
  332.                     sparkle = 0;  // White
  333.                 }
  334.                 else
  335.                     draw_one_icon(nullicon, 128, y, NOSPARKLE);
  336.                 if(joybplayer == (cnt+start) && joybon)
  337.                 {
  338.                     draw_one_icon(joybicon, 160, y, NOSPARKLE);
  339.                     sparkle = 0;  // White
  340.                 }
  341.                 else
  342.                     draw_one_icon(nullicon, 160, y, NOSPARKLE);
  343.                 draw_one_icon((cnt+start), 96, y, sparkle);
  344.                 draw_string(loadplayername[cnt+start], 200, y+6);
  345.                 y+=32;
  346.                 cnt++;
  347.             }
  348.             wldframe++;  // For sparkle
  349.  
  350.  
  351.             // Handle other stuff...
  352.             do_cursor();
  353.             if(pending_click)
  354.             {
  355.             pending_click=FALSE;
  356.                 if(cursory < 40 && start > 0)
  357.                 {
  358.                     // Up button
  359.                     start--;
  360.                 }
  361.                 if(cursory >= (scry-40) && (start + numshow) < numloadplayer)
  362.                 {
  363.                     // Down button
  364.                     start++;
  365.                 }
  366.             }
  367.             if(mousebutton[0])
  368.             {
  369.                 x = (cursorx - 32) >> 5;
  370.                 y = (cursory - 44) >> 5;
  371.                 if(y >= 0 && y < numshow)
  372.                 {
  373.                     y += start;
  374.                     // Assign the controls
  375.                     if(y < numloadplayer)  // !!!BAD!!! do scroll
  376.                     {
  377.                         if(x == 0)  keybplayer = y;
  378.                         if(x == 1)  mousplayer = y;
  379.                         if(x == 3)  joyaplayer = y;
  380.                         if(x == 4)  joybplayer = y;
  381.                     }
  382.                 }
  383.             }
  384.             if(mousebutton[1])
  385.             {
  386.                 // Done picking
  387.                 stillchoosing = FALSE;
  388.             }
  389.             flip_pages();
  390.         }
  391.         wldframe = 0;  // For sparkle
  392.  
  393.  
  394.         // Tell the user we're loading
  395.         y = fontyspacing + 8;
  396.         open = 0;
  397.         while(open < 1.0)
  398.         {
  399.             //clear_surface(lpDDSBack);
  400.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  401.                 glLoadIdentity();
  402.             draw_trim_box_opening(0, 0, scrx, scry, open);
  403.             flip_pages();
  404.             open += .030;
  405.         }
  406.         //clear_surface(lpDDSBack);
  407.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  408.                 glLoadIdentity();
  409.         draw_trim_box(0, 0, scrx, scry);
  410.         draw_string("Copying the imports...", y, y);
  411.         flip_pages();
  412.  
  413.  
  414.         // Now build the import directory...
  415.         empty_import_directory();
  416.         cnt = 0;
  417.         numimport = 0;
  418.         while(cnt < numloadplayer)
  419.         {
  420.             if((cnt == keybplayer && keyon)   ||
  421.                (cnt == mousplayer && mouseon) ||
  422.                (cnt == joyaplayer && joyaon)  ||
  423.                (cnt == joybplayer && joybon))
  424.             {
  425.                 // This character has been selected
  426.                 control = INPUTNONE;
  427.                 if(cnt == keybplayer)  control = control | INPUTKEY;
  428.                 if(cnt == mousplayer)  control = control | INPUTMOUSE;
  429.                 if(cnt == joyaplayer)  control = control | INPUTJOYA;
  430.                 if(cnt == joybplayer)  control = control | INPUTJOYB;
  431.                 localcontrol[numimport] = control;
  432.                 localslot[numimport] = (numimport+(localmachine*4))*9;
  433.  
  434.  
  435.                 // Copy the character to the import directory
  436.                 sprintf(fromdir, FILENAME("players/%s"), loadplayerdir[cnt]);
  437.                 sprintf(todir, FILENAME("import/temp%04d.obj"), localslot[numimport]);
  438.  
  439.         // change back to copy_directory_to_host once networking is
  440.         // working!
  441.                 copy_directory(fromdir, todir);
  442. //                copy_directory_to_host(fromdir, todir);
  443.  
  444.  
  445.                 // Copy all of the character's items to the import directory
  446.                 tnc = 0;
  447.                 while(tnc < 8)
  448.                 {
  449.                     sprintf(fromdir, FILENAME("players/%s/%d.obj"), loadplayerdir[cnt], tnc);
  450.                     sprintf(todir, FILENAME("import/temp%04d.obj"), localslot[numimport]+tnc+1);
  451.  
  452.             // change back to copy_directory_to_host once networking is
  453.             // working!
  454.                     copy_directory(fromdir, todir);
  455. //                    copy_directory_to_host(fromdir, todir);
  456.                     tnc++;
  457.                 }
  458.  
  459.  
  460.                 numimport++;
  461.             }
  462.             cnt++;
  463.         }
  464.  
  465.  
  466.         if(networkon)
  467.         {
  468.             if(hostactive)
  469.             {
  470.                 // Host waits for all files from all remotes
  471.                 numfile = 0;
  472.                 numfileexpected = 0;
  473.                 numplayerrespond = 1;
  474.                 while(numfile < numfileexpected || numplayerrespond < numplayer)
  475.                 {
  476.                     //clear_surface(lpDDSBack);
  477.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  478.                 glLoadIdentity();
  479.                     draw_trim_box(0, 0, scrx, scry);
  480.                     y = fontyspacing + 8;
  481.                     draw_string("Incoming files...", fontyspacing+8, y);  y+=fontyspacing;
  482.                     sprintf(todir, "File %d/%d", numfile, numfileexpected);
  483.                     draw_string(todir, fontyspacing+20, y); y+=fontyspacing;
  484.                     sprintf(todir, "Play %d/%d", numplayerrespond, numplayer);
  485.                     draw_string(todir, fontyspacing+20, y);
  486.                     flip_pages();
  487.                     listen_for_packets();
  488. do_cursor();  if(SDLKEYDOWN(SDLK_ESCAPE)) { numfile = 100000;  gameactive = FALSE;  menuactive = FALSE; }
  489.                 }
  490.  
  491.  
  492.                 // Say you're done
  493.                 //clear_surface(lpDDSBack);
  494.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  495.                 glLoadIdentity();
  496.                 draw_trim_box(0, 0, scrx, scry);
  497.                 y = fontyspacing + 8;
  498.                 draw_string("Sending files to remotes...", fontyspacing+8, y);  y+=fontyspacing;
  499.                 flip_pages();
  500.  
  501.  
  502.                 // Host sends import directory to all remotes, deletes extras
  503.                 numfilesent = 0;
  504.                 import = 0;
  505.                 cnt = 0;
  506.                 while(cnt < MAXIMPORT)
  507.                 {
  508.                     sprintf(todir, "import\\temp%04d.obj", cnt);
  509.                     sprintf(fromdir, "import\\temp%04d.obj", cnt);
  510.                     if(DirGetAttrib(fromdir) != 0xFFFFFFFF)
  511.                     {
  512.                         // Only do directories that actually exist
  513.                         if((cnt % 9)==0) import++;
  514.                         if(import > importamount)
  515.                         {
  516.                             // Too many directories
  517.                             delete_directory(fromdir);
  518.                         }
  519.                         else
  520.                         {
  521.                             // Ship it out
  522.                             copy_directory_to_all_players(fromdir, todir);
  523.                         }
  524.                     }
  525.                     cnt++;
  526.                 }
  527.  
  528.  
  529.                 // Host yells out numfilesent
  530.                 start_building_packet();
  531.                 add_packet_us(TO_REMOTE_FILESENT);
  532.                 add_packet_ui(numfilesent);
  533.                 send_packet_to_all_players();
  534.             }
  535.             else
  536.             {
  537.                 // Remotes tell the host numfilesent
  538.                 start_building_packet();
  539.                 add_packet_us(TO_HOST_FILESENT);
  540.                 add_packet_ui(numfilesent);
  541.                 send_packet_to_host_guaranteed();
  542.  
  543.  
  544.                 // Remotes wait for all files in import directory
  545.                 numfile = 0;
  546.                 numfileexpected = 0;
  547.                 numplayerrespond = 0;
  548.                 while(numfile < numfileexpected || numplayerrespond < 1)
  549.                 {
  550.                     //clear_surface(lpDDSBack);
  551.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  552.                 glLoadIdentity();
  553.                     draw_trim_box(0, 0, scrx, scry);
  554.                     y = fontyspacing + 8;
  555.                     draw_string("Incoming files from host...", fontyspacing+8, y);  y+=fontyspacing;
  556.                     sprintf(todir, "File %d", numfile);
  557.                     draw_string(todir, fontyspacing+20, y);
  558.                     flip_pages();
  559.                     listen_for_packets();
  560. do_cursor();  if(SDLKEYDOWN(SDLK_ESCAPE)) { numfile = 100000;  gameactive = FALSE;  menuactive = FALSE; }
  561.                 }
  562.             }
  563.         }
  564.     }
  565.     nextmenu = MENUG;
  566. }
  567.  
  568. //--------------------------------------------------------------------------------------------
  569. void menu_module_loading(int module)
  570. {
  571.     // ZZ> This function handles the display for when a module is loading
  572.     char text[256];
  573.     int y;
  574.     float open;
  575.     int cnt;
  576.  
  577.  
  578.     // Open some windows
  579.     y = fontyspacing + 8;
  580.     open = 0;
  581.     while(open < 1.0)
  582.     {
  583.         //clear_surface(lpDDSBack);
  584.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  585.                 glLoadIdentity();
  586.         draw_trim_box_opening(0, y, 136, y+136, open);
  587.         draw_trim_box_opening(132, y, scrx, y+136, open);
  588.         draw_trim_box_opening(0, y+132, scrx, scry, open);
  589.         flip_pages();
  590.         open += .030;
  591.     }
  592.  
  593.  
  594.     // Put the stuff in the windows
  595.     //clear_surface(lpDDSBack);
  596.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  597.                 glLoadIdentity();
  598.     y = 0;
  599.     sprintf(text, "Loading...  Wait!!!");  draw_string(text, 0, y);  y+=fontyspacing;
  600.     y+=8;
  601.     draw_module_tag(module, y);
  602.     draw_trim_box(0, y+132, scrx, scry);
  603.  
  604.  
  605.     // Show the summary
  606.     sprintf(text, FILENAME("modules/%s/gamedat/menu.txt"), modloadname[module]);
  607.     get_module_summary(text);
  608.     y = fontyspacing+152;
  609.     cnt = 0;
  610.     while(cnt < SUMMARYLINES)
  611.     {
  612.         sprintf(text, "%s", modsummary[cnt]);  draw_string(text, 14, y);  y+=fontyspacing;
  613.         cnt++;
  614.     }
  615.     flip_pages();
  616.     nextmenu = MENUB;
  617.     menuactive = FALSE;
  618. }
  619.  
  620. //--------------------------------------------------------------------------------------------
  621. void menu_choose_host()
  622. {
  623.     // ZZ> This function lets the player choose a host
  624.     char text[256];
  625.     int x, y;
  626.     float open;
  627.     int cnt;
  628.     int stillchoosing;
  629.  
  630.  
  631.     if(networkon)
  632.     {
  633.         // Bring up a helper window
  634.         open = 0;
  635.         while(open < 1.0)
  636.         {
  637.             //clear_surface(lpDDSBack);
  638.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  639.                 glLoadIdentity();
  640.             draw_trim_box_opening(0, 0, scrx, scry, open);
  641.             flip_pages();
  642.             open += .030;
  643.         }
  644.         //clear_surface(lpDDSBack);
  645.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  646.                 glLoadIdentity();
  647.         draw_trim_box(0, 0, scrx, scry);
  648.         sprintf(text, "Press Enter if");
  649.         draw_string(text, (scrx>>1)-120, (scry>>1)-fontyspacing);
  650.         sprintf(text, "nothing happens");
  651.         draw_string(text, (scrx>>1)-120, (scry>>1));
  652.         flip_pages();
  653.  
  654.  
  655.  
  656.         // Find available games
  657.         find_open_sessions();       // !!!BAD!!!  Do this every now and then
  658.  
  659.         // Open a big window
  660.         open = 0;
  661.         while(open < 1.0)
  662.         {
  663.             //clear_surface(lpDDSBack);
  664.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  665.                 glLoadIdentity();
  666.             draw_trim_box_opening(0, 0, scrx, scry, open);
  667.             draw_trim_box_opening(0, 0, 320, fontyspacing*(numsession+4), open);
  668.             flip_pages();
  669.             open += .030;
  670.         }
  671.  
  672.         // Tell the user which ones we found
  673.         stillchoosing = TRUE;
  674.         while(stillchoosing)
  675.         {
  676.             //clear_surface(lpDDSBack);
  677.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  678.                 glLoadIdentity();
  679.             draw_trim_box(0, 0, scrx, scry);
  680.             draw_trim_box(0, 0, 320, fontyspacing*(numsession+4));
  681.             y = 8;
  682.             sprintf(text, "Open hosts...");
  683.             draw_string(text, 14, y);
  684.             y += fontyspacing;
  685.             cnt = 0;
  686.             while(cnt < numsession)
  687.             {
  688.                 sprintf(text, "%s", netsessionname[cnt]);
  689.                 draw_string(text, 50, y);
  690.                 y += fontyspacing;
  691.                 cnt++;
  692.             }
  693.             sprintf(text, "Go Back...");
  694.             draw_string(text, 50, y);
  695.             do_cursor();
  696.             x = cursorx - 50;
  697.             y = (cursory - 8 - fontyspacing);
  698.             if(x > 0 && x < 300 && y >= 0)
  699.             {
  700.                 y = y/fontyspacing;
  701.                 if(y <= numsession)
  702.                 {
  703.                     if(mousebutton[0] || mousebutton[1])
  704.                     {
  705.                         if(y == numsession)
  706.                         {
  707.                             nextmenu = MENUB;
  708.                             stillchoosing = FALSE;
  709.                         }
  710.                         else
  711.                         {
  712.                             if(join_session(y))
  713.                             {
  714.                                 nextmenu = MENUE;
  715.                                 stillchoosing = FALSE;
  716.                             }
  717.                         }
  718.                     }
  719.                 }
  720.             }
  721.             flip_pages();
  722.         }
  723.     }
  724.     else
  725.     {
  726.         // This should never happen
  727.         nextmenu = MENUB;
  728.     }
  729. }
  730.  
  731. //--------------------------------------------------------------------------------------------
  732. void menu_choose_module()
  733. {
  734.     // ZZ> This function lets the host choose a module
  735.     int numtag;
  736.     char text[256];
  737.     int x, y, ystt;
  738.     float open;
  739.     int cnt;
  740.     int module;
  741.     int stillchoosing;
  742.     if(hostactive)
  743.     {
  744.         // Figure out how many tags to display
  745.         numtag = (scry-4-40)/132;
  746.         ystt = (scry-(numtag*132)-4)>>1;
  747.  
  748.  
  749.         // Open the tag windows
  750.         open = 0;
  751.         while(open < 1.0)
  752.         {
  753.             //clear_surface(lpDDSBack);
  754.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  755.                 glLoadIdentity();
  756.             draw_trim_box_opening(0, 0, scrx, scry, open);
  757.             y = ystt;
  758.             cnt = 0;
  759.             while(cnt < numtag)
  760.             {
  761.                 draw_trim_box_opening(0, y, 136, y+136, open);
  762.                 draw_trim_box_opening(132, y, scrx, y+136, open);
  763.                 y+=132;
  764.                 cnt++;
  765.             }
  766.             flip_pages();
  767.             open += .030;
  768.         }
  769.  
  770.  
  771.  
  772.  
  773.         // Let the user pick a module
  774.         module = 0;
  775.         stillchoosing = TRUE;
  776.         while(stillchoosing)
  777.         {
  778.             // Draw the tags
  779.             //clear_surface(lpDDSBack);
  780.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  781.                 glLoadIdentity();
  782.             draw_trim_box(0, 0, scrx, scry);
  783.             y = ystt;
  784.             cnt = 0;
  785.             while(cnt < numtag)
  786.             {
  787.                 draw_module_tag(module+cnt, y);
  788.                 y+=132;
  789.                 cnt++;
  790.             }
  791.  
  792.             // Draw the Up/Down buttons
  793.             sprintf(text, "Up");
  794.             x = (scrx-40)>>1;
  795.             draw_string(text, x, 10);
  796.             sprintf(text, "Down");
  797.             x = (scrx-80)>>1;
  798.             draw_string(text, x, scry-fontyspacing-20);
  799.  
  800.  
  801.             // Handle the mouse
  802.             do_cursor();
  803.             y = (cursory - ystt)/132;
  804.             if(pending_click)
  805.           {
  806.             pending_click=FALSE;
  807.                 if(cursory < ystt && module > 0)
  808.           {
  809.                     // Up button
  810.                     module--;
  811.           }
  812.                 if(y >= numtag && module + numtag < globalnummodule)
  813.           {
  814.                     // Down button
  815.                     module++;
  816.           }
  817.         if(cursory > ystt && y > -1 && y < numtag)
  818.           {
  819.             y = module + y;
  820.             if((mousebutton[0] || mousebutton[1]) && y < globalnummodule)
  821.               {
  822.             // Set start info
  823.             playersready = 1;
  824.             seed = time(0);
  825.             pickedindex = y;
  826.             sprintf(pickedmodule, "%s", modloadname[y]);
  827.             readytostart = TRUE;
  828.             stillchoosing = FALSE;
  829.               }
  830.           }
  831.           }
  832.             // Check for quitters
  833.             if(SDLKEYDOWN(SDLK_ESCAPE) && networkservice == NONETWORK)
  834.             {
  835.                 nextmenu = MENUB;
  836.                 menuactive = FALSE;
  837.                 stillchoosing = FALSE;
  838.                 gameactive = FALSE;
  839.             }
  840.             flip_pages();
  841.         }
  842.     }
  843.     nextmenu = MENUE;
  844. }
  845.  
  846. //--------------------------------------------------------------------------------------------
  847. void menu_boot_players()
  848. {
  849.     // ZZ> This function shows all the active players and lets the host kick 'em out
  850.     //     !!!BAD!!!  Let the host boot players
  851.     char text[256];
  852.     int x, y, starttime, time;
  853.     float open;
  854.     int cnt, player;
  855.     int stillchoosing;
  856.  
  857.  
  858.     numplayer = 1;
  859.     if(networkon)
  860.     {
  861.         // Find players
  862.         find_all_players();
  863.  
  864.         // Open a big window
  865.         open = 0;
  866.         while(open < 1.0)
  867.         {
  868.             //clear_surface(lpDDSBack);
  869.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  870.                 glLoadIdentity();
  871.             draw_trim_box_opening(0, 0, scrx, scry, open);
  872.             draw_trim_box_opening(0, 0, 320, fontyspacing*(numplayer+4), open);
  873.             flip_pages();
  874.             open += .030;
  875.         }
  876.  
  877.         // Tell the user which ones we found
  878.         starttime = ClockGetTick(); //GetTickCount(); PUSHED INTO win/lin-file
  879.         stillchoosing = TRUE;
  880.         while(stillchoosing)
  881.         {
  882.             time = ClockGetTick(); //GetTickCount();
  883.             if((time-starttime) > NETREFRESH)
  884.             {
  885.                 find_all_players();
  886.                 starttime = time;
  887.             }
  888.             //clear_surface(lpDDSBack);
  889.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  890.                 glLoadIdentity();
  891.             draw_trim_box(0, 0, scrx, scry);
  892.             draw_trim_box(0, 0, 320, fontyspacing*(numplayer+4));
  893.             y = 8;
  894.             sprintf(text, "Active machines...");
  895.             draw_string(text, 14, y);
  896.             y += fontyspacing;
  897.             cnt = 0;
  898.             while(cnt < numplayer)
  899.             {
  900.                 sprintf(text, "%s", netplayername[cnt]);
  901.                 draw_string(text, 50, y);
  902.                 y += fontyspacing;
  903.                 cnt++;
  904.             }
  905.             if(hostactive)
  906.             {
  907.                 sprintf(text, "Start Game");
  908.                 draw_string(text, 50, y);
  909.             }
  910.             else
  911.             {
  912.                 listen_for_packets();
  913.             }
  914.             do_cursor();
  915.             x = cursorx - 50;
  916.             y = (cursory - 8 - fontyspacing);
  917.             if(SDLKEYDOWN(SDLK_ESCAPE)) // !!!BAD!!!
  918.             {
  919.                 nextmenu = MENUB;
  920.                 menuactive = FALSE;
  921.                 stillchoosing = FALSE;
  922.                 gameactive = FALSE;
  923.             }
  924.             if(x > 0 && x < 300 && y >= 0 && (mousebutton[0] || mousebutton[1]) && hostactive)
  925.             {
  926.                 // Let the host do things
  927.                 y = y/fontyspacing;
  928.                 if(y < numplayer && hostactive)
  929.                 {
  930.                     // Boot players
  931.                 }
  932.                 if(y == numplayer && readytostart)
  933.                 {
  934.                     // Start the modules
  935.                     stillchoosing = FALSE;
  936.                 }
  937.             }
  938.             if(readytostart && hostactive == FALSE)
  939.             {
  940.                 // Remotes automatically start
  941.                 stillchoosing = FALSE;
  942.             }
  943.             flip_pages();
  944.         }
  945.     }
  946.     if(networkon && hostactive)
  947.     {
  948.         // Let the host coordinate start
  949.         stop_players_from_joining();
  950.         find_all_players();
  951.         cnt = 0;
  952.         readytostart = FALSE;
  953.         if(numplayer == 1)
  954.         {
  955.             // Don't need to bother, since the host is alone
  956.             readytostart = TRUE;
  957.         }
  958.         while(readytostart==FALSE)
  959.         {
  960.             //clear_surface(lpDDSBack);
  961.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  962.                 glLoadIdentity();
  963.             draw_trim_box(0, 0, scrx, scry);
  964.             y = 8;
  965.             sprintf(text, "Waiting for replies...");
  966.             draw_string(text, 14, y);
  967.             y += fontyspacing;
  968.             do_cursor();
  969.             if(SDLKEYDOWN(SDLK_ESCAPE)) // !!!BAD!!!
  970.             {
  971.                 nextmenu = MENUB;
  972.                 menuactive = FALSE;
  973.                 stillchoosing = FALSE;
  974.                 gameactive = FALSE;
  975.                 readytostart = TRUE;
  976.             }
  977.             if((cnt&63)==0)
  978.             {
  979.                 sprintf(text, "  Lell...");
  980.                 draw_string(text, 14, y);
  981.                 player = 0;
  982.                 while(player < numplayer-1)
  983.                 {
  984.                     start_building_packet();
  985.                     add_packet_us(TO_REMOTE_MODULE);
  986.                     add_packet_ui(seed);
  987.                     add_packet_uc(player+1);
  988.                     add_packet_sz(pickedmodule);
  989. //                    send_packet_to_all_players();
  990.                     send_packet_to_one_player_guaranteed(player);
  991.                     player++;
  992.                 }
  993.             }
  994.             listen_for_packets();
  995.             cnt++;
  996.             flip_pages();
  997.         }
  998.     }
  999.  
  1000.  
  1001.     nextmenu=MENUF;
  1002. }
  1003.  
  1004. //--------------------------------------------------------------------------------------------
  1005. void menu_end_text()
  1006. {
  1007.     // ZZ> This function gives the player the ending text
  1008.     float open;
  1009.     int stillchoosing;
  1010.     SDL_Event ev;
  1011.  
  1012.  
  1013.     // Open the text window
  1014.     open = 0;
  1015.     while(open < 1.0)
  1016.     {
  1017.         //clear_surface(lpDDSBack);
  1018.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1019.                 glLoadIdentity();
  1020.         draw_trim_box_opening(0, 0, scrx, scry, open);
  1021.         flip_pages();
  1022.         open += .030;
  1023.     }
  1024.  
  1025.  
  1026.  
  1027.     // Wait for input
  1028.     stillchoosing = TRUE;
  1029.     while(stillchoosing)
  1030.     {
  1031.         // Show the text
  1032.         //clear_surface(lpDDSBack);
  1033.                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1034.                 glLoadIdentity();
  1035.         draw_trim_box(0, 0, scrx, scry);
  1036.         draw_wrap_string(endtext, 14, 8, scrx-40);
  1037.  
  1038.  
  1039.  
  1040.         // Handle the mouse
  1041.         do_cursor();
  1042.         if(pending_click || SDLKEYDOWN(SDLK_ESCAPE))
  1043.         {
  1044.         pending_click = FALSE;
  1045.             stillchoosing = FALSE;
  1046.         }
  1047.         flip_pages();
  1048.     }
  1049.     nextmenu = MENUB;
  1050. }
  1051.  
  1052. //--------------------------------------------------------------------------------------------
  1053. void menu_initial_text()
  1054. {
  1055.     // ZZ> This function gives the player the initial title screen
  1056.     float open;
  1057.     char text[1024];
  1058.     int stillchoosing;
  1059.  
  1060.  
  1061.     //fprintf(stderr,"DIAG: In menu_initial_text()\n");
  1062.     //draw_trim_box(0, 0, scrx, scry);//draw_trim_box(60, 60, 320, 200); // JUST TEST BOX
  1063.     
  1064.     // Open the text window
  1065.     open = 0;
  1066.     while(open < 1.0)
  1067.     {
  1068.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1069.         glLoadIdentity();
  1070.         
  1071.         // clear_surface(lpDDSBack); PORT!
  1072.         draw_trim_box_opening(0, 0, scrx, scry, open);
  1073.         flip_pages();
  1074.         open += .030;
  1075.     }
  1076.  
  1077.     /*fprintf(stderr,"waiting to read a scanf\n");
  1078.     scanf("%s",text);
  1079.     exit(0);*/
  1080.  
  1081.     // Wait for input
  1082.     stillchoosing = TRUE;
  1083.     while(stillchoosing)
  1084.     {
  1085.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1086.         glLoadIdentity();
  1087.         
  1088.         // Show the text
  1089.         // clear_surface(lpDDSBack); PORT!
  1090.         draw_trim_box(0, 0, scrx, scry);
  1091.         sprintf(text, "Egoboo v2.22");
  1092.         draw_string(text, (scrx>>1)-200, ((scry>>1)-30));
  1093.         sprintf(text, "http://egoboo.sourceforge.net");
  1094.         draw_string(text, (scrx>>1)-200, ((scry>>1)));
  1095.         sprintf(text, "See controls.txt to configure input");
  1096.         draw_string(text, (scrx>>1)-200, ((scry>>1)+30));
  1097.         
  1098.         // get input
  1099.         read_input();
  1100.         
  1101.         // Handle the mouse
  1102.         do_cursor();
  1103.         if ( pending_click || SDLKEYDOWN(SDLK_ESCAPE) )
  1104.         {
  1105.                 pending_click = FALSE;
  1106.             stillchoosing = FALSE;
  1107.         }
  1108.         flip_pages();
  1109.     }
  1110.     nextmenu = MENUA;
  1111. }
  1112.  
  1113. //--------------------------------------------------------------------------------------------
  1114. void fiddle_with_menu()
  1115. {
  1116.     // ZZ> This function gives a nice little menu to play around in.
  1117.  
  1118.     menuactive = TRUE;
  1119.     readytostart = FALSE;
  1120.     playersready = 0;
  1121.     localmachine = 0;
  1122.     rtslocalteam = 0;
  1123.     numfile = 0;
  1124.     numfilesent = 0;
  1125.     numfileexpected = 0;
  1126.     while(menuactive)
  1127.     {
  1128.         switch(nextmenu)
  1129.         {
  1130.             case MENUA:
  1131.                 // MENUA...  Let the user choose a network service
  1132.                 //printf("MENUA\n");
  1133.                 if(menuaneeded)
  1134.                 {
  1135.                     menu_service_select();
  1136.                     menuaneeded = FALSE;
  1137.                 }
  1138.                 nextmenu = MENUB;
  1139.                 break;
  1140.             case MENUB:
  1141.                 // MENUB...  Let the user start or join
  1142.                 //printf("MENUB\n");
  1143.                 menu_start_or_join();
  1144.                 break;
  1145.             case MENUC:
  1146.                 // MENUC...  Choose an open game to join
  1147.                 //printf("MENUC\n");
  1148.                 menu_choose_host();
  1149.                 break;
  1150.             case MENUD:
  1151.                 // MENUD...  Choose a module to run
  1152.                 //printf("MENUD\n");
  1153.                 menu_choose_module();
  1154.                 break;
  1155.             case MENUE:
  1156.                 // MENUE...  Wait for all the players
  1157.                 //printf("MENUE\n");
  1158.                 menu_boot_players();
  1159.                 break;
  1160.             case MENUF:
  1161.                 // MENUF...  Let the players choose characters
  1162.                 //printf("MENUF\n");
  1163.                 menu_pick_player(pickedindex);
  1164.                 break;
  1165.             case MENUG:
  1166.                 // MENUG...  Let the user read while it loads
  1167.                 //printf("MENUG\n");
  1168.                 menu_module_loading(pickedindex);
  1169.                 break;
  1170.             case MENUH:
  1171.                 // MENUH...  Show the end text
  1172.                 //printf("MENUH\n");
  1173.                 menu_end_text();
  1174.                 break;
  1175.             case MENUI:
  1176.                 // MENUI...  Show the initial text
  1177.                 //printf("MENUI\n");
  1178.                 menu_initial_text();
  1179.                 break;
  1180.         }
  1181.     }
  1182.     //printf("Left menu system\n");
  1183. }
  1184.  
  1185. //--------------------------------------------------------------------------------------------
  1186. void release_menu_trim()
  1187. {
  1188.     // ZZ> This function frees the menu trim memory
  1189.     //GLTexture_Release( &TxTrimX );        //RELEASE(lpDDSTrimX);
  1190.     //GLTexture_Release( &TxTrimY );        //RELEASE(lpDDSTrimY);
  1191.     GLTexture_Release( &TxBlip );        //RELEASE(lpDDSBlip);
  1192.     GLTexture_Release( &TxTrim );
  1193.     
  1194. }
  1195.  
  1196. //--------------------------------------------------------------------------------------------
  1197. void release_menu()
  1198. {
  1199.     // ZZ> This function releases all the menu images
  1200.     GLTexture_Release( &TxFont );        //RELEASE(lpDDSFont);
  1201.     release_all_titleimages();
  1202.     release_all_icons();
  1203.     
  1204. }
  1205.  
  1206.