]> icculus.org git repositories - btb/d2x.git/blob - main/object.h
add callback for console hide. disable controls when open.
[btb/d2x.git] / main / object.h
1 /* $Id: object.h,v 1.7 2004-08-28 23:17:45 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-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * object system definitions
18  *
19  */
20
21 #ifndef _OBJECT_H
22 #define _OBJECT_H
23
24 #include "pstypes.h"
25 #include "vecmat.h"
26 #include "segment.h"
27 #include "gameseg.h"
28 #include "aistruct.h"
29 #include "gr.h"
30 #include "piggy.h"
31
32 /*
33  * CONSTANTS
34  */
35
36 #define MAX_OBJECTS     350 // increased on 01/24/95 for multiplayer. --MK;  total number of objects in world
37
38 // Object types
39 #define OBJ_NONE        255 // unused object
40 #define OBJ_WALL        0   // A wall... not really an object, but used for collisions
41 #define OBJ_FIREBALL    1   // a fireball, part of an explosion
42 #define OBJ_ROBOT       2   // an evil enemy
43 #define OBJ_HOSTAGE     3   // a hostage you need to rescue
44 #define OBJ_PLAYER      4   // the player on the console
45 #define OBJ_WEAPON      5   // a laser, missile, etc
46 #define OBJ_CAMERA      6   // a camera to slew around with
47 #define OBJ_POWERUP     7   // a powerup you can pick up
48 #define OBJ_DEBRIS      8   // a piece of robot
49 #define OBJ_CNTRLCEN    9   // the control center
50 #define OBJ_FLARE       10  // a flare
51 #define OBJ_CLUTTER     11  // misc objects
52 #define OBJ_GHOST       12  // what the player turns into when dead
53 #define OBJ_LIGHT       13  // a light source, & not much else
54 #define OBJ_COOP        14  // a cooperative player object.
55 #define OBJ_MARKER      15  // a map marker
56
57 // WARNING!! If you add a type here, add its name to Object_type_names
58 // in object.c
59 #define MAX_OBJECT_TYPES    16
60
61 // Result types
62 #define RESULT_NOTHING  0   // Ignore this collision
63 #define RESULT_CHECK    1   // Check for this collision
64
65 // Control types - what tells this object what do do
66 #define CT_NONE         0   // doesn't move (or change movement)
67 #define CT_AI           1   // driven by AI
68 #define CT_EXPLOSION    2   // explosion sequencer
69 #define CT_FLYING       4   // the player is flying
70 #define CT_SLEW         5   // slewing
71 #define CT_FLYTHROUGH   6   // the flythrough system
72 #define CT_WEAPON       9   // laser, etc.
73 #define CT_REPAIRCEN    10  // under the control of the repair center
74 #define CT_MORPH        11  // this object is being morphed
75 #define CT_DEBRIS       12  // this is a piece of debris
76 #define CT_POWERUP      13  // animating powerup blob
77 #define CT_LIGHT        14  // doesn't actually do anything
78 #define CT_REMOTE       15  // controlled by another net player
79 #define CT_CNTRLCEN     16  // the control center/main reactor
80
81 // Movement types
82 #define MT_NONE         0   // doesn't move
83 #define MT_PHYSICS      1   // moves by physics
84 #define MT_SPINNING     3   // this object doesn't move, just sits and spins
85
86 // Render types
87 #define RT_NONE         0   // does not render
88 #define RT_POLYOBJ      1   // a polygon model
89 #define RT_FIREBALL     2   // a fireball
90 #define RT_LASER        3   // a laser
91 #define RT_HOSTAGE      4   // a hostage
92 #define RT_POWERUP      5   // a powerup
93 #define RT_MORPH        6   // a robot being morphed
94 #define RT_WEAPON_VCLIP 7   // a weapon that renders as a vclip
95
96 // misc object flags
97 #define OF_EXPLODING        1   // this object is exploding
98 #define OF_SHOULD_BE_DEAD   2   // this object should be dead, so next time we can, we should delete this object.
99 #define OF_DESTROYED        4   // this has been killed, and is showing the dead version
100 #define OF_SILENT           8   // this makes no sound when it hits a wall.  Added by MK for weapons, if you extend it to other types, do it completely!
101 #define OF_ATTACHED         16  // this object is a fireball attached to another object
102 #define OF_HARMLESS         32  // this object does no damage.  Added to make quad lasers do 1.5 damage as normal lasers.
103 #define OF_PLAYER_DROPPED   64  // this object was dropped by the player...
104
105 // Different Weapon ID types...
106 #define WEAPON_ID_LASER         0
107 #define WEAPON_ID_MISSLE        1
108 #define WEAPON_ID_CANNONBALL    2
109
110 // Object Initial shields...
111 #define OBJECT_INITIAL_SHIELDS F1_0/2
112
113 // physics flags
114 #define PF_TURNROLL         0x01    // roll when turning
115 #define PF_LEVELLING        0x02    // level object with closest side
116 #define PF_BOUNCE           0x04    // bounce (not slide) when hit will
117 #define PF_WIGGLE           0x08    // wiggle while flying
118 #define PF_STICK            0x10    // object sticks (stops moving) when hits wall
119 #define PF_PERSISTENT       0x20    // object keeps going even after it hits another object (eg, fusion cannon)
120 #define PF_USES_THRUST      0x40    // this object uses its thrust
121 #define PF_BOUNCED_ONCE     0x80    // Weapon has bounced once.
122 #define PF_FREE_SPINNING    0x100   // Drag does not apply to rotation of this object
123 #define PF_BOUNCES_TWICE    0x200   // This weapon bounces twice, then dies
124
125 #define IMMORTAL_TIME   0x3fffffff  // Time assigned to immortal objects, about 32768 seconds, or about 9 hours.
126 #define ONE_FRAME_TIME  0x3ffffffe  // Objects with this lifeleft will live for exactly one frame
127
128 extern char Object_type_names[MAX_OBJECT_TYPES][9];
129
130 // List of objects rendered last frame in order.  Created at render
131 // time, used by homing missiles in laser.c
132 #define MAX_RENDERED_OBJECTS    50
133
134 /*
135  * STRUCTURES
136  */
137
138 // A compressed form for sending crucial data about via slow devices,
139 // such as modems and buggies.
140 typedef struct shortpos {
141         sbyte   bytemat[9];
142         short   xo,yo,zo;
143         short   segment;
144         short   velx, vely, velz;
145 } __pack__ shortpos;
146
147 // This is specific to the shortpos extraction routines in gameseg.c.
148 #define RELPOS_PRECISION    10
149 #define MATRIX_PRECISION    9
150 #define MATRIX_MAX          0x7f    // This is based on MATRIX_PRECISION, 9 => 0x7f
151
152 // information for physics sim for an object
153 typedef struct physics_info {
154         vms_vector  velocity;   // velocity vector of this object
155         vms_vector  thrust;     // constant force applied to this object
156         fix         mass;       // the mass of this object
157         fix         drag;       // how fast this slows down
158         fix         brakes;     // how much brakes applied
159         vms_vector  rotvel;     // rotational velecity (angles)
160         vms_vector  rotthrust;  // rotational acceleration
161         fixang      turnroll;   // rotation caused by turn banking
162         ushort      flags;      // misc physics flags
163 } __pack__ physics_info;
164
165 // stuctures for different kinds of simulation
166
167 typedef struct laser_info {
168         short   parent_type;        // The type of the parent of this object
169         short   parent_num;         // The object's parent's number
170         int     parent_signature;   // The object's parent's signature...
171         fix     creation_time;      // Absolute time of creation.
172         short   last_hitobj;        // For persistent weapons (survive object collision), object it most recently hit.
173         short   track_goal;         // Object this object is tracking.
174         fix     multiplier;         // Power if this is a fusion bolt (or other super weapon to be added).
175 } __pack__ laser_info;
176
177 typedef struct explosion_info {
178     fix     spawn_time;         // when lifeleft is < this, spawn another
179     fix     delete_time;        // when to delete object
180     short   delete_objnum;      // and what object to delete
181     short   attach_parent;      // explosion is attached to this object
182     short   prev_attach;        // previous explosion in attach list
183     short   next_attach;        // next explosion in attach list
184 } __pack__ explosion_info;
185
186 typedef struct light_info {
187     fix     intensity;          // how bright the light is
188 } __pack__ light_info;
189
190 #define PF_SPAT_BY_PLAYER   1   //this powerup was spat by the player
191
192 typedef struct powerup_info {
193         int     count;          // how many/much we pick up (vulcan cannon only?)
194         fix     creation_time;  // Absolute time of creation.
195         int     flags;          // spat by player?
196 } __pack__ powerup_info;
197
198 typedef struct vclip_info {
199         int     vclip_num;
200         fix     frametime;
201         sbyte   framenum;
202 } __pack__ vclip_info;
203
204 // structures for different kinds of rendering
205
206 typedef struct polyobj_info {
207         int     model_num;          // which polygon model
208         vms_angvec anim_angles[MAX_SUBMODELS]; // angles for each subobject
209         int     subobj_flags;       // specify which subobjs to draw
210         int     tmap_override;      // if this is not -1, map all face to this
211         int     alt_textures;       // if not -1, use these textures instead
212 } __pack__ polyobj_info;
213
214 typedef struct object {
215         int     signature;      // Every object ever has a unique signature...
216         ubyte   type;           // what type of object this is... robot, weapon, hostage, powerup, fireball
217         ubyte   id;             // which form of object...which powerup, robot, etc.
218 #ifdef WORDS_NEED_ALIGNMENT
219         short   pad;
220 #endif
221         short   next,prev;      // id of next and previous connected object in Objects, -1 = no connection
222         ubyte   control_type;   // how this object is controlled
223         ubyte   movement_type;  // how this object moves
224         ubyte   render_type;    // how this object renders
225         ubyte   flags;          // misc flags
226         short   segnum;         // segment number containing object
227         short   attached_obj;   // number of attached fireball object
228         vms_vector pos;         // absolute x,y,z coordinate of center of object
229         vms_matrix orient;      // orientation of object in world
230         fix     size;           // 3d size of object - for collision detection
231         fix     shields;        // Starts at maximum, when <0, object dies..
232         vms_vector last_pos;    // where object was last frame
233         sbyte   contains_type;  // Type of object this object contains (eg, spider contains powerup)
234         sbyte   contains_id;    // ID of object this object contains (eg, id = blue type = key)
235         sbyte   contains_count; // number of objects of type:id this object contains
236         sbyte   matcen_creator; // Materialization center that created this object, high bit set if matcen-created
237         fix     lifeleft;       // how long until goes away, or 7fff if immortal
238         // -- Removed, MK, 10/16/95, using lifeleft instead: int     lightlevel;
239
240         // movement info, determined by MOVEMENT_TYPE
241         union {
242                 physics_info phys_info; // a physics object
243                 vms_vector   spin_rate; // for spinning objects
244         } mtype __pack__ ;
245
246         // control info, determined by CONTROL_TYPE
247         union {
248                 laser_info      laser_info;
249                 explosion_info  expl_info;      // NOTE: debris uses this also
250                 ai_static       ai_info;
251                 light_info      light_info;     // why put this here?  Didn't know what else to do with it.
252                 powerup_info    powerup_info;
253         } ctype __pack__ ;
254
255         // render info, determined by RENDER_TYPE
256         union {
257                 polyobj_info    pobj_info;      // polygon model
258                 vclip_info      vclip_info;     // vclip
259         } rtype __pack__ ;
260
261 #ifdef WORDS_NEED_ALIGNMENT
262         short   pad2;
263 #endif
264 } __pack__ object;
265
266 typedef struct obj_position {
267         vms_vector  pos;        // absolute x,y,z coordinate of center of object
268         vms_matrix  orient;     // orientation of object in world
269         short       segnum;     // segment number containing object
270 } obj_position;
271
272 typedef struct {
273         int     frame;
274         object  *viewer;
275         int     rear_view;
276         int     user;
277         int     num_objects;
278         short   rendered_objects[MAX_RENDERED_OBJECTS];
279 } window_rendered_data;
280
281 #define MAX_RENDERED_WINDOWS    3
282
283 extern window_rendered_data Window_rendered_data[MAX_RENDERED_WINDOWS];
284
285 /*
286  * VARIABLES
287  */
288
289 extern int Object_next_signature;   // The next signature for the next newly created object
290
291 extern ubyte CollisionResult[MAX_OBJECT_TYPES][MAX_OBJECT_TYPES];
292 // ie CollisionResult[a][b]==  what happens to a when it collides with b
293
294 extern object Objects[];
295 extern int Highest_object_index;    // highest objnum
296 #define OBJECT_NUMBER(obj) ((int)((obj) - Objects))
297
298 extern char *robot_names[];         // name of each robot
299
300 extern int Num_robot_types;
301
302 extern object *ConsoleObject;       // pointer to the object that is the player
303 extern object *Viewer;              // which object we are seeing from
304 extern object *Dead_player_camera;
305
306 extern object Follow;
307 extern int Player_is_dead;          // !0 means player is dead!
308 extern int Player_exploded;
309 extern int Death_sequence_aborted;
310 extern int Player_fired_laser_this_frame;
311
312 /*
313  * FUNCTIONS
314  */
315
316
317 // do whatever setup needs to be done
318 void init_objects();
319
320 // returns segment number object is in.  Searches out from object's current
321 // seg, so this shouldn't be called if the object has "jumped" to a new seg
322 int obj_get_new_seg(object *obj);
323
324 // when an object has moved into a new segment, this function unlinks it
325 // from its old segment, and links it into the new segment
326 void obj_relink(int objnum,int newsegnum);
327
328 // move an object from one segment to another. unlinks & relinks
329 void obj_set_new_seg(int objnum,int newsegnum);
330
331 // links an object into a segment's list of objects.
332 // takes object number and segment number
333 void obj_link(int objnum,int segnum);
334
335 // unlinks an object from a segment's list of objects
336 void obj_unlink(int objnum);
337
338 // initialize a new object.  adds to the list for the given segment
339 // returns the object number
340 int obj_create(ubyte type, ubyte id, int segnum, vms_vector *pos,
341                vms_matrix *orient, fix size,
342                ubyte ctype, ubyte mtype, ubyte rtype);
343
344 // make a copy of an object. returs num of new object
345 int obj_create_copy(int objnum, vms_vector *new_pos, int newsegnum);
346
347 // remove object from the world
348 void obj_delete(int objnum);
349
350 // called after load.  Takes number of objects, and objects should be
351 // compressed
352 void reset_objects(int n_objs);
353
354 // make object array non-sparse
355 void compress_objects(void);
356
357 // Render an object.  Calls one of several routines based on type
358 void render_object(object *obj);
359
360 // Draw a blob-type object, like a fireball
361 void draw_object_blob(object *obj, bitmap_index bitmap);
362
363 // draw an object that is a texture-mapped rod
364 void draw_object_tmap_rod(object *obj, bitmap_index bitmap, int lighted);
365
366 // Deletes all objects that have been marked for death.
367 void obj_delete_all_that_should_be_dead();
368
369 // Toggles whether or not lock-boxes draw.
370 void object_toggle_lock_targets();
371
372 // move all objects for the current frame
373 void object_move_all();     // moves all objects
374
375 // set viewer object to next object in array
376 void object_goto_next_viewer();
377
378 // draw target boxes for nearby robots
379 void object_render_targets(void);
380
381 // move an object for the current frame
382 void object_move_one(object * obj);
383
384 // make object0 the player, setting all relevant fields
385 void init_player_object();
386
387 // check if object is in object->segnum.  if not, check the adjacent
388 // segs.  if not any of these, returns false, else sets obj->segnum &
389 // returns true callers should really use find_vector_intersection()
390 // Note: this function is in gameseg.c
391 extern int update_object_seg(struct object *obj);
392
393
394 // Finds what segment *obj is in, returns segment number.  If not in
395 // any segment, returns -1.  Note: This function is defined in
396 // gameseg.h, but object.h depends on gameseg.h, and object.h is where
397 // object is defined...get it?
398 extern int find_object_seg(object * obj );
399
400 // go through all objects and make sure they have the correct segment
401 // numbers used when debugging is on
402 void fix_object_segs();
403
404 // Drops objects contained in objp.
405 int object_create_egg(object *objp);
406
407 // Interface to object_create_egg, puts count objects of type type, id
408 // = id in objp and then drops them.
409 int call_object_create_egg(object *objp, int count, int type, int id);
410
411 extern void dead_player_end(void);
412
413 // Extract information from an object (objp->orient, objp->pos,
414 // objp->segnum), stuff in a shortpos structure.  See typedef
415 // shortpos.
416 extern void create_shortpos(shortpos *spp, object *objp, int swap_bytes);
417
418 // Extract information from a shortpos, stuff in objp->orient
419 // (matrix), objp->pos, objp->segnum
420 extern void extract_shortpos(object *objp, shortpos *spp, int swap_bytes);
421
422 // delete objects, such as weapons & explosions, that shouldn't stay
423 // between levels if clear_all is set, clear even proximity bombs
424 void clear_transient_objects(int clear_all);
425
426 // returns the number of a free object, updating Highest_object_index.
427 // Generally, obj_create() should be called to get an object, since it
428 // fills in important fields and does the linking.  returns -1 if no
429 // free objects
430 int obj_allocate(void);
431
432 // frees up an object.  Generally, obj_delete() should be called to
433 // get rid of an object.  This function deallocates the object entry
434 // after the object has been unlinked
435 void obj_free(int objnum);
436
437 // after calling init_object(), the network code has grabbed specific
438 // object slots without allocating them.  Go though the objects &
439 // build the free list, then set the apporpriate globals Don't call
440 // this function if you don't know what you're doing.
441 void special_reset_objects(void);
442
443 // attaches an object, such as a fireball, to another object, such as
444 // a robot
445 void obj_attach(object *parent,object *sub);
446
447 extern void create_small_fireball_on_object(object *objp, fix size_scale, int sound_flag);
448
449 // returns object number
450 int drop_marker_object(vms_vector *pos, int segnum, vms_matrix *orient, int marker_num);
451
452 extern void wake_up_rendered_objects(object *gmissp, int window_num);
453
454 extern void AdjustMineSpawn();
455
456 void reset_player_object(void);
457
458 #endif