Station spawning oxps...
Posted: Mon Nov 22, 2010 9:11 pm
Since I recently installed the Sothis and Wasps oxps, I've been paying a bit more attention to which extra stations are loaded.
Superhubv1.2, Sothis and Wasps oxps all are inconsistent.
With Superhub, they sometimes appear within a particular system, sometimes they don't. With the other two, they will always appear within the particular system, unless the game is reloaded whilst in the system (ie you restore from a saved game), when they don't.
What I would like is for them all to have a set of systems for which they appear, and for them to do this consistently.
So, I've been looking through the spawning scripts, and I think that I can get the behaviour I want by using functions from both.
Having recently become acquainted with the Oolite Javascript Reference wiki pages, the best way to get consistent random behaviour in a system is to use the pseudoRandomNumber method.
Both of Killer Wolf's oxps (namely the Sothis and Wasps) make use of Ahruman's scrambling method, which takes a seed value to give a different output:
However, they both use the same "salt" value of 10. Wasps spawns if the output is less than 0.5; Sothis when the output is less than 0.666. Therefore whenever there is a Sothis, there is always a wasps' nest. They are also only spawned upon the shipWillExitWitchspace method. This is why they won't appear when you reload a game in a system that previously contained them. It also explains why whenever I mis-jump, I end up with both the stations stuck together (mentioned recently here) - I assume that the generated value for interstellar space is less than 0.5.
Superhub, on the other hand, goes about things a slightly different way:
This script covers the fact that stations need to be added when one leaves the main station, but no more than once, and also checks this by using the variable this.superHubBlock. However, the fact that this uses Math.random() as a generating condition, rather than the pseudoRandomNumber method, means that the behaviour is not consistent.
Now, if I combine the two ways of doing things, by replacing Math.random() with the pseudoRandomNumber in the Superhub script, and adding the shipWillLaunchFromStation() event and similar checks to the KW scripts, whilst changing the "salt" values (and possibly the probablilties as well), I hope to get consistent behaviour from these things, and if I'm successful, I'll probably write myself a similar script for KW's Nuit station as well (as it only has a test spawning script that spawns upon every launch from the station!).
Does this make sense to people? Or am I insane and there are added complications that I haven't thought of/seen (though I'll probably find them in the middle of scripting if there are...)?
Superhubv1.2, Sothis and Wasps oxps all are inconsistent.
With Superhub, they sometimes appear within a particular system, sometimes they don't. With the other two, they will always appear within the particular system, unless the game is reloaded whilst in the system (ie you restore from a saved game), when they don't.
What I would like is for them all to have a set of systems for which they appear, and for them to do this consistently.
So, I've been looking through the spawning scripts, and I think that I can get the behaviour I want by using functions from both.
Having recently become acquainted with the Oolite Javascript Reference wiki pages, the best way to get consistent random behaviour in a system is to use the pseudoRandomNumber method.
Both of Killer Wolf's oxps (namely the Sothis and Wasps) make use of Ahruman's scrambling method, which takes a seed value to give a different output:
Code: Select all
this.scrambledPseudoRandom = function(salt)
{
// Convert from float in [0..1) with 24 bits of precision to integer.
var n = Math.floor(system.pseudoRandomNumber * 16777216.0);
// Add salt to enable generation of different sequences.
n += salt;
// Scramble with basic LCG psuedo-random number generator.
n = (214013 * n + 2531011) & 0xFFFFFFFF;
n = (214013 * n + 2531011) & 0xFFFFFFFF;
n = (214013 * n + 2531011) & 0xFFFFFFFF;
// Convert from (effectively) 32-bit signed integer to float in [0..1).
return n / 4294967296.0 + 0.5;
}
Superhub, on the other hand, goes about things a slightly different way:
Code: Select all
this.name = "PAGroove_superhubPopulator";
this.author = "Thargoid";
this.copyright = "This script is hereby placed in the public domain.";
this.version = "1.1";
this.description = "Script to add a single superhub near the system main station";
this.shipWillLaunchFromStation = function(station)
{
if(station.isMainStation)
{
this.spawnHub();
}
}
this.shipWillExitWitchspace = function()
{
this.spawnHub();
}
this.spawnHub = function()
{
if(Math.random() < 0.5 || system.techLevel < 11 || system.government < 4 || system.countShipsWithRole("pagroove_superhub") > 0 || this.superHubBlock)
{
this.superHubBlock = true;
return;
}
else
{
this.xOffset = (Math.random() * 10000) + 10000; // x offset between 10 and 20km
this.yOffset = (Math.random() * 10000) + 10000; // y offset between 10 and 20km
if(Math.random() > 0.5) // 50:50 chance of offsetting in the other direction
{
this.xOffset = -this.xOffset;
}
if(Math.random() > 0.5) // 50:50 chance of offsetting in the other direction
{
this.yOffset = -this.yOffset;
}
system.legacy_addShipsAtPrecisely("pagroove_superhub", 1, "abs", system.mainStation.position.add([this.xOffset, this.yOffset, 0]));
}
}
this.shipWillEnterWitchspace = function()
{
this.superHubBlock = null;
}
Now, if I combine the two ways of doing things, by replacing Math.random() with the pseudoRandomNumber in the Superhub script, and adding the shipWillLaunchFromStation() event and similar checks to the KW scripts, whilst changing the "salt" values (and possibly the probablilties as well), I hope to get consistent behaviour from these things, and if I'm successful, I'll probably write myself a similar script for KW's Nuit station as well (as it only has a test spawning script that spawns upon every launch from the station!).
Does this make sense to people? Or am I insane and there are added complications that I haven't thought of/seen (though I'll probably find them in the middle of scripting if there are...)?