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