Path |
Scripts/orbit_market_saver.js |
this.name = "Orbiter Market Saver";
this.author = "Stranger";
this.copyright = "2019 Stranger";
this.licence = "CC-BY-NC-SA 4.0";
this.description = "Save market in orbital stations";
this.version = "0.3";
// Code tightly based on PlanetFall Market Saver (author SMax)
"use strict";
this._DEBUG = false;
this.orbiterList = [
"kos_kiota4Spur_jovian_orbiter", // Jovian research station KOS-RJ
"kos_kiota2Spur2Sphere_martian_orbiter", // Martian research station KOS-RM
"kos_kiota2Spur2Sphere_terran_orbiter", // Terran research station KOS-RT
"kos_kiota2Spur2Sphere_superterran_orbiter", // Superterran research station KOS-RS
"kos_kiota2Disc2Solar_lunar_orbiter", // Lunar orbital factory KOS-P
"kos_kiota2Spur2Solar_solar_orbiter" // Heliocentric mine processing complex KOS-M
];
this._MARKET = {};
this.shipExitedWitchspace = function()
{
this._logger("shipExitedWitchspace");
this._MARKET = {};
};
this.startUpComplete = function()
{
this._MARKET = {};
var t = missionVariables.OrbiterMarketSaver_DATA;
this._logger("startUpComplete: " + t);
if (t)
{
this._MARKET = JSON.parse(t);
}
};
this.playerWillSaveGame = function()
{
missionVariables.OrbiterMarketSaver_DATA = JSON.stringify(this._MARKET);
this._logger("playerWillSaveGame: " + missionVariables.OrbiterMarketSaver_DATA);
};
this.shipDockedWithStation = function(station)
{
this._logger("shipDockedWithStation: " + station.primaryRole);
var id = this.getID(station);
var stationFlag = 0;
for (var s = 0; s < this.orbiterList.length; s++)
{
if(station.primaryRole === this.orbiterList[s])
{
stationFlag = 1;
}
}
if (stationFlag == 1)
{
if (this._MARKET[id])
{
var market = this._MARKET[id];
for (var i = 0; i < market.length; i++)
{
var m = market[i];
station.setMarketPrice(m.k, m.p);
station.setMarketQuantity(m.k, m.q);
}
}
}
};
this.shipWillLaunchFromStation = function(station)
{
this._logger("shipWillLaunchFromStation: " + station.primaryRole);
var id = this.getID(station);
var stationFlag = 0;
for (var s = 0; s < this.orbiterList.length; s++)
{
if(station.primaryRole === this.orbiterList[s])
{
stationFlag = 1;
}
}
if (stationFlag == 1)
{
var market = station.market;
var res = [];
for (var k in market)
{
var i =
{
k: k,
q: market[k].quantity,
p: market[k].price
};
res.push(i);
}
this._MARKET[id] = res;
}
};
this._logger = function(msg)
{
if (this._DEBUG)
{
log(this.name, msg);
}
};
this.getID = function(station)
{
var id =
{
r: station.primaryRole
};
return JSON.stringify(id);
};
|
Scripts/orbit_station_jovian.js |
"use strict";
this.name = "OrbitStation_Jovian";
this.author = "Stranger";
this.copyright = "Creative Commons: attribution, non-commercial, sharealike.";
this.description = "Simulating station orbital movement";
this.version = "2.4";
this.shipSpawned = function()
{
var w = worldScripts.StationLibrary;
this.$jovianIndex = 0;
if (system.isInterstellarSpace) return;
var jovianTag = w.$stationLib_planetLock_Jovian();
this.$jovianIndex = jovianTag;
if (this.$jovianIndex == 0) return;
this.$radiusOrbit_Jovian = system.planets[this.$jovianIndex].radius * 1.5;
}
this.OrbitSatellite = function()
{
if (this.$jovianIndex == 0) return;
var v = this.ship.position.add(this.ship.heading.multiply(10000));
v = v.subtract(system.planets[this.$jovianIndex].position).direction().multiply(this.$radiusOrbit_Jovian);
this.ship.savedCoordinates = system.planets[this.$jovianIndex].position.add(v);
}
|
Scripts/orbit_station_lunar.js |
"use strict";
this.name = "OrbitStation_Moon";
this.author = "Stranger";
this.copyright = "Creative Commons: attribution, non-commercial, sharealike.";
this.description = "Simulating station orbital movement";
this.version = "2.4";
this.shipSpawned = function()
{
var w = worldScripts.StationLibrary;
this.$moonIndex = 0;
if (system.isInterstellarSpace) return;
this.$moonIndex = w.$stationLib_moonLock();
if (this.$moonIndex == 0) return;
this.$radiusOrbit_Moon = system.planets[this.$moonIndex].radius * 1.75;
}
this.OrbitSatellite = function()
{
if (this.$moonIndex == 0) return;
var v = this.ship.position.add(this.ship.heading.multiply(10000));
v = v.subtract(system.planets[this.$moonIndex].position).direction().multiply(this.$radiusOrbit_Moon);
this.ship.savedCoordinates = system.planets[this.$moonIndex].position.add(v);
}
|
Scripts/orbit_station_martian.js |
"use strict";
this.name = "OrbitStation_Martian";
this.author = "Stranger";
this.copyright = "Creative Commons: attribution, non-commercial, sharealike.";
this.description = "Simulating station orbital movement";
this.version = "2.4";
this.shipSpawned = function()
{
var w = worldScripts.StationLibrary;
this.$martianIndex = 0;
if (system.isInterstellarSpace) return;
var martianTag = w.$stationLib_planetLock_Martian();
this.$martianIndex = martianTag;
if (this.$martianIndex == 0) return;
this.$radiusOrbit_Martian = system.planets[this.$martianIndex].radius * 1.5;
}
this.OrbitSatellite = function()
{
if (this.$martianIndex == 0) return;
var v = this.ship.position.add(this.ship.heading.multiply(10000));
v = v.subtract(system.planets[this.$martianIndex].position).direction().multiply(this.$radiusOrbit_Martian);
this.ship.savedCoordinates = system.planets[this.$martianIndex].position.add(v);
}
|
Scripts/orbit_station_solar.js |
"use strict";
this.name = "OrbitStation_Solar";
this.author = "Stranger";
this.copyright = "Creative Commons: attribution, non-commercial, sharealike.";
this.description = "Spawn processing complex";
this.version = "2.4";
"use strict";
this.shipSpawned = function()
{
if (system.isInterstellarSpace) return;
this.$radiusOrbit_Solar = 10 * system.sun.radius;
}
this.OrbitSatellite = function()
{
var v = this.ship.position.add(this.ship.heading.multiply(10000));
v = v.subtract(system.sun.position).direction().multiply(this.$radiusOrbit_Solar);
this.ship.savedCoordinates = system.sun.position.add(v);
}
|
Scripts/orbit_station_superterran.js |
"use strict";
this.name = "OrbitStation_Superterran";
this.author = "Stranger";
this.copyright = "Creative Commons: attribution, non-commercial, sharealike.";
this.description = "Simulating station orbital movement";
this.version = "2.4";
this.shipSpawned = function()
{
var w = worldScripts.StationLibrary;
this.$superterranIndex = 0;
if (system.isInterstellarSpace) return;
this.$superterranIndex = w.$stationLib_planetLock_Superterran();
if (this.$superterranIndex == 0) return;
this.$radiusOrbit_Superterran = system.planets[this.$superterranIndex].radius * 1.5;
}
this.OrbitSatellite = function()
{
if (this.$superterranIndex == 0) return;
var v = this.ship.position.add(this.ship.heading.multiply(10000));
v = v.subtract(system.planets[this.$superterranIndex].position).direction().multiply(this.$radiusOrbit_Superterran);
this.ship.savedCoordinates = system.planets[this.$superterranIndex].position.add(v);
}
|
Scripts/orbit_station_terran.js |
"use strict";
this.name = "OrbitStation_Terran";
this.author = "Stranger";
this.copyright = "Creative Commons: attribution, non-commercial, sharealike.";
this.description = "Simulating station orbital movement";
this.version = "2.4";
this.shipSpawned = function()
{
var w = worldScripts.StationLibrary;
this.$terranIndex = 0;
if (system.isInterstellarSpace) return;
this.$terranIndex = w.$stationLib_planetLock_Terran();
if (this.$terranIndex == 0) return;
this.$radiusOrbit_Terran = system.planets[this.$terranIndex].radius * 1.5;
}
this.OrbitSatellite = function()
{
if (this.$terranIndex == 0) return;
var v = this.ship.position.add(this.ship.heading.multiply(10000));
v = v.subtract(system.planets[this.$terranIndex].position).direction().multiply(this.$radiusOrbit_Terran);
this.ship.savedCoordinates = system.planets[this.$terranIndex].position.add(v);
}
|
Scripts/spawn_station.js |
"use strict";
this.name = "Spawn_Stations";
this.author = "Stranger";
this.copyright = "This script is hereby placed in the public domain.";
this.version = "2.6";
this.description = "Spawn stations on planet orbit";
//This script uses simplified algorithm from Stations for Extra Planets OXP for station spawn
// Configuration
this.$stationRole_MoonFactory = "kos_kiota2Disc2Solar_lunar_orbiter";
this.$stationRole_Jovian = "kos_kiota4Spur_jovian_orbiter";
this.$stationRole_Martian = "kos_kiota2Spur2Sphere_martian_orbiter";
this.$stationRole_Terran = "kos_kiota2Spur2Sphere_terran_orbiter";
this.$stationRole_Superterran = "kos_kiota2Spur2Sphere_superterran_orbiter";
this.$stationRole_MineComplex = "kos_kiota2Spur2Solar_solar_orbiter";
this.shipWillExitWitchspace = function()
{
// set flags
this.$targetFlag = 0;
this.$count1 = 1;
this.$scriptDelay = new Timer(this, this.$seedStation, 0.5); //delay to set planet orbits!
}
this.$seedStation = function()
{
this.shipDied();
if (system.isInterstellarSpace) return;
if (this.$targetFlag > 0) return; // station already exist - prevents multiple seeding
this.$spaceActivity = system.productivity * (0.75 + 0.5 * system.scrambledPseudoRandomNumber(135));
var w = worldScripts.StationLibrary;
// seed processing complex
if(system.government > 4 && this.$spaceActivity >= 25000)
{
var orbitVector_Solar;
orbitVector_Solar = Vector3D.randomDirection(10 * system.sun.radius);
system.addShips(this.$stationRole_MineComplex, this.$count1, system.sun.position.add(orbitVector_Solar))[0];
}
// seed terran station
var terranTag = 0;
if(system.government > 4 && this.$spaceActivity >= 30000)
{
terranTag = w.$stationLib_planetLock_Terran();
}
if (terranTag != 0)
{
var orbitVector_Terran;
orbitVector_Terran = Vector3D.randomDirection(1.5 * system.planets[terranTag].radius);
system.addShips(this.$stationRole_Terran, this.$count1, system.planets[terranTag].position.add(orbitVector_Terran))[0];
}
// seed martian station
var martianTag = 0;
if(system.government > 4 && this.$spaceActivity >= 32500)
{
martianTag = w.$stationLib_planetLock_Martian();
}
if (martianTag != 0)
{
var orbitVector_Martian;
orbitVector_Martian = Vector3D.randomDirection(1.5 * system.planets[martianTag].radius);
system.addShips(this.$stationRole_Martian, this.$count1, system.planets[martianTag].position.add(orbitVector_Martian))[0];
}
// seed superterran station
var superterranTag = 0;
if(system.government > 4 && this.$spaceActivity >= 35000)
{
superterranTag = w.$stationLib_planetLock_Superterran();
}
if (superterranTag != 0)
{
var orbitVector_Superterran;
orbitVector_Superterran = Vector3D.randomDirection(1.5 * system.planets[superterranTag].radius);
system.addShips(this.$stationRole_Superterran, this.$count1, system.planets[superterranTag].position.add(orbitVector_Superterran))[0];
}
// seed jovian station
var jovianTag = 0;
if(system.government > 4 && this.$spaceActivity >= 37500)
{
jovianTag = w.$stationLib_planetLock_Jovian();
}
if (jovianTag != 0)
{
var orbitVector_Jovian;
orbitVector_Jovian = Vector3D.randomDirection(1.5 * system.planets[jovianTag].radius);
system.addShips(this.$stationRole_Jovian, this.$count1, system.planets[jovianTag].position.add(orbitVector_Jovian))[0];
}
// seed moon plant
var moonTag = 0;
if(system.government > 4 && this.$spaceActivity >= 40000)
{
moonTag = w.$stationLib_moonLock();
}
if (moonTag != 0)
{
var orbitVector_Moon;
orbitVector_Moon = Vector3D.randomDirection(1.8 * system.planets[moonTag].radius);
system.addShips(this.$stationRole_MoonFactory, this.$count1, system.planets[moonTag].position.add(orbitVector_Moon))[0];
}
this.$targetFlag = 1; //stations seeded - set flag to prevent multiple seeding
};
this.shipWillLaunchFromStation = function()
{
this.shipWillExitWitchspace();
delete this.shipWillLaunchFromStation;
}
this.shipWillDockWithStation = this.shipWillEnterWitchspace = function()
{
this.shipDied();
}
this.shipDied = function() // kill timer after stations seeding
{
if(this.$scriptDelay)
{
this.$scriptDelay.stop();
delete this.$scriptDelay;
}
} |
Scripts/spawn_station_library.js |
"use strict";
this.name = "StationLibrary";
this.author = "Stranger";
this.copyright = "This script is hereby placed in the public domain.";
this.version = "2.7";
this.description = "Function library to spawn stations";
this.$stationLib_moonLock = function()
{
var targetMoon = 0;
if (system.isInterstellarSpace) return;
var iplanetRadiusMin = 15000;
var iplanetRadiusMax = 17500;
for (let i=0; i<system.planets.length; i++)
{
if(system.planets[i].radius >= iplanetRadiusMin && system.planets[i].radius < iplanetRadiusMax)
{
targetMoon = i;
}
}
return targetMoon;
}
this.$stationLib_planetLock_Jovian = function()
{
var targetPlanet_Jovian = 0;
if (system.isInterstellarSpace) return;
var iplanetRadius = 100000;
for (let i=0; i<system.planets.length; i++)
{
if(system.planets[i].radius >= iplanetRadius)
{
targetPlanet_Jovian = i;
iplanetRadius = system.planets[i].radius;
}
}
return targetPlanet_Jovian;
}
this.$stationLib_planetLock_Martian = function()
{
var targetPlanet_Martian = 0;
if (system.isInterstellarSpace) return;
for (let i=0; i<system.planets.length; i++)
{
var iplanetRadiusMin = 30000;
var iplanetRadiusMax = 50000;
if(system.planets[i].radius >= iplanetRadiusMin && system.planets[i].radius < iplanetRadiusMax && system.planets[i] != system.mainPlanet)
{
targetPlanet_Martian = i;
}
}
return targetPlanet_Martian;
}
this.$stationLib_planetLock_Terran = function()
{
var targetPlanet_Terran = 0;
if (system.isInterstellarSpace) return;
for (let i=0; i<system.planets.length; i++)
{
var iplanetRadiusMin = 50000;
var iplanetRadiusMax = 75000;
if(system.planets[i].radius >= iplanetRadiusMin && system.planets[i].radius < iplanetRadiusMax && system.planets[i] != system.mainPlanet)
{
targetPlanet_Terran = i;
}
}
return targetPlanet_Terran;
}
this.$stationLib_planetLock_Superterran = function()
{
var targetPlanet_Superterran = 0;
if (system.isInterstellarSpace) return;
for (let i=0; i<system.planets.length; i++)
{
var iplanetRadiusMin = 75000;
var iplanetRadiusMax = 100000;
if(system.planets[i].radius >= iplanetRadiusMin && system.planets[i].radius < iplanetRadiusMax && system.planets[i] != system.mainPlanet)
{
targetPlanet_Superterran = i;
}
}
return targetPlanet_Superterran;
} |