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