File: objpage.c

package info (click to toggle)
d1x-rebirth 0.58.1-1.2
  • links: PTS, VCS
  • area: non-free
  • in suites: bullseye, sid
  • size: 5,876 kB
  • sloc: ansic: 95,642; asm: 1,228; ada: 364; objc: 243; python: 121; cpp: 118; makefile: 23
file content (435 lines) | stat: -rw-r--r-- 11,039 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
/*
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
*/

/*
 *
 * object selection stuff.
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include "inferno.h"
#include "screens.h"			// For GAME_SCREEN?????
#include "editor.h"			// For TMAP_CURBOX??????
#include "gr.h"				// For canves, font stuff
#include "ui.h"				// For UI_GADGET stuff
#include "object.h"			// For robot_bms
#include "dxxerror.h"
#include "objpage.h"
#include "bm.h"
#include "player.h"
#include "piggy.h"
#include "cntrlcen.h"

#define OBJS_PER_PAGE 8

static UI_GADGET_USERBOX * ObjBox[OBJS_PER_PAGE];
static UI_GADGET_USERBOX * ObjCurrent;

static int ObjectPage = 0;

#include "vecmat.h"
#include "3d.h"
#include "polyobj.h"
#include "texmap.h"

#include "hostage.h"
#include "powerup.h"

vms_angvec objpage_view_orient;
fix objpage_view_dist;

//this is bad to have the extern, but this snapshot stuff is special
extern int polyobj_lighting;


//canvas set
void draw_object_picture(int id, vms_angvec *orient_angles, int type)
{

	if (id >= Num_object_subtypes)
		return;

	switch (type) {

		case OBJ_HOSTAGE:
			PIGGY_PAGE_IN(Vclip[Hostage_vclip_num[id]].frames[0]);
			gr_bitmap(0,0,&GameBitmaps[Vclip[Hostage_vclip_num[id]].frames[0].index]);
			break;

		case OBJ_POWERUP:
			if ( Powerup_info[id].vclip_num > -1 )	{
				PIGGY_PAGE_IN(Vclip[Powerup_info[id].vclip_num].frames[0]);
				gr_bitmap(0,0,&GameBitmaps[Vclip[Powerup_info[id].vclip_num].frames[0].index]);
			}
			break;

		case OBJ_PLAYER:
			draw_model_picture(Player_ship->model_num,orient_angles);		// Draw a poly model below
			break;

		case OBJ_ROBOT:
			draw_model_picture(Robot_info[id].model_num,orient_angles);	// Draw a poly model below
			break;

		case OBJ_CNTRLCEN:
			draw_model_picture(get_reactor_model_number(id), orient_angles);
			break;
		case OBJ_CLUTTER:
			draw_model_picture(id, orient_angles);
			break;
		default:
			//Int3();	// Invalid type!!!
			return;
	}

}

void redraw_current_object()
{
	grs_canvas * cc;

	cc = grd_curcanv;
	gr_set_current_canvas(ObjCurrent->canvas);
	draw_object_picture(Cur_object_id, &objpage_view_orient, Cur_object_type);
	gr_set_current_canvas(cc);
}

void gr_label_box( int i)
{

	gr_clear_canvas(BM_XRGB(0,0,0));
	draw_object_picture(i, &objpage_view_orient, Cur_object_type);

//	char s[20];
//	sprintf( s, " %d ", i );
//	gr_clear_canvas( BM_XRGB(0,15,0) );
//	gr_set_fontcolor( CWHITE, BM_XRGB(0,15,0) );
//	ui_string_centered(  grd_curcanv->cv_bitmap.bm_w/2, grd_curcanv->cv_bitmap.bm_h/2, Description[i] );
}

int objpage_goto_first()
{
	int i;

	ObjectPage=0;
	for (i=0;  i<OBJS_PER_PAGE; i++ ) {
		gr_set_current_canvas(ObjBox[i]->canvas);
		if (i+ObjectPage*OBJS_PER_PAGE < Num_object_subtypes ) {
			//gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
			gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
		} else
			gr_clear_canvas( CGREY );
	}

	return 1;
}

int objpage_goto_last()
{
	int i;

	ObjectPage=(Num_object_subtypes)/OBJS_PER_PAGE;
	for (i=0;  i<OBJS_PER_PAGE; i++ )
	{
		gr_set_current_canvas(ObjBox[i]->canvas);
		if (i+ObjectPage*OBJS_PER_PAGE < Num_object_subtypes )
		{
			//gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
			gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
		} else {
			gr_clear_canvas( CGREY );
		}
	}
	return 1;
}

static int objpage_goto_prev()
{
	int i;
	if (ObjectPage > 0) {
		ObjectPage--;
		for (i=0;  i<OBJS_PER_PAGE; i++ )
		{
			gr_set_current_canvas(ObjBox[i]->canvas);
			if (i+ObjectPage*OBJS_PER_PAGE < Num_object_subtypes)
			{
				//gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
				gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
			} else {
				gr_clear_canvas( CGREY );
			}
		}
	}
	return 1;
}

static int objpage_goto_next()
{
	int i;
	if ((ObjectPage+1)*OBJS_PER_PAGE < Num_object_subtypes) {
		ObjectPage++;
		for (i=0;  i<OBJS_PER_PAGE; i++ )
		{
			gr_set_current_canvas(ObjBox[i]->canvas);
			if (i+ObjectPage*OBJS_PER_PAGE < Num_object_subtypes)
			{
				//gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
				gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
			} else {
				gr_clear_canvas( CGREY );
			}
		}
	}
	return 1;
}

int objpage_grab_current(int n)
{
	int i;

	if ((n < 0) || (n >= Num_object_subtypes)) return 0;
	
	ObjectPage = n / OBJS_PER_PAGE;
	
	if (ObjectPage*OBJS_PER_PAGE < Num_object_subtypes) {
		for (i=0;  i<OBJS_PER_PAGE; i++ )
		{
			gr_set_current_canvas(ObjBox[i]->canvas);
			if (i + ObjectPage*OBJS_PER_PAGE < Num_object_subtypes)
			{
				//gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
				gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
			} else {
				gr_clear_canvas( CGREY );
			}
		}
	}

	Cur_object_id = n;
	gr_set_current_canvas(ObjCurrent->canvas);
	//gr_ubitmap(0,0, robot_bms[robot_bm_nums[ Cur_robot_type ] ] );
	gr_label_box(Cur_object_id);

	//objpage_display_name( Texture[Cur_robot_type]->filename );
	
	return 1;
}

int objpage_goto_next_object()
{
	// there should be a pop-up menu for this
	switch (Cur_object_type)
	{
		case OBJ_ROBOT:
			Cur_object_type = OBJ_HOSTAGE;
			Num_object_subtypes = 1;
			break;

		case OBJ_HOSTAGE:
			Cur_object_type = OBJ_PLAYER;
			Num_object_subtypes = 1;	// can have anarchy/coop, but this is handled automatically
			break;

		case OBJ_PLAYER:
			Cur_object_type = OBJ_POWERUP;
			Num_object_subtypes = N_powerup_types;
			break;

		case OBJ_POWERUP:
			Cur_object_type = OBJ_CNTRLCEN;
			Num_object_subtypes = get_num_reactor_models();
			break;

		case OBJ_CNTRLCEN:
		default:
			Cur_object_type = OBJ_ROBOT;
			Num_object_subtypes = N_robot_types;
			break;
	}

	objpage_grab_current(0);

	return 1;

}

#define OBJBOX_X	(TMAPBOX_X)	//location of first one
#define OBJBOX_Y	(OBJCURBOX_Y - 24 )
#define OBJBOX_W	64
#define OBJBOX_H	64

#define DELTA_ANG 0x800

int objpage_increase_pitch()
{
	objpage_view_orient.p += DELTA_ANG;
	redraw_current_object();
	return 1;
}

int objpage_decrease_pitch()
{
	objpage_view_orient.p -= DELTA_ANG;
	redraw_current_object();
	return 1;
}

int objpage_increase_heading()
{
	objpage_view_orient.h += DELTA_ANG;
	redraw_current_object();
	return 1;
}

int objpage_decrease_heading()
{
	objpage_view_orient.h -= DELTA_ANG;
	redraw_current_object();
	return 1;
}

int objpage_increase_bank()
{
	objpage_view_orient.b += DELTA_ANG;
	redraw_current_object();
	return 1;
}

int objpage_decrease_bank()
{
	objpage_view_orient.b -= DELTA_ANG;
	redraw_current_object();
	return 1;
}

int objpage_increase_z()
{
	objpage_view_dist -= 0x8000;
	redraw_current_object();
	return 1;
}

int objpage_decrease_z()
{
	objpage_view_dist += 0x8000;
	redraw_current_object();
	return 1;
}

int objpage_reset_orient()
{
	objpage_view_orient.p = 0;
	objpage_view_orient.b = 0;
	objpage_view_orient.h = -0x8000;
	//objpage_view_dist = DEFAULT_VIEW_DIST;
	redraw_current_object();
	return 1;
}


// INIT TEXTURE STUFF

void objpage_init( UI_DIALOG *dlg )
{
	int i;

	//Num_total_object_types = N_polygon_models + N_hostage_types + N_powerup_types;
	//Assert (N_polygon_models < MAX_POLYGON_MODELS);
	//Assert (Num_total_object_types < MAX_OBJTYPE );
	//Assert (N_hostage_types < MAX_HOSTAGE_TYPES ); 
	//Assert (N_powerup_types < MAX_POWERUP_TYPES );
	// Assert (N_robot_types < MAX_ROBOTS);

	ui_add_gadget_button( dlg, OBJCURBOX_X + 00, OBJCURBOX_Y - 27, 30, 20, "<<", objpage_goto_prev );
	ui_add_gadget_button( dlg, OBJCURBOX_X + 32, OBJCURBOX_Y - 27, 30, 20, ">>", objpage_goto_next );

	ui_add_gadget_button( dlg, OBJCURBOX_X + 00, OBJCURBOX_Y - 54, 30, 20, "B", objpage_goto_first );
	ui_add_gadget_button( dlg, OBJCURBOX_X + 32, OBJCURBOX_Y - 54, 30, 20, "E", objpage_goto_last );

	ui_add_gadget_button( dlg, OBJCURBOX_X + 25, OBJCURBOX_Y + 62, 22, 13, "P-", objpage_decrease_pitch );
	ui_add_gadget_button( dlg, OBJCURBOX_X + 25, OBJCURBOX_Y + 90, 22, 13, "P+", objpage_increase_pitch );
	ui_add_gadget_button( dlg, OBJCURBOX_X + 00, OBJCURBOX_Y + 90, 22, 13, "B-", objpage_decrease_bank );
	ui_add_gadget_button( dlg, OBJCURBOX_X + 50, OBJCURBOX_Y + 90, 22, 13, "B+", objpage_increase_bank );
	ui_add_gadget_button( dlg, OBJCURBOX_X + 00, OBJCURBOX_Y + 76, 22, 13, "H-", objpage_decrease_heading );
	ui_add_gadget_button( dlg, OBJCURBOX_X + 50, OBJCURBOX_Y + 76, 22, 13, "H+", objpage_increase_heading );
	ui_add_gadget_button( dlg, OBJCURBOX_X + 00, OBJCURBOX_Y + 62, 22, 13, "Z+", objpage_increase_z );
	ui_add_gadget_button( dlg, OBJCURBOX_X + 50, OBJCURBOX_Y + 62, 22, 13, "Z-", objpage_decrease_z );
	ui_add_gadget_button( dlg, OBJCURBOX_X + 25, OBJCURBOX_Y + 76, 22, 13, "R", objpage_reset_orient );

	for (i=0;i<OBJS_PER_PAGE;i++)
		ObjBox[i] = ui_add_gadget_userbox( dlg, OBJBOX_X + (i/2)*(2+OBJBOX_W), OBJBOX_Y + (i%2)*(2+OBJBOX_H), OBJBOX_W, OBJBOX_H);

	ObjCurrent = ui_add_gadget_userbox( dlg, OBJCURBOX_X, OBJCURBOX_Y-5, 64, 64 );

	objpage_reset_orient();

}

void objpage_close()
{
	//gr_free_sub_canvas(ObjnameCanvas);
}


// DO TEXTURE STUFF

int objpage_do(d_event *event)
{
	int i;
	
	if (event->type == EVENT_UI_DIALOG_DRAW)
	{
		for (i=0;  i<OBJS_PER_PAGE; i++ )
		{
			gr_set_current_canvas(ObjBox[i]->canvas);
			if (i+ObjectPage*OBJS_PER_PAGE < Num_object_subtypes)
			{
				//gr_ubitmap(0,0, robot_bms[robot_bm_nums[ i+ObjectPage*OBJS_PER_PAGE ] ] );
				gr_label_box(i+ObjectPage*OBJS_PER_PAGE );
			} else {
				gr_clear_canvas( CGREY );
			}
		}
		
		// Don't reset robot_type when we return to editor.
		//	Cur_robot_type = ObjectPage*OBJS_PER_PAGE;
		gr_set_current_canvas(ObjCurrent->canvas);
		//gr_ubitmap(0,0, robot_bms[robot_bm_nums[ Cur_robot_type ] ] );
		gr_label_box(Cur_object_id);
		
		//ObjnameCanvas = gr_create_sub_canvas(&grd_curscreen->sc_canvas, OBJCURBOX_X , OBJCURBOX_Y + OBJBOX_H + 10, 100, 20);
		//gr_set_current_canvas( ObjnameCanvas );
		//gr_set_curfont( ui_small_font ); 
		//gr_set_fontcolor( CBLACK, CWHITE );
		//objpage_display_name( Texture[Cur_robot_type]->filename );
		
		return 1;
	}

	for (i=0; i<OBJS_PER_PAGE; i++ )
	{
		if (GADGET_PRESSED(ObjBox[i]) && (i+ObjectPage*OBJS_PER_PAGE < Num_object_subtypes))
		{
			Cur_object_id = i+ObjectPage*OBJS_PER_PAGE;
			gr_set_current_canvas(ObjCurrent->canvas);
			//gr_ubitmap(0,0, robot_bms[robot_bm_nums[ Cur_robot_type ] ] );
			gr_label_box(Cur_object_id);
			//objpage_display_name( Texture[Cur_robot_type]->filename );
			return 1;
		}
	}
	
	return 0;
}