Part of the problem may lie in the function stacking your doing in this line:
Code:
this.startUpComplete = this.equipmentAdded = this.playerBoughtNewShip = function()
This code will run whenever you start up from a save game (as you've noted), and theoretically would run every time
any equipment is added, or whenever the player buys a new ship.
I think it would be better to do something like this:
Code:
this.startUpComplete = function()
{
this.$adjustSpeed();
}
this.equipmentAdded = function(equipmentKey)
{
log(this.name, "adding equipment " + equipmentKey);
if (equipmentKey == "EQ_TRANSIT_DEFAULT" || equipmentKey == "EQ_TRANSIT_GRADE" || equipmentKey == "EQ_PERFORMANCE_DEFAULT" || equipmentKey == "EQ_PERFORMANCE_GRADE")
this.$adjustSpeed();
}
this.playerBoughtNewShip = function(ship, price)
{
log(this.name, "new ship " + ship);
this.$adjustSpeed();
}
this.$adjustSpeed = function()
{
var p = player.ship;
var td = p.equipmentStatus("EQ_TRANSIT_DEFAULT");
var tg = p.equipmentStatus("EQ_TRANSIT_GRADE");
var pd = p.equipmentStatus("EQ_PERFORMANCE_DEFAULT");
var pg = p.equipmentStatus("EQ_PERFORMANCE_GRADE");
log(this.name, "transit def " + td + ", gde " + tg);
log(this.name, "perform def " + pd + ", gde " + pg);
log(this.name, "maxspeed pre = " + p.maxSpeed);
if(tg == "EQUIPMENT_OK" && td != "EQUIPMENT_OK" && pd != "EQUIPMENT_OK") {p.maxSpeed -= 50;}
if(pg == "EQUIPMENT_OK" && pd != "EQUIPMENT_OK" && td != "EQUIPMENT_OK") {p.maxSpeed += 50;}
if(tg == "EQUIPMENT_OK" && pd == "EQUIPMENT_OK") {p.maxSpeed -= 100;}
if(pg == "EQUIPMENT_OK" && td == "EQUIPMENT_OK") {p.maxSpeed += 100;}
log(this.name, "maxspeed post = " + p.maxSpeed);
}
This way you can see which of the events is not firing, plus the
equipmentAdded
function won't keep adjusting your speed when non-related equipment items are added.