2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/Object/Object.h $
15 * <insert description of file here>
18 * Revision 1.2 2002/06/09 04:41:14 relnev
19 * added copyright header
21 * Revision 1.1.1.1 2002/05/03 03:28:12 root
25 * 17 8/16/99 3:53p Andsager
26 * Add special warp in interface in Fred and saving / reading.
28 * 16 7/15/99 9:20a Andsager
29 * FS2_DEMO initial checkin
31 * 15 7/01/99 11:44a Dave
32 * Updated object sound system to allow multiple obj sounds per ship.
33 * Added hit-by-beam sound. Added killed by beam sound.
35 * 14 6/28/99 4:51p Andsager
36 * Add ship-guardian sexp (does not allow ship to be killed)
38 * 13 5/18/99 11:50a Andsager
39 * Remove unused object type OBJ_GHOST_SAVE
41 * 12 4/26/99 10:58a Andsager
42 * Add OF_BEAM_PROTECTED flag to keep object from being targeted for zing.
44 * 11 4/23/99 5:53p Dave
45 * Started putting in new pof nebula support into Fred.
47 * 10 4/21/99 6:15p Dave
48 * Did some serious housecleaning in the beam code. Made it ready to go
49 * for anti-fighter "pulse" weapons. Fixed collision pair creation. Added
50 * a handy macro for recalculating collision pairs for a given object.
52 * 9 3/29/99 6:17p Dave
53 * More work on demo system. Got just about everything in except for
54 * blowing ships up, secondary weapons and player death/warpout.
56 * 8 1/25/99 5:03a Dave
57 * First run of stealth, AWACS and TAG missile support. New mission type
60 * 7 1/24/99 11:37p Dave
61 * First full rev of beam weapons. Very customizable. Removed some bogus
62 * Int3()'s in low level net code.
64 * 6 1/12/99 12:53a Dave
65 * More work on beam weapons - made collision detection very efficient -
66 * collide against all object types properly - made 3 movement types
67 * smooth. Put in test code to check for possible non-darkening pixels on
70 * 5 11/14/98 5:33p Dave
71 * Lots of nebula work. Put in ship contrails.
73 * 4 11/05/98 4:18p Dave
74 * First run nebula support. Beefed up localization a bit. Removed all
75 * conditional compiles for foreign versions. Modified mission file
78 * 3 10/16/98 3:42p Andsager
79 * increase MAX_WEAPONS and MAX_SHIPS and som header files
81 * 2 10/07/98 10:53a Dave
84 * 1 10/07/98 10:50a Dave
86 * 96 6/30/98 2:25p Dave
87 * Revamped object update system
89 * 95 6/30/98 2:23p Dave
90 * Revised object update system. Removed updates for all weapons. Put
91 * button info back into control info packet.
93 * 94 5/11/98 4:33p Allender
94 * fixed ingame join problems -- started to work on new object updating
95 * code (currently ifdef'ed out)
97 * 93 5/01/98 12:59a Dave
98 * Put in some test code for a new object update system. Found the problem
99 * with the current system (low-level packet buffering). Gonna fix it :)
101 * 92 4/02/98 11:40a Lawrance
102 * check for #ifdef DEMO instead of #ifdef DEMO_RELEASE
104 * 91 4/01/98 9:20a Mike
105 * Reduce MAX_SHIPS, MAX_OBJECTS and make MAX_AI_INFO same as MAX_SHIPS
107 * 90 3/31/98 5:18p John
108 * Removed demo/save/restore. Made NDEBUG defined compile. Removed a
109 * bunch of debug stuff out of player file. Made model code be able to
110 * unload models and malloc out only however many models are needed.
113 * 89 3/26/98 5:43p Lawrance
114 * rename ship_team_from_obj(), obj_team() and move to object lib
116 * 88 3/12/98 1:24p Mike
117 * When weapons linked, increase firing delay.
118 * Free up weapon slots for AI ships, if necessary.
119 * Backside render shield effect.
120 * Remove shield hit triangle if offscreen.
122 * 87 3/09/98 10:56a Hoffoss
123 * Added jump node objects to Fred.
125 * 86 3/07/98 2:34p Allender
126 * more ingame join stuff. Works in a basic fashion in this new system.
128 * 85 2/27/98 4:48p John
129 * Made objects keep track of number of pairs they have associated with
130 * them. Then, I can early out of the obj_remove_all which was 2.5% of
131 * frametime at beginning of sm2-2 which then is 0% after this.
133 * 84 2/26/98 3:46p Hoffoss
134 * Externed object_inited variable for use in state restore.
136 * 83 2/23/98 5:08p Allender
137 * made net_signature an unsigned short. Now using permanent and
138 * non-permanent object "pools".
140 * 82 2/05/98 12:51a Mike
141 * Early asteroid stuff.
143 * 81 1/18/98 5:09p Lawrance
144 * Added support for TEAM_TRAITOR
146 * 80 12/12/97 5:23p Lawrance
147 * add TEAM_ANY #define... used for some targeting functions
149 * 79 12/11/97 5:46p Hoffoss
150 * Changed Fred to not display weapons that are not available to various
153 * 78 11/03/97 5:38p Dave
154 * Cleaned up more multiplayer sequencing. Added OBJ_OBSERVER module/type.
155 * Restructured HUD_config structs/flags.
157 * 77 10/23/97 4:41p Allender
158 * lots of new rearm/repair code. Rearm requests now queue as goals for
159 * support ship. Warp in of new support ships functional. Support for
160 * stay-still and play-dead.
162 * 76 10/16/97 4:40p Allender
163 * removed object structure member (for multiplayer) -- moved to ship
166 * 75 9/30/97 5:05p Dave
167 * Added OF_COULD_BE_PLAYER flag for objects which ingame joiners can
170 * 74 9/25/97 4:50p Mike
171 * Support ignoring wings.
173 * 73 9/17/97 5:12p John
174 * Restructured collision routines. Probably broke a lot of stuff.
176 * 72 9/15/97 4:43p Dave
177 * Got basic observer mode working. Seems bug free so far.
179 * 71 9/11/97 5:01p Dave
180 * Minor changes to handle ingame joining/dropping for multiplayer.
182 * 70 9/09/97 12:01a Mike
183 * Further support for new team numbering, switched from 0, 1, 2, 3 to 1,
184 * 2, 4, 8 to allow attacking of two simultaneous teams.
186 * 69 9/08/97 10:24p Mike
187 * Working on attacking multiple simultaneous teams.
189 * 68 9/08/97 5:20p Dave
190 * Added OF_IS_ORIGINAL flag
192 * 67 9/06/97 2:13p Mike
193 * Replace support for TEAM_NEUTRAL
195 * 66 9/05/97 5:02p Lawrance
196 * save/restore object pairs
198 * 65 8/29/97 10:13a Allender
199 * work on server/client prediction code -- doesn't work too well. Made
200 * all clients simulate their own orientation with the server giving
201 * corrections every so often.
203 * 64 8/20/97 7:54p Lawrance
204 * make obj_reset_pairs() external
206 * 63 8/16/97 3:53p Hoffoss
207 * Added OF_NO_SHIELDS define and support in Fred and mission load/save.
209 * 62 8/11/97 8:46p Hoffoss
210 * Added a new object type for Fred usage.
212 * 61 8/11/97 10:36a John
213 * added new function that you should call when changing object flags.
215 * 60 8/04/97 11:45a Lawrance
216 * split off initialization of CheckObject[] elements into separate
219 * 59 7/31/97 5:55p John
220 * made so you pass flags to obj_create.
221 * Added new collision code that ignores any pairs that will never
224 * 58 7/30/97 9:40a Allender
225 * added last_orient to object structure in anticipation of use for
228 * 57 7/28/97 5:10p Hoffoss
229 * Removed all occurances of neutral team from Fred.
231 * 56 7/24/97 10:24a Mike
232 * Restore support for Unknown team
234 * 55 7/16/97 2:52p Lawrance
235 * make shockwaves objects
237 * 54 6/24/97 10:04a Allender
238 * major multiplayer improvements. Better sequencing before game.
239 * Dealing with weapon/fireball/counter measure objects between
242 * 53 6/23/97 10:12a Hoffoss
243 * Added new object type for Fred.
245 * 52 6/19/97 1:43p Allender
246 * basic object syncing when a mission loads. basic object update packets
249 * 51 6/13/97 1:15p Allender
250 * use player positions for multiplayer games. No real error checking
251 * yet, but you can get people into a mutiplayer mission now.
253 * 50 6/06/97 4:13p Lawrance
254 * use an index instead of a pointer for object-linked sounds
256 * 49 6/05/97 6:08p Hoffoss
257 * Added an object flag, and rearranged them to make it more organized.
259 * 48 5/19/97 1:07p Mike
260 * Add OBJ_GHOST and deal with a dead player better.
262 * 47 5/14/97 4:08p Lawrance
263 * removing my_index from game arrays
265 * 46 5/12/97 6:00p Mike
266 * Add countermeasures.
268 * 45 5/09/97 4:34p Lawrance
269 * move out obj_snd typedef
271 * 44 5/08/97 4:30p Lawrance
272 * split off object sound stuff into separate file
274 * 43 5/06/97 9:36a Lawrance
275 * added object-linked persistant sounds
277 * 42 4/25/97 3:29p Mike
278 * Making shield multi-part.
280 * 41 4/24/97 4:39p Hoffoss
281 * Waypoint navbouys are now objects of type OBJ_WAYPOINT and displaying
282 * of them can be toggled on and off through DCF.
284 * 40 4/10/97 3:20p Mike
285 * Change hull damage to be like shields.
287 * 39 3/07/97 4:37p Mike
288 * Make rockeye missile home.
289 * Remove UNKNOWN and NEUTRAL teams.
291 * 38 3/05/97 12:49p John
292 * added Viewer_obj. Took out the interp_??? variables for turning
293 * outline,etc on and put them in flags you pass to model_render.
294 * Cleaned up model_interp code to fit new coding styles.
296 * 37 2/07/97 9:09a John
297 * Added new debris objects
299 * 36 2/04/97 8:31a Adam
301 * 35 1/21/97 1:37p Hoffoss
302 * Added an object flag for Fred.
304 * 34 1/20/97 7:58p John
305 * Fixed some link errors with testcode.
307 * 33 1/10/97 5:15p Mike
308 * Moved ship-specific parameters from obj_subsystem to ship_subsys.
310 * Added turret code to AI system.
328 #define MAX_OBJECTS 300
330 #define MAX_OBJECTS 1000
333 #define MAX_SHIELD_SECTIONS 4 // Number of sections in shield.
340 #define TEAM_HOSTILE (1 << 0)
341 #define TEAM_FRIENDLY (1 << 1)
342 #define TEAM_NEUTRAL (1 << 2)
343 #define TEAM_UNKNOWN (1 << 3)
344 #define TEAM_TRAITOR (1 << 4)
345 #define TEAM_ANY (TEAM_HOSTILE|TEAM_FRIENDLY|TEAM_NEUTRAL|TEAM_UNKNOWN|TEAM_TRAITOR)
346 #define MAX_TEAM_NAMES_INDEX TEAM_TRAITOR
349 #define OBJ_NONE 0 //unused object
350 #define OBJ_SHIP 1 //a ship
351 #define OBJ_WEAPON 2 //a laser, missile, etc
352 #define OBJ_FIREBALL 3 //an explosion
353 #define OBJ_START 4 //a starting point marker (player start, etc)
354 #define OBJ_WAYPOINT 5 //a waypoint object, maybe only ever used by Fred
355 #define OBJ_DEBRIS 6 //a flying piece of ship debris
356 #define OBJ_CMEASURE 7 //a countermeasure, such as chaff
357 #define OBJ_GHOST 8 //so far, just a placeholder for when a player dies.
358 #define OBJ_POINT 9 //generic object type to display a point in Fred.
359 #define OBJ_SHOCKWAVE 10 // a shockwave
360 #define OBJ_WING 11 // not really a type used anywhere, but I need it for Fred.
361 #define OBJ_OBSERVER 12 // used for multiplayer observers (possibly single player later)
362 #define OBJ_ASTEROID 13 // An asteroid, you know, a big rock, like debris, sort of.
363 #define OBJ_JUMP_NODE 14 // A jump node object, used only in Fred.
364 #define OBJ_BEAM 15 // beam weapons. we have to roll them into the object system to get the benefits of the collision pairs
366 //Make sure to change Object_type_names in Object.c when adding another type!
367 #define MAX_OBJECT_TYPES 16
369 #define UNUSED_OBJNUM (-MAX_OBJECTS*2) // Newer systems use this instead of -1 for invalid object.
372 extern char *Object_type_names[MAX_OBJECT_TYPES];
375 // each object type should have these functions: (I will use weapon as example)
377 // int weapon_create( weapon specific parameters )
380 // objnum = obj_create();
381 // ... Do some check to correctly handle obj_create returning which
382 // means that that object couldn't be created
383 // ... Initialize the weapon-specific info in Objects[objnum]
387 // void weapon_delete( object * obj )
389 // {Put a call to this in OBJECT.C, function obj_delete_all_that_should_be_dead }
390 // WARNING: To kill an object, set it's OF_SHOULD_BE_DEAD flag. Then,
391 // this function will get called when it's time to clean up the data.
392 // Assert( obj->flags & OF_SHOULD_BE_DEAD );
394 // ... Free up all weapon-specfic data
395 // obj_delete(objnum);
398 // void weapon_move( object * obj )
400 // {Put a call to this in ??? }
401 // ... Do whatever needs to be done each frame. Usually this amounts
402 // to setting the thrust, seeing if we've died, etc.
405 // int weapon_check_collision( object * obj, object * other_obj, vector * hitpos )
407 // this should check if a vector from
408 // other_obj->last_pos to other_obj->pos with a radius of other_obj->radius
409 // collides with object obj. If it does, then fill in hitpos with the point
410 // of impact and return non-zero, otherwise return 0 if no impact. Note that
411 // this shouldn't take any action... that happens in weapon_hit.
415 // void weapon_hit( object * obj, object * other_obj, vector * hitpos )
417 // {Put a call to this in COLLIDE.C}
418 // ... Do what needs to be done when this object gets hit
419 // ... Reducing shields, etc
423 #define OF_RENDERS (1<<0) //It renders as something ( objtype_render gets called)
424 #define OF_COLLIDES (1<<1) //It collides with stuff (objtype_check_impact & objtype_hit gets called)
425 #define OF_PHYSICS (1<<2) //It moves with standard physics.
426 #define OF_SHOULD_BE_DEAD (1<<3) //this object should be dead, so next time we can, we should delete this object.
427 #define OF_INVULNERABLE (1<<4) // invulnerable
428 #define OF_PROTECTED (1<<5) // Don't kill this object, probably mission-critical.
429 #define OF_PLAYER_SHIP (1<<6) // this object under control of some player -- don't do ai stuff on it!!!
430 #define OF_NO_SHIELDS (1<<7) // object has no shield generator system (i.e. no shileds)
431 #define OF_JUST_UPDATED (1<<8) // for multiplayer -- indicates that we received object update this frame
432 #define OF_COULD_BE_PLAYER (1<<9) // for multiplayer -- indicates that it is selectable ingame joiners as their ship
433 #define OF_WAS_RENDERED (1<<10) // Set if this object was rendered this frame. Only gets set if OF_RENDERS set. Gets cleared or set in obj_render_all().
434 #define OF_NOT_IN_COLL (1<<11) // object has not been added to collision list
435 #define OF_BEAM_PROTECTED (1<<12) // don't fire beam weapons at this type of object, probably mission critical.
436 #define OF_GUARDIAN (1<<13) // Don't allow ship to die, keep at least 1% hull
437 #define OF_SPECIAL_WARP (1<<14) // Object has special warp-in enabled.
439 // Flags used by Fred
440 #define OF_MARKED (1<<16) //Object is marked (Fred). Can be reused in Freespace for anything that won't be used by Fred.
441 #define OF_TEMP_MARKED (1<<17) //Temporarily marked (Fred).
442 #define OF_REFERENCED (1<<18) // (Fred) Object is referenced by something somewhere
443 #define OF_HIDDEN (1<<19) // Object is hidden (not shown) and can't be manipulated
445 // max # of object sounds per object
446 #define MAX_OBJECT_SOUNDS 4
448 typedef struct object {
449 struct object *next, *prev; // for linked lists of objects
450 int signature; // Every object ever has a unique signature...
451 char type; // what type of object this is... robot, weapon, hostage, powerup, fireball
452 int parent; // This object's parent.
453 int parent_sig; // This object's parent's signature
454 char parent_type; // This object's parent's type
455 int instance; // which instance. ie.. if type is Robot, then this indexes into the Robots array
456 uint flags; // misc flags. Call obj_set_flags to change this.
457 vector pos; // absolute x,y,z coordinate of center of object
458 matrix orient; // orientation of object in world
459 float radius; // 3d size of object - for collision detection
460 vector last_pos; // where object was last frame
461 matrix last_orient; // how the object was oriented last frame
462 physics_info phys_info; // a physics object
463 float shields[MAX_SHIELD_SECTIONS]; // Shield is broken into components. Quadrants on 4/24/97.
464 float hull_strength; // Remaining hull strength.
465 short objsnd_num[MAX_OBJECT_SOUNDS]; // Index of persistant sound struct. -1 if no persistant sound assigned.
466 ushort net_signature;
467 int num_pairs; // How many object pairs this is associated with. When 0 then there are no more.
470 // object backup struct used by Fred.
471 typedef struct object_orient_pos {
480 extern int Object_inited;
481 extern int Show_waypoints;
483 // The next signature for the next newly created object. Zero is bogus
484 #define OBJECT_SIG_SHIP_START 300000; // ships start at this signature
485 extern int Object_next_ship_signature;
486 extern int Object_next_signature;
487 extern int num_objects;
489 extern object Objects[];
490 extern int Highest_object_index; //highest objnum
491 extern int Highest_ever_object_index;
492 extern object obj_free_list;
493 extern object obj_used_list;
494 extern object obj_create_list;
496 extern int render_total;
497 extern int render_order[MAX_OBJECTS];
499 extern object *Viewer_obj; // Which object is the viewer. Can be NULL.
500 extern object *Player_obj; // Which object is the player. Has to be valid.
502 // Use this instead of "objp - Objects" to get an object number
503 // given it's pointer. This way, we can replace it will a macro
504 // to check that the pointer is valid for debugging.
505 #define OBJ_INDEX(objp) (objp-Objects)
511 //do whatever setup needs to be done
514 //initialize a new object. adds to the list for the given segment.
515 //returns the object number. The object will be a non-rendering, non-physics
516 //object. Returns 0 if failed, otherwise object index.
517 //You can pass 0 for parent if you don't care about that.
518 //You can pass null for orient and/or pos if you don't care.
519 int obj_create(ubyte type,int parent_obj, int instance, matrix * orient, vector * pos, float radius, uint flags );
521 //Render an object. Calls one of several routines based on type
522 void obj_render(object *obj);
524 //Sorts and renders all the ojbects
525 void obj_render_all(void (*render_function)(object *objp) );
527 //move all objects for the current frame
528 void obj_move_all(float frametime); // moves all objects
530 //move an object for the current frame
531 void obj_move_one(object * obj, float frametime);
533 // function to delete an object -- should probably only be called directly from editor code
534 void obj_delete(int objnum);
536 // should only be used by the editor!
537 void obj_merge_created_list(void);
539 // recalculate object pairs for an object
540 #define OBJ_RECALC_PAIRS(obj_to_reset) do { obj_set_flags(obj_to_reset, obj_to_reset->flags & ~(OF_COLLIDES)); obj_set_flags(obj_to_reset, obj_to_reset->flags | OF_COLLIDES); } while(0);
542 // Removes any occurances of object 'a' from the pairs list.
543 void obj_remove_pairs( object * a );
545 // add an object to the pairs list
546 void obj_add_pairs(int objnum);
548 // Returns true if objects A and B are expected to collide in next duration seconds.
549 // For purposes of this check, the first object moves from current location to predicted
550 // location. The second object is assumed to be where it will be at time duration, NOT
551 // where it currently is.
552 // radius_scale: 0.0f means use polygon models, else scale sphere size by radius_scale
553 // radius_scale == 1.0f means Descent style collisions.
554 int objects_will_collide(object *A, object *B, float duration, float radius_scale);
556 // Used for pausing. Seems hacked. Was in PHYSICS, but that broke the TestCode program,
557 // so I moved it into the object lib. -John
558 void obj_init_all_ships_physics();
560 float get_shield_strength(object *objp);
561 void set_shield_strength(object *objp, float strength);
562 void add_shield_strength(object *objp, float delta);
564 // returns the average 3-space position of all ships. useful to find "center" of battle (sort of)
565 void obj_get_average_ship_pos(vector *pos);
567 // function to deal with firing player things like lasers, missiles, etc.
568 // separated out because of multiplayer issues.
569 void obj_player_fire_stuff( object *objp, control_info ci );
571 // Call this if you want to change an object flag so that the
572 // object code knows what's going on. For instance if you turn
573 // off OF_COLLIDES, the object code needs to know this in order to
574 // actually turn the object collision detection off. By calling
575 // this you shouldn't get Int3's in the checkobject code. If you
576 // do, then put code in here to correctly handle the case.
577 void obj_set_flags(object *obj, uint new_flags);
579 // get the Ship_info flags for a given ship (if you have the object)
580 int obj_get_SIF(object *objp);
581 int obj_get_SIF(int obj);
583 // get the team for any object
584 int obj_team(object *objp);
586 void obj_move_all_pre(object *objp, float frametime);
587 void obj_move_all_post(object *objp, float frametime);
589 void obj_move_call_physics(object *objp, float frametime);
591 // multiplayer object update stuff begins -------------------------------------------
593 // do client-side pre-interpolation object movement
594 void obj_client_pre_interpolate();
596 // do client-side post-interpolation object movement
597 void obj_client_post_interpolate();
599 // move an observer object in multiplayer
600 void obj_observer_move(float flFrametime);