Difference between revisions of "Oolite JavaScript Reference: SystemInfo"

From Elite Wiki
m (Added example to retrieve system coordinates)
(Methods)
Line 30: Line 30:
 
== Methods ==
 
== Methods ==
 
=== <code>distanceToSystem</code> ===
 
=== <code>distanceToSystem</code> ===
function '''distanceToSystem'''(SystenInfo) : Number
+
function '''distanceToSystem'''(SystemInfo) : Number
 
Returns the distance in light year to the other SystemInfo.
 
Returns the distance in light year to the other SystemInfo.
  +
  +
=== <code>routeToSystem</code> ===
  +
function '''routeToSystem'''(SystemInfo) [, "OPTIMIZED_BY_JUMPS" | "OPTIMIZED_BY_TIME"] : Dictionary
  +
Returns a dictionary containing the route information to the other SystemInfo. The dictionary contains the array of system IDs that belong to the route found, the distance and the time corresponding to said route. Takes the optional parameter "OPTIMIZED_BY_JUMPS" or "OPTIMIZED_BY_TIME" to calculate least number of jumps or fastest transit time routes respectively. If the second parameter is omitted, "OPTIMIZED_BY_JUMPS" is implied.
   
 
=== <code>systemsInRange</code> ===
 
=== <code>systemsInRange</code> ===
 
function '''systemsInRange'''(Number) : Array
 
function '''systemsInRange'''(Number) : Array
 
Returns an array of SystemInfos in range. When no distance is defined, 7 is assumed.
 
Returns an array of SystemInfos in range. When no distance is defined, 7 is assumed.
 
   
 
== Static methods ==
 
== Static methods ==

Revision as of 23:59, 11 February 2010

Prototype: Object

This class was added in Oolite test release 1.74.

SystemInfo objects provide information about a specific system.

Properties

coordinates

coordinates : Vector (read-only)

The coordinates of the system in light years. e.g. for Lave: (8, 34.6, 0). The z component is always zero.
e.g.

System.infoForSystem(galaxyNumber, 7).coordinates

returns the coordinates of the system with an ID numberr of 7 in the current galaxy. In the first galaxy that would be the Lave coordinates: (8, 34.6, 0).

galaxyID

galaxyID : Number (read/write nonnegative integer)

The ID number of the galaxy.

systemID

systemID : Number (read/write nonnegative integer)

The ID number of the system.


More properties

Additional to these properties you have access to many other system properties, using the same keys as planetinfo.plist. e.g.

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

sets the description of the current planet to "This is a dull planet."


Methods

distanceToSystem

function distanceToSystem(SystemInfo) : Number

Returns the distance in light year to the other SystemInfo.

routeToSystem

function routeToSystem(SystemInfo) [, "OPTIMIZED_BY_JUMPS" | "OPTIMIZED_BY_TIME"] : Dictionary

Returns a dictionary containing the route information to the other SystemInfo. The dictionary contains the array of system IDs that belong to the route found, the distance and the time corresponding to said route. Takes the optional parameter "OPTIMIZED_BY_JUMPS" or "OPTIMIZED_BY_TIME" to calculate least number of jumps or fastest transit time routes respectively. If the second parameter is omitted, "OPTIMIZED_BY_JUMPS" is implied.

systemsInRange

function systemsInRange(Number) : Array

Returns an array of SystemInfos in range. When no distance is defined, 7 is assumed.

Static methods

filteredSystems

function filteredSystems(this : Object, predicate : Function ) : Array of SystemInfo

A list of the SystemInfos for which predicate returns true. Example:

SystemInfo.systemsInRange = function(range) 
{ 
   if (range === undefined) 
   { 
       range = 7; 
   } 
   
   var thisSystem = system.info; 
   return SystemInfo.filteredSystems(this, function(other) 
   { 
       return (other.systemID !== thisSystem.systemID) && (thisSystem.distanceToSystem(other) <= range); 
   }); 
}