Difference between revisions of "Oolite JavaScript Reference: SystemInfo"

From Elite Wiki
m (Moving Oolite JS reference into a *correctly-named* subcategory of Oolite scripting.)
(Stylistic consistency.)
Line 7: Line 7:
 
== Properties ==
 
== Properties ==
 
=== <code>coordinates</code> ===
 
=== <code>coordinates</code> ===
'''coordinates''' : Vector (read-only)
+
'''coordinates''' : {{oojsclass|Vector3D}} (read-only)
The coordinates of the system in light years. e.g. for Lave: <code>(8, 34.6, 0)</code>. The z component is always zero.<br>
+
The coordinates of the system in light years. e.g. for Lave: <code>(8, 34.6, 0)</code>. The z component is always zero.
The upper left corner has the coordinate <code>(0, 0, 0)</code>. Going right increases the x value while going down on the map increases the y value.<br>
+
e.g.
+
The upper left corner has the coordinate <code>(0, 0, 0)</code>. Going right increases the x value while going down on the map increases the y value.
  +
  +
'''Example:'''
 
System.infoForSystem(galaxyNumber, 7).coordinates
 
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: <code>(8, 34.6, 0)</code>.
+
returns the coordinates of the system with an ID number of 7 in the current galaxy. In the first galaxy that would be the coordinates for Lave: <code>(8, 34.6, 0)</code>.
   
 
=== <code>galaxyID</code> ===
 
=== <code>galaxyID</code> ===
Line 24: Line 24:
   
 
== More properties ==
 
== More properties ==
Additional to these properties you have access to many other system properties, using the same keys as [[planetinfo.plist]]. e.g.
+
In addition to the properties above, you can access many other system properties, using the same keys as [[planetinfo.plist]].
  +
  +
'''Example:'''
 
<code>System.info.description = "This is a dull planet."</code>
 
<code>System.info.description = "This is a dull planet."</code>
sets the description of the current planet to "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.
+
Properties that are changed in <code>system.info</code> are stored in the save file and are permanently changed for that commander. When both the planetInfo.plist and the data from a changed <code>system.info</code> file are present, those of the system.info are used. You can undo any changes in <code>system.info</code> by setting the value to <code>null</code>.
<code>System.info.description = null</code>
 
will make that the system will use the original description.
 
   
 
== Methods ==
 
== Methods ==
 
=== <code>distanceToSystem</code> ===
 
=== <code>distanceToSystem</code> ===
function '''distanceToSystem'''(SystemInfo) : Number
+
function '''distanceToSystem'''(system : SystemInfo) : Number
Returns the distance in light year to the other SystemInfo.<br>
+
Returns the distance in light years to another <code>SystemInfo</code>.
e.g.
+
  +
'''Example:'''
 
System.infoForSystem(galaxyNumber, 7).distanceToSystem(System.infoForSystem(galaxyNumber, 8))
 
System.infoForSystem(galaxyNumber, 7).distanceToSystem(System.infoForSystem(galaxyNumber, 8))
returns: <code>92.8</code> as the distance between system 7 and 8 in light years.
 
  +
If galaxyNumber is 0, this returns 92.8.
   
 
=== <code>routeToSystem</code> ===
 
=== <code>routeToSystem</code> ===
 
function '''routeToSystem'''(system : SystemInfo [, "OPTIMIZED_BY_JUMPS" | "OPTIMIZED_BY_TIME"] ) : Object
 
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 <code>route</code> found, the <code>distance</code> and the <code>time</code> 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.<br>
+
Returns a dictionary containing the route information to another <code>SystemInfo</code>. The dictionary contains the array of system IDs that belong to the <code>route</code> found, the <code>distance</code> and the <code>time</code> corresponding to said route. Takes the optional parameter <code>"OPTIMIZED_BY_JUMPS"</code> (default) or <code>"OPTIMIZED_BY_TIME"</code> to calculate least number of jumps or fastest transit time routes respectively.
e.g.
+
  +
