Difference between revisions of "Oolite JavaScript Reference: System"

From Elite Wiki
m (Moving Oolite JS reference into a *correctly-named* subcategory of Oolite scripting.)
(Partially updated for 1.74.)
Line 1: Line 1:
 
<small>'''Prototype:''' <code>Object</code></small><br />
 
<small>'''Prototype:''' <code>Object</code></small><br />
<small>'''Subtypes:''' none
+
<small>'''Subtypes:''' none</small>
  
 
The '''<code>System</code>''' class represents the current system. There is always one <code>System</code> object, available through the global property <code>system</code>.
 
The '''<code>System</code>''' class represents the current system. There is always one <code>System</code> object, available through the global property <code>system</code>.
Line 8: Line 8:
 
== Properties ==
 
== Properties ==
 
=== <code>allShips</code> ===
 
=== <code>allShips</code> ===
{{Oolite-prop-added|1.70}}
 
 
  '''allShips''' : Array (read-only)
 
  '''allShips''' : Array (read-only)
A list of the ships in the system. If there are none, an empty list.
+
A list of the ships in the system.
  
'''See Also:''' <code>[[#shipsWithPrimaryRole|shipsWithPrimaryRole]]()</code>, <code>[[#shipsWithRole|shipsWithRole]]()</code>, <code>[[#entitiesWithScanClass|entitiesWithScanClass]]()</code>, <code>[[#filteredEntities|filteredEntities]]()</code>.
+
'''See Also:''' <code>[[#entitiesWithScanClass|entitiesWithScanClass]]()</code>, <code>[[#filteredEntities|filteredEntities]]()</code>, <code>[[#shipsWithPrimaryRole|shipsWithPrimaryRole]]()</code>, <code>[[#shipsWithRole|shipsWithRole]]()</code>
  
 
=== <code>description</code> ===
 
=== <code>description</code> ===
Line 20: Line 19:
 
=== <code>economy</code> ===
 
=== <code>economy</code> ===
 
  '''economy''' : Number (integer, read/write)
 
  '''economy''' : Number (integer, read/write)
The type of economy in the current system, ranging from 0 (Rich Industrial) to 7 (Poor Agricultural). (See also: <code>[[#economyDescription|economyDescription]]</code>)
+
The type of economy in the current system, ranging from 0 (Rich Industrial) to 7 (Poor Agricultural).
 +
 
 +
'''See Also:''' <code>[[#economyDescription|economyDescription]]</code>
  
 
=== <code>economyDescription</code> ===
 
=== <code>economyDescription</code> ===
 
  '''economyDescription''' : String (read-only)
 
  '''economyDescription''' : String (read-only)
A description of the economy type, for example, “Mostly Industrial”. (See also: <code>[[#economy|economy]]</code>)
+
A description of the economy type, for example, “Mostly Industrial”.
 
 
=== <code>goingNova</code> ===
 
{{Oolite-script-item-deprecated|property|1.74}}
 
'''goingNova''' : Boolean (read-only)
 
Use <code>[[Oolite JavaScript Reference: Sun#isGoingNova|system.sun.isGoingNova]]</code> instead.
 
  
=== <code>goneNova</code> ===
+
'''See Also:''' <code>[[#economy|economy]]</code>
{{Oolite-script-item-deprecated|property|1.74}}
 
'''goneNova''' : Boolean (read-only)
 
Use <code>[[Oolite JavaScript Reference: Sun#hasGoneNova|system.sun.hasGoneNova]]</code> instead.
 
  
 
=== <code>government</code> ===
 
=== <code>government</code> ===
 
  '''government''' : Number (read/write, integer)
 
  '''government''' : Number (read/write, integer)
The type of government in the current system, ranging from 0 (Anarchy) to 7 (Corporate State). (See also: <code>[[#governmentDescription|governmentDescription]]</code>)
+
The type of government in the current system, ranging from 0 (Anarchy) to 7 (Corporate State).
 +
 
 +
'''See Also:''' <code>[[#governmentDescription|governmentDescription]]</code>
  
 
=== <code>governmentDescription</code> ===
 
=== <code>governmentDescription</code> ===
 
  '''governmentDescription''' : String (read-only)
 
  '''governmentDescription''' : String (read-only)
A description of the government type, for example, “Democracy”. (See also: <code>[[#government|government]]</code>)
+
A description of the government type, for example, “Democracy”.
 +
 
 +
'''See Also:''' <code>[[#government|government]]</code>
  
 
=== <code>ID</code> ===
 
=== <code>ID</code> ===
 
  ID : Number (integer, read-only)
 
  ID : Number (integer, read-only)
A number identifying the system. 0 to 255, or -1 for interstellar space. Equivalent to <code>planet_number</code> in plist scripts.
+
A number identifying the system. 0 to 255, or -1 for interstellar space.
  
 
=== <code>info</code> ===
 
=== <code>info</code> ===
{{Oolite-prop-added|1.72}} (write-only until 1.73)
 
 
  '''info''' : [[Oolite JavaScript Reference: SystemInfo|SystemInfo]] (read/write)
 
  '''info''' : [[Oolite JavaScript Reference: SystemInfo|SystemInfo]] (read/write)
Allows access to system properties, using the same keys as [[planetinfo.plist]]. e.g.
+
Allows access to system properties, using the same keys as [[planetinfo.plist]].
  <code>System.info.description = "This is a dull planet."</code>
+
 
sets the description of the current planet  to "This is a dull planet."
+
'''Example:'''
 +
  System.info.description = "This is a dull planet.";
  
 
=== <code>inhabitantsDescription</code> ===
 
=== <code>inhabitantsDescription</code> ===
Line 60: Line 57:
  
 
=== <code>isInterstellarSpace</code> ===
 
=== <code>isInterstellarSpace</code> ===
{{Oolite-prop-added|1.70}}
 
 
  '''isInterstellarSpace''' : Boolean (read-only)
 
  '''isInterstellarSpace''' : Boolean (read-only)
 
<code>true</code> if the current system is in interstellar space, <code>false</code> otherwise.
 
<code>true</code> if the current system is in interstellar space, <code>false</code> otherwise.
  
 
=== <code>mainPlanet</code> ===
 
=== <code>mainPlanet</code> ===
{{Oolite-prop-added|1.70}}
+
  '''mainPlanet''' : {{oojsclass|Planet}} (read-only)
  '''mainPlanet''' : [[Oolite JavaScript Reference: Planet|Planet]] (read-only)
 
 
The system’s main planet, or <code>null</code> if there is none.
 
The system’s main planet, or <code>null</code> if there is none.
  
 
=== <code>mainStation</code> ===
 
=== <code>mainStation</code> ===
{{Oolite-prop-added|1.70}}
 
 
  '''mainStation''' : [[Oolite JavaScript Reference: Station|Station]] (read-only)
 
  '''mainStation''' : [[Oolite JavaScript Reference: Station|Station]] (read-only)
 
The system’s main station, or <code>null</code> if there is none.
 
The system’s main station, or <code>null</code> if there is none.
 +
 +
=== <code>name</code> ===
 +
<small>This property was first documented in connection with Oolite '''1.74''', although it existed earlier.</small>
 +
'''name''' : String (read/write)
 +
The name of the system.
  
 
=== <code>planets</code> ===
 
=== <code>planets</code> ===
{{Oolite-prop-added|1.70}}
 
 
  '''planets''' : Array (read-only)
 
  '''planets''' : Array (read-only)
A list of the planets in the system. If there are none, an empty list.
+
A list of the planets in the system.
  
 
=== <code>population</code> ===
 
=== <code>population</code> ===
Line 88: Line 86:
  
 
=== <code>pseudoRandom100</code> ===
 
=== <code>pseudoRandom100</code> ===
  '''pseudoRandom100''' : Number (integer, read)
+
  '''pseudoRandom100''' : Number (integer, read-only)
A random number between 0 and 99 that is always the same for a given system.
+
A random number between 0 and 99 that is always the same for a given system. '''Important:''' this method has the undesirable side effect of resetting the system random number generator. It should only be used for backwards-compatibility. For new development, use <code>[[#pseudoRandomNumber|pseudoRandomNumber]]</code>.
  
 
=== <code>pseudoRandom256</code> ===
 
=== <code>pseudoRandom256</code> ===
  '''pseudoRandom256''' : Number (integer, read)
+
  '''pseudoRandom256''' : Number (integer, read-only)
A random number between 0 and 255 that is always the same for a given system.
+
A random number between 0 and 255 that is always the same for a given system. '''Important:''' this method has the undesirable side effect of resetting the system random number generator. It should only be used for backwards-compatibility. For new development, use <code>[[#pseudoRandomNumber|pseudoRandomNumber]]</code>.
 +
 
 +
=== <code>pseudoRandomNumber</code> ===
 +
'''pseudoRandomNumber''' : Number (read-only)
 +
A random number between 0 and 1 that is always the same for a given system.
  
 
=== <code>sun</code> ===
 
=== <code>sun</code> ===
{{Oolite-prop-added|1.70}}
 
 
  '''sun''' : [[Oolite JavaScript Reference: Sun|Sun]] (read-only)
 
  '''sun''' : [[Oolite JavaScript Reference: Sun|Sun]] (read-only)
 
The system’s sun, or <code>null</code> if there is none.
 
The system’s sun, or <code>null</code> if there is none.
Line 105: Line 106:
  
 
== Methods ==
 
== Methods ==
 +
=== <code>addGroup</code> ===
 +
{{Oolite-method-added|1.74}}
 +
function '''addGroup'''(role : String, count : Number [, position: {{oojsvecexpr}}] [, radius: Number]) : {{oojsclass|ShipGroup}}
 +
Like <code>[[#addShips|addShips()]]</code>, but puts the ships in a group and returns the group.
 +
 +
'''See Also:''' <code>[[#addGroupToRoute|addGroupToRoute()]]</code>, <code>[[#addShips|addShips()]]</code>
 +
 +
=== <code>addGroupToRoute</code> ===
 +
{{Oolite-method-added|1.74}}
 +
function '''addGroupToRoute'''(role : String, count : Number [, fraction: Number] [, route: String]) : {{oojsclass|ShipGroup}}
 +
Like <code>[[#addShipsToRoute|addShipsToRoute()]]</code>, but puts the ships in a group and returns the group.
 +
 +
'''See Also:''' <code>[[#addGroup|addGroup()]]</code>, <code>[[#addShipsToRoute|addShipsToRoute()]]</code>
 +
 
=== <code>addMoon</code> ===
 
=== <code>addMoon</code> ===
  function '''addMoon'''(planetInfoKey : String)
+
  function '''addMoon'''(planetInfoKey : String) : {{oojsclass|Planet}}
 
Adds a moon to the system, using the specified entry in ''[[planetinfo.plist]]''. A moon is the same as a planet, except that it has no atmosphere.
 
Adds a moon to the system, using the specified entry in ''[[planetinfo.plist]]''. A moon is the same as a planet, except that it has no atmosphere.
  
As of Oolite 1.74, this method will return a <code>[[Oolite JavaScript Reference:Planet|Planet]]</code> object.
+
'''See Also:''' <code>[[#addPlanet|addPlanet()]]</code>
 
 
'''See also:''' <code>[[#addPlanet|addPlanet()]]</code>
 
  
 
=== <code>addPlanet</code> ===
 
=== <code>addPlanet</code> ===
  function '''addPlanet'''(planetInfoKey : String)
+
  function '''addPlanet'''(planetInfoKey : String) : {{oojsclass|Planet}}
 
Adds a planet to the system, using the specified entry in ''[[planetinfo.plist]]''.
 
Adds a planet to the system, using the specified entry in ''[[planetinfo.plist]]''.
  
As of Oolite 1.74, this method will return a <code>[[Oolite JavaScript Reference:Planet|Planet]]</code> object.
+
'''See Also:''' <code>[[#addMoon|addMoon()]]</code>
  
'''See also:''' <code>[[#addMoon|addMoon()]]</code>
+
=== <code>addShips</code> ===
 
 
=== <code>addGroup</code> ===
 
 
{{Oolite-method-added|1.74}}
 
{{Oolite-method-added|1.74}}
  function '''addGroup'''(role : String, count : Number[, position: Vector] [, radius: Number]) : [[Oolite JavaScript Reference: ShipGroup|ShipGroup]]
+
  function '''addShips'''(role : String, count : Number [, position: {{oojsvecexpr}}] [, radius: Number]) : Array
Adds ships to the system, puts them in a single group and returns the added ships as a [[Oolite JavaScript Reference: ShipGroup|ShipGroup]]. This method does the same as addShips but now the ships are put in a group and the shipGroup is returned.
+
Adds ships to the system and returns the added ships in an array. Position is in absolute coordinates. When no position is given, the witchpoint is assumed. When no radius is given, the maximum scanner range is used. Ships added in range of the witchpoint automatically create a witchpoint entry cloud.
  
'''See also:''' <code>[[#addShips|addShips()]]</code>
+
'''See Also:''' <code>[[#addGroup|addGroup()]]</code>, <code>[[#addShipsToRoute|addShipsToRoute()]]</code>
  
=== <code>addShips</code> ===
+
=== <code>addShipsToRoute</code> ===
 
{{Oolite-method-added|1.74}}
 
{{Oolite-method-added|1.74}}
  function '''addShips'''(role : String, count : Number[, position: Vector] [, radius: Number]) : Array
+
  function '''addShipsToRoute'''(role : String, count : Number [, fraction: Number] [, route: String]) : Array
Adds ships to the system and returns the added ships in an array. Position is in absolute coordinates.  When no position is given, the witchpoint is assumed. When no radius is given is selects one itself with a maximum radius of max_scanner_range. Ships added in range of the witchpoint, automatically create a witchpoint entry cloud.
+
Adds ships to the system on certain common routes and returns the added ships as an array. The routes are the two character codes <code>wp</code>, <code>pw</code>, <code>ws</code>, <code>sw</code>, <code>sp</code>, and <code>ps</code>, where <code>w</code> stands for the witchpoint, <code>p</code> for the planet and <code>s</code> for the sun.
  
=== <code>addGroupToRoute</code> ===
+
  When no route is defined, the route witchpoint → main station is assumed.
{{Oolite-method-added|1.74}}
 
  function '''addGroupToRoute'''(role : String, count : Number[, fraction: Number]  [, route: String]) : [[Oolite JavaScript Reference: ShipGroup|ShipGroup]]
 
Adds ships to the system, puts them in a single group and returns the added ships as a [[Oolite JavaScript Reference: ShipGroup|ShipGroup]]. This method does the same as addShipsToRoute but now the ships are put in a group and the shipGroup is returned.
 
  
'''See also:''' <code>[[#addShipsToRoute|addShipsToRoute()]]</code>
+
  The position is a fraction of the route and must be between 0 and 1. Unlike the legacy commands the fraction takes planetary radii in account, so it does not start counting in the centre of sun/planet but from its surface. When no fraction is defined, a random fraction is chosen. Ships are added within scanner range of this position. Ships added in range of the witchpoint automatically create a witchpoint entry cloud.
  
=== <code>addShipsToRoute</code> ===
+
'''Example''':
{{Oolite-method-added|1.74}}
 
function '''addShipsToRoute'''(role : String, count : Number[, fraction: Number]  [, route: String]) : Array
 
Adds ships to the system on certain common routes and returns the added ships as an array. The routes are the two character codes: "<code>wp pw ws sw sp ps</code>".  (witchpoint->planet, planet->witchpoint, witchpoint->sun etc.) When no route is defined, the route witchpoint->mainStation is assumed. The position is a fraction of the route and must be between 0 and 1. Unlike the legacy commands the fraction takes planetary radii in account. So it does not start counting in the centre of sun/planet but from its surface. When no fraction is defined, a random fraction is chosen, but the same fraction when multiple ships are added.  Ships are added within scanner range of this position. Ships added in range of the witchpoint, automatically create a witchpoint entry cloud. e.g.
 
 
  var ships = system.addShipsToRoute("myShips", 2, 0.7, "sw")
 
  var ships = system.addShipsToRoute("myShips", 2, 0.7, "sw")
adds 2 ships near each-other on the route from sun to witchpoint and puts the added ship in the array: "ships".
+
adds 2 ships near each-other on the route from sun to witchpoint and puts the added ship in the array <code>ships</code>.
  
=== <code>countShipsWithRole</code> ===
+
'''See Also:''' <code>[[#addGroup|addGroup()]]</code>, <code>[[#addShips|addShips()]]</code>
function '''countShipsWithRole'''(role : String) : Number (integer)
 
Returns the number of ships with the specified role in the system; Counts not only the primary role the ship is added with but all roles a ship can have. Specially useful for counting a group of ships linked together with a common but not used role.
 
  
 
=== <code>countShipsWithPrimaryRole</code> ===
 
=== <code>countShipsWithPrimaryRole</code> ===
 
  function '''countShipsWithPrimaryRole'''(role : String) : Number (integer)
 
  function '''countShipsWithPrimaryRole'''(role : String) : Number (integer)
Returns the number of ships with the specified primary role in the system; equivalent to checkForShips: in plist scripts. (added with Oolite 1.72)
+
Returns the number of ships with the specified primary role in the system.
 +
 
 +
=== <code>countShipsWithRole</code> ===
 +
function '''countShipsWithRole'''(role : String) : Number (integer)
 +
Returns the number of ships with the specified role in the system. Counts not only the primary role the ship is added with but all roles a ship can have.
  
 
=== <code>entitiesWithScanClass</code> ===
 
=== <code>entitiesWithScanClass</code> ===
{{Oolite-method-added|1.70}}
+
  function '''entitiesWithScanClass'''(scanClass : String [, relativeTo : {{oojsclass|Entity}} [, range : Number]]) : Array
  function '''entitiesWithScanClass'''(scanClass : String [, relativeTo : [[Oolite JavaScript Reference: Entity|Entity]] [, range : Number]]) : Array
 
 
A list of the entities in the system whose scan class is <code>scanClass</code>. If <code>relativeTo</code> is specified, the list will be sorted in order of proximity to <code>relativeTo</code> (i.e., the first element of the list is closest). If <code>range</code> is also specified, entities further than <code>range</code> metres from <code>relativeTo</code> will be excluded. If no matching entities are found, an empty array is returned.
 
A list of the entities in the system whose scan class is <code>scanClass</code>. If <code>relativeTo</code> is specified, the list will be sorted in order of proximity to <code>relativeTo</code> (i.e., the first element of the list is closest). If <code>range</code> is also specified, entities further than <code>range</code> metres from <code>relativeTo</code> will be excluded. If no matching entities are found, an empty array is returned.
  
Line 163: Line 169:
  
 
=== <code>filteredEntities</code> ===
 
=== <code>filteredEntities</code> ===
{{Oolite-method-added|1.70}}
+
  function '''filteredEntities'''(this : Object, predicate : Function [, relativeTo : {{oojsclass|Entity}} [, range : Number]]) : Array
  function '''filteredEntities'''(this : Object, predicate : Function [, relativeTo : [[Oolite JavaScript Reference: Entity|Entity]] [, range : Number]]) : Array
 
 
A list of the entities for which <code>predicate</code> returns <code>true</code>. If <code>relativeTo</code> is specified, the list will be sorted in order of proximity to <code>relativeTo</code> (i.e., the first element of the list is closest). If <code>range</code> is also specified, entities further than <code>range</code> metres from <code>relativeTo</code> will be excluded. If no matching entities are found, an empty array is returned.
 
A list of the entities for which <code>predicate</code> returns <code>true</code>. If <code>relativeTo</code> is specified, the list will be sorted in order of proximity to <code>relativeTo</code> (i.e., the first element of the list is closest). If <code>range</code> is also specified, entities further than <code>range</code> metres from <code>relativeTo</code> will be excluded. If no matching entities are found, an empty array is returned.
  
 
'''Example:'''
 
'''Example:'''
  this.findIdlePoliceInScannerRange = function()  
+
  this.findIdlePoliceInScannerRange = function()
  {  
+
  {
     function isIdlePolice(entity)  
+
     function isIdlePolice(entity)
     {  
+
     {
         return entity.isShip && entity.isPolice && !entity.target  
+
         return entity.isShip && entity.isPolice && !entity.target
     }  
+
     }
   
+
 
     return system.filteredEntities(this, isIdlePolice, player, 25600)  
+
     return system.filteredEntities(this, isIdlePolice, player, 25600);
 
  }
 
  }
  
 
'''See Also:''' <code>[[#shipsWithPrimaryRole|shipsWithPrimaryRole]]()</code>, <code>[[#shipsWithRole|shipsWithRole]]()</code>, <code>[[#entitiesWithScanClass|entitiesWithScanClass]]()</code>.
 
'''See Also:''' <code>[[#shipsWithPrimaryRole|shipsWithPrimaryRole]]()</code>, <code>[[#shipsWithRole|shipsWithRole]]()</code>, <code>[[#entitiesWithScanClass|entitiesWithScanClass]]()</code>.
 
=== <code>infoForSystem</code> ===
 
function '''infoForSystem'''(galaxyNumber: Integer, systemID : Integer) (write-only)
 
Overwrites existing info of the given system. As properties it uses the [[planetinfo.plist]] keys. e.g.
 
System.infoForSystem(0, 55).description = "This is a dull planet."
 
sets the description of planet nr 55 in galaxy 0 to his is a dull planet." (added with Oolite 1.72.1)
 
 
Starting from Oolite 1.73, all system Info for the present galaxy is also readable. Even though any galaxy system info property is fully settable, due to engine limitations other galaxies' data is not accessible. In other words
 
System.infoForSystem(0, 55).description
 
would return "This is a dull planet." if called from galaxy 0, null from the other galaxies.
 
  
 
=== <code>legacy_addShips etc.</code> ===
 
=== <code>legacy_addShips etc.</code> ===
 
  function '''legacy_addShips'''(role : String, count : Number)
 
  function '''legacy_addShips'''(role : String, count : Number)
 
  function '''legacy_addSystemShips'''(role : String, count : Number, position : Number)
 
  function '''legacy_addSystemShips'''(role : String, count : Number, position : Number)
  function '''legacy_addShipsAt'''(role : String, count : Number, coordscheme : String, where : [[Oolite JavaScript Reference: Vector#Vector Expressions|vectorExpression]])
+
  function '''legacy_addShipsAt'''(role : String, count : Number, coordscheme : String, where : {{oojsvecexpr}})
  function '''legacy_addShipsAtPrecisely'''(role : String, count : Number, coordscheme : String, where : [[Oolite JavaScript Reference: Vector#Vector Expressions|vectorExpression]])
+
  function '''legacy_addShipsAtPrecisely'''(role : String, count : Number, coordscheme : String, where : {{oojsclass|Planet}})
  function '''legacy_addShipsWithinRadius'''(role : String, count : Number, coordScheme : String, where : [[Oolite JavaScript Reference: Vector#Vector Expressions|vectorExpression]], radius : Number)
+
  function '''legacy_addShipsWithinRadius'''(role : String, count : Number, coordScheme : String, where : {{oojsclass|Planet}}, radius : Number)
 
  function '''legacy_spawnShip'''(shipDataKey : String)
 
  function '''legacy_spawnShip'''(shipDataKey : String)
Various ways of causing ships to appear. Each of these corresponds to a legacy scripting method. For more info about the coordscheme, look at [[oolite coordinate systems]]. A new, more flexible <code>addShips()</code> function will supersede all of them.
+
Various ways of causing ships to appear. Each of these corresponds to a legacy scripting method. For more info about the <code>coordScheme</code>, look at [[Oolite coordinate systems]]. These methods are kept for backwards-compatibility; for new development, <code>[[#addShips|addShips()]] is preferred.
  
'''Important:''' <code>legacy_spawn</code>, previously listed here, never worked as intended and has been replaced with <code>Ship.[[Oolite JavaScript Reference: Ship#spawn|spawn]]()</code>. Starting with 1.74 new ship adding commands are added that return the added ships. (See: <code>[[#addShips|addShips()]]</code>) However, all legacy_addShipsxxx methods will also stay available for scripting.
+
'''Important:''' <code>legacy_spawn</code>, previously listed here, never worked as intended and has been replaced with <code>Ship.[[Oolite JavaScript Reference: Ship#spawn|spawn]]()</code>.
  
 
=== <code>sendAllShipsAway</code> ===
 
=== <code>sendAllShipsAway</code> ===
 
  function '''sendAllShipsAway'''()
 
  function '''sendAllShipsAway'''()
 
Makes all ships hyperspace out of the system.
 
Makes all ships hyperspace out of the system.
 
=== <code>setSunNova</code> ===
 
function '''setSunNova'''(secondsUntilNova : Number)
 
Sets the system’s sun to go nova after the specified time interval. Time is specified in [[Time scales in Oolite#Game real time|game real time]].
 
Deprecated since 1.72 in favour of: system.sun.goNova()
 
  
 
=== <code>shipsWithPrimaryRole</code> ===
 
=== <code>shipsWithPrimaryRole</code> ===
{{Oolite-method-added|1.70}}
+
  function '''shipsWithPrimaryRole'''(role : String [, relativeTo : {{oojsclass|Entity}} [, range : Number]]) : Array
  function '''shipsWithPrimaryRole'''(role : String [, relativeTo : [[Oolite JavaScript Reference: Entity|Entity]] [, range : Number]]) : Array
 
 
A list of the entities in the system whose [[Oolite JavaScript Reference: Ship#primaryRole|primary role]] is <code>role</code>. If <code>relativeTo</code> is specified, the list will be sorted in order of proximity to <code>relativeTo</code> (i.e., the first element of the list is closest). If <code>range</code> is also specified, entities further than <code>range</code> metres from <code>relativeTo</code> will be excluded. If no matching entities are found, an empty array is returned.
 
A list of the entities in the system whose [[Oolite JavaScript Reference: Ship#primaryRole|primary role]] is <code>role</code>. If <code>relativeTo</code> is specified, the list will be sorted in order of proximity to <code>relativeTo</code> (i.e., the first element of the list is closest). If <code>range</code> is also specified, entities further than <code>range</code> metres from <code>relativeTo</code> will be excluded. If no matching entities are found, an empty array is returned.
  
Line 218: Line 207:
  
 
=== <code>shipsWithRole</code> ===
 
=== <code>shipsWithRole</code> ===
{{Oolite-method-added|1.70}}
+
  function '''shipsWithRole'''(role : String [, relativeTo : {{oojsclass|Entity}} [, range : Number]]) : Array
  function '''shipsWithRole'''(role : String [, relativeTo : [[Oolite JavaScript Reference: Entity|Entity]] [, range : Number]]) : Array
 
 
A list of the entities in the system whose [[Oolite JavaScript Reference: Ship#roles|role set]] contains <code>role</code>. If <code>relativeTo</code> is specified, the list will be sorted in order of proximity to <code>relativeTo</code> (i.e., the first element of the list is closest). If <code>range</code> is also specified, entities further than <code>range</code> metres from <code>relativeTo</code> will be excluded. If no matching entities are found, an empty array is returned.
 
A list of the entities in the system whose [[Oolite JavaScript Reference: Ship#roles|role set]] contains <code>role</code>. If <code>relativeTo</code> is specified, the list will be sorted in order of proximity to <code>relativeTo</code> (i.e., the first element of the list is closest). If <code>range</code> is also specified, entities further than <code>range</code> metres from <code>relativeTo</code> will be excluded. If no matching entities are found, an empty array is returned.
  
 
'''See Also:''' <code>[[#shipsWithRole|shipsWithRole]]()</code>, <code>[[#entitiesWithScanClass|entitiesWithScanClass]]()</code>, <code>[[#filteredEntities|filteredEntities]]()</code>.
 
'''See Also:''' <code>[[#shipsWithRole|shipsWithRole]]()</code>, <code>[[#entitiesWithScanClass|entitiesWithScanClass]]()</code>, <code>[[#filteredEntities|filteredEntities]]()</code>.
 +
 +
 +
== Static Methods ==
 +
=== <code>infoForSystem</code> ===
 +
function '''infoForSystem'''(galaxyNumber: Integer, systemID : Integer) (write-only)
 +
Overwrites existing info of the given system. As properties it uses the [[planetinfo.plist]] keys. e.g.
 +
System.infoForSystem(0, 55).description = "This is a dull planet."
 +
sets the description of planet nr 55 in galaxy 0 to his is a dull planet."
 +
 +
Starting from Oolite 1.73, all system Info for the present galaxy is also readable. Even though any galaxy system info property is fully settable, due to engine limitations other galaxies' data is not accessible. In other words
 +
System.infoForSystem(0, 55).description
 +
would return "This is a dull planet." if called from galaxy 0, null from the other galaxies.
  
 
=== <code>systemIDForName</code> ===
 
=== <code>systemIDForName</code> ===
  function '''systemIDForName'''(systemName : String) : Integer
+
  function '''systemIDForName'''(systemName : String) : Integer
 
Returns the ID number of a system in the current galaxy based on the system name)
 
Returns the ID number of a system in the current galaxy based on the system name)
  
 
=== <code>systemNameForID</code> ===
 
=== <code>systemNameForID</code> ===
  function '''systemNameForID'''(systemID : Integer) : String
+
  function '''systemNameForID'''(systemID : Integer) : String
 
Returns the name of a system in the current galaxy based on the given ID number)
 
Returns the name of a system in the current galaxy based on the given ID number)
 +
  
 
[[Category:Oolite JavaScript Reference]]
 
[[Category:Oolite JavaScript Reference]]

Revision as of 18:06, 20 June 2010

Prototype: Object
Subtypes: none

The System class represents the current system. There is always one System object, available through the global property system.

Attempts to change system properties are ignored in interstellar space (i.e., the place you end up in after a witchspace malfunction).

Properties

allShips

allShips : Array (read-only)

A list of the ships in the system.

See Also: entitiesWithScanClass(), filteredEntities(), shipsWithPrimaryRole(), shipsWithRole()

description

description : String (read/write)

The description of the current system, as seen on the planet info screen.

economy

economy : Number (integer, read/write)

The type of economy in the current system, ranging from 0 (Rich Industrial) to 7 (Poor Agricultural).

See Also: economyDescription

economyDescription

economyDescription : String (read-only)

A description of the economy type, for example, “Mostly Industrial”.

See Also: economy

government

government : Number (read/write, integer)

The type of government in the current system, ranging from 0 (Anarchy) to 7 (Corporate State).

See Also: governmentDescription

governmentDescription

governmentDescription : String (read-only)

A description of the government type, for example, “Democracy”.

See Also: government

ID

ID : Number (integer, read-only)

A number identifying the system. 0 to 255, or -1 for interstellar space.

info

info : SystemInfo (read/write)

Allows access to system properties, using the same keys as planetinfo.plist.

Example:

System.info.description = "This is a dull planet.";

inhabitantsDescription

inhabitantsDescription : String (read/write)

The description of the inhabitants of the current system, such as “Slimy Blue Frogs”.

isInterstellarSpace

isInterstellarSpace : Boolean (read-only)

true if the current system is in interstellar space, false otherwise.

mainPlanet

mainPlanet : Planet (read-only)

The system’s main planet, or null if there is none.

mainStation

mainStation : Station (read-only)

The system’s main station, or null if there is none.

name

This property was first documented in connection with Oolite 1.74, although it existed earlier.

name : String (read/write)

The name of the system.

planets

planets : Array (read-only)

A list of the planets in the system.

population

population : Number (integer, read/write)

The population of the current system.

productivity

productivity : Number (integer, read/write)

The productivity of the current system.

pseudoRandom100

pseudoRandom100 : Number (integer, read-only)

A random number between 0 and 99 that is always the same for a given system. Important: this method has the undesirable side effect of resetting the system random number generator. It should only be used for backwards-compatibility. For new development, use pseudoRandomNumber.

pseudoRandom256

pseudoRandom256 : Number (integer, read-only)

A random number between 0 and 255 that is always the same for a given system. Important: this method has the undesirable side effect of resetting the system random number generator. It should only be used for backwards-compatibility. For new development, use pseudoRandomNumber.

pseudoRandomNumber

pseudoRandomNumber : Number (read-only)

A random number between 0 and 1 that is always the same for a given system.

sun

sun : Sun (read-only)

The system’s sun, or null if there is none.

techLevel

techLevel : Number (integer, read/write)

The technology level of the current system, ranging from 0 to 15.

Methods

addGroup

This method was added in Oolite test release 1.74.

function addGroup(role : String, count : Number [, position: vectorExpression] [, radius: Number]) : ShipGroup

Like addShips(), but puts the ships in a group and returns the group.

See Also: addGroupToRoute(), addShips()

addGroupToRoute

This method was added in Oolite test release 1.74.

function addGroupToRoute(role : String, count : Number [, fraction: Number] [, route: String]) : ShipGroup

Like addShipsToRoute(), but puts the ships in a group and returns the group.

See Also: addGroup(), addShipsToRoute()

addMoon

function addMoon(planetInfoKey : String) : Planet

Adds a moon to the system, using the specified entry in planetinfo.plist. A moon is the same as a planet, except that it has no atmosphere.

See Also: addPlanet()

addPlanet

function addPlanet(planetInfoKey : String) : Planet

Adds a planet to the system, using the specified entry in planetinfo.plist.

See Also: addMoon()

addShips

This method was added in Oolite test release 1.74.

function addShips(role : String, count : Number [, position: vectorExpression] [, radius: Number]) : Array

Adds ships to the system and returns the added ships in an array. Position is in absolute coordinates. When no position is given, the witchpoint is assumed. When no radius is given, the maximum scanner range is used. Ships added in range of the witchpoint automatically create a witchpoint entry cloud.

See Also: addGroup(), addShipsToRoute()

addShipsToRoute

This method was added in Oolite test release 1.74.

function addShipsToRoute(role : String, count : Number [, fraction: Number] [, route: String]) : Array

Adds ships to the system on certain common routes and returns the added ships as an array. The routes are the two character codes wp, pw, ws, sw, sp, and ps, where w stands for the witchpoint, p for the planet and s for the sun.

When no route is defined, the route witchpoint → main station is assumed.
The position is a fraction of the route and must be between 0 and 1. Unlike the legacy commands the fraction takes planetary radii in account, so it does not start counting in the centre of sun/planet but from its surface. When no fraction is defined, a random fraction is chosen. Ships are added within scanner range of this position. Ships added in range of the witchpoint automatically create a witchpoint entry cloud.

Example:

var ships = system.addShipsToRoute("myShips", 2, 0.7, "sw")

adds 2 ships near each-other on the route from sun to witchpoint and puts the added ship in the array ships.

See Also: addGroup(), addShips()

countShipsWithPrimaryRole

function countShipsWithPrimaryRole(role : String) : Number (integer)

Returns the number of ships with the specified primary role in the system.

countShipsWithRole

function countShipsWithRole(role : String) : Number (integer)

Returns the number of ships with the specified role in the system. Counts not only the primary role the ship is added with but all roles a ship can have.

entitiesWithScanClass

function entitiesWithScanClass(scanClass : String [, relativeTo : Entity [, range : Number]]) : Array

A list of the entities in the system whose scan class is scanClass. If relativeTo is specified, the list will be sorted in order of proximity to relativeTo (i.e., the first element of the list is closest). If range is also specified, entities further than range metres from relativeTo will be excluded. If no matching entities are found, an empty array is returned.

See Also: shipsWithPrimaryRole(), shipsWithRole(), filteredEntities().

filteredEntities

function filteredEntities(this : Object, predicate : Function [, relativeTo : Entity [, range : Number]]) : Array

A list of the entities for which predicate returns true. If relativeTo is specified, the list will be sorted in order of proximity to relativeTo (i.e., the first element of the list is closest). If range is also specified, entities further than range metres from relativeTo will be excluded. If no matching entities are found, an empty array is returned.

Example:

this.findIdlePoliceInScannerRange = function()
{
    function isIdlePolice(entity)
    {
        return entity.isShip && entity.isPolice && !entity.target
    }
  
    return system.filteredEntities(this, isIdlePolice, player, 25600);
}

See Also: shipsWithPrimaryRole(), shipsWithRole(), entitiesWithScanClass().

legacy_addShips etc.

function legacy_addShips(role : String, count : Number)
function legacy_addSystemShips(role : String, count : Number, position : Number)
function legacy_addShipsAt(role : String, count : Number, coordscheme : String, where : vectorExpression)
function legacy_addShipsAtPrecisely(role : String, count : Number, coordscheme : String, where : Planet)
function legacy_addShipsWithinRadius(role : String, count : Number, coordScheme : String, where : Planet, radius : Number)
function legacy_spawnShip(shipDataKey : String)

Various ways of causing ships to appear. Each of these corresponds to a legacy scripting method. For more info about the coordScheme, look at Oolite coordinate systems. These methods are kept for backwards-compatibility; for new development, addShips() is preferred.

Important: legacy_spawn, previously listed here, never worked as intended and has been replaced with Ship.spawn().

sendAllShipsAway

function sendAllShipsAway()

Makes all ships hyperspace out of the system.

shipsWithPrimaryRole

function shipsWithPrimaryRole(role : String [, relativeTo : Entity [, range : Number]]) : Array

A list of the entities in the system whose primary role is role. If relativeTo is specified, the list will be sorted in order of proximity to relativeTo (i.e., the first element of the list is closest). If range is also specified, entities further than range metres from relativeTo will be excluded. If no matching entities are found, an empty array is returned.

See Also: shipsWithRole(), entitiesWithScanClass(), filteredEntities().

shipsWithRole

function shipsWithRole(role : String [, relativeTo : Entity [, range : Number]]) : Array

A list of the entities in the system whose role set contains role. If relativeTo is specified, the list will be sorted in order of proximity to relativeTo (i.e., the first element of the list is closest). If range is also specified, entities further than range metres from relativeTo will be excluded. If no matching entities are found, an empty array is returned.

See Also: shipsWithRole(), entitiesWithScanClass(), filteredEntities().


Static Methods

infoForSystem

function infoForSystem(galaxyNumber: Integer, systemID : Integer) (write-only)

Overwrites existing info of the given system. As properties it uses the planetinfo.plist keys. e.g.

System.infoForSystem(0, 55).description = "This is a dull planet."

sets the description of planet nr 55 in galaxy 0 to his is a dull planet."

Starting from Oolite 1.73, all system Info for the present galaxy is also readable. Even though any galaxy system info property is fully settable, due to engine limitations other galaxies' data is not accessible. In other words

System.infoForSystem(0, 55).description

would return "This is a dull planet." if called from galaxy 0, null from the other galaxies.

systemIDForName

function systemIDForName(systemName : String) : Integer

Returns the ID number of a system in the current galaxy based on the system name)

systemNameForID

function systemNameForID(systemID : Integer) : String

Returns the name of a system in the current galaxy based on the given ID number)