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-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
29 int N_robot_types = 0;
30 int N_robot_joints = 0;
33 robot_info Robot_info[MAX_ROBOT_TYPES];
35 //Big array of joint positions. All robots index into this array
37 #define deg(a) ((int) (a) * 32768 / 180)
39 //test data for one robot
40 jointpos Robot_joints[MAX_ROBOT_JOINTS] = {
43 {2,{deg(-30),0,0}}, //rest (2 joints)
46 {2,{deg(0),0,0}}, //alert
49 {2,{deg(0),0,0}}, //fire
52 {2,{deg(50),0,0}}, //recoil
55 {2,{deg(10),0,deg(70)}}, //flinch
56 {3,{deg(0),deg(20),0}},
59 {4,{deg(-30),0,0}}, //rest (2 joints)
62 {4,{deg(0),0,0}}, //alert
65 {4,{deg(0),0,0}}, //fire
68 {4,{deg(50),0,0}}, //recoil
71 {4,{deg(20),0,deg(-50)}}, //flinch
72 {5,{deg(0),0,deg(20)}},
74 //rest of body (the head)
76 {1,{deg(70),0,0}}, //rest (1 joint, head)
78 {1,{deg(0),0,0}}, //alert
80 {1,{deg(0),0,0}}, //fire
82 {1,{deg(0),0,0}}, //recoil
84 {1,{deg(-20),deg(15),0}}, //flinch
89 //given an object and a gun number, return position in 3-space of gun
91 void calc_gun_point(vms_vector *gun_point,object *obj,int gun_num)
97 int mn; //submodel number
99 Assert(obj->render_type==RT_POLYOBJ || obj->render_type==RT_MORPH);
100 Assert(obj->id < N_robot_types);
102 r = &Robot_info[obj->id];
103 pm =&Polygon_models[r->model_num];
105 if (gun_num >= r->n_guns)
107 mprintf((1, "Bashing gun num %d to 0.\n", gun_num));
112 // Assert(gun_num < r->n_guns);
114 pnt = r->gun_points[gun_num];
115 mn = r->gun_submodels[gun_num];
117 //instance up the tree for this gun
121 vm_angles_2_matrix(&m,&obj->rtype.pobj_info.anim_angles[mn]);
122 vm_transpose_matrix(&m);
123 vm_vec_rotate(&tpnt,&pnt,&m);
125 vm_vec_add(&pnt,&tpnt,&pm->submodel_offsets[mn]);
127 mn = pm->submodel_parents[mn];
130 //now instance for the entire object
132 vm_copy_transpose_matrix(&m,&obj->orient);
133 vm_vec_rotate(gun_point,&pnt,&m);
134 vm_vec_add2(gun_point,&obj->pos);
138 //fills in ptr to list of joints, and returns the number of joints in list
139 //takes the robot type (object id), gun number, and desired state
140 int robot_get_anim_state(jointpos **jp_list_ptr,int robot_type,int gun_num,int state)
143 Assert(gun_num <= Robot_info[robot_type].n_guns);
145 *jp_list_ptr = &Robot_joints[Robot_info[robot_type].anim_states[gun_num][state].offset];
147 return Robot_info[robot_type].anim_states[gun_num][state].n_joints;
152 //for test, set a robot to a specific state
153 void set_robot_state(object *obj,int state)
159 Assert(obj->type == OBJ_ROBOT);
161 ri = &Robot_info[obj->id];
163 for (g=0;g<ri->n_guns+1;g++) {
165 jl = &ri->anim_states[g][state];
169 for (j=0;j<jl->n_joints;j++,jo++) {
172 jn = Robot_joints[jo].jointnum;
174 obj->rtype.pobj_info.anim_angles[jn] = Robot_joints[jo].angles;
182 //--unused-- int cur_state=0;
184 //--unused-- test_anim_states()
186 //--unused-- set_robot_state(&Objects[1],cur_state);
188 //--unused-- mprintf(0,"Robot in state %d\n",cur_state);
190 //--unused-- cur_state = (cur_state+1)%N_ANIM_STATES;
194 //set the animation angles for this robot. Gun fields of robot info must
196 void robot_set_angles(robot_info *r,polymodel *pm,vms_angvec angs[N_ANIM_STATES][MAX_SUBMODELS])
199 int gun_nums[MAX_SUBMODELS]; //which gun each submodel is part of
201 for (m=0;m<pm->n_models;m++)
202 gun_nums[m] = r->n_guns; //assume part of body...
204 gun_nums[0] = -1; //body never animates, at least for now
206 for (g=0;g<r->n_guns;g++) {
207 m = r->gun_submodels[g];
210 gun_nums[m] = g; //...unless we find it in a gun
211 m = pm->submodel_parents[m];
215 for (g=0;g<r->n_guns+1;g++) {
217 //mprintf(0,"Gun %d:\n",g);
219 for (state=0;state<N_ANIM_STATES;state++) {
221 //mprintf(0," State %d:\n",state);
223 r->anim_states[g][state].n_joints = 0;
224 r->anim_states[g][state].offset = N_robot_joints;
226 for (m=0;m<pm->n_models;m++) {
227 if (gun_nums[m] == g) {
228 //mprintf(0," Joint %d: %x %x %x\n",m,angs[state][m].pitch,angs[state][m].bank,angs[state][m].head);
229 Robot_joints[N_robot_joints].jointnum = m;
230 Robot_joints[N_robot_joints].angles = angs[state][m];
231 r->anim_states[g][state].n_joints++;
233 Assert(N_robot_joints < MAX_ROBOT_JOINTS);
242 * reads a jointlist structure from a CFILE
244 static void jointlist_read(jointlist *jl, CFILE *fp)
246 jl->n_joints = cfile_read_short(fp);
247 jl->offset = cfile_read_short(fp);
251 * reads a robot_info structure from a CFILE
253 void robot_info_read(robot_info *ri, CFILE *fp)
257 ri->model_num = cfile_read_int(fp);
258 for (i = 0; i < MAX_GUNS; i++)
259 cfile_read_vector(&(ri->gun_points[i]), fp);
260 cfread(ri->gun_submodels, MAX_GUNS, 1, fp);
262 ri->exp1_vclip_num = cfile_read_short(fp);
263 ri->exp1_sound_num = cfile_read_short(fp);
265 ri->exp2_vclip_num = cfile_read_short(fp);
266 ri->exp2_sound_num = cfile_read_short(fp);
268 ri->weapon_type = cfile_read_byte(fp);
269 ri->weapon_type2 = cfile_read_byte(fp);
270 ri->n_guns = cfile_read_byte(fp);
271 ri->contains_id = cfile_read_byte(fp);
273 ri->contains_count = cfile_read_byte(fp);
274 ri->contains_prob = cfile_read_byte(fp);
275 ri->contains_type = cfile_read_byte(fp);
276 ri->kamikaze = cfile_read_byte(fp);
278 ri->score_value = cfile_read_short(fp);
279 ri->badass = cfile_read_byte(fp);
280 ri->energy_drain = cfile_read_byte(fp);
282 ri->lighting = cfile_read_fix(fp);
283 ri->strength = cfile_read_fix(fp);
285 ri->mass = cfile_read_fix(fp);
286 ri->drag = cfile_read_fix(fp);
288 for (i = 0; i < NDL; i++)
289 ri->field_of_view[i] = cfile_read_fix(fp);
290 for (i = 0; i < NDL; i++)
291 ri->firing_wait[i] = cfile_read_fix(fp);
292 for (i = 0; i < NDL; i++)
293 ri->firing_wait2[i] = cfile_read_fix(fp);
294 for (i = 0; i < NDL; i++)
295 ri->turn_time[i] = cfile_read_fix(fp);
296 for (i = 0; i < NDL; i++)
297 ri->max_speed[i] = cfile_read_fix(fp);
298 for (i = 0; i < NDL; i++)
299 ri->circle_distance[i] = cfile_read_fix(fp);
300 cfread(ri->rapidfire_count, NDL, 1, fp);
302 cfread(ri->evade_speed, NDL, 1, fp);
304 ri->cloak_type = cfile_read_byte(fp);
305 ri->attack_type = cfile_read_byte(fp);
307 ri->see_sound = cfile_read_byte(fp);
308 ri->attack_sound = cfile_read_byte(fp);
309 ri->claw_sound = cfile_read_byte(fp);
310 ri->taunt_sound = cfile_read_byte(fp);
312 ri->boss_flag = cfile_read_byte(fp);
313 ri->companion = cfile_read_byte(fp);
314 ri->smart_blobs = cfile_read_byte(fp);
315 ri->energy_blobs = cfile_read_byte(fp);
317 ri->thief = cfile_read_byte(fp);
318 ri->pursuit = cfile_read_byte(fp);
319 ri->lightcast = cfile_read_byte(fp);
320 ri->death_roll = cfile_read_byte(fp);
322 ri->flags = cfile_read_byte(fp);
323 cfread(ri->pad, 3, 1, fp);
325 ri->deathroll_sound = cfile_read_byte(fp);
326 ri->glow = cfile_read_byte(fp);
327 ri->behavior = cfile_read_byte(fp);
328 ri->aim = cfile_read_byte(fp);
330 for (i = 0; i < MAX_GUNS + 1; i++)
331 for (j = 0; j < N_ANIM_STATES; j++)
332 jointlist_read(&ri->anim_states[i][j], fp);
334 ri->always_0xabcd = cfile_read_int(fp);
338 * reads a jointpos structure from a CFILE
340 void jointpos_read(jointpos *jp, CFILE *fp)
342 jp->jointnum = cfile_read_short(fp);
343 cfile_read_angvec(&jp->angles, fp);