Back to Index Page generated: Jun 13, 2026, 7:54:54 PM

Expansion Station Validator

Content

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description Tracks when stations are destroyed and then the station OXP's can query how much time has passed since destruction to enable a station to shown as partially built. Tracks when stations are destroyed and then the station OXP's can query how much time has passed since destruction to enable a station to shown as partially built.
Identifier oolite.oxp.spara.station_validator oolite.oxp.spara.station_validator
Title Station Validator Station Validator
Category Miscellaneous Miscellaneous
Author spara spara
Version 1.1 1.1
Tags
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL https://wiki.alioth.net/index.php/Station_Validator n/a
Download URL https://wiki.alioth.net/img_auth.php/2/23/StationValidator.oxz n/a
License CC-BY-NC-SA 3.0 CC-BY-NC-SA 3.0
File Size n/a
Upload date 1779080996

Relationships Diagram

Documentation

Also read http://wiki.alioth.net/index.php/Station%20Validator

station_validator_readme_&_license.txt

Station Validator OXP ver 1.0 (29.1.2014)

Author: spara (Mika Spåra)

_Overview_

In the core game, when a station is destroyed, it magically resurrects after save/load or witchjump. This oxp aim's to make a change to that. When a stationary station is destroyed, this oxp stores it's primary role, the system it died in, the place it died at and the time it died. When that destroyed station is to be spawned next, it can query this oxp, if there has been any destructions of that kind of stations in the current system. Then it's up to the station oxp to decide whether to spawn or not.

Main stations and rock hermits are also handled.

_In_detail_

For oxp creators this oxp has two uses

1. Hold the spawning of a destroyed station until it has been rebuild.
2. Create a set of unfinished station models and let it show that the station is being rebuilt

_Usage_

Call worldScripts.station_validator.$deathTime("your_station_role", rebuildTime) and you'll receive an array of objects. Each object is a death of "your_station_role"-station that has not met the rebuildTime yet in the current system . Each object has two properties: time (integer) and place (Vector3D). RebuildTime parameter is optional and defaults to 30.

Scenarios:

1. There is only one station with "your_station_role" in system

Call worldScripts.station_validator.$deathTime("your_station_role", rebuildTime) and check the array's length. If it's 0, then the station can be built.

2. There are multiple station with "your_station_role" in system 

Call worldScripts.station_validator.$deathTime("your_station_role", rebuildTime), iterate through the array and act accordingly

3. Show station in it's construction phase

Call worldScripts.station_validator.$deathTime("your_station_role", rebuildTime) and find the station from the list. Use time-property to decide which phase to show and spawn the unfinished model to the position of the place property.

If the unfinished construct is destroyed, the deathTime of the original station should be resetted. For that construct must have "construct" in it's roles and there must be constructRole = "role_of_the_station_to_be_built" in it's script_info.

_Stations_supporting_

* SothisTC
* RandomHits 1.5.3 ->
* AstroFactory 2.0
* Stations for Extra Planets
* Rescue Stations 1.3

Install the OXP by copying station_validator.oxp to your AddOns-folder.

------

This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/

Version 1.1
Fixed issue with overriding of shipDied events, where parameters were not being correctly passed to pre-existing functions.

Equipment

This expansion declares no equipment.

Ships

This expansion declares no ships.

Models

This expansion declares no models.

Scripts

Path
Config/script.js
"use strict";
this.name        = "station_validator"; 
this.author      = "spara"; 
this.copyright   = "2013 - 2014 Mika Spara";
this.licence     = "CC BY-NC-SA 3.0"; 
this.description = "Centralized service to keep track of destroyed stations"; 
this.version     = "1.0";

//This oxp keeps track of destroyed stations. When a station gets destroyed the destruction is noted. The primary role of the destroyed station is saved along with the destruction time, systemID and place of death. Oxps can then ask this oxp for an array or death times and places when they want to spawn a station with a specific role. If a station with that role has been destroyed in current system and the rebuild time has not been reached, then the death details are given. In case of multiple stations, the array can have multiple items.

//Usage 1: Simple check before spawning a singular station.
// * Ask for spawning permission by putting worldScripts.station_validator.$deathTime("your_station_role", rebuildTime) into your spawning script and receive an array of deaths in return.
// * An empty array means that the station was not found from the destroyed stations array and can be spawned.

//Example: SothisTC uses the following code before spawning the station:
//if (worldScripts.station_validator && (worldScripts.station_validator.$deaths("sothis").length !== 0))
//	return;

//Usage 2: Case of multiple stations of the same role.
// * Ask for spawning permission by putting worldScripts.station_validator.$deaths("your_station_role", rebuildTime) into your spawning script and receive an array of deaths in return.
// * Cycle through the list of death times and spawn places and act accordingly.

//Usage 3: Use for showing different stages of construct when rebuilding a station
// * Ask for spawning permission by putting worldScripts.station_validator.$deaths("your_station_role", rebuildTime) into your spawning script and receive an array of deaths in return.
// * Spawn and unfinished construct to the place of death. Construct must have "construct" among it's roles and constructRole = "role_of_the_station_to_be_built" in its script_info
// * If the unfinished station gets destroyed, the original deathTime is reset.

