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