]> icculus.org git repositories - btb/d2x.git/blob - main/editor/info.c
Fix crash if Num_walls=0
[btb/d2x.git] / main / editor / info.c
1 /* $Id: info.c,v 1.4 2005-01-24 21:59:35 schaffner 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  * Print debugging info in ui.
18  *
19  */
20
21 #ifdef RCS
22 static char rcsid[] = "$Id: info.c,v 1.4 2005-01-24 21:59:35 schaffner 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 <string.h>
32
33 #ifdef DO_MEMINFO
34 #include <i86.h>
35 #include <malloc.h>
36 #endif
37
38 #include "inferno.h"
39 #include "segment.h"
40 #include "gr.h"
41 #include "ui.h"
42 #include "editor.h"
43
44 #include "mono.h"
45 #include "error.h"
46 #include "textures.h"
47 #include "object.h"
48 #include "ai.h"
49
50 #include "texpage.h"            // Textue selection paging stuff
51 #include "objpage.h"            // Object selection paging stuff
52
53 #include "wall.h"
54 #include "switch.h"
55
56 int init_info;
57
58 #ifdef DO_MEMINFO
59 struct meminfo {
60     int LargestBlockAvail;
61     int MaxUnlockedPage;
62     int LargestLockablePage;
63     int LinAddrSpace;
64     int NumFreePagesAvail;
65     int NumPhysicalPagesFree;
66     int TotalPhysicalPages;
67     int FreeLinAddrSpace;
68     int SizeOfPageFile;
69     int Reserved[3];
70 } MemInfo;
71
72 #define DPMI_INT        0x31
73
74 void read_mem_info()
75 {
76     union REGS regs;
77     struct SREGS sregs;
78
79     regs.x.eax = 0x00000500;
80     memset( &sregs, 0, sizeof(sregs) );
81     sregs.es = FP_SEG( &MemInfo );
82     regs.x.edi = FP_OFF( &MemInfo );
83
84     int386x( DPMI_INT, &regs, &regs, &sregs );
85 }
86 #endif
87
88 char * get_object_type(int num, char *name)
89 {
90         switch (num) {
91                 case OBJ_NONE:                  strcpy(name, "OBJ_NONE    ");   break;
92                 case OBJ_WALL:          strcpy(name, "OBJ_WALL    ");   break;
93                 case OBJ_FIREBALL:      strcpy(name, "OBJ_FIREBALL");   break;
94                 case OBJ_ROBOT:                 strcpy(name, "OBJ_ROBOT   ");   break;
95                 case OBJ_HOSTAGE:       strcpy(name, "OBJ_HOSTAGE ");   break;
96                 case OBJ_PLAYER:                strcpy(name, "OBJ_PLAYER  ");   break;
97                 case OBJ_WEAPON:                strcpy(name, "OBJ_WEAPON  ");   break;
98                 case OBJ_CAMERA:                strcpy(name, "OBJ_CAMERA  ");   break;
99                 case OBJ_POWERUP:       strcpy(name, "OBJ_POWERUP ");   break;
100                 default:                                        strcpy(name, " (unknown)  ");   break;
101         }
102
103         return name;
104 }
105
106 char * get_control_type(int num, char *name)
107 {
108         switch (num) {
109                 case CT_NONE:                                   strcpy(name, "CT_NONE       "); break;
110                 case CT_AI:                                             strcpy(name, "CT_AI         "); break;
111                 case CT_EXPLOSION:                      strcpy(name, "CT_EXPLOSION  "); break;
112                 //case CT_MULTIPLAYER:                  strcpy(name, "CT_MULTIPLAYER"); break;
113                 case CT_FLYING:                         strcpy(name, "CT_FLYING     "); break;
114                 case CT_SLEW:                                   strcpy(name, "CT_SLEW       "); break;
115                 case CT_FLYTHROUGH:                     strcpy(name, "CT_FLYTHROUGH "); break;
116                 //case CT_DEMO:                                 strcpy(name, "CT_DEMO       "); break;
117                 //case CT_ROBOT_FLYTHROUGH:     strcpy(name, "CT_FLYTHROUGH "); break;
118                 case CT_WEAPON:                         strcpy(name, "CT_WEAPON     "); break;
119                 default:                                                        strcpy(name, " (unknown)    "); break;
120         }
121         return name;
122 }
123
124 char * get_movement_type(int num, char *name)
125 {
126         switch (num) {
127                 case MT_NONE:                   strcpy(name, "MT_NONE       "); break;
128                 case MT_PHYSICS:                strcpy(name, "MT_PHYSICS    "); break;
129                 //case MT_MULTIPLAYER:  strcpy(name, "MT_MULTIPLAYER"); break;
130                 default:                                        strcpy(name, " (unknown)    "); break;
131         }
132         return name;
133 }
134
135 char * get_ai_behavior(int num, char *name)
136 {
137 #define AIB_STILL                                               0x80
138 #define AIB_NORMAL                                              0x81
139 #define AIB_HIDE                                                        0x82
140 #define AIB_RUN_FROM                                    0x83
141 #define AIB_FOLLOW_PATH                         0x84
142
143         switch (num) {
144                 case AIB_STILL:                         strcpy(name, "STILL       ");   break;
145                 case AIB_NORMAL:                                strcpy(name, "NORMAL      ");   break;
146                 case AIB_HIDE:                                  strcpy(name, "HIDE        ");   break;
147                 case AIB_RUN_FROM:                      strcpy(name, "RUN_FROM    ");   break;
148                 case AIB_FOLLOW_PATH:           strcpy(name, "FOLLOW_PATH ");   break;
149                 default:                                                        strcpy(name, " (unknown)  ");   break;
150         }
151         return name;
152 }
153
154 //      ---------------------------------------------------------------------------------------------------
155 void info_display_object_placement(int show_all)
156 {
157         static  int     old_Cur_object_index;
158         static  int     old_type;
159         static  int     old_movement_type;
160         static  int     old_control_type;
161         static  int     old_mode;
162
163         char            name[30];
164
165         if (init_info | show_all) {
166                 old_Cur_object_index = -2;
167                 old_type = -2;
168                 old_movement_type = -2;
169                 old_control_type = -2;
170                 old_mode = -2;
171         }
172
173         if ( ( Cur_object_index != old_Cur_object_index) || 
174                         ( Objects[Cur_object_index].type != old_type) || 
175                         ( Objects[Cur_object_index].movement_type != old_movement_type) || 
176                         ( Objects[Cur_object_index].control_type != old_control_type) || 
177                         ( Objects[Cur_object_index].ctype.ai_info.behavior != old_mode) ) {
178
179                 gr_uprintf( 0, 0, "Object id: %4d\n", Cur_object_index);
180                 gr_uprintf( 0, 16, "Type: %s\n", get_object_type(Objects[Cur_object_index].type , name));
181                 gr_uprintf( 0, 32, "Movmnt: %s\n", get_movement_type(Objects[Cur_object_index].movement_type, name));
182                 gr_uprintf( 0, 48, "Cntrl: %s\n", get_control_type(Objects[Cur_object_index].control_type, name));
183                 gr_uprintf( 0, 64, "Mode: %s\n", get_ai_behavior(Objects[Cur_object_index].ctype.ai_info.behavior, name));
184
185                 old_Cur_object_index = Cur_object_index;
186                 old_type = Objects[Cur_object_index].type;
187                 old_movement_type = Objects[Cur_object_index].movement_type;
188                 old_mode = Objects[Cur_object_index].control_type;
189                 old_mode = Objects[Cur_object_index].ctype.ai_info.behavior;
190         }
191
192 }
193
194 //      ---------------------------------------------------------------------------------------------------
195 void info_display_segsize(int show_all)
196 {
197         static  int     old_SegSizeMode;
198
199         char            name[30];
200
201         if (init_info | show_all) {
202                 old_SegSizeMode = -2;
203         }
204
205         if (old_SegSizeMode != SegSizeMode  ) {
206                 switch (SegSizeMode) {
207                         case SEGSIZEMODE_FREE:          strcpy(name, "free   ");        break;
208                         case SEGSIZEMODE_ALL:           strcpy(name, "all    ");        break;
209                         case SEGSIZEMODE_CURSIDE:       strcpy(name, "curside");        break;
210                         case SEGSIZEMODE_EDGE:          strcpy(name, "edge   ");        break;
211                         case SEGSIZEMODE_VERTEX:        strcpy(name, "vertex ");        break;
212                         default:
213                                 Error("Illegal value for SegSizeMode in info.c/info_display_segsize\n");
214                 }
215
216                 gr_uprintf( 0, 0, "Mode: %s\n", name);
217
218                 old_SegSizeMode = SegSizeMode;
219         }
220
221 }
222
223 extern int num_objects;
224
225 //      ---------------------------------------------------------------------------------------------------
226 void info_display_default(int show_all)
227 {
228         static int old_Num_segments = -1;
229         static int old_Num_vertices = -1;
230         static int old_Num_objects = -1;
231         static int old_Cursegp_num = -1;
232         static int old_Curside = -1;
233         static int old_Cursegp_num_for_verts = -1;
234         static int old_CurrentTexture = -1;
235         static int old_Num_walls = -1;
236         static int old_Num_triggers = -1;
237
238         if (init_info | show_all) {
239                 init_info = 0;
240                 old_Num_segments = -1;
241                 old_Num_vertices = -1;
242                 old_Num_objects = -1;
243                 old_Cursegp_num = -1;
244                 old_Cursegp_num_for_verts = -1;
245                 old_Curside = -1;
246                 old_CurrentTexture = -1;
247                 old_Num_walls = -1;
248                 old_Num_triggers = -1;
249         }
250
251         gr_set_fontcolor(CBLACK,CWHITE);
252
253         //--------------- Number of segments ----------------
254
255         if ( old_Num_segments != Num_segments ) {
256                 gr_uprintf( 0, 0, "Segments: %4d/%4d", Num_segments, MAX_SEGMENTS );
257                 old_Num_segments = Num_segments;
258         }
259
260         //---------------- Number of vertics -----------------
261         
262         if ( old_Num_vertices != Num_vertices ) {
263                 gr_uprintf( 0, 16, "Vertices: %4d/%4d", Num_vertices, MAX_VERTICES );
264                 old_Num_vertices = Num_vertices;
265         }
266
267         //---------------- Number of objects -----------------
268         
269         if ( old_Num_objects != num_objects )   {
270                 gr_uprintf( 0, 32, "Objs: %3d/%3d", num_objects, MAX_OBJECTS );
271                 old_Num_objects = num_objects;
272         }
273
274         //--------------- Current_segment_number -------------
275         //--------------- Current_side_number -------------
276
277         if (( old_Cursegp_num != Cursegp-Segments ) || ( old_Curside != Curside ))      {
278                 gr_uprintf( 0, 48, "Cursegp/side: %3d/%1d", Cursegp-Segments, Curside);
279                 gr_uprintf( 0, 128, " tmap1,2,o: %3d/%3dx%1d", Cursegp->sides[Curside].tmap_num, Cursegp->sides[Curside].tmap_num2 & 0x3FFF, (Cursegp->sides[Curside].tmap_num2 >> 14) & 3);
280                 old_Cursegp_num = Cursegp-Segments;
281                 old_Curside = Curside;
282         }
283
284         //--------------- Current_vertex_numbers -------------
285
286         if ( old_Cursegp_num_for_verts != Cursegp-Segments )    {
287
288                 gr_uprintf( 0, 64, "{%3d,%3d,%3d,%3d,", Cursegp->verts[0],Cursegp->verts[1],
289                                                                                                                                                                                          Cursegp->verts[2],Cursegp->verts[3] );
290                 gr_uprintf( 0, 80," %3d,%3d,%3d,%3d}", Cursegp->verts[4],Cursegp->verts[5],
291                                                                                                                                                                                          Cursegp->verts[6],Cursegp->verts[7] );
292                 old_Cursegp_num_for_verts = Cursegp-Segments;
293         }
294
295         //--------------- Num walls/links/triggers -------------------------
296
297         if ( old_Num_walls != Num_walls ) {
298 //              gr_uprintf( 0, 96, "Walls/Links %d/%d", Num_walls, Num_links );
299                 gr_uprintf( 0, 96, "Walls %3d", Num_walls );
300                 old_Num_walls = Num_walls;
301         }
302
303         //--------------- Num triggers ----------------------
304
305         if ( old_Num_triggers != Num_triggers ) {
306                 gr_uprintf( 0, 112, "Num_triggers %2d", Num_triggers );
307                 old_Num_triggers = Num_triggers;
308         }
309
310         //--------------- Current texture number -------------
311
312         if ( old_CurrentTexture != CurrentTexture )     {
313                 gr_uprintf( 0, 144, "Tex/Light: %3d %5.2f", CurrentTexture, f2fl(TmapInfo[CurrentTexture].lighting));
314                 old_CurrentTexture = CurrentTexture;
315         }
316
317 }
318
319 //      ------------------------------------------------------------------------------------
320 void clear_pad_display(void)
321 {
322         gr_clear_canvas(CWHITE);
323    gr_set_fontcolor( CBLACK, CWHITE );
324 }
325
326 //      ------------------------------------------------------------------------------------
327 void info_display_all( UI_WINDOW * wnd )
328 {
329         static int old_padnum = -1;
330         int        padnum,show_all = 0;
331         grs_canvas *save_canvas = grd_curcanv;
332
333         wnd++;          //kill warning
334
335         grd_curcanv = Pad_text_canvas;
336
337         padnum = ui_pad_get_current();
338         Assert(padnum <= MAX_PAD_ID);
339
340         if (padnum != old_padnum) {
341                 clear_pad_display();
342                 old_padnum = padnum;
343                 show_all = 1;
344         }
345
346         switch (padnum) {
347                 case OBJECT_PAD_ID:                     // Object placement
348                         info_display_object_placement(show_all);
349                         break;
350                 case SEGSIZE_PAD_ID:                    // Segment sizing
351                         info_display_segsize(show_all);
352                         break;
353                 default:
354                         info_display_default(show_all);
355                         break;
356         }
357         grd_curcanv = save_canvas;
358 }
359