Back to Index Page generated: May 8, 2024, 6:16:03 AM

Expansion Torus To Sun Drive

Content

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description Reach the Sun faster due to your Torus works better far from planetary masses. Practical when an addon moved the Sun farther. Moreover provide 2x time forwarding anywhere at Torus speeds when your weapons are offline. Reach the Sun faster due to your Torus works better far from planetary masses. Practical when an addon moved the Sun farther. Moreover provide 2x time forwarding anywhere at Torus speeds when your weapons are offline.
Identifier oolite.oxp.Norby.TorusToSun oolite.oxp.Norby.TorusToSun
Title Torus To Sun Drive Torus To Sun Drive
Category Mechanics Mechanics
Author Norby Norby
Version 1.7 1.7
Tags
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL http://wiki.alioth.net/index.php/TorusToSun n/a
Download URL https://wiki.alioth.net/img_auth.php/8/87/TorusToSun_1.7.oxz n/a
License CC-BY-NC-SA 4.0 CC-BY-NC-SA 4.0
File Size n/a
Upload date 1610873353

Documentation

Also read http://wiki.alioth.net/index.php/Torus%20To%20Sun%20Drive

TorusToSun_readme.txt

Torus To Sun OXP

Your Torus Drive get an upgrade to reach the Sun faster if you buy Torus To Sun Drive for 500Cr.
Practical when an addon moved the Sun farther and if you travel to non-main stations also.

Your speed multiplier will be limited by the distance and mass of the nearest planetary object and can reach maximum 8 times of the original Torus Drive.

The built-in proximity detector will slow to 1x Torus speed when anything is arrive into scanner range. This is a help to do not miss Rock Hermits, but you still must press the slow key immediately if you want stop.

Multipliers over 2x need unpowered weapons. If you want to slow down at far objects like Giant Space Pizza then turn back your weapons in time to avoid overrun.

By unpowering your weapons (press the underscore key) a 2x time forwarding is applied in addition so your game clock will adjusting. When you reach the maximal Torus multiplier (8x) then forwarding will be inceased to 4x so your top speed is as if you have a 32x drive. In this way you can use Realistic Stars OXP where the Sun is 8 times farther and still arrive to the Sun in 2 minutes due to the very fast last part of the travel will compensate the slow start from the planet.

Combat MFD can display the multiplier if installed and is not damaged so no console messages printed in this case.


You can not leave the Sun as fast as you arrived due to the high gravity of this huge mass can help to keep up the high speed until the last moment when you fall into but will slow you strongly when you turn back to leave until you are near.

There are side effects what you must accept as feedbacks of the extreme speeds:
-the sky will shaking,
-the engine trails in the aft view will get left far behind you.

You can move the Sun farther in this addon also in Config/planetinfo.plist.


Instructions:

In Oolite v1.79 or later do not unzip the .oxz file, just move into the AddOns folder of your Oolite installation.
In Oolite v1.77 make a TorusToSun.oxp subfolder in your AddOns folder and unzip the .oxz file into the newly created subfolder.

License:

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License version 4.0.
If you are re-using any piece of this OXP, please let me know by sending an e-mail to norbylite@gmail.com.


Changelog:
 2018.08.19. v1.7  Performance improvement when no speed bonus, thanks to tokugawa.
 2015.07.27. v1.6  Bugfix of increasing speed bonus after multiple jumps, thanks to avder.
 2015.05.18. v1.5  Slow to 1x Torus speed when anything is arrive into scanner range.
                   Speed multiplier is limited to 2x if weapons are online.
                   A 2x time forward is always available with offline weapons.
                   Maximal time forwarding is reduced to 4x (adjustable in torustosun.js).
                   Fixed timer stop.
 2014.08.03. v1.4  Speed is limited to 4x if weapons are online.
 2014.07.27. v1.3  Use the gravity of Sun to earn faster approach and slower leaving.
                   Use 8x time forwarding to earn 64x top speed (not TAF but adjustment).
 2014.07.26. v1.2  Nonlinear speed calculation.
                   Better handling of Additional planets.
                   Fix the ovelapping gravity if the distance is small between two planets.
 2014.07.24. v1.1  Equipment added.
 2014.07.23. v1.0  First release.

