To come to the conclusions bellow, I put traces in oolite-equipment-control, like this:
Code: Select all
this.equipmentAdded = function(equip)
{
log(this.name,"equipmentAdded "+equip);
if (!this.$started)
{
return;
}
if (!this.$equipmentEnabled[equip])
{
if (this.$equipmentEnable[equip])
{
var info = EquipmentInfo.infoForKey(equip);
// log(this.name,"Enabling "+info.equipmentKey); //tmp - remove later
var result = this.$equipmentEnable[equip].bind(this,info)();
if (result == -1)
{
return;
}
}
}
var eq_dict = this.$equipmentEnabled;
var eqInfo;
for (var eqKey in eq_dict) {
eqInfo = EquipmentInfo.infoForKey(eqKey);
if (eqInfo && eqInfo.incompatibleEquipment && eqInfo.incompatibleEquipment.indexOf(equip) >= 0) {
player.ship.removeEquipment(eqKey);
}
}
this.$equipmentEnabled[equip] = 1;
log(this.name,"equipment Added "+equip);
};
this.$equipmentEnable["EQ_SHIELD_BOOSTER"] = this.$equipmentEnable["EQ_NAVAL_SHIELD_BOOSTER"] = function(info)
{
player.ship.maxForwardShield += parseFloat(info.scriptInfo.oolite_shield_increase);
player.ship.maxAftShield += parseFloat(info.scriptInfo.oolite_shield_increase);
player.ship.forwardShieldRechargeRate *= parseFloat(info.scriptInfo.oolite_shield_recharge_multiplier);
player.ship.aftShieldRechargeRate *= parseFloat(info.scriptInfo.oolite_shield_recharge_multiplier);
if (player.ship.docked)
{
player.ship.aftShield = player.ship.maxAftShield;
player.ship.forwardShield = player.ship.maxForwardShield;
}
log(this.name, "Enabled "+info.name+", maxShield: "+player.ship.maxForwardShield+"/"+player.ship.maxAftShield+", shieldRecharge: "+player.ship.forwardShieldRechargeRate+"/"+player.ship.aftShieldRechargeRate);
};
Then comes the world script startUp event, and Oolite Equipment Control's calls its playerBoughNewShip function, that sets its this.$started to true and calls its equipmentAdded function to all installed equipments - then, if Shield Booster is installed, maxShield will go from 128 to 256.
This is the normal and expected behaviour, so far so good!
When player.replaceShip is called, the whole process is repeated, BUT now Oolite Equipment Control's this.$started is true, so the call to its equipmentAdded event handler doesn't return at the begin, but goes on to call its equipmentEnable, and that first pass will change maxShield from 128 to 256 if there's a Shield Booster installed... afterwards, when playerBoughtNewShip function is called, Oolite Equipment Control's will again call its equipmentEnable for all equipments installed, and that Shield Booster will get maxShield from 256 to 384!
Try player.replaceShip("ferdelance-player") on DebugConsole to reproduce it.
So I would suggest adding to oolite-equipment-control.js:
Code: Select all
this.playerWIllReplaceShip = function() {
this.$started = false;
}