]> icculus.org git repositories - taylor/freespace2.git/blob - include/ship.h
added copyright header
[taylor/freespace2.git] / include / ship.h
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
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
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Ship/Ship.h $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * all sorts of cool stuff about ships
16  *
17  * $Log$
18  * Revision 1.2  2002/06/09 04:41:14  relnev
19  * added copyright header
20  *
21  * Revision 1.1.1.1  2002/05/03 03:28:12  root
22  * Initial import.
23  *
24  * 
25  * 73    9/01/99 10:15a Dave
26  * 
27  * 72    8/30/99 5:01p Dave
28  * Made d3d do less state changing in the nebula. Use new chat server for
29  * PXO.
30  * 
31  * 71    8/27/99 9:07p Dave
32  * LOD explosions. Improved beam weapon accuracy.
33  * 
34  * 70    8/26/99 8:52p Dave
35  * Gave multiplayer TvT messaging a heavy dose of sanity. Cheat codes.
36  * 
37  * 69    8/18/99 12:09p Andsager
38  * Add debug if message has no anim for message.  Make messages come from
39  * wing leader.
40  * 
41  * 68    8/16/99 10:04p Andsager
42  * Add special-warp-dist and special-warpout-name sexp for Knossos device
43  * warpout.
44  * 
45  * 67    8/16/99 2:01p Andsager
46  * Knossos warp-in warp-out.
47  * 
48  * 66    8/13/99 10:49a Andsager
49  * Knossos and HUGE ship warp out.  HUGE ship warp in.  Stealth search
50  * modes dont collide big ships.
51  * 
52  * 65    8/02/99 10:39p Dave
53  * Added colored shields. OoOoOoooOoo
54  * 
55  * 64    7/28/99 1:36p Andsager
56  * Modify cargo1 to include flag CARGO_NO_DEPLETE.  Add sexp
57  * cargo-no-deplete (only for BIG / HUGE).  Modify ship struct to pack
58  * better.
59  * 
60  * 63    7/26/99 8:06a Andsager
61  * Consistent personas
62  * 
63  * 62    7/19/99 8:56p Andsager
64  * Added Ship_exited red_alert_carry flag and hull strength for RED ALERT
65  * carry over of Exited_ships
66  * 
67  * 61    7/18/99 5:20p Dave
68  * Jump node icon. Fixed debris fogging. Framerate warning stuff.
69  * 
70  * 60    7/15/99 9:20a Andsager
71  * FS2_DEMO initial checkin
72  * 
73  * 59    7/09/99 5:54p Dave
74  * Seperated cruiser types into individual types. Added tons of new
75  * briefing icons. Campaign screen.
76  * 
77  * 58    7/08/99 12:06p Andsager
78  * Add turret-tagged-only and turret-tagged-clear sexp.
79  * 
80  * 57    7/08/99 11:45a Dave
81  * Bumped up max ship types.
82  * 
83  * 56    7/08/99 10:53a Dave
84  * New multiplayer interpolation scheme. Not 100% done yet, but still
85  * better than the old way.
86  * 
87  * 55    7/06/99 10:45a Andsager
88  * Modify engine wash to work on any ship that is not small.  Add AWACS
89  * ask for help.
90  * 
91  * 54    7/01/99 4:23p Dave
92  * Full support for multiple linked ambient engine sounds. Added "big
93  * damage" flag.
94  * 
95  * 53    7/01/99 11:44a Dave
96  * Updated object sound system to allow multiple obj sounds per ship.
97  * Added hit-by-beam sound. Added killed by beam sound.
98  * 
99  * 52    6/30/99 5:53p Dave
100  * Put in new anti-camper code.
101  * 
102  * 51    6/14/99 3:21p Andsager
103  * Allow collisions between ship and its debris.  Fix up collision pairs
104  * when large ship is warping out.
105  * 
106  * 50    6/07/99 4:21p Andsager
107  * Add HUD color for tagged object.  Apply to target and radar.
108  * 
109  * 49    6/03/99 11:43a Dave
110  * Added the ability to use a different model when rendering to the HUD
111  * target box.
112  * 
113  * 48    6/01/99 8:35p Dave
114  * Finished lockarm weapons. Added proper supercap weapons/damage. Added
115  * awacs-set-radius sexpression.
116  * 
117  * 47    5/28/99 9:26a Andsager
118  * Added check_world_pt_in_expanded_ship_bbox() function
119  * 
120  * 46    5/26/99 11:46a Dave
121  * Added ship-blasting lighting and made the randomization of lighting
122  * much more customizable.
123  * 
124  * 45    5/21/99 5:03p Andsager
125  * Add code to display engine wash death.  Modify ship_kill_packet
126  * 
127  * 44    5/20/99 7:00p Dave
128  * Added alternate type names for ships. Changed swarm missile table
129  * entries.
130  * 
131  * 43    5/14/99 11:50a Andsager
132  * Added vaporize for SMALL ships hit by HUGE beams.  Modified dying
133  * frame.  Enlarged debris shards and range at which visible.
134  * 
135  * 42    5/12/99 2:55p Andsager
136  * Implemented level 2 tag as priority in turret object selection
137  * 
138  * 41    5/11/99 10:16p Andsager
139  * First pass on engine wash effect.  Rotation (control input), damage,
140  * shake.  
141  * 
142  * 40    4/28/99 3:11p Andsager
143  * Stagger turret weapon fire times.  Make turrets smarter when target is
144  * protected or beam protected.  Add weaopn range to weapon info struct.
145  * 
146  * 39    4/28/99 9:39a Andsager
147  * flag for ship_weapon turret lock
148  * 
149  * 38    4/23/99 12:01p Johnson
150  * Added SIF_HUGE_SHIP
151  * 
152  * 37    4/20/99 6:39p Dave
153  * Almost done with artillery targeting. Added support for downloading
154  * images on the PXO screen.
155  * 
156  * 36    4/19/99 11:01p Dave
157  * More sophisticated targeting laser support. Temporary checkin.
158  * 
159  * 35    4/19/99 12:21p Johnson
160  * Allow ships with invisible polygons which do not collide
161  * 
162  * 34    4/16/99 5:54p Dave
163  * Support for on/off style "stream" weapons. Real early support for
164  * target-painting lasers.
165  * 
166  * 33    4/12/99 10:07p Dave
167  * Made network startup more forgiving. Added checkmarks to dogfight
168  * screen for players who hit commit.
169  * 
170  * 32    4/02/99 9:55a Dave
171  * Added a few more options in the weapons.tbl for beam weapons. Attempt
172  * at putting "pain" packets into multiplayer.
173  * 
174  * 31    3/31/99 8:24p Dave
175  * Beefed up all kinds of stuff, incluging beam weapons, nebula effects
176  * and background nebulae. Added per-ship non-dimming pixel colors.
177  * 
178  * 30    3/30/99 5:40p Dave
179  * Fixed reinforcements for TvT in multiplayer.
180  * 
181  * 29    3/28/99 5:58p Dave
182  * Added early demo code. Make objects move. Nice and framerate
183  * independant, but not much else. Don't use yet unless you're me :)
184  * 
185  * 28    3/20/99 3:46p Dave
186  * Added support for model-based background nebulae. Added 3 new
187  * sexpressions.
188  * 
189  * 27    3/08/99 7:03p Dave
190  * First run of new object update system. Looks very promising.
191  * 
192  * 26    3/04/99 6:09p Dave
193  * Added in sexpressions for firing beams and checking for if a ship is
194  * tagged.
195  * 
196  * 25    3/02/99 9:25p Dave
197  * Added a bunch of model rendering debug code. Started work on fixing
198  * beam weapon wacky firing.
199  * 
200  * 24    3/01/99 7:39p Dave
201  * Added prioritizing ship respawns. Also fixed respawns in TvT so teams
202  * don't mix respawn points.
203  * 
204  * 23    2/26/99 6:01p Andsager
205  * Add sexp has-been-tagged-delay and cap-subsys-cargo-known-delay
206  * 
207  * 22    2/26/99 4:14p Dave
208  * Put in the ability to have multiple shockwaves for ships.
209  * 
210  * 21    2/11/99 5:22p Andsager
211  * Fixed bugs, generalized block Sexp_variables
212  * 
213  * 20    2/11/99 2:15p Andsager
214  * Add ship explosion modification to FRED
215  * 
216  * 19    2/03/99 6:06p Dave
217  * Groundwork for FS2 PXO usertracker support.  Gametracker support next.
218  * 
219  * $NoKeywords: $
220  */
221
222 #ifndef _SHIP_H
223 #define _SHIP_H
224
225 #include "parselo.h"            // for defintions of token lengths -- maybe move this elsewhere later
226 #include "model.h"
227 #include "2d.h"                 // for color def
228 #include "multi_obj.h"
229 #include "trails.h"
230 #include "palman.h"
231
232 struct object;
233
234 //      Part of the player died system.
235 extern vector   Dead_camera_pos, Original_vec_to_deader;
236
237 //      States for player death sequence, stuffed in Player_died_state.
238 #define PDS_NONE                1
239 #define PDS_DIED                2
240 #define PDS_EJECTED     3
241
242 #ifdef NDEBUG
243         #ifdef FRED
244                 #define MAX_SHIPS                                       100                     // max number of ship instances there can be.
245                 #define SHIPS_LIMIT                                     100                     // what MAX_SHIPS will be at release time (for error checking in debug mode)
246         #else
247                 #define MAX_SHIPS                                       150                     // max number of ship instances there can be.
248                 #define SHIPS_LIMIT                                     150                     // what MAX_SHIPS will be at release time (for error checking in debug mode)
249         #endif
250 #else
251 #define MAX_SHIPS                                       200                     // max number of ship instances there can be.
252 #define SHIPS_LIMIT                                     200                     // what MAX_SHIPS will be at release time (for error checking in debug mode)
253 #endif
254
255 #define HULL_DAMAGE_THRESHOLD_PERCENT   0.25f   //      Apply damage to hull, not shield if shield < this
256 #define HP_SCALE                                                1.2                     //      1.2 means die when 20% of hits remaining
257 #define MAX_SHIP_HITS                           8                               // hits to kill a ship
258 #define MAX_SHIP_DETAIL_LEVELS  5                               // maximum detail levels that a ship can render at
259 #define MAX_REINFORCEMENTS              10
260
261 #define MAX_ESCORT_SHIPS        3
262 #define MAX_SHIP_WEAPONS        5
263 #define MAX_OBJECT_STATUS       10
264
265 #define MAX_PRIMARY_WEAPON_TYPES        10
266 #define MAX_SECONDARY_WEAPON_TYPES      10
267
268 // defines for 'direction' parameter of ship_select_next_primary()
269 #define CYCLE_PRIMARY_NEXT              0
270 #define CYCLE_PRIMARY_PREV              1
271
272 #define BANK_1          0
273 #define BANK_2          1
274 #define BANK_3          2
275 #define BANK_4          3
276 #define BANK_5          4
277 #define BANK_6          5
278 #define BANK_7          6
279 #define BANK_8          7
280 #define BANK_9          8
281
282 #define TYPE_ATTACK_PROTECT     0
283 #define TYPE_REPAIR_REARM               1
284
285 #define MAX_REINFORCEMENT_MESSAGES      5
286
287 #define RF_IS_AVAILABLE                 (1<<0)                  // reinforcement is now available
288
289 typedef struct {
290         char    name[NAME_LENGTH];      // ship or wing name (ship and wing names don't collide)
291         int     type;                                           // what operations this reinforcement unit can perform
292         int     uses;                                           // number of times reinforcemnt unit can be used
293         int     num_uses;                               // number of times this reinforcement was actually used
294         int     arrival_delay;                  // how long after called does this reinforcement appear
295         int     flags;
296         char    no_messages[MAX_REINFORCEMENT_MESSAGES][NAME_LENGTH];           // list of messages to possibly send when calling for reinforcement not available
297         char    yes_messages[MAX_REINFORCEMENT_MESSAGES][NAME_LENGTH];  // list of messages to acknowledge reinforcement on the way
298 } reinforcements;
299
300 // ship weapon flags
301 #define SW_FLAG_BEAM_FREE                                       (1<<0)                                                  // if this is a beam weapon, its free to fire
302 #define SW_FLAG_TURRET_LOCK                             (1<<1)                                                  //      is this turret is free to fire or locked
303 #define SW_FLAG_TAGGED_ONLY                             (1<<2)                                                  // only fire if target is tagged
304
305 typedef struct {
306         int num_primary_banks;                                  // Number of primary banks (same as model)
307         int num_secondary_banks;                                // Number of secondary banks (same as model)
308
309         int primary_bank_weapons[MAX_PRIMARY_BANKS];                    // Weapon_info[] index for the weapon in the bank
310         int secondary_bank_weapons[MAX_SECONDARY_BANKS];        // Weapon_info[] index for the weapon in the bank
311
312         int current_primary_bank;                       // currently selected primary bank
313         int current_secondary_bank;             // currently selected secondary bank
314
315         int next_primary_fire_stamp[MAX_PRIMARY_BANKS];                 // next time this primary bank can fire
316         int next_secondary_fire_stamp[MAX_SECONDARY_BANKS];     // next time this secondary bank can fire       
317
318         int secondary_bank_ammo[MAX_SECONDARY_BANKS];                   // Number of missiles left in secondary bank
319         int secondary_bank_start_ammo[MAX_SECONDARY_BANKS];     // Number of missiles starting in secondary bank
320         int secondary_bank_capacity[MAX_SECONDARY_BANKS];               // Max number of missiles in bank
321         int secondary_next_slot[MAX_SECONDARY_BANKS];                   // Next slot to fire in the bank
322         int secondary_bank_rearm_time[MAX_SECONDARY_BANKS];     // timestamp which indicates when bank can get new missile
323
324         int last_fired_weapon_index;            //      Index of last fired secondary weapon.  Used for remote detonates.
325         int last_fired_weapon_signature;        //      Signature of last fired weapon.
326         int detonate_weapon_time;                       //      time at which last fired weapon can be detonated
327         int ai_class;
328
329         int flags;                                                              // see SW_FLAG_* defines above
330 } ship_weapon;
331
332
333 // structure definition for a linked list of subsystems for a ship.  Each subsystem has a pointer
334 // to the static data for the subsystem.  The obj_subsystem data is defined and read in the model
335 // code.  Other dynamic data (such as current_hits) should remain in this structure.
336 typedef struct ship_subsys {
337         struct ship_subsys *next, *prev;                                //      Index of next and previous objects in list.
338         model_subsystem *system_info;                                   // pointer to static data for this subsystem -- see model.h for definition
339         float           current_hits;                                                   // current number of hits this subsystem has left.
340
341         // turret info
342         vector  turret_last_fire_direction;             //      direction pointing last time this turret fired
343         int             turret_next_enemy_check_stamp;  //      time at which to next look for a new enemy.
344         int             turret_next_fire_stamp;                         // next time this turret can fire
345         int             turret_enemy_objnum;                                    //      object index of ship this turret is firing upon
346         int             turret_enemy_sig;                                               //      signature of object ship this turret is firing upon
347         int             turret_next_fire_pos;                           // counter which tells us which gun position to fire from next
348         float           turret_time_enemy_in_range;             //      Number of seconds enemy in view cone, accuracy improves over time.
349         ship_subsys     *targeted_subsys;                                       //      subsystem this turret is attacking
350
351         int             turret_pick_big_attack_point_timestamp; //      Next time to pick an attack point for this turret
352         vector  turret_big_attack_point;                        //      local coordinate of point for this turret to attack on enemy
353
354         // swarm (rapid fire) info
355         int             turret_swarm_info_index;        
356
357         // awacs info
358         float           awacs_intensity;
359         float           awacs_radius;
360
361         ship_weapon     weapons;
362
363         // Data the renderer needs for ship instance specific data, like
364         // angles and if it is blown off or not.
365         // There are 2 of these because turrets need one for the turret and one for the barrel.
366         // Things like radar dishes would only use one.
367         submodel_instance_info  submodel_info_1;                // Instance data for main turret or main object
368         submodel_instance_info  submodel_info_2;                // Instance data for turret guns, if there is one
369
370         int disruption_timestamp;                                                       // time at which subsystem isn't disrupted
371
372         int subsys_cargo_name;                  // cap ship cargo on subsys
373         int subsys_cargo_revealed;
374 } ship_subsys;
375
376 // structure for subsystems which tells us the total count of a particular type of subsystem (i.e.
377 // we might have 3 engines), and the relative strength of the subsystem.  The #defines in model.h
378 // for SUBSYSTEM_xxx will be used as indices into this array.
379 typedef struct ship_subsys_info {
380         int             num;                            // number of subsystems of type on this ship;
381         float           total_hits;             // total number of hits between all subsystems of this type.
382         float           current_hits;   // current count of hits for all subsystems of this type.       
383 } ship_subsys_info;
384
385 #define MAX_IFF_COLORS  7
386
387 #define IFF_COLOR_HOSTILE               0
388 #define IFF_COLOR_FRIENDLY      1
389 #define IFF_COLOR_NEUTRAL               2
390 #define IFF_COLOR_UNKNOWN               3
391 #define IFF_COLOR_SELECTION     4
392 #define IFF_COLOR_MESSAGE               5
393 #define IFF_COLOR_TAGGED                6
394
395 #define SET_COLOR_HOSTILE       gr_set_color_fast(&IFF_colors[IFF_COLOR_HOSTILE][0])
396 #define SET_COLOR_FRIENDLY      gr_set_color_fast(&IFF_colors[IFF_COLOR_FRIENDLY][0])
397 #define SET_COLOR_NEUTRAL       gr_set_color_fast(&IFF_colors[IFF_COLOR_NEUTRAL][0])
398 #define SET_COLOR_UNKNOWN       gr_set_color_fast(&IFF_colors[IFF_COLOR_UNKNOWN][0])
399 #define SET_COLOR_TAGGED        gr_set_color_fast(&IFF_colors[IFF_COLOR_TAGGED][0])
400
401 // reference an array to store the different IFF colors
402 extern color IFF_colors[MAX_IFF_COLORS][2];
403         
404 #include "ai.h"  // ship_subsys must be declared before we include this.
405 #include "weapon.h"             // ship_subsys must be declared before we include this.
406
407 //#define       MAX_SHIP_SUBOBJECTS             50
408
409 //extern ship_subobj    Ship_subsystems[MAX_SHIP_SUBOBJECTS];
410
411 // states for the flags variable within the ship structure
412 // low bits are for mission file savable flags..
413 // FRED needs these to be the low-order bits with no holes,
414 // because it indexes into an array, Hoffoss says.
415 #define SF_IGNORE_COUNT                 (1 << 0)                // ignore this ship when counting ship types for goals
416 #define SF_REINFORCEMENT                        (1 << 1)                // this ship is a reinforcement ship
417 #define SF_ESCORT                                       (1 << 2)                // this ship is an escort ship
418 #define SF_NO_ARRIVAL_MUSIC             (1 << 3)                // don't play arrival music when ship arrives
419 #define SF_NO_ARRIVAL_WARP              (1 << 4)                // no arrival warp in effect
420 #define SF_NO_DEPARTURE_WARP            (1 << 5)                // no departure warp in effect
421 #define SF_LOCKED                                       (1 << 6)                // can't manipulate ship in loadout screens
422 #define SF_INVULNERABLE                 (1 << 7)
423
424 // high bits are for internal flags not saved to mission files
425 // Go from bit 31 down to bit 3
426 #define SF_KILL_BEFORE_MISSION  (1 << 31)
427 #define SF_DYING                                                (1 << 30)
428 #define SF_DISABLED                                     (1 << 29)
429 #define SF_DEPART_WARP                          (1 << 28)       // ship is departing via warp-out
430 #define SF_DEPART_DOCKBAY                       (1 << 27)       // ship is departing via docking bay
431 #define SF_ARRIVING_STAGE_1             (1 << 26)       // ship is arriving. In other words, doing warp in effect, stage 1
432 #define SF_ARRIVING_STAGE_2             (1 << 25)       // ship is arriving. In other words, doing warp in effect, stage 2
433 #define  SF_ARRIVING             (SF_ARRIVING_STAGE_1|SF_ARRIVING_STAGE_2)
434 #define SF_ENGINES_ON                           (1 << 24)       // engines sound should play if set
435 #define SF_INITIALLY_DOCKED             (1 << 23)       // used by Fred to tell if this ship is initially docked with something else
436 #define SF_CARGO_REVEALED                       (1 << 22)       // ship's cargo is revealed to all friendly ships
437 #define SF_FROM_PLAYER_WING             (1      << 21)  // set for ships that are members of any player starting wing
438 #define SF_PRIMARY_LINKED                       (1 << 20)       // ships primary weapons are linked together
439 #define SF_SECONDARY_DUAL_FIRE  (1 << 19)       // ship is firing two missiles from the current secondary bank
440 #define SF_WARP_BROKEN                          (1      << 18)  // set when warp drive is not working, but is repairable
441 #define SF_WARP_NEVER                           (1      << 17)  // set when ship can never warp
442 #define SF_TRIGGER_DOWN                 (1 << 16)       // ship has its "trigger" held down
443 #define SF_AMMO_COUNT_RECORDED  (1      <<      15)     // we've recorded the inital secondary weapon count (which is used to limit support ship rearming)
444 #define SF_HIDDEN_FROM_SENSORS  (1      << 14)  // ship doesn't show up on sensors, blinks in/out on radar
445 #define SF_SCANNABLE                            (1      << 13)  // ship is "scannable".  Play scan effect and report as "Scanned" or "not scanned".
446 #define SF_WARPED_SUPPORT                       (1 << 12)       // set when this is a support ship which was warped in automatically
447 #define SF_EXPLODED                                     (1 << 11)       // ship has exploded (needed for kill messages)
448 #define SF_SHIP_HAS_SCREAMED            (1 << 10)       // ship has let out a death scream
449 #define SF_RED_ALERT_STORE_STATUS (1 << 9)      // ship status should be stored/restored if red alert mission
450 #define SF_VAPORIZE                                     (1<<8)          // ship is vaporized by beam - alternative death sequence
451
452 // MWA -- don't go below whatever bitfield is used for Fred above (currently 7)!!!!
453
454 #define SF_DEPARTING                            (SF_DEPART_WARP | SF_DEPART_DOCKBAY)                            // ship is departing
455 #define SF_CANNOT_WARP                          (SF_WARP_BROKEN | SF_WARP_NEVER | SF_DISABLED)  // ship cannot warp out
456
457 #define MAX_DAMAGE_SLOTS        32
458 #define MAX_SHIP_ARCS           2               // How many "arcs" can be active at once... Must be less than MAX_ARC_EFFECTS in model.h. 
459 #define NUM_SUB_EXPL_HANDLES    2       // How many different big ship sub explosion sounds can be played.
460
461 #define MAX_SHIP_CONTRAILS              6
462
463 typedef struct ship_spark {
464         vector pos;                     // position of spark in the submodel's RF
465         int submodel_num;       // which submodel is making the spark
466         int end_time;
467 } ship_spark;
468
469 #define AWACS_WARN_NONE         (1 << 0)
470 #define AWACS_WARN_25           (1 << 1)
471 #define AWACS_WARN_75           (1 << 2)
472
473
474 typedef struct ship {
475         int     objnum;
476         int     ai_index;                       // Index in Ai_info of ai_info associated with this ship.
477         int     ship_info_index;        // Index in ship_info for this ship
478         int     modelnum;       
479         int     hotkey;
480         int     escort_priority;
481         int     score;
482         int     respawn_priority;
483         
484         // BEGIN PACK ubytes and chars
485         ubyte   pre_death_explosion_happened;           // If set, it means the 4 or 5 smaller explosions 
486         ubyte wash_killed;
487         char    cargo1;
488
489         // ship wing status info
490         char    wing_status_wing_index;                 // wing index (0-4) in wingman status gauge
491         char    wing_status_wing_pos;                   // wing position (0-5) in wingman status gauge
492
493         // alternate type name index
494         char alt_type_index;                                                            // only used for display purposes (read : safe)
495
496         // targeting laser info
497         char targeting_laser_bank;                                              // -1 if not firing, index into polymodel gun points if it _is_ firing
498         // corkscrew missile stuff
499         ubyte num_corkscrew_to_fire;                                            // # of corkscrew missiles lef to fire
500         // END PACK
501         // targeting laser info
502         int targeting_laser_objnum;                                     // -1 if invalid, beam object # otherwise
503         // corkscrew missile stuff
504         int next_corkscrew_fire;                                                // next time to fire a corkscrew missile
505
506         int     final_death_time;                               // Time until big fireball starts
507         int     really_final_death_time;        // Time until ship breaks up and disappears
508         vector  deathroll_rotvel;                       // Desired death rotational velocity
509         int     dock_objnum_when_dead;          // Objnum of ship docked to when ship died (-1 if none)
510         int     final_warp_time;        // pops when ship is completely warped out or warped in.  Used for both warp in and out.
511         vector  warp_effect_pos;                // where the warp in effect comes in at
512         vector  warp_effect_fvec;               // The warp in effect's forward vector
513         int     next_fireball;
514
515         int     next_hit_spark;
516         int     num_hits;                       //      Note, this is the number of spark emitter positions!
517         ship_spark      sparks[MAX_SHIP_HITS];
518
519         int     special_exp_index;      
520
521         char    ship_name[NAME_LENGTH];
522
523         int     team;                           //      Which team it's on, HOSTILE, FRIENDLY, UNKNOWN, NEUTRAL
524         
525         fix     time_cargo_revealed;                                    // time at which the cargo was revealed
526
527         int     arrival_location;
528         int     arrival_distance;                                               // how far away this ship should arrive
529         int     arrival_anchor;         // name of object this ship arrives near (or in front of)
530         int     arrival_cue;
531         int     arrival_delay;
532         int     departure_location;     // depart to hyperspace or someplace else (like docking bay)
533         int     departure_anchor;               // when docking day -- index of ship to use
534         int     departure_cue;                  // sexpression to eval when departing
535         int     departure_delay;                // time in seconds after sexp is true that we delay.
536         int     determination;
537         int     wingnum;                                                                // wing number this ship is in.  -1 if in no wing, Wing array index otherwise
538         int     orders_accepted;                                        // set of orders this ship will accept from the player.
539
540         // Subsystem fields.  The subsys_list is a list of all subsystems (which might include multiple types
541         // of a particular subsystem, like engines).  The subsys_info struct is information for particular
542         // types of subsystems.  (i.e. the list might contain 3 engines.  There will be one subsys_info entry
543         // describing the state of all engines combined) -- MWA 4/1/97
544         ship_subsys     subsys_list;                                                                    //      linked list of subsystems for this ship.
545         ship_subsys     *last_targeted_subobject[MAX_PLAYERS];  // Last subobject that has been targeted.  NULL if none;(player specific)
546         ship_subsys_info        subsys_info[SUBSYSTEM_MAX];             // info on particular generic types of subsystems       
547
548         float   *shield_integrity;                                      //      Integrity at each triangle in shield mesh.
549
550         // ETS fields
551         int     shield_recharge_index;                  // index into array holding the shield recharge rate
552         int     weapon_recharge_index;                  // index into array holding the weapon recharge rate
553         int     engine_recharge_index;                  // index into array holding the engine recharge rate
554         float   weapon_energy;                                          // Number of EUs in energy reserves
555         float   current_max_speed;                              // Max ship speed (based on energy diverted to engines)
556         int     next_manage_ets;                                        // timestamp for when ai can next modify ets ( -1 means never )
557
558         uint    flags;                                                          // flag variable to contain ship state (see SF_ #defines)
559         int     reinforcement_index;                            // index into reinforcement struct or -1
560         
561         float   afterburner_fuel;                                       // amount of afterburner fuel remaining (capacity is stored
562                                                                                                         // as afterburner_fuel_capacity in ship_info).
563
564         int cmeasure_count;                                             //      Number of charges of countermeasures this ship can hold.
565         int current_cmeasure;                                   //      Currently selected countermeasure.
566
567         int cmeasure_fire_stamp;                                //      Time at which can fire countermeasure.
568
569         float   target_shields_delta;                   //      Target for shield recharge system.
570         float   target_weapon_energy_delta;     //      Target for recharge system.
571         ship_weapon     weapons;
572
573         int     shield_hits;                                            //      Number of hits on shield this frame.
574
575         float           wash_intensity;
576         vector  wash_rot_axis;
577         int             wash_timestamp;
578
579         // store blast information about shockwaves that hit the ship
580 //      ship_shockwave  sw;
581
582         int     num_swarm_missiles_to_fire;     // number of swarm missiles that need to be launched
583         int     next_swarm_fire;                                        // timestamp of next swarm missile to fire
584         int     next_swarm_path;                                        // next path number for swarm missile to take
585         int     num_turret_swarm_info;                  // number of turrets in process of launching swarm
586
587         int     group;                                                          // group ship is in, or -1 if none.  Fred thing
588         int     death_roll_snd;                                 // id of death roll sound, may need to be stopped early 
589         int     ship_list_index;                                        // index of ship in Ship_objs[] array
590
591         int     thruster_bitmap;                                        // What frame the current thruster bitmap is at for this ship
592         float   thruster_frame;                                 // Used to keep track of which frame the animation should be on.
593
594         int     thruster_glow_bitmap;                   // What frame the current thruster engine glow bitmap is at for this ship
595         float   thruster_glow_frame;                            // Used to keep track of which frame the engine glow animation should be on.
596         float   thruster_glow_noise;                            // Noise for current frame
597
598         int     next_engine_stutter;                            // timestamp to time the engine stuttering when a ship dies
599
600         float total_damage_received;        // total damage received (for scoring purposes)
601         float damage_ship[MAX_DAMAGE_SLOTS];    // damage applied from each player
602         int   damage_ship_id[MAX_DAMAGE_SLOTS]; // signature of the damager (corresponds to each entry in damage_ship)
603         int     persona_index;                                          // which persona is this guy.
604
605         int     subsys_disrupted_flags;                                 // bitflags used to check if SUBYSTEM_* is disrupted or not
606         int     subsys_disrupted_check_timestamp;       // timer to control how oftern flags are set/cleared in subsys_disrupted_flags
607
608         uint    create_time;                                            // time ship was created, set by gettime()
609
610         // keep multiplayer specific stuff below this point     
611         int     ts_index;                                                       // index into the team select and Wss_slots array (or -1 if not in one of those arrays)
612
613         int     large_ship_blowup_index;                        // -1 if not a large ship exploding, else this is an index used by the shipfx large ship exploding code.
614         int     sub_expl_sound_handle[NUM_SUB_EXPL_HANDLES];
615
616
617         // Stuff for showing electrical arcs on damaged ships
618         vector  arc_pts[MAX_SHIP_ARCS][2];                      // The endpoints of each arc
619         int             arc_timestamp[MAX_SHIP_ARCS];           // When this times out, the spark goes away.  -1 is not used
620         ubyte           arc_type[MAX_SHIP_ARCS];                        // see MARC_TYPE_* defines in model.h
621         int             arc_next_time;                                                  // When the next arc will be created.   
622
623         // emp missile stuff
624         float emp_intensity;                                                            // <= 0.0f if no emp effect present
625         float emp_decr;                                                                 // how much to decrement EMP effect per second for this ship
626
627         // contrail stuff
628         short trail_num[MAX_SHIP_CONTRAILS];    
629
630         // tag stuff
631         float tag_total;                                                                        // total tag time
632         float tag_left;                                                                 // total tag remaining  
633         fix     time_first_tagged;
634         float level2_tag_total;                                                 // total tag time
635         float level2_tag_left;                                                  // total tag remaining  
636
637         // old-style object update stuff
638         np_update               np_updates[MAX_PLAYERS];        // for both server and client
639
640         // lightning timestamp
641         int lightning_stamp;
642
643         // AWACS warning flag
644         ubyte   awacs_warning_flag;
645
646         // Special warpout objnum (warpout at knossos)
647         int special_warp_objnum;
648 } ship;
649
650 // structure and array def for ships that have exited the game.  Keeps track of certain useful
651 // information.
652 #define SEF_DESTROYED                   (1<<0)
653 #define SEF_DEPARTED                            (1<<1)
654 #define SEF_CARGO_KNOWN                 (1<<2)
655 #define SEF_PLAYER_DELETED              (1<<3)                  // ship deleted by a player in ship select
656 #define SEF_BEEN_TAGGED                 (1<<4)
657 #define SEF_RED_ALERT_CARRY     (1<<5)
658
659 #define MAX_EXITED_SHIPS        200
660
661 typedef struct exited_ship {
662         char            ship_name[NAME_LENGTH];
663         int             obj_signature;
664         int             team;
665         int             flags;
666         fix             time;
667         int             hull_strength;
668 } exited_ship;
669
670 extern exited_ship Ships_exited[MAX_EXITED_SHIPS];
671
672 // a couple of functions to get at the data
673 extern void ship_add_exited_ship( ship *shipp, int reason );
674 extern int ship_find_exited_ship_by_name( char *name );
675 extern int ship_find_exited_ship_by_signature( int signature);
676
677 #define SIF_DO_COLLISION_CHECK  (1 << 0)
678 #define SIF_PLAYER_SHIP                 (1 << 1)
679 #define SIF_DEFAULT_PLAYER_SHIP (1 << 2)
680 #define SIF_PATH_FIXUP                          (1 << 3)                // when set, path verts have been set for this ship's model
681 #define SIF_SUPPORT                                     (1 << 4)                // this ship can perform repair/rearm functions
682 #define SIF_AFTERBURNER                 (1 << 5)                // this ship has afterburners
683
684 // If you add a new ship type, then please add the appriopriate type in the ship_count
685 // structure later in this file!!! and let MWA know!!
686 #define SIF_CARGO                                       (1 << 6)                // is this ship a cargo type ship -- used for docking purposes
687 #define SIF_FIGHTER                                     (1 << 7)                // this ship is a fighter
688 #define SIF_BOMBER                                      (1 << 8)                // this ship is a bomber
689 #define SIF_CRUISER                                     (1 << 9)                // this ship is a cruiser
690 #define SIF_FREIGHTER                           (1 << 10)       // this ship is a freighter
691 #define SIF_CAPITAL                                     (1 << 11)       // this ship is a capital/installation ship
692 #define SIF_TRANSPORT                           (1 << 12)       // this ship is a transport
693 #define SIF_NAVBUOY                                     (1      << 13)  // AL 11-24-97: this is a navbuoy
694 #define SIF_SENTRYGUN                           (1      << 14)  // AL 11-24-97: this is a navbuoy with turrets
695 #define SIF_ESCAPEPOD                           (1 << 15)       // AL 12-09-97: escape pods that fire from big ships
696 #define SIF_NO_SHIP_TYPE                        (1 << 16)       // made distinct to help trap errors
697
698 #define SIF_SHIP_COPY                           (1 << 17)       // this ship is a copy of another ship in the table -- meaningful for scoring and possible other things
699 #define SIF_IN_TECH_DATABASE            (1 << 18)       // is ship type to be listed in the tech database?
700 #define SIF_IN_TECH_DATABASE_M  (1 << 19)       // is ship type to be listed in the tech database for multiplayer?
701
702 #define SIF_STEALTH                                     (1 << 20)       // the ship is a stealth ship
703 #define SIF_SUPERCAP                            (1 << 21)       // the ship is a supercap
704 #define SIF_DRYDOCK                                     (1 << 22)       // the ship is a drydock
705 #define SIF_DONT_COLLIDE_INVIS  (1 << 23)       // Don't collide with this ship's invisible polygons
706
707 #define SIF_BIG_DAMAGE                          (1 << 24)       // this ship is classified as a big damage ship
708 #define SIF_HAS_AWACS                           (1 << 25)       // ship has an awacs subsystem
709
710 #define SIF_CORVETTE                            (1 << 26)       // corvette class (currently this only means anything for briefing icons)
711 #define SIF_GAS_MINER                           (1 << 27)       // also just for briefing icons
712 #define SIF_AWACS                                       (1 << 28)       // ditto
713
714 #define SIF_KNOSSOS_DEVICE              (1 << 29)       // this is the knossos device
715
716 #define SIF_NO_FRED                                     (1 << 30)       // not available in fred
717
718 #define MAX_SHIP_FLAGS  8               //      Number of flags for flags field in ship_info struct
719 #define SIF_DEFAULT_VALUE                       (SIF_DO_COLLISION_CHECK)
720 #define SIF_ALL_SHIP_TYPES              (SIF_CARGO | SIF_FIGHTER | SIF_BOMBER | SIF_CRUISER | SIF_FREIGHTER | SIF_CAPITAL | SIF_TRANSPORT | SIF_SUPPORT | SIF_NO_SHIP_TYPE | SIF_NAVBUOY | SIF_SENTRYGUN | SIF_ESCAPEPOD | SIF_SUPERCAP | SIF_CORVETTE | SIF_GAS_MINER | SIF_AWACS | SIF_KNOSSOS_DEVICE)
721 #define SIF_SMALL_SHIP                          (SIF_FIGHTER | SIF_BOMBER | SIF_SUPPORT | SIF_ESCAPEPOD )
722 #define SIF_BIG_SHIP                            (SIF_CRUISER | SIF_FREIGHTER | SIF_TRANSPORT | SIF_CORVETTE | SIF_GAS_MINER | SIF_AWACS)
723 #define SIF_HUGE_SHIP                           (SIF_CAPITAL | SIF_SUPERCAP | SIF_DRYDOCK | SIF_KNOSSOS_DEVICE)
724 #define SIF_NOT_FLYABLE                 (SIF_CARGO | SIF_NAVBUOY | SIF_SENTRYGUN)               // AL 11-24-97: this useful to know for targeting reasons
725 #define SIF_HARMLESS                            (SIF_CARGO | SIF_NAVBUOY | SIF_ESCAPEPOD)               // AL 12-3-97: ships that are not a threat
726 // for ships of this type, we make beam weapons miss a little bit otherwise they'd be way too powerful
727 #define SIF_BEAM_JITTER                 (SIF_CARGO | SIF_FIGHTER | SIF_BOMBER | SIF_FREIGHTER | SIF_TRANSPORT | SIF_SENTRYGUN | SIF_NAVBUOY | SIF_ESCAPEPOD)
728
729 // defines for ship types.  These defines are distinct from the flag values in the ship_info struct.  These
730 // values are used for array lookups, etc.
731 #define MAX_SHIP_TYPE_COUNTS                            20
732
733 #define SHIP_TYPE_NONE                                          0
734 #define SHIP_TYPE_CARGO                                         1
735 #define SHIP_TYPE_FIGHTER_BOMBER                        2
736 #define SHIP_TYPE_CRUISER                                       3
737 #define SHIP_TYPE_FREIGHTER                             4
738 #define SHIP_TYPE_CAPITAL                                       5
739 #define SHIP_TYPE_TRANSPORT                             6
740 #define SHIP_TYPE_REPAIR_REARM                  7
741 #define SHIP_TYPE_NAVBUOY                                       8
742 #define SHIP_TYPE_SENTRYGUN                             9
743 #define SHIP_TYPE_ESCAPEPOD                             10
744 #define SHIP_TYPE_SUPERCAP                                      11
745 #define SHIP_TYPE_STEALTH                                       12
746 #define SHIP_TYPE_FIGHTER                                       13
747 #define SHIP_TYPE_BOMBER                                        14
748 #define SHIP_TYPE_DRYDOCK                                       15
749 #define SHIP_TYPE_AWACS                                         16
750 #define SHIP_TYPE_GAS_MINER                             17
751 #define SHIP_TYPE_CORVETTE                                      18
752 #define SHIP_TYPE_KNOSSOS_DEVICE                        19
753
754 // The real FreeSpace ship_info struct.
755 typedef struct ship_info {
756         char            name[NAME_LENGTH];                              // name for the ship
757         char            short_name[NAME_LENGTH];                // short name, for use in the editor?
758         int             species;                                                                // which species this craft belongs to
759         char            *type_str;                                                      // type string used by tooltips
760         char            *maneuverability_str;                   // string used by tooltips
761         char            *armor_str;                                                     // string used by tooltips
762         char            *manufacturer_str;                              // string used by tooltips
763         char            *desc;                                                          // string used by tooltips
764         char            *tech_desc;                                                     // string used by tech database
765
766         char     *ship_length;                                          // string used by multiplayer ship desc
767         char     *gun_mounts;                            // string used by multiplayer ship desc
768         char     *missile_banks;                                        // string used by multiplayer ship desc
769
770         char            pof_file[NAME_LENGTH];                  // POF file to load/associate with ship
771         char            pof_file_hud[NAME_LENGTH];              // POF file to load for the HUD target box
772         int             num_detail_levels;                              // number of detail levels for this ship
773         int             detail_distance[MAX_SHIP_DETAIL_LEVELS];                                        // distance to change detail levels at
774         int             modelnum;                                                       // ship model
775         int             modelnum_hud;                                           // model to use when rendering to the HUD (eg, mini supercap)
776         float           density;                                                                // density of the ship in g/cm^3 (water  = 1)
777         float           damp;                                                                   // drag
778         float           rotdamp;                                                                // rotational drag
779         vector  max_vel;                                                                //      max velocity of the ship in the linear directions -- read from ships.tbl
780         vector  afterburner_max_vel;                            //      max velocity of the ship in the linear directions when afterburners are engaged -- read from ships.tbl
781         vector  max_rotvel;                                                     // maximum rotational velocity
782         vector  rotation_time;                                          // time to rotate in x/y/z dimension traveling at max rotvel
783         float           srotation_time;                                 //      scalar, computed at runtime as (rotation_time.x + rotation_time.y)/2
784         float           max_rear_vel;                                           // max speed ship can go backwards.
785         float           forward_accel;
786         float           afterburner_forward_accel;              // forward acceleration with afterburner engaged
787         float           forward_decel;
788         float           slide_accel;
789         float           slide_decel;
790         int             flags;                                                          //      See SIF_xxxx
791         int             ai_class;                                                       //      Index into Ai_classes[].  Defined in ai.tbl
792         float           shields;
793         float           max_speed, min_speed, max_accel;
794
795         // ship explosion info
796         float inner_rad;                                                                // radius within which maximum damage is applied
797         float   outer_rad;                                                              // radius at which no damage is applied
798         float damage;                                                                   // maximum damage applied from ship explosion
799         float blast;                                                                    // maximum blast impulse from ship explosion                                                                    
800         int     explosion_propagates;                           // If true, then the explosion propagates
801         float   shockwave_speed;                                                // speed at which shockwave expands, 0 means no shockwave
802         int     shockwave_count;                                                // the # of total shockwaves
803
804         // subsystem information
805         int             n_subsystems;                                           // this number comes from ships.tbl
806         model_subsystem *subsystems;                            // see model.h for structure definition
807
808         // Energy Transfer System fields
809         float           power_output;                                           // power output of ships reactor (EU/s)
810         float           max_overclocked_speed;                  // max speed when 100% power output sent to engines
811         float           max_weapon_reserve;                             // maximum energy that can be stored for primary weapon usage
812
813         // Afterburner fields
814         float           afterburner_fuel_capacity;              // maximum afterburner fuel that can be stored
815         float           afterburner_burn_rate;                  // rate in fuel/second that afterburner consumes fuel
816         float           afterburner_recover_rate;               //      rate in fuel/second that afterburner recovers fuel
817
818         int             cmeasure_max;                                           //      Number of charges of countermeasures this ship can hold.
819
820         int num_primary_banks;                                                                          // Actual number of primary banks (property of model)
821         int num_secondary_banks;                                                                        //      Actual number of secondary banks (property of model)
822         int primary_bank_weapons[MAX_PRIMARY_BANKS];                    // Weapon_info[] index for the weapon in the bank
823         int secondary_bank_weapons[MAX_SECONDARY_BANKS];        // Weapon_info[] index for the weapon in the bank
824         int secondary_bank_ammo_capacity[MAX_SECONDARY_BANKS];  // Capacity of bank (not number of missiles)
825
826         float   initial_hull_strength;                  // Initial hull strength of this class of ship.
827         int engine_snd;                                                 // handle to engine sound for ship (-1 if no engine sound)
828
829         vector  closeup_pos;                                    // position for camera when using ship in closeup view (eg briefing and hud target monitor)
830         float           closeup_zoom;                                   // zoom when using ship in closeup view (eg briefing and hud target monitor)
831
832         int             allowed_weapons[MAX_WEAPON_TYPES];                      // array which specifies which weapons can be loaded out by the
833                                                                                                                                                 // player during weapons loadout.
834
835         ubyte   shield_icon_index;                              // index to locate ship-specific animation frames for the shield on HUD
836         char    icon_filename[NAME_LENGTH];     // filename for icon that is displayed in ship selection
837         char    anim_filename[NAME_LENGTH];     // filename for animation that plays in ship selection
838         char    overhead_filename[NAME_LENGTH]; // filename for animation that plays weapons loadout
839
840         int     score;                                                          // default score for this ship
841
842         int     scan_time;                                                      // time to scan this ship (in ms)
843
844         // contrail info
845         trail_info ct_info[MAX_SHIP_CONTRAILS]; 
846         int ct_count;
847
848         // rgb non-dimming pixels for this ship type
849         int num_nondark_colors;
850         ubyte nondark_colors[MAX_NONDARK_COLORS][3];
851
852         // rgb shield color
853         ubyte shield_color[3];
854 } ship_info;
855
856 extern int num_wings;
857 extern ship Ships[MAX_SHIPS];
858 extern ship     *Player_ship;
859
860 // Data structure to track the active missiles
861 typedef struct ship_obj {
862         ship_obj                 *next, *prev;
863         int                     flags, objnum;
864 } ship_obj;
865 extern ship_obj Ship_obj_list;
866
867 typedef struct engine_wash_info
868 {
869         char            name[32];
870         float           angle;                  // half angle of cone around engine thruster
871         float           radius_mult;    // multiplier for radius 
872         float           length;                 // length of engine wash, measured from thruster
873         float           intensity;              // intensity of engine wash
874 } engine_wash_info;
875
876 #define MAX_ENGINE_WASH_TYPES   20
877 extern engine_wash_info Engine_wash_info[MAX_ENGINE_WASH_TYPES];
878
879 // ****************************************************************
880 // DO NOT CHANGE THIS - IT WILL LIKELY BREAK FREESPACE2 PXO SUPPORT
881 // TALK TO DAVE B FIRST
882 // ****************************************************************
883 #define MAX_SHIP_TYPES          130
884
885 #define MAX_SHIPS_PER_WING      6
886
887 #ifdef FS2_DEMO
888         #define MAX_WINGS                               15
889 #else
890         #define MAX_WINGS                               25
891 #endif
892
893 #define MAX_PLAYER_WINGS        3  // number of wings player can start a mission with
894
895 // flags defined for wings
896 #define MAX_WING_FLAGS                          8                               // total number of flags in the wing structure -- used for parsing wing flags
897 #define WF_WING_GONE                                    (1<<0)          // all ships were either destroyed or departed
898 #define WF_WING_DEPARTING                       (1<<1)          // wing's departure cue turned true
899 #define WF_IGNORE_COUNT                         (1<<2)          // ignore all ships in this wing for goal counting purposes.
900 #define WF_REINFORCEMENT                        (1<<3)          // is this wing a reinforcement wing
901 #define WF_RESET_REINFORCEMENT  (1<<4)          // needed when we need to reset the wing's reinforcement flag (after calling it in)
902 #define WF_NO_ARRIVAL_MUSIC             (1<<5)          // don't play arrival music when wing arrives
903 #define WF_EXPANDED                                     (1<<6)          // wing expanded in hotkey select screen
904 #define WF_NO_ARRIVAL_MESSAGE           (1<<7)          // don't play any arrival message
905 #define WF_NO_ARRIVAL_WARP                      (1<<8)          // don't play warp effect for any arriving ships in this wing.
906 #define WF_NO_DEPARTURE_WARP            (1<<9)          // don't play warp effect for any departing ships in this wing.
907 #define WF_NO_DYNAMIC                           (1<<10)         // members of this wing relentlessly pursue their ai goals
908 #define WF_DEPARTURE_ORDERED            (1<<11)         // departure of this wing was ordered by player
909 #define WF_NEVER_EXISTED                        (1<<12)         // this wing never existed because something prevented it from being created (like its mother ship being destroyed)
910
911 //      Defines a wing of ships.
912 typedef struct wing {
913         char    name[NAME_LENGTH];
914         int     reinforcement_index;                                    // index in reinforcement struct or -1
915         int     hotkey;
916
917         int     num_waves, current_wave;                        // members for dealing with waves
918         int     threshold;                                                              // when number of ships in the wing reaches this number -- new wave
919
920         fix     time_gone;                                                              // time into the mission when this wing is officiall gone.
921
922         int     wave_count;                                                             // max ships per wave (as defined by the number of ships in the ships list)
923         int     total_arrived_count;                                    // count of number of ships that we have created, regardless of wave
924         int     current_count;                                                  // count of number of ships actually in this wing -- used for limit in next array
925         int     ship_index[MAX_SHIPS_PER_WING]; // index into ships array of all ships currently in the wing
926
927         int     total_destroyed;                                                // total number of ships destroyed in the wing (including all waves)
928         int     total_departed;                                         // total number of ships departed in this wing (including all waves)
929
930         int     special_ship;                                                   // the leader of the wing.  An index into ship_index[].
931
932         int     arrival_location;                                               // arrival and departure information for wings -- similar to info for ships
933         int     arrival_distance;                                               // distance from some ship where this ship arrives
934         int     arrival_anchor;                                         // name of object this ship arrives near (or in front of)
935         int     arrival_cue;
936         int     arrival_delay;
937
938         int     departure_location;
939         int     departure_anchor;                                               // name of object that we depart to (in case of dock bays)
940         int     departure_cue;
941         int     departure_delay;
942
943         int     wave_delay_min;                                         // minimum number of seconds before new wave can arrive
944         int     wave_delay_max;                                         // maximum number of seconds before new wave can arrive
945         int     wave_delay_timestamp;                           // timestamp used for delaying arrival of next wave
946
947         int flags;
948
949         ai_goal ai_goals[MAX_AI_GOALS];                 // goals for the wing -- converted to ai_goal struct
950
951         ushort  net_signature;                                          // starting net signature for ships in this wing. assiged at mission load time
952
953 } wing;
954
955 #define STARTING_WING_ALPHA             0
956 #define STARTING_WING_BETA                      1
957 #define STARTING_WING_GAMMA             2
958 #define STARTING_WING_ZETA                      3
959
960 extern wing Wings[MAX_WINGS];
961 extern int Starting_wings[MAX_PLAYER_WINGS];
962 extern int ai_paused;
963
964 extern int Num_reinforcements;
965 extern int Num_ship_types;
966 extern ship_info Ship_info[MAX_SHIP_TYPES];
967 extern reinforcements Reinforcements[MAX_REINFORCEMENTS];
968
969 // structure definition for ship type counts.  Used to give a count of the number of ships
970 // of a particular type, and the number of times that a ship of that particular type has been
971 // killed.  When changing any info here, be sure to update the ship_type_names array in Ship.cpp
972 // the order of the types here MUST match the order of the types in the array
973 typedef struct ship_counts {
974         int     total;
975         int     killed;
976 } ship_counts;
977
978 extern char *Ship_type_names[MAX_SHIP_TYPE_COUNTS];
979 extern int Ship_type_flags[MAX_SHIP_TYPE_COUNTS];                                       // SIF_* flags for each ship type
980 extern ship_counts      Ship_counts[MAX_SHIP_TYPE_COUNTS];
981
982
983 // Use the below macros when you want to find the index of an array element in the
984 // Wings[] or Ships[] arrays.
985 #define WING_INDEX(wingp) (wingp-Wings)
986 #define SHIP_INDEX(shipp) (shipp-Ships)
987
988
989 extern void ship_init();                                // called once  at game start
990 extern void ship_level_init();          // called before the start of each level
991
992 //returns -1 if failed
993 extern int ship_create(matrix * orient, vector * pos, int ship_type);
994 extern void change_ship_type(int n, int ship_type);
995 extern void ship_model_change(int n, int ship_type);
996 extern void ship_process_pre( object * objp, float frametime );
997 extern void ship_process_post( object * objp, float frametime );
998 extern void ship_render( object * objp );
999 extern void ship_delete( object * objp );
1000 extern int ship_check_collision_fast( object * obj, object * other_obj, vector * hitpos );
1001 extern int ship_get_num_ships();
1002
1003 extern int ship_fire_primary_debug(object *objp);       //      Fire the debug laser.
1004 extern int ship_fire_primary(object * objp, int stream_weapons, int force = 0);
1005 extern int ship_fire_secondary(object * objp, int allow_swarm = 0 );
1006 extern int ship_launch_countermeasure(object *objp, int rand_val = -1);
1007
1008 // for special targeting lasers
1009 extern void ship_start_targeting_laser(ship *shipp);
1010 extern void ship_stop_targeting_laser(ship *shipp);
1011 extern void ship_process_targeting_lasers();
1012
1013 extern int ship_select_next_primary(object *objp, int direction);
1014 extern int  ship_select_next_secondary(object *objp);
1015 extern int get_available_secondary_weapons(object *objp, int *outlist, int *outbanklist);
1016 extern void ship_recalc_subsys_strength( ship *shipp );
1017 extern void subsys_set(int objnum, int ignore_subsys_info = 0);
1018 extern void physics_ship_init(object *objp);
1019
1020 //      Note: This is not a general purpose routine.
1021 //      It is specifically used for targeting.
1022 //      It only returns a subsystem position if it has shields.
1023 //      Return true/false for subsystem found/not found.
1024 //      Stuff vector *pos with absolute position.
1025 extern int get_subsystem_pos(vector *pos, object *objp, ship_subsys *subsysp);
1026
1027 extern int ship_info_lookup(char *name);
1028 extern int ship_info_base_lookup(int si_index);
1029 extern int ship_name_lookup(char *name, int inc_players = 0);   // returns the index into Ship array of name
1030 extern int ship_type_name_lookup(char *name);
1031
1032 extern int wing_lookup(char *name);
1033
1034 // returns 0 if no conflict, 1 if conflict, -1 on some kind of error with wing struct
1035 extern int wing_has_conflicting_teams(int wing_index);
1036
1037 // next function takes optional second parameter which says to ignore the current count of ships
1038 // in the wing -- used to tell is the wing exists or not, not whether it exists and has ships currently
1039 // present.
1040 extern int wing_name_lookup(char *name, int ignore_count = 0);
1041
1042 extern int Player_ship_class;
1043
1044 #define MAX_PLAYER_SHIP_CHOICES 15
1045 extern int Num_player_ship_precedence;                          // Number of ship types in Player_ship_precedence
1046 extern int Player_ship_precedence[MAX_PLAYER_SHIP_CHOICES];     // Array of ship types, precedence list for player ship/wing selection
1047
1048
1049 //      Do the special effect for energy dissipating into the shield for a hit.
1050 //      model_num       = index in Polygon_models[]
1051 //      centerp         = pos of object, sort of the center of the shield
1052 //      tcp                     = hit point, probably the global hit_point set in polygon_check_face
1053 //      tr0                     = index of polygon in shield pointer in polymodel.
1054 extern void create_shield_explosion(int objnum, int model_num, matrix *orient, vector *centerp, vector *tcp, int tr0);
1055
1056 //      Initialize shield hit system.
1057 extern void shield_hit_init();
1058 extern void create_shield_explosion_all(object *objp);
1059 extern void shield_frame_init();
1060 extern void add_shield_point(int objnum, int tri_num, vector *hit_pos);
1061 extern void add_shield_point_multi(int objnum, int tri_num, vector *hit_pos);
1062 extern void shield_point_multi_setup();
1063 extern void shield_hit_close();
1064
1065 void ship_draw_shield( object *objp);
1066
1067 float apply_damage_to_shield(object *objp, int shield_quadrant, float damage);
1068 float compute_shield_strength(object *objp);
1069
1070 // Returns true if the shield presents any opposition to something 
1071 // trying to force through it.
1072 // If quadrant is -1, looks at entire shield, otherwise
1073 // just one quadrant
1074 int ship_is_shield_up( object *obj, int quadrant );
1075
1076 //=================================================
1077 // These two functions transfer instance specific angle
1078 // data into and out of the model structure, which contains
1079 // angles, but not for each instance of model being used. See
1080 // the actual functions in ship.cpp for more details.
1081 extern void ship_model_start(object *objp);
1082 extern void ship_model_stop(object *objp);
1083
1084 //============================================
1085 extern int ship_find_num_crewpoints(object *objp);
1086 extern int ship_find_num_turrets(object *objp);
1087
1088 extern void ship_get_eye( vector *eye_pos, matrix *eye_orient, object *obj );           // returns in eye the correct viewing position for the given object
1089 extern ship_subsys *ship_get_indexed_subsys( ship *sp, int index, vector *attacker_pos = NULL );        // returns index'th subsystem of this ship
1090 extern int ship_get_index_from_subsys(ship_subsys *ssp, int objnum, int error_bypass = 0);
1091 extern int ship_get_subsys_index(ship *sp, char *ss_name, int error_bypass = 0);                // returns numerical index in linked list of subsystems
1092 extern float ship_get_subsystem_strength( ship *shipp, int type );
1093 extern ship_subsys *ship_get_subsys(ship *shipp, char *subsys_name);
1094
1095 // subsys disruption
1096 extern int ship_subsys_disrupted(ship_subsys *ss);
1097 extern int ship_subsys_disrupted(ship *sp, int type);
1098 extern void ship_subsys_set_disrupted(ship_subsys *ss, int time);
1099
1100 extern int      ship_do_rearm_frame( object *objp, float frametime );
1101 extern void     ship_wing_cleanup( int shipnum, wing *wingp );
1102
1103 extern object *ship_find_repair_ship( object *requester );
1104 extern void ship_close();       // called in game_shutdown() to free malloced memory
1105
1106
1107 extern void ship_assign_sound_all();
1108 extern void ship_assign_sound(ship *sp);
1109
1110 extern void ship_add_ship_type_count( int ship_info_flag, int num );
1111 extern void ship_add_ship_type_kill_count( int ship_info_flag );
1112
1113
1114 extern int ship_get_default_orders_accepted( ship_info *sip );
1115 extern int ship_query_general_type(int ship);
1116 extern int ship_query_general_type(ship *shipp);
1117 extern int ship_docking_valid(int docker, int dockee);
1118 extern int get_quadrant(vector *hit_pnt);                                               //      Return quadrant num of last hit ponit.
1119
1120 extern void ship_obj_list_rebuild();    // only called by save/restore code
1121 extern int ship_query_state(char *name);
1122
1123 int ship_secondary_bank_has_ammo(int shipnum);  // check if current secondary bank has ammo
1124
1125 void ship_departed( int num );
1126 int ship_can_warp(ship *sp);            // check if ship has engine power to warp
1127 int ship_return_subsys_path_normal(ship *sp, ship_subsys *ss, vector *gsubpos, vector *norm);
1128 int ship_subsystem_in_sight(object* objp, ship_subsys* subsys, vector *eye_pos, vector* subsys_pos, int do_facing_check=1, float *dot_out=NULL, vector *vec_out=NULL);
1129 ship_subsys *ship_return_next_subsys(ship *shipp, int type, vector *attacker_pos);
1130
1131 // defines and definition for function to get a random ship of a particular team (any ship,
1132 // any ship but player ships, or only players)
1133 #define SHIP_GET_ANY_SHIP                               0
1134 #define SHIP_GET_NO_PLAYERS                     1
1135 #define SHIP_GET_ONLY_PLAYERS                   2
1136
1137 extern int ship_get_random_team_ship( int team, int flags = SHIP_GET_ANY_SHIP, float max_dist=0.0f );
1138 extern int ship_get_random_player_wing_ship( int flags = SHIP_GET_ANY_SHIP, float max_dist=0.0f, int persona_index = -1, int get_first=0, int multi_team = -1 );
1139 extern int ship_get_random_ship_in_wing(int wingnum, int flags = SHIP_GET_ANY_SHIP, float max_dist=0.0f, int get_first=0 );
1140
1141 // return ship index
1142 int ship_get_random_ship();
1143
1144 extern int ship_get_by_signature(int signature);
1145
1146 #ifndef NDEBUG
1147 extern int Ai_render_debug_flag;
1148 extern int Show_shield_mesh, New_shield_system;
1149 extern int Ship_auto_repair;    // flag to indicate auto-repair of subsystem should occur
1150 #endif
1151
1152 void ship_subsystem_delete(ship *shipp);
1153 void ship_set_default_weapons(ship *shipp, ship_info *sip);
1154 float ship_quadrant_shield_strength(object *hit_objp, vector *hitpos);
1155
1156 int ship_dumbfire_threat(ship *sp);
1157 int ship_lock_threat(ship *sp);
1158
1159 int     bitmask_2_bitnum(int num);
1160 char    *ship_return_orders(char *outbuf, ship *sp);
1161 char    *ship_return_time_to_goal(char *outbuf, ship *sp);
1162 void    ship_check_cargo_all(); // called from game_simulation_frame
1163
1164 void    ship_maybe_warn_player(ship *enemy_sp, float dist);
1165 void    ship_maybe_praise_player(ship *deader_sp);
1166 void    ship_maybe_ask_for_help(ship *sp);
1167 void    ship_scream(ship *sp);
1168 void    ship_maybe_scream(ship *sp);
1169 void    ship_maybe_tell_about_rearm(ship *sp);
1170 void    ship_maybe_lament();
1171
1172 void ship_primary_changed(ship *sp);
1173 void ship_secondary_changed(ship *sp);
1174
1175 // get the Ship_info flags for a given ship
1176 int ship_get_SIF(ship *shipp);
1177 int ship_get_SIF(int sh);
1178 extern void ship_do_cargo_revealed( ship *shipp, int from_network = 0 );
1179
1180 float ship_get_secondary_weapon_range(ship *shipp);
1181 int get_max_ammo_count_for_bank(int ship_class, int bank, int ammo_type);
1182
1183 int is_support_allowed(object *objp);
1184
1185 // Given an object and a turret on that object, return the actual firing point of the gun
1186 // and its normal.   This uses the current turret angles.  We are keeping track of which
1187 // gun to fire next in the ship specific info for this turret subobject.  Use this info
1188 // to determine which position to fire from next.
1189 //      Stuffs:
1190 //              *gpos: absolute position of gun firing point
1191 //              *gvec: vector fro *gpos to *targetp
1192 void ship_get_global_turret_gun_info(object *objp, ship_subsys *ssp, vector *gpos, vector *gvec, int use_angles, vector *targetp);
1193
1194 //      Given an object and a turret on that object, return the global position and forward vector
1195 //      of the turret.   The gun normal is the unrotated gun normal, (the center of the FOV cone), not
1196 // the actual gun normal given using the current turret heading.  But it _is_ rotated into the model's orientation
1197 //      in global space.
1198 void ship_get_global_turret_info(object *objp, model_subsystem *tp, vector *gpos, vector *gvec);
1199
1200 // return 1 if objp is in fov of the specified turret, tp.  Otherwise return 0.
1201 //      dist = distance from turret to center point of object
1202 int object_in_turret_fov(object *objp, model_subsystem *tp, vector *tvec, vector *tpos, float dist);
1203
1204 // forcible jettison cargo from a ship
1205 void ship_jettison_cargo(ship *shipp);
1206
1207 // get damage done by exploding ship, takes into account mods for individual ship
1208 float ship_get_exp_damage(object* objp);
1209
1210 // get whether ship has shockwave, takes into account mods for individual ship
1211 int ship_get_exp_propagates(ship *sp);
1212
1213 // get outer radius of damage, takes into account mods for individual ship
1214 float ship_get_exp_outer_rad(object *ship_objp);
1215
1216 // returns whether subsys is allowed to have cargo
1217 int valid_cap_subsys_cargo_list(char *subsys_name);
1218
1219 // determine turret status of a given subsystem, returns 0 for no turret, 1 for "fixed turret", 2 for "rotating" turret
1220 int ship_get_turret_type(ship_subsys *subsys);
1221
1222 // get ship by object signature, returns OBJECT INDEX
1223 int ship_get_by_signature(int sig);
1224
1225 // get the team of a reinforcement item
1226 int ship_get_reinforcement_team(int r_index);
1227
1228 // determine if the given texture is used by a ship type. return ship info index, or -1 if not used by a ship
1229 int ship_get_texture(int bitmap);
1230
1231 // update artillery lock info
1232 void ship_update_artillery_lock();
1233
1234 // checks if a world point is inside the extended bounding box of a ship
1235 int check_world_pt_in_expanded_ship_bbox(vector *world_pt, object *objp, float delta_box);
1236
1237 // returns true if objp is ship and is tagged
1238 int ship_is_tagged(object *objp);
1239
1240 // returns max normal speed of ship (overclocked / afterburned)
1241 float ship_get_max_speed(ship *shipp);
1242
1243 // returns warp speed of ship
1244 float ship_get_warp_speed(object *objp);
1245
1246 // returns true if ship is beginning to speed up in warpout
1247 int ship_is_beginning_warpout_speedup(object *objp);
1248
1249 // given a ship info type, return a species
1250 int ship_get_species_by_type(int ship_info_index);
1251
1252 // return the length of the ship
1253 float ship_get_length(ship* shipp);
1254
1255
1256 #endif
1257