Equipment

Name Visible Cost [deci-credits] Tech-Level
Torus To Sun Drive yes 5000 5+

Ships

This expansion declares no ships.

Models

This expansion declares no models.

Scripts

Path
Scripts/torustosun.js
"use strict";
this.name        = "torustosun";
this.author      = "Norby";
this.copyright   = "2014 Norbert Nagy";
this.licence     = "CC BY-NC-SA 4.0";
this.description = "Reach the Sun faster.";

//http://aegidian.org/bb/viewtopic.php?f=6&t=16704&p=223460#p223405
//-start at 1x when you leave the masslock of planet,
//-increasing exponentially between the planet and sun up to 8x,
//-multipliers over 2x need unpowered weapons,
//-fall down to the base value before the sun,
//-limited to the max value if far from both the sun and planet.
//-unpowered weapons provide 2x time forwarding at torus speeds.

//customizable properties
this.$MaxWithWeapons = 2; //chop the bonus to be able to catch Space Pizzas
this.$MaxTimeFw = 4; //time forwarding at max. multiplier (adjustment, not TAF)
this.$Messages = true; //show messages about the current speed (but no messages with CombatMFD regardless of this)
this.$MessagesWithCombatMFD = false; //send Torus multiplier messages with combatMFD also
this.$TimeFwWeaponsOff = 2; //default time forwarding with offline weapons
this.$MaxMultiplier = 8; //*32*400m/s (Asp) almost fit into the 5 digit NumericHUD

//internal properties, should not touch
this.$TimeFw = 1; //actual time forwarding, checked in CombatMFD
this.$TorusToSunBonus = 1; //current speed multiplier, checked in CombatMFD
this.$DBonus = ""; //the lastly displayed speed multiplier
this.$DMore = false; //the lastly displayed more need offline weapons message
this.$FCB = null; //framecallback
this.$FwSec = 0; //part of a second during forwarding
this.$NearestPlanet = null; //store the nearest planet between rechecks
this.$PrevEnergy = 0; //previous energy value of player
this.$Timer = null; //Timer for Torus speedup
this.$WED = null; //the worldscript of EscortDeck
this.$WFP = null; //store worldScripts.farplanets

//world script events
this.startUp = function() {
	this.$WED = worldScripts.escortdeck;
	this.$WFP = worldScripts.farplanets;
//	var n = worldScripts.numerichudv3;
//	if( n && n.version * 1 >= 3.24 ) this.$Messages = false;
	this.$Timer = new Timer(this, this._Timed.bind(this), 1, 0.25);
	this._StopTimer(); //pause timer
}

this.alertConditionChanged = function(newCondition, oldCondition) {
//     log("alertConditionChanged", newCondition  + "::" + oldCondition)
       if (newCondition == 1)       {
               this._StartTimer();
       } else  {
               this._StopTimer();
       }
}

this.shipWillDockWithStation = function() {
	this._StopTimer();
}

this.shipWillEnterWitchspace = function() {
	this._StopTimer();
}

this.shipWillExitWitchspace = function() {
	this._StartTimer(); //must start before Telescope FCBs!
}

this.shipWillLaunchFromStation = function() {
	this._StartTimer(); //must start before Telescope FCBs!
}

//TorusToSun functions
this._FCB = function( delta ) { //masslockcheck in this framecallback
	var b = this.$TorusToSunBonus;
	var ps = player.ship;
	if( !ps ) return; //player is died
//	log("TorusToSun", "speed: "+Math.round(ps.speed)+" velocity: "+Math.round(ps.velocity.magnitude())); //debug
	if( player.alertCondition > 1 || ps.speed < ps.maxSpeed * 31.9 //not in full torus
		|| this.$WFP && //FarPlanets OXP active
		( this.$WFP.$FarPlanetsSlowDown || this.$WFP.$FarPlanetsBonus > 1 )
		|| this._Proximity(this) ) //turn off near asteroids
		 this._TorusSlowDown(); //do not apply TorusToSun
	if( !this.$SlowDown && b > 1 ) { //currently travel at bonus speeds
		var f = ps.vectorForward;
		var s = ps.maxSpeed * 32;
		var t = this.$TimeFw - 1; //torus speed with time forwarding
		ps.position = ps.position.add( f.multiply( delta * s * ( t + b - 1 ) ) ); //apply speed bonus
        } else {
                if( isValidFrameCallback( this.$FCB ) )
                       removeFrameCallback( this.$FCB );
        }
}

