Config/script.js |
"use strict";
this.name = "Kyota_relocator";
this.author = "Astrobe";
this.copyright = "Astrobe";
this.licence = "Public domain";
this.description = "Only one Kyota station per system at most, located near the sun.";
this.version = "1.0.1";
this.kyotaPopulator = function ()
{
//calculate distances
var planetToSun = system.sun.position.distanceTo(system.mainPlanet.position);
var wpToSun = system.sun.position.magnitude();
var distanceFromPlanetSurface = 0.9 * (planetToSun - system.sun.radius - system.mainPlanet.radius);
//randomize the position a bit
var x_coord = system.scrambledPseudoRandomNumber(600) * 25E3;
var y_coord = system.scrambledPseudoRandomNumber(484) * 25E3;
var z_coord = system.mainPlanet.radius + distanceFromPlanetSurface;
var exactPosition = Vector3D(x_coord, y_coord, z_coord).fromCoordinateSystem("psm");
if(system.scrambledPseudoRandomNumber(188) < 0.2 ) {
// add Disc stations
if(system.population > 40)
var solar_station = "wildShips_kiota4Disc";
else
var solar_station = "wildShips_kiota2Disc";
system.setPopulator("wild_ships_disc", {
callback: function(pos) {
system.addShips(solar_station, 1, pos, 0);
}.bind(this),
location: "COORDINATES",
coordinates: exactPosition,
deterministic: true
})
}
else if(system.scrambledPseudoRandomNumber(189) < 0.2 ) {
// add solar stations
if(system.population > 40)
var solar_station = "wildShips_kiota4Solar";
else
var solar_station = "wildShips_kiota2Solar";
system.setPopulator("wild_ships_solar", {
callback: function(pos) {
system.addShips(solar_station, 1, pos, 0);
}.bind(this),
location: "COORDINATES",
coordinates: exactPosition,
deterministic: true
})
}
else if(system.scrambledPseudoRandomNumber(127) < 0.2) {
//comms stations
// add comms stations
if(system.population > 40)
var comms_station = "wildShips_kiota4Comms";
else
var comms_station = "wildShips_kiota2Comms";
system.setPopulator("wild_ships_comms", {
callback: function(pos) {
system.addShips(comms_station, 1, pos, 0);
}.bind(this),
location: "COORDINATES",
coordinates: exactPosition,
deterministic: true
})
}
else if(system.scrambledPseudoRandomNumber(891) < 0.2 ) {
if (system.population < 30)
var hab_station = "wildShips_kiota2Ring";
else {
if (system.population > 45) {
if (system.scrambledPseudoRandomNumber(319) > 0.5)
var hab_station = "wildShips_kiota8Ring";
else
var hab_station = "wildShips_kiota8RingV";
}
else {
if(system.scrambledPseudoRandomNumber(319) > 0.5)
var hab_station = "wildShips_kiota4Ring";
else
var hab_station = "wildShips_kiota4RingV";
}
}
system.setPopulator("wild_ships_habitat", {
callback: function(pos) {
system.addShips(hab_station, 1, pos, 0);
}.bind(this),
location: "COORDINATES",
coordinates: exactPosition,
deterministic: true
})
}
else if(system.techLevel > 6 && system.scrambledPseudoRandomNumber(713) < 0.2 ) {
// add research stations to higher tech systems
if(system.techLevel > 11)
var research_station = "wildShips_kiota4Spur";
else
var research_station = "wildShips_kiota2Spur";
system.setPopulator("wild_ships_research", {
callback: function(pos) {
system.addShips(research_station, 1, pos, 0);
}.bind(this),
location: "COORDINATES",
coordinates: exactPosition,
deterministic: true
})
}
else if (system.scrambledPseudoRandomNumber(301) < 0.2 ) {
// add manufacturing stations to industrial systems
if (system.economy < 3) {
if(system.productivity > (30000 - (system.economy * 2500)))
var man_station = "wildShips_kiota4Sphere";
else
var man_station = "wildShips_kiota2Sphere";
}
else if (system.economy > 4) {
if(system.productivity > (30000 - ((system.economy - 5) * 2500)))
var man_station = "wildShips_kiota4Sphere";
else
var man_station = "wildShips_kiota2Sphere";
}
else return;
system.setPopulator("wild_ships_manufacturing", {
callback: function(pos) {
system.addShips(man_station, 1, pos, 0);
}.bind(this),
location: "COORDINATES",
coordinates: exactPosition,
deterministic: true
})
}
log(this.name, "relocated a station succesfully");
}
this.startUp = function()
{
// This is taken from http://wiki.alioth.net/index.php/Handling_OXP_Dependencies_with_JavaScript
delete this.startUp;
// function to handle the initialising of other scripts
function runOtherStartUp(s) {
if (worldScripts[s].startUp) worldScripts[s].startUp(); // Call the other startUp.
if (worldScripts[s].startUp) delete worldScripts[s].startUp; // Make sure the other startUp is deleted as it may not be written using
// this template.
};
runOtherStartUp("wildShips_populator.js");
// Test for existence of an OXP that isn't required but effects the way this OXP works.
this.Oxp_X_Script_Exists = !!worldScripts["wildShips_populator.js"];
worldScripts["wildShips_populator.js"].systemWillPopulate=this.kyotaPopulator; // This is what I want to do.
log(this.name, this.version +" loaded."); // This goes last so the load messages appear in a sensible order.
}
|