Back to Index Page generated: Dec 20, 2024, 7:22:10 AM

Expansion Market Cooldown

Content

Warnings

  1. Information URL mismatch between OXP Manifest and Expansion Manager string length at character position 0

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description Changes the game to remember markets when changing systems. The memory gradually fades away over time. This encourages to move a bit rather than zipping between two systems. Changes the game to remember markets when changing systems. The memory gradually fades away over time. This encourages to move a bit rather than zipping between two systems.
Identifier oolite.oxp.spara.market_cooldown oolite.oxp.spara.market_cooldown
Title Market Cooldown Market Cooldown
Category Mechanics Mechanics
Author spara spara
Version 0.3 0.3
Tags
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL n/a
Download URL https://wiki.alioth.net/img_auth.php/4/40/Market_cooldown_0.3.oxz n/a
License CC-BY-NC-SA 4.0 CC-BY-NC-SA 4.0
File Size n/a
Upload date 1610873282

Documentation

Also read http://wiki.alioth.net/index.php/Market%20Cooldown

Equipment

This expansion declares no equipment. This may be related to warnings.

Ships

This expansion declares no ships. This may be related to warnings.

Models

This expansion declares no models. This may be related to warnings.

Scripts

Path
Config/script.js
"use strict";

this.name = "market_cooldown";
this.author = "spara";
this.description = "Create a fade out effect to the markets";

this.startUp = function() {
	//this is the number of jumps needed to fade the effect
	this.$jumpsNeeded = 10.0;

	//fadecounter is a number between ]0, 10]
	//this calculates the step the counter needs to take each time. don't touch
	this.$step = 10.0 / this.$jumpsNeeded;
	
	if (missionVariables.marketCooldown) {
		this.$storedMarkets = JSON.parse(missionVariables.marketCooldown);
	}
	else this.$storedMarkets = new Object();
}

//store market on exiting station
this.shipLaunchedFromStation = function(station) {
	if (system.isInterstellarSpace) return;
	var sMarket = station.market;
	var marketObj = new Object();
	marketObj.fadeCounter = 0.0;
	for (var i in sMarket) {
		marketObj[i] = sMarket[i].quantity;
	}
	//a uniqueish key for the station calculated from station to witchpoint buoy and sun distances
	var idKey = Math.round(station.position.magnitude() + station.position.distanceTo(system.sun.position));
	this.$storedMarkets[idKey] = marketObj;
}

//advance counters on exiting withcspace. when a counter reaches 10, delete the market entry.
this.shipWillExitWitchspace = function() {
	for (var i in this.$storedMarkets) {
		//rounding used here for rounding possible rounding error on using fractional step counter.
		if (Math.round(this.$storedMarkets[i].fadeCounter) >= 10){
			delete this.$storedMarkets[i];
		}
		else {
			this.$storedMarkets[i].fadeCounter += this.$step;
		}
	}
}

//add cooldown effect to all recently visited markets.
this.shipExitedWitchspace = function() {
	var stations = system.stations;
	for (var i = 0; i < stations.length; i++) {
		var station = stations[i];
		var idKey = Math.round(station.position.magnitude() + station.position.distanceTo(system.sun.position));
		if (this.$storedMarkets[idKey]) {
			var sMarket = station.market;
			var oMarket = this.$storedMarkets[idKey];
			var percentageMultiplier = oMarket.fadeCounter / 10.0;
			for (var j in sMarket) {
				var oldQuantity = oMarket[j];
				var proposedQuantity = sMarket[j].quantity;
				var diff = Math.round((proposedQuantity - oldQuantity) * percentageMultiplier);
				station.setMarketQuantity(j, oldQuantity + diff);
			}
		}
	}
}


this.playerWillSaveGame = function() {
	missionVariables.marketCooldown = JSON.stringify(this.$storedMarkets);
}

//clear all saved markets on galactic jump.
this.playerEnteredNewGalaxy = function() {
	delete this.$storedMarkets;
	this.$storedMarkets = new Object();
}