this._NearestMass = function(skip) {
	var d = 100000000000000000000.0; //10^20m for sure
	var psp = player.ship.position;
	var nm = null;
	var p = system.planets;
	var len = p.length;
	for( var i = 0; i < len; i++ ) { //find the smallest distance
		var pl = p[i];
		if( pl != skip ) { //the second nearest if requested
			var s = psp.distanceTo( pl.position );
			if( d > s ) {
				d = s;
				nm = pl;
			}
		}
	}
	return( nm );
}

this._Proximity = function(ws) { //there is a similar function in TimeControl oxp, if changed then must change both!
	var s = player.ship.checkScanner(false);
	for( var i = 0; s && s.length > i; i++ ) {  //exclude escorts and telescopemarker
		if( ws.$WED && ws.$WED.$EscortDeckShip.indexOf(s[i]) == -1
			&& s[i].dataKey && s[i].dataKey != "telescopemarker" ) {
			return(true);
		}
	}
	return(false);
}

this._StartTimer = function() {
	this.$PrevEnergy = player.ship.maxEnergy;
	this.$FwSec = 0; //part of a second during forwarding
	if( this.$Timer ) {
		this.$Timer.start();
	}
}

this._StopTimer = function() {
	if( this.$Timer ) {
		this.$Timer.stop();
	}
	if( isValidFrameCallback( this.$FCB ) )
		removeFrameCallback( this.$FCB );
	this._TorusSlowDown(); //set bonus to 1
}

this._Timed = function() {
	var ps = player.ship;
	if( !ps || !ps.isValid ) return; //player died
	if( player.alertCondition == 1 && ps.speed > ps.maxSpeed * 31.9 ) {//Green Alert and Torus maxed
		this._TorusSpeedUp();
		if( !isValidFrameCallback( this.$FCB ) )
		        this.$FCB = addFrameCallback( this._FCB.bind(this) );
	}
}

this._TimeFw = function( bonus ) { //use time forwarding at maximal bonus if weapons off
	if( bonus == this.$MaxMultiplier && !player.ship.weaponsOnline ) return(true);
	return(false);
}

this._TorusSlowDown = function() { //slowdown from extreme speed to normal or Torus speeds
	if( this.$TorusToSunBonus <= 1 ) return; //need to avoid block Injector speeds
	this.$PrevEnergy = player.ship.energy;
	this.$TorusToSunBonus = 1; //the main thing for slowdown
	this.$DBonus = "";
	this.$DMore = false;
	this.$SlowDown = true; //flag to FCB
}

