]> icculus.org git repositories - btb/d2x.git/blob - main/robot.c
hardcode robot names
[btb/d2x.git] / main / robot.c
1 /*
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.
12 */
13
14 /*
15  *
16  * Code for handling robots
17  *
18  */
19
20
21 #ifdef HAVE_CONFIG_H
22 #include <conf.h>
23 #endif
24
25 #include <stdio.h>
26
27 #include "error.h"
28 #include "inferno.h"
29 #include "mono.h"
30
31
32 int     N_robot_types = 0;
33 int     N_robot_joints = 0;
34
35 //      Robot stuff
36 robot_info Robot_info[MAX_ROBOT_TYPES];
37
38 #ifndef EDITOR
39 /* names "mech" through "escort" found in bitmaps.tbl */
40 char Robot_names[MAX_ROBOT_TYPES][ROBOT_NAME_LENGTH] = {
41         "mech",
42         "green",        // green guy
43         "spider",       // red spider
44         "josh",
45         "violet",       // spike
46         "clkvulc",      // cloak vulcan guy
47         "clkmech",      // cloak mech
48         "brain",
49         "onearm",       // one arm
50         "plasguy",
51         "toaster",
52         "bird",
53         "mislbird",
54         "splitpod",     // splitter pods
55         "smspider",     // small spider
56         "miniboss",
57         "suprmech",     // super mech
58         "boss1",        // shareware boss
59         "cloakgrn",     // cloaked green
60         "vulcnguy",     // vulcan guy
61         "rifleman",
62         "fourclaw",
63         "quadlaser",
64         "boss2",        // bigboss
65         "babyplas",
66         "newguy",
67         "icespidr",     // icespider
68         "gaussguy",
69         "newguy2",
70         "newguy3",
71         "newguy4",
72         "newguy5",
73         "newboss1",
74         "escort",
75 };
76 #endif
77
78 //Big array of joint positions.  All robots index into this array
79
80 #define deg(a) ((int) (a) * 32768 / 180)
81
82 //test data for one robot
83 jointpos Robot_joints[MAX_ROBOT_JOINTS] = {
84
85 //gun 0
86         {2,{deg(-30),0,0}},         //rest (2 joints)
87         {3,{deg(-40),0,0}},
88
89         {2,{deg(0),0,0}},           //alert
90         {3,{deg(0),0,0}},
91
92         {2,{deg(0),0,0}},           //fire
93         {3,{deg(0),0,0}},
94
95         {2,{deg(50),0,0}},          //recoil
96         {3,{deg(-50),0,0}},
97
98         {2,{deg(10),0,deg(70)}},    //flinch
99         {3,{deg(0),deg(20),0}},
100
101 //gun 1
102         {4,{deg(-30),0,0}},         //rest (2 joints)
103         {5,{deg(-40),0,0}},
104
105         {4,{deg(0),0,0}},           //alert
106         {5,{deg(0),0,0}},
107
108         {4,{deg(0),0,0}},           //fire
109         {5,{deg(0),0,0}},
110
111         {4,{deg(50),0,0}},          //recoil
112         {5,{deg(-50),0,0}},
113
114         {4,{deg(20),0,deg(-50)}},   //flinch
115         {5,{deg(0),0,deg(20)}},
116
117 //rest of body (the head)
118
119         {1,{deg(70),0,0}},          //rest (1 joint, head)
120
121         {1,{deg(0),0,0}},           //alert
122
123         {1,{deg(0),0,0}},           //fire
124
125         {1,{deg(0),0,0}},           //recoil
126
127         {1,{deg(-20),deg(15),0}},   //flinch
128
129 };
130
131 //given an object and a gun number, return position in 3-space of gun
132 //fills in gun_point
133 void calc_gun_point(vms_vector *gun_point,object *obj,int gun_num)
134 {
135         polymodel *pm;
136         robot_info *r;
137         vms_vector pnt;
138         vms_matrix m;
139         int mn;                         //submodel number
140
141         Assert(obj->render_type==RT_POLYOBJ || obj->render_type==RT_MORPH);
142         Assert(obj->id < N_robot_types);
143
144         r = &Robot_info[obj->id];
145         pm =&Polygon_models[r->model_num];
146
147         if (gun_num >= r->n_guns)
148         {
149                 mprintf((1, "Bashing gun num %d to 0.\n", gun_num));
150                 //Int3();
151                 gun_num = 0;
152         }
153
154 //      Assert(gun_num < r->n_guns);
155
156         pnt = r->gun_points[gun_num];
157         mn = r->gun_submodels[gun_num];
158
159         //instance up the tree for this gun
160         while (mn != 0) {
161                 vms_vector tpnt;
162
163                 vm_angles_2_matrix(&m,&obj->rtype.pobj_info.anim_angles[mn]);
164                 vm_transpose_matrix(&m);
165                 vm_vec_rotate(&tpnt,&pnt,&m);
166
167                 vm_vec_add(&pnt,&tpnt,&pm->submodel_offsets[mn]);
168
169                 mn = pm->submodel_parents[mn];
170         }
171
172         //now instance for the entire object
173
174         vm_copy_transpose_matrix(&m,&obj->orient);
175         vm_vec_rotate(gun_point,&pnt,&m);
176         vm_vec_add2(gun_point,&obj->pos);
177
178 }
179
180 //fills in ptr to list of joints, and returns the number of joints in list
181 //takes the robot type (object id), gun number, and desired state
182 int robot_get_anim_state(jointpos **jp_list_ptr,int robot_type,int gun_num,int state)
183 {
184
185         Assert(gun_num <= Robot_info[robot_type].n_guns);
186
187         *jp_list_ptr = &Robot_joints[Robot_info[robot_type].anim_states[gun_num][state].offset];
188
189         return Robot_info[robot_type].anim_states[gun_num][state].n_joints;
190
191 }
192
193
194 //for test, set a robot to a specific state
195 void set_robot_state(object *obj,int state)
196 {
197         int g,j,jo;
198         robot_info *ri;
199         jointlist *jl;
200
201         Assert(obj->type == OBJ_ROBOT);
202
203         ri = &Robot_info[obj->id];
204
205         for (g=0;g<ri->n_guns+1;g++) {
206
207                 jl = &ri->anim_states[g][state];
208
209                 jo = jl->offset;
210
211                 for (j=0;j<jl->n_joints;j++,jo++) {
212                         int jn;
213
214                         jn = Robot_joints[jo].jointnum;
215
216                         obj->rtype.pobj_info.anim_angles[jn] = Robot_joints[jo].angles;
217
218                 }
219         }
220 }
221
222 #include "mono.h"
223
224 //--unused-- int cur_state=0;
225
226 //--unused-- test_anim_states()
227 //--unused-- {
228 //--unused--    set_robot_state(&Objects[1],cur_state);
229 //--unused--
230 //--unused--    mprintf(0,"Robot in state %d\n",cur_state);
231 //--unused--
232 //--unused--    cur_state = (cur_state+1)%N_ANIM_STATES;
233 //--unused--
234 //--unused-- }
235
236 //set the animation angles for this robot.  Gun fields of robot info must
237 //be filled in.
238 void robot_set_angles(robot_info *r,polymodel *pm,vms_angvec angs[N_ANIM_STATES][MAX_SUBMODELS])
239 {
240         int m,g,state;
241         int gun_nums[MAX_SUBMODELS];                    //which gun each submodel is part of
242
243         for (m=0;m<pm->n_models;m++)
244                 gun_nums[m] = r->n_guns;                //assume part of body...
245
246         gun_nums[0] = -1;               //body never animates, at least for now
247
248         for (g=0;g<r->n_guns;g++) {
249                 m = r->gun_submodels[g];
250
251                 while (m != 0) {
252                         gun_nums[m] = g;                                //...unless we find it in a gun
253                         m = pm->submodel_parents[m];
254                 }
255         }
256
257         for (g=0;g<r->n_guns+1;g++) {
258
259                 //mprintf(0,"Gun %d:\n",g);
260
261                 for (state=0;state<N_ANIM_STATES;state++) {
262
263                         //mprintf(0," State %d:\n",state);
264
265                         r->anim_states[g][state].n_joints = 0;
266                         r->anim_states[g][state].offset = N_robot_joints;
267
268                         for (m=0;m<pm->n_models;m++) {
269                                 if (gun_nums[m] == g) {
270                                         //mprintf(0,"  Joint %d: %x %x %x\n",m,angs[state][m].pitch,angs[state][m].bank,angs[state][m].head);
271                                         Robot_joints[N_robot_joints].jointnum = m;
272                                         Robot_joints[N_robot_joints].angles = angs[state][m];
273                                         r->anim_states[g][state].n_joints++;
274                                         N_robot_joints++;
275                                         Assert(N_robot_joints < MAX_ROBOT_JOINTS);
276                                 }
277                         }
278                 }
279         }
280
281 }
282
283 #ifndef FAST_FILE_IO
284 /*
285  * reads n jointlist structs from a CFILE
286  */
287 static int jointlist_read_n(jointlist *jl, int n, CFILE *fp)
288 {
289         int i;
290
291         for (i = 0; i < n; i++) {
292                 jl[i].n_joints = cfile_read_short(fp);
293                 jl[i].offset = cfile_read_short(fp);
294         }
295         return i;
296 }
297
298 /*
299  * reads n robot_info structs from a CFILE
300  */
301 int robot_info_read_n(robot_info *ri, int n, CFILE *fp)
302 {
303         int i, j;
304
305         for (i = 0; i < n; i++) {
306                 ri[i].model_num = cfile_read_int(fp);
307                 for (j = 0; j < MAX_GUNS; j++)
308                         cfile_read_vector(&(ri[i].gun_points[j]), fp);
309                 cfread(ri[i].gun_submodels, MAX_GUNS, 1, fp);
310
311                 ri[i].exp1_vclip_num = cfile_read_short(fp);
312                 ri[i].exp1_sound_num = cfile_read_short(fp);
313
314                 ri[i].exp2_vclip_num = cfile_read_short(fp);
315                 ri[i].exp2_sound_num = cfile_read_short(fp);
316
317                 ri[i].weapon_type = cfile_read_byte(fp);
318                 ri[i].weapon_type2 = cfile_read_byte(fp);
319                 ri[i].n_guns = cfile_read_byte(fp);
320                 ri[i].contains_id = cfile_read_byte(fp);
321
322                 ri[i].contains_count = cfile_read_byte(fp);
323                 ri[i].contains_prob = cfile_read_byte(fp);
324                 ri[i].contains_type = cfile_read_byte(fp);
325                 ri[i].kamikaze = cfile_read_byte(fp);
326
327                 ri[i].score_value = cfile_read_short(fp);
328                 ri[i].badass = cfile_read_byte(fp);
329                 ri[i].energy_drain = cfile_read_byte(fp);
330
331                 ri[i].lighting = cfile_read_fix(fp);
332                 ri[i].strength = cfile_read_fix(fp);
333
334                 ri[i].mass = cfile_read_fix(fp);
335                 ri[i].drag = cfile_read_fix(fp);
336
337                 for (j = 0; j < NDL; j++)
338                         ri[i].field_of_view[j] = cfile_read_fix(fp);
339                 for (j = 0; j < NDL; j++)
340                         ri[i].firing_wait[j] = cfile_read_fix(fp);
341                 for (j = 0; j < NDL; j++)
342                         ri[i].firing_wait2[j] = cfile_read_fix(fp);
343                 for (j = 0; j < NDL; j++)
344                         ri[i].turn_time[j] = cfile_read_fix(fp);
345                 for (j = 0; j < NDL; j++)
346                         ri[i].max_speed[j] = cfile_read_fix(fp);
347                 for (j = 0; j < NDL; j++)
348                         ri[i].circle_distance[i] = cfile_read_fix(fp);
349                 cfread(ri[i].rapidfire_count, NDL, 1, fp);
350
351                 cfread(ri[i].evade_speed, NDL, 1, fp);
352
353                 ri[i].cloak_type = cfile_read_byte(fp);
354                 ri[i].attack_type = cfile_read_byte(fp);
355
356                 ri[i].see_sound = cfile_read_byte(fp);
357                 ri[i].attack_sound = cfile_read_byte(fp);
358                 ri[i].claw_sound = cfile_read_byte(fp);
359                 ri[i].taunt_sound = cfile_read_byte(fp);
360
361                 ri[i].boss_flag = cfile_read_byte(fp);
362                 ri[i].companion = cfile_read_byte(fp);
363                 ri[i].smart_blobs = cfile_read_byte(fp);
364                 ri[i].energy_blobs = cfile_read_byte(fp);
365
366                 ri[i].thief = cfile_read_byte(fp);
367                 ri[i].pursuit = cfile_read_byte(fp);
368                 ri[i].lightcast = cfile_read_byte(fp);
369                 ri[i].death_roll = cfile_read_byte(fp);
370
371                 ri[i].flags = cfile_read_byte(fp);
372                 cfread(ri[i].pad, 3, 1, fp);
373
374                 ri[i].deathroll_sound = cfile_read_byte(fp);
375                 ri[i].glow = cfile_read_byte(fp);
376                 ri[i].behavior = cfile_read_byte(fp);
377                 ri[i].aim = cfile_read_byte(fp);
378
379                 for (j = 0; j < MAX_GUNS + 1; j++)
380                         jointlist_read_n(ri[i].anim_states[j], N_ANIM_STATES, fp);
381
382                 ri[i].always_0xabcd = cfile_read_int(fp);
383         }
384         return i;
385 }
386
387 /*
388  * reads n jointpos structs from a CFILE
389  */
390 int jointpos_read_n(jointpos *jp, int n, CFILE *fp)
391 {
392         int i;
393
394         for (i = 0; i < n; i++) {
395                 jp[i].jointnum = cfile_read_short(fp);
396                 cfile_read_angvec(&jp[i].angles, fp);
397         }
398         return i;
399 }
400 #endif