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 the
6  * source.
7  *
8 */
9 
10 
11 
12 #ifndef _SHIP_H
13 #define _SHIP_H
14 
15 
16 
17 #include "globalincs/globals.h"		// for defintions of token lengths -- maybe move this elsewhere later (Goober5000 - moved to globals.h)
18 #include "graphics/2d.h"			// for color def
19 #include "model/model.h"
20 #include "model/modelanim.h"
21 #include "palman/palman.h"
22 #include "weapon/trails.h"
23 #include "ai/ai.h"
24 #include "network/multi_obj.h"
25 #include "hud/hudparse.h"
26 #include "render/3d.h"
27 #include "radar/radarsetup.h"
28 #include "weapon/shockwave.h"
29 #include "species_defs/species_defs.h"
30 #include "globalincs/pstypes.h"
31 #include "fireball/fireballs.h"
32 #include "hud/hud.h"
33 
34 #include <string>
35 
36 class object;
37 class WarpEffect;
38 
39 //	Part of the player died system.
40 extern vec3d	Original_vec_to_deader;
41 
42 //	States for player death sequence, stuffed in Player_died_state.
43 #define	PDS_NONE		1
44 #define	PDS_DIED		2
45 #define	PDS_EJECTED	3
46 
47 #define SHIP_GUARDIAN_THRESHOLD_DEFAULT	1	// Goober5000
48 
49 #define	HULL_DAMAGE_THRESHOLD_PERCENT	0.25f	//	Apply damage to hull, not shield if shield < this
50 
51 // the #defines below are to avoid round-off errors
52 #define WEAPON_RESERVE_THRESHOLD		0.01f	// energy threshold where ship is considered to have no weapon energy system
53 #define SUBSYS_MAX_HITS_THRESHOLD		0.01f	// max_hits threshold where subsys is considered to take damage
54 
55 #define	HP_SCALE						1.2			//	1.2 means die when 20% of hits remaining
56 #define	MAX_SHIP_HITS				8				// hits to kill a ship
57 #define	MAX_SHIP_DETAIL_LEVELS	5				// maximum detail levels that a ship can render at
58 #define	MAX_REINFORCEMENTS		32
59 
60 
61 // defines for 'direction' parameter of ship_select_next_primary()
62 #define CYCLE_PRIMARY_NEXT		0
63 #define CYCLE_PRIMARY_PREV		1
64 
65 #define BANK_1		0
66 #define BANK_2		1
67 #define BANK_3		2
68 #define BANK_4		3
69 #define BANK_5		4
70 #define BANK_6		5
71 #define BANK_7		6
72 #define BANK_8		7
73 #define BANK_9		8
74 
75 #define TYPE_ATTACK_PROTECT	0
76 #define TYPE_REPAIR_REARM		1
77 
78 #define MAX_REINFORCEMENT_MESSAGES	5
79 
80 #define RF_IS_AVAILABLE			(1<<0)			// reinforcement is now available
81 
82 typedef struct {
83 	char	name[NAME_LENGTH];	// ship or wing name (ship and wing names don't collide)
84 	int	type;						// what operations this reinforcement unit can perform
85 	int	uses;						// number of times reinforcemnt unit can be used
86 	int	num_uses;				// number of times this reinforcement was actually used
87 	int	arrival_delay;			// how long after called does this reinforcement appear
88 	int	flags;
89 	char	no_messages[MAX_REINFORCEMENT_MESSAGES][NAME_LENGTH];		// list of messages to possibly send when calling for reinforcement not available
90 	char	yes_messages[MAX_REINFORCEMENT_MESSAGES][NAME_LENGTH];	// list of messages to acknowledge reinforcement on the way
91 } reinforcements;
92 
93 // ship weapon flags
94 #define SW_FLAG_BEAM_FREE					(1<<0)							// if this is a beam weapon, its free to fire
95 #define SW_FLAG_TURRET_LOCK				(1<<1)							//	is this turret is free to fire or locked
96 #define SW_FLAG_TAGGED_ONLY				(1<<2)							// only fire if target is tagged
97 
98 typedef struct ship_weapon {
99 	int num_primary_banks;					// Number of primary banks (same as model)
100 	int num_secondary_banks;				// Number of secondary banks (same as model)
101 	int num_tertiary_banks;
102 
103 	int primary_bank_weapons[MAX_SHIP_PRIMARY_BANKS];			// Weapon_info[] index for the weapon in the bank
104 	int secondary_bank_weapons[MAX_SHIP_SECONDARY_BANKS];	// Weapon_info[] index for the weapon in the bank
105 
106 	int current_primary_bank;			// currently selected primary bank
107 	int current_secondary_bank;		// currently selected secondary bank
108 	int current_tertiary_bank;
109 
110 	int previous_primary_bank;
111 	int previous_secondary_bank;		// currently selected secondary bank
112 
113 	int next_primary_fire_stamp[MAX_SHIP_PRIMARY_BANKS];			// next time this primary bank can fire
114 	int last_primary_fire_stamp[MAX_SHIP_PRIMARY_BANKS];			// last time this primary bank fired (mostly used by SEXPs)
115 	int next_secondary_fire_stamp[MAX_SHIP_SECONDARY_BANKS];		// next time this secondary bank can fire
116 	int last_secondary_fire_stamp[MAX_SHIP_SECONDARY_BANKS];		// last time this secondary bank fired (mostly used by SEXPs)
117 	int next_tertiary_fire_stamp;
118 	int last_primary_fire_sound_stamp[MAX_SHIP_PRIMARY_BANKS];		// trailing end of the last time this primary bank was fired, for purposes of timing the pre-launch sound
119 
120 	// ballistic primary support - by Goober5000
121 	int primary_bank_ammo[MAX_SHIP_PRIMARY_BANKS];			// Number of missiles left in primary bank
122 	int primary_bank_start_ammo[MAX_SHIP_PRIMARY_BANKS];	// Number of missiles starting in primary bank
123 	int primary_bank_capacity[MAX_SHIP_PRIMARY_BANKS];		// Max number of projectiles in bank
124 	int primary_next_slot[MAX_SHIP_PRIMARY_BANKS];			// Next slot to fire in the bank
125 	int primary_bank_rearm_time[MAX_SHIP_PRIMARY_BANKS];	// timestamp which indicates when bank can get new projectile
126 	// end ballistic primary support
127 
128 	float primary_bank_fof_cooldown[MAX_SHIP_PRIMARY_BANKS];      // SUSHI: Current FOF cooldown level for the primary weapon
129 
130 	// dynamic weapon linking - by RSAXVC
131 	int primary_bank_slot_count[MAX_SHIP_PRIMARY_BANKS];	// Fire this many slots at a time
132 	// end dynamic weapon linking
133 
134 	int secondary_bank_ammo[MAX_SHIP_SECONDARY_BANKS];			// Number of missiles left in secondary bank
135 	int secondary_bank_start_ammo[MAX_SHIP_SECONDARY_BANKS];	// Number of missiles starting in secondary bank
136 	int secondary_bank_capacity[MAX_SHIP_SECONDARY_BANKS];		// Max number of missiles in bank
137 	int secondary_next_slot[MAX_SHIP_SECONDARY_BANKS];			// Next slot to fire in the bank
138 	int secondary_bank_rearm_time[MAX_SHIP_SECONDARY_BANKS];	// timestamp which indicates when bank can get new missile
139 
140 	int tertiary_bank_ammo;			// Number of shots left tertiary bank
141 	int tertiary_bank_start_ammo;	// Number of shots starting in tertiary bank
142 	int tertiary_bank_capacity;		// Max number of shots in bank
143 	int tertiary_bank_rearm_time;	// timestamp which indicates when bank can get new something (used for ammopod or boostpod)
144 
145 	int last_fired_weapon_index;		//	Index of last fired secondary weapon.  Used for remote detonates.
146 	int last_fired_weapon_signature;	//	Signature of last fired weapon.
147 	int detonate_weapon_time;			//	time at which last fired weapon can be detonated
148 	int ai_class;
149 
150 	int flags;								// see SW_FLAG_* defines above
151 	EModelAnimationPosition primary_animation_position[MAX_SHIP_PRIMARY_BANKS];
152 	EModelAnimationPosition secondary_animation_position[MAX_SHIP_SECONDARY_BANKS];
153 	int primary_animation_done_time[MAX_SHIP_PRIMARY_BANKS];
154 	int  secondary_animation_done_time[MAX_SHIP_SECONDARY_BANKS];
155 
156 	int	burst_counter[MAX_SHIP_PRIMARY_BANKS + MAX_SHIP_SECONDARY_BANKS];
157 	int external_model_fp_counter[MAX_SHIP_PRIMARY_BANKS + MAX_SHIP_SECONDARY_BANKS];
158 
159 	size_t primary_bank_pattern_index[MAX_SHIP_PRIMARY_BANKS];
160 	size_t secondary_bank_pattern_index[MAX_SHIP_SECONDARY_BANKS];
161 } ship_weapon;
162 
163 //**************************************************************
164 //WMC - Damage type handling code
165 
166 int damage_type_add(char *name);
167 
168 //**************************************************************
169 //WMC - Armor stuff
170 
171 // Nuke: some defines for difficulty scaling type
172 #define ADT_DIFF_SCALE_BAD_VAL	-1 // error mode
173 #define ADT_DIFF_SCALE_FIRST	0
174 #define ADT_DIFF_SCALE_LAST		1
175 #define ADT_DIFF_SCALE_MANUAL	2 // this is the user defined mode where the modder has to handle difficulty scaling in their calculations
176 
177 // Nuke: +value: replacing constants
178 // these are stored as altArguments, positive values mean storage idxes and -1 means not used, anything below that is fair game
179 #define AT_CONSTANT_NOT_USED	-1	// will probibly never get used
180 #define AT_CONSTANT_BAD_VAL		-2	// this conveys table error to the user
181 #define AT_CONSTANT_BASE_DMG	-3	// what the damage was at start of calculations
182 #define AT_CONSTANT_CURRENT_DMG	-4	// what the damage currently is
183 #define AT_CONSTANT_DIFF_FACTOR	-5	// difficulty factor (by default 0.2 (easy) to 1.0 (insane))
184 #define AT_CONSTANT_RANDOM		-6	// number between 0 and 1 (redundant but saves a calculation)
185 #define AT_CONSTANT_PI			-7	// because everyone likes pi
186 
187 struct ArmorDamageType
188 {
189 	friend class ArmorType;
190 private:
191 	//Rather than make an extra struct,
192 	//I just made two arrays
193 	int					DamageTypeIndex;
194 	SCP_vector<int>	Calculations;
195 	SCP_vector<float>	Arguments;
196 	SCP_vector<int>		altArguments;		// Nuke: to facilitate optional importation of data in place of +value: tag -nuke
197 	float				shieldpierce_pct;
198 
199 	// piercing effect data
200 	float				piercing_start_pct;
201 	int					piercing_type;
202 	// Nuke: difficulty scale type
203 	int					difficulty_scale_type;
204 
205 public:
206 	void clear();
207 };
208 
209 class ArmorType
210 {
211 private:
212 	char Name[NAME_LENGTH];
213 
214 	SCP_vector<ArmorDamageType> DamageTypes;
215 public:
216 	ArmorType(char* in_name);
217 	int flags;
218 
219 	//Get
GetNamePtr()220 	char *GetNamePtr(){return Name;}
IsName(char * in_name)221 	bool IsName(char *in_name){return (stricmp(in_name,Name)==0);}
222 	float GetDamage(float damage_applied, int in_damage_type_idx, float diff_dmg_scale);
223 	float GetShieldPiercePCT(int damage_type_idx);
224 	int GetPiercingType(int damage_type_idx);
225 	float GetPiercingLimit(int damage_type_idx);
226 
227 	//Set
228 	void ParseData();
229 };
230 
231 extern SCP_vector<ArmorType> Armor_types;
232 
233 //**************************************************************
234 //WMC - Damage type handling code
235 
236 typedef struct DamageTypeStruct
237 {
238 	char name[NAME_LENGTH];
239 } DamageTypeStruct;
240 
241 extern SCP_vector<DamageTypeStruct>	Damage_types;
242 
243 #define SAF_IGNORE_SS_ARMOR			(1 << 0)		// hull armor is applied regardless of the subsystem armor for hull damage
244 
245 #define SADTF_PIERCING_NONE			0				// no piercing effects, no beam tooling
246 #define SADTF_PIERCING_DEFAULT		1				// piercing effects, beam tooling
247 #define SADTF_PIERCING_RETAIL		2				// no piercing effects, beam tooling
248 
249 //SUSHI: Damage lightning types. SLT = Ship Lighting Type.
250 #define SLT_NONE	0
251 #define SLT_DEFAULT	1
252 
253 #define NUM_TURRET_ORDER_TYPES		3
254 extern char *Turret_target_order_names[NUM_TURRET_ORDER_TYPES];	//aiturret.cpp
255 
256 // Swifty: Cockpit displays
257 typedef struct cockpit_display {
258 	int target;
259 	int source;
260 	int foreground;
261 	int background;
262 	int offset[2];
263 	int size[2];
264 	char name[MAX_FILENAME_LEN];
265 } cockpit_display;
266 
267 extern SCP_vector<cockpit_display> Player_displays;
268 
269 typedef struct cockpit_display_info {
270 	char name[MAX_FILENAME_LEN];
271 	char filename[MAX_FILENAME_LEN];
272 	char fg_filename[MAX_FILENAME_LEN];
273 	char bg_filename[MAX_FILENAME_LEN];
274 	int offset[2];
275 	int size[2];
276 } cockpit_display_info;
277 
278 // Goober5000
279 #define SSF_CARGO_REVEALED		(1 << 0)
280 #define SSF_UNTARGETABLE		(1 << 1)
281 #define SSF_NO_SS_TARGETING     (1 << 2)
282 
283 //nuke
284 #define SSF_HAS_FIRED		    (1 << 3)		//used by scripting to flag a turret as having been fired
285 #define SSF_FOV_REQUIRED		(1 << 4)
286 #define SSF_FOV_EDGE_CHECK		(1 << 5)
287 
288 #define SSF_NO_REPLACE			(1 << 6)		// prevents 'destroyed' submodel from being rendered if subsys is destroyed.
289 #define SSF_NO_LIVE_DEBRIS		(1 << 7)		// prevents subsystem from generating live debris
290 #define SSF_VANISHED			(1 << 8)		// allows subsystem to be made to disappear without a trace (for swapping it for a true model for example.
291 #define SSF_MISSILES_IGNORE_IF_DEAD	(1 << 9)	// forces homing missiles to target hull if subsystem is dead before missile hits it.
292 #define SSF_ROTATES				(1 << 10)
293 #define SSF_DAMAGE_AS_HULL		(1 << 11)		// Applies armor damage instead of subsystem damge. - FUBAR
294 #define SSF_NO_AGGREGATE		(1 << 12)		// exclude this subsystem from the aggregate subsystem-info tracking - Goober5000
295 #define SSF_PLAY_SOUND_FOR_PLAYER	( 1 << 13)	// If this subsystem is a turret on a player ship, play firing sounds - The E
296 #define SSF_NO_DISAPPEAR		( 1 << 14)		// prevents submodel from disappearing when subsys destroyed
297 
298 
299 // Wanderer
300 #define SSSF_ALIVE					(1 << 0)		// subsystem has active alive sound
301 #define SSSF_DEAD					(1 << 1)		// subsystem has active dead sound
302 #define SSSF_ROTATE					(1 << 2)		// subsystem has active rotation sound
303 #define SSSF_TURRET_ROTATION		(1 << 3)		// rotation sound to be scaled like turrets do
304 
305 // structure definition for a linked list of subsystems for a ship.  Each subsystem has a pointer
306 // to the static data for the subsystem.  The obj_subsystem data is defined and read in the model
307 // code.  Other dynamic data (such as current_hits) should remain in this structure.
308 class ship_subsys
309 {
310 public:
311 	class ship_subsys *next, *prev;				//	Index of next and previous objects in list.
312 	model_subsystem *system_info;					// pointer to static data for this subsystem -- see model.h for definition
313 
314 	int			parent_objnum;						// objnum of the parent ship
315 
316 	char		sub_name[NAME_LENGTH];					//WMC - Name that overrides name of original
317 	float		current_hits;							// current number of hits this subsystem has left.
318 	float		max_hits;
319 
320 	int flags;						// Goober5000
321 
322 	int subsys_guardian_threshold;	// Goober5000
323 	int armor_type_idx;				// FUBAR
324 
325 	// turret info
326 	//Important -WMC
327 	//With the new turret code, indexes run from 0 to MAX_SHIP_WEAPONS; a value of MAX_SHIP_PRIMARY_WEAPONS
328 	//or higher, an index into the turret weapons is considered to be an index into the secondary weapons
329 	//for much of the code. See turret_next_weap_fire_stamp.
330 
331 	int		turret_best_weapon;				// best weapon for current target; index into prim/secondary banks
332 	vec3d	turret_last_fire_direction;		//	direction pointing last time this turret fired
333 	int		turret_next_enemy_check_stamp;	//	time at which to next look for a new enemy.
334 	int		turret_next_fire_stamp;				// next time this turret can fire
335 	int		turret_enemy_objnum;					//	object index of ship this turret is firing upon
336 	int		turret_enemy_sig;						//	signature of object ship this turret is firing upon
337 	int		turret_next_fire_pos;				// counter which tells us which gun position to fire from next
338 	float	turret_time_enemy_in_range;		//	Number of seconds enemy in view cone, accuracy improves over time.
339 	int		turret_targeting_order[NUM_TURRET_ORDER_TYPES];	//Order that turrets target different types of things.
340 	float	optimum_range;
341 	float	favor_current_facing;
342 	ship_subsys	*targeted_subsys;					//	subsystem this turret is attacking
343 	bool	scripting_target_override;
344 	int		last_fired_weapon_info_index;		// which weapon class was last fired
345 
346 	int		turret_pick_big_attack_point_timestamp;	//	Next time to pick an attack point for this turret
347 	vec3d	turret_big_attack_point;			//	local coordinate of point for this turret to attack on enemy
348 
349 	EModelAnimationPosition	turret_animation_position;
350 	int		turret_animation_done_time;
351 
352 	// swarm (rapid fire) info
353 	int		turret_swarm_info_index[MAX_TFP];
354 	int		turret_swarm_num;
355 
356 	// awacs info
357 	float		awacs_intensity;
358 	float		awacs_radius;
359 
360 	ship_weapon	weapons;
361 
362 	// Data the renderer needs for ship instance specific data, like
363 	// angles and if it is blown off or not.
364 	// There are 2 of these because turrets need one for the turret and one for the barrel.
365 	// Things like radar dishes would only use one.
366 	submodel_instance_info	submodel_info_1;		// Instance data for main turret or main object
367 	submodel_instance_info	submodel_info_2;		// Instance data for turret guns, if there is one
368 
369 	int disruption_timestamp;							// time at which subsystem isn't disrupted
370 
371 	int subsys_cargo_name;			// cap ship cargo on subsys
372 	fix time_subsys_cargo_revealed;	// added by Goober5000
373 
374 	int triggered_rotation_index;		//the actual currently running animation and assosiated states
375 
376 	float points_to_target;
377 	float base_rotation_rate_pct;
378 	float gun_rotation_rate_pct;
379 
380 	// still going through these...
381 	int subsys_snd_flags;
382 
383 	int      rotation_timestamp;
384 	matrix   world_to_turret_matrix;
385 
386 	// target priority setting for turrets
387 	int      target_priority[32];
388 	int      num_target_priorities;
389 
390 	//SUSHI: Fields for max_turret_aim_update_delay
391 	//Only used when targeting small ships
392 	fix		next_aim_pos_time;
393 	vec3d	last_aim_enemy_pos;
394 	vec3d	last_aim_enemy_vel;
395 
396 	//scaler for setting adjusted turret rof
397 	float	rof_scaler;
398 	float	turn_rate;
399 
400 	//Per-turret ownage settings - SUSHI
401 	int turret_max_bomb_ownage;
402 	int turret_max_target_ownage;
403 
ship_subsys()404 	ship_subsys()
405 		: next(NULL), prev(NULL)
406 	{}
407 
408 	void clear();
409 };
410 
411 // structure for subsystems which tells us the total count of a particular type of subsystem (i.e.
412 // we might have 3 engines), and the relative strength of the subsystem.  The #defines in model.h
413 // for SUBSYSTEM_xxx will be used as indices into this array.
414 typedef struct ship_subsys_info {
415 	int	type_count;					// number of subsystems of type on this ship;
416 	float aggregate_max_hits;		// maximum number of hits for all subsystems of this type.
417 	float aggregate_current_hits;	// current count of hits for all subsystems of this type.
418 } ship_subsys_info;
419 
420 // Karajorma - Used by the alter-ship-flag SEXP as an alternative to having lots of ship flag SEXPs
421 typedef struct ship_flag_name {
422 	int flag;							// the actual ship flag constant as given by the define below
423 	char flag_name[TOKEN_LENGTH];		// the name written to the mission file for its corresponding parse_object flag
424 	int flag_list;						// is this flag in the 1st or 2nd ship flags list?
425 } ship_flag_name;
426 
427 #define MAX_SHIP_FLAG_NAMES					16
428 extern ship_flag_name Ship_flag_names[];
429 
430 // states for the flags variable within the ship structure
431 // low bits are for mission file savable flags..
432 // FRED needs these to be the low-order bits with no holes,
433 // because it indexes into an array, Hoffoss says.
434 #define	SF_IGNORE_COUNT			(1 << 0)		// ignore this ship when counting ship types for goals
435 #define	SF_REINFORCEMENT			(1 << 1)		// this ship is a reinforcement ship
436 #define	SF_ESCORT					(1 << 2)		// this ship is an escort ship
437 #define	SF_NO_ARRIVAL_MUSIC		(1 << 3)		// don't play arrival music when ship arrives
438 #define	SF_NO_ARRIVAL_WARP		(1 << 4)		// no arrival warp in effect
439 #define	SF_NO_DEPARTURE_WARP		(1 << 5)		// no departure warp in effect
440 //#define	SF_LOCKED					(1 << 6)		// can't manipulate ship in loadout screens
441 
442 // high bits are for internal flags not saved to mission files
443 // Go from bit 31 down to bit 6
444 #define	SF_KILL_BEFORE_MISSION	(1 << 31)
445 #define	SF_DYING						(1 << 30)
446 #define	SF_DISABLED					(1 << 29)
447 #define	SF_DEPART_WARP				(1 << 28)	// ship is departing via warp-out
448 #define	SF_DEPART_DOCKBAY			(1 << 27)	// ship is departing via docking bay
449 #define	SF_ARRIVING_STAGE_1		(1 << 26)	// ship is arriving. In other words, doing warp in effect, stage 1
450 #define	SF_ARRIVING_STAGE_2		(1 << 25)	// ship is arriving. In other words, doing warp in effect, stage 2
451 #define  SF_ARRIVING             (SF_ARRIVING_STAGE_1|SF_ARRIVING_STAGE_2)
452 #define	SF_ENGINES_ON				(1 << 24)	// engines sound should play if set
453 #define	SF_DOCK_LEADER			(1 << 23)	// Goober5000 - this guy is in charge of everybody he's docked to
454 #define	SF_CARGO_REVEALED			(1 << 22)	// ship's cargo is revealed to all friendly ships
455 #define	SF_FROM_PLAYER_WING		(1	<< 21)	// set for ships that are members of any player starting wing
456 #define	SF_PRIMARY_LINKED			(1 << 20)	// ships primary weapons are linked together
457 #define	SF_SECONDARY_DUAL_FIRE	(1 << 19)	// ship is firing two missiles from the current secondary bank
458 #define	SF_WARP_BROKEN				(1	<< 18)	// set when warp drive is not working, but is repairable
459 #define	SF_WARP_NEVER				(1	<< 17)	// set when ship can never warp
460 #define	SF_TRIGGER_DOWN			(1 << 16)	// ship has its "trigger" held down
461 #define	SF_AMMO_COUNT_RECORDED	(1	<<	15)	// we've recorded the initial secondary weapon count (which is used to limit support ship rearming)
462 #define	SF_HIDDEN_FROM_SENSORS	(1	<< 14)	// ship doesn't show up on sensors, blinks in/out on radar
463 #define	SF_SCANNABLE				(1	<< 13)	// ship is "scannable".  Play scan effect and report as "Scanned" or "not scanned".
464 #define	SF_WARPED_SUPPORT			(1 << 12)	// set when this is a support ship which was warped in automatically
465 #define	SF_EXPLODED					(1 << 11)	// ship has exploded (needed for kill messages)
466 #define	SF_SHIP_HAS_SCREAMED		(1 << 10)	// ship has let out a death scream
467 #define	SF_RED_ALERT_STORE_STATUS (1 << 9)	// ship status should be stored/restored if red alert mission
468 #define	SF_VAPORIZE					(1<<8)		// ship is vaporized by beam - alternative death sequence
469 #define SF_DEPARTURE_ORDERED		(1<<7)		// departure of this ship was ordered by player - Goober5000, similar to WF_DEPARTURE_ORDERED
470 
471 // MWA -- don't go below whatever bitfield is used for Fred above (currently 6)!!!!
472 
473 #define	SF_DEPARTING				(SF_DEPART_WARP | SF_DEPART_DOCKBAY)				// ship is departing
474 #define	SF_CANNOT_WARP				(SF_WARP_BROKEN | SF_WARP_NEVER | SF_DISABLED)	// ship cannot warp out
475 
476 
477 #define DEFAULT_SHIP_PRIMITIVE_SENSOR_RANGE		10000	// Goober5000
478 
479 
480 // Bits for ship.flags2
481 #define SF2_PRIMITIVE_SENSORS				(1<<0)		// Goober5000 - primitive sensor display
482 #define SF2_FRIENDLY_STEALTH_INVIS			(1<<1)		// Goober5000 - when stealth, don't appear on radar even if friendly
483 #define SF2_STEALTH							(1<<2)		// Goober5000 - is this particular ship stealth
484 #define SF2_DONT_COLLIDE_INVIS				(1<<3)		// Goober5000 - is this particular ship don't-collide-invisible
485 #define SF2_NO_SUBSPACE_DRIVE				(1<<4)		// Goober5000 - this ship has no subspace drive
486 #define SF2_NAVPOINT_CARRY					(1<<5)		// Kazan      - This ship autopilots with the player
487 #define SF2_AFFECTED_BY_GRAVITY				(1<<6)		// Goober5000 - ship affected by gravity points
488 #define SF2_TOGGLE_SUBSYSTEM_SCANNING		(1<<7)		// Goober5000 - switch whether subsystems are scanned
489 #define SF2_NO_BUILTIN_MESSAGES				(1<<8)		// Karajorma - ship should not send built-in messages
490 #define SF2_PRIMARIES_LOCKED				(1<<9)		// Karajorma - This ship can't fire primary weapons
491 #define SF2_SECONDARIES_LOCKED				(1<<10)		// Karajorma - This ship can't fire secondary weapons
492 #define SF2_GLOWMAPS_DISABLED				(1<<11)		// taylor - to disable glow maps
493 #define SF2_NO_DEATH_SCREAM					(1<<12)		// Goober5000 - for WCS
494 #define SF2_ALWAYS_DEATH_SCREAM				(1<<13)		// Goober5000 - for WCS
495 #define SF2_NAVPOINT_NEEDSLINK				(1<<14)		// Kazan	- This ship requires "linking" for autopilot (when player ship gets within specified distance SF2_NAVPOINT_NEEDSLINK is replaced by SF2_NAVPOINT_CARRY)
496 #define SF2_HIDE_SHIP_NAME					(1<<15)		// Karajorma - Hides the ships name (like the -wcsaga command line used to but for any selected ship)
497 #define SF2_AFTERBURNER_LOCKED				(1<<16)		// KeldorKatarn - This ship can't use its afterburners
498 #define SF2_SET_CLASS_DYNAMICALLY			(1<<18)		// Karajorma - This ship should have its class assigned rather than simply read from the mission file
499 #define SF2_LOCK_ALL_TURRETS_INITIALLY		(1<<19)		// Karajorma - Lock all turrets on this ship at mission start or on arrival
500 #define SF2_FORCE_SHIELDS_ON				(1<<20)
501 #define SF2_NO_ETS							(1<<21)		// The E - This ship does not have an ETS
502 #define SF2_CLOAKED							(1<<22)		// The E - This ship will not be rendered
503 #define SF2_NO_THRUSTERS					(1<<23)		// The E - Thrusters on this ship are not rendered.
504 #define SF2_SHIP_LOCKED						(1<<24)		// Karajorma - Prevents the player from changing the ship class on loadout screen
505 #define SF2_WEAPONS_LOCKED					(1<<25)		// Karajorma - Prevents the player from changing the weapons on the ship on the loadout screen
506 #define SF2_SHIP_SELECTIVE_LINKING			(1<<26)		// RSAXVC - Allow pilot to pick firing configuration
507 #define SF2_SCRAMBLE_MESSAGES				(1<<27)		// Goober5000 - all messages sent from this ship appear scrambled
508 
509 // If any of these bits in the ship->flags are set, ignore this ship when targeting
510 extern int TARGET_SHIP_IGNORE_FLAGS;
511 
512 #define MAX_DAMAGE_SLOTS	32
513 #define MAX_SHIP_ARCS		2		// How many "arcs" can be active at once... Must be less than MAX_ARC_EFFECTS in model.h.
514 #define NUM_SUB_EXPL_HANDLES	2	// How many different big ship sub explosion sounds can be played.
515 
516 #define MAX_SHIP_CONTRAILS		24
517 #define MAX_MAN_THRUSTERS	128
518 
519 typedef struct ship_spark {
520 	vec3d pos;			// position of spark in the submodel's RF
521 	int submodel_num;	// which submodel is making the spark
522 	int end_time;
523 } ship_spark;
524 
525 #define AWACS_WARN_NONE		(1 << 0)
526 #define AWACS_WARN_25		(1 << 1)
527 #define AWACS_WARN_75		(1 << 2)
528 
529 // NOTE: Can't be treated as a struct anymore, since it has STL data structures in its object tree!
530 class ship
531 {
532 public:
533 	int	objnum;
534 	int	ai_index;			// Index in Ai_info of ai_info associated with this ship.
535 	int	ship_info_index;	// Index in ship_info for this ship
536 	int	hotkey;
537 	int	escort_priority;
538 	int	score;
539 	float assist_score_pct;
540 	int	respawn_priority;
541 
542 	// BEGIN PACK ubytes and chars
543 	ubyte	pre_death_explosion_happened;		// If set, it means the 4 or 5 smaller explosions
544 	ubyte wash_killed;
545 	char	cargo1;
546 
547 	// ship wing status info
548 	char	wing_status_wing_index;			// wing index (0-4) in wingman status gauge
549 	char	wing_status_wing_pos;			// wing position (0-5) in wingman status gauge
550 
551 	// alternate indexes
552 	int	 alt_type_index;								// only used for display purposes (read : safe)
553 	int	 callsign_index;								// ditto
554 
555 	// targeting laser info
556 	char targeting_laser_bank;						// -1 if not firing, index into polymodel gun points if it _is_ firing
557 	int targeting_laser_objnum;					// -1 if invalid, beam object # otherwise
558 
559 	// corkscrew missile stuff
560 	ubyte num_corkscrew_to_fire;						// # of corkscrew missiles lef to fire
561 	int corkscrew_missile_bank;
562 	int next_corkscrew_fire;						// next time to fire a corkscrew missile
563 	// END PACK
564 
565 	int	final_death_time;				// Time until big fireball starts
566 	int	death_time;				// Time until big fireball starts
567 	int	end_death_time;				// Time until big fireball starts
568 	int	really_final_death_time;	// Time until ship breaks up and disappears
569 	vec3d	deathroll_rotvel;			// Desired death rotational velocity
570 
571 	WarpEffect *warpin_effect;
572 	WarpEffect *warpout_effect;
573 
574 	int	next_fireball;
575 
576 	int	next_hit_spark;
577 	int	num_hits;			//	Note, this is the number of spark emitter positions!
578 	ship_spark	sparks[MAX_SHIP_HITS];
579 
580 	bool use_special_explosion;
581 	int special_exp_damage;					// new special explosion/hitpoints system
582 	int special_exp_blast;
583 	int special_exp_inner;
584 	int special_exp_outer;
585 	bool use_shockwave;
586 	int special_exp_shockwave_speed;
587 	int special_exp_deathroll_time;
588 
589 	int	special_hitpoints;
590 	int	special_shield;
591 
592 	float ship_max_shield_strength;
593 	float ship_max_hull_strength;
594 
595 	int ship_guardian_threshold;	// Goober5000 - now also determines whether ship is guardian'd
596 
597 
598 	char	ship_name[NAME_LENGTH];
599 
600 	int	team;				//	Which team it's on, HOSTILE, FRIENDLY, UNKNOWN, NEUTRAL
601 
602 	fix	time_cargo_revealed;					// time at which the cargo was revealed
603 
604 	int	arrival_location;
605 	int	arrival_distance;		// how far away this ship should arrive
606 	int	arrival_anchor;			// name of object this ship arrives near (or in front of)
607 	int	arrival_path_mask;		// Goober5000 - possible restrictions on which bay paths to use
608 	int	arrival_cue;
609 	int	arrival_delay;
610 
611 	int	departure_location;		// depart to hyperspace or someplace else (like docking bay)
612 	int	departure_anchor;		// when docking bay -- index of ship to use
613 	int departure_path_mask;	// Goober5000 - possible restrictions on which bay paths to use
614 	int	departure_cue;			// sexpression to eval when departing
615 	int	departure_delay;		// time in seconds after sexp is true that we delay.
616 
617 	int	wingnum;								// wing number this ship is in.  -1 if in no wing, Wing array index otherwise
618 	int	orders_accepted;					// set of orders this ship will accept from the player.
619 
620 	// Subsystem fields.  The subsys_list is a list of all subsystems (which might include multiple types
621 	// of a particular subsystem, like engines).  The subsys_info struct is information for particular
622 	// types of subsystems.  (i.e. the list might contain 3 engines.  There will be one subsys_info entry
623 	// describing the state of all engines combined) -- MWA 4/1/97
624 	ship_subsys	subsys_list;									//	linked list of subsystems for this ship.
625 	ship_subsys	*last_targeted_subobject[MAX_PLAYERS];	// Last subobject that has been targeted.  NULL if none;(player specific)
626 	ship_subsys_info	subsys_info[SUBSYSTEM_MAX];		// info on particular generic types of subsystems
627 
628 	float	*shield_integrity;					//	Integrity at each triangle in shield mesh.
629 
630 	// ETS fields
631 	int	shield_recharge_index;			// index into array holding the shield recharge rate
632 	int	weapon_recharge_index;			// index into array holding the weapon recharge rate
633 	int	engine_recharge_index;			// index into array holding the engine recharge rate
634 	float	weapon_energy;						// Number of EUs in energy reserves
635 	float	current_max_speed;				// Max ship speed (based on energy diverted to engines)
636 	int	next_manage_ets;					// timestamp for when ai can next modify ets ( -1 means never )
637 
638 	uint	flags;								// flag variable to contain ship state (see SF_ #defines)
639 	uint	flags2;								// another flag variable (see SF2_ #defines)
640 	int	reinforcement_index;				// index into reinforcement struct or -1
641 
642 	float	afterburner_fuel;					// amount of afterburner fuel remaining (capacity is stored
643 													// as afterburner_fuel_capacity in ship_info).
644 
645 	int cmeasure_count;						//	Number of charges of countermeasures this ship can hold.
646 	int current_cmeasure;					//	Currently selected countermeasure.
647 
648 	int cmeasure_fire_stamp;				//	Time at which can fire countermeasure.
649 
650 	float	target_shields_delta;			//	Target for shield recharge system.
651 	float	target_weapon_energy_delta;	//	Target for recharge system.
652 	ship_weapon	weapons;
653 
654 	int	shield_hits;						//	Number of hits on shield this frame.
655 
656 	SCP_vector<vec3d>	shield_points;
657 
658 	float		wash_intensity;
659 	vec3d	wash_rot_axis;
660 	int		wash_timestamp;
661 
662 	int	num_swarm_missiles_to_fire;	// number of swarm missiles that need to be launched
663 	int	next_swarm_fire;					// timestamp of next swarm missile to fire
664 	int	next_swarm_path;					// next path number for swarm missile to take
665 	int	num_turret_swarm_info;			// number of turrets in process of launching swarm
666 	int swarm_missile_bank;				// The missilebank the swarm was originally launched from
667 
668 	int	group;								// group ship is in, or -1 if none.  Fred thing
669 	int	death_roll_snd;					// id of death roll sound, may need to be stopped early
670 	int	ship_list_index;					// index of ship in Ship_objs[] array
671 
672 	int	thruster_bitmap;					// What frame the current thruster bitmap is at for this ship
673 	float	thruster_frame;					// Used to keep track of which frame the animation should be on.
674 
675 	int	thruster_glow_bitmap;			// What frame the current thruster engine glow bitmap is at for this ship
676 	float	thruster_glow_frame;				// Used to keep track of which frame the engine glow animation should be on.
677 	float	thruster_glow_noise;				// Noise for current frame
678 
679 	int	thruster_secondary_glow_bitmap;		// Bobboau
680 	int	thruster_tertiary_glow_bitmap;		// Bobboau
681 	int	thruster_distortion_bitmap;			// Valathil
682 
683 	int	next_engine_stutter;				// timestamp to time the engine stuttering when a ship dies
684 
685 	fix base_texture_anim_frametime;		// Goober5000 - zero mark for texture animations
686 
687 	float total_damage_received;        // total damage received (for scoring purposes)
688 	float damage_ship[MAX_DAMAGE_SLOTS];    // damage applied from each player
689 	int   damage_ship_id[MAX_DAMAGE_SLOTS]; // signature of the damager (corresponds to each entry in damage_ship)
690 	int	persona_index;						// which persona is this guy.
691 
692 	int	subsys_disrupted_flags;					// bitflags used to check if SUBYSTEM_* is disrupted or not
693 	int	subsys_disrupted_check_timestamp;	// timer to control how oftern flags are set/cleared in subsys_disrupted_flags
694 
695 	uint	create_time;						// time ship was created, set by gettime()
696 
697 	// keep multiplayer specific stuff below this point
698 	int	ts_index;							// index into the team select and Wss_slots array (or -1 if not in one of those arrays)
699 
700 	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.
701 	int	sub_expl_sound_handle[NUM_SUB_EXPL_HANDLES];
702 
703 
704 	// Stuff for showing electrical arcs on damaged ships
705 	vec3d	arc_pts[MAX_SHIP_ARCS][2];			// The endpoints of each arc
706 	int		arc_timestamp[MAX_SHIP_ARCS];		// When this times out, the spark goes away.  -1 is not used
707 	ubyte		arc_type[MAX_SHIP_ARCS];			// see MARC_TYPE_* defines in model.h
708 	int		arc_next_time;							// When the next arc will be created.
709 
710 	// emp missile stuff
711 	float emp_intensity;								// <= 0.0f if no emp effect present
712 	float emp_decr;									// how much to decrement EMP effect per second for this ship
713 
714 	// contrail stuff
715 	trail *trail_ptr[MAX_SHIP_CONTRAILS];
716 
717 	// tag stuff
718 	float tag_total;									// total tag time
719 	float tag_left;									// total tag remaining
720 	fix	time_first_tagged;
721 	float level2_tag_total;							// total tag time
722 	float level2_tag_left;							// total tag remaining
723 
724 	// old-style object update stuff
725 	np_update		np_updates[MAX_PLAYERS];	// for both server and client
726 
727 	// lightning timestamp
728 	int lightning_stamp;
729 
730 	// AWACS warning flag
731 	ubyte	awacs_warning_flag;
732 
733 	// Special warp objnum (warping at knossos)
734 	int special_warpin_objnum;
735 	int special_warpout_objnum;
736 
737 	ship_subsys fighter_beam_turret_data;		//a fake subsystem that pretends to be a turret for fighter beams
738 	model_subsystem beam_sys_info;
739 	int was_firing_last_frame[MAX_SHIP_PRIMARY_BANKS];
740 
741 	// Goober5000 - range of primitive sensors
742 	int primitive_sensor_range;
743 
744 	// Goober5000 - revised nameplate implementation
745 	int *ship_replacement_textures;
746 
747 	// Goober5000 - index into pm->view_positions[]
748 	// apparently, early in FS1 development, there was a field called current_eye_index
749 	// that had this same functionality
750 	int current_viewpoint;
751 
752 	trail *ABtrail_ptr[MAX_SHIP_CONTRAILS];		//after burner trails -Bobboau
753 	trail_info ab_info[MAX_SHIP_CONTRAILS];
754 	int ab_count;
755 
756 	// glow points
757 	std::deque<bool> glow_point_bank_active;
758 
759 	//Animated Shader effects
760 	int shader_effect_num;
761 	int shader_effect_duration;
762 	int shader_effect_start_time;
763 	bool shader_effect_active;
764 
765 	int last_fired_point[MAX_SHIP_PRIMARY_BANKS]; //for fire point cylceing
766 	ship_subsys *last_fired_turret; // which turret has fired last
767 
768 	// fighter bay door stuff, parent side
769 	int bay_doors_anim_done_time;		// ammount of time to transition from one animation state to another
770 	EModelAnimationPosition bay_doors_status;			// anim status of the bay doors (closed/not-animating, opening, open/not-animating)
771 	int bay_doors_wanting_open;		// how many ships want/need the bay door open
772 
773 	// figther bay door stuff, client side
774 	ubyte bay_doors_launched_from;	// the bay door that I launched from
775 	bool bay_doors_need_open;		// keep track of whether I need the door open or not
776 	int bay_doors_parent_shipnum;	// our parent ship, what we are entering/leaving
777 
778 	float secondary_point_reload_pct[MAX_SHIP_SECONDARY_BANKS][MAX_SLOTS];	//after fireing a secondary it takes some time for that secondary weapon to reload, this is how far along in that proces it is (from 0 to 1)
779 	float primary_rotate_rate[MAX_SHIP_PRIMARY_BANKS];
780 	float primary_rotate_ang[MAX_SHIP_PRIMARY_BANKS];
781 
782 	int thrusters_start[MAX_MAN_THRUSTERS];		//Timestamp of when thrusters started
783 	int thrusters_sounds[MAX_MAN_THRUSTERS];	//Sound index for thrusters
784 
785 	SCP_vector<alt_class> s_alt_classes;
786 
787 	int ship_iff_color[MAX_IFFS][MAX_IFFS];
788 
789 	int ammo_low_complaint_count;				// number of times this ship has complained about low ammo
790 	int armor_type_idx;
791 	int shield_armor_type_idx;
792 	int collision_damage_type_idx;
793 	int debris_damage_type_idx;
794 	ushort debris_net_sig;						// net signiture of the first piece of debris this ship has
795 
796 	int model_instance_num;
797 
798 	fix time_created;
799 
800 	fix radar_visible_since; // The first time this ship was visible on the radar. Gets reset when ship is not visible anymore
801 	fix radar_last_contact; // The last time this ship appeared on the radar. When it is currently visible this has the value if Missiontime
802 
803 	RadarVisibility radar_last_status; // Last radar status
804 	RadarVisibility radar_current_status; // Current radar status
805 
806 	SCP_string team_name;
807 	SCP_string secondary_team_name;	//If the change-team-color sexp is used, these fields control the fading behaviour
808 	fix team_change_timestamp;
809 	int team_change_time;
810 
811 	float autoaim_fov;
812 
813 	// reset to a completely blank ship
814 	void clear();
815 };
816 
817 struct ai_target_priority {
818 	char name[NAME_LENGTH];
819 
820 	int obj_type;
821 	SCP_vector <int> ship_type;
822 	SCP_vector <int> ship_class;
823 	SCP_vector <int> weapon_class;
824 
825 	unsigned int obj_flags;
826 	int sif_flags;
827 	int sif2_flags;
828 	int wif_flags;
829 	int wif2_flags;
830 };
831 
832 extern SCP_vector <ai_target_priority> Ai_tp_list;
833 
834 void parse_ai_target_priorities();
835 void parse_weapon_targeting_priorities();
836 ai_target_priority init_ai_target_priorities();
837 
838 // structure and array def for ships that have exited the game.  Keeps track of certain useful
839 // information.
840 #define SEF_DESTROYED			(1<<0)
841 #define SEF_DEPARTED				(1<<1)
842 #define SEF_CARGO_KNOWN			(1<<2)
843 #define SEF_PLAYER_DELETED		(1<<3)			// ship deleted by a player in ship select
844 #define SEF_BEEN_TAGGED			(1<<4)
845 #define SEF_RED_ALERT_CARRY	(1<<5)
846 
847 typedef struct exited_ship {
848 	char	ship_name[NAME_LENGTH];
849 	int		obj_signature;
850 	int		ship_class;
851 	int		team;
852 	int		flags;
853 	fix		time;
854 	int		hull_strength;
855 	fix		time_cargo_revealed;
856 	char	cargo1;
857 	float damage_ship[MAX_DAMAGE_SLOTS];		// A copy of the arrays from the ship so that we can figure out what damaged it
858 	int   damage_ship_id[MAX_DAMAGE_SLOTS];
859 } exited_ship;
860 
861 extern SCP_vector<exited_ship> Ships_exited;
862 
863 // a couple of functions to get at the data
864 extern void ship_add_exited_ship( ship *shipp, int reason );
865 extern int ship_find_exited_ship_by_name( char *name );
866 extern int ship_find_exited_ship_by_signature( int signature);
867 
868 #define	SIF_NO_COLLIDE				(1 << 0)
869 #define	SIF_PLAYER_SHIP				(1 << 1)
870 #define	SIF_DEFAULT_PLAYER_SHIP		(1 << 2)
871 #define	SIF_PATH_FIXUP				(1 << 3)		// when set, path verts have been set for this ship's model
872 #define	SIF_SUPPORT					(1 << 4)		// this ship can perform repair/rearm functions
873 #define	SIF_AFTERBURNER				(1 << 5)		// this ship has afterburners
874 #define SIF_BALLISTIC_PRIMARIES		(1 << 6)		// this ship can equip ballistic primaries - Goober5000
875 
876 // If you add a new ship type, then please add the appropriate type in the ship_count
877 // structure later in this file!!! and let MWA know!!
878 #define	SIF_CARGO					(1 << 7)		// is this ship a cargo type ship -- used for docking purposes
879 #define	SIF_FIGHTER					(1 << 8)		// this ship is a fighter
880 #define	SIF_BOMBER					(1 << 9)		// this ship is a bomber
881 #define	SIF_CRUISER					(1 << 10)		// this ship is a cruiser
882 #define	SIF_FREIGHTER				(1 << 11)	// this ship is a freighter
883 #define	SIF_CAPITAL					(1 << 12)	// this ship is a capital/installation ship
884 #define	SIF_TRANSPORT				(1 << 13)	// this ship is a transport
885 #define	SIF_NAVBUOY					(1 << 14)	// AL 11-24-97: this is a navbuoy
886 #define	SIF_SENTRYGUN				(1 << 15)	// AL 11-24-97: this is a navbuoy with turrets
887 #define	SIF_ESCAPEPOD				(1 << 16)	// AL 12-09-97: escape pods that fire from big ships
888 #define	SIF_NO_SHIP_TYPE			(1 << 17)	// made distinct to help trap errors
889 
890 #define	SIF_SHIP_COPY				(1 << 18)	// this ship is a copy of another ship in the table -- meaningful for scoring and possible other things
891 #define	SIF_IN_TECH_DATABASE		(1 << 19)	// is ship type to be listed in the tech database?
892 #define	SIF_IN_TECH_DATABASE_M		(1 << 20)	// is ship type to be listed in the tech database for multiplayer?
893 
894 #define	SIF_STEALTH					(1 << 21)	// the ship has stealth capabilities
895 #define	SIF_SUPERCAP				(1 << 22)	// the ship is a supercap
896 #define	SIF_DRYDOCK					(1 << 23)	// the ship is a drydock
897 #define	SIF_SHIP_CLASS_DONT_COLLIDE_INVIS	(1 << 24)	// Don't collide with this ship's invisible polygons
898 
899 #define	SIF_BIG_DAMAGE				(1 << 25)	// this ship is classified as a big damage ship
900 #define	SIF_HAS_AWACS				(1 << 26)	// ship has an awacs subsystem
901 
902 #define	SIF_CORVETTE				(1 << 27)	// corvette class (currently this only means anything for briefing icons)
903 #define	SIF_GAS_MINER				(1 << 28)	// also just for briefing icons
904 #define	SIF_AWACS					(1 << 29)	// ditto
905 
906 #define	SIF_KNOSSOS_DEVICE			(1 << 30)	// this is the knossos device
907 
908 #define	SIF_NO_FRED					(1 << 31)	// not available in fred
909 
910 
911 // flags2 list.
912 #define SIF2_DEFAULT_IN_TECH_DATABASE		(1 << 0)	// default in tech database - Goober5000
913 #define SIF2_DEFAULT_IN_TECH_DATABASE_M		(1 << 1)	// ditto - Goober5000
914 #define SIF2_FLASH							(1 << 2)	// makes a flash when it explodes
915 #define SIF2_SHOW_SHIP_MODEL				(1 << 3)	// Show ship model even in first person view
916 #define SIF2_SURFACE_SHIELDS                (1 << 4)    // _argv[-1], 16 Jan 2005: Enable surface shields for this ship.
917 #define SIF2_GENERATE_HUD_ICON				(1 << 5)	// Enable generation of a HUD shield icon
918 #define SIF2_DISABLE_WEAPON_DAMAGE_SCALING	(1 << 6)	// WMC - Disable weapon scaling based on flags
919 #define SIF2_GUN_CONVERGENCE				(1 << 7)	// WMC - Gun convergence based on model weapon norms.
920 #define SIF2_NO_THRUSTER_GEO_NOISE			(1 << 8)	// Echelon9 - No thruster geometry noise.
921 #define SIF2_INTRINSIC_NO_SHIELDS			(1 << 9)	// Chief - disables shields for this ship even without No Shields in mission.
922 #define SIF2_NO_PRIMARY_LINKING				(1 << 10)	// Chief - slated for 3.7 originally, but this looks pretty simple to implement.
923 #define SIF2_NO_PAIN_FLASH					(1 << 11)	// The E - disable red pain flash
924 #define SIF2_ALLOW_LANDINGS					(1 << 12)	// SUSHI: Automatically set if any subsystems allow landings (as a shortcut)
925 #define SIF2_NO_ETS							(1 << 13)	// The E - No ETS on this ship class
926 #define SIF2_NO_LIGHTING					(1 << 14)	// Valathil - No lighting for this ship
927 #define SIF2_DYN_PRIMARY_LINKING			(1 << 15)	// RSAXVC - Dynamically generate weapon linking options
928 #define SIF2_AUTO_SPREAD_SHIELDS			(1 << 16)	// zookeeper - auto spread shields
929 #define SIF2_DRAW_WEAPON_MODELS				(1 << 17)	// the ship draws weapon models of any sort (used to be a boolean)
930 #define SIF2_MODEL_POINT_SHIELDS			(1 << 18)	// zookeeper - uses model-defined shield points instead of quadrants
931 
932 #define	SIF_DEFAULT_VALUE		0
933 #define SIF2_DEFAULT_VALUE		0
934 
935 #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)
936 #define	SIF_SMALL_SHIP				(SIF_FIGHTER | SIF_BOMBER | SIF_SUPPORT | SIF_ESCAPEPOD )
937 #define	SIF_BIG_SHIP				(SIF_CRUISER | SIF_FREIGHTER | SIF_TRANSPORT | SIF_CORVETTE | SIF_GAS_MINER | SIF_AWACS)
938 #define	SIF_HUGE_SHIP				(SIF_CAPITAL | SIF_SUPERCAP | SIF_DRYDOCK | SIF_KNOSSOS_DEVICE)
939 #define	SIF_NOT_FLYABLE			(SIF_CARGO | SIF_NAVBUOY | SIF_SENTRYGUN)		// AL 11-24-97: this useful to know for targeting reasons
940 #define	SIF_HARMLESS				(SIF_CARGO | SIF_NAVBUOY | SIF_ESCAPEPOD)		// AL 12-3-97: ships that are not a threat
941 // for ships of this type, we make beam weapons miss a little bit otherwise they'd be way too powerful
942 #define	SIF_BEAM_JITTER			(SIF_CARGO | SIF_FIGHTER | SIF_BOMBER | SIF_FREIGHTER | SIF_TRANSPORT | SIF_SENTRYGUN | SIF_NAVBUOY | SIF_ESCAPEPOD)
943 // these ships avoid shockwaves
944 // (the weird thing is that freighters and transports used to be explicitly allowed in one part of the code but then explicitly disallowed in another)
945 #define SIF_AVOID_SHOCKWAVE		SIF_SMALL_SHIP
946 
947 // masks for preventing only non flag entry SIF flags from being cleared
948 #define SIF_MASK				SIF_AFTERBURNER
949 #define SIF2_MASK				SIF2_DRAW_WEAPON_MODELS
950 
951 #define REGULAR_WEAPON	(1<<0)
952 #define DOGFIGHT_WEAPON (1<<1)
953 
954 #define AIM_FLAG_AUTOAIM				(1 << 0)	// has autoaim
955 #define AIM_FLAG_AUTO_CONVERGENCE		(1 << 1)	// has automatic convergence
956 #define AIM_FLAG_STD_CONVERGENCE		(1 << 2)	// has standard - ie. non-automatic - convergence
957 #define AIM_FLAG_AUTOAIM_CONVERGENCE	(1 << 3)	// has autoaim with convergence
958 #define AIM_FLAG_CONVERGENCE_OFFSET		(1 << 4)	// marks that convergence has offset value
959 
960 typedef struct thruster_particles {
961 	generic_anim thruster_bitmap;
962 	float		min_rad;
963 	float		max_rad;
964 	int			n_high;
965 	int			n_low;
966 	float		variance;
967 } thruster_particles;
968 
969 typedef struct particle_effect {
970 	int				n_low;
971 	int				n_high;
972 	float			min_rad;
973 	float			max_rad;
974 	float			min_life;
975 	float			max_life;
976 	float			min_vel;
977 	float			max_vel;
978 	float			variance;
979 } particle_effect;
980 
981 #define STI_MSG_COUNTS_FOR_ALONE		(1<<0)
982 #define STI_MSG_PRAISE_DESTRUCTION		(1<<1)
983 
984 #define STI_HUD_HOTKEY_ON_LIST			(1<<0)
985 #define STI_HUD_TARGET_AS_THREAT		(1<<1)
986 #define STI_HUD_SHOW_ATTACK_DIRECTION	(1<<2)
987 #define STI_HUD_NO_CLASS_DISPLAY		(1<<3)
988 
989 #define STI_SHIP_SCANNABLE				(1<<0)
990 #define STI_SHIP_WARP_PUSHES			(1<<1)
991 #define STI_SHIP_WARP_PUSHABLE			(1<<2)
992 #define STI_TURRET_TGT_SHIP_TGT			(1<<3)
993 
994 #define STI_WEAP_BEAMS_EASILY_HIT		(1<<0)
995 #define STI_WEAP_NO_HUGE_IMPACT_EFF		(1<<1)
996 
997 #define STI_AI_ACCEPT_PLAYER_ORDERS		(1<<0)
998 #define STI_AI_AUTO_ATTACKS				(1<<1)
999 #define STI_AI_ATTEMPT_BROADSIDE		(1<<2)
1000 #define STI_AI_GUARDS_ATTACK			(1<<3)
1001 #define STI_AI_TURRETS_ATTACK			(1<<4)
1002 #define STI_AI_CAN_FORM_WING			(1<<5)
1003 #define STI_AI_PROTECTED_ON_CRIPPLE		(1<<6)
1004 
1005 typedef struct ship_type_info {
1006 	char name[NAME_LENGTH];
1007 
1008 	//Messaging?
1009 	int message_bools;
1010 
1011 	//HUD
1012 	int hud_bools;
1013 
1014 	//Ship
1015 	int ship_bools;	//For lack of better term
1016 	float debris_max_speed;
1017 
1018 	//Weapons
1019 	int weapon_bools;
1020 	float ff_multiplier;
1021 	float emp_multiplier;
1022 
1023 	//Fog
1024 	float fog_start_dist;
1025 	float fog_complete_dist;
1026 
1027 	//AI
1028 	int	ai_valid_goals;
1029 	int ai_player_orders;
1030 	int ai_bools;
1031 	int ai_active_dock;
1032 	int ai_passive_dock;
1033 	SCP_vector<int> ai_actively_pursues;
1034 	SCP_vector<int> ai_cripple_ignores;
1035 
1036 	//Explosions
1037 	float vaporize_chance;
1038 
1039 	//Resources
1040 	SCP_vector<int> explosion_bitmap_anims;
1041 
1042 	//Regen values - need to be converted after all types have loaded
1043 	SCP_vector<SCP_string> ai_actively_pursues_temp;
1044 	SCP_vector<SCP_string> ai_cripple_ignores_temp;
1045 
ship_type_infoship_type_info1046 	ship_type_info( )
1047 		: message_bools( 0 ), hud_bools( 0 ), ship_bools( 0 ), debris_max_speed( 0.f ),
1048 		  weapon_bools( 0 ), ff_multiplier( 0.f ), emp_multiplier( 0.f ),
1049 		  fog_start_dist( 0.f ), fog_complete_dist( 0.f ),
1050 		  ai_valid_goals( 0 ), ai_player_orders( 0 ), ai_bools( 0 ), ai_active_dock( 0 ), ai_passive_dock( 0 ),
1051 		  vaporize_chance( 0.f )
1052 
1053 	{
1054 		name[ 0 ] = '\0';
1055 	}
1056 } ship_type_info;
1057 
1058 extern SCP_vector<ship_type_info> Ship_types;
1059 
1060 struct man_thruster_renderer {
1061 	int bmap_id;
1062 	geometry_batcher man_batcher;
1063 
man_thruster_rendererman_thruster_renderer1064 	man_thruster_renderer(int id){bmap_id = id;}
1065 };
1066 
1067 extern SCP_vector<man_thruster_renderer> Man_thrusters;
1068 
1069 #define MT_BANK_RIGHT		(1<<0)
1070 #define MT_BANK_LEFT		(1<<1)
1071 #define MT_PITCH_UP			(1<<2)
1072 #define MT_PITCH_DOWN		(1<<3)
1073 #define MT_ROLL_RIGHT		(1<<4)
1074 #define MT_ROLL_LEFT		(1<<5)
1075 #define MT_SLIDE_RIGHT		(1<<6)
1076 #define MT_SLIDE_LEFT		(1<<7)
1077 #define MT_SLIDE_UP			(1<<8)
1078 #define MT_SLIDE_DOWN		(1<<9)
1079 #define MT_FORWARD			(1<<10)
1080 #define MT_REVERSE			(1<<11)
1081 
1082 typedef struct man_thruster {
1083 	int use_flags;
1084 
1085 	int start_snd;
1086 	int loop_snd;
1087 	int stop_snd;
1088 
1089 	int tex_id;
1090 	int tex_nframes;
1091 	int tex_fps;
1092 	float length;
1093 	float radius;
1094 
1095 	vec3d pos, norm;
1096 } man_thruster;
1097 
1098 //Warp type defines
1099 #define WT_DEFAULT					0
1100 #define WT_KNOSSOS					1
1101 #define WT_DEFAULT_THEN_KNOSSOS		2
1102 #define WT_IN_PLACE_ANIM			3
1103 #define WT_SWEEPER					4
1104 #define WT_HYPERSPACE				5
1105 
1106 // Holds variables for collision physics (Gets its own struct purely for clarity purposes)
1107 // Most of this only really applies properly to small ships
1108 typedef struct ship_collision_physics {
1109 	// Collision physics definitions: how a ship responds to collisions
1110 	float both_small_bounce;	// Bounce factor when both ships are small
1111 								// This currently only comes into play if one ship is the player...
1112 								// blame retail for that.
1113 	float bounce;				// Bounce factor for all other cases
1114 	float friction;				// Controls lateral velocity lost when colliding with a large ship
1115 	float rotation_factor;		// Affects the rotational energy of collisions... TBH not sure how.
1116 
1117 	// Speed & angle constraints for a smooth landing
1118 	// Note that all angles are stored as a dotproduct between normalized vectors instead. This saves us from having
1119 	// to do a lot of dot product calculations later.
1120 	float landing_max_z;
1121 	float landing_min_z;
1122 	float landing_min_y;
1123 	float landing_max_x;
1124 	float landing_max_angle;
1125 	float landing_min_angle;
1126 	float landing_max_rot_angle;
1127 
1128 	// Speed & angle constraints for a "rough" landing (one with normal collision consequences, but where
1129 	// the ship is still reoriented towards its resting orientation)
1130 	float reorient_max_z;
1131 	float reorient_min_z;
1132 	float reorient_min_y;
1133 	float reorient_max_x;
1134 	float reorient_max_angle;
1135 	float reorient_min_angle;
1136 	float reorient_max_rot_angle;
1137 
1138 	// Landing response parameters
1139 	float reorient_mult;		// How quickly the ship will reorient towards it's resting position
1140 	float landing_rest_angle;	// The vertical angle where the ship's orientation comes to rest
1141 	int landing_sound_idx;		//Sound to play on successful landing collisions
1142 
1143 } ship_collision_physics;
1144 
1145 typedef struct path_metadata {
1146 	vec3d departure_rvec;
1147 } path_metadata;
1148 
1149 // The real FreeSpace ship_info struct.
1150 // NOTE: Can't be treated as a struct anymore, since it has STL data structures in its object tree!
1151 class ship_info
1152 {
1153 public:
1154 	char		name[NAME_LENGTH];				// name for the ship
1155 	char		alt_name[NAME_LENGTH];			// display another name for the ship
1156 	char		short_name[NAME_LENGTH];		// short name, for use in the editor?
1157 	int			species;								// which species this craft belongs to
1158 	int			class_type;						//For type table
1159 
1160 	char		*type_str;							// type string used by tooltips
1161 	char		*maneuverability_str;			// string used by tooltips
1162 	char		*armor_str;							// string used by tooltips
1163 	char		*manufacturer_str;				// string used by tooltips
1164 	char		*desc;								// string used by tooltips
1165 	char		*tech_desc;							// string used by tech database
1166 	char		tech_title[NAME_LENGTH];			// ship's name (in tech database)
1167 
1168 	char     *ship_length;						// string used by multiplayer ship desc
1169 	char     *gun_mounts;			         // string used by multiplayer ship desc
1170 	char     *missile_banks;					// string used by multiplayer ship desc
1171 
1172 	char		cockpit_pof_file[MAX_FILENAME_LEN];	// POF file for cockpit view
1173 	vec3d		cockpit_offset;
1174 	char		pof_file[MAX_FILENAME_LEN];			// POF file to load/associate with ship
1175 	char		pof_file_hud[MAX_FILENAME_LEN];		// POF file to load for the HUD target box
1176 	int		num_detail_levels;				// number of detail levels for this ship
1177 	int		detail_distance[MAX_SHIP_DETAIL_LEVELS];					// distance to change detail levels at
1178 	int		cockpit_model_num;					// cockpit model
1179 	int		model_num;							// ship model
1180 	int		model_num_hud;						// model to use when rendering to the HUD (eg, mini supercap)
1181 	int		hud_target_lod;						// LOD to use for rendering to the HUD targetbox (if not already using special HUD model)
1182 	float		density;								// density of the ship in g/cm^3 (water  = 1)
1183 	float		damp;									// drag
1184 	float		rotdamp;								// rotational drag
1185 	float		delta_bank_const;
1186 	vec3d	max_vel;								//	max velocity of the ship in the linear directions -- read from ships.tbl
1187 	vec3d	max_rotvel;							// maximum rotational velocity
1188 	vec3d	rotation_time;						// time to rotate in x/y/z dimension traveling at max rotvel
1189 	float		srotation_time;					//	scalar, computed at runtime as (rotation_time.x + rotation_time.y)/2
1190 	float		max_rear_vel;						// max speed ship can go backwards.
1191 	float		forward_accel;
1192 	float		forward_decel;
1193 	float		slide_accel;
1194 	float		slide_decel;
1195 
1196 	char		warpin_anim[MAX_FILENAME_LEN];
1197 	float		warpin_radius;
1198 	int			warpin_snd_start;
1199 	int			warpin_snd_end;
1200 	float		warpin_speed;
1201 	int			warpin_time;	//in ms
1202 	float		warpin_decel_exp;
1203 	int			warpin_type;
1204 
1205 	char		warpout_anim[MAX_FILENAME_LEN];
1206 	float		warpout_radius;
1207 	int			warpout_snd_start;
1208 	int			warpout_snd_end;
1209 	int			warpout_engage_time;	//in ms
1210 	float		warpout_speed;
1211 	int			warpout_time;	//in ms
1212 	float		warpout_accel_exp;
1213 	int			warpout_type;
1214 
1215 	float		warpout_player_speed;
1216 
1217 	int		flags;							//	See SIF_xxxx - changed to uint by Goober5000, changed back by Zacam
1218 	int		flags2;							//	See SIF2_xxxx - added by Goober5000, changed by Zacam
1219 	int		ai_class;							//	Index into Ai_classes[].  Defined in ai.tbl
1220 	float		max_speed, min_speed, max_accel;
1221 
1222 	//Collision
1223 	int						collision_damage_type_idx;
1224 	ship_collision_physics	collision_physics;
1225 
1226 	// ship explosion info
1227 	shockwave_create_info shockwave;
1228 	int	explosion_propagates;				// If true, then the explosion propagates
1229 	float big_exp_visual_rad;				//SUSHI: The visual size of the main explosion
1230 	float prop_exp_rad_mult;				// propagating explosions radius multiplier
1231 	float death_roll_r_mult;
1232 	float death_fx_r_mult;
1233 	float death_roll_time_mult;
1234 	int death_roll_base_time;
1235 	int death_fx_count;
1236 	int	shockwave_count;					// the # of total shockwaves
1237 	SCP_vector<int> explosion_bitmap_anims;
1238 	float vaporize_chance;
1239 
1240 	particle_effect		impact_spew;
1241 	particle_effect		damage_spew;
1242 	particle_effect		split_particles;
1243 	particle_effect		knossos_end_particles;
1244 	particle_effect		regular_end_particles;
1245 
1246 	//Debris stuff
1247 	float			debris_min_lifetime;
1248 	float			debris_max_lifetime;
1249 	float			debris_min_speed;
1250 	float			debris_max_speed;
1251 	float			debris_min_rotspeed;
1252 	float			debris_max_rotspeed;
1253 	int				debris_damage_type_idx;
1254 	float			debris_min_hitpoints;
1255 	float			debris_max_hitpoints;
1256 	float			debris_damage_mult;
1257 	float			debris_arc_percent;
1258 
1259 	// subsystem information
1260 	int		n_subsystems;						// this number comes from ships.tbl
1261 	model_subsystem *subsystems;				// see model.h for structure definition
1262 
1263 	// Energy Transfer System fields
1264 	float		power_output;					// power output of ships reactor (EU/s)
1265 	float		max_overclocked_speed;			// max speed when 100% power output sent to engines
1266 	float		max_weapon_reserve;				// maximum energy that can be stored for primary weapon usage
1267 	float		max_shield_regen_per_second;	// Goober5000 - max percent/100 of shield energy regenerated per second
1268 	float		max_weapon_regen_per_second;	// Goober5000 - max percent/100 of weapon energy regenerated per second
1269 
1270 	// Afterburner fields
1271 	vec3d		afterburner_max_vel;				//	max velocity of the ship in the linear directions when afterburners are engaged -- read from ships.tbl
1272 	float		afterburner_forward_accel;		// forward acceleration with afterburner engaged
1273 	float		afterburner_fuel_capacity;		// maximum afterburner fuel that can be stored
1274 	float		afterburner_burn_rate;			// rate in fuel/second that afterburner consumes fuel
1275 	float		afterburner_recover_rate;		//	rate in fuel/second that afterburner recovers fuel
1276 	//SparK: reverse afterburner
1277 	float		afterburner_max_reverse_vel;
1278 	float		afterburner_reverse_accel;
1279 
1280 	int		cmeasure_type;						// Type of countermeasures this ship carries
1281 	int		cmeasure_max;						//	Number of charges of countermeasures this ship can hold.
1282 
1283 	int num_primary_banks;										// Actual number of primary banks (property of model)
1284 	int primary_bank_weapons[MAX_SHIP_PRIMARY_BANKS];			// Weapon_info[] index for the weapon in the bank
1285 	// Goober5000's ballistic conversion
1286 	int primary_bank_ammo_capacity[MAX_SHIP_PRIMARY_BANKS];	// Capacity of primary ballistic bank
1287 
1288 	int num_secondary_banks;									//	Actual number of secondary banks (property of model)
1289 	int secondary_bank_weapons[MAX_SHIP_SECONDARY_BANKS];	// Weapon_info[] index for the weapon in the bank
1290 	int secondary_bank_ammo_capacity[MAX_SHIP_SECONDARY_BANKS];	// Capacity of bank (not number of missiles)
1291 
1292 	bool draw_primary_models[MAX_SHIP_PRIMARY_BANKS];
1293 	bool draw_secondary_models[MAX_SHIP_SECONDARY_BANKS];
1294 	float weapon_model_draw_distance;
1295 
1296 	float	max_hull_strength;				// Max hull strength of this class of ship.
1297 	float	max_shield_strength;
1298 	float	auto_shield_spread;
1299 	bool	auto_shield_spread_bypass;
1300 	int		auto_shield_spread_from_lod;
1301 
1302 	int		shield_point_augment_ctrls[4];	// Re-mapping of shield augmentation controls for model point shields
1303 
1304 	float	hull_repair_rate;				//How much of the hull is repaired every second
1305 	float	subsys_repair_rate;		//How fast
1306 
1307 	float	sup_hull_repair_rate;
1308 	float	sup_shield_repair_rate;
1309 	float	sup_subsys_repair_rate;
1310 
1311 	vec3d	closeup_pos;					// position for camera when using ship in closeup view (eg briefing and hud target monitor)
1312 	float		closeup_zoom;					// zoom when using ship in closeup view (eg briefing and hud target monitor)
1313 
1314 	int		allowed_weapons[MAX_WEAPON_TYPES];	// array which specifies which weapons can be loaded out by the
1315 												// player during weapons loadout.
1316 
1317 	// Goober5000 - fix for restricted banks mod
1318 	int restricted_loadout_flag[MAX_SHIP_WEAPONS];
1319 	int allowed_bank_restricted_weapons[MAX_SHIP_WEAPONS][MAX_WEAPON_TYPES];
1320 
1321 	ubyte	shield_icon_index;				// index to locate ship-specific animation frames for the shield on HUD
1322 	char	icon_filename[MAX_FILENAME_LEN];	// filename for icon that is displayed in ship selection
1323 	char	anim_filename[MAX_FILENAME_LEN];	// filename for animation that plays in ship selection
1324 	char	overhead_filename[MAX_FILENAME_LEN];	// filename for animation that plays weapons loadout
1325 	int 	selection_effect;
1326 
1327 	int bii_index_ship;						// if this ship has a briefing icon that overrides the normal icon set
1328 	int bii_index_ship_with_cargo;
1329 	int bii_index_wing;
1330 	int bii_index_wing_with_cargo;
1331 
1332 	int	score;								// default score for this ship
1333 
1334 	int	scan_time;							// time to scan this ship (in ms)
1335 
1336 	// contrail info
1337 	trail_info ct_info[MAX_SHIP_CONTRAILS];
1338 	int ct_count;
1339 
1340 	// rgb non-dimming pixels for this ship type
1341 	int num_nondark_colors;
1342 	ubyte nondark_colors[MAX_NONDARK_COLORS][3];
1343 
1344 	// rgb shield color
1345 	ubyte shield_color[3];
1346 
1347 	// HW2-style team coloring
1348 	bool uses_team_colors;
1349 	SCP_string default_team_name;
1350 
1351 	// optional afterburner trail values
1352 	generic_bitmap afterburner_trail;
1353 	float afterburner_trail_width_factor;
1354 	float afterburner_trail_alpha_factor;
1355 	float afterburner_trail_life;
1356 	int afterburner_trail_faded_out_sections;
1357 
1358 	// thruster particles
1359 	SCP_vector<thruster_particles> normal_thruster_particles;
1360 	SCP_vector<thruster_particles> afterburner_thruster_particles;
1361 
1362 	// Bobboau's extra thruster stuff
1363 	thrust_pair			thruster_flame_info;
1364 	thrust_pair			thruster_glow_info;
1365 	thrust_pair_bitmap	thruster_secondary_glow_info;
1366 	thrust_pair_bitmap	thruster_tertiary_glow_info;
1367 	thrust_pair_bitmap	thruster_distortion_info;
1368 
1369 	float		thruster01_glow_rad_factor;
1370 	float		thruster02_glow_rad_factor;
1371 	float		thruster03_glow_rad_factor;
1372 	float		thruster02_glow_len_factor;
1373 	float		thruster_dist_rad_factor;
1374 	float		thruster_dist_len_factor;
1375 
1376 	bool		draw_distortion;
1377 
1378 	int splodeing_texture;
1379 	char splodeing_texture_name[MAX_FILENAME_LEN];
1380 
1381 
1382 	int armor_type_idx;
1383 	int shield_armor_type_idx;
1384 
1385 	bool can_glide;
1386 	float glide_cap;	//Backslash - for 'newtonian'-style gliding, the cap on velocity
1387 	bool glide_dynamic_cap;	//SUSHI: Whether or not we are using a dynamic glide cap
1388 	float glide_accel_mult;	//SUSHI: acceleration multiplier for glide mode
1389 	bool use_newtonian_damp; //SUSHI: Whether or not to use newtonian dampening for this ship
1390 	bool newtonian_damp_override;
1391 
1392 	float autoaim_fov;
1393 
1394 	bool topdown_offset_def;
1395 	vec3d topdown_offset;
1396 
1397 	int engine_snd;							// handle to engine sound for ship (-1 if no engine sound)
1398 	int glide_start_snd;					// handle to sound to play at the beginning of a glide maneuver (default is 0 for regular throttle down sound)
1399 	int glide_end_snd;						// handle to sound to play at the end of a glide maneuver (default is 0 for regular throttle up sound)
1400 
1401 	SCP_map<GameSoundsIndex, int> ship_sounds;			// specifies ship-specific sound indexes
1402 
1403 	int num_maneuvering;
1404 	man_thruster maneuvering[MAX_MAN_THRUSTERS];
1405 
1406 	int radar_image_2d_idx;
1407 	int radar_color_image_2d_idx;
1408 	int radar_image_size;
1409 	float radar_projection_size_mult;
1410 
1411 	int ship_iff_info[MAX_IFFS][MAX_IFFS];
1412 
1413 	int aiming_flags;
1414 	float minimum_convergence_distance;
1415 	float convergence_distance;
1416 	vec3d convergence_offset;
1417 
1418 	float emp_resistance_mod;
1419 
1420 	float piercing_damage_draw_limit;
1421 
1422 	int damage_lightning_type;
1423 
1424 	SCP_vector<HudGauge*> hud_gauges;
1425 	bool hud_enabled;
1426 	bool hud_retail;
1427 
1428 	SCP_vector<cockpit_display_info> displays;
1429 
1430 	SCP_map<SCP_string, path_metadata> pathMetadata;
1431 };
1432 
1433 extern int Num_wings;
1434 extern ship Ships[MAX_SHIPS];
1435 extern ship	*Player_ship;
1436 extern int	*Player_cockpit_textures;
1437 
1438 // Data structure to track the active missiles
1439 typedef struct ship_obj {
1440 	ship_obj		 *next, *prev;
1441 	int			flags, objnum;
1442 } ship_obj;
1443 extern ship_obj Ship_obj_list;
1444 
1445 typedef struct engine_wash_info
1446 {
1447 	char		name[NAME_LENGTH];
1448 	float		angle;			// half angle of cone around engine thruster
1449 	float		radius_mult;	// multiplier for radius
1450 	float		length;			// length of engine wash, measured from thruster
1451 	float		intensity;		// intensity of engine wash
1452 
1453 } engine_wash_info;
1454 
1455 extern SCP_vector<engine_wash_info> Engine_wash_info;
1456 
1457 // flags defined for wings
1458 #define MAX_WING_FLAGS				8				// total number of flags in the wing structure -- used for parsing wing flags
1459 #define WF_WING_GONE					(1<<0)		// all ships were either destroyed or departed
1460 #define WF_WING_DEPARTING			(1<<1)		// wing's departure cue turned true
1461 #define WF_IGNORE_COUNT				(1<<2)		// ignore all ships in this wing for goal counting purposes.
1462 #define WF_REINFORCEMENT			(1<<3)		// is this wing a reinforcement wing
1463 #define WF_RESET_REINFORCEMENT	(1<<4)		// needed when we need to reset the wing's reinforcement flag (after calling it in)
1464 #define WF_NO_ARRIVAL_MUSIC		(1<<5)		// don't play arrival music when wing arrives
1465 #define WF_EXPANDED					(1<<6)		// wing expanded in hotkey select screen
1466 #define WF_NO_ARRIVAL_MESSAGE		(1<<7)		// don't play any arrival message
1467 #define WF_NO_ARRIVAL_WARP			(1<<8)		// don't play warp effect for any arriving ships in this wing.
1468 #define WF_NO_DEPARTURE_WARP		(1<<9)		// don't play warp effect for any departing ships in this wing.
1469 #define WF_NO_DYNAMIC				(1<<10)		// members of this wing relentlessly pursue their ai goals
1470 #define WF_DEPARTURE_ORDERED		(1<<11)		// departure of this wing was ordered by player
1471 #define WF_NEVER_EXISTED			(1<<12)		// this wing never existed because something prevented it from being created (like its mother ship being destroyed)
1472 #define WF_NAV_CARRY				(1<<13)		// Kazan - Wing has nav-carry-status
1473 
1474 //	Defines a wing of ships.
1475 typedef struct wing {
1476 	char	name[NAME_LENGTH];
1477 	char	wing_squad_filename[MAX_FILENAME_LEN];	// Goober5000
1478 	int	reinforcement_index;					// index in reinforcement struct or -1
1479 	int	hotkey;
1480 
1481 	int	num_waves, current_wave;			// members for dealing with waves
1482 	int	threshold;								// when number of ships in the wing reaches this number -- new wave
1483 
1484 	fix	time_gone;								// time into the mission when this wing is officially gone.
1485 
1486 	int	wave_count;								// max ships per wave (as defined by the number of ships in the ships list)
1487 	int	total_arrived_count;					// count of number of ships that we have created, regardless of wave
1488 	int red_alert_skipped_ships;				// Goober5000 - if we skipped over any indexes while creating red-alert ships
1489 	int	current_count;							// count of number of ships actually in this wing -- used for limit in next array
1490 	int	ship_index[MAX_SHIPS_PER_WING];	// index into ships array of all ships currently in the wing
1491 
1492 	int	total_destroyed;						// total number of ships destroyed in the wing (including all waves)
1493 	int	total_departed;						// total number of ships departed in this wing (including all waves)
1494 	int total_vanished;						// total number of ships vanished in this wing (including all waves)
1495 
1496 	int	special_ship;							// the leader of the wing.  An index into ship_index[].
1497 
1498 	int	arrival_location;						// arrival and departure information for wings -- similar to info for ships
1499 	int	arrival_distance;						// distance from some ship where this ship arrives
1500 	int	arrival_anchor;						// name of object this ship arrives near (or in front of)
1501 	int	arrival_path_mask;					// Goober5000 - possible restrictions on which bay paths to use
1502 	int	arrival_cue;
1503 	int	arrival_delay;
1504 
1505 	int	departure_location;
1506 	int	departure_anchor;						// name of object that we depart to (in case of dock bays)
1507 	int departure_path_mask;				// Goober5000 - possible restrictions on which bay paths to use
1508 	int	departure_cue;
1509 	int	departure_delay;
1510 
1511 	int	wave_delay_min;						// minimum number of seconds before new wave can arrive
1512 	int	wave_delay_max;						// maximum number of seconds before new wave can arrive
1513 	int	wave_delay_timestamp;				// timestamp used for delaying arrival of next wave
1514 
1515 	int flags;
1516 
1517 	ai_goal	ai_goals[MAX_AI_GOALS];			// goals for the wing -- converted to ai_goal struct
1518 
1519 	ushort	net_signature;						// starting net signature for ships in this wing. assiged at mission load time
1520 
1521 	// Goober5000 - if this wing has a unique squad logo
1522 	// it's specified for the wing rather than each individual ship to cut down on the amount
1523 	// of stuff that needs to be sitting in memory at once - each ship uses the wing texture;
1524 	// and it also makes practical sense: no wing has two different squadrons in it :)
1525 	int wing_insignia_texture;
1526 } wing;
1527 
1528 extern wing Wings[MAX_WINGS];
1529 
1530 extern int Starting_wings[MAX_STARTING_WINGS];
1531 extern int Squadron_wings[MAX_SQUADRON_WINGS];
1532 extern int TVT_wings[MAX_TVT_WINGS];
1533 
1534 extern char Starting_wing_names[MAX_STARTING_WINGS][NAME_LENGTH];
1535 extern char Squadron_wing_names[MAX_SQUADRON_WINGS][NAME_LENGTH];
1536 extern char TVT_wing_names[MAX_TVT_WINGS][NAME_LENGTH];
1537 
1538 extern int ai_paused;
1539 extern int CLOAKMAP;
1540 
1541 extern int Num_reinforcements;
1542 extern int Num_ship_classes;
1543 extern ship_info Ship_info[MAX_SHIP_CLASSES];
1544 extern reinforcements Reinforcements[MAX_REINFORCEMENTS];
1545 
1546 // structure definition for ship type counts.  Used to give a count of the number of ships
1547 // of a particular type, and the number of times that a ship of that particular type has been
1548 // killed.  When changing any info here, be sure to update the ship_type_names array in Ship.cpp
1549 // the order of the types here MUST match the order of the types in the array
1550 typedef struct ship_counts {
1551 	int	total;
1552 	int	killed;
ship_countsship_counts1553 	ship_counts(){total=0;killed=0;}
1554 } ship_counts;
1555 
1556 extern SCP_vector<ship_counts> Ship_type_counts;
1557 
1558 
1559 // Use the below macros when you want to find the index of an array element in the
1560 // Wings[] or Ships[] arrays.
1561 #define WING_INDEX(wingp) (wingp-Wings)
1562 #define SHIP_INDEX(shipp) (shipp-Ships)
1563 
1564 
1565 extern void ship_init();				// called once	at game start
1566 extern void ship_level_init();		// called before the start of each level
1567 
1568 //returns -1 if failed
1569 extern int ship_create(matrix * orient, vec3d * pos, int ship_type, char *ship_name = NULL);
1570 extern void change_ship_type(int n, int ship_type, int by_sexp = 0);
1571 extern void ship_model_change(int n, int ship_type);
1572 extern void ship_process_pre( object * objp, float frametime );
1573 extern void ship_process_post( object * objp, float frametime );
1574 extern void ship_render( object * objp );
1575 extern void ship_render_cockpit( object * objp);
1576 extern void ship_render_show_ship_cockpit( object * objp);
1577 extern void ship_delete( object * objp );
1578 extern int ship_check_collision_fast( object * obj, object * other_obj, vec3d * hitpos );
1579 extern int ship_get_num_ships();
1580 
1581 #define SHIP_VANISHED			(1<<0)
1582 #define SHIP_DESTROYED			(1<<1)
1583 #define SHIP_DEPARTED_WARP		(1<<2)
1584 #define SHIP_DEPARTED_BAY		(1<<3)
1585 #define SHIP_DEPARTED			( SHIP_DEPARTED_BAY | SHIP_DEPARTED_WARP )
1586 // Goober5000
1587 extern void ship_cleanup(int shipnum, int cleanup_mode);
1588 extern void ship_destroy_instantly(object *ship_obj, int shipnum);
1589 extern void ship_actually_depart(int shipnum, int method = SHIP_DEPARTED_WARP);
1590 
1591 extern int ship_fire_primary_debug(object *objp);	//	Fire the debug laser.
1592 extern int ship_stop_fire_primary(object * obj);
1593 extern int ship_fire_primary(object * objp, int stream_weapons, int force = 0);
1594 extern int ship_fire_secondary(object * objp, int allow_swarm = 0 );
1595 extern int ship_launch_countermeasure(object *objp, int rand_val = -1);
1596 
1597 // for special targeting lasers
1598 extern void ship_start_targeting_laser(ship *shipp);
1599 extern void ship_stop_targeting_laser(ship *shipp);
1600 extern void ship_process_targeting_lasers();
1601 
1602 extern int ship_select_next_primary(object *objp, int direction);
1603 extern int  ship_select_next_secondary(object *objp);
1604 
1605 // Goober5000
1606 extern int get_available_primary_weapons(object *objp, int *outlist, int *outbanklist);
1607 
1608 extern int get_available_secondary_weapons(object *objp, int *outlist, int *outbanklist);
1609 extern void ship_recalc_subsys_strength( ship *shipp );
1610 extern int subsys_set(int objnum, int ignore_subsys_info = 0);
1611 extern void physics_ship_init(object *objp);
1612 
1613 //	Note: This is not a general purpose routine.
1614 //	It is specifically used for targeting.
1615 //	It only returns a subsystem position if it has shields.
1616 //	Return true/false for subsystem found/not found.
1617 //	Stuff vector *pos with absolute position.
1618 extern int get_subsystem_pos(vec3d *pos, object *objp, ship_subsys *subsysp);
1619 
1620 //Template stuff, here's as good a place as any.
1621 int parse_ship_values(ship_info* sip, bool isTemplate, bool first_time, bool replace);
1622 extern int ship_template_lookup(const char *name = NULL);
1623 void parse_ship_particle_effect(ship_info* sip, particle_effect* pe, char *id_string);
1624 
1625 extern int ship_info_lookup(const char *name = NULL);
1626 extern int ship_name_lookup(const char *name, int inc_players = 0);	// returns the index into Ship array of name
1627 extern int ship_type_name_lookup(const char *name);
1628 
1629 extern int wing_lookup(const char *name);
1630 
1631 // returns 0 if no conflict, 1 if conflict, -1 on some kind of error with wing struct
1632 extern int wing_has_conflicting_teams(int wing_index);
1633 
1634 // next function takes optional second parameter which says to ignore the current count of ships
1635 // in the wing -- used to tell is the wing exists or not, not whether it exists and has ships currently
1636 // present.
1637 extern int wing_name_lookup(const char *name, int ignore_count = 0);
1638 
1639 // for generating a ship name for arbitrary waves/indexes of that wing... correctly handles the # character
1640 extern void wing_bash_ship_name(char *ship_name, const char *wing_name, int index);
1641 
1642 extern int Player_ship_class;
1643 
1644 //	Do the special effect for energy dissipating into the shield for a hit.
1645 //	model_num	= index in Polygon_models[]
1646 //	centerp		= pos of object, sort of the center of the shield
1647 //	tcp			= hit point, probably the global hit_point set in polygon_check_face
1648 //	tr0			= index of polygon in shield pointer in polymodel.
1649 extern void create_shield_explosion(int objnum, int model_num, matrix *orient, vec3d *centerp, vec3d *tcp, int tr0);
1650 
1651 //	Initialize shield hit system.
1652 extern void shield_hit_init();
1653 extern void create_shield_explosion_all(object *objp);
1654 extern void shield_frame_init();
1655 extern void add_shield_point(int objnum, int tri_num, vec3d *hit_pos);
1656 extern void add_shield_point_multi(int objnum, int tri_num, vec3d *hit_pos);
1657 extern void shield_point_multi_setup();
1658 extern void shield_hit_close();
1659 
1660 void ship_draw_shield( object *objp);
1661 
1662 float apply_damage_to_shield(object *objp, int quadrant, float damage);
1663 float compute_shield_strength(object *objp);
1664 
1665 // Returns true if the shield presents any opposition to something
1666 // trying to force through it.
1667 // If quadrant is -1, looks at entire shield, otherwise
1668 // just one quadrant
1669 int ship_is_shield_up( object *obj, int quadrant );
1670 
1671 //=================================================
1672 // These two functions transfer instance specific angle
1673 // data into and out of the model structure, which contains
1674 // angles, but not for each instance of model being used. See
1675 // the actual functions in ship.cpp for more details.
1676 extern void ship_model_start(object *objp);
1677 extern void ship_model_stop(object *objp);
1678 void ship_model_update_instance(object *objp);
1679 
1680 //============================================
1681 extern int ship_find_num_crewpoints(object *objp);
1682 extern int ship_find_num_turrets(object *objp);
1683 
1684 extern void compute_slew_matrix(matrix *orient, angles *a);
1685 //extern camid ship_set_eye( object *obj, int eye_index);
1686 extern void ship_set_eye(object *obj, int eye_index);
1687 extern void ship_get_eye( vec3d *eye_pos, matrix *eye_orient, object *obj, bool do_slew = true, bool from_origin = false);		// returns in eye the correct viewing position for the given object
1688 //extern camid ship_get_followtarget_eye(object *obj);
1689 extern ship_subsys *ship_get_indexed_subsys( ship *sp, int index, vec3d *attacker_pos = NULL );	// returns index'th subsystem of this ship
1690 extern int ship_get_index_from_subsys(ship_subsys *ssp, int objnum, int error_bypass = 0);
1691 extern int ship_get_subsys_index(ship *sp, char *ss_name, int error_bypass = 0);		// returns numerical index in linked list of subsystems
1692 extern float ship_get_subsystem_strength( ship *shipp, int type );
1693 extern ship_subsys *ship_get_subsys(ship *shipp, char *subsys_name);
1694 extern int ship_get_num_subsys(ship *shipp);
1695 extern ship_subsys *ship_get_closest_subsys_in_sight(ship *sp, int subsys_type, vec3d *attacker_pos);
1696 
1697 //WMC
1698 char *ship_subsys_get_name(ship_subsys *ss);
1699 bool ship_subsys_has_instance_name(ship_subsys *ss);
1700 void ship_subsys_set_name(ship_subsys *ss, char *n_name);
1701 
1702 // subsys disruption
1703 extern int ship_subsys_disrupted(ship_subsys *ss);
1704 extern int ship_subsys_disrupted(ship *sp, int type);
1705 extern void ship_subsys_set_disrupted(ship_subsys *ss, int time);
1706 
1707 extern int	ship_do_rearm_frame( object *objp, float frametime );
1708 extern float ship_calculate_rearm_duration( object *objp );
1709 extern void	ship_wing_cleanup( int shipnum, wing *wingp );
1710 
1711 extern int ship_find_repair_ship( object *requester_obj, object **ship_we_found = NULL );
1712 extern void ship_close();	// called in game_shutdown() to free malloced memory
1713 
1714 
1715 extern void ship_assign_sound_all();
1716 extern void ship_assign_sound(ship *sp);
1717 
1718 extern void ship_clear_ship_type_counts();
1719 extern void ship_add_ship_type_count( int ship_info_index, int num );
1720 extern void ship_add_ship_type_kill_count( int ship_info_index );
1721 
1722 extern int ship_get_type(char* output, ship_info* sip);
1723 extern int ship_get_default_orders_accepted( ship_info *sip );
1724 extern int ship_query_general_type(int ship);
1725 extern int ship_class_query_general_type(int ship_class);
1726 extern int ship_query_general_type(ship *shipp);
1727 extern int ship_docking_valid(int docker, int dockee);
1728 extern int get_quadrant(vec3d *hit_pnt, object *shipobjp = NULL);	//	Return quadrant num of given hit point.
1729 
1730 extern void ship_obj_list_rebuild();	// only called by save/restore code
1731 extern int ship_query_state(char *name);
1732 
1733 // Goober5000
1734 int ship_primary_bank_has_ammo(int shipnum);	// check if current primary bank has ammo
1735 int ship_secondary_bank_has_ammo(int shipnum);	// check if current secondary bank has ammo
1736 
1737 int ship_engine_ok_to_warp(ship *sp);		// check if ship has engine power to warp
1738 int ship_navigation_ok_to_warp(ship *sp);	// check if ship has navigation power to warp
1739 
1740 int ship_return_subsys_path_normal(ship *sp, ship_subsys *ss, vec3d *gsubpos, vec3d *norm);
1741 int ship_subsystem_in_sight(object* objp, ship_subsys* subsys, vec3d *eye_pos, vec3d* subsys_pos, int do_facing_check=1, float *dot_out=NULL, vec3d *vec_out=NULL);
1742 ship_subsys *ship_return_next_subsys(ship *shipp, int type, vec3d *attacker_pos);
1743 
1744 // defines and definition for function to get a random ship of a particular team (any ship,
1745 // any ship but player ships, or only players)
1746 #define SHIP_GET_ANY_SHIP				0
1747 #define SHIP_GET_NO_PLAYERS				1
1748 #define SHIP_GET_ONLY_PLAYERS			2
1749 #define SHIP_GET_UNSILENCED				3	// Karajorma - Returns no_players that can send builtin messages.
1750 
1751 
1752 extern int ship_get_random_team_ship(int team_mask, int flags = SHIP_GET_ANY_SHIP, float max_dist = 0.0f);
1753 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);
1754 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);
1755 
1756 // return ship index
1757 int ship_get_random_targetable_ship();
1758 
1759 extern int ship_get_by_signature(int signature);
1760 
1761 #ifndef NDEBUG
1762 extern int Ai_render_debug_flag;
1763 extern int Show_shield_mesh;
1764 extern int Ship_auto_repair;	// flag to indicate auto-repair of subsystem should occur
1765 #endif
1766 
1767 void ship_subsystem_delete(ship *shipp);
1768 void ship_set_default_weapons(ship *shipp, ship_info *sip);
1769 float ship_quadrant_shield_strength(object *hit_objp, vec3d *hitpos);
1770 
1771 int ship_dumbfire_threat(ship *sp);
1772 int ship_lock_threat(ship *sp);
1773 
1774 int	bitmask_2_bitnum(int num);
1775 char	*ship_return_orders(char *outbuf, ship *sp);
1776 char	*ship_return_time_to_goal(char *outbuf, ship *sp);
1777 
1778 void	ship_maybe_warn_player(ship *enemy_sp, float dist);
1779 void	ship_maybe_praise_player(ship *deader_sp);
1780 void	ship_maybe_praise_self(ship *deader_sp, ship *killer_sp);
1781 void	ship_maybe_ask_for_help(ship *sp);
1782 void	ship_scream(ship *sp);
1783 void	ship_maybe_scream(ship *sp);
1784 void	ship_maybe_tell_about_rearm(ship *sp);
1785 void	ship_maybe_tell_about_low_ammo(ship *sp);
1786 void	ship_maybe_lament();
1787 
1788 void ship_primary_changed(ship *sp);
1789 void ship_secondary_changed(ship *sp);
1790 
1791 // get the Ship_info flags for a given ship
1792 int ship_get_SIF(ship *shipp);
1793 int ship_get_SIF(int sh);
1794 
1795 // get the ship type info (objecttypes.tbl)
1796 ship_type_info *ship_get_type_info(object *objp);
1797 
1798 extern void ship_do_cargo_revealed( ship *shipp, int from_network = 0 );
1799 extern void ship_do_cargo_hidden( ship *shipp, int from_network = 0 );
1800 extern void ship_do_cap_subsys_cargo_revealed( ship *shipp, ship_subsys *subsys, int from_network = 0);
1801 extern void ship_do_cap_subsys_cargo_hidden( ship *shipp, ship_subsys *subsys, int from_network = 0);
1802 
1803 float ship_get_secondary_weapon_range(ship *shipp);
1804 
1805 // Goober5000
1806 int primary_out_of_ammo(ship_weapon *swp, int bank);
1807 int get_max_ammo_count_for_primary_bank(int ship_class, int bank, int ammo_type);
1808 
1809 int get_max_ammo_count_for_bank(int ship_class, int bank, int ammo_type);
1810 
1811 int is_support_allowed(object *objp, bool do_simple_check = false);
1812 
1813 // Given an object and a turret on that object, return the actual firing point of the gun
1814 // and its normal.   This uses the current turret angles.  We are keeping track of which
1815 // gun to fire next in the ship specific info for this turret subobject.  Use this info
1816 // to determine which position to fire from next.
1817 //	Stuffs:
1818 //		*gpos: absolute position of gun firing point
1819 //		*gvec: vector fro *gpos to *targetp
1820 void ship_get_global_turret_gun_info(object *objp, ship_subsys *ssp, vec3d *gpos, vec3d *gvec, int use_angles, vec3d *targetp);
1821 
1822 //	Given an object and a turret on that object, return the global position and forward vector
1823 //	of the turret.   The gun normal is the unrotated gun normal, (the center of the FOV cone), not
1824 // the actual gun normal given using the current turret heading.  But it _is_ rotated into the model's orientation
1825 //	in global space.
1826 void ship_get_global_turret_info(object *objp, model_subsystem *tp, vec3d *gpos, vec3d *gvec);
1827 
1828 // return 1 if objp is in fov of the specified turret, tp.  Otherwise return 0.
1829 //	dist = distance from turret to center point of object
1830 int object_in_turret_fov(object *objp, ship_subsys *ss, vec3d *tvec, vec3d *tpos, float dist);
1831 
1832 // functions for testing fov.. returns true if fov test is passed.
1833 bool turret_std_fov_test(ship_subsys *ss, vec3d *gvec, vec3d *v2e, float size_mod = 0);
1834 bool turret_adv_fov_test(ship_subsys *ss, vec3d *gvec, vec3d *v2e, float size_mod = 0);
1835 bool turret_fov_test(ship_subsys *ss, vec3d *gvec, vec3d *v2e, float size_mod = 0);
1836 
1837 // function for checking adjusted turret rof
1838 float get_adjusted_turret_rof(ship_subsys *ss);
1839 
1840 // forcible jettison cargo from a ship
1841 void object_jettison_cargo(object *objp, object *cargo_objp);
1842 
1843 // get damage done by exploding ship, takes into account mods for individual ship
1844 float ship_get_exp_damage(object* objp);
1845 
1846 // get whether ship has shockwave, takes into account mods for individual ship
1847 int ship_get_exp_propagates(ship *sp);
1848 
1849 // get outer radius of damage, takes into account mods for individual ship
1850 float ship_get_exp_outer_rad(object *ship_objp);
1851 
1852 // externed by Goober5000
1853 extern int ship_explode_area_calc_damage( vec3d *pos1, vec3d *pos2, float inner_rad, float outer_rad, float max_damage, float max_blast, float *damage, float *blast );
1854 
1855 // returns whether subsys is allowed to have cargo
1856 int valid_cap_subsys_cargo_list(char *subsys_name);
1857 
1858 // determine turret status of a given subsystem, returns 0 for no turret, 1 for "fixed turret", 2 for "rotating" turret
1859 int ship_get_turret_type(ship_subsys *subsys);
1860 
1861 // get ship by object signature, returns OBJECT INDEX
1862 int ship_get_by_signature(int sig);
1863 
1864 // get the team of a reinforcement item
1865 int ship_get_reinforcement_team(int r_index);
1866 
1867 // determine if the given texture is used by a ship type. return ship info index, or -1 if not used by a ship
1868 int ship_get_texture(int bitmap);
1869 
1870 // page in bitmaps for all ships on a given level
1871 void ship_page_in();
1872 
1873 // Goober5000 - helper for above
1874 void ship_page_in_textures(int ship_index = -1);
1875 
1876 // fixer for above - taylor
1877 void ship_page_out_textures(int ship_index, bool release = false);
1878 
1879 // update artillery lock info
1880 void ship_update_artillery_lock();
1881 
1882 // checks if a world point is inside the extended bounding box of a ship
1883 int check_world_pt_in_expanded_ship_bbox(vec3d *world_pt, object *objp, float delta_box);
1884 
1885 // returns true if objp is ship and is tagged
1886 int ship_is_tagged(object *objp);
1887 
1888 // returns max normal speed of ship (overclocked / afterburned)
1889 float ship_get_max_speed(ship *shipp);
1890 
1891 // returns warpout speed of ship
1892 float ship_get_warpout_speed(object *objp);
1893 
1894 // returns true if ship is beginning to speed up in warpout
1895 int ship_is_beginning_warpout_speedup(object *objp);
1896 
1897 // return the length of the ship class
1898 float ship_class_get_length(ship_info *sip);
1899 
1900 // Goober5000 - used by change-ai-class
1901 extern void ship_set_new_ai_class(int ship_num, int new_ai_class);
1902 extern void ship_subsystem_set_new_ai_class(int ship_num, char *subsystem, int new_ai_class);
1903 
1904 // wing squad logos - Goober5000
1905 extern void wing_load_squad_bitmap(wing *w);
1906 
1907 // Goober5000 - needed by new hangar depart code
1908 extern bool ship_has_dock_bay(int shipnum);
1909 extern bool ship_useful_for_departure(int shipnum, int path_mask = 0);
1910 extern int ship_get_ship_for_departure(int team);
1911 
1912 // Goober5000 - moved here from hudbrackets.cpp
1913 extern bool ship_subsys_is_fighterbay(ship_subsys *ss);
1914 
1915 // Goober5000
1916 extern bool ship_fighterbays_all_destroyed(ship *shipp);
1917 
1918 // Goober5000
1919 extern bool ship_subsys_takes_damage(ship_subsys *ss);
1920 
1921 //phreak
1922 extern int ship_fire_tertiary(object *objp);
1923 
1924 // Goober5000 - handles submodel rotation, incorporating conditions such as gun barrels when firing
1925 extern void ship_do_submodel_rotation(ship *shipp, model_subsystem *psub, ship_subsys *pss);
1926 
1927 // Goober5000 - shortcut hud stuff
1928 extern int ship_has_energy_weapons(ship *shipp);
1929 extern int ship_has_engine_power(ship *shipp);
1930 
1931 // Swifty - Cockpit displays
1932 void ship_init_cockpit_displays(ship *shipp);
1933 void ship_add_cockpit_display(cockpit_display_info *display, int cockpit_model_num);
1934 void ship_set_hud_cockpit_targets();
1935 void ship_clear_cockpit_displays();
1936 int ship_start_render_cockpit_display(int cockpit_display_num);
1937 void ship_end_render_cockpit_display(int cockpit_display_num);
1938 
1939 //WMC - Warptype stuff
1940 int warptype_match(char *p);
1941 
1942 // Goober5000
1943 int ship_starting_wing_lookup(const char *wing_name);
1944 int ship_squadron_wing_lookup(const char *wing_name);
1945 int ship_tvt_wing_lookup(const char *wing_name);
1946 
1947 // Goober5000
1948 int ship_class_compare(int ship_class_1, int ship_class_2);
1949 
1950 int armor_type_get_idx(char* name);
1951 
1952 void armor_init();
1953 
1954 int thruster_glow_anim_load(generic_anim *ga);
1955 
1956 // Sushi - Path metadata
1957 void init_path_metadata(path_metadata& metadata);
1958 
1959 
1960 typedef struct ship_effect {
1961 	char name[NAME_LENGTH];
1962 	bool disables_rendering;
1963 	bool invert_timer;
1964 	int shader_effect;
1965 } ship_effect;
1966 
1967 extern SCP_vector<ship_effect> Ship_effects;
1968 
1969 /**
1970  *  @brief Returns a ship-specific sound index
1971  *
1972  *  @param objp An object pointer. Has to be of type OBJ_SHIP
1973  *  @param id A sound id as defined in gamsesnd.h. If the given id is unknown then the game_snd with the id as index is returned.
1974  *
1975  *  @return An index into the Snds vector, if the specified index could not be found then the id itself will be returned
1976  */
1977 int ship_get_sound(object *objp, GameSoundsIndex id);
1978 
1979 /**
1980  *  @brief Specifies if a ship has a custom sound for the specified id
1981  *
1982  *  @param objp An object pointer. Has to be of type OBJ_SHIP
1983  *  @param id A sound id as defined in gamsesnd.h
1984  *
1985  *  @return True if this object has the specified sound, false otherwise
1986  */
1987 bool ship_has_sound(object *objp, GameSoundsIndex id);
1988 
1989 /**
1990  * @brief Returns the index of the default player ship
1991  *
1992  * @return An index into Ship_info[], location of the default player ship.
1993  */
1994 int get_default_player_ship_index();
1995 
1996 /**
1997  * Given a ship with bounding box and a point, find the closest point on the bbox
1998  *
1999  * @param ship_obj Object that has the bounding box (should be a ship)
2000  * @param start World position of the point being compared
2001  * @param box_pt OUTPUT PARAMETER: closest point on the bbox to start
2002  *
2003  * @return point is inside bbox, TRUE/1
2004  * @return point is outside bbox, FALSE/0
2005  */
2006 int get_nearest_bbox_point(object *ship_obj, vec3d *start, vec3d *box_pt);
2007 
2008 #endif
2009