Scripts/docking_fee.js |
// oolite.oxp.Layne.DockingFees
"use strict";
this.name = "Docking Fees";
this.license = "CC BY-NC-SA 4.0";
this._simulator = false; // holding variable to work out whether this launch/dock routine was part of a simulator run
this._escapepod = false;
this._fees = {};
//-------------------------------------------------------------------------------------------------------------
this.startUpComplete = function () {
this.$addCoreFees();
}
//-------------------------------------------------------------------------------------------------------------
this.shipLaunchedEscapePod = function (escapepod, passengers) {
this._escapepod = true;
}
//-------------------------------------------------------------------------------------------------------------
this.shipDockedWithStation = function (station) {
// if this was a simulator run, reset the variable and return - no docking fee in this case
if (this._simulator == true) {
this._simulator = false;
return;
}
// is this a redock after an escape pod
if (this._escapepod == true) {
this._escapepod = false;
return;
}
// work out fee based on system tech level and station type
var f = ((system.techLevel * 0.5) + 0.5);
var fee = 0;
var messageKey = ""; //no message by default
var message = "";
// add the current system techlevel, gov and eco to mission variables so they can be referenced by descriptions
missionVariables.systemTechLevel = system.techLevel;
missionVariables.systemGovernment = system.government;
missionVariables.systemEconomy = system.economy;
if (station.isMainStation) { // main system stations for GalCop
var def = this._fees["_default"];
fee = (def.hasOwnProperty("fee") ? def.fee : (def.hasOwnProperty("multiplier") ? f * def.multiplier : 0));
// make sure the "messageKey" value is the same as what you used in the descriptions.plist file
messageKey = expandDescription(def.messageKey);
message = def.message;
}
var roles = Object.keys(this._fees);
for (var i = 0; i < roles.length; i++) {
if (station.hasRole(roles[i])) {
var chk = this._fees[roles[i]];
fee = (chk.hasOwnProperty("fee") ? chk.fee : (chk.hasOwnProperty("multiplier") ? f * chk.multiplier : 0));
messageKey = expandDescription(chk.messageKey);
message = chk.message;
}
}
if (fee > 0) { // ignore any station not specifically assigned a fee or message
if (player.credits > fee) { // make sure the player has enough credits
player.credits -= fee;
} else {
player.addMessageToArrivalReport("Welcome Commander! You seem to be down on your luck, so we've waived the docking fee this time. You can work it off washing dishes in the station commissary!");
this.$cleanUp();
// don't try to send any other message
return;
}
}
// display the docking message
if (messageKey != "" || message != "") {
if (messageKey != "") {
player.addMessageToArrivalReport(expandDescription("[" + messageKey + "]", {
fee_amt: formatCredits(fee, true, true),
st_name: station.displayName
}));
} else {
player.addMessageToArrivalReport(expandDescription(messageKey, {
fee_amt: formatCredits(fee, true, true),
st_name: station.displayName
}));
}
}
this.$cleanUp();
}
//-------------------------------------------------------------------------------------------------------------
this.$cleanUp = function() {
delete missionVariables.systemTechLevel;
delete missionVariables.systemGovernment;
delete missionVariables.systemEconomy;
}
//-------------------------------------------------------------------------------------------------------------
// check when the player launches if this is a simulator run
this.shipLaunchedFromStation = function (station) {
if (this.$simulatorRunning()) this._simulator = true;
}
//-------------------------------------------------------------------------------------------------------------
// routine to check the combat simulator worldscript, to see if it's running or not
this.$simulatorRunning = function () {
var w = worldScripts["Combat Simulator"];
if (w && w.$checkFight && w.$checkFight.isRunning) return true;
return false;
}
//-------------------------------------------------------------------------------------------------------------
// adds a fee object to the dictionary
// role: the station role to be checked for
// obj is a dictionary with the following options:
// fee: a simple value to be used for the fee (eg 20) which overrides the default calc
// multiplier: a multiplier to be applied to the default fee calculation (eg 1.5)
// messageKey: the key from descriptions.plist that holds the docking message to be added to the arrival report (eg "my_dock_message")
// message: the docking message to be added to the arrival report (eg "Welcome to my station, commander!")
// note: if both messageKey and message are defined, the messageKey will take priority
// note: if no fee or multiplier are specified, but the message keys are defined and not blank, the multiplier will be set to 1,
// which applies a normal fee calculation.
// note: descriptions can include [fee_amt] and [st_name], which will be expanded to be the fee amount and the station name respectively.
// note: to have a station ignored, just specify a blank message. For example: $addFee("my_station_role", {message:""});
this.$addFee = function (role, obj) {
var newfee = {};
if (obj.hasOwnProperty("fee")) {
newfee.fee = obj.fee;
}
if (obj.hasOwnProperty("multiplier")) {
newfee.multiplier = obj.multiplier;
}
if (obj.hasOwnProperty("messageKey")) {
newfee.messageKey = obj.messageKey;
} else {
newfee.messageKey = "";
}
if (obj.hasOwnProperty("message")) {
newfee.message = obj.message;
} else {
newfee.message = "";
}
if ((!newfee.hasOwnProperty("fee") || newfee.fee == 0) && (!newfee.hasOwnProperty("multiplier") || newfee.multiplier == 0) && (newfee.messageKey != "" || newfee.message != "")) {
newfee.multiplier = 1;
}
this._fees[role] = newfee;
}
//-------------------------------------------------------------------------------------------------------------
this.$addCoreFees = function () {
this.$addFee("_default", {messageKey: "dockfee_[mission_systemTechLevel]"}); // default for main stations
this.$addFee("rockhermit", {fee: 0, messageKey: "dockfee_rock"}); // rockhermits are free, must be before astromine
this.$addFee("sfep_station", {multiplier: 0.5, messageKey: "dockfee_[mission_systemTechLevel]"}); // stations for extra planets are cheaper to visit than main station
this.$addFee("constore", {fee: 0, messageKey: "dockfee_store"}); // con stores are free for encouraging customers
this.$addFee("smivs_pizza_giftshop", {messageKey: ""}); // space-pizza charges a fee of its own, so no dock message
this.$addFee("oolite-tutorial-station", {messageKey: ""}); // the training station in the tutorial; no fee or message
this.$addFee("rrs-plague-mine", {messageKey: ""}); // plague mine, free docking for medical couriers
this.$addFee("random_hits_any_spacebar", {multiplier: 1.5, messageKey: "dockfee_spacebar"}); // space bars are a little bit more expensive
this.$addFee("rrs_group_spacestation", {fee: 0, messageKey: "dockfee_RRS"}); // rescue stations are free
this.$addFee("casinoship", {multiplier: 2, messageKey: "dockfee_hoopy"}); // casinos are a bit more expensive
this.$addFee("wildShips_kiota", {multiplier: 1.3, messageKey: "dockfee_kiota"}); // kiota ships are a little bit more expensive
this.$addFee("rrs-mining-outpost", {fee: 0, messageKey: "dockfee_mining"}); // mining outposts are free
this.$addFee("free_trade_zone", {fee: 0, messageKey: "dockfee_FTZ"}); // free trade zones charge huge fuel prices in lieu of fee
this.$addFee("astromine", {fee: 20, messageKey: "dockfee_astromine"}); // penal colonies require a fair bribe to enter
this.$addFee("comczgf", {multiplier: 2.5, messageKey: "dockfee_ZGF"}); // Zero-G-Factories require a small bribe to enter
this.$addFee("comslapu", {multiplier: 2.5, messageKey: "dockfee_SLAPU"}); // SLAPU collectives require a small bribe to enter
this.$addFee("astrofactory", {multiplier: 2, messageKey: "dockfee_astrofactory"}); // imperial factories require a small bribe to enter
this.$addFee("laveAcademy_academy", {fee: 0, messageKey: "dockfee_laveacademy"}); // Lave Academy is free as a public service
this.$addFee("anarchies_sentinel_station", {fee: 0, messageKey: "dockfee_secom"}); // Sentinel Stations are free naval bases
this.$addFee("anarchies_renegade_station", {messageKey: ""}); // renegade stations have their own penalties for docking
this.$addFee("anarchies_hacker_outpost", {fee: 0, messageKey: "dockfee_hackers"}); // if you can find them, hacker outposts are free
this.$addFee("anarchies_salvage_gang", {multiplier: 2, messageKey: "dockfee_salvager"}); // salvage gangs need a bribe to grease the wheels
this.$addFee("navystat", {fee: 0, messageKey: "dockfee_secom"}); // navy stations are free (your tax dollars at work)
this.$addFee("behemoth", {fee: 0, messageKey: "dockfee_behemoth"}); // behemoths are free
this.$addFee("liners_liner", {fee: 0, messageKey: "dockfee_liner"}); // passenger liners are free
this.$addFee("feudal-hunting-lodge", {fee: 0, messageKey: "dockfee_hunting"}); // royal lodges are free
this.$addFee("planetFall_surface", {multiplier: 1.2, messageKey: "dockfee_planet"}); // planets are slightly more to discourage spacers
this.$addFee("monkbranch", {fee: 0, messageKey: "dockfee_monks"}); // black monk monasteries are free
this.$addFee("blackmonk_monastery", {fee: 0, messageKey: "dockfee_monks"});
this.$addFee("taxi_station", {multiplier: 0.5, messageKey: "dockfee_taxi"}); // taxi stations just charge for the parking
this.$addFee("aquatics_HQ", {fee: 0, messageKey: "dockfee_aquatica"}); //Aquatics Shipyards are free to dock with
this.$addFee("GRS-Station", {fee: 0, messageKey: "dockfee_buoystat"}); //BuoyRepair HQ is free to dock with
this.$addFee("pagroove_superhub", {multiplier: 2, messageKey: "dockfee_suphub"}); //Superhubs are expensive to dock with
this.$addFee("toriA", {multiplier: 1.2, messageKey: "dockfee_[mission_systemTechLevel]"}); //Torus station cost more than standard GalCop stations
this.$addFee("toriB", {multiplier: 1.2, messageKey: "dockfee_[mission_systemTechLevel]"}); //Torus station cost more than standard GalCop stations
this.$addFee("dredgers", {fee: 0, messageKey: "dockfee_dredgj"}); //Deep Space Dredger are free to dock with, if you can find one
this.$addFee("globestation", {multiplier: 1.5, messageKey: "dockfee_[mission_systemTechLevel]"}); //Globe stations are more expensive to dock with
this.$addFee("globestationxl", {multiplier: 1.5, messageKey: "dockfee_[mission_systemTechLevel]"}); //Globe stations are more expensive to dock with
this.$addFee("tgy_station", {messageKey: "dockfee_togy"}); // tionisla orbital graveyard
this.$addFee("togy_station", {messageKey: "dockfee_togy"}); // tionisla orbital graveyard
this.$addFee("baakili-fartrader", {multiplier: 0.5, messageKey: "dockfee_short"}); //Baakili Far Trader
this.$addFee("bh01", {multiplier: 0.5, messageKey: "dockfee_short"}); //Bulk Haulers
this.$addFee("broadcast_array", {messageKey: ""}); //Tionisla Chronicle Array - ignore
this.$addFee("cb68_sodalite_station-riredi-coluber", {messageKey: "dockfee_short"}); //Riredi
this.$addFee("draven_c", {messageKey: "dockfee_short"}); //Draven Carrier
this.$addFee("draven_st", {messageKey: "dockfee_short"}); //Draven Oodulldoff Station
this.$addFee("habmk2", {messageKey: "dockfee_short"}); //Zieman's Habitat Station
this.$addFee("kihq", {messageKey: "dockfee_short"}); //Koneko Industries OXP
this.$addFee("mandotech-main-station", {messageKey: "dockfee_short"}); //MandotechStation Shipyard
this.$addFee("medusa", {messageKey: "dockfee_short"}); //Nuit Space Station OXP
this.$addFee("PAGroove-Orisis", {messageKey: "dockfee_short"}); //Orisis
this.$addFee("ryan_villa", {fee: 0, messageKey: ""}); //Ryan's Villa - ignore
this.$addFee("SIRF-YARD", {messageKey: "dockfee_short"}); //S.I.R.F.
this.$addFee("sothis", {messageKey: "dockfee_short"}); //SothisTC
this.$addFee("taranis", {messageKey: "dockfee_short"}); //Taranis
this.$addFee("tianve-pulsar-station", {messageKey: "dockfee_short"}); //Tianve and Navy Station
this.$addFee("transhabstation", {messageKey: "dockfee_short"}); //Transhab station
}
|