Line data Source code
1 0 : /*
2 :
3 : ShipEntity.h
4 :
5 : Entity subclass representing a ship, or various other flying things like cargo
6 : pods and stations (a subclass).
7 :
8 : Oolite
9 : Copyright (C) 2004-2013 Giles C Williams and contributors
10 :
11 : This program is free software; you can redistribute it and/or
12 : modify it under the terms of the GNU General Public License
13 : as published by the Free Software Foundation; either version 2
14 : of the License, or (at your option) any later version.
15 :
16 : This program is distributed in the hope that it will be useful,
17 : but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : GNU General Public License for more details.
20 :
21 : You should have received a copy of the GNU General Public License
22 : along with this program; if not, write to the Free Software
23 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 : MA 02110-1301, USA.
25 :
26 : */
27 :
28 : #import "OOEntityWithDrawable.h"
29 : #import "OOPlanetEntity.h"
30 : #import "OOJSPropID.h"
31 :
32 : @class OOColor, StationEntity, WormholeEntity, AI, Octree, OOMesh, OOScript,
33 : OOJSScript, OORoleSet, OOShipGroup, OOEquipmentType, OOWeakSet,
34 : OOExhaustPlumeEntity, OOFlasherEntity;
35 :
36 0 : #define MAX_TARGETS 24
37 0 : #define RAIDER_MAX_CARGO 5
38 0 : #define MERCHANTMAN_MAX_CARGO 125
39 :
40 0 : #define PIRATES_PREFER_PLAYER YES
41 :
42 0 : #define TURRET_MINIMUM_COS 0.20f
43 :
44 0 : #define SHIP_THRUST_FACTOR 5.0f
45 0 : #define AFTERBURNER_BURNRATE 0.25f
46 :
47 0 : #define CLOAKING_DEVICE_ENERGY_RATE 12.8f
48 0 : #define CLOAKING_DEVICE_MIN_ENERGY 128
49 0 : #define CLOAKING_DEVICE_START_ENERGY 0.75f
50 :
51 0 : #define MILITARY_JAMMER_ENERGY_RATE 3
52 0 : #define MILITARY_JAMMER_MIN_ENERGY 128
53 :
54 0 : #define COMBAT_IN_RANGE_FACTOR 0.035f
55 0 : #define COMBAT_BROADSIDE_IN_RANGE_FACTOR 0.020f
56 0 : #define COMBAT_OUT_RANGE_FACTOR 0.500f
57 0 : #define COMBAT_BROADSIDE_RANGE_FACTOR 0.900f
58 0 : #define COMBAT_WEAPON_RANGE_FACTOR 1.200f
59 0 : #define COMBAT_JINK_OFFSET 500.0f
60 :
61 0 : #define SHIP_COOLING_FACTOR 0.1f
62 : // heat taken from energy damage depends on mass
63 : // but limit maximum rate since masses vary so much
64 : // Cobra III ~=215000
65 0 : #define SHIP_ENERGY_DAMAGE_TO_HEAT_FACTOR (mass > 400000 ? 200000 / mass : 0.5)
66 0 : #define SHIP_INSULATION_FACTOR 0.00175f
67 0 : #define SHIP_MAX_CABIN_TEMP 256.0f
68 0 : #define SHIP_MIN_CABIN_TEMP 60.0f
69 0 : #define EJECTA_TEMP_FACTOR 0.85f
70 0 : #define DEFAULT_HYPERSPACE_SPIN_TIME 15.0f
71 :
72 0 : #define SUN_TEMPERATURE 1250.0f
73 :
74 0 : #define MAX_ESCORTS 16
75 0 : #define ESCORT_SPACING_FACTOR 3.0
76 :
77 0 : #define SHIPENTITY_MAX_MISSILES 32
78 :
79 0 : #define TURRET_TYPICAL_ENERGY 25.0f
80 0 : #define TURRET_SHOT_SPEED 2000.0f
81 0 : #define TURRET_SHOT_DURATION 3.0
82 0 : #define TURRET_SHOT_RANGE (TURRET_SHOT_SPEED * TURRET_SHOT_DURATION)
83 0 : #define TURRET_SHOT_FREQUENCY (TURRET_SHOT_DURATION * TURRET_SHOT_DURATION * TURRET_SHOT_DURATION / 100.0)
84 :
85 0 : #define NPC_PLASMA_SPEED 1500.0f
86 0 : #define MAIN_PLASMA_DURATION 5.0
87 0 : #define NPC_PLASMA_RANGE (MAIN_PLASMA_DURATION * NPC_PLASMA_SPEED)
88 :
89 0 : #define PLAYER_PLASMA_SPEED 1000.0f
90 0 : #define PLAYER_PLASMA_RANGE (MAIN_PLASMA_DURATION * PLAYER_PLASMA_SPEED)
91 :
92 0 : #define TRACTOR_FORCE 2500.0f
93 :
94 0 : #define AIMS_AGGRESSOR_SWITCHED_TARGET @"AGGRESSOR_SWITCHED_TARGET"
95 :
96 : // number of vessels considered when scanning around
97 0 : #define MAX_SCAN_NUMBER 32
98 :
99 0 : #define BASELINE_SHIELD_LEVEL 128.0f // Max shield level with no boosters.
100 0 : #define INITIAL_SHOT_TIME 100.0
101 :
102 0 : #define MIN_FUEL 0 // minimum fuel required for afterburner use
103 : #ifdef OO_DUMP_PLANETINFO
104 : // debugging planetinfo needs rapid jumping
105 : #define MAX_JUMP_RANGE 150.0
106 : #else
107 0 : #define MAX_JUMP_RANGE 7.0 // the 7 ly limit
108 : #endif
109 :
110 0 : #define ENTITY_PERSONALITY_MAX 0x7FFFU
111 0 : #define ENTITY_PERSONALITY_INVALID 0xFFFFU
112 :
113 :
114 0 : #define WEAPON_COOLING_FACTOR 6.0f
115 0 : #define NPC_MAX_WEAPON_TEMP 256.0f
116 0 : #define WEAPON_COOLING_CUTOUT 0.85f
117 :
118 0 : #define COMBAT_AI_WEAPON_TEMP_READY 0.25f * NPC_MAX_WEAPON_TEMP
119 0 : #define COMBAT_AI_WEAPON_TEMP_USABLE WEAPON_COOLING_CUTOUT * NPC_MAX_WEAPON_TEMP
120 : // factor determining how close to target AI has to be to be confident in aim
121 : // higher factor makes confident at longer ranges
122 0 : #define COMBAT_AI_CONFIDENCE_FACTOR 1250000.0f
123 0 : #define COMBAT_AI_ISNT_AWFUL 0.0f
124 : // removes BEHAVIOUR_ATTACK_FLY_TO_TARGET_SIX/TWELVE (unless thargoid)
125 0 : #define COMBAT_AI_IS_SMART 5.0f
126 : // adds BEHAVIOUR_(FLEE_)EVASIVE_ACTION
127 0 : #define COMBAT_AI_FLEES_BETTER 6.0f
128 : // adds BEHAVIOUR_ATTACK_BREAK_OFF_TARGET
129 0 : #define COMBAT_AI_DOGFIGHTER 6.5f
130 : // adds BEHAVIOUR_ATTACK_SLOW_DOGFIGHT
131 0 : #define COMBAT_AI_TRACKS_CLOSER 7.5f
132 0 : #define COMBAT_AI_USES_SNIPING 8.5f
133 : // adds BEHAVIOUR_ATTACK_SNIPER
134 0 : #define COMBAT_AI_FLEES_BETTER_2 9.0f
135 : // AI reacts to changes in target path in about 1.5 seconds.
136 0 : #define COMBAT_AI_STANDARD_REACTION_TIME 1.5f
137 :
138 :
139 :
140 0 : #define MAX_LANDING_SPEED 50.0
141 0 : #define MAX_LANDING_SPEED2 (MAX_LANDING_SPEED * MAX_LANDING_SPEED)
142 :
143 0 : #define MAX_COS 0.995 // cos(5 degrees) is close enough in most cases for navigation
144 0 : #define MAX_COS2 (MAX_COS * MAX_COS)
145 :
146 :
147 0 : #define ENTRY(label, value) label = value,
148 :
149 0 : typedef enum OOBehaviour
150 : {
151 : #include "OOBehaviour.tbl"
152 0 : } OOBehaviour;
153 :
154 : #undef ENTRY
155 :
156 :
157 : /*typedef enum
158 : {
159 : WEAPON_NONE = 0U,
160 : WEAPON_PLASMA_CANNON = 1,
161 : WEAPON_PULSE_LASER = 2,
162 : WEAPON_BEAM_LASER = 3,
163 : WEAPON_MINING_LASER = 4,
164 : WEAPON_MILITARY_LASER = 5,
165 : WEAPON_THARGOID_LASER = 10,
166 : WEAPON_UNDEFINED
167 : } OOWeaponType; */
168 0 : typedef OOEquipmentType* OOWeaponType;
169 :
170 :
171 0 : typedef enum
172 : {
173 : // Alert conditions are used by player and station entities.
174 : // NOTE: numerical values are available to scripts and shaders.
175 : ALERT_CONDITION_DOCKED = 0,
176 : ALERT_CONDITION_GREEN = 1,
177 : ALERT_CONDITION_YELLOW = 2,
178 : ALERT_CONDITION_RED = 3
179 : } OOAlertCondition;
180 :
181 :
182 0 : typedef enum
183 : {
184 0 : #define DIFF_STRING_ENTRY(label, string) label,
185 : #include "OOShipDamageType.tbl"
186 : #undef DIFF_STRING_ENTRY
187 :
188 : kOOShipDamageTypeDefault = kOODamageTypeEnergy
189 : } OOShipDamageType;
190 :
191 :
192 0 : @interface ShipEntity: OOEntityWithDrawable <OOSubEntity, OOBeaconEntity>
193 : {
194 : @public
195 : // derived variables
196 : OOTimeDelta shot_time; // time elapsed since last shot was fired
197 0 :
198 : // navigation
199 : Vector v_forward, v_up, v_right; // unit vectors derived from the direction faced
200 0 :
201 : // variables which are controlled by AI
202 : HPVector _destination; // for flying to/from a set point
203 0 :
204 : GLfloat desired_range; // range to which to journey/scan
205 0 : GLfloat desired_speed; // speed at which to travel
206 0 : // next three used to set desired attitude, flightRoll etc. gradually catch up to target
207 : GLfloat stick_roll; // stick roll
208 0 : GLfloat stick_pitch; // stick pitch
209 0 : GLfloat stick_yaw; // stick yaw
210 0 : OOBehaviour behaviour; // ship's behavioural state
211 0 :
212 : BoundingBox totalBoundingBox; // records ship configuration
213 0 :
214 : @protected
215 : //set-up
216 : NSDictionary *shipinfoDictionary;
217 0 :
218 : Quaternion subentityRotationalVelocity;
219 0 :
220 : //scripting
221 : OOJSScript *script;
222 0 : OOJSScript *aiScript;
223 0 : OOTimeAbsolute aiScriptWakeTime;
224 0 :
225 : //docking instructions
226 : NSDictionary *dockingInstructions;
227 0 :
228 : OOColor *laser_color;
229 0 : OOColor *default_laser_color;
230 0 : OOColor *exhaust_emissive_color;
231 0 : OOColor *scanner_display_color1;
232 0 : OOColor *scanner_display_color2;
233 0 : OOColor *scanner_display_color_hostile1;
234 0 : OOColor *scanner_display_color_hostile2;
235 0 :
236 : // per ship-type variables
237 : //
238 : GLfloat maxFlightSpeed; // top speed (160.0 for player) (200.0 for fast raider)
239 0 : GLfloat max_flight_roll; // maximum roll rate (2.0 for player) (3.0 for fast raider)
240 0 : GLfloat max_flight_pitch; // maximum pitch rate (1.0 for player) (1.5 for fast raider) also radians/sec for (* turrets *)
241 0 : GLfloat max_flight_yaw;
242 0 : GLfloat cruiseSpeed; // 80% of top speed
243 0 :
244 : GLfloat max_thrust; // acceleration
245 0 : GLfloat thrust; // acceleration
246 0 : float hyperspaceMotorSpinTime; // duration of hyperspace countdown
247 0 :
248 : unsigned military_jammer_active: 1, // military_jammer
249 0 :
250 : docking_match_rotation: 1,
251 0 :
252 : pitching_over: 1, // set to YES if executing a sharp loop
253 0 : rolling_over: 1, // set to YES if executing a sharp roll
254 0 : reportAIMessages: 1, // normally NO, suppressing AI message reporting
255 0 :
256 : being_mined: 1, // normally NO, set to Yes when fired on by mining laser
257 0 :
258 : being_fined: 1,
259 0 :
260 : isHulk: 1, // This is used to distinguish abandoned ships from cargo
261 0 : trackCloseContacts: 1,
262 0 : isNearPlanetSurface: 1, // check for landing on planet
263 0 : isFrangible: 1, // frangible => subEntities can be damaged individually
264 0 : cloaking_device_active: 1, // cloaking_device
265 0 : cloakPassive: 1, // cloak deactivates when main weapons or missiles are fired
266 0 : cloakAutomatic: 1, // cloak activates itself automatic during attack
267 0 : canFragment: 1, // Can it break into wreckage?
268 0 : isWreckage: 1, // Is it wreckage?
269 0 : _showDamage: 1, // Show damage?
270 0 : suppressExplosion: 1, // Avoid exploding on death (script hook)
271 0 : suppressAegisMessages: 1, // No script/AI messages sent by -checkForAegis,
272 0 : isMissile: 1, // Whether this was launched by fireMissile (used to track submunitions).
273 0 : _explicitlyUnpiloted: 1, // Is meant to not have crew
274 0 : hasScoopMessage: 1, // suppress scoop messages when false.
275 0 :
276 : // scripting
277 : scripted_misjump: 1,
278 0 : haveExecutedSpawnAction: 1,
279 0 : haveStartedJSAI: 1,
280 0 : noRocks: 1,
281 0 : _lightsActive: 1;
282 0 :
283 : GLfloat _scriptedMisjumpRange;
284 0 :
285 : GLfloat sunGlareFilter; // Range 0.0 - 1.0, where 0 means no sun glare filter, 1 means glare fully filtered
286 0 :
287 : OOFuelQuantity fuel; // witch-space fuel
288 0 : GLfloat fuel_accumulator;
289 0 :
290 : GLfloat afterburner_rate;
291 0 : GLfloat afterburner_speed_factor;
292 0 :
293 : OOCargoQuantity likely_cargo; // likely amount of cargo (for pirates, this is what is spilled as loot)
294 0 : OOCargoQuantity max_cargo; // capacity of cargo hold
295 0 : OOCargoQuantity extra_cargo; // capacity of cargo hold extension (if any)
296 0 : OOCargoQuantity equipment_weight; // amount of equipment using cargo space (excluding passenger_berth & extra_cargo_bay)
297 0 : OOCargoType cargo_type; // if this is scooped, this is indicates contents
298 0 : OOCargoFlag cargo_flag; // indicates contents for merchantmen
299 0 : OOCreditsQuantity bounty; // bounty (if any)
300 0 :
301 : GLfloat energy_recharge_rate; // recharge rate for energy banks
302 0 :
303 : OOWeaponFacingSet weapon_facings; // weapon mounts available (bitmask)
304 0 : OOWeaponType forward_weapon_type; // type of forward weapon (allows lasers, plasma cannon, others)
305 0 : OOWeaponType aft_weapon_type; // type of aft weapon (allows lasers, plasma cannon, others)
306 0 : OOWeaponType port_weapon_type; // type of port weapon
307 0 : OOWeaponType starboard_weapon_type; // type of starboard weapon
308 0 : GLfloat weapon_damage; // energy damage dealt by weapon
309 0 : GLfloat weapon_damage_override; // custom energy damage dealt by front laser, if applicable
310 0 : GLfloat weaponRange; // range of the weapon (in meters)
311 0 : OOWeaponFacing currentWeaponFacing; // not necessarily the same as view for the player
312 0 :
313 : GLfloat weapon_energy_use, weapon_temp, weapon_shot_temperature; // active weapon temp, delta-temp
314 0 : GLfloat forward_weapon_temp, aft_weapon_temp, port_weapon_temp, starboard_weapon_temp; // current weapon temperatures
315 0 :
316 : GLfloat scannerRange; // typically 25600
317 0 :
318 : unsigned missiles; // number of on-board missiles
319 0 : unsigned max_missiles; // number of missile pylons
320 0 : NSString *_missileRole;
321 0 : OOTimeDelta missile_load_time; // minimum time interval between missile launches
322 0 : OOTimeAbsolute missile_launch_time; // time of last missile launch
323 0 :
324 : AI *shipAI; // ship's AI system
325 0 :
326 : NSString *name; // descriptive name
327 0 : NSString *shipUniqueName; // uniqish name e.g. "Terror of Lave"
328 0 : NSString *shipClassName; // e.g. "Cobra III"
329 0 : NSString *displayName; // name shown on screen
330 0 : NSString *scan_description; // scan class name
331 0 : OORoleSet *roleSet; // Roles a ship can take, eg. trader, hunter, police, pirate, scavenger &c.
332 0 : NSString *primaryRole; // "Main" role of the ship.
333 0 :
334 : NSArray *explosionType; // explosion.plist entries
335 0 :
336 : // AI stuff
337 : Vector jink; // x and y set factors for offsetting a pursuing ship's position
338 0 : HPVector coordinates; // for flying to/from a set point
339 0 : Vector reference; // a direction vector of magnitude 1 (* turrets *)
340 0 :
341 : NSUInteger _subIdx; // serialisation index - used only if this ship is a subentity
342 0 : NSUInteger _maxShipSubIdx; // serialisation index - the number of ship subentities inside the shipdata
343 0 : double launch_time; // time at which launched
344 0 : double launch_delay; // delay for thinking after launch
345 0 : OOUniversalID planetForLanding; // for landing
346 0 :
347 : GLfloat frustration, // degree of dissatisfaction with the current behavioural state, factor used to test this
348 0 : success_factor;
349 0 :
350 : int patrol_counter; // keeps track of where the ship is along a patrol route
351 0 :
352 : NSMutableDictionary *previousCondition; // restored after collision avoidance
353 0 :
354 : // derived variables
355 : float weapon_recharge_rate; // time between shots
356 0 : int shot_counter; // number of shots fired
357 0 : OOTimeAbsolute cargo_dump_time; // time cargo was last dumped
358 0 : OOTimeAbsolute last_shot_time; // time shot was last fired
359 0 :
360 : NSMutableArray *cargo; // cargo containers go in here
361 0 :
362 : OOCommodityType commodity_type; // type of commodity in a container
363 0 : OOCargoQuantity commodity_amount; // 1 if unit is TONNES (0), possibly more if precious metals KILOGRAMS (1)
364 0 : // or gem stones GRAMS (2)
365 :
366 : // navigation
367 : GLfloat flightSpeed; // current speed
368 0 : GLfloat flightRoll; // current roll rate
369 0 : GLfloat flightPitch; // current pitch rate
370 0 : GLfloat flightYaw; // current yaw rate
371 0 :
372 : GLfloat accuracy;
373 0 : GLfloat pitch_tolerance;
374 0 : GLfloat aim_tolerance;
375 0 : int _missed_shots;
376 0 :
377 : OOAegisStatus aegis_status; // set to YES when within the station's protective zone
378 0 : OOSystemID home_system;
379 0 : OOSystemID destination_system;
380 0 :
381 : double messageTime; // counts down the seconds a radio message is active for
382 0 :
383 : double next_spark_time; // time of next spark when throwing sparks
384 0 :
385 : Vector collision_vector; // direction of colliding thing.
386 0 :
387 : GLfloat _scaleFactor; // scale factor for size variation
388 0 :
389 :
390 : BOOL _multiplyWeapons; // multiply instead of splitting weapons
391 0 : //position of gun ports
392 : NSArray *forwardWeaponOffset,
393 0 : *aftWeaponOffset,
394 0 : *portWeaponOffset,
395 0 : *starboardWeaponOffset;
396 0 :
397 : // crew (typically one OOCharacter - the pilot)
398 : NSArray *crew;
399 0 :
400 : // close contact / collision tracking
401 : NSMutableDictionary *closeContactsInfo;
402 0 :
403 : NSString *lastRadioMessage;
404 0 :
405 : // scooping...
406 : Vector tractor_position;
407 0 :
408 : // from player entity moved here now we're doing more complex heat stuff
409 : float ship_temperature;
410 0 :
411 : // for advanced scanning etc.
412 : ShipEntity *scanned_ships[MAX_SCAN_NUMBER + 1];
413 0 : GLfloat distance2_scanned_ships[MAX_SCAN_NUMBER + 1];
414 0 : unsigned n_scanned_ships;
415 0 :
416 : // advanced navigation
417 : HPVector navpoints[32];
418 0 : unsigned next_navpoint_index;
419 0 : unsigned number_of_navpoints;
420 0 :
421 : // Collision detection
422 : Octree *octree;
423 0 :
424 : #ifndef NDEBUG
425 : // DEBUGGING
426 : OOBehaviour debugLastBehaviour;
427 0 : #endif
428 :
429 : uint16_t entity_personality; // Per-entity random number. Exposed to shaders and scripts.
430 0 : NSDictionary *scriptInfo; // script_info dictionary from shipdata.plist, exposed to scripts.
431 0 :
432 : NSMutableArray *subEntities;
433 0 : OOEquipmentType *missile_list[SHIPENTITY_MAX_MISSILES];
434 0 :
435 : // various types of target
436 : OOWeakReference *_primaryTarget; // for combat or rendezvous
437 0 : OOWeakReference *_primaryAggressor; // recorded after attack
438 0 : OOWeakReference *_targetStation; // for docking
439 0 : OOWeakReference *_foundTarget; // from scans
440 0 : OOWeakReference *_lastEscortTarget; // last target an escort was deployed after
441 0 : OOWeakReference *_thankedShip; // last ship thanked
442 0 : OOWeakReference *_rememberedShip; // ship being remembered
443 0 : OOWeakReference *_proximityAlert; // a ShipEntity within 2x collision_radius
444 0 :
445 : // Stuff for the target tracking curve. The ship records the position of the target every reactionTime/2 seconds, then fits a curve to the
446 : // last three recorded positions. Instead of tracking the primary target's actual position it uses the curve to calculate the target's position.
447 : // This introduces a small amount of lag to the target tracking making the NPC more human.
448 : float reactionTime;
449 0 : HPVector trackingCurvePositions[4];
450 0 : OOTimeAbsolute trackingCurveTimes[4];
451 0 : HPVector trackingCurveCoeffs[3];
452 0 :
453 :
454 :
455 : @private
456 : OOWeakReference *_subEntityTakingDamage; // frangible => subEntities can be damaged individually
457 0 :
458 : NSString *_shipKey;
459 0 :
460 : NSMutableArray *_equipment;
461 0 : float _heatInsulation;
462 0 :
463 : OOWeakReference *_lastAegisLock; // remember last aegis planet/sun
464 0 :
465 : OOShipGroup *_group;
466 0 : OOShipGroup *_escortGroup;
467 0 : uint8_t _maxEscortCount;
468 0 : uint8_t _pendingEscortCount;
469 0 : // Cache of ship-relative positions, managed by -coordinatesForEscortPosition:.
470 : Vector _escortPositions[MAX_ESCORTS];
471 0 : BOOL _escortPositionsValid;
472 0 :
473 : OOWeakSet *_defenseTargets; // defense targets
474 0 :
475 : // ships in this set can't be collided with
476 : OOWeakSet *_collisionExceptions;
477 0 :
478 : GLfloat _profileRadius;
479 0 :
480 : OOWeakReference *_shipHitByLaser; // entity hit by the last laser shot
481 0 :
482 : // beacons
483 : NSString *_beaconCode;
484 0 : NSString *_beaconLabel;
485 0 : OOWeakReference *_prevBeacon;
486 0 : OOWeakReference *_nextBeacon;
487 0 : id <OOHUDBeaconIcon> _beaconDrawable;
488 0 :
489 : double _nextAegisCheck;
490 0 :
491 : // Demo ship state
492 : BOOL isDemoShip;
493 0 : OOScalar demoRate;
494 0 : OOTimeAbsolute demoStartTime;
495 0 : Quaternion demoStartOrientation;
496 0 : }
497 :
498 : // ship brains
499 : - (void) setStateMachine:(NSString *)ai_desc;
500 0 : - (void) setAI:(AI *)ai;
501 0 : - (AI *) getAI;
502 0 : - (BOOL) hasAutoAI;
503 0 : - (BOOL) hasNewAI;
504 0 : - (void) setShipScript:(NSString *)script_name;
505 0 : - (void) removeScript;
506 0 : - (OOScript *) shipScript;
507 0 : - (OOScript *) shipAIScript;
508 0 : - (OOTimeAbsolute) shipAIScriptWakeTime;
509 0 : - (void) setAIScriptWakeTime:(OOTimeAbsolute) t;
510 0 : - (double) frustration;
511 0 : - (void) setLaunchDelay:(double)delay;
512 0 :
513 : - (void) interpretAIMessage:(NSString *)message;
514 0 :
515 : - (GLfloat)accuracy;
516 0 : - (void)setAccuracy:(GLfloat) new_accuracy;
517 0 :
518 : - (OOMesh *)mesh;
519 0 : - (void)setMesh:(OOMesh *)mesh;
520 0 :
521 : - (BoundingBox) totalBoundingBox;
522 0 :
523 : - (Vector) forwardVector;
524 0 : - (Vector) upVector;
525 0 : - (Vector) rightVector;
526 0 :
527 : - (NSArray *)subEntities;
528 0 : - (NSUInteger) subEntityCount;
529 0 : - (BOOL) hasSubEntity:(Entity<OOSubEntity> *)sub;
530 0 :
531 : - (NSEnumerator *)subEntityEnumerator;
532 0 : - (NSEnumerator *)shipSubEntityEnumerator;
533 0 : - (NSEnumerator *)flasherEnumerator;
534 0 : - (NSEnumerator *)exhaustEnumerator;
535 0 :
536 : - (ShipEntity *) subEntityTakingDamage;
537 0 : - (void) setSubEntityTakingDamage:(ShipEntity *)sub;
538 0 :
539 : - (void) clearSubEntities; // Releases and clears subentity array, after making sure subentities don't think ship is owner.
540 0 :
541 : - (Quaternion) subEntityRotationalVelocity;
542 0 : - (void) setSubEntityRotationalVelocity:(Quaternion)rv;
543 0 :
544 : // subentities management
545 : - (NSString *) serializeShipSubEntities;
546 0 : - (void) deserializeShipSubEntitiesFrom:(NSString *)string;
547 0 : - (NSUInteger) maxShipSubEntities;
548 0 : - (void) setSubIdx:(NSUInteger)value;
549 0 : - (NSUInteger) subIdx;
550 0 :
551 : - (Octree *) octree;
552 0 : - (float) volume;
553 0 :
554 : // octree collision hunting
555 : - (GLfloat)doesHitLine:(HPVector)v0 :(HPVector)v1;
556 0 : - (GLfloat)doesHitLine:(HPVector)v0 :(HPVector)v1 :(ShipEntity**)hitEntity;
557 0 : - (GLfloat)doesHitLine:(HPVector)v0 :(HPVector)v1 withPosition:(HPVector)o andIJK:(Vector)i :(Vector)j :(Vector)k; // for subentities
558 0 :
559 : - (BoundingBox) findBoundingBoxRelativeToPosition:(HPVector)opv InVectors:(Vector)i :(Vector)j :(Vector)k;
560 0 :
561 : - (HPVector)absoluteTractorPosition;
562 0 :
563 : // beacons // definitions now in <OOBeaconEntity> protocol
564 :
565 : - (void) setIsBoulder:(BOOL)flag;
566 0 : - (BOOL) isBoulder;
567 0 : - (BOOL) isMinable;
568 0 :
569 : - (BOOL) countsAsKill;
570 0 :
571 : - (void) setUpEscorts;
572 0 : - (void) updateEscortFormation;
573 0 :
574 : - (id)initWithKey:(NSString *)key definition:(NSDictionary *)dict;
575 0 : - (BOOL)setUpFromDictionary:(NSDictionary *) shipDict;
576 0 : - (BOOL)setUpShipFromDictionary:(NSDictionary *) shipDict;
577 0 : - (BOOL)setUpSubEntities;
578 0 : - (BOOL) setUpOneStandardSubentity:(NSDictionary *) subentDict asTurret:(BOOL)asTurret;
579 0 : - (GLfloat)frustumRadius;
580 0 :
581 : - (NSString *) shipDataKey;
582 0 : - (NSString *) shipDataKeyAutoRole;
583 0 : - (void)setShipDataKey:(NSString *)key;
584 0 :
585 : - (NSDictionary *)shipInfoDictionary;
586 0 :
587 : - (NSArray *) getWeaponOffsetFrom:(NSDictionary *)dict withKey:(NSString *)key inMode:(NSString *)mode;
588 0 : - (NSArray *) aftWeaponOffset;
589 0 : - (NSArray *) forwardWeaponOffset;
590 0 : - (NSArray *) portWeaponOffset;
591 0 : - (NSArray *) starboardWeaponOffset;
592 0 : - (BOOL) hasAutoWeapons;
593 0 :
594 : - (BOOL) isFrangible;
595 0 : - (BOOL) suppressFlightNotifications;
596 0 :
597 : - (void) respondToAttackFrom:(Entity *)from becauseOf:(Entity *)other;
598 0 :
599 : // Equipment
600 : - (OOWeaponFacingSet) weaponFacings;
601 0 : - (BOOL) hasEquipmentItem:(id)equipmentKeys includeWeapons:(BOOL)includeWeapons whileLoading:(BOOL)loading; // This can take a string or an set or array of strings. If a collection, returns YES if ship has _any_ of the specified equipment. If includeWeapons is NO, missiles and primary weapons are not checked.
602 0 : - (BOOL) hasEquipmentItem:(id)equipmentKeys; // Short for hasEquipmentItem:foo includeWeapons:NO whileLoading:NO
603 0 : - (NSUInteger) countEquipmentItem:(NSString *)eqkey;
604 0 : - (NSString *) equipmentItemProviding:(NSString *)equipmentType;
605 0 : - (BOOL) hasEquipmentItemProviding:(NSString *)equipmentType;
606 0 : - (BOOL) hasAllEquipment:(id)equipmentKeys includeWeapons:(BOOL)includeWeapons whileLoading:(BOOL)loading; // Like hasEquipmentItem:includeWeapons:, but requires _all_ elements in collection.
607 0 : - (BOOL) hasAllEquipment:(id)equipmentKeys; // Short for hasAllEquipment:foo includeWeapons:NO
608 0 : - (BOOL) setWeaponMount:(OOWeaponFacing)facing toWeapon:(NSString *)eqKey;
609 0 : - (BOOL) canAddEquipment:(NSString *)equipmentKey inContext:(NSString *)context; // Test ability to add equipment, taking equipment-specific constriants into account.
610 0 : - (BOOL) equipmentValidToAdd:(NSString *)equipmentKey inContext:(NSString *)context; // Actual test if equipment satisfies validation criteria.
611 0 : - (BOOL) equipmentValidToAdd:(NSString *)equipmentKey whileLoading:(BOOL)loading inContext:(NSString *)context;
612 0 : - (BOOL) addEquipmentItem:(NSString *)equipmentKey inContext:(NSString *)context;
613 0 : - (BOOL) addEquipmentItem:(NSString *)equipmentKey withValidation:(BOOL)validateAddition inContext:(NSString *)context;
614 0 : - (BOOL) hasHyperspaceMotor;
615 0 : - (float) hyperspaceSpinTime;
616 0 : - (void) setHyperspaceSpinTime:(float)new;
617 0 :
618 :
619 : - (NSEnumerator *) equipmentEnumerator;
620 0 : - (NSUInteger) equipmentCount;
621 0 : - (void) removeEquipmentItem:(NSString *)equipmentKey;
622 0 : - (void) removeAllEquipment;
623 0 : - (OOEquipmentType *) selectMissile;
624 0 : - (OOCreditsQuantity) removeMissiles;
625 0 :
626 : // Internal, subject to change. Use the methods above instead.
627 : - (BOOL) hasOneEquipmentItem:(NSString *)itemKey includeWeapons:(BOOL)includeMissiles whileLoading:(BOOL)loading;
628 0 : - (BOOL) hasOneEquipmentItem:(NSString *)itemKey includeMissiles:(BOOL)includeMissiles whileLoading:(BOOL)loading;
629 0 : - (BOOL) hasPrimaryWeapon:(OOWeaponType)weaponType;
630 0 : - (BOOL) removeExternalStore:(OOEquipmentType *)eqType;
631 0 :
632 : // Passengers and parcels - not supported for NPCs, but interface is here for genericity.
633 : - (NSUInteger) parcelCount;
634 0 : - (NSUInteger) passengerCount;
635 0 : - (NSUInteger) passengerCapacity;
636 0 :
637 : - (NSUInteger) missileCount;
638 0 : - (NSUInteger) missileCapacity;
639 0 :
640 : - (NSUInteger) extraCargo;
641 0 :
642 : // Tests for the various special-cased equipment items
643 : // (Nowadays, more convenience methods)
644 : - (BOOL) hasScoop;
645 0 : - (BOOL) hasFuelScoop;
646 0 : - (BOOL) hasCargoScoop;
647 0 : - (BOOL) hasECM;
648 0 : - (BOOL) hasCloakingDevice;
649 0 : - (BOOL) hasMilitaryScannerFilter;
650 0 : - (BOOL) hasMilitaryJammer;
651 0 : - (BOOL) hasExpandedCargoBay;
652 0 : - (BOOL) hasShieldBooster;
653 0 : - (BOOL) hasMilitaryShieldEnhancer;
654 0 : - (BOOL) hasHeatShield;
655 0 : - (BOOL) hasFuelInjection;
656 0 : - (BOOL) hasCascadeMine;
657 0 : - (BOOL) hasEscapePod;
658 0 : - (BOOL) hasDockingComputer;
659 0 : - (BOOL) hasGalacticHyperdrive;
660 0 :
661 : // Shield information derived from equipment. NPCs can't have shields, but that should change at some point.
662 : - (float) shieldBoostFactor;
663 0 : - (float) maxForwardShieldLevel;
664 0 : - (float) maxAftShieldLevel;
665 0 : - (float) shieldRechargeRate;
666 0 :
667 : - (double) maxHyperspaceDistance;
668 0 : - (float) afterburnerFactor;
669 0 : - (float) afterburnerRate;
670 0 : - (void) setAfterburnerFactor:(GLfloat)new;
671 0 : - (void) setAfterburnerRate:(GLfloat)new;
672 0 : - (float) maxThrust;
673 0 : - (float) thrust;
674 0 :
675 : - (void) setMaxThrust:(GLfloat)new;
676 0 : - (void) setMaxFlightPitch:(GLfloat)new;
677 0 : - (void) setMaxFlightSpeed:(GLfloat)new;
678 0 : - (void) setMaxFlightRoll:(GLfloat)new;
679 0 : - (void) setMaxFlightYaw:(GLfloat)new;
680 0 : - (void) setEnergyRechargeRate:(GLfloat)new;
681 0 :
682 :
683 : - (void) processBehaviour:(OOTimeDelta)delta_t;
684 0 : // Behaviours
685 : - (void) behaviour_stop_still:(double) delta_t;
686 0 : - (void) behaviour_idle:(double) delta_t;
687 0 : - (void) behaviour_tumble:(double) delta_t;
688 0 : - (void) behaviour_tractored:(double) delta_t;
689 0 : - (void) behaviour_track_target:(double) delta_t;
690 0 : - (void) behaviour_intercept_target:(double) delta_t;
691 0 : - (void) behaviour_attack_target:(double) delta_t;
692 0 : - (void) behaviour_attack_slow_dogfight:(double) delta_t;
693 0 : - (void) behaviour_evasive_action:(double) delta_t;
694 0 : - (void) behaviour_attack_break_off_target:(double) delta_t;
695 0 : - (void) behaviour_fly_to_target_six:(double) delta_t;
696 0 : - (void) behaviour_attack_mining_target:(double) delta_t;
697 0 : - (void) behaviour_attack_fly_to_target:(double) delta_t;
698 0 : - (void) behaviour_attack_fly_from_target:(double) delta_t;
699 0 : - (void) behaviour_running_defense:(double) delta_t;
700 0 : - (void) behaviour_flee_target:(double) delta_t;
701 0 : - (void) behaviour_attack_broadside:(double) delta_t;
702 0 : - (void) behaviour_attack_broadside_left:(double) delta_t;
703 0 : - (void) behaviour_attack_broadside_right:(double) delta_t;
704 0 : - (void) behaviour_close_to_broadside_range:(double) delta_t;
705 0 : - (void) behaviour_close_with_target:(double) delta_t;
706 0 : - (void) behaviour_attack_broadside_target:(double) delta_t leftside:(BOOL)leftside;
707 0 : - (void) behaviour_attack_sniper:(double) delta_t;
708 0 : - (void) behaviour_fly_range_from_destination:(double) delta_t;
709 0 : - (void) behaviour_face_destination:(double) delta_t;
710 0 : - (void) behaviour_land_on_planet:(double) delta_t;
711 0 : - (void) behaviour_formation_form_up:(double) delta_t;
712 0 : - (void) behaviour_fly_to_destination:(double) delta_t;
713 0 : - (void) behaviour_fly_from_destination:(double) delta_t;
714 0 : - (void) behaviour_avoid_collision:(double) delta_t;
715 0 : - (void) behaviour_track_as_turret:(double) delta_t;
716 0 : - (void) behaviour_fly_thru_navpoints:(double) delta_t;
717 0 : - (void) behaviour_scripted_ai:(double) delta_t;
718 0 :
719 : - (float) reactionTime;
720 0 : - (void) setReactionTime: (float) newReactionTime;
721 0 : - (HPVector) calculateTargetPosition;
722 0 : - (void) startTrackingCurve;
723 0 : - (void) updateTrackingCurve;
724 0 : - (void) calculateTrackingCurve;
725 0 :
726 : - (GLfloat *) scannerDisplayColorForShip:(ShipEntity*)otherShip :(BOOL)isHostile :(BOOL)flash :(OOColor *)scannerDisplayColor1 :(OOColor *)scannerDisplayColor2 :(OOColor *)scannerDisplayColorH1 :(OOColor *)scannerDisplayColorH2;
727 0 : - (void)setScannerDisplayColor1:(OOColor *)color1;
728 0 : - (void)setScannerDisplayColor2:(OOColor *)color2;
729 0 : - (OOColor *)scannerDisplayColor1;
730 0 : - (OOColor *)scannerDisplayColor2;
731 0 : - (void)setScannerDisplayColorHostile1:(OOColor *)color1;
732 0 : - (void)setScannerDisplayColorHostile2:(OOColor *)color2;
733 0 : - (OOColor *)scannerDisplayColorHostile1;
734 0 : - (OOColor *)scannerDisplayColorHostile2;
735 0 :
736 : - (BOOL)isCloaked;
737 0 : - (void)setCloaked:(BOOL)cloak;
738 0 : - (BOOL)hasAutoCloak;
739 0 : - (void)setAutoCloak:(BOOL)automatic;
740 0 :
741 : - (void) applyThrust:(double) delta_t;
742 0 : - (void) applyAttitudeChanges:(double) delta_t;
743 0 :
744 : - (void) avoidCollision;
745 0 : - (void) resumePostProximityAlert;
746 0 :
747 : - (double) messageTime;
748 0 : - (void) setMessageTime:(double) value;
749 0 :
750 : - (OOShipGroup *) group;
751 0 : - (void) setGroup:(OOShipGroup *)group;
752 0 :
753 : - (OOShipGroup *) escortGroup;
754 0 : - (void) setEscortGroup:(OOShipGroup *)group; // Only for use in unconventional set-up situations.
755 0 :
756 : - (OOShipGroup *) stationGroup; // should probably be defined in stationEntity.m
757 0 :
758 : - (BOOL) hasEscorts;
759 0 : - (NSEnumerator *) escortEnumerator;
760 0 : - (NSArray *) escortArray;
761 0 :
762 : - (uint8_t) escortCount;
763 0 :
764 : // Pending escort count: number of escorts to set up "later".
765 : - (uint8_t) pendingEscortCount;
766 0 : - (void) setPendingEscortCount:(uint8_t)count;
767 0 :
768 : // allow adjustment of escort numbers from shipdata.plist levels
769 : - (uint8_t) maxEscortCount;
770 0 : - (void) setMaxEscortCount:(uint8_t)newCount;
771 0 :
772 : - (NSUInteger) turretCount;
773 0 :
774 : - (NSString *) name;
775 0 : - (NSString *) shipUniqueName;
776 0 : - (NSString *) shipClassName;
777 0 : - (NSString *) displayName;
778 0 : - (NSString *) scanDescription;
779 0 : - (NSString *) scanDescriptionForScripting;
780 0 : - (void) setName:(NSString *)inName;
781 0 : - (void) setShipUniqueName:(NSString *)inName;
782 0 : - (void) setShipClassName:(NSString *)inName;
783 0 : - (void) setDisplayName:(NSString *)inName;
784 0 : - (void) setScanDescription:(NSString *)inName;
785 0 : - (NSString *) identFromShip:(ShipEntity*) otherShip; // name displayed to other ships
786 0 :
787 : - (BOOL) hasRole:(NSString *)role;
788 0 : - (OORoleSet *)roleSet;
789 0 :
790 : - (void) addRole:(NSString *)role;
791 0 : - (void) addRole:(NSString *)role withProbability:(float)probability;
792 0 : - (void) removeRole:(NSString *)role;
793 0 :
794 : - (NSString *)primaryRole;
795 0 : - (void)setPrimaryRole:(NSString *)role;
796 0 : - (BOOL)hasPrimaryRole:(NSString *)role;
797 0 :
798 : - (BOOL)isPolice; // Scan class is CLASS_POLICE
799 0 : - (BOOL)isThargoid; // Scan class is CLASS_THARGOID
800 0 : - (BOOL)isTrader; // Primary role is "trader" || isPlayer
801 0 : - (BOOL)isPirate; // Primary role is "pirate"
802 0 : - (BOOL)isMissile; // Primary role has suffix "MISSILE"
803 0 : - (BOOL)isMine; // Primary role has suffix "MINE"
804 0 : - (BOOL)isWeapon; // isMissile || isWeapon
805 0 : - (BOOL)isEscort; // Primary role is "escort" or "wingman"
806 0 : - (BOOL)isShuttle; // Primary role is "shuttle"
807 0 : - (BOOL)isTurret; // Behaviour is BEHAVIOUR_TRACK_AS_TURRET
808 0 : - (BOOL)isPirateVictim; // Primary role is listed in pirate-victim-roles.plist
809 0 : - (BOOL)isExplicitlyUnpiloted; // Has unpiloted = yes in its shipdata.plist entry
810 0 : - (BOOL)isUnpiloted; // Explicitly unpiloted, hulk, rock, cargo, debris etc; an open-ended criterion that may grow.
811 0 :
812 : - (OOAlertCondition) alertCondition; // quick calc for shaders
813 0 : - (OOAlertCondition) realAlertCondition; // full calculation for scripting
814 0 : - (BOOL) hasHostileTarget;
815 0 : - (BOOL) isHostileTo:(Entity *)entity;
816 0 :
817 : // defense target handling
818 : - (NSUInteger) defenseTargetCount;
819 0 : - (NSArray *) allDefenseTargets;
820 0 : - (NSEnumerator *) defenseTargetEnumerator;
821 0 : - (void) validateDefenseTargets;
822 0 : - (BOOL) addDefenseTarget:(Entity *)target;
823 0 : - (BOOL) isDefenseTarget:(Entity *)target;
824 0 : - (void) removeDefenseTarget:(Entity *)target;
825 0 : - (void) removeAllDefenseTargets;
826 0 :
827 : // collision exceptions
828 : - (NSArray *) collisionExceptions;
829 0 : - (void) addCollisionException:(ShipEntity *)ship;
830 0 : - (void) removeCollisionException:(ShipEntity *)ship;
831 0 : - (BOOL) collisionExceptedFor:(ShipEntity *)ship;
832 0 :
833 :
834 :
835 : - (GLfloat) weaponRange;
836 0 : - (void) setWeaponRange:(GLfloat) value;
837 0 : - (void) setWeaponDataFromType:(OOWeaponType)weapon_type;
838 0 : - (float) energyRechargeRate; // final rate after energy units
839 0 : - (float) weaponRechargeRate;
840 0 : - (void) setWeaponRechargeRate:(float)value;
841 0 : - (void) setWeaponEnergy:(float)value;
842 0 : - (OOWeaponFacing) currentWeaponFacing;
843 0 :
844 : - (GLfloat) scannerRange;
845 0 : - (void) setScannerRange:(GLfloat)value;
846 0 :
847 : - (Vector) reference;
848 0 : - (void) setReference:(Vector)v;
849 0 :
850 : - (BOOL) reportAIMessages;
851 0 : - (void) setReportAIMessages:(BOOL)yn;
852 0 :
853 : - (void) transitionToAegisNone;
854 0 : - (OOPlanetEntity *) findNearestPlanet;
855 0 : - (Entity<OOStellarBody> *) findNearestStellarBody; // NOTE: includes sun.
856 0 : - (OOPlanetEntity *) findNearestPlanetExcludingMoons;
857 0 : - (OOAegisStatus) checkForAegis;
858 0 : - (void) forceAegisCheck;
859 0 : - (BOOL) withinStationAegis;
860 0 : - (void) setLastAegisLock:(Entity<OOStellarBody> *)lastAegisLock;
861 0 :
862 : - (OOSystemID) homeSystem;
863 0 : - (OOSystemID) destinationSystem;
864 0 : - (void) setHomeSystem:(OOSystemID)s;
865 0 : - (void) setDestinationSystem:(OOSystemID)s;
866 0 :
867 :
868 : - (NSArray *) crew;
869 0 : - (NSArray *) crewForScripting;
870 0 : - (void) setCrew:(NSArray *)crewArray;
871 0 : /**
872 : Convenience to set the crew to a single character of the given role,
873 : originating in the ship's home system. Does nothing if unpiloted.
874 : */
875 : - (void) setSingleCrewWithRole:(NSString *)crewRole;
876 1 :
877 : // Fuel and capacity in tenths of light-years.
878 : - (OOFuelQuantity) fuel;
879 0 : - (void) setFuel:(OOFuelQuantity)amount;
880 0 : - (OOFuelQuantity) fuelCapacity;
881 0 :
882 : - (GLfloat) fuelChargeRate;
883 0 :
884 : - (void) setRoll:(double)amount;
885 0 : - (void) setRawRoll:(double)amount; // does not multiply by PI/2
886 0 : - (void) setPitch:(double)amount;
887 0 : - (void) setYaw:(double)amount;
888 0 : - (void) setThrust:(double)amount;
889 0 : - (void) applySticks:(double)delta_t;
890 0 :
891 :
892 : - (void)setThrustForDemo:(float)factor;
893 0 :
894 : /*
895 : Sets the bounty on this ship to amount.
896 : Does not check to see if the ship is allowed to have a bounty, for example if it is police.
897 : */
898 : - (void) setBounty:(OOCreditsQuantity)amount;
899 0 : - (void) setBounty:(OOCreditsQuantity)amount withReason:(OOLegalStatusReason)reason;
900 0 : - (void) setBounty:(OOCreditsQuantity)amount withReasonAsString:(NSString *)reason;
901 0 : - (OOCreditsQuantity) bounty;
902 0 :
903 : - (int) legalStatus;
904 0 :
905 : - (BOOL) isTemplateCargoPod;
906 0 : - (void) setUpCargoType:(NSString *)cargoString;
907 0 : - (void) setCommodity:(OOCommodityType)co_type andAmount:(OOCargoQuantity)co_amount;
908 0 : - (void) setCommodityForPod:(OOCommodityType)co_type andAmount:(OOCargoQuantity)co_amount;
909 0 : - (OOCommodityType) commodityType;
910 0 : - (OOCargoQuantity) commodityAmount;
911 0 :
912 : - (OOCargoQuantity) maxAvailableCargoSpace;
913 0 : - (void) setMaxAvailableCargoSpace:(OOCargoQuantity)new;
914 0 : - (OOCargoQuantity) availableCargoSpace;
915 0 : - (OOCargoQuantity) cargoQuantityOnBoard;
916 0 : - (OOCargoType) cargoType;
917 0 : - (NSArray *) cargoListForScripting;
918 0 : - (NSMutableArray *) cargo;
919 0 : - (void) setCargo:(NSArray *)some_cargo;
920 0 : - (BOOL) addCargo:(NSArray *) some_cargo;
921 0 : - (BOOL) removeCargo:(OOCommodityType)commodity amount:(OOCargoQuantity) amount;
922 0 : - (BOOL) showScoopMessage;
923 0 :
924 : - (NSArray *) passengerListForScripting;
925 0 : - (NSArray *) parcelListForScripting;
926 0 : - (NSArray *) contractListForScripting;
927 0 : - (NSArray *) equipmentListForScripting;
928 0 : - (OOWeaponType) weaponTypeIDForFacing:(OOWeaponFacing)facing strict:(BOOL)strict;
929 0 : - (OOEquipmentType *) weaponTypeForFacing:(OOWeaponFacing)facing strict:(BOOL)strict;
930 0 : - (NSArray *) missilesList;
931 0 :
932 : - (OOCargoFlag) cargoFlag;
933 0 : - (void) setCargoFlag:(OOCargoFlag)flag;
934 0 :
935 : - (void) setSpeed:(double)amount;
936 0 : - (double) desiredSpeed;
937 0 : - (void) setDesiredSpeed:(double)amount;
938 0 : - (double) desiredRange;
939 0 : - (void) setDesiredRange:(double)amount;
940 0 :
941 : - (double) cruiseSpeed;
942 0 :
943 : - (Vector) thrustVector;
944 0 : - (void) setTotalVelocity:(Vector)vel; // Set velocity to vel - thrustVector, effectively setting the instanteneous velocity to vel.
945 0 :
946 : - (void) increase_flight_speed:(double)delta;
947 0 : - (void) decrease_flight_speed:(double)delta;
948 0 : - (void) increase_flight_roll:(double)delta;
949 0 : - (void) decrease_flight_roll:(double)delta;
950 0 : - (void) increase_flight_pitch:(double)delta;
951 0 : - (void) decrease_flight_pitch:(double)delta;
952 0 : - (void) increase_flight_yaw:(double)delta;
953 0 : - (void) decrease_flight_yaw:(double)delta;
954 0 :
955 : - (GLfloat) flightRoll;
956 0 : - (GLfloat) flightPitch;
957 0 : - (GLfloat) flightYaw;
958 0 : - (GLfloat) flightSpeed;
959 0 : - (GLfloat) maxFlightPitch;
960 0 : - (GLfloat) maxFlightSpeed;
961 0 : - (GLfloat) maxFlightRoll;
962 0 : - (GLfloat) maxFlightYaw;
963 0 : - (GLfloat) speedFactor;
964 0 :
965 : - (GLfloat) temperature;
966 0 : - (void) setTemperature:(GLfloat) value;
967 0 : - (GLfloat) heatInsulation;
968 0 : - (void) setHeatInsulation:(GLfloat) value;
969 0 :
970 : - (float) randomEjectaTemperature;
971 0 : - (float) randomEjectaTemperatureWithMaxFactor:(float)factor;
972 0 :
973 : // the percentage of damage taken (100 is destroyed, 0 is fine)
974 : - (int) damage;
975 0 :
976 : - (void) dealEnergyDamage:(GLfloat) baseDamage atRange:(GLfloat) range withBias:(GLfloat) velocityBias;
977 0 : - (void) dealEnergyDamageWithinDesiredRange;
978 0 : - (void) dealMomentumWithinDesiredRange:(double)amount;
979 0 :
980 : // Dispatch shipTakingDamage() event.
981 : - (void) noteTakingDamage:(double)amount from:(Entity *)entity type:(OOShipDamageType)type;
982 0 : // Dispatch shipDied() and possibly shipKilledOther() events. This is only for use by getDestroyedBy:damageType:, but needs to be visible to PlayerEntity's version.
983 : - (void) noteKilledBy:(Entity *)whom damageType:(OOShipDamageType)type;
984 0 :
985 : - (void) getDestroyedBy:(Entity *)whom damageType:(OOShipDamageType)type;
986 0 : - (void) becomeExplosion;
987 0 : - (void) becomeLargeExplosion:(double) factor;
988 0 : - (void) becomeEnergyBlast;
989 0 : - (void) broadcastEnergyBlastImminent;
990 0 : - (void) setIsWreckage:(BOOL)isw;
991 0 : - (BOOL) showDamage;
992 0 :
993 : - (Vector) positionOffsetForAlignment:(NSString*) align;
994 0 : Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q, NSString* align);
995 0 :
996 : - (void) collectBountyFor:(ShipEntity *)other;
997 0 :
998 : - (BoundingBox) findSubentityBoundingBox;
999 0 :
1000 : - (Triangle) absoluteIJKForSubentity;
1001 0 :
1002 : - (GLfloat)weaponRecoveryTime;
1003 0 : - (GLfloat)laserHeatLevel;
1004 0 : - (GLfloat)laserHeatLevelAft;
1005 0 : - (GLfloat)laserHeatLevelForward;
1006 0 : - (GLfloat)laserHeatLevelPort;
1007 0 : - (GLfloat)laserHeatLevelStarboard;
1008 0 : - (GLfloat)hullHeatLevel;
1009 0 : - (GLfloat)entityPersonality;
1010 0 : - (GLint)entityPersonalityInt;
1011 0 : - (void) setEntityPersonalityInt:(uint16_t)value;
1012 0 :
1013 : - (void)setSuppressExplosion:(BOOL)suppress;
1014 0 :
1015 : - (void) resetExhaustPlumes;
1016 0 :
1017 : - (void) removeExhaust:(OOExhaustPlumeEntity *)exhaust;
1018 0 : - (void) removeFlasher:(OOFlasherEntity *)flasher;
1019 0 :
1020 :
1021 : /*-----------------------------------------
1022 :
1023 : AI piloting methods
1024 :
1025 : -----------------------------------------*/
1026 :
1027 : - (void) checkScanner;
1028 0 : - (void) checkScannerIgnoringUnpowered;
1029 0 : - (ShipEntity**) scannedShips;
1030 0 : - (int) numberOfScannedShips;
1031 0 :
1032 : - (Entity *)foundTarget;
1033 0 : - (Entity *)primaryAggressor;
1034 0 : - (Entity *)lastEscortTarget;
1035 0 : - (Entity *)thankedShip;
1036 0 : - (Entity *)rememberedShip;
1037 0 : - (Entity *)proximityAlert;
1038 0 : - (void) setFoundTarget:(Entity *) targetEntity;
1039 0 : - (void) setPrimaryAggressor:(Entity *) targetEntity;
1040 0 : - (void) setLastEscortTarget:(Entity *) targetEntity;
1041 0 : - (void) setThankedShip:(Entity *) targetEntity;
1042 0 : - (void) setRememberedShip:(Entity *) targetEntity;
1043 0 : - (void) setProximityAlert:(ShipEntity *) targetEntity;
1044 0 : - (void) setTargetStation:(Entity *) targetEntity;
1045 0 : - (BOOL) isValidTarget:(Entity *) target;
1046 0 : - (void) addTarget:(Entity *) targetEntity;
1047 0 : - (void) removeTarget:(Entity *) targetEntity;
1048 0 : - (BOOL) canStillTrackPrimaryTarget;
1049 0 : - (id) primaryTarget;
1050 0 : - (id) primaryTargetWithoutValidityCheck;
1051 0 : - (StationEntity *) targetStation;
1052 0 :
1053 : - (BOOL) isFriendlyTo:(ShipEntity *)otherShip;
1054 0 :
1055 : - (ShipEntity *) shipHitByLaser;
1056 0 :
1057 : - (void) noteLostTarget;
1058 0 : - (void) noteLostTargetAndGoIdle;
1059 0 : - (void) noteTargetDestroyed:(ShipEntity *)target;
1060 0 :
1061 : - (OOBehaviour) behaviour;
1062 0 : - (void) setBehaviour:(OOBehaviour) cond;
1063 0 :
1064 : - (void) trackOntoTarget:(double) delta_t withDForward: (GLfloat) dp;
1065 0 :
1066 : - (double) ballTrackLeadingTarget:(double) delta_t atTarget:(Entity *)target;
1067 0 :
1068 : - (GLfloat) rollToMatchUp:(Vector) up_vec rotating:(GLfloat) match_roll;
1069 0 :
1070 : - (GLfloat) rangeToDestination;
1071 0 : - (double) trackDestination:(double) delta_t :(BOOL) retreat;
1072 0 :
1073 : - (void) setCoordinate:(HPVector)coord;
1074 0 : - (HPVector) coordinates;
1075 0 : - (HPVector) destination;
1076 0 : - (HPVector) distance_six: (GLfloat) dist;
1077 0 : - (HPVector) distance_twelve: (GLfloat) dist withOffset:(GLfloat)offset;
1078 0 :
1079 : - (void) setEvasiveJink:(GLfloat) z;
1080 0 : - (void) evasiveAction:(double) delta_t;
1081 0 : - (double) trackPrimaryTarget:(double) delta_t :(BOOL) retreat;
1082 0 : - (double) trackSideTarget:(double) delta_t :(BOOL) leftside;
1083 0 : - (double) missileTrackPrimaryTarget:(double) delta_t;
1084 0 :
1085 : //return 0.0 if there is no primary target
1086 : - (double) rangeToPrimaryTarget;
1087 0 : - (double) approachAspectToPrimaryTarget;
1088 0 : - (double) rangeToSecondaryTarget:(Entity *)target;
1089 0 : - (BOOL) hasProximityAlertIgnoringTarget:(BOOL)ignore_target;
1090 0 : - (GLfloat) currentAimTolerance;
1091 0 : /* This method returns a value between 0.0f and 1.0f, depending on how directly our view point
1092 : faces the sun and is used for generating the "staring at the sun" glare effect. 0.0f means that
1093 : we are not facing the sun, 1.0f means that we are looking directly at it. The cosine of the
1094 : threshold angle between view point and sun, below which we consider the ship as looking
1095 : at the sun, is passed as parameter to the method.
1096 : */
1097 : - (GLfloat) lookingAtSunWithThresholdAngleCos:(GLfloat) thresholdAngleCos;
1098 0 :
1099 : - (BOOL) onTarget:(OOWeaponFacing)direction withWeapon:(OOWeaponType)weapon;
1100 0 :
1101 : - (OOTimeDelta) shotTime;
1102 0 : - (void) resetShotTime;
1103 0 :
1104 : - (BOOL) fireMainWeapon:(double)range;
1105 0 : - (BOOL) fireAftWeapon:(double)range;
1106 0 : - (BOOL) firePortWeapon:(double)range;
1107 0 : - (BOOL) fireStarboardWeapon:(double)range;
1108 0 : - (BOOL) fireTurretCannon:(double)range;
1109 0 : - (void) setLaserColor:(OOColor *)color;
1110 0 : - (void) setExhaustEmissiveColor:(OOColor *)color;
1111 0 : - (OOColor *)laserColor;
1112 0 : - (OOColor *)exhaustEmissiveColor;
1113 0 : - (BOOL) fireSubentityLaserShot:(double)range;
1114 0 : - (BOOL) fireDirectLaserShot:(double)range;
1115 0 : - (BOOL) fireDirectLaserDefensiveShot;
1116 0 : - (BOOL) fireDirectLaserShotAt:(Entity *)my_target;
1117 0 : - (NSArray *) laserPortOffset:(OOWeaponFacing)direction;
1118 0 : - (BOOL) fireLaserShotInDirection:(OOWeaponFacing)direction weaponIdentifier:(NSString *)weaponIdentifier;
1119 0 : - (void) adjustMissedShots:(int)delta;
1120 0 : - (int) missedShots;
1121 0 : - (void) considerFiringMissile:(double)delta_t;
1122 0 : - (Vector) missileLaunchPosition;
1123 0 : - (ShipEntity *) fireMissile;
1124 0 : - (ShipEntity *) fireMissileWithIdentifier:(NSString *) identifier andTarget:(Entity *) target;
1125 0 : - (BOOL) isMissileFlagSet;
1126 0 : - (void) setIsMissileFlag:(BOOL)newValue;
1127 0 : - (OOTimeDelta) missileLoadTime;
1128 0 : - (void) setMissileLoadTime:(OOTimeDelta)newMissileLoadTime;
1129 0 : - (void) noticeECM;
1130 0 : - (BOOL) fireECM;
1131 0 : - (BOOL) cascadeIfAppropriateWithDamageAmount:(double)amount cascadeOwner:(Entity *)owner;
1132 0 : - (BOOL) activateCloakingDevice;
1133 0 : - (void) deactivateCloakingDevice;
1134 0 : - (BOOL) launchCascadeMine;
1135 0 : - (ShipEntity *) launchEscapeCapsule;
1136 0 : - (OOCommodityType) dumpCargo;
1137 0 : - (ShipEntity *) dumpCargoItem:(OOCommodityType)preferred;
1138 0 : - (OOCargoType) dumpItem: (ShipEntity*) jetto;
1139 0 :
1140 : - (void) manageCollisions;
1141 0 : - (BOOL) collideWithShip:(ShipEntity *)other;
1142 0 : - (void) adjustVelocity:(Vector) xVel;
1143 0 : - (void) addImpactMoment:(Vector) moment fraction:(GLfloat) howmuch;
1144 0 : - (BOOL) canScoop:(ShipEntity *)other;
1145 0 : - (void) getTractoredBy:(ShipEntity *)other;
1146 0 : - (void) scoopIn:(ShipEntity *)other;
1147 0 : - (void) scoopUp:(ShipEntity *)other;
1148 0 : - (void) scoopUpProcess:(ShipEntity *)other processEvents:(BOOL) proc_events processMessages:(BOOL) proc_messages;
1149 0 :
1150 : - (BOOL) abandonShip;
1151 0 :
1152 : - (void) takeScrapeDamage:(double) amount from:(Entity *) ent;
1153 0 : - (void) takeHeatDamage:(double) amount;
1154 0 :
1155 : - (void) enterDock:(StationEntity *)station;
1156 0 : - (void) leaveDock:(StationEntity *)station;
1157 0 :
1158 : - (void) enterWormhole:(WormholeEntity *) w_hole;
1159 0 : - (void) enterWormhole:(WormholeEntity *) w_hole replacing:(BOOL)replacing;
1160 0 : - (void) enterWitchspace;
1161 0 : - (void) leaveWitchspace;
1162 0 : - (BOOL) witchspaceLeavingEffects;
1163 0 :
1164 : /*
1165 : Mark this ship as an offender, this is different to setBounty as some ships such as police
1166 : are not markable. The final bounty may not be equal to existing bounty plus offence_value.
1167 : */
1168 : - (void) markAsOffender:(int)offence_value;
1169 0 : - (void) markAsOffender:(int)offence_value withReason:(OOLegalStatusReason)reason;
1170 0 :
1171 : - (void) switchLightsOn;
1172 0 : - (void) switchLightsOff;
1173 0 : - (BOOL) lightsActive;
1174 0 :
1175 : - (void) setDestination:(HPVector) dest;
1176 0 : - (void) setEscortDestination:(HPVector) dest;
1177 0 :
1178 : - (BOOL) canAcceptEscort:(ShipEntity *)potentialEscort;
1179 0 : - (BOOL) acceptAsEscort:(ShipEntity *) other_ship;
1180 0 : - (void) deployEscorts;
1181 0 : - (void) dockEscorts;
1182 0 :
1183 : - (void) setTargetToNearestFriendlyStation;
1184 0 : - (void) setTargetToNearestStation;
1185 0 : - (void) setTargetToSystemStation;
1186 0 :
1187 : - (void) landOnPlanet:(OOPlanetEntity *)planet;
1188 0 :
1189 : - (void) abortDocking;
1190 0 : - (NSDictionary *) dockingInstructions;
1191 0 :
1192 : - (void) broadcastThargoidDestroyed;
1193 0 :
1194 : - (void) broadcastHitByLaserFrom:(ShipEntity*) aggressor_ship;
1195 0 :
1196 : // Sun glare filter - 0 for no filter, 1 for full filter
1197 : - (GLfloat) sunGlareFilter;
1198 0 : - (void) setSunGlareFilter:(GLfloat)newValue;
1199 0 :
1200 : // Unpiloted ships cannot broadcast messages, unless the unpilotedOverride is set to YES.
1201 : - (void) sendExpandedMessage:(NSString *) message_text toShip:(ShipEntity*) other_ship;
1202 0 : - (void) sendMessage:(NSString *) message_text toShip:(ShipEntity*) other_ship withUnpilotedOverride:(BOOL)unpilotedOverride;
1203 0 : - (void) broadcastAIMessage:(NSString *) ai_message;
1204 0 : - (void) broadcastMessage:(NSString *) message_text withUnpilotedOverride:(BOOL) unpilotedOverride;
1205 0 : - (void) setCommsMessageColor;
1206 0 : - (void) receiveCommsMessage:(NSString *) message_text from:(ShipEntity *) other;
1207 0 : - (void) commsMessage:(NSString *)valueString withUnpilotedOverride:(BOOL)unpilotedOverride;
1208 0 :
1209 : - (BOOL) markedForFines;
1210 0 : - (BOOL) markForFines;
1211 0 :
1212 : - (BOOL) isMining;
1213 0 :
1214 : - (void) spawn:(NSString *)roles_number;
1215 0 :
1216 : - (int) checkShipsInVicinityForWitchJumpExit;
1217 0 :
1218 : - (BOOL) trackCloseContacts;
1219 0 : - (void) setTrackCloseContacts:(BOOL) value;
1220 0 :
1221 : /*
1222 : * Changes a ship to a hulk, for example when the pilot ejects.
1223 : * Aso unsets hulkiness for example when a new pilot gets in.
1224 : */
1225 : - (void) setHulk:(BOOL) isNowHulk;
1226 0 : - (BOOL) isHulk;
1227 0 : #if OO_SALVAGE_SUPPORT
1228 : - (void) claimAsSalvage;
1229 : - (void) sendCoordinatesToPilot;
1230 : - (void) pilotArrived;
1231 : #endif
1232 :
1233 :
1234 :
1235 : - (OOJSScript *) script;
1236 0 : - (NSDictionary *) scriptInfo;
1237 0 : - (void) overrideScriptInfo:(NSDictionary *)override; // Add items from override (if not nil) to scriptInfo, replacing in case of duplicates. Used for subentities.
1238 0 :
1239 : - (BOOL) scriptedMisjump;
1240 0 : - (void) setScriptedMisjump:(BOOL)newValue;
1241 0 : - (GLfloat) scriptedMisjumpRange;
1242 0 : - (void) setScriptedMisjumpRange:(GLfloat)newValue;
1243 0 :
1244 :
1245 : - (Entity *)entityForShaderProperties;
1246 0 :
1247 : // Demo ship
1248 : - (void) setDemoShip: (OOScalar) demoRate;
1249 0 : - (BOOL) isDemoShip;
1250 0 : - (void) setDemoStartTime: (OOTimeAbsolute) time;
1251 0 :
1252 : /* *** Script events.
1253 : For NPC ships, these call doEvent: on the ship script.
1254 : For the player, they do that and also call doWorldScriptEvent:.
1255 : */
1256 : - (void) doScriptEvent:(jsid)message;
1257 0 : - (void) doScriptEvent:(jsid)message withArgument:(id)argument;
1258 0 : - (void) doScriptEvent:(jsid)message withArgument:(id)argument1 andArgument:(id)argument2;
1259 0 : - (void) doScriptEvent:(jsid)message withArguments:(NSArray *)arguments;
1260 0 : - (void) doScriptEvent:(jsid)message withArguments:(jsval *)argv count:(uintN)argc;
1261 0 : - (void) doScriptEvent:(jsid)message inContext:(JSContext *)context withArguments:(jsval *)argv count:(uintN)argc;
1262 0 :
1263 : /* Convenience to send an event with raw JS values, for example:
1264 : ShipScriptEventNoCx(ship, "doSomething", INT_TO_JSVAL(42));
1265 : */
1266 0 : #define ShipScriptEvent(context, ship, event, ...) do { \
1267 : jsval argv[] = { __VA_ARGS__ }; \
1268 : uintN argc = sizeof argv / sizeof *argv; \
1269 : [ship doScriptEvent:OOJSID(event) inContext:context withArguments:argv count:argc]; \
1270 : } while (0)
1271 :
1272 0 : #define ShipScriptEventNoCx(ship, event, ...) do { \
1273 : jsval argv[] = { __VA_ARGS__ }; \
1274 : uintN argc = sizeof argv / sizeof *argv; \
1275 : [ship doScriptEvent:OOJSID(event) withArguments:argv count:argc]; \
1276 : } while (0)
1277 :
1278 : - (void) reactToAIMessage:(NSString *)message context:(NSString *)debugContext; // Immediate message
1279 0 : - (void) sendAIMessage:(NSString *)message; // Queued message
1280 0 : - (void) doScriptEvent:(jsid)scriptEvent andReactToAIMessage:(NSString *)aiMessage;
1281 0 : - (void) doScriptEvent:(jsid)scriptEvent withArgument:(id)argument andReactToAIMessage:(NSString *)aiMessage;
1282 0 :
1283 : @end
1284 :
1285 :
1286 : #ifndef NDEBUG
1287 : @interface ShipEntity (Debug)
1288 :
1289 : - (OOShipGroup *) rawEscortGroup;
1290 0 :
1291 : @end
1292 : #endif
1293 :
1294 :
1295 : @interface Entity (SubEntityRelationship)
1296 :
1297 : /* For the common case of testing whether foo is a ship, bar is a ship, bar
1298 : is a subentity of foo and this relationship is represented sanely.
1299 : */
1300 : - (BOOL) isShipWithSubEntityShip:(Entity *)other;
1301 0 :
1302 : @end
1303 :
1304 :
1305 : NSDictionary *OODefaultShipShaderMacros(void);
1306 0 :
1307 : GLfloat getWeaponRangeFromType(OOWeaponType weapon_type);
1308 0 :
1309 : // Defined in OOConstToString.m
1310 : NSString *OOStringFromBehaviour(OOBehaviour behaviour) CONST_FUNC;
1311 0 :
1312 : // Weapon strings prefixed with EQ_, used in shipyard.plist.
1313 : NSString *OOEquipmentIdentifierFromWeaponType(OOWeaponType weapon) CONST_FUNC;
1314 0 : OOWeaponType OOWeaponTypeFromEquipmentIdentifierSloppy(NSString *string) PURE_FUNC; // Uses suffix match for backwards compatibility.
1315 0 : OOWeaponType OOWeaponTypeFromEquipmentIdentifierStrict(NSString *string) PURE_FUNC;
1316 0 : OOWeaponType OOWeaponTypeFromEquipmentIdentifierLegacy(NSString *string);
1317 0 :
1318 :
1319 : NSString *OOStringFromWeaponType(OOWeaponType weapon) CONST_FUNC;
1320 0 : OOWeaponType OOWeaponTypeFromString(NSString *string) PURE_FUNC;
1321 0 :
1322 : BOOL isWeaponNone(OOWeaponType weapon);
1323 0 :
1324 : NSString *OODisplayStringFromAlertCondition(OOAlertCondition alertCondition);
1325 0 :
1326 : NSString *OOStringFromShipDamageType(OOShipDamageType type) CONST_FUNC;
1327 0 :
|