Difference between revisions of "Oolite JavaScript Reference: Ship"

From Elite Wiki
(Methods)
(Partially updated for 1.74.)
Line 1: Line 1:
 
<small>'''Prototype:''' <code>[[Oolite JavaScript Reference: Entity|Entity]]</code></small><br />
 
<small>'''Prototype:''' <code>[[Oolite JavaScript Reference: Entity|Entity]]</code></small><br />
 
<small>'''Subtypes:''' <code>[[Oolite JavaScript Reference: Station|Station]]</code>, <code>[[Oolite JavaScript Reference: PlayerShip|PlayerShip]]</code></small>
 
<small>'''Subtypes:''' <code>[[Oolite JavaScript Reference: Station|Station]]</code>, <code>[[Oolite JavaScript Reference: PlayerShip|PlayerShip]]</code></small>
 
{{Oolite-class-added|1.70}}
 
   
 
The '''<code>Ship</code>''' class is an <code>[[Oolite JavaScript Reference: Entity|Entity]]</code> representing a ship, station, missile, cargo pod or other flying item – anything that can be specified in [[shipdata.plist]]. A <code>Ship</code> has all the properties and methods of a <code>Entity</code>, and several others.
 
The '''<code>Ship</code>''' class is an <code>[[Oolite JavaScript Reference: Entity|Entity]]</code> representing a ship, station, missile, cargo pod or other flying item – anything that can be specified in [[shipdata.plist]]. A <code>Ship</code> has all the properties and methods of a <code>Entity</code>, and several others.
   
<code>[[Oolite JavaScript Reference: Station|Station]]</code>s and the <code>[[Oolite JavaScript Reference: Player|Player]]</code> are types of ship. Note that these more specific types have additional properties and methods.
+
<code>[[Oolite JavaScript Reference: Station|Station]]</code>s and the <code>[[Oolite JavaScript Reference: PlayerShip|PlayerShip]]</code> are types of ship. Note that these more specific types have additional properties and methods.
   
 
== Properties ==
 
== Properties ==
 
=== <code>aftWeapon</code> ===
 
