Oolite JavaScript Reference: SystemInfo

From Elite Wiki
Revision as of 15:07, 19 June 2010 by Ahruman (talk | contribs) (Moving Oolite JS reference into a *correctly-named* subcategory of Oolite scripting.)

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.
The upper left corner has the coordinate (0, 0, 0). Going right increases the x value while going down on the map increases the y value.
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-only nonnegative integer)

The ID number of the galaxy.

systemID

systemID : Number (read-only 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."

Properties that are changed in system.info are stored in the save file and are permanently changed for that commander. When both the planetInfo.plist and the data from a changed system.info file are present, those of the system.info are used. You can undo any changes in system.info by setting the value to null e.g.

System.info.description = null

will make that the system will use the original description.

Methods

distanceToSystem

function distanceToSystem(SystemInfo) : Number

Returns the distance in light year to the other SystemInfo.
e.g.

System.infoForSystem(galaxyNumber, 7).distanceToSystem(System.infoForSystem(galaxyNumber, 8))

returns: 92.8 as the distance between system 7 and 8 in light years.

routeToSystem

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

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.
e.g.

var myRoute = System.infoForSystem(galaxyNumber, 7).routeToSystem(System.infoForSystem(galaxyNumber, 8))
myRoute.route
myRoute.distance
myRoute.time

returns:

7,129,227,73,89,222,29,42,131,62,150,36,28,16,185,86,138,51,8  (the route)
96.40  (distance of added jumps)
530.40 (travelled time)

systemsInRange

function systemsInRange(range : Number) : Array

Returns an array of SystemInfos in range from the present planetary system. When no distance is defined, it returns all systems within 7 light years.

Usage:

SystemInfo.systemsInRange(5);


N.B. will not produce correct results if used in interstellar space.

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); 
   }); 
}