'''Example:'''
 
var myRoute = System.infoForSystem(galaxyNumber, 7).routeToSystem(System.infoForSystem(galaxyNumber, 8))
 
var myRoute = System.infoForSystem(galaxyNumber, 7).routeToSystem(System.infoForSystem(galaxyNumber, 8))
 
myRoute.route
 
myRoute.route
Line 52: Line 52:
   
 
=== <code>systemsInRange</code> ===
 
=== <code>systemsInRange</code> ===
function '''systemsInRange'''(range : Number) : Array
 
  +
{{Oolite-method-future|1.74.2}}
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.
 
  +
function '''systemsInRange'''([range : Number]) : Array
  +
Returns an array of <code>SystemInfo</code>s in range (default: 7) from the given system.
   
Usage:
 
  +
'''Note:''' will not produce correct results if used in interstellar space.
   
SystemInfo.systemsInRange(5);
 
  +
'''See also:''' <code>SystemInfo.[[#systemsInRange_2|systemsInRange()]]</code> (which always provides results relative to the current system).
 
 
'''N.B.''' will not produce correct results if used in interstellar space.
 
   
 
== Static methods ==
 
== Static methods ==
 
=== <code>filteredSystems</code> ===
 
=== <code>filteredSystems</code> ===
function '''filteredSystems'''(this : Object, predicate : Function ) : Array of SystemInfo
+
function '''filteredSystems'''(this : Object, predicate : Function) : Array of SystemInfo
A list of the SystemInfos for which <code>predicate</code> returns <code>true</code>.
+
A list of the <code>SystemInfo</code>s for which <code>predicate</code> returns <code>true</code>.
  +
 
'''Example:'''
 
'''Example:'''
  +
// This is the actual implementation of <code>[[#systemsInRange_2|systemsInRange()]]</code> in Oolite 1.74.
 
SystemInfo.systemsInRange = function(range)
 
SystemInfo.systemsInRange = function(range)
 
{
 
{
Line 81: Line 80:
 
}
 
}
   
  +
=== <code>systemsInRange</code> ===
  +
function '''systemsInRange'''([range : Number]) : Array
  +
Returns an array of <code>SystemInfo</code>s in range (default: 7) from the current system.
  +
  +
'''Note:''' will not produce correct results if used in interstellar space.
  +
  +
'''Example:'''
  +
SystemInfo.systemsInRange(5);
   
 
[[Category:Oolite JavaScript Reference]]
 
[[Category:Oolite JavaScript Reference]]

Revision as of 10:09, 28 June 2010

Prototype: Object

This class was added in Oolite test release 1.74.

SystemInfo objects provide information about a specific system.

Properties

coordinates

coordinates : Vector3D (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.

Example:

System.infoForSystem(galaxyNumber, 7).coordinates

returns the coordinates of the system with an ID number of 7 in the current galaxy. In the first galaxy that would be the coordinates for Lave: (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

In addition to the properties above, you can access many other system properties, using the same keys as planetinfo.plist.

Example:

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.

Methods

distanceToSystem

function distanceToSystem(system : SystemInfo) : Number

Returns the distance in light years to another SystemInfo.

Example:

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

If galaxyNumber is 0, this returns 92.8.

routeToSystem

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

Returns a dictionary containing the route information to another 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" (default) or "OPTIMIZED_BY_TIME" to calculate least number of jumps or fastest transit time routes respectively.

Example:

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 (default: 7) from the given system.

Note: will not produce correct results if used in interstellar space.

See also: SystemInfo.systemsInRange() (which always provides results relative to the current system).

Static methods

filteredSystems

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

A list of the SystemInfos for which predicate returns true.

Example:

// This is the actual implementation of systemsInRange() in Oolite 1.74.
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); 
   }); 
}

systemsInRange

function systemsInRange([range : Number]) : Array

Returns an array of SystemInfos in range (default: 7) from the current system.

Note: will not produce correct results if used in interstellar space.

Example:

SystemInfo.systemsInRange(5);