Scripts/fuelStation_satellite.js |
"use strict";
this.name = "FuelSatellite";
this.author = "Thargoid";
this.copyright = "Creative Commons: attribution, non-commercial, sharealike with clauses - see readme.txt";
this.description = "Script for fuel satellite";
this.version = "2.3";
this.shipSpawned = function () { // line the station up with the route one. Code borrowed from Anarchies for convenience.
this.ship.scannerDisplayColor1 = "greenColor";
this.ship.scannerDisplayColor2 = "darkGrayColor";
if (system.isInterstellarSpace || !system.mainPlanet) { return; }
var targetVector = system.mainPlanet.position.subtract(this.ship.position).direction()
var angle = this.ship.heading.angleTo(targetVector)
var cross = this.ship.heading.cross(targetVector).direction()
this.ship.orientation = this.ship.orientation.rotate(cross, -angle);
// this.setColour();
this.setPrice();
this.maxAmount = worldScripts["FuelStation-Setup"].maxSatelliteAmount;
this.dispensed = 0;
}
//this.setColour = function()
// {
// this.colRand = system.scrambledPseudoRandomNumber(45.32)
// colName = "yellowColor";
// if(this.colRand < 0.25) { colName = "blueColor"; }
// if(this.colRand < 0.75) { colName = "redColor"; }
// if(this.colRand > 0.25 && this.colRand < 0.5) { colName = "magentaColor"; }
// this.ship.setMaterials({"fuelStation_satellite.png": { diffuse: colName }});
// }
this.setPrice = function () {
this.fuelPrice = 0.15 * EquipmentInfo.infoForKey("EQ_FUEL").price * player.ship.fuelChargeRate; // price per 0.1LY of fuel
if (system.economy === 0 || system.economy === 5) { this.fuelPrice *= 1.2; } // rich industrial or agricultural
if (system.techLevel > 4 && system.techLevel < 11) { this.fuelPrice *= 1.1; } // mid-tech level
this.fuelPrice = this.decPlaces(this.fuelPrice, 2);
}
this.decPlaces = function (number, places) {
if (!places || places < 0) { places = 0; }
if (!number) { return 0; }
return ((Math.round(number * Math.pow(10, places))) / Math.pow(10, places));
}
this.playerDetected = function () {
if (this.dispensed >= this.maxAmount) {
if (this.scanTimer && this.scanTimer.isRunning) this.scanTimer.stop();
return;
}
this.firstMessage = true;
this.secondMessage = true;
this.thirdMessage = true;
this.fuelTransferred = 0; // how many 0.1LY units are transferred
this.fuelBill = 0;
var msg = "Greetings Commander " + player.name + ". Refuel here for only " + this.decPlaces((10 * this.fuelPrice), 1) + " credits per ly.";
if (this.maxAmount < 7) {
msg += " Limit of " + this.maxAmount + "ly per ship.";
}
this.ship.commsMessage(msg, player.ship);
if (this.scanTimer) {
this.scanTimer.start();
} else {
this.scanTimer = new Timer(this, this.locatePlayer, 0, 0.50);
}
}
this.locatePlayer = function () {
if (!this.ship || !this.ship.isValid || !this.ship.position || !player.ship.isValid) { // if the ship no longer exists but timer is running, e.g. if player has jumped whilst near a satellite into a system without one
this.playerGone();
return;
}
if (this.ship.position.distanceTo(player.ship.position) < 150) { // player ship within 150m of the centre of the satellite
if (player.ship.fuel < 7 && this.dispensed < this.maxAmount) {
if (player.credits > this.fuelBill) { // player in place, fuel tank not full and credit balance not empty
player.ship.fuel += 0.1;
this.dispensed += 0.1;
this.fuelBill += this.fuelPrice;
this.fuelTransferred++;
if (this.firstMessage) {
player.consoleMessage("Fuel transfer is underway, please come to a halt.", 6);
this.firstMessage = false;
}
return;
} else { // not enough funds left
if (this.secondMessage) {
player.consoleMessage("Insufficient credits remaining for further transfer.", 6);
this.secondMessage = false;
}
return;
}
} else { // Fuel tank full or limit reached
if (player.ship.fuel < 7) {
if (this.thirdMessage) {
player.consoleMessage("Fuel transfer limit reached.", 6);
this.thirdMessage = false;
}
} else {
if (this.thirdMessage) {
player.consoleMessage("Fuel tanks are full.", 6);
this.thirdMessage = false;
}
}
return;
}
} else {
if (this.fuelTransferred > 0) {
this.fuelBill = this.decPlaces(this.fuelPrice * this.fuelTransferred, 1);
player.consoleMessage("Summary - " + (this.fuelTransferred / 10) + " ly transferred, " + this.fuelBill + " credits charged.", 6);
player.credits -= this.fuelBill;
this.fuelTransferred = 0;
this.fuelBill = 0;
this.firstMessage = true;
this.secondMessage = true;
this.thirdMessage = true;
if (this.maxAmount == 7) this.dispensed = 0;
}
}
}
this.playerWillEnterWitchspace = this.playerGone = function () {
if (this.scanTimer) {
this.scanTimer.stop();
delete this.scanTimer;
}
}
this.shipDied = function (whom, why) {
this.playerGone();
this.fuelCount = (Math.ceil(Math.random() * 30) + 30);
this.ship.spawn("fuelStation_burningFuel", this.fuelCount); // lets make this go with a bang!
if (whom && whom.isPlayer) {
player.consoleMessage("CCTV beam towards the main station detected.", 6);
player.score -= 1; // don't condone vandalism!
player.bounty += 20;
}
}
this.attackedMessage = function () {
this.ship.commsMessage("ALERT - fuel satellite under attack, explosion danger!");
}
|
Scripts/fuelStation_station.js |
"use strict";
this.name = "FuelStation";
this.author = "Thargoid";
this.copyright = "Creative Commons: attribution, non-commercial, sharealike with clauses - see readme.txt";
this.description = "Script for fuel station";
this.version = "2.3";
this.shipSpawned = function () {
this.ship.scannerDisplayColor1 = "greenColor";
this.ship.scannerDisplayColor2 = "lightGrayColor";
var traders = system.shipsWithPrimaryRole("trader", this.ship, 50E3)
if (traders.length > 0 && worldScripts["FuelStation-Setup"].extraB && traders[0].AIState == "HEAD_FOR_PLANET") {
traders[0].script.checkFuelStationDistance = this.checkFuelStationDistance; // attach function to script.
traders[0].script.checkUsage = this.checkUsage; // attach function to script.
traders[0].setAI("fuelStation_gotoFuelStationAI.plist");
}
// line the station up with the route one. Code borrowed from Anarchies for convenience.
if (system.isInterstellarSpace || !system.mainPlanet) { return; }
var targetVector = system.mainPlanet.position.subtract(this.ship.position).direction();
var angle = this.ship.heading.angleTo(targetVector);
var cross = this.ship.heading.cross(targetVector).direction();
this.ship.orientation = this.ship.orientation.rotate(cross, -angle);
// this.setColour();
this.setPrice();
this.maxAmount = worldScripts["FuelStation-Setup"].maxStationAmount;
this.dispensed = 0;
}
//this.setColour = function()
// {
// this.colRand = system.scrambledPseudoRandomNumber(45.32)
// colName = "yellowColor";
// if(this.colRand < 0.25) { colName = "blueColor"; }
// if(this.colRand < 0.75) { colName = "redColor"; }
// if(this.colRand > 0.25 && this.colRand < 0.5) { colName = "magentaColor"; }
// this.ship.setMaterials({"fuelStation_station.png": { diffuse: colName }});
// }
this.setPrice = function () {
this.fuelPrice = 0.15 * EquipmentInfo.infoForKey("EQ_FUEL").price * player.ship.fuelChargeRate; // price per 0.1LY of fuel
if (system.economy === 0 || system.economy === 5) { this.fuelPrice *= 1.2; } // rich industrial or agricultural
if (system.techLevel > 4 && system.techLevel < 11) { this.fuelPrice *= 1.1; } // mid-tech level
this.fuelPrice = this.decPlaces(this.fuelPrice, 2);
}
this.decPlaces = function (number, places) {
if (!places || places < 0) { places = 0; }
if (!number) { return 0; }
return ((Math.round(number * Math.pow(10, places))) / Math.pow(10, places));
}
this.playerDetected = function () {
if (this.dispensed >= this.maxAmount) {
if (this.scanTimer && this.scanTimer.isRunning) this.scanTimer.stop();
return;
}
this.firstMessage = true;
this.fuelTransferred = 0; // how many 0.1LY units are transferred
this.fuelBill = 0;
var msg = "Greetings Commander " + player.name + ". Refuel here for only " + this.decPlaces((10 * this.fuelPrice), 1) + " credits per ly.";
if (this.maxAmount < 7) {
msg += " Limit of " + this.maxAmount + "ly per ship.";
}
this.ship.commsMessage(msg, player.ship);
if (this.scanTimer) {
this.scanTimer.start();
} else {
this.scanTimer = new Timer(this, this.locatePlayer, 0, 0.50);
}
}
this.locatePlayer = function () {
if (!this.ship || !this.ship.isValid || !this.ship.position || !player.ship.isValid) { // if the ship no longer exists but timer is running, e.g. if player has jumped whilst near a satellite into a system without one
this.playerGone();
return;
}
if (this.ship.position.distanceTo(player.ship.position) < 150) { // player ship within 150m of the centre of the fuel station
if (player.ship.fuel < 7 && this.dispensed < this.maxAmount) {
if (player.credits > this.fuelBill) { // player in place, fuel tank not full and credit balance not empty
player.ship.fuel += 0.1;
this.dispensed += 0.1;
this.fuelBill += this.fuelPrice;
this.fuelTransferred++;
if (this.firstMessage) {
player.consoleMessage("Fuel transfer is underway, please come to a halt.", 6);
this.firstMessage = false;
}
return;
} else { // not enough funds left
player.consoleMessage("Insufficient credits remaining, transfer terminated.", 6);
this.scanTimer.stop();
return;
}
} else { // Fuel tank full or limit reached
if (player.ship.fuel < 7) {
if (this.thirdMessage) {
player.consoleMessage("Ship transfer limit reached.", 6);
}
} else {
if (this.thirdMessage) {
player.consoleMessage("Fuel tanks are full.", 6);
}
}
return;
}
}
}
this.shipTraversePositiveZ = this.shipTraverseNegativeZ = function (ship) {
if (ship.isPlayer) this.playerLeaving()
}
this.playerLeaving = function () {
this.fuelBill = this.decPlaces(this.fuelPrice * this.fuelTransferred, 1);
player.consoleMessage("Summary - " + (this.fuelTransferred / 10) + " ly transferred, " + this.fuelBill + " credits charged.", 6);
player.credits -= this.fuelBill;
this.fuelTransferred = 0;
this.fuelBill = 0;
this.firstMessage = true;
if (this.maxAmount == 7) this.dispensed = 0;
}
this.playerWillEnterWitchspace = this.playerGone = function () {
if (this.scanTimer) {
this.scanTimer.stop();
delete this.scanTimer;
}
}
this.shipDied = function (whom, why) {
this.playerGone();
this.fuelCount = (Math.ceil(Math.random() * 30) + 30);
this.ship.spawn("fuelStation_burningFuel", this.fuelCount); // lets make this go with a bang!
if (whom && whom.isPlayer) {
player.consoleMessage("CCTV beam towards the main station detected.", 6);
player.score -= 1; // don't condone vandalism!
player.bounty += 20;
}
}
// below not used by stationscript but is attached to traderscript.
this.checkFuelStationDistance = function () {
if (this.ship.position.distanceTo(this.ship.target.position) > 50E3) {
this.ship.reactToAIMessage("NEXT_FUELSTATION")
}
}
this.checkUsage = function () {
if (this.ship.target.position.distanceTo(player.ship.position) < 1000) {
this.ship.reactToAIMessage("NEXT_FUELSTATION")
} else {
this.ship.reactToAIMessage("STATION_CLEAR")
}
}
this.attackedMessage = function () {
this.ship.commsMessage("ALERT - fuel station under attack, explosion danger!");
}
this.collisionMessage = function () {
this.ship.commsMessage("ALERT - proximity detection, please take evasive action");
}
|
Scripts/fuelStation_stationSetup.js |
"use strict";
this.name = "FuelStation-Setup";
this.author = "Thargoid";
this.copyright = "Creative Commons: attribution, non-commercial, sharealike with clauses - see readme.txt";
this.description = "Script to add fuel station to certain systems";
this.version = "2.3";
this.extraA = true; // for use with turretted ships - set to false to only get fuel satellites
this.extraB = true; // if set to false, no NPCs will use the stations (if extraA is false, has no effect)
this.positionOverride = false; // set this to true to use alternative station positioning at far side of witchpoint only.
this.maxSatelliteAmount = 7; // change this to limit the amount of fuel a satellite can dispense
this.maxStationAmount = 7; // change this to limit the amount of fuel a station can dispense
this.halfwayChance = 0.25; // 3 in 4 chance to add a station at the half-way point of route 1.
this.witchpointChance = 0.33; // 2 in 3 chance to add a station near the witchpoint.
this.minGovernment = 2;
this.minTL = 4;
this.oxpcSettings = {
Info: { Name: this.name, Display: this.name, InfoB: "1 - If false only fuel satellites will appear.\n2 - If false NPCs will not use fuel stations (ignored if extraA is false)." },
Bool0: { Name: "extraA", Def: true, Desc: "Suppress fuel stations." },
Bool1: { Name: "extraB", Def: false, Desc: "Allow NPCs to use fuel stations." }
};
// configuration settings for use in Lib_Config
this._fsConfig = {
Name: this.name,
Alias: "Fuel Station",
Display: "General settings",
Alive: "_fsConfig",
Bool: {
B0: { Name: "extraA", Def: true, Desc: "Include fuel stations." },
B1: { Name: "extraB", Def: true, Desc: "Allow NPCs to use fuel stations." },
B2: { Name: "positionOverride", Def: false, Desc: "Use original positions"},
Info: "0 - If false only fuel satellites will appear." +
"\n1 - If false NPCs will not use fuel stations (ignored if extraA is false)." +
"\n2 - If true, use original station positioning at WP or mid-point."
},
SInt: {
S0: { Name: "maxSatelliteAmount", Def: 7, Min: 1, Max: 7, Desc: "Satellite max fuel" },
S1: { Name: "maxStationAmount", Def: 7, Min: 1, Max: 7, Desc: "Station max fuel" },
S2: { Name: "witchpointChance", Def: 0.33, Min: 0, Max: 1, Float: true, Desc: "Spawn chance at WP"},
S3: { Name: "halfwayChance", Def: 0.25, Min: 0, Max: 1, Float: true, Desc: "Spawn change midpoint"},
S4: { Name: "minGovernment", Def: 2, Min:0, Max: 7, Desc: "Min Government"},
S5: { Name: "minTL", Def: 4, Min:0, Max: 14, Desc: "Min TL"},
Info: "0: Maximum amount of fuel that can be dispensed per ship at a Fuel Satellite." +
"\n1: Maximum amount of fuel that can be dispensed per ship at a Fuel Station." +
"\n2: Chance of spawning at WP." +
"\n3: For original positions, chance of spawning at midpoint of WP-planet route." +
"\n4: Min government level required for fuel stations. 5: Min Techlevel required for fuel stations."
}
};
this.startUp = function() {
if (missionVariables.FuelStation_extraA) this.extraA = (missionVariables.FuelStation_extraA == "Y" ? true : false);
if (missionVariables.FuelStation_extraB) this.extraB = (missionVariables.FuelStation_extraB == "Y" ? true : false);
if (missionVariables.FuelStation_posOvr) this.positionOverride = (missionVariables.FuelStation_posOvr == "Y" ? true : false);
if (missionVariables.FuelStation_maxSatAmt) this.maxSatelliteAmount = parseInt(missionVariables.FuelStation_maxSatAmt);
if (missionVariables.FuelStation_maxStnAmt) this.maxStationAmount = parseInt(missionVariables.FuelStation_maxStnAmt);
if (missionVariables.FuelStation_WPChance) this.witchpointChance = parseFloat(missionVariables.FuelStation_WPChance);
if (missionVariables.FuelStation_MidChance) this.halfwayChance = parseFloat(missionVariables.FuelStation_MidChance);
if (missionVariables.FuelStation_MinGovernment) this.minGovernment = parseInt(missionVariables.FuelStation_MinGovernment);
if (missionVariables.FuelStation_MinTL) this.minTL = parseInt(missionVariables.FuelStation_MinTL);
}
this.startUpComplete = function () {
// register our settings, if Lib_Config is present
if (worldScripts.Lib_Config) {
worldScripts.Lib_Config._registerSet(this._fsConfig);
}
}
this.playerWillSaveGame = function() {
missionVariables.FuelStation_extraA = (this.extraA ? "Y" : "N");
missionVariables.FuelStation_extraB = (this.extraB ? "Y" : "N");
missionVariables.FuelStation_posOvr = (this.positionOverride ? "Y" : "N");
missionVariables.FuelStation_maxSatAmt = this.maxSatelliteAmount;
missionVariables.FuelStation_maxStnAmt = this.maxStationAmount;
missionVariables.FuelStation_WPChance = this.witchpointChance;
missionVariables.FuelStation_MidChance = this.halfwayChance;
missionVariables.FuelStation_MinGovernment = this.minGovernment;
missionVariables.FuelStation_MinTL = this.minTL;
}
this.systemWillPopulate = function() {
system.setPopulator("fuelstation", {
callback: function() {
var ws = worldScripts["FuelStation-Setup"];
if (ws.positionOverride === false) {
ws.originalStationSetup();
} else {
ws.witchpointStationSetup();
}
}.bind(this),
location: "WITCHPOINT",
});
}
this.witchpointStationSetup = function () { // fixed station position on far side of witchpoint area.
if (system.isInterstellarSpace || system.sun.isGoingNova || system.sun.hasGoneNova || missionVariables.longwayround === "STAGE1" || missionVariables.longwayround === "STAGE2") {
// stop the script if interstellar space, or system is going Nova(to allow Nova mission unhindered) or indeed if it has gone nova already.
return;
}
if (system.government >= this.minGovernment && system.techLevel >= this.minTL && system.countShipsWithRole("fuelStation_location") === 0) {
if (system.scrambledPseudoRandomNumber(13.7) > this.witchpointChance) {
if (this.extraA && system.scrambledPseudoRandomNumber(19.7) > 0.33) {
//system.legacy_addShipsAt("fuelStation_station", 1, "wpm", [0, 0, -24000]);
system.addShips("fuelStation_station", 1, Vector3D(0, 0, -24000).fromCoordinateSystem("wpm"));
} else {
//system.legacy_addShipsAt("fuelStation_satellite", 1, "wpm", [0, 0, -24000]);
system.addShips("fuelStation_satellite", 1, Vector3D(0, 0, -24000).fromCoordinateSystem("wpm"));
}
}
}
}
this.originalStationSetup = function () { // original locations, near witchpoint and on route 1.
if (system.isInterstellarSpace || system.sun.isGoingNova || system.sun.hasGoneNova) { // stop the script if interstellar space, or system is going Nova(to allow Nova mission unhindered) or indeed if it has gone nova already.
return;
}
var wp = this.witchpointChance;
var hw = this.halfwayChance;
if (missionVariables.longwayround === "STAGE1" || missionVariables.longwayround === "STAGE2") { // drastically reduce the chances if you're in the middle of Long Way Round mission
hw = 0.9; // 1 in 10 chance to add a station at the half-way point of route 1.
wp = 0.95; // 1 in 20 chance to add a station near the witchpoint.
}
if (system.government > 1 && system.techLevel > 3 && system.countShipsWithRole("fuelStation_location") === 0) {
if (system.scrambledPseudoRandomNumber(13.7) > wp) {
if (this.extraA && system.scrambledPseudoRandomNumber(17.4) > 0.33) {
//system.legacy_addShipsAt("fuelStation_station", 1, "pwu", [0.02, 0, 1]);
system.addShips("fuelStation_station", 1, Vector3D(0.02, 0, 1).fromCoordinateSystem("pwu"));
} else {
//system.legacy_addShipsAt("fuelStation_satellite", 1, "pwu", [0.02, 0, 1]);
system.addShips("fuelStation_satellite", 1, Vector3D(0.02, 0, 1).fromCoordinateSystem("pwu"));
}
}
if (system.scrambledPseudoRandomNumber(25.3) > hw) {
if (this.extraA && system.scrambledPseudoRandomNumber(24.1) > 0.33) {
//system.legacy_addShipsAt("fuelStation_station", 1, "pwu", [0.02, 0, 0.5]);
system.addShips("fuelStation_station", 1, Vector3D(0.02, 0, 0.5).fromCoordinateSystem("pwu"));
} else {
//system.legacy_addShipsAt("fuelStation_satellite", 1, "pwu", [0.02, 0, 0.5]);
system.addShips("fuelStation_satellite", 1, Vector3D(0.02, 0, 0.5).fromCoordinateSystem("pwu"));
}
}
}
} |