]> icculus.org git repositories - btb/d2x.git/blob - main/editor/centers.c
remove rcs tags
[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 /*
15  *
16  * Dialog box stuff for control centers, material centers, etc.
17  *
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "conf.h"
22 #endif
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <math.h>
27 #include <string.h>
28
29 #include "fuelcen.h"
30 #include "screens.h"
31 #include "inferno.h"
32 #include "segment.h"
33 #include "editor.h"
34
35 #include "timer.h"
36 #include "objpage.h"
37 #include "fix.h"
38 #include "mono.h"
39 #include "error.h"
40 #include "kdefs.h"
41 #include        "object.h"
42 #include "polyobj.h"
43 #include "game.h"
44 #include "powerup.h"
45 #include "ai.h"
46 #include "hostage.h"
47 #include "eobject.h"
48 #include "medwall.h"
49 #include "eswitch.h"
50 #include "ehostage.h"
51 #include "key.h"
52 #include "medrobot.h"
53 #include "bm.h"
54 #include "centers.h"
55
56 //-------------------------------------------------------------------------
57 // Variables for this module...
58 //-------------------------------------------------------------------------
59 static UI_WINDOW                                *MainWindow = NULL;
60 static UI_GADGET_BUTTON         *QuitButton;
61 static UI_GADGET_RADIO          *CenterFlag[MAX_CENTER_TYPES];
62 static UI_GADGET_CHECKBOX       *RobotMatFlag[64];      // 2 ints = 64 bits
63
64 static int old_seg_num;
65
66 char    center_names[MAX_CENTER_TYPES][CENTER_STRING_LENGTH] = {
67         "Nothing",
68         "FuelCen",
69         "RepairCen",
70         "ControlCen",
71         "RobotMaker"
72 };
73
74 //-------------------------------------------------------------------------
75 // Called from the editor... does one instance of the centers dialog box
76 //-------------------------------------------------------------------------
77 int do_centers_dialog()
78 {
79         int i;
80
81         // Only open 1 instance of this window...
82         if ( MainWindow != NULL ) return 0;
83
84         // Close other windows. 
85         close_trigger_window();
86         hostage_close_window();
87         close_wall_window();
88         robot_close_window();
89
90         // Open a window with a quit button
91         MainWindow = ui_open_window( TMAPBOX_X+20, TMAPBOX_Y+20, 765-TMAPBOX_X, 545-TMAPBOX_Y, WIN_DIALOG );
92         QuitButton = ui_add_gadget_button( MainWindow, 20, 252, 48, 40, "Done", NULL );
93
94         // These are the checkboxes for each door flag.
95         i = 80;
96         CenterFlag[0] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "NONE" );                    i += 24;
97         CenterFlag[1] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "FuelCen" );         i += 24;
98         CenterFlag[2] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "RepairCen" );       i += 24;
99         CenterFlag[3] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "ControlCen" );      i += 24;
100         CenterFlag[4] = ui_add_gadget_radio( MainWindow, 18, i, 16, 16, 0, "RobotCen" );                i += 24;
101
102         // These are the checkboxes for each robot flag.
103         for (i=0; i < 64; i++)
104                 RobotMatFlag[i] = ui_add_gadget_checkbox( MainWindow, 128 + (i%2)*92, 20+(i/2)*24, 16, 16, 0, Robot_names[i]);
105                                                                                                                                                                                                           
106         old_seg_num = -2;               // Set to some dummy value so everything works ok on the first frame.
107
108         return 1;
109 }
110
111 void close_centers_window()
112 {
113         if ( MainWindow!=NULL ) {
114                 ui_close_window( MainWindow );
115                 MainWindow = NULL;
116         }
117 }
118
119 void do_centers_window()
120 {
121         int i;
122         int robot_flags;
123         int redraw_window;
124         int robot_index;
125
126         if ( MainWindow == NULL ) return;
127
128         //------------------------------------------------------------
129         // Call the ui code..
130         //------------------------------------------------------------
131         ui_button_any_drawn = 0;
132         ui_window_do_gadgets(MainWindow);
133
134         //------------------------------------------------------------
135         // If we change walls, we need to reset the ui code for all
136         // of the checkboxes that control the wall flags.  
137         //------------------------------------------------------------
138         if (old_seg_num != SEGMENT_NUMBER(Cursegp)) {
139                 Assert(Curseg2p->special < MAX_CENTER_TYPES);
140                 ui_radio_set_value(CenterFlag[Curseg2p->special], 1);
141
142                 mprintf((0, "Curseg2p->matcen_num = %i\n", Curseg2p->matcen_num));
143
144                 //      Read materialization center robot bit flags
145                 for (i = 0; i < 2; i++)
146                 {
147                         robot_index = i * 32;
148                         robot_flags = RobotCenters[Curseg2p->matcen_num].robot_flags[i];
149                         while (robot_flags)
150                         {
151                                 ui_checkbox_check(RobotMatFlag[i], robot_flags & 1);
152                                 robot_flags >>= 1;
153                                 robot_index++;
154                         }
155                 }
156
157         }
158
159         //------------------------------------------------------------
160         // If any of the radio buttons that control the mode are set, then
161         // update the corresponding center.
162         //------------------------------------------------------------
163
164         redraw_window=0;
165         for (   i=0; i < MAX_CENTER_TYPES; i++ )        {
166                 if ( CenterFlag[i]->flag == 1 )
167                  {
168                         if ( i == 0)
169                                 fuelcen_delete(Cursegp);
170                         else if (Curseg2p->special != i)
171                         {
172                                 fuelcen_delete(Cursegp);
173                                 redraw_window = 1;
174                                 fuelcen_activate( Cursegp, i );
175                         }
176                  }
177         }
178
179         for (i = 0; i < 2; i++)
180         {
181                 robot_flags = RobotCenters[Curseg2p->matcen_num].robot_flags[i];
182
183                 for (robot_index = 0; robot_index < 32; robot_index++)
184                 {
185                         if (RobotMatFlag[robot_index + i * 32]->flag == 1)
186                         {
187                                 if (!(robot_flags & (1 << robot_index)))
188                                 {
189                                         robot_flags |= (1 << robot_index);
190                                         mprintf((0, "Segment %i, matcen = %i, robot_flags[%d] = %d\n", SEGMENT_NUMBER(Cursegp), Curseg2p->matcen_num, i, robot_flags));
191                                 }
192                         }
193                         else if (robot_flags & 1 << robot_index)
194                         {
195                                 robot_flags &= ~(1 << robot_index);
196                                 mprintf((0, "Segment %i, matcen = %i, robot_flags[%d] = %d\n", SEGMENT_NUMBER(Cursegp), Curseg2p->matcen_num, i, robot_flags));
197                         }
198                 }
199
200                 RobotCenters[Curseg2p->matcen_num].robot_flags[i] = robot_flags;
201         }
202         
203         //------------------------------------------------------------
204         // If anything changes in the ui system, redraw all the text that
205         // identifies this wall.
206         //------------------------------------------------------------
207         if ( redraw_window || (old_seg_num != SEGMENT_NUMBER(Cursegp)) ) {
208 //              int     i;
209 //              char    temp_text[CENTER_STRING_LENGTH];
210         
211                 ui_wprintf_at( MainWindow, 12, 6, "Seg: %3d", SEGMENT_NUMBER(Cursegp) );
212
213 //              for (i=0; i<CENTER_STRING_LENGTH; i++)
214 //                      temp_text[i] = ' ';
215 //              temp_text[i] = 0;
216
217 //              Assert(Curseg2p->special < MAX_CENTER_TYPES);
218 //              strncpy(temp_text, Center_names[Curseg2p->special], strlen(Center_names[Curseg2p->special]));
219 //              ui_wprintf_at( MainWindow, 12, 23, " Type: %s", temp_text );
220                 Update_flags |= UF_WORLD_CHANGED;
221         }
222
223         if ( QuitButton->pressed || (last_keypress==KEY_ESC) )  {
224                 close_centers_window();
225                 return;
226         }               
227
228         old_seg_num = SEGMENT_NUMBER(Cursegp);
229 }
230
231
232