1 /* $Id: robot.c,v 1.5 2003-10-10 09:36:35 btb Exp $ */
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-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Code for handling robots
20 * Revision 1.1 1995/05/16 15:30:34 allender
23 * Revision 2.1 1995/03/07 16:52:02 john
24 * Fixed robots not moving without edtiro bug.
26 * Revision 2.0 1995/02/27 11:31:11 john
27 * New version 2.0, which has no anonymous unions, builds with
28 * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
30 * Revision 1.19 1995/02/22 13:58:09 allender
31 * remove anonymous unions from object structure
33 * Revision 1.18 1995/01/27 11:17:06 rob
34 * Avoid problems with illegal gun num.
36 * Revision 1.17 1994/11/19 15:15:02 mike
37 * remove unused code and data
39 * Revision 1.16 1994/11/05 16:41:31 adam
40 * upped MAX_ROBOT_JOINTS
42 * Revision 1.15 1994/09/26 15:29:29 matt
43 * Allow morphing objects to fire
45 * Revision 1.14 1994/06/20 14:31:02 matt
46 * Don't include joint zero in animation data
48 * Revision 1.13 1994/06/10 14:39:58 matt
49 * Increased limit of robot joints
51 * Revision 1.12 1994/06/10 10:59:18 matt
52 * Do error checking on list of angles
54 * Revision 1.11 1994/06/09 16:21:32 matt
55 * Took out special-case and test code.
57 * Revision 1.10 1994/06/07 13:21:14 matt
58 * Added support for new chunk-based POF files, with robot animation data.
60 * Revision 1.9 1994/06/01 17:58:24 mike
61 * Greater flinch effect.
63 * Revision 1.8 1994/06/01 14:59:25 matt
64 * Fixed calc_gun_position(), which was rotating the wrong way for the
67 * Revision 1.7 1994/06/01 12:44:04 matt
68 * Added flinch state for test robot
70 * Revision 1.6 1994/05/31 19:17:24 matt
71 * Fixed test robot angles
73 * Revision 1.5 1994/05/30 19:43:50 mike
74 * Call set_test_robot.
77 * Revision 1.4 1994/05/30 00:02:44 matt
78 * Got rid of robot render type, and generally cleaned up polygon model
81 * Revision 1.3 1994/05/29 18:46:15 matt
82 * Added stuff for getting robot animation info for different states
84 * Revision 1.2 1994/05/26 21:09:15 matt
85 * Moved robot stuff out of polygon model and into robot_info struct
86 * Made new file, robot.c, to deal with robots
88 * Revision 1.1 1994/05/26 18:02:04 matt
110 int N_robot_types = 0;
111 int N_robot_joints = 0;
114 robot_info Robot_info[MAX_ROBOT_TYPES];
116 //Big array of joint positions. All robots index into this array
118 #define deg(a) ((int) (a) * 32768 / 180)
120 //test data for one robot
121 jointpos Robot_joints[MAX_ROBOT_JOINTS] = {
124 {2,{deg(-30),0,0}}, //rest (2 joints)
127 {2,{deg(0),0,0}}, //alert
130 {2,{deg(0),0,0}}, //fire
133 {2,{deg(50),0,0}}, //recoil
136 {2,{deg(10),0,deg(70)}}, //flinch
137 {3,{deg(0),deg(20),0}},
140 {4,{deg(-30),0,0}}, //rest (2 joints)
143 {4,{deg(0),0,0}}, //alert
146 {4,{deg(0),0,0}}, //fire
149 {4,{deg(50),0,0}}, //recoil
152 {4,{deg(20),0,deg(-50)}}, //flinch
153 {5,{deg(0),0,deg(20)}},
155 //rest of body (the head)
157 {1,{deg(70),0,0}}, //rest (1 joint, head)
159 {1,{deg(0),0,0}}, //alert
161 {1,{deg(0),0,0}}, //fire
163 {1,{deg(0),0,0}}, //recoil
165 {1,{deg(-20),deg(15),0}}, //flinch
169 //given an object and a gun number, return position in 3-space of gun
171 void calc_gun_point(vms_vector *gun_point,object *obj,int gun_num)
177 int mn; //submodel number
179 Assert(obj->render_type==RT_POLYOBJ || obj->render_type==RT_MORPH);
180 Assert(obj->id < N_robot_types);
182 r = &Robot_info[obj->id];
183 pm =&Polygon_models[r->model_num];
185 if (gun_num >= r->n_guns)
187 mprintf((1, "Bashing gun num %d to 0.\n", gun_num));
192 // Assert(gun_num < r->n_guns);
194 pnt = r->gun_points[gun_num];
195 mn = r->gun_submodels[gun_num];
197 //instance up the tree for this gun
201 vm_angles_2_matrix(&m,&obj->rtype.pobj_info.anim_angles[mn]);
202 vm_transpose_matrix(&m);
203 vm_vec_rotate(&tpnt,&pnt,&m);
205 vm_vec_add(&pnt,&tpnt,&pm->submodel_offsets[mn]);
207 mn = pm->submodel_parents[mn];
210 //now instance for the entire object
212 vm_copy_transpose_matrix(&m,&obj->orient);
213 vm_vec_rotate(gun_point,&pnt,&m);
214 vm_vec_add2(gun_point,&obj->pos);
218 //fills in ptr to list of joints, and returns the number of joints in list
219 //takes the robot type (object id), gun number, and desired state
220 int robot_get_anim_state(jointpos **jp_list_ptr,int robot_type,int gun_num,int state)
223 Assert(gun_num <= Robot_info[robot_type].n_guns);
225 *jp_list_ptr = &Robot_joints[Robot_info[robot_type].anim_states[gun_num][state].offset];
227 return Robot_info[robot_type].anim_states[gun_num][state].n_joints;
232 //for test, set a robot to a specific state
233 void set_robot_state(object *obj,int state)
239 Assert(obj->type == OBJ_ROBOT);
241 ri = &Robot_info[obj->id];
243 for (g=0;g<ri->n_guns+1;g++) {
245 jl = &ri->anim_states[g][state];
249 for (j=0;j<jl->n_joints;j++,jo++) {
252 jn = Robot_joints[jo].jointnum;
254 obj->rtype.pobj_info.anim_angles[jn] = Robot_joints[jo].angles;
262 //--unused-- int cur_state=0;
264 //--unused-- test_anim_states()
266 //--unused-- set_robot_state(&Objects[1],cur_state);
268 //--unused-- mprintf(0,"Robot in state %d\n",cur_state);
270 //--unused-- cur_state = (cur_state+1)%N_ANIM_STATES;
274 //set the animation angles for this robot. Gun fields of robot info must
276 void robot_set_angles(robot_info *r,polymodel *pm,vms_angvec angs[N_ANIM_STATES][MAX_SUBMODELS])
279 int gun_nums[MAX_SUBMODELS]; //which gun each submodel is part of
281 for (m=0;m<pm->n_models;m++)
282 gun_nums[m] = r->n_guns; //assume part of body...
284 gun_nums[0] = -1; //body never animates, at least for now
286 for (g=0;g<r->n_guns;g++) {
287 m = r->gun_submodels[g];
290 gun_nums[m] = g; //...unless we find it in a gun
291 m = pm->submodel_parents[m];
295 for (g=0;g<r->n_guns+1;g++) {
297 //mprintf(0,"Gun %d:\n",g);
299 for (state=0;state<N_ANIM_STATES;state++) {
301 //mprintf(0," State %d:\n",state);
303 r->anim_states[g][state].n_joints = 0;
304 r->anim_states[g][state].offset = N_robot_joints;
306 for (m=0;m<pm->n_models;m++) {
307 if (gun_nums[m] == g) {
308 //mprintf(0," Joint %d: %x %x %x\n",m,angs[state][m].pitch,angs[state][m].bank,angs[state][m].head);
309 Robot_joints[N_robot_joints].jointnum = m;
310 Robot_joints[N_robot_joints].angles = angs[state][m];
311 r->anim_states[g][state].n_joints++;
313 Assert(N_robot_joints < MAX_ROBOT_JOINTS);
323 * reads n jointlist structs from a CFILE
325 static int jointlist_read_n(jointlist *jl, int n, CFILE *fp)
329 for (i = 0; i < n; i++) {
330 jl[i].n_joints = cfile_read_short(fp);
331 jl[i].offset = cfile_read_short(fp);
337 * reads n robot_info structs from a CFILE
339 int robot_info_read_n(robot_info *ri, int n, CFILE *fp)
343 for (i = 0; i < n; i++) {
344 ri[i].model_num = cfile_read_int(fp);
345 for (j = 0; j < MAX_GUNS; j++)
346 cfile_read_vector(&(ri[i].gun_points[j]), fp);
347 cfread(ri[i].gun_submodels, MAX_GUNS, 1, fp);
349 ri[i].exp1_vclip_num = cfile_read_short(fp);
350 ri[i].exp1_sound_num = cfile_read_short(fp);
352 ri[i].exp2_vclip_num = cfile_read_short(fp);
353 ri[i].exp2_sound_num = cfile_read_short(fp);
355 ri[i].weapon_type = cfile_read_byte(fp);
356 ri[i].weapon_type2 = cfile_read_byte(fp);
357 ri[i].n_guns = cfile_read_byte(fp);
358 ri[i].contains_id = cfile_read_byte(fp);
360 ri[i].contains_count = cfile_read_byte(fp);
361 ri[i].contains_prob = cfile_read_byte(fp);
362 ri[i].contains_type = cfile_read_byte(fp);
363 ri[i].kamikaze = cfile_read_byte(fp);
365 ri[i].score_value = cfile_read_short(fp);
366 ri[i].badass = cfile_read_byte(fp);
367 ri[i].energy_drain = cfile_read_byte(fp);
369 ri[i].lighting = cfile_read_fix(fp);
370 ri[i].strength = cfile_read_fix(fp);
372 ri[i].mass = cfile_read_fix(fp);
373 ri[i].drag = cfile_read_fix(fp);
375 for (j = 0; j < NDL; j++)
376 ri[i].field_of_view[j] = cfile_read_fix(fp);
377 for (j = 0; j < NDL; j++)
378 ri[i].firing_wait[j] = cfile_read_fix(fp);
379 for (j = 0; j < NDL; j++)
380 ri[i].firing_wait2[j] = cfile_read_fix(fp);
381 for (j = 0; j < NDL; j++)
382 ri[i].turn_time[j] = cfile_read_fix(fp);
383 for (j = 0; j < NDL; j++)
384 ri[i].max_speed[j] = cfile_read_fix(fp);
385 for (j = 0; j < NDL; j++)
386 ri[i].circle_distance[i] = cfile_read_fix(fp);
387 cfread(ri[i].rapidfire_count, NDL, 1, fp);
389 cfread(ri[i].evade_speed, NDL, 1, fp);
391 ri[i].cloak_type = cfile_read_byte(fp);
392 ri[i].attack_type = cfile_read_byte(fp);
394 ri[i].see_sound = cfile_read_byte(fp);
395 ri[i].attack_sound = cfile_read_byte(fp);
396 ri[i].claw_sound = cfile_read_byte(fp);
397 ri[i].taunt_sound = cfile_read_byte(fp);
399 ri[i].boss_flag = cfile_read_byte(fp);
400 ri[i].companion = cfile_read_byte(fp);
401 ri[i].smart_blobs = cfile_read_byte(fp);
402 ri[i].energy_blobs = cfile_read_byte(fp);
404 ri[i].thief = cfile_read_byte(fp);
405 ri[i].pursuit = cfile_read_byte(fp);
406 ri[i].lightcast = cfile_read_byte(fp);
407 ri[i].death_roll = cfile_read_byte(fp);
409 ri[i].flags = cfile_read_byte(fp);
410 cfread(ri[i].pad, 3, 1, fp);
412 ri[i].deathroll_sound = cfile_read_byte(fp);
413 ri[i].glow = cfile_read_byte(fp);
414 ri[i].behavior = cfile_read_byte(fp);
415 ri[i].aim = cfile_read_byte(fp);
417 for (j = 0; j < MAX_GUNS + 1; j++)
418 jointlist_read_n(ri[i].anim_states[j], N_ANIM_STATES, fp);
420 ri[i].always_0xabcd = cfile_read_int(fp);
426 * reads n jointpos structs from a CFILE
428 int jointpos_read_n(jointpos *jp, int n, CFILE *fp)
432 for (i = 0; i < n; i++) {
433 jp[i].jointnum = cfile_read_short(fp);
434 cfile_read_angvec(&jp[i].angles, fp);