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

Expansion Asteroid tweaks

Content

Warnings

  1. http://wiki.alioth.net/index.php/Asteroid%20tweaks -> 404 Not Found
  2. 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 Control asteroid respawning and the number of asteroids the game spawns at system creation. Configure settings via an interface screen. Control asteroid respawning and the number of asteroids the game spawns at system creation. Configure settings via an interface screen.
Identifier oolite.oxp.spara.asteroid-tweaks oolite.oxp.spara.asteroid-tweaks
Title Asteroid tweaks Asteroid tweaks
Category Mechanics Mechanics
Author spara spara
Version 1.3 1.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/e/ef/Asteroid_tweaks_1.3.oxz n/a
License CC-BY-NC-SA 4.0 CC-BY-NC-SA 4.0
File Size n/a
Upload date 1610873507

Documentation

asteroid_tweaks_readme_&_license.txt

Asteroid Tweaks OXP ver 1.3 (24.10.2015)

Author: spara (Mika Spåra)

_Description_

This oxp combines two of my previous small experimental OXPs, Moar Rocks and Asteroid Respawn, into one and adds an interface screen to configure them.

1. Control the number of asteroids spawned at system population by setting a multiplier that multiplies every spawned asteroid. Multiplication factor can be selected from 1-5. Note that multiplying asteroids means more entities and that means more stress to the computer.
2. Respawn destroyed asteroids when the player docks by creating new asteroids around hermits and/or an asteroid field somewhere in system. The size of the field is the number of destroyed asteroids before docking and the placement is around random asteroid far enough from the player. If no suitable asteroid can be found, then the asteroids are scattered around.
3. Configure settings via an interface screen. Interface screen is available at the main station and any rock hermit. If preferred, the interface can be disabled from the main stations.

------

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

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.author      = "spara"; 
this.copyright   = "2015 spara"; 
this.description = "asteroid respawner and multiplier"; 
this.name        = "asteroid_tweaks";

this.startUp = function() {
	//asteroid respawn
	if (!missionVariables.asteroid_tweaks_respawn) {
		this.$respawn = false;
	}
	else this.$respawn = true;
	
	//asteroid multiplier
	if (!missionVariables.asteroid_tweaks_multiplier) {
		missionVariables.asteroid_tweaks_multiplier = 1;
	}
	this.$asteroidMultiplier = missionVariables.asteroid_tweaks_multiplier;
	
	//main station configuration interface
	if (!missionVariables.asteroid_tweaks_config_main) {
		this.$configMain = true;
	}
	else this.$configMain = false;
}

this.missionScreenOpportunity= function() {
	if (!missionVariables.asteroid_tweaks_run_once) {
		this._showAsteroidConfig();
		missionVariables.asteroid_tweaks_run_once = true;
	}
	delete this.missionScreenOpportunity;
}

//multiply the number of asteroids when populating
this.systemWillPopulate = function (){
	var addition = this.$asteroidMultiplier - 1;
	if (addition > 0) {
		system.setPopulator("moar_rocks", {
			callback: function(pos) {
				var asteroids = system.shipsWithPrimaryRole("asteroid");
				for (var i = 0; i < asteroids.length; i++) {
					var position = asteroids[i].position;
					system.addShips("asteroid", addition, position, 25E3);
				};
			}.bind(this),
			location: "INNER_SYSTEM_OFFPLANE"
		});
	}
}

this.shipExitedWitchspace = function() {
	function $findHermits(entity) {
		if (entity.primaryRole && entity.primaryRole.indexOf("rockhermit") !== -1) {
			return true;
		}
		return false;
	}
	if (this.$respawn) {
		
		//count the total number of asteroids
		this.$asteroidsTotal = system.countShipsWithPrimaryRole("asteroid");
		
		//define upper and lower limits for asteroid spawning around hermits.
		var hermits = system.filteredEntities(this, $findHermits, player.ship);
		if (hermits.length > 0) {
			var asteroidsAroundHermits = 0;
			for (var i = 0; i < hermits.length; i++) {
				var hermit = hermits[i];
				asteroidsAroundHermits += system.countShipsWithPrimaryRole("asteroid", hermit, 25E3);
			}
			var average = asteroidsAroundHermits / hermits.length;
			this.$upperHermitLimit = Math.ceil(average / 2);
			this.$lowerHermitLimit = Math.floor(average / 4);
		}
	}
}

this.startUpComplete = function() {
	this.shipWillDockWithStation(player.ship.dockedStation);
	this.shipExitedWitchspace();
}