=== <code>aftWeapon</code> ===
{{Oolite-prop-future|1.74}}
+
{{Oolite-prop-added|1.74}}
'''aftWeapon''' : EquipmentType(read-only)
+
'''aftWeapon''' : EquipmentType (read-only)
The currently equipped aft weapon, or null.
+
The currently equipped aft weapon, or <code>null</code>.
Identical to the equivalent [[Oolite JavaScript Reference: PlayerShip#aftWeapon|PlayerShip]] property.
+
  +
'''Bug:''' In Oolite 1.74.0, attempting to access a weapon slot with no weapon in it will halt the script without any error message.
   
'''See also''': <code>[[#forwardWeapon|forwardWeapon]]</code>
+
'''See also''': <code>[[#forwardWeapon|forwardWeapon]]</code>, <code>[[#portWeapon|portWeapon]]</code>, <code>[[#starboardWeapon|starboardWeapon]]</code>
   
 
=== <code>AI</code> ===
 
=== <code>AI</code> ===
Line 28: Line 26:
   
 
'''See also:''' <code>[[#AI|AI]]</code>, <code>[[#reactToAIMessage|reactToAIMessage()]]</code>, <code>[[#hasSuspendedAI|hasSuspendedAI]]</code>
 
'''See also:''' <code>[[#AI|AI]]</code>, <code>[[#reactToAIMessage|reactToAIMessage()]]</code>, <code>[[#hasSuspendedAI|hasSuspendedAI]]</code>
 
=== <code>availableCargoSpace (deprecated)</code> ===
 
{{Oolite-prop-added|1.72}}
 
'''availableCargoSpace''': Number (read-only integer)
 
The ship’s free cargo space, in tons. Deprecated in favour of cargoSpaceAvailable.
 
   
 
=== <code>beaconCode</code> ===
 
=== <code>beaconCode</code> ===
Line 44: Line 37:
 
The bounty on the ship. In the case of the player, it is halved at each witchspace jump.<br>
 
The bounty on the ship. In the case of the player, it is halved at each witchspace jump.<br>
 
It is actually the legal status of the ship that is shown here and not the bounty. For all ships both are the same but for anything with scan class Thargoid the legal status is only based on the ships mass and has no relation to its defined bounty.
 
It is actually the legal status of the ship that is shown here and not the bounty. For all ships both are the same but for anything with scan class Thargoid the legal status is only based on the ships mass and has no relation to its defined bounty.
 
=== <code>cargoCapacity (deprecated)</code> ===
 
'''cargoCapacity''': Number (read-only integer)
 
The ship’s cargo capacity, in tons. Name introduced with version 1.72. Old name was maxCargo. Deprecated in favour of '''cargoSpaceCapacity'''
 
   
 
=== <code>cargoSpaceAvailable</code> ===
 
=== <code>cargoSpaceAvailable</code> ===
{{Oolite-prop-future|1.74}}
+
{{Oolite-prop-added|1.74}}
 
'''cargoSpaceAvailable''' : Number (read-only integer)
 
'''cargoSpaceAvailable''' : Number (read-only integer)
 
The ship’s available cargo space, in tons. Name introduced with version 1.74. Replaces availableCargoSpace.
 
The ship’s available cargo space, in tons. Name introduced with version 1.74. Replaces availableCargoSpace.
   
 
=== <code>cargoSpaceCapacity</code> ===
 
=== <code>cargoSpaceCapacity</code> ===
{{Oolite-prop-future|1.74}}
+
{{Oolite-prop-added|1.74}}
 
'''cargoSpaceCapacity''' : Number (read-only integer)
 
'''cargoSpaceCapacity''' : Number (read-only integer)
 
The ship’s cargo capacity, in tons. Name introduced with version 1.74. Old names were maxCargo, cargoCapacity.
 
The ship’s cargo capacity, in tons. Name introduced with version 1.74. Old names were maxCargo, cargoCapacity.
   
 
=== <code>cargoSpaceUsed</code> ===
 
=== <code>cargoSpaceUsed</code> ===
{{Oolite-prop-added|1.72}}
 
 
'''cargoSpaceUsed''' : Number (read-only integer)
 
'''cargoSpaceUsed''' : Number (read-only integer)
 
The ship’s current cargo, in tons. Any ship carrying less than
 
The ship’s current cargo, in tons. Any ship carrying less than
   
 
=== <code>contracts</code> ===
 
=== <code>contracts</code> ===
{{Oolite-prop-future|1.74}}
+
{{Oolite-prop-added|1.74}}
 
'''contracts''' : Array (read-only NSDictionary)
 
'''contracts''' : Array (read-only NSDictionary)
 
The ship’s contracts. (For now only available for the player). Each contract contains the entries: <code>commodity: string, quantity: integer, description: string, start: integer, destination: integer, startName: string, destinationName: string, eta: integer, etaDescription: string, fee: Integer, premium: Integer</code><br>
 
The ship’s contracts. (For now only available for the player). Each contract contains the entries: <code>commodity: string, quantity: integer, description: string, start: integer, destination: integer, startName: string, destinationName: string, eta: integer, etaDescription: string, fee: Integer, premium: Integer</code><br>
Line 85: Line 73:
   
 
=== <code>desiredSpeed</code> ===
 
=== <code>desiredSpeed</code> ===
{{Oolite-prop-added|1.72}}
 
 
'''desiredSpeed''' : Number (read/write nonnegative, read-only for player)
 
'''desiredSpeed''' : Number (read/write nonnegative, read-only for player)
 
The speed the AI will attempt to maintain. The AI core and AI script may change this from time to time. The corresponding AI method is <code>setSpeedFactorTo:</code>; a speed factor of 1.0 corresponds to a <code>desiredSpeed</code> equal to <code>[[#maxSpeed|maxSpeed]]</code>.
 
The speed the AI will attempt to maintain. The AI core and AI script may change this from time to time. The corresponding AI method is <code>setSpeedFactorTo:</code>; a speed factor of 1.0 corresponds to a <code>desiredSpeed</code> equal to <code>[[#maxSpeed|maxSpeed]]</code>.
Line 91: Line 78:
 
=== <code>displayName</code> ===
 
=== <code>displayName</code> ===
 
'''displayName''' : String (read/write, read-only for player)
 
'''displayName''' : String (read/write, read-only for player)
The name of the ship as seen by the player. By default it is the same as name(<code>name</code> key in [[shipdata.plist]]). This property is changed from '''shipDisplayName''' in 1.72
+
The name of the ship as seen by the player. By default it is the same as name(<code>name</code> key in [[shipdata.plist]]).
   
 
=== <code>entityPersonality</code> ===
 
=== <code>entityPersonality</code> ===
Line 98: Line 85:
   
 
=== <code>equipment</code> ===
 
=== <code>equipment</code> ===
{{Oolite-prop-future|1.74}}
+
{{Oolite-prop-added|1.74}}
 
'''equipment''' : Array of [[Oolite_JavaScript_Reference:_EquipmentInfo|EquipmentInfo ]] (read-only)
 
'''equipment''' : Array of [[Oolite_JavaScript_Reference:_EquipmentInfo|EquipmentInfo ]] (read-only)
 
The equipment a ship is carrying.
 
The equipment a ship is carrying.
  +
  +
=== <code>escortGroup</code> ===
  +
'''escortGroup''' : [[Oolite JavaScript Reference: ShipGroup|ShipGroup]]
  +
The ship’s deployed escorts.
   
 
=== <code>escorts</code> ===
 
=== <code>escorts</code> ===
 
'''escorts''' : Array (read-only array of [[Oolite JavaScript Reference: Entity|Entity]]s)
 
'''escorts''' : Array (read-only array of [[Oolite JavaScript Reference: Entity|Entity]]s)
The ship’s deployed escorts.
 
 
=== <code>escortGroup</code> ===
 
{{Oolite-prop-added|1.73}}
 
'''escortGroup''' : [[Oolite JavaScript Reference: ShipGroup|ShipGroup]] (Class added with Oolite 1.73)
 
 
The ship’s deployed escorts.
 
The ship’s deployed escorts.
   
 
=== <code>forwardWeapon</code> ===
 
=== <code>forwardWeapon</code> ===
{{Oolite-prop-future|1.74}}
+
{{Oolite-prop-added|1.74}}
'''forwardWeapon''' : EquipmentType(read-only)
+
'''forwardWeapon''' : EquipmentType (read-only)
Identical to the equivalent [[Oolite JavaScript Reference: PlayerShip#forwardWeapon|PlayerShip]] property.
+
The currently equipped forward weapon, or <code>null</code>.
   
'''See also''': <code>[[#aftWeapon|aftWeapon]]</code>
 
  +
'''Bug:''' In Oolite 1.74.0, attempting to access a weapon slot with no weapon in it will halt the script without any error message.
  +
  +
'''See also''': <code>[[#aftWeapon|aftWeapon]]</code>, <code>[[#portWeapon|portWeapon]]</code>, <code>[[#starboardWeapon|starboardWeapon]]</code>
   
 
=== <code>fuel</code> ===
 
=== <code>fuel</code> ===
Line 123: Line 111:
   
 
'''See also:''' <code>[[Oolite JavaScript Reference: Player#fuelLeakRate|Player.fuelLeakRate]]</code>
 
'''See also:''' <code>[[Oolite JavaScript Reference: Player#fuelLeakRate|Player.fuelLeakRate]]</code>
  +
  +
<!--
  +
=== <code>fuelChargeRate</code> ===
  +
Added in 1.74 but not documented, because it’s currently always 1.0.
  +
-->
   
 
=== <code>group</code> ===
 
=== <code>group</code> ===
{{Oolite-prop-added|1.73}}
 
  +
'''group''' : [[Oolite JavaScript Reference: ShipGroup|ShipGroup]]
'''group''' : [[Oolite JavaScript Reference: ShipGroup|ShipGroup]] (Class added with Oolite 1.73)
 
 
Contains ship’s belonging to each other. Added pirate groups are an example or a station with its launched defenders.<br>
 
Contains ship’s belonging to each other. Added pirate groups are an example or a station with its launched defenders.<br>
 
A group is an individual object that can be linked to several ships belonging to the same group. When a ship dies and the group object has still owners, the group stays active as object. The group is only removed from memory after the last ship that had this group as property is removed.<br>
 
A group is an individual object that can be linked to several ships belonging to the same group. When a ship dies and the group object has still owners, the group stays active as object. The group is only removed from memory after the last ship that had this group as property is removed.<br>
Line 133: Line 125:
 
this.ship.group = new ShipGroup();
 
this.ship.group = new ShipGroup();
 
this.ship.group.addShip(this.ship);
 
this.ship.group.addShip(this.ship);
 
=== <code><del>groupID</del></code> ===
 
Removed in 1.73. Use <code>[[#group|group]]</code> instead.
 
   
 
=== <code>hasHostileTarget</code> ===
 
=== <code>hasHostileTarget</code> ===
Line 148: Line 137:
 
'''heatInsulation''' : Number (read/write)
 
'''heatInsulation''' : Number (read/write)
 
The ship’s heat insulation factor. 1.0 is normal, higher values mean more resistance to heat.
 
The ship’s heat insulation factor. 1.0 is normal, higher values mean more resistance to heat.
 
=== <code>isBoulder</code> ===
 
{{Oolite-prop-added|1.74}}
 
'''isBoulder''' : Boolean (read/write)
 
<code>true</code> if the ship is a boulder (i.e., has the role "boulder in its roleset)
 
   
 
=== <code>isBeacon</code> ===
 
=== <code>isBeacon</code> ===
Line 159: Line 143:
   
 
'''See also:''' <code>[[#beaconCode|beaconCode]]</code>
 
'''See also:''' <code>[[#beaconCode|beaconCode]]</code>
  +
  +
=== <code>isBoulder</code> ===
  +
{{Oolite-prop-added|1.74}}
  +
'''isBoulder''' : Boolean (read/write)
  +
<code>true</code> if the ship is a boulder (i.e., has the role "boulder in its roleset)
   
 
=== <code>isCargo</code> ===
 
=== <code>isCargo</code> ===
Line 185: Line 174:
   
 
=== <code>isMine</code> ===
 
=== <code>isMine</code> ===
{{Oolite-prop-added|1.73}}
 
 
'''isMine''' : Boolean (read-only)
 
'''isMine''' : Boolean (read-only)
 
<code>true</code> if the ship is a mine, <code>false</code> otherwise.
 
<code>true</code> if the ship is a mine, <code>false</code> otherwise.
   
 
=== <code>isMissile</code> ===
 
=== <code>isMissile</code> ===
{{Oolite-prop-added|1.73}}
 
 
'''isMissile''' : Boolean (read-only)
 
'''isMissile''' : Boolean (read-only)
 
<code>true</code> if the ship is a missile, <code>false</code> otherwise.
 
<code>true</code> if the ship is a missile, <code>false</code> otherwise.
Line 220: Line 207:
   
 
=== <code>isWeapon</code> ===
 
=== <code>isWeapon</code> ===
{{Oolite-prop-added|1.73}}
 
 
'''isWeapon''' : Boolean (read-only)
 
'''isWeapon''' : Boolean (read-only)
 
<code>true</code> if the ship is a weapon, <code>false</code> otherwise. Currently equivalent to <code>[[#isMissile|isMissile]] || [[#isMine|isMine]] </code>, but new categories of weapon could be added in future.
 
<code>true</code> if the ship is a weapon, <code>false</code> otherwise. Currently equivalent to <code>[[#isMissile|isMissile]] || [[#isMine|isMine]] </code>, but new categories of weapon could be added in future.
   
 
=== <code>lightsActive</code> ===
 
=== <code>lightsActive</code> ===
{{Oolite-prop-future|1.74}}
+
{{Oolite-prop-added|1.74}}
 
'''lightsActive''' : Boolean (read-write)
 
'''lightsActive''' : Boolean (read-write)
 
Setting this property to <code>true</code> turns on all the entity’s flashers, and setting it to <code>false</code> turns them off. Setting it sets the <code>lightsActive</code> property for all subentities, but subentities’ setting can also be manipulated separately. In addition to affecting flashers, the value can be used by shaders.
 
Setting this property to <code>true</code> turns on all the entity’s flashers, and setting it to <code>false</code> turns them off. Setting it sets the <code>lightsActive</code> property for all subentities, but subentities’ setting can also be manipulated separately. In addition to affecting flashers, the value can be used by shaders.
   
 
Note: <code>lightsActive</code> is always <code>true</code> when a ship is spawned, although individual flashers may be off because they have <code>initially_on</code> set to false in their ''shipdata.plist'' declarations.
 
Note: <code>lightsActive</code> is always <code>true</code> when a ship is spawned, although individual flashers may be off because they have <code>initially_on</code> set to false in their ''shipdata.plist'' declarations.
 
=== <code>maxCargo</code> ===
 
'''maxCargo''' : Number (read-only integer)
 
The ship’s cargo capacity. This property is renamed to '''cargoCapacity''' in 1.72.
 
   
 
=== <code>maxSpeed</code> ===
 
=== <code>maxSpeed</code> ===
Line 242: Line 224:
   
 
=== <code>maxThrust</code> ===
 
=== <code>maxThrust</code> ===
{{Oolite-prop-future|1.74}}
+
{{Oolite-prop-added|1.74}}
 
'''maxThrust''' : Number (read-only)
 
'''maxThrust''' : Number (read-only)
 
The ship’s maximum <code>[[#thrust|thrust]]</code>. This value is the one defined as <code>thrust</code> in ''[[Shipdata.plist#thrust|shipdata.plist]]''.
 
The ship’s maximum <code>[[#thrust|thrust]]</code>. This value is the one defined as <code>thrust</code> in ''[[Shipdata.plist#thrust|shipdata.plist]]''.
   
 
=== <code>missileCapacity</code> ===
 
=== <code>missileCapacity</code> ===
{{Oolite-prop-future|1.74}}
+
{{Oolite-prop-added|1.74}}
 
'''missileCapacity''' : Number (read-only integer)
 
'''missileCapacity''' : Number (read-only integer)
 
The maximum number of missiles the ship can carry.
 
The maximum number of missiles the ship can carry.
   
 
=== <code>missiles</code> ===
 
=== <code>missiles</code> ===
{{Oolite-prop-future|1.74}}
+
{{Oolite-prop-added|1.74}}
 
'''missiles''' : Array (read-only array of [[Oolite JavaScript Reference: EquipmentInfo|EquipmentInfo]])
 
'''missiles''' : Array (read-only array of [[Oolite JavaScript Reference: EquipmentInfo|EquipmentInfo]])
 
The ship’s loaded missiles.
 
The ship’s loaded missiles.
Line 258: Line 240:
 
=== <code>name</code> ===
 
=== <code>name</code> ===
 
'''name''' : String (read/write, read-only for player)
 
'''name''' : String (read/write, read-only for player)
The name of the ship type (<code>name</code> key in [[shipdata.plist]]). This property was changed from '''shipDescription''' in 1.72
+
The name of the ship type (<code>name</code> key in [[shipdata.plist]]).
   
 
=== <code>passengerCapacity</code> ===
 
=== <code>passengerCapacity</code> ===
{{Oolite-prop-added|1.72}}
 
 
'''passengerCapacity''' : Number (read-only integer)
 
'''passengerCapacity''' : Number (read-only integer)
 
The ship’s maximum passenger capacity.
 
The ship’s maximum passenger capacity.
   
 
=== <code>passengerCount</code> ===
 
=== <code>passengerCount</code> ===
{{Oolite-prop-added|1.72}}
 
 
'''passengerCount''' : Number (read-only integer)
 
'''passengerCount''' : Number (read-only integer)
 
The ship’s current number of passengers.
 
The ship’s current number of passengers.
   
 
=== <code>passengers</code> ===
 
=== <code>passengers</code> ===
{{Oolite-prop-future|1.74}}
+
{{Oolite-prop-added|1.74}}
 
'''passengers''' : Array (read-only NSDictionary)
 
'''passengers''' : Array (read-only NSDictionary)
 
The ship’s passengers. (For now only available for the player). Each passengers list contains the entries: <code>name: String, start: integer, destination: integer, startName: string, destinationName: string, eta: integer, etaDescription: string, fee: Integer, premium: Integer</code><br>
 
The ship’s passengers. (For now only available for the player). Each passengers list contains the entries: <code>name: String, start: integer, destination: integer, startName: string, destinationName: string, eta: integer, etaDescription: string, fee: Integer, premium: Integer</code><br>
Line 286: Line 266:
   
 
start and destination contain system ID numbers for planets in the current galaxy chart, eta is in clock seconds, fee is the amount that the player will receive when delivering this passenger, and premium shows the amount the player received when the passenger boarded the ship.
 
start and destination contain system ID numbers for planets in the current galaxy chart, eta is in clock seconds, fee is the amount that the player will receive when delivering this passenger, and premium shows the amount the player received when the passenger boarded the ship.
  +
  +
=== <code>portWeapon</code> ===
  +
{{Oolite-prop-added|1.74}}
  +
'''portWeapon''' : EquipmentType (read-only)
  +
The currently equipped forward weapon, or <code>null</code>. Currently, this is always <code>null</code> for non-player ships.
  +
  +
'''Bug:''' In Oolite 1.74.0, attempting to access a weapon slot with no weapon in it will halt the script without any error message.
  +
  +
'''See also''': <code>[[#aftWeapon|aftWeapon]]</code>, <code>[[#forwardWeapon|forwardWeapon]]</code>, <code>[[#starboardWeapon|starboardWeapon]]</code>
   
 
=== <code>potentialCollider</code> ===
 
=== <code>potentialCollider</code> ===
Line 317: Line 306:
   
 
=== <code>savedCoordinates</code> ===
 
=== <code>savedCoordinates</code> ===
{{Oolite-prop-future|1.74}}
+
{{Oolite-prop-added|1.74}}
 
'''savedCoordinates''' : [[Oolite JavaScript Reference: Vector|Vector]] (read-write)
 
'''savedCoordinates''' : [[Oolite JavaScript Reference: Vector|Vector]] (read-write)
 
The savedCoordinates of the ship in system co-ordinates. The savedCoordinates vector is only used by AI scripting to store a coordinate that can be used by other AI commands like <code>setDestinationToCoordinates</code>. It are the same coordinates that are set by the AI command: <code>"setCoordinates: X Y Z"</code>
 
The savedCoordinates of the ship in system co-ordinates. The savedCoordinates vector is only used by AI scripting to store a coordinate that can be used by other AI commands like <code>setDestinationToCoordinates</code>. It are the same coordinates that are set by the AI command: <code>"setCoordinates: X Y Z"</code>
Line 333: Line 322:
 
The contents of the <code>script_info</code> key in the ship’s ''[[shipdata.plist]]'' entry, if any. This may be any [[property list]] object, but the reccomended approach is to use a dictionary whose keys have a unique prefix (such as you should be using for file names, ship names etc.). A property list dictionary is converted to a JavaScript object with properties corresponding to the dictionary’s keys. All other property list types used with Oolite have directly corresponding JavaScript types.
 
The contents of the <code>script_info</code> key in the ship’s ''[[shipdata.plist]]'' entry, if any. This may be any [[property list]] object, but the reccomended approach is to use a dictionary whose keys have a unique prefix (such as you should be using for file names, ship names etc.). A property list dictionary is converted to a JavaScript object with properties corresponding to the dictionary’s keys. All other property list types used with Oolite have directly corresponding JavaScript types.
   
=== <code>shipDescription</code> ===
 
'''shipDescription''' : String (read/write, read-only for player)
 
The name of the ship type (<code>name</code> key in [[shipdata.plist]]). This property is changed into '''name''' in 1.72
 
 
=== <code>shipDisplayName</code> ===
 
'''shipDisplayName''' : String (read/write, read-only for player)
 
The name of the ship as seen by the player. By default it is the same as shipDescription(<code>name</code> key in [[shipdata.plist]]). This property is changed into '''displayName''' in 1.72
 
   
 
=== <code>speed</code> ===
 
=== <code>speed</code> ===
Line 346: Line 328:
   
 
'''See also:''' <code>[[#maxSpeed|maxSpeed]]</code>
 
'''See also:''' <code>[[#maxSpeed|maxSpeed]]</code>
  +
  +
=== <code>starboardWeapon</code> ===
  +
{{Oolite-prop-added|1.74}}
  +
'''starboardWeapon''' : EquipmentType (read-only)
  +
The currently equipped forward weapon, or <code>null</code>. Currently, this is always <code>null</code> for non-player ships.
  +
  +
'''Bug:''' In Oolite 1.74.0, attempting to access a weapon slot with no weapon in it will halt the script without any error message.
  +
  +
'''See also''': <code>[[#aftWeapon|aftWeapon]]</code>, <code>[[#forwardWeapon|forwardWeapon]]</code>, <code>[[#portWeapon|portWeapon]]</code>
   
 
=== <code>subEntities</code> ===
 
=== <code>subEntities</code> ===
Line 363: Line 354:
   
 
=== <code>thrust</code> ===
 
=== <code>thrust</code> ===
{{Oolite-prop-future|1.74}}
+
{{Oolite-prop-added|1.74}}
 
'''thrust''' : Number (read/write (For player read-only))
 
'''thrust''' : Number (read/write (For player read-only))
 
The ship’s thrust, ranging from 0 to <code>maxThrust</code>. This value determines how fast the ship accelerates or decelerates. Speed-change in m/s².
 
The ship’s thrust, ranging from 0 to <code>maxThrust</code>. This value determines how fast the ship accelerates or decelerates. Speed-change in m/s².
   
 
=== <code>thrustVector</code> ===
 
=== <code>thrustVector</code> ===
{{Oolite-prop-future|1.74}}
+
{{Oolite-prop-added|1.74}}
 
'''thrustVector''' : Vector3D (read-only)
 
'''thrustVector''' : Vector3D (read-only)
 
The inertialess velocity generated by the engines.
 
The inertialess velocity generated by the engines.
Line 375: Line 366:
   
 
=== <code>velocity</code> ===
 
=== <code>velocity</code> ===
{{Oolite-prop-future|1.74}}
+
{{Oolite-prop-added|1.74}}
 
'''velocity''' : Vector3D (read/write)
 
'''velocity''' : Vector3D (read/write)
 
The ship’s velocity.
 
The ship’s velocity.
Line 440: Line 431:
   
 
=== <code>commsMessage</code> ===
 
=== <code>commsMessage</code> ===
{{oolite-method-added|1.72}}
 
 
function '''commsMessage'''(message : String) : Ship
 
function '''commsMessage'''(message : String) : Ship
 
Make the ship type entity broadcast the specified message. Works on buoys and subentities as well as normal ships and stations.
 
Make the ship type entity broadcast the specified message. Works on buoys and subentities as well as normal ships and stations.
Line 453: Line 443:
   
 
=== <code>dumpCargo</code> ===
 
=== <code>dumpCargo</code> ===
{{oolite-method-added|1.71}}
 
 
function '''dumpCargo'''() : Ship
 
function '''dumpCargo'''() : Ship
 
Ejects one item of cargo from the ship, and returns the cargo item. Returns <code>null</code> if the ship has no cargo, anything has been ejected in the last 0.5 seconds, or if sent to the player while docked.
 
Ejects one item of cargo from the ship, and returns the cargo item. Returns <code>null</code> if the ship has no cargo, anything has been ejected in the last 0.5 seconds, or if sent to the player while docked.
Line 467: Line 456:
   
 
=== <code>ejectSpecificItem</code> ===
 
=== <code>ejectSpecificItem</code> ===
{{oolite-method-added|1.71}}
 
 
function '''ejectSpecificItem'''(itemKey : String) : Ship
 
function '''ejectSpecificItem'''(itemKey : String) : Ship
 
Spawns a ship with the ''shipdata.plist'' key <code>itemKey</code> immediately behind the ship, with a slight backwards velocity. The scanClass of the ejected item will always be CLASS_CARGO.
 
Spawns a ship with the ''shipdata.plist'' key <code>itemKey</code> immediately behind the ship, with a slight backwards velocity. The scanClass of the ejected item will always be CLASS_CARGO.
Line 495: Line 483:
   
 
=== <code>fireECM</code> ===
 
=== <code>fireECM</code> ===
{{Oolite-method-added|1.73}}
 
 
function '''fireECM'''()
 
function '''fireECM'''()
 
activates an ecm burst, identical as the AI command.
 
activates an ecm burst, identical as the AI command.
Line 505: Line 492:
   
 
=== <code>hasEquipment</code> ===
 
=== <code>hasEquipment</code> ===
{{Oolite-method-added|1.73}}
 
 
function '''hasEquipment'''(equipmentType : [[Oolite JavaScript Reference: EquipmentInfo#Equipment Expressions|equipmentInfoExpression]] [, includeWeapons : Boolean]) : Boolean
 
function '''hasEquipment'''(equipmentType : [[Oolite JavaScript Reference: EquipmentInfo#Equipment Expressions|equipmentInfoExpression]] [, includeWeapons : Boolean]) : Boolean
 
Returns <code>true</code> if the given piece of equipment is present on/in the ship, <code>false</code> if it is not. If <code>includeWeapons</code> is false, primary weapons (lasers) and secondary weapons (missiles and mines) are excluded. If <code>includeWeapons</code> is not specified, <code>true</code> is assumed.
 
Returns <code>true</code> if the given piece of equipment is present on/in the ship, <code>false</code> if it is not. If <code>includeWeapons</code> is false, primary weapons (lasers) and secondary weapons (missiles and mines) are excluded. If <code>includeWeapons</code> is not specified, <code>true</code> is assumed.
Line 523: Line 509:
   
 
=== <code>remove</code> ===
 
=== <code>remove</code> ===
{{Oolite-method-added|1.72}}
 
 
function '''remove'''()
 
function '''remove'''()
 
Immediately removes the ship from the universe. Works on all ships except the player, including the main station.
 
Immediately removes the ship from the universe. Works on all ships except the player, including the main station.
Line 532: Line 517:
 
{{Oolite-method-future|1.74}}
 
{{Oolite-method-future|1.74}}
 
function '''removeEquipment'''(equipmentType : [[Oolite JavaScript Reference: EquipmentInfo#Equipment Expressions|equipmentInfoExpression]])
 
function '''removeEquipment'''(equipmentType : [[Oolite JavaScript Reference: EquipmentInfo#Equipment Expressions|equipmentInfoExpression]])
Removes the given piece of equipment from the ship. (Prior to Oolite 1.74, this method was only available for the player’s ship.)
+
Removes the given piece of equipment from the ship.
 
This function can also be used to remove missiles (and mines). If more than one missile of the same type is found on board, only one of them will be removed.
 
This function can also be used to remove missiles (and mines). If more than one missile of the same type is found on board, only one of them will be removed.
   
Line 560: Line 545:
 
{{Oolite-method-future|1.74}}
 
{{Oolite-method-future|1.74}}
 
function '''setEquipmentStatus'''(equipmentType : [[Oolite JavaScript Reference: EquipmentInfo#Equipment Expressions|equipmentInfoExpression]], statusKey : String)
 
function '''setEquipmentStatus'''(equipmentType : [[Oolite JavaScript Reference: EquipmentInfo#Equipment Expressions|equipmentInfoExpression]], statusKey : String)
Changes the status of the given piece of equipment from the ship. The two only valid status keys are <code>"EQUIPMENT_OK"</code>, <code>"EQUIPMENT_DAMAGED"</code>. (Prior to Oolite 1.74, this method was only available for the player’s ship.)
+
Changes the status of the given piece of equipment from the ship. The two only valid status keys are <code>"EQUIPMENT_OK"</code>, <code>"EQUIPMENT_DAMAGED"</code>.
   
 
'''Note:''' by design, this method will throw an exception if called with an equipment type that does not exist. To test whether an equipment type exists, use <code>[[Oolite JavaScript Reference: EquipmentInfo#infoForKey|EquipmentInfo.infoForKey()]]</code>, which will return <code>null</code> for undefined equipment.
 
'''Note:''' by design, this method will throw an exception if called with an equipment type that does not exist. To test whether an equipment type exists, use <code>[[Oolite JavaScript Reference: EquipmentInfo#infoForKey|EquipmentInfo.infoForKey()]]</code>, which will return <code>null</code> for undefined equipment.
Line 567: Line 552:
   
 
=== <code>setScript</code> ===
 
=== <code>setScript</code> ===
{{oolite-method-added|1.71}}
 
 
function '''setScript'''(scriptName : String)
 
function '''setScript'''(scriptName : String)
 
Set, or completely replace, the javascript code associated to a ship entity.
 
Set, or completely replace, the javascript code associated to a ship entity.
   
 
=== <code>spawn</code> ===
 
=== <code>spawn</code> ===
{{oolite-method-added|1.71}}
 
 
function '''spawn'''(role : String [, count : Number]) : Array
 
function '''spawn'''(role : String [, count : Number]) : Array
 
Attempts to create <code>count</code> (maximum: 64) ships of role <code>role</code> close to the ship – specifically, inside the ship’s collision radius. (Since creating ships may fail, the number created may be less than <code>count</code>). The created ships are returned in an array. If <code>count</code> is not specified, one will be assumed.
 
Attempts to create <code>count</code> (maximum: 64) ships of role <code>role</code> close to the ship – specifically, inside the ship’s collision radius. (Since creating ships may fail, the number created may be less than <code>count</code>). The created ships are returned in an array. If <code>count</code> is not specified, one will be assumed.
Line 582: Line 565:
   
 
=== <code>spawnOne</code> ===
 
=== <code>spawnOne</code> ===
{{oolite-method-added|1.71}}
 
 
function '''spawnOne'''(role : String) : Ship
 
function '''spawnOne'''(role : String) : Ship
 
Convenience method which calls <code>[[#spawn|spawn]](role)</code> and returns the first element of the resulting array, or <code>null</code> if <code>spawn()</code> fails.
 
Convenience method which calls <code>[[#spawn|spawn]](role)</code> and returns the first element of the resulting array, or <code>null</code> if <code>spawn()</code> fails.

Revision as of 14:18, 18 June 2010

Prototype: Entity
Subtypes: Station, PlayerShip

The Ship class is an Entity representing a ship, station, missile, cargo pod or other flying item – anything that can be specified in shipdata.plist. A Ship has all the properties and methods of a Entity, and several others.

Stations and the PlayerShip are types of ship. Note that these more specific types have additional properties and methods.

Contents

Properties

aftWeapon

This property was added in Oolite test release 1.74.

aftWeapon : EquipmentType (read-only)

The currently equipped aft weapon, or null.

Bug: In Oolite 1.74.0, attempting to access a weapon slot with no weapon in it will halt the script without any error message.

See also: forwardWeapon, portWeapon, starboardWeapon

AI

AI : String (read-only)

The name of the ship’s current AI.

See also: AIState, setAI(), switchAI(), exitAI()

AIState

AIState : String (read/write, read-only for player)

The ship’s AI’s current state.

See also: AI, reactToAIMessage(), hasSuspendedAI

beaconCode

beaconCode : String (read-only)

If the ship is a beacon, an identifying string. The first character is used for identification on the Advanced Space Compass. For non-beacons, this property is null.

See also: isBeacon

bounty

bounty : Number (read/write integer)

The bounty on the ship. In the case of the player, it is halved at each witchspace jump.
It is actually the legal status of the ship that is shown here and not the bounty. For all ships both are the same but for anything with scan class Thargoid the legal status is only based on the ships mass and has no relation to its defined bounty.

cargoSpaceAvailable

This property was added in Oolite test release 1.74.

cargoSpaceAvailable : Number (read-only integer)

The ship’s available cargo space, in tons. Name introduced with version 1.74. Replaces availableCargoSpace.

cargoSpaceCapacity

This property was added in Oolite test release 1.74.

cargoSpaceCapacity : Number (read-only integer)

The ship’s cargo capacity, in tons. Name introduced with version 1.74. Old names were maxCargo, cargoCapacity.

cargoSpaceUsed

cargoSpaceUsed : Number (read-only integer)

The ship’s current cargo, in tons. Any ship carrying less than

contracts

This property was added in Oolite test release 1.74.

contracts : Array (read-only NSDictionary)

The ship’s contracts. (For now only available for the player). Each contract contains the entries: commodity: string, quantity: integer, description: string, start: integer, destination: integer, startName: string, destinationName: string, eta: integer, etaDescription: string, fee: Integer, premium: Integer

For example, the information of the first contract can be obtained by:

player.ship.contracts[0].commodity
player.ship.contracts[0].quantity
player.ship.contracts[0].description
player.ship.contracts[0].start
player.ship.contracts[0].destination
player.ship.contracts[0].startName
player.ship.contracts[0].destinationName
player.ship.contracts[0].eta  // Estimated Time of Arrival.
player.ship.contracts[0].etaDescription
player.ship.contracts[0].fee      // The profit of the contract, paid out on successful delivery.
player.ship.contracts[0].premium  // The sum paid to obtain the goods and paid back on successful delivery.

start and destination contain system ID numbers for planets in the current galaxy chart, eta is in clock seconds, fee is the amount that the player will receive when delivering this contract, and premium was the amount the player had to pay to secure this contract.

desiredSpeed

desiredSpeed : Number (read/write nonnegative, read-only for player)

The speed the AI will attempt to maintain. The AI core and AI script may change this from time to time. The corresponding AI method is setSpeedFactorTo:; a speed factor of 1.0 corresponds to a desiredSpeed equal to maxSpeed.

displayName

displayName : String (read/write, read-only for player)

The name of the ship as seen by the player. By default it is the same as name(name key in shipdata.plist).

entityPersonality

entityPersonality : Number (read-only integer)

A random number in the range 0..32767 which is generated when the ship is created. Equivalent to the entityPersonalityInt uniform binding.

equipment

This property was added in Oolite test release 1.74.

equipment : Array of EquipmentInfo  (read-only)

The equipment a ship is carrying.

escortGroup

escortGroup : ShipGroup

The ship’s deployed escorts.

escorts

escorts : Array (read-only array of Entitys)

The ship’s deployed escorts.

forwardWeapon

This property was added in Oolite test release 1.74.

forwardWeapon : EquipmentType (read-only)

The currently equipped forward weapon, or null.

Bug: In Oolite 1.74.0, attempting to access a weapon slot with no weapon in it will halt the script without any error message.

See also: aftWeapon, portWeapon, starboardWeapon

fuel

fuel : Number (read/write)

The ship’s current fuel capacity, in LY. The game will limit this to the range 0..7, and round it off to the nearest tenth.

See also: Player.fuelLeakRate


group

group : ShipGroup

Contains ship’s belonging to each other. Added pirate groups are an example or a station with its launched defenders.
A group is an individual object that can be linked to several ships belonging to the same group. When a ship dies and the group object has still owners, the group stays active as object. The group is only removed from memory after the last ship that had this group as property is removed.
Adding a group to a ship does not automatic puts that ship in the group. For that to happen you need also use the addShip() command. e.g.

this.ship.group = new ShipGroup();
this.ship.group.addShip(this.ship);

hasHostileTarget

hasHostileTarget : Boolean (read-only)

true if the ship’s AI is trying to kill something, false otherwise. Always false for the player.

hasSuspendedAI

hasSuspendedAI : Boolean (read-only)

true if the ship has suspended AIs, false otherwise.

heatInsulation

heatInsulation : Number (read/write)

The ship’s heat insulation factor. 1.0 is normal, higher values mean more resistance to heat.

isBeacon

isBeacon : Boolean (read-only)

true if the ship is a beacon (i.e., can show up on the Advanced Space Compass with a character indicating its identity), false otherwise.

See also: beaconCode

isBoulder

This property was added in Oolite test release 1.74.

isBoulder : Boolean (read/write)

true if the ship is a boulder (i.e., has the role "boulder in its roleset)

isCargo

This property was added in Oolite test release 1.74.

isCargo : Boolean (read-only)

true if the ship is cargo (i.e., has scan_class CLASS_CARGO and contains at least one unit)

isCloaked

isCloaked : Boolean (read-only)

true if the ship has a cloaking device which is currently active false otherwise. If the ship has a cloaking device and sufficient energy to use it, you can activate it by setting isCloaked to true.

isDerelict

This property was added in Oolite test release 1.74.

isDerelict : Boolean (read-only)

true if the ship is a derelict (i.e., the pilot has ejected from the ship, or the ship was created with the ship-key: "is_hulk")

isFrangible

isFrangible : Boolean (read-only)

true if the ship is frangible (i.e., its subentities can be destroyed separately from the main ship), false otherwise.

See also: subEntities

isJamming

isJamming : Boolean (read-only)

true if the ship has a military scanner jammer which is currently active false otherwise.

isMine

isMine : Boolean (read-only)

true if the ship is a mine, false otherwise.

isMissile

isMissile : Boolean (read-only)

true if the ship is a missile, false otherwise.

isPirate

isPirate : Boolean (read-only)

true if the ship is a pirate vessel, false otherwise. Currently equivalent to primaryRole == "pirate".

isPirateVictim

isPirateVictim : Boolean (read-only)

true if the ship’s primary role is listed in pirate-victim-roles.plist, false otherwise. This is the same test used by the pirate AI to select victims.

isPolice

isPolice : Boolean (read-only)

true if the ship is a police vessel, false otherwise. Currently equivalent to scanClass == "CLASS_POLICE".

isRock

This property was added in Oolite test release 1.74.

isRock : Boolean (read-only)

true if the ship is a rock (i.e., has scan_class: CLASS_ROCK)

isThargoid

isThargoid : Boolean (read-only)

true if the ship is a Thargoid vessel, false otherwise. Currently equivalent to scanClass == "CLASS_THARGOID".

isTrader

isTrader : Boolean (read-only)

true if the ship is a merchant vessel, false otherwise. Currently equivalent to primaryRole == "trader" || isPlayer. Note: isPirateVictim may be a better choice in many cases.

isWeapon

isWeapon : Boolean (read-only)

true if the ship is a weapon, false otherwise. Currently equivalent to isMissile || isMine , but new categories of weapon could be added in future.

lightsActive

This property was added in Oolite test release 1.74.

lightsActive : Boolean (read-write)

Setting this property to true turns on all the entity’s flashers, and setting it to false turns them off. Setting it sets the lightsActive property for all subentities, but subentities’ setting can also be manipulated separately. In addition to affecting flashers, the value can be used by shaders.

Note: lightsActive is always true when a ship is spawned, although individual flashers may be off because they have initially_on set to false in their shipdata.plist declarations.

maxSpeed

maxSpeed : Number (read-only)

The ship’s maximum speed under normal power. Note that speed may exceed this when witch fuel injectors or hyperspeed are in use.

See also: speed

maxThrust

This property was added in Oolite test release 1.74.

maxThrust : Number (read-only)

The ship’s maximum thrust. This value is the one defined as thrust in shipdata.plist.

missileCapacity

This property was added in Oolite test release 1.74.

missileCapacity : Number (read-only integer)

The maximum number of missiles the ship can carry.

missiles

This property was added in Oolite test release 1.74.

missiles : Array (read-only array of EquipmentInfo)

The ship’s loaded missiles.

name

name : String (read/write, read-only for player)

The name of the ship type (name key in shipdata.plist).

passengerCapacity

passengerCapacity : Number (read-only integer)

The ship’s maximum passenger capacity.

passengerCount

passengerCount : Number (read-only integer)

The ship’s current number of passengers.

passengers

This property was added in Oolite test release 1.74.

passengers : Array (read-only NSDictionary)

The ship’s passengers. (For now only available for the player). Each passengers list contains the entries: name: String, start: integer, destination: integer, startName: string, destinationName: string, eta: integer, etaDescription: string, fee: Integer, premium: Integer
For example, the information of the first contract can be obtained by:

player.ship.passengers[0].name
player.ship.passengers[0].start
player.ship.passengers[0].destination
player.ship.passengers[0].startName
player.ship.passengers[0].destinationName
player.ship.passengers[0].eta
player.ship.passengers[0].etaDescription
player.ship.passengers[0].fee  // The final fee, paid out on successful delivery.
player.ship.passengers[0].premium  // The advance fee, already paid on acceptance of the contract.

start and destination contain system ID numbers for planets in the current galaxy chart, eta is in clock seconds, fee is the amount that the player will receive when delivering this passenger, and premium shows the amount the player received when the passenger boarded the ship.

portWeapon

This property was added in Oolite test release 1.74.

portWeapon : EquipmentType (read-only)

The currently equipped forward weapon, or null. Currently, this is always null for non-player ships.

Bug: In Oolite 1.74.0, attempting to access a weapon slot with no weapon in it will halt the script without any error message.

See also: aftWeapon, forwardWeapon, starboardWeapon

potentialCollider

potentialCollider : Entity (read-only)

The entity the ship is currently trying not to crash into, if any.

primaryRole

primaryRole : String (read/write, read-only for player)

The main role of the ship; the role for which it was created. For instance, if a ship’s shipdata.plist entry specifies the roles “pirate trader(0.5) escort”, and a ship of that type is spawned to be a trader, its primaryRole is "trader", its roles is ["escort", "pirate", "trader"] and its roleProbabilities is { "escort":1, "pirate":1, "trader":0.5}.

See also: roles, roleProbabilities

reportAIMessages

reportAIMessages : Boolean (read/write)

Debugging facility: set to true to dump information about AI activity to the log.

roleProbabilities

roles : Object (read-only)

The probabilities for each role in roles.

Example:

this.pirateProb = ship.roleProbabilities["pirate"]

See also: primaryRole, roles

roles

roles : Array (read-only array of Strings)

The roles of the ship. This consists of the roles specified in the ship’s shipdata.plist entry, as well as the primaryRole if it is not among those.

See also: primaryRole, roleProbabilities, hasRole()

savedCoordinates

This property was added in Oolite test release 1.74.

savedCoordinates : Vector (read-write)

The savedCoordinates of the ship in system co-ordinates. The savedCoordinates vector is only used by AI scripting to store a coordinate that can be used by other AI commands like setDestinationToCoordinates. It are the same coordinates that are set by the AI command: "setCoordinates: X Y Z"

scannerRange

scannerRange : Number (read-only)

The range of the ship’s scanner.

script

script : Script (read-only)

The ship’s script.

scriptInfo

scriptInfo : Object (read-only)

The contents of the script_info key in the ship’s shipdata.plist entry, if any. This may be any property list object, but the reccomended approach is to use a dictionary whose keys have a unique prefix (such as you should be using for file names, ship names etc.). A property list dictionary is converted to a JavaScript object with properties corresponding to the dictionary’s keys. All other property list types used with Oolite have directly corresponding JavaScript types.


speed

speed : Number (read-only)

The ship’s current speed.

See also: maxSpeed

starboardWeapon

This property was added in Oolite test release 1.74.

starboardWeapon : EquipmentType (read-only)

The currently equipped forward weapon, or null. Currently, this is always null for non-player ships.

Bug: In Oolite 1.74.0, attempting to access a weapon slot with no weapon in it will halt the script without any error message.

See also: aftWeapon, forwardWeapon, portWeapon

subEntities

subEntities : Array (read-only array of Ships)

The ships subentities, or null if it has none. Special subentities such as flashers and exhaust plumes are not included.

See also: isFrangible

target

target : Ship (read-write)

The ship’s primary target, i.e. the entity it will attempt to shoot at. This value is automatically co-ordinated between a ship and its subentities.
Starting with 1.74 a current target can be deselected by setting "target = null". (Before defining null resulted in an error)

temperature

temperature : Number (read/write)

The ship’s temperature, normalized such that a temperature of 1.0 is the level at which a ship starts taking heat damage.

thrust

This property was added in Oolite test release 1.74.

thrust : Number (read/write (For player read-only))

The ship’s thrust, ranging from 0 to maxThrust. This value determines how fast the ship accelerates or decelerates. Speed-change in m/s².

thrustVector

This property was added in Oolite test release 1.74.

thrustVector : Vector3D (read-only)

The inertialess velocity generated by the engines.

See also: velocity

velocity

This property was added in Oolite test release 1.74.

velocity : Vector3D (read/write)

The ship’s velocity.

Note: A ship’s velocity consists of two components, inertial velocity and inertialess thrust. Generally, inertial velocity is zero (so velocity is equal to thrustVector), but inertial impulses may be applied if a ship collides or is caught in an explosion. If inertial velocity is non-zero, the ship’s engines will work to counteract it. Changing the ship’s velocity will always apply inertial velocity, so for ships with non-zero maxThrust the effect will be temporary.

See also: thrustVector

weaponRange

weaponRange : Number (read-only)

The maximum range of the ship’s primary weapon. For the player it is the range of the weapon that fired as last, even when the view direction changed.
Range values are: WEAPON_PLASMA_CANNON: 5000, WEAPON_PULSE_LASER: 12500, WEAPON_BEAM_LASER: 15000, WEAPON_MINING_LASER: 12500, WEAPON_THARGOID_LASER: 17500, WEAPON_MILITARY_LASER: 30000, WEAPON_NONE: 32000.
(Turrets are secondary weapons with a maximum range of 6000)

withinStationAegis

withinStationAegis : Boolean (read-only)

true if the ship is within the aegis of the system’s main station (i.e., no more than 51 200 game metres from the station, or twice scanner range).

Methods

abandonShip

function abandonShip() : Boolean

Returns true when the ship has an escapepod. It will launch all escapeposd on board leaving the ship behind as a empty hulk. (scanClass = CLASS_CARGO). This command does nothing when no escape-pod is present.
Pressence of an escapepod can be tested with: hasEquipment("EQ_ESCAPE_POD")

awardContract

function awardContract(quantity : Integer, commodity : String, start : Integer, destination : Integer, eta: Integer, fee : Integer) : Boolean

Adds a contract to the ship. (Currently only for the player). eta is in seconds and must be greater than the current time. start and destination are the ID numbers of the system.
It returns false when there is no room for the cargo or the eta is chosen wrong or there is not enough money to accept the contracts. e.g.

player.ship.awardContract(12, "Food", 34, 67, clock.seconds+7*24*3600, 5000)

If successful - and in galaxy chart 1 - the player will have 12 more food containers on board, the manifest will show that the cargo was picked up at Inus, to be delivered at Cemave, within exactly 7 days from now, and the player will be given 5000 credits if the cargo is delivered on time (early or late delivery will affect the amount paid). N.B. Normally to get a contract, the player will have to buy the cargo at the local market price. Using this method, no inital payment is made.

awardEquipment

function awardEquipment(equipmentType : equipmentInfoExpression)

Adds the given piece of equipment to the ship. (Prior to Oolite 1.74, this method was only available for the player’s ship.)

Example:

ship.awardEquipment("EQ_ECM");

See also: canAwardEquipment(), removeEquipment()

awardPassenger

function awardPassenger(name : String, start : Integer, destination : Integer, eta : Integer, fee : Integer) : Boolean

Adds a contract to the ship. (Currently only for the player). eta is in seconds and must be greater than the current time. start and destination are the ID numbers of the system.
It returns false when there is no room for the passenger or the eta is chosen wrong. e.g.

 player.ship.awardPassenger("cmdr Jameson", 34, 67, clock.seconds+3*24*3600, 1500)

If successful - and in galaxy chart 1 - the player will have cmdr Jameson as a passenger, his documents will show that he boarded the ship at Inus, to go to Cemave, within exactly 3 days from now, and the player will be given 1500 credits if he gets there on time (early or late arrival will affect the amount paid). N.B. Normally a passenger will pay the captain a small advance upon boarding. Using this method, no inital payment is made.

canAwardEquipment

function canAwardEquipment(equipmentType : equipmentInfoExpression) : Boolean

Tests whether it is possible to add a given equipment type. Returns true if awardEquipment() is expected to succeed, false otherwise.

See also: awardEquipment()

commsMessage

function commsMessage(message : String) : Ship

Make the ship type entity broadcast the specified message. Works on buoys and subentities as well as normal ships and stations.

deployEscorts

function deployEscorts()

Launch the ship’s escorts, if any.

dockEscorts

function dockEscorts()

Dock the ship’s deployed escorts, if any.

dumpCargo

function dumpCargo() : Ship

Ejects one item of cargo from the ship, and returns the cargo item. Returns null if the ship has no cargo, anything has been ejected in the last 0.5 seconds, or if sent to the player while docked.

See also: dumpCargo, ejectSpecificItem

ejectItem

This method was added in Oolite test release 1.71.

function ejectItem(role : String) : Ship

Spawns a ship of role role immediately behind the ship, with a slight backwards velocity. (Note: an equal and opposite reaction is applied to the parent ship, so doing this with large ships is rarely useful. player.ejectItem("station") may seem funny, but don’t come running to me if you have someone’s eye out.) Returns the generated ship, or null if no ship is generated. The scanClass of the ejected item will always be CLASS_CARGO.

See also: dumpCargo, ejectSpecificItem

ejectSpecificItem

function ejectSpecificItem(itemKey : String) : Ship

Spawns a ship with the shipdata.plist key itemKey immediately behind the ship, with a slight backwards velocity. The scanClass of the ejected item will always be CLASS_CARGO.

See also: dumpCargo, ejectItem

equipmentStatus

function equipmentStatus(equipmentType : equipmentInfoExpression) : String

Tests whether the specified type of equipment is installed, and whether it is functioning. Returns one of the following strings: "EQUIPMENT_OK", "EQUIPMENT_DAMAGED", "EQUIPMENT_UNAVAILABLE". (Prior to Oolite 1.74, this method was only available for the player’s ship.)

Note: by design, this method will throw an exception if called with an equipment type that does not exist. To test whether an equipment type exists, use EquipmentInfo.infoForKey(), which will return null for undefined equipment.

See also: setEquipmentStatus()

explode

function explode()

Causes the ship to explode. Works on all ships, including the main station and the player except when docked.

See also: remove()

exitAI

function exitAI()

Exit the current AI, restoring the previous one. Equivalent to the exitAI: AI method. May not be used on player. Will generate a warning if there are no suspended AI states.

See also: AI, setAI(), hasSuspendedAI

fireECM

function fireECM()

activates an ecm burst, identical as the AI command.

fireMissile

function fireMissile([missile]) : Ship

fireMissile() will try and fire the first available missile and will return the missile fired, or null if no missiles can be fired at this time. It can take the optional missile identifier parameter, to allow for a specific missile to be fired. Missiles cannot be fired if the NPC ship hasn't got a valid target, or if the previous missile was launched less than missile_load_time seconds before. If a missile type was specified, and not found on the ship, no missile will be fired.

hasEquipment

function hasEquipment(equipmentType : equipmentInfoExpression [, includeWeapons : Boolean]) : Boolean

Returns true if the given piece of equipment is present on/in the ship, false if it is not. If includeWeapons is false, primary weapons (lasers) and secondary weapons (missiles and mines) are excluded. If includeWeapons is not specified, true is assumed.

Example:

if (player.ship.hasEquipment("EQ_TRUMBLE")) log("Oh noes, I has a trumble!");

hasRole

function hasRole(role : String)

Returns true if the ship has role among its roles, false otherwise.

See also: roles

reactToAIMessage

function reactToAIMessage(AIState : String)

Immediately execute the ship’s AI in the specified state.

remove

function remove()

Immediately removes the ship from the universe. Works on all ships except the player, including the main station.

See also: explode()

removeEquipment

function removeEquipment(equipmentType : equipmentInfoExpression)

Removes the given piece of equipment from the ship. This function can also be used to remove missiles (and mines). If more than one missile of the same type is found on board, only one of them will be removed.

Example:

ship.removeEquipment("EQ_ECM");

selectNewMissile

function selectNewMissile() : equipmentKey

selectNewMissile() will automatically select a missile for a specific ship. It uses the missile_role shipdata.plist key to find out which missiles to select. As with the system populator, there's a small chance that missiles other than the missile_role specified in shipdata will be selected. e.g.

this.ship.awardEquipment(this.ship.selectNewMissile())

will automatically add the 'right type' of missile to a ship, i.e. one that its captain would normally choose.

setAI

function setAI(AIName : String)

Set the current AI, leaving the old one suspended. Equivalent to the setAITo: AI method. May not be used on player.

See also: AI, switchAI(), exitAI()

setCargo

function setCargo(commodity : String [, count : Number]) : Boolean

Attempts to create count weight units of the commodity commodity for a cargo barrel. (Can not be used to set cargo for ships) When more units are defined than 1 ton, the count is reduced to one ton. It returns false when the selected commodity is unknown. If count is not specified, one will be assumed.

setEquipmentStatus

function setEquipmentStatus(equipmentType : equipmentInfoExpression, statusKey : String)

Changes the status of the given piece of equipment from the ship. The two only valid status keys are "EQUIPMENT_OK", "EQUIPMENT_DAMAGED".

Note: by design, this method will throw an exception if called with an equipment type that does not exist. To test whether an equipment type exists, use EquipmentInfo.infoForKey(), which will return null for undefined equipment.

See also: equipmentStatus()

setScript

function setScript(scriptName : String)

Set, or completely replace, the javascript code associated to a ship entity.

spawn

function spawn(role : String [, count : Number]) : Array

Attempts to create count (maximum: 64) ships of role role close to the ship – specifically, inside the ship’s collision radius. (Since creating ships may fail, the number created may be less than count). The created ships are returned in an array. If count is not specified, one will be assumed.

spawn() is intended for cases when a ship splits into multiple parts or drops parts. In particular, it has the following special behaviour:

  • The spawned ships inherit most of the temperature of the parent.
  • If the parent is a missile and a child has the is_submunition property, the child will be considered a missile, its target will be set to that of the parent and the child’s owner will be set to the parent.
  • spawn() does not set up escorts for the new ships, or generate witchspace effects, or do any special AI handling.

spawnOne

function spawnOne(role : String) : Ship

Convenience method which calls spawn(role) and returns the first element of the resulting array, or null if spawn() fails.

switchAI

function switchAI(AIName : String)

Set the current AI, exiting the old one. Equivalent to the switchAITo: AI method. May not be used on player.

See also: AI, setAI(), exitAI()