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