I have a Boa with a bunch of escort ships in the list. The Boa launches and heads off (via the "
launchShipWithRole
" function), I add it to a new group and assign it as the leader. Then, as each escort is created with the "
launchShipWithRole
" function, I start adding things to it: I switch the AI to an escort, I add the ship to the Boa's group and do "s
hip.offerToEscort(leaderShip);
" followed by "
ship.performEscort();
" and finally, just to make sure, "
leaderShip.updateEscortFormation();
". What I expect to see when I watch this happen outside the station is for the Boa to head off in one direction (without music), and for each escort ship to head off in the same direction, following the leader. But what I see is the Boa launch, head off, and then each escort launches and heads in a completely different directions. They all seem to be completely aimless until the Boa enters a wormhole, whereupon they all make a bee line for it.
I can confirm each of the escorts is part of the group, with the Boa as the leader. But I can't work out why their behaviour on launch is different to what happens with the standard process. Any ideas?
Here's the (almost) complete code for launching the leader:
Code: Select all
var ship = station.launchShipWithRole("[" + shipData.shipDataKey + "]");
// push all the stored data onto the ship;
if (oolite.compareVersion("1.80") < 0) {
ship.entityPersonality = shipData.personality; // can only do this in Oolite 1.81 or greater
}
ship.primaryRole = shipData.primaryRole; // shipData.primaryRole equals "trader" at this point
ship.accuracy = shipData.accuracy;
ship.heatInsulation = shipData.heatInsulation;
ship.setBounty(shipData.bounty, "setup actions");
ship.shipUniqueName = shipData.shipName;
ship.homeSystem = shipData.homeSystem;
ship.destinationSystem = shipData.destinationSystem;
ship.fuel = shipData.fuel;
var seed = "0 0 0 0 " + shipData.pilotHomeSystem.toString() + " 2";
if (shipData.goods != "") {
// put some cargo in the hold
ship.setCargoType(shipData.goods);
}
if (shipData.equipment != "") {
// process all the equipment additions
...snip...
}
// set the ai of the ship (if required)
if (shipData.shipAI != "") ship.switchAI(shipData.shipAI); // shipData.shipAI equals "oolite-traderAI.js" at this point
// create a group with the ship as the leader
var stdGroup = new ShipGroup(shipData.groupName, ship);
ship.group = stdGroup;
// put the group into a holding array so we can easily find it later for any escort members
this._launchingGroups.push(stdGroup);
And here's the equivalent code for launching the escorts
Code: Select all
var ship = station.launchShipWithRole("[" + shipData.shipDataKey + "]");
// push all the stored data onto the ship;
if (oolite.compareVersion("1.80") < 0) {
ship.entityPersonality = shipData.personality; // can only do this in Oolite 1.81 or greater
}
ship.primaryRole = shipData.primaryRole; // shipData.primaryRole will equal one of these: escort, escort-heavy, escort-medium
ship.accuracy = shipData.accuracy;
ship.heatInsulation = shipData.heatInsulation;
ship.setBounty(shipData.bounty, "setup actions");
ship.shipUniqueName = shipData.shipName;
ship.homeSystem = shipData.homeSystem;
ship.destinationSystem = shipData.destinationSystem;
ship.fuel = shipData.fuel;
var seed = "0 0 0 0 " + shipData.pilotHomeSystem.toString() + " 2";
if (shipData.goods != "") {
// put some cargo in the hold
ship.setCargoType(shipData.goods);
}
if (shipData.equipment != "") {
// process all the equipment additions
...snip...
}
// set the ai of the ship (if required)
if (shipData.shipAI != "") ship.switchAI(shipData.shipAI); // shipData.shipAI equals "oolite-escortAI.js" at this point
// is this ship part of a group
var groupName = shipData.groupName;
var stdGroup = null;
// look for an existing group
if (this._launchingGroups.length > 0) {
for (var j = 0; j < this._launchingGroups.length; j++) {
if (this._launchingGroups[j].name == groupName) {
stdGroup = this._launchingGroups[j];
break;
}
}
}
// if we found an escort group, just add the ship
ship.group = stdGroup;
stdGroup.addShip(ship);
ship.offerToEscort(stdGroup.leader);
stdGroup.leader.updateEscortFormation();
ship.performEscort();