this._TorusSpeedUp = function() {
	var ps = player.ship;
	if( !ps || !ps.isValid || this.$WFP && //FarPlanets OXP active
		( this.$WFP.$FarPlanetsSlowDown || this.$WFP.$FarPlanetsBonus > 1 ))
		return;

	var bonus = 1;
	if( ps.equipmentStatus("EQ_TORUSTOSUN") == "EQUIPMENT_OK"
		&& system && system.planets && system.planets.length > 0
		&& !system.isInterstellarSpace && system.sun && system.sun.isValid
		&& !system.sun.hasGoneNova ) {
		this.$SlowDown = false;
	
		var co = 1000; //coefficient, larger value cause smaller speeds
		var mm = this.$MaxMultiplier;

		var sr = system.sun.radius;
		var pds = ps.position.distanceTo( system.sun.position ) - sr; //playerDistanceFromSun
		//check sun direction and apply gravity pullback, angle=0: aft, angle=PI: front
		var angle = ps.vectorForward.angleTo(ps.position.subtract(system.sun.position));
		sr = Math.min(sr, 200000); //max. 200km in the following formula
		//keep up the high speed much longer when approach the sun
		var min = pds / ( 10000 + ( 1 - angle / Math.PI ) * sr *
			Math.max( 0, 1 - pds / ( 10 * sr ) ) ); //no gravity pullback over 10 sun radius
		bonus = 1 + (mm - 1) * Math.min( 1, min * min / co ); //nonlinear calculation

		var nm = this._NearestMass();
		var nr = Math.max(nm.radius, 50000); //min. 50k to reduce speeds near small moons
		var pdp = ps.position.distanceTo( nm.position ) - 2 * nr; //playerDistanceFromPlanet
		min = pdp / nr;
		var b1 = 1 + (mm - 1) * Math.min( 1, min * min / co ); //nonlinear calculation
		bonus = Math.min(b1, bonus); //use the smaller bonus
		
		var nm2 = this._NearestMass(nm); //the second nearest mass
		if( nm2 ) {
			var nr2 = Math.max(nm2.radius, 50000); //min. 50k to reduce speeds near small moons
			var pdp2 = ps.position.distanceTo( nm2.position ) - 2 * nr2; //playerDistanceFromPlanet2
			min = pdp2 / nr2;
			var b2 = 1 + (mm - 1) * Math.min( 1, min * min / co ); //nonlinear calculation
			bonus = Math.min(b2, bonus); //use the smallest bonus
		}
//		log("TorusToSun", " bonus:"+bonus+" pdp:"+pdp+" pds:"+pds+" nm:"+nm); //debug
	}
	
	if( ps.weaponsOnline ) bonus = Math.min(bonus, this.$MaxWithWeapons);

	if( bonus > 1 ) { //show speed bonus, apply will happen in FCB
		var b = Math.round( bonus );
		if( this._TimeFw( bonus ) ) this.$TimeFw = this.$MaxTimeFw;
		else if( !ps.weaponsOnline ) this.$TimeFw = this.$TimeFwWeaponsOff; //2x
		else this.$TimeFw = 1; //no time forward with online weapons
		
		if( this.$TimeFw > 1 ) {
			var delta = 0.25; //0.25sec timer
			//calculate the bonus time plus add the previous remainder
			var sec = delta * ( this.$TimeFw - 1 ) + this.$FwSec;
//			log("TorusToSun", " bonus:"+bonus+" mm:"+mm+" sec:"+sec); //debug
			if( sec >= 1 ) {
				var maxsec = 2592000; //not allowed to add more sec in one step
				if( sec < maxsec ) clock.addSeconds( Math.floor( sec ) ); //add the integer part
				else {
					var sec2 = Math.floor( sec / maxsec );
					for(var i=0; i<sec2; i++) clock.addSeconds( maxsec );
					clock.addSeconds( sec - maxsec * sec2 );
				}
//				log("TorusToSun", this.$TimeFw+"x added "+sec+"s = "+(sec/86400)+" day"); //debug
				this.$FwSec = sec - Math.floor( sec ); //save the remainder
			} else this.$FwSec = sec;
			if( this.$PrevEnergy < ps.energy && ps.energy < ps.maxEnergy - 1 ) {
				//recharge speed up scaled with forwarding
				ps.energy +=  ( ps.energy - this.$PrevEnergy ) * sec / delta;
			}
		}

		if( this.$Messages && !this.$DMore && ps.weaponsOnline
			&& bonus == this.$MaxWithWeapons ) {
			this.$DMore = " - more need offline weapons";
			player.consoleMessage( "Torus " + b + "x" + this.$DMore, 5 );
		} else {
			if( this.$Messages && this.$DBonus != b && ( this.$MessagesWithCombatMFD
				|| ps.equipmentStatus("EQ_COMBATMFD") != "EQUIPMENT_OK" ) ) {
				player.consoleMessage( "Torus " + b + "x", 5 );
			}
		}
		if( bonus < this.$MaxWithWeapons) this.$DMore = false; //prevent repeated message
		this.$PrevEnergy = ps.energy;
		this.$TorusToSunBonus = bonus;
		this.$DBonus = b; //save last message to avoid repeat
	}  else this._TorusSlowDown(); //slowdown
}