home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / centers.c < prev    next >
C/C++ Source or Header  |  1998-06-08  |  8KB  |  243 lines

  1. /*
  2.  * $Source: f:/miner/source/main/editor/rcs/centers.c $
  3.  * $Revision: 2.0 $
  4.  * $Author: john $
  5.  * $Date: 1995/02/27 11:35:30 $
  6.  * 
  7.  * Dialog box stuff for control centers, material centers, etc.
  8.  * 
  9.  * $Log: centers.c $
  10.  * Revision 2.0  1995/02/27  11:35:30  john
  11.  * Version 2.0! No anonymous unions, Watcom 10.0, with no need
  12.  * for bitmaps.tbl.
  13.  * 
  14.  * Revision 1.9  1994/11/27  23:17:28  matt
  15.  * Made changes for new mprintf calling convention
  16.  * 
  17.  * Revision 1.8  1994/10/05  22:13:46  mike
  18.  * Clean up Centers dialog.
  19.  * 
  20.  * Revision 1.7  1994/10/03  23:39:55  mike
  21.  * Call fuelcen_activate instead of fuelcen_create.
  22.  * 
  23.  * Revision 1.6  1994/08/02  12:16:35  mike
  24.  * Change materialization center functionality.
  25.  * 
  26.  * Revision 1.5  1994/08/01  11:04:42  yuan
  27.  * New materialization centers.
  28.  * 
  29.  * Revision 1.4  1994/07/22  17:19:10  yuan
  30.  * Working on dialog box for refuel/repair/material/control centers.
  31.  * 
  32.  * Revision 1.3  1994/07/21  19:35:09  yuan
  33.  * Fixed #include problem
  34.  * 
  35.  * Revision 1.2  1994/07/21  19:02:41  yuan
  36.  * *** empty log message ***
  37.  * 
  38.  * Revision 1.1  1994/07/18  16:00:54  yuan
  39.  * Initial revision
  40.  * 
  41.  * 
  42.  */
  43.  
  44.  
  45. #pragma off (unreferenced)
  46. static char rcsid[] = "$Id: centers.c 2.0 1995/02/27 11:35:30 john Exp $";
  47. #pragma on (unreferenced)
  48.  
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #include <math.h>
  52. #include <string.h>
  53.  
  54. #include "fuelcen.h"
  55. #include "screens.h"
  56. #include "inferno.h"
  57. #include "segment.h"
  58. #include "editor.h"
  59.  
  60. #include "timer.h"
  61. #include "objpage.h"
  62. #include "fix.h"
  63. #include "mono.h"
  64. #include "error.h"
  65. #include "kdefs.h"
  66. #include    "object.h"
  67. #include "polyobj.h"
  68. #include "game.h"
  69. #include "powerup.h"
  70. #include "ai.h"
  71. #include "hostage.h"
  72. #include "eobject.h"
  73. #include "medwall.h"
  74. #include "eswitch.h"
  75. #include "ehostage.h"
  76. #include "key.h"
  77. #include "medrobot.h"
  78. #include "bm.h"
  79. #include "centers.h"
  80.  
  81. //-------------------------------------------------------------------------
  82. // Variables for this module...
  83. //-------------------------------------------------------------------------
  84. static UI_WINDOW                 *MainWindow = NULL;
  85. static UI_GADGET_BUTTON     *QuitButton;
  86. static UI_GADGET_RADIO        *CenterFlag[MAX_CENTER_TYPES];
  87. static UI_GADGET_CHECKBOX    *RobotMatFlag[MAX_ROBOT_TYPES];
  88.  
  89. static int old_seg_num;
  90.  
  91. extern    char    center_names[MAX_CENTER_TYPES][CENTER_STRING_LENGTH] = {
  92.     "Nothing",
  93.     "FuelCen",
  94.     "RepairCen",
  95.     "ControlCen",
  96.     "RobotMaker"
  97. };
  98.  
  99. //-------------------------------------------------------------------------
  100. // Called from the editor... does one instance of the centers dialog box
  101. //-------------------------------------------------------------------------
  102. int do_centers_dialog()
  103. {
  104.     int i;
  105.  
  106.     // Only open 1 instance of this window...
  107.     if ( MainWindow != NULL ) return 0;
  108.  
  109.     // Close other windows.    
  110.     close_trigger_window();
  111.     hostage_close_window();
  112.     close_wall_window();
  113.     robot_close_window();
  114.  
  115.     // Open a window with a quit button
  116.     MainWindow = ui_open_window( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, WIN_DIALOG );
  117.     QuitButton = ui_add_gadget_button( MainWindow, 20, 252, 48, 40, "Done", NULL );
  118.  
  119.     // These are the checkboxes for each door flag.
  120.     i = 80;
  121.     CenterFlag[0] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "NONE" );             i += 24;
  122.     CenterFlag[1] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "FuelCen" );        i += 24;
  123.     CenterFlag[2] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "RepairCen" );    i += 24;
  124.     CenterFlag[3] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "ControlCen" );    i += 24;
  125.     CenterFlag[4] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "RobotCen" );        i += 24;
  126.  
  127.     // These are the checkboxes for each door flag.
  128.     for (i=0; i<N_robot_types; i++)
  129.         RobotMatFlag[i] = ui_add_gadget_checkbox( MainWindow, 128 + (i%2)*92, 20+(i/2)*24, 16, 16, 0, Robot_names[i]);
  130.                                                                                                       
  131.     old_seg_num = -2;        // Set to some dummy value so everything works ok on the first frame.
  132.  
  133.     return 1;
  134. }
  135.  
  136. void close_centers_window()
  137. {
  138.     if ( MainWindow!=NULL )    {
  139.         ui_close_window( MainWindow );
  140.         MainWindow = NULL;
  141.     }
  142. }
  143.  
  144. void do_centers_window()
  145. {
  146.     int i;
  147. //    int robot_flags;
  148.     int redraw_window;
  149.  
  150.     if ( MainWindow == NULL ) return;
  151.  
  152.     //------------------------------------------------------------
  153.     // Call the ui code..
  154.     //------------------------------------------------------------
  155.     ui_button_any_drawn = 0;
  156.     ui_window_do_gadgets(MainWindow);
  157.  
  158.     //------------------------------------------------------------
  159.     // If we change walls, we need to reset the ui code for all
  160.     // of the checkboxes that control the wall flags.  
  161.     //------------------------------------------------------------
  162.     if (old_seg_num != Cursegp-Segments) {
  163.         for (    i=0; i < MAX_CENTER_TYPES; i++ ) {
  164.             CenterFlag[i]->flag = 0;        // Tells ui that this button isn't checked
  165.             CenterFlag[i]->status = 1;        // Tells ui to redraw button
  166.         }
  167.  
  168.         Assert(Cursegp->special < MAX_CENTER_TYPES);
  169.         CenterFlag[Cursegp->special]->flag = 1;
  170.  
  171.         mprintf((0, "Cursegp->matcen_num = %i\n", Cursegp->matcen_num));
  172.  
  173.         //    Read materialization center robot bit flags
  174.         for (    i=0; i < N_robot_types; i++ ) {
  175.             RobotMatFlag[i]->status = 1;        // Tells ui to redraw button
  176.             if (RobotCenters[Cursegp->matcen_num].robot_flags & (1 << i))
  177.                 RobotMatFlag[i]->flag = 1;        // Tells ui that this button is checked
  178.             else
  179.                 RobotMatFlag[i]->flag = 0;        // Tells ui that this button is not checked
  180.         }
  181.  
  182.     }
  183.  
  184.     //------------------------------------------------------------
  185.     // If any of the radio buttons that control the mode are set, then
  186.     // update the corresponding center.
  187.     //------------------------------------------------------------
  188.  
  189.     redraw_window=0;
  190.     for (    i=0; i < MAX_CENTER_TYPES; i++ )    {
  191.         if ( CenterFlag[i]->flag == 1 )
  192.             if ( i == 0)
  193.                 fuelcen_delete(Cursegp);
  194.             else if ( Cursegp->special != i ) {
  195.                 fuelcen_delete(Cursegp);
  196.                 redraw_window = 1;
  197.                 fuelcen_activate( Cursegp, i );
  198.             }
  199.     }
  200.  
  201.     for (    i=0; i < N_robot_types; i++ )    {
  202.         if ( RobotMatFlag[i]->flag == 1 ) {
  203.             if (!(RobotCenters[Cursegp->matcen_num].robot_flags & (1<<i) )) {
  204.                 RobotCenters[Cursegp->matcen_num].robot_flags |= (1<<i);
  205.                 mprintf((0,"Segment %i, matcen = %i, Robot_flags %d\n", Cursegp-Segments, Cursegp->matcen_num, RobotCenters[Cursegp->matcen_num].robot_flags));
  206.             } 
  207.         } else if (RobotCenters[Cursegp->matcen_num].robot_flags & 1<<i) {
  208.             RobotCenters[Cursegp->matcen_num].robot_flags &= ~(1<<i);
  209.             mprintf((0,"Segment %i, matcen = %i, Robot_flags %d\n", Cursegp-Segments, Cursegp->matcen_num, RobotCenters[Cursegp->matcen_num].robot_flags));
  210.         }
  211.     }
  212.     
  213.     //------------------------------------------------------------
  214.     // If anything changes in the ui system, redraw all the text that
  215.     // identifies this wall.
  216.     //------------------------------------------------------------
  217.     if (redraw_window || (old_seg_num != Cursegp-Segments ) ) {
  218. //        int    i;
  219. //        char    temp_text[CENTER_STRING_LENGTH];
  220.     
  221.         ui_wprintf_at( MainWindow, 12, 6, "Seg: %3d", Cursegp-Segments );
  222.  
  223. //        for (i=0; i<CENTER_STRING_LENGTH; i++)
  224. //            temp_text[i] = ' ';
  225. //        temp_text[i] = 0;
  226.  
  227. //        Assert(Cursegp->special < MAX_CENTER_TYPES);
  228. //        strncpy(temp_text, Center_names[Cursegp->special], strlen(Center_names[Cursegp->special]));
  229. //        ui_wprintf_at( MainWindow, 12, 23, " Type: %s", temp_text );
  230.         Update_flags |= UF_WORLD_CHANGED;
  231.     }
  232.  
  233.     if ( QuitButton->pressed || (last_keypress==KEY_ESC) )    {
  234.         close_centers_window();
  235.         return;
  236.     }        
  237.  
  238.     old_seg_num = Cursegp-Segments;
  239. }
  240.  
  241.  
  242.  
  243.