Config/script.js |
"use strict";
this.name = "DeepSpaceDredgers_Facelift";
this.author = "phkb";
this.license = "CC-BY-NC-SA 3.0";
this.startUp = function () {
log(this.name, "Monkey-patching Deep Space Dredgers spawning routines");
var ws = worldScripts.deep_space_dredger;
delete ws.shipExitedWitchspace;
ws.addDredger = this.new_addDredger;
ws.systemWillPopulate = this.new_systemWillPopulate;
ws.isSystemAtWar = this.new_isSystemAtWar;
}
this.startUpComplete = function () {
// update Vimana-X with the changes to models
var vx = worldScripts.VimanaX_HUD;
if (vx) {
vx._gameShips["Dredger Shuttle"] = "orbital_shuttle";
vx._gameShips["Dredger Trader"] = "python_cruiser";
vx._gameShips["Sidewinder Fury"] = "sidewinder_escort";
}
}
this.new_addDredger = function () {
var orientation = player.ship.orientation;
var forwardPosition = player.ship.position.add(orientation.vectorForward().multiply(300E3));
var dr = system.addShips("dredgers", 1, forwardPosition, 1);
// only add the extra if we successfully spawned a dredger
if (dr && dr.length > 0 && Math.random() < 0.5) {
system.addShips("asteroid", Math.ceil(Math.random() * 3), forwardPosition, 10E3);
system.addShips("miner", Math.ceil(Math.random() * 3), forwardPosition, 10E3);
}
}
this.new_systemWillPopulate = function () {
if (this.salvageList) { delete this.salvageList; delete this.salvageNameList };
if (system.isInterstellarSpace || system.sun.hasGoneNova) return;
this.dredger = false;
if (system.techLevel > 8) {
if (Math.random() < 0.5) {
if (Math.random() < 0.2) {
system.addShipsToRoute("dredgertrader", 1, Math.random(), "pw");
}
this.dredger = true; // dredger can be added to this system.
} else {
if (Math.random() < 0.05 && !worldScripts["bigShips_populator"]) {
system.addShipsToRoute("dredgers", 1, Math.random() * 0.5, "pw");
}
}
}
if (player.ship.isInSpace && (system.description.indexOf("civil war") != -1 || this.isSystemAtWar()) && system.government < Math.random() * 7) { // more chance in "civil war" systems
if (Math.random() < 0.1) this.addDerelict(0.1 + Math.random() * 0.8, 1);
if (Math.random() < 0.02) {
var location = Math.ceil(Math.random() * 5);
this._msgkey = "";
switch (location) {
case 1:
this.addDerelict(0.97, 5); // 20%
this._msgkey = "salvage_drone_battle_station";
break;
case 5:
this.addDerelict(0, 5); // 20%
this._msgkey = "salvage_drone_battle_witchpoint";
break;
default:
this.addDerelict(0.2 + Math.random() * 0.7, 5); // 60%
this._msgkey = "salvage_drone_battle_spacelane";
break;
}
this._msgTimer = new Timer(this, function(){var wpb = system.shipsWithRole("buoy-witchpoint")[0]; if (wpb) wpb.commsMessage(expandDescription("[" + worldScripts.deep_space_dredger._msgkey + "]"), player.ship);}, 3, 0);
this.dredger = true;
}
}
}
this.new_isSystemAtWar = function() {
var de = worldScripts.DayDiplomacy_010_Systems;
if (!de) return false;
var we = worldScripts.DayDiplomacy_040_WarEngine;
var id = de.$retrieveActorFromSystem(galaxyNumber, system.ID).id;
var warlist = we.$getAlliancesAndWars()[id];
return (Object.keys(warlist).length > 0);
} |