]> icculus.org git repositories - btb/d2x.git/blob - main/editor/centers.c
include conf.h in new editor files
[btb/d2x.git] / main / editor / centers.c
1 /* $Id: centers.c,v 1.3 2004-12-19 15:21:11 btb Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Dialog box stuff for control centers, material centers, etc.
18  *
19  */
20
21 #ifdef RCS
22 static char rcsid[] = "$Id: centers.c,v 1.3 2004-12-19 15:21:11 btb Exp $";
23 #endif
24
25 #ifdef HAVE_CONFIG_H
26 #include "conf.h"
27 #endif
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <math.h>
32 #include <string.h>
33
34 #include "fuelcen.h"
35 #include "screens.h"
36 #include "inferno.h"
37 #include "segment.h"
38 #include "editor.h"
39
40 #include "timer.h"
41 #include "objpage.h"
42 #include "fix.h"
43 #include "mono.h"
44 #include "error.h"
45 #include "kdefs.h"
46 #include        "object.h"
47 #include "polyobj.h"
48 #include "game.h"
49 #include "powerup.h"
50 #include "ai.h"
51 #include "hostage.h"
52 #include "eobject.h"
53 #include "medwall.h"
54 #include "eswitch.h"
55 #include "ehostage.h"
56 #include "key.h"
57 #include "medrobot.h"
58 #include "bm.h"
59 #include "centers.h"
60
61 //-------------------------------------------------------------------------
62 // Variables for this module...
63 //-------------------------------------------------------------------------
64 static UI_WINDOW                                *MainWindow = NULL;
65 static UI_GADGET_BUTTON         *QuitButton;
66 static UI_GADGET_RADIO          *CenterFlag[MAX_CENTER_TYPES];
67 static UI_GADGET_CHECKBOX       *RobotMatFlag[MAX_ROBOT_TYPES];
68
69 static int old_seg_num;
70
71 char    center_names[MAX_CENTER_TYPES][CENTER_STRING_LENGTH] = {
72         "Nothing",
73         "FuelCen",
74         "RepairCen",
75         "ControlCen",
76         "RobotMaker"
77 };
78
79 //-------------------------------------------------------------------------
80 // Called from the editor... does one instance of the centers dialog box
81 //-------------------------------------------------------------------------
82 int do_centers_dialog()
83 {
84         int i;
85
86         // Only open 1 instance of this window...
87         if ( MainWindow != NULL ) return 0;
88
89         // Close other windows. 
90         close_trigger_window();
91         hostage_close_window();
92         close_wall_window();
93         robot_close_window();
94
95         // Open a window with a quit button
96         MainWindow = ui_open_window( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, WIN_DIALOG );
97         QuitButton = ui_add_gadget_button( MainWindow, 20, 252, 48, 40, "Done", NULL );
98
99         // These are the checkboxes for each door flag.
100         i = 80;
101         CenterFlag[0] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "NONE" );                    i += 24;
102         CenterFlag[1] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "FuelCen" );         i += 24;
103         CenterFlag[2] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "RepairCen" );       i += 24;
104         CenterFlag[3] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "ControlCen" );      i += 24;
105         CenterFlag[4] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "RobotCen" );                i += 24;
106
107         // These are the checkboxes for each door flag.
108         for (i=0; i<N_robot_types; i++)
109                 RobotMatFlag[i] = ui_add_gadget_checkbox( MainWindow, 128 + (i%2)*92, 20+(i/2)*24, 16, 16, 0, Robot_names[i]);
110                                                                                                                                                                                                           
111         old_seg_num = -2;               // Set to some dummy value so everything works ok on the first frame.
112
113         return 1;
114 }
115
116 void close_centers_window()
117 {
118         if ( MainWindow!=NULL ) {
119                 ui_close_window( MainWindow );
120                 MainWindow = NULL;
121         }
122 }
123
124 void do_centers_window()
125 {
126         int i;
127 //      int robot_flags;
128         int redraw_window;
129
130         if ( MainWindow == NULL ) return;
131
132         //------------------------------------------------------------
133         // Call the ui code..
134         //------------------------------------------------------------
135         ui_button_any_drawn = 0;
136         ui_window_do_gadgets(MainWindow);
137
138         //------------------------------------------------------------
139         // If we change walls, we need to reset the ui code for all
140         // of the checkboxes that control the wall flags.  
141         //------------------------------------------------------------
142         if (old_seg_num != Cursegp-Segments) {
143                 for (   i=0; i < MAX_CENTER_TYPES; i++ ) {
144                         CenterFlag[i]->flag = 0;                // Tells ui that this button isn't checked
145                         CenterFlag[i]->status = 1;              // Tells ui to redraw button
146                 }
147
148                 Assert(Cursegp->special < MAX_CENTER_TYPES);
149                 CenterFlag[Cursegp->special]->flag = 1;
150
151                 mprintf((0, "Cursegp->matcen_num = %i\n", Cursegp->matcen_num));
152
153                 //      Read materialization center robot bit flags
154                 for (   i=0; i < N_robot_types; i++ ) {
155                         RobotMatFlag[i]->status = 1;            // Tells ui to redraw button
156                         if (RobotCenters[Cursegp->matcen_num].robot_flags & (1 << i))
157                                 RobotMatFlag[i]->flag = 1;              // Tells ui that this button is checked
158                         else
159                                 RobotMatFlag[i]->flag = 0;              // Tells ui that this button is not checked
160                 }
161
162         }
163
164         //------------------------------------------------------------
165         // If any of the radio buttons that control the mode are set, then
166         // update the corresponding center.
167         //------------------------------------------------------------
168
169         redraw_window=0;
170         for (   i=0; i < MAX_CENTER_TYPES; i++ )        {
171                 if ( CenterFlag[i]->flag == 1 )
172                  {
173                         if ( i == 0)
174                                 fuelcen_delete(Cursegp);
175                         else if ( Cursegp->special != i ) {
176                                 fuelcen_delete(Cursegp);
177                                 redraw_window = 1;
178                                 fuelcen_activate( Cursegp, i );
179                         }
180                  }
181         }
182
183         for (   i=0; i < N_robot_types; i++ )   {
184                 if ( RobotMatFlag[i]->flag == 1 ) {
185                         if (!(RobotCenters[Cursegp->matcen_num].robot_flags & (1<<i) )) {
186                                 RobotCenters[Cursegp->matcen_num].robot_flags |= (1<<i);
187                                 mprintf((0,"Segment %i, matcen = %i, Robot_flags %d\n", Cursegp-Segments, Cursegp->matcen_num, RobotCenters[Cursegp->matcen_num].robot_flags));
188                         } 
189                 } else if (RobotCenters[Cursegp->matcen_num].robot_flags & 1<<i) {
190                         RobotCenters[Cursegp->matcen_num].robot_flags &= ~(1<<i);
191                         mprintf((0,"Segment %i, matcen = %i, Robot_flags %d\n", Cursegp-Segments, Cursegp->matcen_num, RobotCenters[Cursegp->matcen_num].robot_flags));
192                 }
193         }
194         
195         //------------------------------------------------------------
196         // If anything changes in the ui system, redraw all the text that
197         // identifies this wall.
198         //------------------------------------------------------------
199         if (redraw_window || (old_seg_num != Cursegp-Segments ) ) {
200 //              int     i;
201 //              char    temp_text[CENTER_STRING_LENGTH];
202         
203                 ui_wprintf_at( MainWindow, 12, 6, "Seg: %3d", Cursegp-Segments );
204
205 //              for (i=0; i<CENTER_STRING_LENGTH; i++)
206 //                      temp_text[i] = ' ';
207 //              temp_text[i] = 0;
208
209 //              Assert(Cursegp->special < MAX_CENTER_TYPES);
210 //              strncpy(temp_text, Center_names[Cursegp->special], strlen(Center_names[Cursegp->special]));
211 //              ui_wprintf_at( MainWindow, 12, 23, " Type: %s", temp_text );
212                 Update_flags |= UF_WORLD_CHANGED;
213         }
214
215         if ( QuitButton->pressed || (last_keypress==KEY_ESC) )  {
216                 close_centers_window();
217                 return;
218         }               
219
220         old_seg_num = Cursegp-Segments;
221 }
222
223
224