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