this.$runOnce = 1;

this.startUp = function() {
	//Make sure startUp is ran exactly once.
	if (this.$runOnce) {
	//destroyed stations array is used for storing all destroyed stations in a galaxy.
		if (missionVariables.stationValidator)
			this.$destroyedStations = JSON.parse(missionVariables.stationValidator);
		else this.$destroyedStations = new Array();
		this.$blockedHermits = 0;
		this.$runOnce = 0;
	}
}

//A public function for oxps to use for asking a spawning permit. Returns an array of death times and spawn places.
this.$deaths = function(role, rebuildTime) {
	if (typeof rebuildTime === 'undefined') rebuildTime = 30;
	//Make sure startUp is ran before this function returns anything
	//This might happen if a scripts calls this function from it's startUp
	if (this.$runOnce) this.startUp();
	var i;
	var systemID = system.ID;
	var time = clock.days;
	var deaths = new Array();
	//Go through the destroyed stations array and when a match is found, add it to the deaths array
	for (i = 0; i < this.$destroyedStations.length; i++) {
		if (this.$destroyedStations[i][0] === systemID && role === this.$destroyedStations[i][1] && time < this.$destroyedStations[i][2] + rebuildTime)
			//station found from the array is not yet rebuilt and spawning is not permitted
			deaths.push({time: this.$destroyedStations[i][2], place: this.$destroyedStations[i][3]});
	}
	return deaths;
}

this.playerWillSaveGame = function() {
	if (this.$destroyedStations.length > 0)
		missionVariables.stationValidator = JSON.stringify(this.$destroyedStations);
	else delete missionVariables.stationValidator;
}

//When a stationary station or a construct is spawned, add death note to it's shipDied script.
//Handle main stations and hermits
this.shipSpawned = function(ship) {
 	//handle main station
	if (ship.isMainStation && this.$deaths(ship.primaryRole).length !== 0) {
		ship.remove();
		log("stat","Main station removed");
		return;
	}
	//handle hermits
	if (ship.primaryRole === "rockhermit" && this.$deaths("rockhermit").length > this.$blockedHermits) {
		//remove miners around the destroyed hermit
		var miners = system.shipsWithPrimaryRole("miner",ship,25000);
		var i;
		for (i = 0; i < miners.length; i++)
			miners[i].remove();
		//remove hermit
		ship.remove();
		this.$blockedHermits++;
		return;
	}
	//note only stationary stations in normal space
	if (!system.isInterstellarSpace && ship.isStation && !ship.maxSpeed || ship.hasRole("construct")) {
		//add shipscript to notify on death event
		if (ship.script.shipDied)
			ship.script.$sparaShipDied = ship.script.shipDied;
		else ship.script.$sparaShipDied = function() {};
		ship.sparaSpawnPosition = ship.position;
		ship.script.shipDied = function(who, why) {
			worldScripts.station_validator.$stationDied(ship);
			ship.script.$sparaShipDied(who, why);
			delete ship.script.shipDied;
			ship.script.shipDied = ship.script.$sparaShipDied;
			delete ship.script.$sparaShipDied;
		}
	}
}

//stations call this when they die.
this.$stationDied = function(shipObj) {
	//if the destroyed station is an unfinished construct, alter the death time of the original instead of adding a new destroyed station to the array.
	if (shipObj.hasRole("construct") && shipObj.scriptInfo.constructRole) {
		var i;
		var role = shipObj.scriptInfo.constructRole;
		var spawnPosition = shipObj.sparaSpawnPosition;
		for (i = 0; i < this.$destroyedStations.length; i++) {
			if (role === this.$destroyedStations[i][1] && spawnPosition === this.$destroyedStations[i][3]) {
				this.$destroyedStations[i][2] = clock.days;
				return;
			}
		}
		//if something went wrong and the original station was not found, return silently.
		return;
	}
	//add the destroyed station to the array
	this.$destroyedStations.push([system.ID, shipObj.primaryRole, clock.days, shipObj.sparaSpawnPosition]);
}

//clean destroyed stations array when witchspacing or docking
this.shipWillEnterWitchspace = function() {
	this.$cleanDestroyedStations();
	this.$blockedHermits = 0;
}

this.shipWillDockWithStation = function() {
	this.$cleanDestroyedStations();
}

this.$cleanDestroyedStations = function() {
	var i;
	var time = clock.days;
	//remove stations that have been destroyed for more than 60 days from the destroyed stations array
	for (i = this.$destroyedStations.length - 1; i >= 0 ; i--) {
		if (time >= this.$destroyedStations[i][2] + 60)
			this.$destroyedStations.splice(i, 1);
	}	
}

//forget everything when entering a new galaxy
this.playerEnteredNewGalaxy = function(galaxyNumber) {
     this.$destroyedStations = new Array();
}