Scripts/astro_library.js |
"use strict";
this.name = "AstroLibrary";
this.author = "Stranger";
this.copyright = "Creative Commons: attribution, non-commercial, sharealike with clauses - see readme.txt";
this.description = "Library of oostronomical functions";
this.version = "4.3";
// SunEngine functions
this.$astroLib_sunSpectrum = function(sunRadius) // sun spectrum class as function of sun radius
{
if (system.isInterstellarSpace) return;
var spectrum;
var spectrumSelector;
if (sunRadius <= 600000)
{
spectrumSelector = Math.floor(sunRadius / 30000);
}
else
{
if(sunRadius > 1000000)
{
spectrumSelector = Math.floor((sunRadius + 500000) / 15000);
}
else
{
spectrumSelector = Math.floor(sunRadius / 10000);
}
}
switch (spectrumSelector)
{
// M class red dwarf
case 12: spectrum = "M3.5V"; break;
case 13: spectrum = "M3V"; break;
case 14: spectrum = "M2.5V"; break;
case 15: spectrum = "M2V"; break;
case 16: spectrum = "M1.5V"; break;
case 17: spectrum = "M1V"; break;
case 18: spectrum = "M0.5V"; break;
case 19: spectrum = "M0V"; break;
// K class orange dwarf
case 60: spectrum = "K9.5V"; break;
case 61: spectrum = "K9V"; break;
case 62: spectrum = "K8.5V"; break;
case 63: spectrum = "K8V"; break;
case 64: spectrum = "K7.5V"; break;
case 65: spectrum = "K7V"; break;
case 66: spectrum = "K6.5V"; break;
case 67: spectrum = "K6V"; break;
case 68: spectrum = "K5.5V"; break;
case 69: spectrum = "K5V"; break;
case 70: spectrum = "K4.5V"; break;
case 71: spectrum = "K4V"; break;
case 72: spectrum = "K3.5V"; break;
case 73: spectrum = "K3V"; break;
case 74: spectrum = "K2.5V"; break;
case 75: spectrum = "K2V"; break;
case 76: spectrum = "K1.5V"; break;
case 77: spectrum = "K1V"; break;
case 78: spectrum = "K0.5V"; break;
case 79: spectrum = "K0V"; break;
// G class yellow dwarf
case 80: spectrum = "G9.5V"; break;
case 81: spectrum = "G9V"; break;
case 82: spectrum = "G8.5V"; break;
case 83: spectrum = "G8V"; break;
case 84: spectrum = "G7.5V"; break;
case 85: spectrum = "G7V"; break;
case 86: spectrum = "G6.5V"; break;
case 87: spectrum = "G6V"; break;
case 88: spectrum = "G5.5V"; break;
case 89: spectrum = "G5V"; break;
case 90: spectrum = "G4.5V"; break;
case 91: spectrum = "G4V"; break;
case 92: spectrum = "G3.5V"; break;
case 93: spectrum = "G3V"; break;
case 94: spectrum = "G2.5V"; break;
case 95: spectrum = "G2V"; break;
case 96: spectrum = "G1.5V"; break;
case 97: spectrum = "G1V"; break;
case 98: spectrum = "G0.5V"; break;
case 99: spectrum = "G0V"; break;
// F class white hot star
case 100: spectrum = "F9.5V"; break;
case 101: spectrum = "F9V"; break;
case 102: spectrum = "F8.5V"; break;
case 103: spectrum = "F8V"; break;
case 104: spectrum = "F7.5V"; break;
case 105: spectrum = "F7V"; break;
case 106: spectrum = "F6.5V"; break;
case 107: spectrum = "F6V"; break;
default: spectrum = null;
};
return spectrum;
}
this.$astroLib_sunTemperature = function(sunRadius) // sun temperature as function of sun radius
{
if (system.isInterstellarSpace) return;
var solarTemperature;
if (sunRadius <= 600000)
{
solarTemperature = 4000 - (600000 - sunRadius) / 300;
}
else
{
if (sunRadius > 1000000)
{
solarTemperature = 6000 + (sunRadius - 1000000) / 300;
}
else
{
solarTemperature = 6000 - (1000000 - sunRadius) / 200;
}
}
var solarTemperatureTweaked = solarTemperature - 25 + 50 * system.scrambledPseudoRandomNumber(119);
return solarTemperatureTweaked;
}
this.$astroLib_sunLuminosity = function(sunTemperature, sunRadius) // sun luminosity as function of sun radius
{
if (system.isInterstellarSpace) return;
var sunLuminosity = Math.pow((sunTemperature / 6000),4) * Math.pow((sunRadius / 1000000),2); // Stefan-Boltzmann law
return sunLuminosity;
}
this.$astroLib_sunMass = function(sunRadius) // sun mass as function of sun radius
{
if (system.isInterstellarSpace) return;
var solarMass;
if (sunRadius <= 300000)
{
solarMass = 0.175;
}
else
{
solarMass = 1.0 - (960000 - sunRadius) / 1000000 * 1.25;
}
var sunMassTweaked = solarMass * (0.975 + 0.05 * system.scrambledPseudoRandomNumber(120));
return sunMassTweaked;
}
this.$astroLib_solPeriod = function(sunMass) // main planet period as function of sun mass
{
if (system.isInterstellarSpace) return;
var standardOU = 63750 * 675; // Sol-Terra system twin AU
var standardYear = 365.25; // standard year for Sol-Terra system twin
var mainOrbitVector = new Vector3D(system.sun.position.subtract(system.mainPlanet.position));
var ouScale = mainOrbitVector.magnitude(); // OU in custom system
var mainPeriod = standardYear * Math.pow((ouScale / standardOU),1.5) / Math.pow(sunMass,0.5); // 3rd Kepler low
return mainPeriod;
}
this.$astroLib_orbitRadius = function() // planet orbits in OU
{
if (system.isInterstellarSpace) return;
var mainOrbitVector = new Vector3D(system.sun.position.subtract(system.mainPlanet.position));
var ouScale = mainOrbitVector.magnitude();
var planetsOrbitsOU = new Array();
var planetOrbitVector;
for (let i=0; i<system.planets.length; i++)
{
planetOrbitVector = new Vector3D(system.sun.position.subtract(system.planets[i].position));
planetsOrbitsOU[i] = planetOrbitVector.magnitude() / ouScale;
}
return planetsOrbitsOU;
}
this.$astroLib_mainPlanetTemperature = function(sunLuminosity,sunDistance,mainPlanetRadius) // main planet temperature - simplified function of radius
{
if (system.isInterstellarSpace) return;
var mainInsolation = sunLuminosity * Math.pow((50000000 / sunDistance),2);
var equilibriumTemperature = 255 * Math.pow(mainInsolation,0.25);
var mainTemperature;
mainTemperature = equilibriumTemperature + (mainPlanetRadius - 4800) * 3 / 400 + 20;
return mainTemperature;
}
this.$astroLib_SolarWind = function(sunDistance) // solar wind. Used to collect fuel
{
if (system.isInterstellarSpace) return;
var solarWindDensity = (system.sun.radius * system.sun.radius) / (sunDistance * sunDistance) * system.info.corona_flare;
if (player.alertCondition != 1)
{
solarWindDensity = 0;
}
var solarWindFlux;
if(player.ship.speed > player.ship.maxSpeed)
{
solarWindFlux = solarWindDensity * player.ship.maxSpeed;
}
else
{
solarWindFlux = solarWindDensity * player.ship.speed; //rate of fuel collection, LY/min
}
return solarWindFlux;
}
// PlanetEngine functions
this.$astroLib_insolation = function(sunLuminosity, sunDistance) // insolation level
{
if (system.isInterstellarSpace) return;
var insolation = sunLuminosity * Math.pow((50000000 / sunDistance),2);
return insolation;
}
this.$astroLib_equilibriumTemperature = function(insolation) // equilibrium temperature without greenhouse effect. Albedo same as Earth
{
if (system.isInterstellarSpace) return;
var equilibriumTemperature = 255 * Math.pow(insolation,0.25);
return equilibriumTemperature;
}
this.$astroLib_planetDensity = function(planetRadius, equilibriumTemperature) // planet density as function of planet radius and equilibrium temperature
{
if (system.isInterstellarSpace) return;
var planetDensity = 0.925 + Math.sqrt(planetRadius / 302.5) * Math.sqrt(equilibriumTemperature / 255);
return planetDensity;
}
this.$astroLib_escapeVelocity = function(planetRadius, planetDensity) // escape velocity as function of planet radius and density
{
if (system.isInterstellarSpace) return;
var escapeVelocity = 11180 * planetRadius / 6400 * Math.sqrt(planetDensity / 5.5);
return escapeVelocity;
}
this.$astroLib_surfaceGravity = function(planetRadius, escapeVelocity) // planet surface gravity as function of planet radius and escape velocity
{
if (system.isInterstellarSpace) return;
var surfaceGravity = escapeVelocity * escapeVelocity / (planetRadius * 1000) / (9.81 * 2);
return surfaceGravity;
}
this.$astroLib_atmosphereMass = function(planetRadius, escapeVelocity, equilibriumTemperature) // mass of atmosphere per unit of surface square as function of planet radius, escape velocity and equilibrium temperature
{
if (system.isInterstellarSpace) return;
var termosphereTemperature = equilibriumTemperature * 4;
var termosphereVelocity = 320 * Math.sqrt(termosphereTemperature / 273.15);
var dissipation_ratio = termosphereVelocity / escapeVelocity;
var dissipation_adjust = dissipation_ratio * 25;
var volatile_pool = planetRadius / 1600 * Math.pow(255 / equilibriumTemperature,2);
var atmosphereMass;
var insolation = Math.pow(equilibriumTemperature / 255,4);
var volatile_adjust = (planetRadius - 6250) / 100;
if (insolation > 1.75 && planetRadius > 6250 && planetRadius < 7500) // runaway greenhouse trigger
{
atmosphereMass = volatile_pool * Math.exp(-dissipation_adjust) * (1 + volatile_adjust * volatile_adjust);
}
else
{
atmosphereMass = volatile_pool * Math.exp(-dissipation_adjust);
}
return atmosphereMass;
}
this.$astroLib_atmospherePressure = function(atmosphereMass, surfaceGravity) // atmosphere pressure as function of atmosphere mass and surface gravity
{
if (system.isInterstellarSpace) return;
var atmospherePressure = atmosphereMass * surfaceGravity;
return atmospherePressure;
}
this.$astroLib_atmosphereTemperature = function(equilibriumTemperature, atmosphereMass) // planet surface temperature as function of equilibrium temperature and atmosphere mass (greenhouse effect)
{
if (system.isInterstellarSpace) return;
var atmosphereTemperature = equilibriumTemperature + 0.125 * equilibriumTemperature * Math.sqrt(atmosphereMass);
return atmosphereTemperature;
}
|
Scripts/solar_activity.js |
"use strict";
this.name = "SolarActivity";
this.author = "Stranger";
this.copyright = "Creative Commons: attribution, non-commercial, sharealike with clauses - see readme.txt";
this.description = "Dynamic solar flares";
this.version = "2.5";
this.shipWillLaunchFromStation = this.shipWillExitWitchspace = function()
{
if (system.isInterstellarSpace) return;
var info = system.info;
// regular case
var flareBasic = 0.10 + Math.random() * 0.10;
var flareRate = 0.10 * 1000000 / system.sun.radius; // red dwarves has more frequent flares than yellow stars
var flareFlux = 0.30;
// peculiar solar activity mentioned in system description
if (system.info.description.indexOf("occasional solar activity") > -1)
{
flareRate = 0.30;
flareFlux = 0.40;
}
if (system.info.description.indexOf("unpredictable solar activity") > -1)
{
flareRate = 0.35;
flareFlux = 0.50;
}
if (system.info.description.indexOf("frequent solar activity") > -1)
{
flareRate = 0.40;
flareFlux = 0.60;
}
if (system.info.description.indexOf("dreadful solar activity") > -1)
{
flareRate = 0.45;
flareFlux = 0.70;
}
if (system.info.description.indexOf("deadly solar activity") > -1)
{
flareRate = 0.50;
flareFlux = 0.80;
}
var flareTrigger = Math.random();
// active sun
if (flareTrigger < flareRate)
{
info.corona_flare = flareBasic + Math.random() * flareFlux;
}
// quiet sun
else
{
info.corona_flare = flareBasic;
}
}
|
Scripts/solar_system_data.js |
"use strict";
this.name = "SolarSystemData";
this.author = "Stranger";
this.copyright = "This work is hereby placed in the public domain.";
this.description = "Displays system sun and planet data on MFD and F4 info page.";
this.version = "4.5.2";
this.startUpComplete = function()
{
this.self = player.ship;
this.$setupDelay = new Timer(this, this.$setupSystemInfo, 1); //delay to set planet orbits!
}
this.shipWillLaunchFromStation = this.shipWillExitWitchspace = function()
{
if (system.isInterstellarSpace) return;
if(this.self.equipmentStatus("EQ_ADVANCED_COMPASS") == "EQUIPMENT_OK")
{
this.self.awardEquipment("EQ_ADVANCED_SYSTEM_DATA_MFD");
this.$scriptDelay = new Timer(this, this.$setupSystemInfo, 1);
this.$startUpdateMFDTimer();
}
else
{
this.self.removeEquipment("EQ_ADVANCED_SYSTEM_DATA_MFD");
}
}
this.$startUpdateMFDTimer = function()
{
if(this.$updateMFDTimer)
{ this.$updateMFDTimer.start(); }
else
{ this.$updateMFDTimer = new Timer(this, this.$updateMFD,0,1); }
}
this.shipWillDockWithStation = this.shipDied = this.$stop$updateMFDTimer = function()
{
if(this.$updateMFDTimer && this.$updateMFDTimer.isRunning) { this.$updateMFDTimer.stop(); }
}
this.$updateMFD = function()
{
if(this.self.equipmentStatus("EQ_ADVANCED_COMPASS") != "EQUIPMENT_OK") return;
if(this.self.compassMode === "COMPASS_MODE_SUN")
{
this.$starPage();
}
else
{
this.$planetPage();
}
}
this.$starPage = function()
{
var w = worldScripts.AstroLibrary;
var info = system.info;
var catNum = " " + galaxyNumber + " " + system.ID;
if (system.info.sun_radius)
{
var sunRadius = system.sun.radius;
}
var sunDistance = player.ship.position.distanceTo(system.sun).toFixed(0);
var sunRelDistance = (sunDistance/system.sun.radius);
var solarWind = w.$astroLib_SolarWind(sunDistance);
var solarActivity = 10 * info.corona_flare;
var output = "Catalog number: " + catNum + "\n"
+ "Spectral class: " + this.$spectrumText + "\n"
+ "Radius: " + this.$solRadius.toFixed(2) + "\n"
+ "Mass: " + this.$sunMass.toFixed(2) + "\n"
+ "Luminosity: " + this.$solLuminosity.toFixed(2) + "\n"
+ "Solar activity: " + solarActivity.toFixed(2) + "\n"
+ "Main planet period: " + this.$localYear.toFixed(2) + " days" + "\n"
+ "Sun distance: " + sunRelDistance.toFixed(2) + " R" + "\n"
+ "Solar wind flux: " + solarWind.toFixed(2) + " LY/min" + "\n\n";
this.self.setMultiFunctionText("EQ_ADVANCED_SYSTEM_DATA_MFD", output, false);
}
this.$planetPage = function()
{
var output = this.$planetOrbitInfo;
this.self.setMultiFunctionText("EQ_ADVANCED_SYSTEM_DATA_MFD", output, false);
}
this.$setupSystemInfo = function()
{
var w = worldScripts.AstroLibrary;
// sun info
var info = system.info;
var catNum = " " + galaxyNumber + " " + system.ID;
if (system.info.sun_radius)
{
var sunRadius = system.sun.radius;
}
var spectrumText = w.$astroLib_sunSpectrum(sunRadius);
var solRadius = system.sun.radius/950000 * (0.99 + 0.02 * system.scrambledPseudoRandomNumber(119));
var sunMass = w.$astroLib_sunMass(sunRadius);
var sunTemperature = w.$astroLib_sunTemperature(sunRadius);
var sunLuminosity = w.$astroLib_sunLuminosity(sunTemperature,sunRadius);
var solLuminosity = 1.31 * sunLuminosity; // use for display only, not in real calculations!
var localYear = w.$astroLib_solPeriod(sunMass);
this.$spectrumText = spectrumText;
this.$solRadius = solRadius;
this.$sunMass = sunMass;
this.$solLuminosity = solLuminosity;
this.$localYear = localYear;
// planet info
var infoFlag = 1;
var planetMaxNumber = 8;
var planetOrbitInfoRow = new Array();
planetOrbitInfoRow[0] = "1.00 OU * Main Planet\n";
for (let i=1; i<planetMaxNumber; i++)
{
planetOrbitInfoRow[i] = "";
}
var planetOrbitRadius;
var planetRadius;
var planetDataTag;
var planetOrbitScan = w.$astroLib_orbitRadius();
var planetOrbitInfo = "PLANETS" + "\n";
for (let i=0; i<system.planets.length; i++)
{
planetOrbitRadius = planetOrbitScan[i];
planetRadius = system.planets[i].radius;
if(system.planets[i].radius < 25000)
{
planetDataTag = 0;
}
if(system.planets[i].radius >= 27500 && system.planets[i].radius < 30000 && system.planets[i] != system.mainPlanet)
{
planetDataTag = 1;
}
if(system.planets[i].radius >= 50000 && system.planets[i].radius < 75000 && system.planets[i] != system.mainPlanet)
{
planetDataTag = 2;
}
if(system.planets[i].radius >= 30000 && system.planets[i].radius < 50000 && system.planets[i] != system.mainPlanet)
{
planetDataTag = 3;
}
if(system.planets[i].radius >= 75000 && system.planets[i].radius < 100000 && system.planets[i] != system.mainPlanet)
{
planetDataTag = 4;
}
if(system.planets[i].radius >= 150000 && system.planets[i].radius < 175000 && system.planets[i] != system.mainPlanet)
{
planetDataTag = 5;
}
if(system.planets[i].radius >= 125000 && system.planets[i].radius < 150000 && system.planets[i] != system.mainPlanet)
{
planetDataTag = 6;
}
if(system.planets[i].radius >= 100000 && system.planets[i].radius < 125000 && system.planets[i] != system.mainPlanet)
{
planetDataTag = 7;
}
if(system.planets[i].radius >= 25000 && system.planets[i].radius < 27500 && system.planets[i] != system.mainPlanet)
{
planetDataTag = 8;
}
switch (planetDataTag)
{
case 0: infoFlag = 0; break;
case 1: planetOrbitInfoRow[1] = planetOrbitRadius.toFixed(2) + " OU * Miniterra\n"; break;
case 2: planetOrbitInfoRow[2] = planetOrbitRadius.toFixed(2) + " OU * Terra\n"; break;
case 3: planetOrbitInfoRow[3] = planetOrbitRadius.toFixed(2) + " OU * Subterra\n"; break;
case 4: planetOrbitInfoRow[4] = planetOrbitRadius.toFixed(2) + " OU * Superterra\n"; break;
case 5: planetOrbitInfoRow[5] = planetOrbitRadius.toFixed(2) + " OU * Gas Giant\n"; break;
case 6: planetOrbitInfoRow[6] = planetOrbitRadius.toFixed(2) + " OU * Gas Giant\n"; break;
case 7: planetOrbitInfoRow[7] = planetOrbitRadius.toFixed(2) + " OU * Ice Giant\n"; break;
case 8: planetOrbitInfoRow[8] = planetOrbitRadius.toFixed(2) + " OU * Dwarf Terra\n"; break;
}
}
for (let i=0; i<planetOrbitInfoRow.length; i++)
{
planetOrbitInfo += planetOrbitInfoRow[i];
}
this.$planetOrbitInfo = planetOrbitInfo;
if(this.self.docked) this.$initInterface(this.self.dockedStation);
}
this.shipWillDockWithStation = this.shipWillEnterWitchspace = function()
{
this.shipDied();
}
this.shipDied = function()
{
if(this.$scriptDelay)
{
this.$scriptDelay.stop();
delete this.$scriptDelay;
}
}
this.shipDockedWithStation = function(station)
{
this.$setupSystemInfo();
if (this.self.dockedStation.isMainStation == true)
{
this.$initInterface(station);
}
}
this.$initInterface = function(station)
{
station.setInterface(this.name,{
title:"System Data Sheet",
category:"Informational",
summary:"Provide advanced system data",
callback:this.$setupSystemInfoPage.bind(this)
});
}
this.$setupSystemInfoPage = function()
{
var systemAdvancedInfo = "SUN" + "\n"
+ "Spectral class: " + this.$spectrumText + "\n"
+ "Radius: " + this.$solRadius.toFixed(2) + "\n"
+ "Mass: " + this.$sunMass.toFixed(2) + "\n"
+ "Luminosity: " + this.$solLuminosity.toFixed(2) + "\n"
+ "Main planet period: " + this.$localYear.toFixed(2) + " days" + "\n"
+ "\n"
+ this.$planetOrbitInfo;
mission.runScreen({
title: "System Data Sheet",
// background: {name: "specialCargoLoad.png", height: 480 },
message: systemAdvancedInfo,}
);
} |
Scripts/spectral_class.js |
"use strict";
this.name = "SunSpectralAnalyzer";
this.author = "Stranger";
this.copyright = "This work is hereby placed in the public domain.";
this.description = "Conversion sun color to spectral index";
this.version = "3.9";
//This script inspired and partly based on Wildblood's Spectroscope script
this.guiScreenChanged = function()
{
if (guiScreen === "GUI_SCREEN_SYSTEM_DATA")
{
var info = System.infoForSystem(galaxyNumber, player.ship.targetSystem);
if (info.sun_gone_nova) return;
var w = worldScripts.AstroLibrary;
var name = info.name;
var sunName = info.sun_name;
var sunRadius = info.sun_radius;
var spectrumText = w.$astroLib_sunSpectrum(sunRadius);
if (spectrumText && sunName) mission.addMessageText("The planet " + name + " orbits the " + spectrumText + " " + sunName + ".");
else if (spectrumText) mission.addMessageText("The planet " + name + " orbits a " + spectrumText + " " + "star.");
else if (sunName) mission.addMessageText("The planet " + name + " orbits the star " + sunName + ".");
}
}
|