Oolite JavaScript Reference: System
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).
Contents
- 1 Properties
- 1.1 allShips
- 1.2 description
- 1.3 economy
- 1.4 economyDescription
- 1.5 goingNova
- 1.6 goneNova
- 1.7 government
- 1.8 governmentDescription
- 1.9 ID
- 1.10 info
- 1.11 inhabitantsDescription
- 1.12 isInterstellarSpace
- 1.13 mainPlanet
- 1.14 mainStation
- 1.15 planets
- 1.16 population
- 1.17 productivity
- 1.18 pseudoRandom100
- 1.19 pseudoRandom256
- 1.20 sun
- 1.21 techLevel
- 2 Methods
- 2.1 addMoon
- 2.2 addPlanet
- 2.3 addGroup
- 2.4 addShips
- 2.5 addGroupToRoute
- 2.6 addShipsToRoute
- 2.7 countShipsWithRole
- 2.8 countShipsWithPrimaryRole
- 2.9 entitiesWithScanClass
- 2.10 filteredEntities
- 2.11 infoForSystem
- 2.12 legacy_addShips etc.
- 2.13 sendAllShipsAway
- 2.14 setSunNova
- 2.15 shipsWithPrimaryRole
- 2.16 shipsWithRole
- 2.17 systemIDForName
- 2.18 systemNameForID
Properties
allShips
This property was added in Oolite test release 1.70.
allShips : Array (read-only)
A list of the ships in the system. If there are none, an empty list.
See Also: shipsWithPrimaryRole()
, shipsWithRole()
, entitiesWithScanClass()
, filteredEntities()
.
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
)
goingNova
This property is deprecated and will be removed in Oolite test release 1.74.
goingNova : Boolean (read-only)
Use system.sun.isGoingNova
instead.
goneNova
This property is deprecated and will be removed in Oolite test release 1.74.
goneNova : Boolean (read-only)
Use system.sun.hasGoneNova
instead.
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. Equivalent to planet_number
in plist scripts.
info
This property was added in Oolite test release 1.72. (write-only until 1.73)
info : SystemInfo (read/write)
Allows access to 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."
inhabitantsDescription
inhabitantsDescription : String (read/write)
The description of the inhabitants of the current system, such as “Slimy Blue Frogs”.
isInterstellarSpace
This property was added in Oolite test release 1.70.
isInterstellarSpace : Boolean (read-only)
true
if the current system is in interstellar space, false
otherwise.
mainPlanet
This property was added in Oolite test release 1.70.
mainPlanet : Planet (read-only)
The system’s main planet, or null
if there is none.
mainStation
This property was added in Oolite test release 1.70.
mainStation : Station (read-only)
The system’s main station, or null
if there is none.
planets
This property was added in Oolite test release 1.70.
planets : Array (read-only)
A list of the planets in the system. If there are none, an empty list.
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)
A random number between 0 and 99 that is always the same for a given system.
pseudoRandom256
pseudoRandom256 : Number (integer, read)
A random number between 0 and 255 that is always the same for a given system.
sun
This property was added in Oolite test release 1.70.
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
addMoon
function addMoon(planetInfoKey : String)
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)
Adds a planet to the system, using the specified entry in planetinfo.plist. (See also: addMoon()
)
addGroup
This method was added in Oolite test release 1.74.
function addGroup(role : String, count : Number[, position: Vector] [, radius: Number]) : ShipGroup
Adds ships to the system, puts them in a single group and returns the added ships as a ShipGroup. This method does the same as addShips but now the ships are put in a group and the shipGroup is returned. (See also: addShips()
)
addShips
This method was added in Oolite test release 1.74.
function addShips(role : String, count : Number[, position: Vector] [, 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 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.
addGroupToRoute
This method was added in Oolite test release 1.74.
function addGroupToRoute(role : String, count : Number[, fraction: Number] [, route: String]) : ShipGroup
Adds ships to the system, puts them in a single group and returns the added ships as a ShipGroup. This method does the same as addShipsToRoute but now the ships are put in a group and the shipGroup is returned. (See also: 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 ps
". (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")
adds 2 ships near each-other on the route from sun to witchpoint and puts the added ship in the array: "ships".
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. Specially useful for counting a group of ships linked together with a common but not used role.
countShipsWithPrimaryRole
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)
entitiesWithScanClass
This method was added in Oolite test release 1.70.
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
This method was added in Oolite test release 1.70.
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()
.
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." (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.
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 : vectorExpression) function legacy_addShipsWithinRadius(role : String, count : Number, coordScheme : String, where : vectorExpression, 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. A new, more flexible addShips()
function will supersede all of them.
Important: legacy_spawn
, previously listed here, never worked as intended and has been replaced with Ship.spawn()
. Starting with 1.74 new ship adding commands are added that return the added ships. (See: addShips()
) However, all legacy_addShipsxxx methods will also stay available for scripting.
sendAllShipsAway
function sendAllShipsAway()
Makes all ships hyperspace out of the system.
setSunNova
function setSunNova(secondsUntilNova : Number)
Sets the system’s sun to go nova after the specified time interval. Time is specified in game real time. Deprecated since 1.72 in favour of: system.sun.goNova()
shipsWithPrimaryRole
This method was added in Oolite test release 1.70.
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
This method was added in Oolite test release 1.70.
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()
.
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)