There are all sorts of spawn methods in Oolite. Most of them are for backward compatibility though. The preferred methods are
addShips/addGroup
and
addShipsToRoute/addGroupToRoute
. Since we are just adding one object to a fixed position and not dealing with groups we'll be using
addShips
.
Spawning is possible at any time, but stations especially are preferred to be spawned using a populator as part of the system population. If you think of the game as a theater, the population step is setting the stage ready.
With regards to the Sothis, which is an old OXP and for which we are using an overriding method, two things are needed:
- suppress the original (and deprecated) spawning functionality.
- reintroduce the spawning functionality by using populator.
1. Suppressing the original spawning functionality
Look at the script.js inside the original Sothis. The method
this.shipWillExitWitchSpace
handles spawning and need to be dealt with. The whole method can be deleted from the script of course, but if we want to keep the original intact for licensing issues or what ever, then we need to nullify the function in an overriding oxp.
Let's nullify. Look at the sothis_tc.js inside SothisTC. In
this.startUp
you see this:
Code: Select all
if(!worldScripts["Spawn-sothis"]) { //check for sothis station oxp
delete this.shipWillExitWitchspace;
delete this.$addSothis;
delete this.shipDockedWithStation;
delete this.playerBoughtEquipment;
delete this.shipLaunchedFromStation;
player.consoleMessage("Sothis OXP is not installed, exiting SothisTC.", 5);
log("SothisTC","Sothis OXP is not installed, exiting SothisTC.");
}
else {
delete worldScripts["Spawn-sothis"].shipWillExitWitchspace;
this.$addSothis();
}
It checks for the presence of Sothis oxp by looking for it's world script and acts accordingly. If Sothis oxp is not present the functionality of SothisTC is effectively neutered. If Sothis oxp is present, then
this.shipWillExitWitchSpace
method is deleted from from memory to prevent it from spawning the station. This is done in
startUp
step which happens before anything else happens.
SothisTC also uses the same deprecated method for adding stations. The trigger for spawning is
this.shipWillExitWitchspace
and the actual spawning logic is in
this.$addSothis
. Lucky us, the spawning logic works just fine, so we can easily modify it to use populator. You can also find a call to
this.$addSothis
from startUp. That's there because one might save/reload at the main station and in that case
shipWillExitWitchspace
will not happen and the station would not be there. This is an old school thingy, so remove that call from the else clause.
2. Modify the the spawning functionality to use populator
Populators are executed when the system is to be populated. Before that happens,
systemWillPopulate
will trigger to set the populators.
Change
this.shipWillExitWitchspace
to
this.systemWillPopulate
to move the spawning functionality to a correct step. Do this change also to the neutering part to prevent script errors.
The only thing we need to change in
this.$addSothis
is replace "
system.addShips("sothis", 1, [x, y, z]);
" with a proper populator:
Code: Select all
var exactPosition = [x, y, z];
system.setPopulator("sothis_tc", {
callback: function(pos) {
system.addShips("sothis", 1, pos, 0);
}.bind(this),
location: "COORDINATES",
coordinates: exactPosition,
deterministic: true
})
Shift-start the game, load your save game, lauch, and see if Sothis is there or not. It's also a good idea to look at the Latest.log if there's something funky there. If all goes well you should now be able to save at the station.
The positioning of the station is currently a bit complicated geometry-wise. To make changes to the positioning requires a bit understanding on the coordinate system used by oolite and some vector calculus. If you just want to push the station farther from the planet, adding a >1 multiplier to the c variable probably does the trick. If you want to do something more ambitious, then we need to have a short lesson on Oolite coordinate system and vectors.