Scripts/cargoDelivery.js |
"use strict";
this.name = "In-System Cargo Delivery";
this.author = "Stranger";
this.copyright = "Creative Commons: attribution, non-commercial, sharealike with clauses - see readme.txt";
this.description = "In-System cargo delivery";
this.version = "0.6.0";
this.$planetInfo = new Array();
this.$planetFlag = new Array();
// No active mission
this.$missionRefuse = "It would seem that you are taking this mission just as outing.\n Really, you'd better prepare for this sort of activity. Ship with planet landing capability and 5 tons of available cargo space at least. And free 250 credits for insurance fee of course.\n Return then you'll be ready.";
this.$missionEmpty = "Thanks for your willingness, commander.\n Nothing to do in open task list now.";
this.$missionOffered = "Mission was already offered, commander, and cargo is in your cargo bay. Just deliver it to destination!";
// Special missions
this.$specialCargoList = [
"Atmospheric Probes",
"Datapads",
"Scientific Equipment Toolkit",
"Long Range Scanners",
"Scout Spiders",
"Mining Bots",
"Mobile Shelter",
"Meteostation",
"Seismic Station",
"Relay Station",
"Biomaterials",
"Biosensors"
];
this.$specialCargoLegend = [
"Airborne data gathering is very important for atmospheric research and air survey.\n Special delivery of radiosondes, solar powered sail-planes and multicopters to support field research is needed.",
"Increased volume of scientific data collected in field explorations demands huge data processing power.\n Data storage and processing devices must be delivered to research field outpost by special flight to prevent loss of valuable information.",
"We have shortage of functional scientific equipment due to unplanned lag in regular supply.\n Replacement units, spare parts and consumables must be delivered to provide uninterrupted supply for research field outpost.",
"Long range scanners extremely needed to provide safe remote monitoring of hazardous environment.\n This is dual-purpose technology too risky for regular delivery!",
"Autonomous bots are extremely valuable tools to increase efficiency and decrease personnel risk for remote field explorations in hazardous environment.\n Special delivery to support field research is needed.",
"Research group on remote survey camp has a pressing need to replace old mining bots for new ones.",
"Long-range field expedition needs fully equipped mobile shelter to provide temporary base camp.\n Construction kit must be delivered to remote field observation post to overcome constrains of limited local logistics.",
"More data needed for understanding perfectly unusual seasonal weather patterns.\n Set of automatic meteo equipment must be deployed in remote field location to support field research.",
"Sporadic seismic activity poses a threat to planned construction area.\n Seismic detectors must be deployed in remote field location to expand coverage of seismic early warning network.",
"Ionospheric storms induced by solar activity sometimes interrupts signal transmissions between main colony base and remote sites.\n Relay transceiver must be deployed in remote field location to expand coverage of communication network.",
"Our terraforming project switched over from modelling studies to field test.\n Biological samples must be delivered intact to testing ground in strictly controlled conditions. Regular delivery of biomaterial is prohibited due to biohazard regulations.",
"Some new data indicates possibility of alien life on testing ground planned for terraforming.\n Biochips for xenobiota detection must be delivered intact in sterilized container to prevent contamination of alien ecosystem in question."
];
// Accident missions
this.$accidentCargoSheet = [
// life support system failure
[1,1,2,2,3,3,9,10,11,12],
// lost in field
[6,8,8,8,8,8,8,8,8,15],
// life threatening accident
[0,0,0,1,1,1,3,4,8,17],
// fire
[0,0,1,1,2,2,3,4,6,7],
// power failure
[1,2,2,5,5,7,13,13,13,13],
// seismic collapse
[0,1,2,3,4,6,7,8,8,8],
// atmosphere loss
[1,1,1,2,2,3,3,3,6,7],
// solar flare
[2,5,5,5,5,6,7,14,15,16]
];
this.$accidentEventLegend = [
// life support system failure
"Partial failure of life supporting systems is reported.",
// lost in field
"Contact with field survey team was abruptly lost.",
// life threatening accident
"A serious life threatened accident with number of badly injured personnel is reported.",
// fire
"Installation caught heavy fire. Zone of ignition is isolated, but situation remains critical.",
// power failure
"Partial shutdown of installation power grid is reported.",
// seismic collapse
"Installation was severely damaged due to seismic shock.",
// atmosphere loss
"Part of living area was depressurized.",
// solar flare
"Overload and multiple short circuits of electrical network was caused by particularly intense solar storm."
];
this.$accidentCargoList = [
"First-aid Kit",
"Emergency Toolkit",
"Repair Toolkit",
"Spacesuits",
"Exoskeletons",
"Radiation Protective Suits",
"Emergency Shelter",
"Repair Bots",
"SAR Drones",
"Atmosphere Processing Unit",
"Water Processing Unit",
"Climate Control Unit",
"Waste Processing Unit",
"Auxiliary Power Unit",
"Auxiliary Navigation Beacon",
"Communication Transceiver",
"LAN Mainframes",
"Biomedical equipment"
];
this.$accidentCargoLegend = [
"Urgent delivery of first-aid medkit is a first priority task to support recovery of accident victims.",
"Urgent delivery of emergency toolkit is a first priority task to provide personnel survival.",
"Urgent delivery of repair toolkit is a first priority task to support system recovery.",
"External repair of installation without spacesuits is ruled out due to lack of breathable atmosphere.\n Urgent delivery of spacesuits is a first priority task to perform external activity.",
"It is extremely important to provide safe access onto zone of accident. Using of heavy bots is not option.\n Urgent delivery of exoskeletons is a first priority task to clear way for special task team.",
"High level of background radiation poses a threat to health of unshielded personnel.\n Urgent delivery of radiation protective suits is a first priority task to support safe work of repair team.",
"Urgent delivery of emergency shelter is a first priority task to provide personnel survival.",
"Environment too hazardous for personnel prevents manned activity.\n Urgent delivery of repair bots is a first priority task to perform crucial part of repair mission.",
"It is absolutely essential to begin search and rescue mission as soon as possible.\n Urgent delivery of SAR drones is a first priority task to support salvage operations.",
"Urgent delivery of atmospheric processing unit is a first priority task to support breathable atmosphere.",
"Urgent delivery of water processing unit is a first priority task to recover from water deficiency.",
"Urgent delivery of climate control unit is a first priority task to provide acceptable living conditions.",
"Urgent delivery of waste processing unit is a first priority task to recycle waste.",
"Urgent delivery of auxiliary power unit is a first priority task to support power for repair mission.",
"Shutdown of navigation system makes regular supply too risky.\n Urgent delivery of auxiliary navigation beacon is a first priority task to support safe port operations.",
"Shutdown of communication network makes external activity too risky.\n Urgent delivery of communication transceiver is a first priority task to support safe external operations.",
"Partial shutdown of computing network led to serious degradation of port functionality.\n Urgent delivery of new LAN mainframes is a first priority task to recover installation functions.",
"Physical state of some victims is too bad to cope with regular first-aid kit.\n Urgent delivery of special biomedical equipment is a first priority task to support recovery of accident victims."
];
this.startUp = function()
{
if (missionVariables.cargoDelivery_missionFlag == "ON") // activate saved mission
{
this.$planetFlagSelected = missionVariables.cargoDelivery_planetFlag;
this.$deliveryItem = missionVariables.cargoDelivery_deliveryItem;
this.$destinationPort = missionVariables.cargoDelivery_destinationPort;
this.$urgentMissionFlag = missionVariables.cargoDelivery_urgentFlag;
this.$specialMissionFlag = missionVariables.cargoDelivery_specialFlag;
this.$dangerStatus();
this.$insuranceFee = 250;
if (this.$urgentMissionFlag >= 0)
{
this.$urgentPremium = 500 + 500 * this.$dangerIndex;
this.$urgentPremiumTotal = this.$insuranceFee + this.$urgentPremium;
}
else
{
this.$specialPremium = 250 + 250 * this.$dangerIndex;
this.$specialPremiumTotal = this.$insuranceFee + this.$specialPremium;
}
}
}
this.shipWillExitWitchspace = function()
{
// reset mission flags
this.$awardMissionFlag = -1; // set mission offer block OFF
this.$planetInfoSelected = 0;
this.$planetFlagSelected = 0;
missionVariables.cargoDelivery_missionFlag = "OFF";
missionVariables.cargoDelivery_planetFlag = 0;
missionVariables.cargoDelivery_destinationPort = "";
missionVariables.cargoDelivery_deliveryCash = 0;
mission.setInstructions(null);
}
this.shipDockedWithStation = function(station)
{
// main station - contract offer
if (player.ship.dockedStation.isMainStation == true)
{
this.$initInterface(station);
}
// cargo delivered
if ((player.ship.equipmentStatus ("EQ_SCU") == "EQUIPMENT_OK") || (player.ship.equipmentStatus ("EQ_UCU") == "EQUIPMENT_OK"))
{
this.$cargoRemove(station);
}
}
this.$initInterface = function(station)
{
station.setInterface(this.name,{
title:"In-System Cargo Delivery",
category:"Deliveries",
summary:"Pick up special cargo and transfer it to appointed port",
callback:this.$setupMissionPage.bind(this)
});
}
this.$setupMissionPage = function()
{
this.$showMissionPage();
}
this.$showMissionPage = function()
{
// scan all system planets
this.$scanSystem();
if(this.$awardMissionFlag == -1)
{
this.$setMissionGenerator();
this.$missionActualInfo();
}
else
{
this.$missionObsoleteInfo();
}
}
this.shipApproachingPlanetSurface = function(planet)
{
if (planet.radius == this.$planetFlagSelected)
{
this.$deliveryFlag = 1;
}
else
{
this.$deliveryFlag = 0;
}
}
this.$scanSystem = function()
{
this.$planetNameList = worldScripts["planetaryCompass_worldScript.js"].planetNames;
this.$planetList = worldScripts["planetaryCompass_worldScript.js"].stellarArray;
}
this.$setMissionGenerator = function()
{
var k = 0;
for (let i=0; i<this.$planetList.length; i++)
{
if(this.$planetList[i].hasAtmosphere)
{
this.$planetInfo[k] = this.$planetNameList[k];
this.$planetFlag[k] = this.$planetList[i].radius;
k += 1;
}
}
var p = Math.floor(Math.random()*k);
this.$planetInfoSelected = this.$planetInfo[p];
this.$planetFlagSelected = this.$planetFlag[p];
this.$awardMissionFlag = 1; // set mission flag ON
this.$dangerStatus();
this.$insuranceFee = 250;
// set emergency mission - high priority!
this.$urgentlMissionFlag = -1;
this.$LSSRate = 0.975; // life support systems durability
this.$LSSRateTotal = Math.pow(this.$LSSRate,k); // cumulative life support systems durability
this.$flareRate = 1 - system.info.corona_flare / 100; // equipment durability for solar flares
this.$flareRateTotal = Math.pow(this.$flareRate,k); // cumulative durability for solar flares
this.$genericUrgentRate = 0.990; // generic accident durability
this.$genericUrgentRateTotal = Math.pow(this.$genericUrgentRate,k); // cumulative accident durability
this.$urgentPremium = 500 + 500 * this.$dangerIndex;
this.$urgentPremiumTotal = this.$insuranceFee + this.$urgentPremium;
this.$generateUrgentMission();
// set special mission
this.$specialMissionFlag = -1;
this.$specialLogisticRate = 0.75 - 0.5 * this.$dangerIndex; // more logistic lags in more dangerous systems
this.$specialLogisticTotal = Math.pow(this.$specialLogisticRate,k); // cumulative logistic rate
this.$specialPremium = 250 + 250 * this.$dangerIndex;
this.$specialPremiumTotal = this.$insuranceFee + this.$specialPremium;
if (this.$specialLogisticTotal < Math.random())
{
this.$generateSpecialMission();
}
}
this.$generateSpecialMission = function()
{
this.$specialMissionIndex = Math.floor(Math.random()*12);
this.$specialMissionFlag = this.$specialMissionIndex;
if((this.$planetFlagSelected < 40000) && ((this.$specialMissionIndex == 0) || (this.$specialMissionIndex > 6)))
{
this.$specialMissionFlag = -1; // exclude some equipment for small planets without dense atmosphere
}
if((this.$planetFlagSelected >= 100000) && (this.$specialMissionIndex > 3))
{
this.$specialMissionFlag = -1; // exclude surface based equipment for gas giant stations
}
if(this.$planetFlagSelected == system.mainPlanet.radius)
{
this.$specialMissionFlag = -1; // exclude main planet
}
}
this.$generateUrgentMission = function()
{
if(this.$LSSRateTotal < Math.random())
{
this.$urgentMissionFlag = 0; // life support system failure
}
if(this.$flareRateTotal < Math.random())
{
this.$urgentMissionFlag = 1; // lost in field
}
if(this.$flareRateTotal < Math.random())
{
this.$urgentMissionFlag = 7; // solar storm
}
if(this.$genericUrgentRateTotal < Math.random())
{
this.$urgentMissionIndex = Math.floor(Math.random()*7);
this.$urgentMissionFlag = this.$urgentMissionIndex; // generic accidents
}
if((this.$planetFlagSelected >= 100000) && ((this.$urgentMissionIndex == 1) || (this.$urgentMissionIndex == 5)))
{
this.$urgentMissionFlag = -1; // exclude ground based accidents on gas giants
}
if(this.$planetFlagSelected == system.mainPlanet.radius)
{
this.$urgentMissionFlag = -1; // exclude main planet
}
}
this.$cargoLoad = function()
{
// set mission state for save
missionVariables.cargoDelivery_missionFlag = "ON";
missionVariables.cargoDelivery_planetFlag = this.$planetFlagSelected;
missionVariables.cargoDelivery_deliveryItem = this.$deliveryItem;
missionVariables.cargoDelivery_destinationPort = this.$destinationPort;
missionVariables.cargoDelivery_urgentFlag = this.$urgentMissionFlag;
missionVariables.cargoDelivery_specialFlag = this.$specialMissionFlag;
// load cargo
if(this.$urgentMissionFlag >= 0)
{
player.ship.awardEquipment("EQ_UCU");
missionVariables.cargoDelivery_deliveryCash = this.$urgentPremium;
}
else
{
player.ship.awardEquipment("EQ_SCU");
missionVariables.cargoDelivery_deliveryCash = this.$specialPremium;
}
player.credits -= this.$insuranceFee;
}
this.$cargoRemove = function(station)
{
// unload cargo & reset mission state
var arrivalInfo = "";
player.ship.removeEquipment("EQ_SCU");
player.ship.removeEquipment("EQ_UCU");
missionVariables.cargoDelivery_missionFlag = "OFF";
missionVariables.cargoDelivery_planetFlag = 0;
missionVariables.cargoDelivery_deliveryItem = "";
missionVariables.cargoDelivery_destinationPort = "";
missionVariables.cargoDelivery_deliveryCash = 0;
missionVariables.cargoDelivery_urgentFlag = -1;
missionVariables.cargoDelivery_specialFlag = -1;
// pay cash & generate mission info
if(station.hasRole("planetFall_surface") && this.$deliveryFlag == 1) // delivery successfull - emergency OR special mission check
{
if(this.$urgentMissionFlag >= 0)
{
player.credits += this.$urgentPremiumTotal;
arrivalInfo = "Thank you for help commander!" + "\n\n"
+ this.$urgentPremium.toFixed(0) + " Cr already transferred to you cash with " + this.$insuranceFee + " Cr of insurance fee, " + this.$urgentPremiumTotal.toFixed(0) + " Cr total." + "\n\n"
+ "Good luck!";
}
else
{
player.credits += this.$specialPremiumTotal;
arrivalInfo = "Thank you for help commander!" + "\n\n"
+ this.$specialPremium.toFixed(0) + " Cr already transferred to you cash with " + this.$insuranceFee + " Cr of insurance fee, " + this.$specialPremiumTotal.toFixed(0) + " Cr total." + "\n\n"
+ "Good luck!";
}
}
else // delivery failed
{
arrivalInfo = "You failed to delivery cargo commander!" + "\n\n"
+ "More responsible pilot will be selected for this job next time." + "\n\n"
+ "Good-bye!";
}
mission.runScreen({
title: "Cargo Arrival Info",
background: {name: "specialCargoLoad.png", height: 480 },
message: arrivalInfo,}
);
}
this.$missionActualInfo = function()
{
var u = -1;
var s = -1;
this.$destinationPort = system.info.name + " " + this.$planetInfoSelected;
var deliveryInfo = "";
// emergency missions
// *** item selection
if(this.$urgentMissionFlag >= 0)
{
u = this.$urgentMissionFlag;
this.$urgentBreef = this.$accidentEventLegend[u];
this.$urgentMissionList = this.$accidentCargoSheet[u];
var l = Math.floor(Math.random()*10);
this.$urgentCargoTag = this.$urgentMissionList[l];
var t = this.$urgentCargoTag;
this.$urgentCargoItem = this.$accidentCargoList[t];
this.$urgentCargoLegend = this.$accidentCargoLegend[t];
this.$deliveryItem = this.$urgentCargoItem;
}
if(u >= 0)
{
deliveryInfo = "Urgent cargo delivery - "
+ this.$urgentCargoItem + "\n\n"
+ this.$urgentBreef + "\n\n"
+ this.$urgentCargoLegend + "\n\n"
+ "Destination port: " + this.$destinationPort + "\n\n"
+ "Insurance fee " + this.$insuranceFee + " Cr will be removed from your cash if you will assign this contract." + "\n"
+ "This fee will be returned with " + this.$urgentPremium.toFixed(0) + " Cr premium only in case of successful cargo delivery.";
// *** case 1 - ship is not equipped for mission
if((player.ship.equipmentStatus ("EQ_PLANETFALL") != "EQUIPMENT_OK") || (player.ship.cargoSpaceAvailable < 5) || (player.credits < this.$insuranceFee))
{
deliveryInfo = this.$missionRefuse;
mission.runScreen({
title: "Cargo Delivery Info",
background: {name: "specialCargoLoad.png", height: 480 },
message: deliveryInfo,}
);
}
// *** case 2 - mission available
else
{
mission.runScreen({
title: "Cargo Delivery Info",
background: {name: "specialCargoLoad.png", height: 480 },
message: deliveryInfo,
choicesKey: "cargo_contract"},
function (choice)
{
if (choice === "1_Accept_Contract") this.$cargoLoad();
}
);
}
}
// special missions
if(u >= 0) return; // check for emergency missions priority!
s = this.$specialMissionFlag;
this.$deliveryItem = this.$specialCargoList[s];
if(s >= 0)
{
deliveryInfo = "Special cargo delivery - "
+ this.$specialCargoList[s] + "\n\n"
+ this.$specialCargoLegend[s] + "\n\n"
+ "Destination port: " + this.$destinationPort + "\n\n"
+ "Insurance fee " + this.$insuranceFee + " Cr will be removed from your cash if you will assign this contract." + "\n"
+ "This fee will be returned with " + this.$specialPremium.toFixed(0) + " Cr premium only in case of successful cargo delivery.";
}
// *** case 1 - ship is not equipped for mission
if((player.ship.equipmentStatus ("EQ_PLANETFALL") != "EQUIPMENT_OK") || (player.ship.cargoSpaceAvailable < 5) || (player.credits < this.$insuranceFee))
{
deliveryInfo = this.$missionRefuse;
mission.runScreen({
title: "Cargo Delivery Info",
background: {name: "specialCargoLoad.png", height: 480 },
message: deliveryInfo,}
);
}
else
{
if (s >= 0) // *** case 2 - mission available
{
mission.runScreen({
title: "Cargo Delivery Info",
background: {name: "specialCargoLoad.png", height: 480 },
message: deliveryInfo,
choicesKey: "cargo_contract"},
function (choice)
{
if (choice === "1_Accept_Contract") this.$cargoLoad();
}
);
}
else // *** case 3 - no mission
{
deliveryInfo = this.$missionEmpty;
mission.runScreen({
title: "Cargo Delivery Info",
background: {name: "specialCargoLoad.png", height: 480 },
message: deliveryInfo,}
);
}
}
}
this.$missionObsoleteInfo = function()
{
var deliveryInfo = "";
if (missionVariables.cargoDelivery_missionFlag == "ON")
{
deliveryInfo = this.$missionOffered;
mission.runScreen({
title: "Cargo Delivery Info",
background: {name: "specialCargoLoad.png", height: 480 },
message: deliveryInfo,}
);
}
else
{
deliveryInfo = this.$missionEmpty;
mission.runScreen({
title: "Cargo Delivery Info",
background: {name: "specialCargoLoad.png", height: 480 },
message: deliveryInfo,}
);
}
}
this.guiScreenWillChange = function (to, from)
{
if (to === "GUI_SCREEN_MANIFEST")
{
if (missionVariables.cargoDelivery_missionFlag == "ON")
{
this.portInfo = "In-System Cargo Delivery: " + this.$deliveryItem + " to " + this.$destinationPort + ".";
mission.setInstructions(this.portInfo);
}
else
{
mission.setInstructions(null);
}
}
}
this.$dangerStatus = function()
{
if(system.isInterstellarSpace || !system.sun || system.sun.isGoingNova || system.sun.hasGoneNova) return;
var g = system.info.galaxyID;
this.$dangerLevelTotal = 25 - 5 * system.government; // system danger level per se
var dangerLevel = 0;
var l = System.infoForSystem(g, system.ID).systemsInRange();
for (var i = 0; i < l.length; i++)
{
var m = l[i].systemID;
dangerLevel = 5 - System.infoForSystem(g, m).government; // 7 LY zone of influence added
this.$dangerLevelTotal += dangerLevel;
}
this.$dangerLevelMax = 25 + 5 * l.length; // max possible danger level
this.$dangerRate = this.$dangerLevelTotal / this.$dangerLevelMax; // final danger level
this.$dangerIndex = this.$dangerRate.toFixed(3);
} |