//replace destroyed asteroids when docking.
this.shipDockedWithStation = function(station) {
	function $findHermits(entity) {
		if (entity.primaryRole && entity.primaryRole.indexOf("rockhermit") !== -1) {
			return true;
		}
		return false;
	}
	function $findFarawayAsteroids(entity){
		if (entity.primaryRole && entity.primaryRole === "asteroid" && entity.position.distanceTo(player.ship.position) > 500E3) {
			return true;
		}
		return false;
	}
	if (this.$respawn) {
		//how many asteroids are we missing?
		//4 boulders count as one asteroid and 4 splinters count as one boulder
		//these are averages. an asteroid spawns 2-6 boulders and a boulder 2-6 splinters
		var reSpawnCount = Math.floor(this.$asteroidsTotal - system.countShipsWithPrimaryRole("asteroid") - (system.countShipsWithPrimaryRole("boulder") + system.countShipsWithPrimaryRole("GriffBoulderBrown") + system.countShipsWithPrimaryRole("GriffBoulderBlue") + system.countShipsWithPrimaryRole("GriffBoulderGrey")) / 4 - system.countShipsWithPrimaryRole("splinter") / 16);
		
		//log(this.name, "missing " + reSpawnCount + " asteroids");
		
		//check hermits
		if (reSpawnCount > 0) {
			var hermits = system.filteredEntities(this, $findHermits);
			if (hermits.length > 0) {
				for (var i = 0; i < hermits.length; i++) {
					var hermit = hermits[i];
					var asteroids = Math.floor(system.countShipsWithPrimaryRole("asteroid", hermit, 25E3) - (system.countShipsWithPrimaryRole("boulder", hermit, 25E3) + system.countShipsWithPrimaryRole("GriffBoulderBrown", hermit, 25E3) + system.countShipsWithPrimaryRole("GriffBoulderBlue", hermit, 25E3) + system.countShipsWithPrimaryRole("GriffBoulderGrey", hermit, 25E3)) / 4 - system.countShipsWithPrimaryRole("splinter", hermit, 25E3) / 16);
					//check if we're between the spawn limits
					if (asteroids < this.$upperHermitLimit && asteroids > this.$lowerHermitLimit) {
						var difference = this.$upperHermitLimit - asteroids;
						while (difference > 0 && reSpawnCount > 0) {
							system.addShips("asteroid", 1, hermit.position, 25E3);
							
							//log(this.name, "spawned a hermit asteroid");
							
							difference--;
							reSpawnCount--;
						}
					}
				}
			}
		};
		//Do we still have more asteroids to respawn? If so, try to create a new field into space
		if (reSpawnCount > 0) {
			//report asteroids over min distance away from player
			var asteroids = system.filteredEntities(this, $findFarawayAsteroids);	
			//Add field only if it can be added around an asteroid far away enough
			if (asteroids.length > 0) {
				var spawnPosition = asteroids[Math.floor(Math.random(asteroids.length))].position;
				//add asteroids as a cloud
				system.addShips("asteroid", reSpawnCount, spawnPosition, 25E3);
				
				//log(this.name, "spawned a field of " +reSpawnCount + " asteroids");
				
			}
			//In case there's no suitable asteroid to be used as a spawn position, spread 'em around the player
			else {
				for (var i = 0; i < reSpawnCount; i++) {
					var spawnPosition = player.ship.position.add(Vector3D.randomDirection(500E3)).multiply(1 + Math.random());
					system.addShips("asteroid", 1, spawnPosition, 25E3);
					
					//log(this.name, "spawned a scattered asteroid");
					
				}
			}
		};
	}
}

this.shipWillDockWithStation = function(station) {
	if (station.primaryRole.indexOf("rockhermit") !== -1 || (station.isMainStation && this.$configMain)) {
		station.setInterface("asteroid_tweaks",{
			title: "Asteroid tweaks",
			category: "Config",
			summary: "Configure asteroid tweaks.",
			callback: this._showAsteroidConfig.bind(this)
		});
	}
}

this._showAsteroidConfig = function() {
	var options = {
		"1_X" : "1x",
		"2_X" : "2x",
		"3_X" : "3x",
		"4_X" : "4x",
		"5_X" : "5x"
	};
	mission.runScreen({
		title: "Asteroid Tweaks",
		message: "Do you want moar asteroids? Multiply the number of asteroids the game spawns when a system is being created. Note though, more asteroids means more stress for your computer. Current multiplier is " + this.$asteroidMultiplier + ".",
		choices: options
	},
	function (choice) {
		this.$asteroidMultiplier = choice.split('_')[0];
		missionVariables.asteroid_tweaks_multiplier = this.$asteroidMultiplier;
		this._showRespawnConfig();
	});
}

this._showRespawnConfig = function() {
	var options = {
		"1_NO" : "No, don't respawn asteroids",
		"2_YES" : "Yes, respawn asteroids"
	};
	mission.runScreen({
		title: "Asteroid Tweaks",
		message: "In the default game, it's possible to empty a system from asteroids by destroying them all. This setting makes the game respawn destroyed asteroids as a new asteroid field somewhere in system when the player docks. Current asteroid respawn setting is: " + this.$respawn + ".",
		choices: options
	},
	function (choice) {
		if (choice === "1_NO" && this.$respawn) {
			this.$respawn = false;
			delete missionVariables.asteroid_tweaks_respawn;
		}
		else if (choice === "2_YES" && !this.$respawn) {
			this.$respawn = true;
			this.shipExitedWitchspace();
			missionVariables.asteroid_tweaks_respawn = 1;
		}
		this._showMainConfig();
	});
}

this._showMainConfig = function() {
	var options = {
		"1_YES" : "Yes, show it at the main station",
		"2_NO" : "No, don't show it at the main station"
	};
	mission.runScreen({
		title: "Asteroid Tweaks",
		message: "Show this config interface at the main station interfaces. Interface is always available at any rock hermit.\n\nDon't worry, the settings you have chosen will remain active even if you decide to hide the interface from the main station.",
		choices: options
	},
	function (choice) {
		if (choice === "1_YES" && !this.$configMain) {
			this.$configMain = true;
			delete missionVariables.asteroid_tweaks_config_main;
		}
		else if (choice === "2_NO" && this.$configMain){
			this.$configMain = false;
			missionVariables.asteroid_tweaks_config_main = 1;
			system.mainStation.setInterface("asteroid_tweaks",null);
		}
	});
}