Scripts/convoys.js |
"use strict";
this.name = "convoys";
this.author = "Norby";
this.copyright = "2017 Norby";
this.description= "Convoys worldscript";
this.licence = "CC BY-NC-SA 4.0";
//this function is almost a copy from Escort Formations OXP but handle the new roles added in Oolite 1.79.
this.shipSpawned = function(ship) {
if (!ship.script) return; // odd, but seems to happen occasionally
if (ship.script.coordinatesForEscortPosition != Script.prototype.coordinatesForEscortPosition) {
//this.$debug(ship.displayName+" has escort coordinates already");
return;
} // already has some custom coordinates
if (ship.script.$efr_pattern) {
//this.$debug(ship.displayName+" has $efr_pattern already");
return;
} // variable name conflict
if (ship.script.$efr_timer) {
//this.$debug(ship.displayName+" has $efr_pattern already");
return;
} // variable name conflict
var offensiveChance = 0, r = ship.primaryRole;
if ( r == "miner" || r == "scavenger" || r == "shuttle" ) {
offensiveChance = 0;
} else if ( r == "escort" || r == "escort-medium" || r == "escort-heavy" ) {
offensiveChance = 0;
} else if ( r == "trader" || r == "trader-courier" || r == "trader-smuggler" ) {
offensiveChance = 0.15;
} else if (r == "pirate" || r == "pirate-light-fighter" || r == "pirate-medium-fighter"
|| r == "pirate-heavy-fighter" || r == "pirate-light-freighter"
|| r == "pirate-medium-freighter" || r == "pirate-heavy-freighter"
|| r == "pirate-aegis-raider" || r == "pirate-interceptor" ) {
offensiveChance = 0.75;
} else if (r == "police" || r == "interceptor" || r == "wingman" ) {
offensiveChance = 0.9;
} else if (r == "hunter" || r == "hunter-medium" || r == "hunter-heavy" ) {
offensiveChance = 0.9;
} else if (r == "assassin-light" || r == "assassin-medium" || r == "assassin-heavy") {
offensiveChance = 1;
} else if (r == "thargoid") {
offensiveChance = 1;
} else {
//this.$debug(ship.displayName+" has no included role");
return; // stock ships only
}
if (Math.random() < 0.10) {
//this.$debug("No escort change for "+ship.displayName);
return;
} // keep default formation
// timer to allow escorts to be set up too
if (Math.random() < offensiveChance) {
ship.script.$efr_timer = new Timer(ship,function() {
worldScripts["Escort Formations Randomiser"].$setupOffensiveEscorts(ship); },0.25);
} else {
ship.script.$efr_timer = new Timer(ship,function() {
worldScripts["Escort Formations Randomiser"].$setupDefensiveEscorts(ship); },0.25);
}
}
this.$debug = function(msg) {
log(this.name,msg);
}
|