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