Scripts/vacuum_pump.js |
"use strict";
this.author = "Neelix";
this.copyright = "© 2011-2014 Neelix.";
this.licence = "CC-BY-NC-SA 4.0";
this.version = "0.3";
this.name = "VacuumPump";
this.description = "Vacuum Pump World Script";
this.startUp = function() {
//Prepare data storage and mode selection
this.$commodities = [
{commName: "gold", mask: 1},
{commName: "platinum", mask: 2},
{commName: "gem_stones", mask: 4}
];
this.$mode = 0;
//Prepare data storage for "crushed cargo pods" functionality
this.$alloysStored = missionVariables.vacuumPump_alloysStored;
if (!this.$alloysStored) {
this.$alloysStored = 0;
}
this.$maxStorage = 20;
//setup sound
this.$pumpSound = new SoundSource;
this.$pumpSound.sound = "vacuumpump.ogg";
this.$pumpSound.loop = false;
}
this.playerWillSaveGame = function() {
//Keep record of internally stored crushed pods across sessions
missionVariables.vacuumPump_alloysStored = this.$alloysStored;
}
this.shipWillLaunchFromStation = function() {
// Record amount of gold, platinum and gem stones stored in the safe on launch.
if (manifest.gold > 499) {
this.$commodities[0].inSafe = 499;
} else {
this.$commodities[0].inSafe = manifest.gold;
}
if (manifest.platinum > 499) {
this.$commodities[1].inSafe = 499;
} else {
this.$commodities[1].inSafe = manifest.platinum;
}
if (manifest.gemStones > 499999) {
this.$commodities[2].inSafe = 499999;
} else {
this.$commodities[2].inSafe = manifest.gemStones;
}
}
this._startPump = function() {
var $i, $j;
var $ml = manifest.list;
var $commInfo = [{},{},{}];
var $activated = false;
var $totalRecovered = 0;
var $alloyTotal = 0;
//Calculate how much of each commodity is in the hold, and whether or not it needs to be consolidated
for ($i = 0; $i < $ml.length; $i++) {
for ($j = 0; $j < 3; $j++) {
if ($ml[$i].commodity == this.$commodities[$j].commName) {
$commInfo[$j].index = $i;
$commInfo[$j].inHold = $ml[$i].quantity-this.$commodities[$j].inSafe;
$commInfo[$j].minContainers = Math.ceil($commInfo[$j].inHold / (($j == 2) ? 1000000 : 1000));
$commInfo[$j].pumpUseful = ($commInfo[$j].minContainers < $ml[$i].containers) ? true : false;
}
}
}
// Actvate pump based on mode and whether or not it is useful for a given commodity
for ($j = 0; $j < 3; $j++) {
if (player.alertCondition == 1 && player.ship.energy >= 64 && $commInfo[$j].pumpUseful &&
(this.$commodities[$j].mask & this.$mode || this.$mode == 0 && !$activated)) {
this.$pumpSound.play();
this._pumpAct($j,$commInfo[$j]);
$totalRecovered += $ml[$commInfo[$j].index].containers - $commInfo[$j].minContainers;
$activated = true;
//Convert cargo pods to alloys and add to internal storage or cargo bay
this.$alloysStored += $totalRecovered;
while (this.$alloysStored >= this.$maxStorage) {
manifest.alloys += 1;
this.$alloysStored -= this.$maxStorage;
$alloyTotal += 1;
}
}
}
if ($activated) {
//notify player how much cargo space has been recovered.
player.consoleMessage("Cargo load " + player.ship.cargoSpaceUsed + " of " + player.ship.cargoSpaceCapacity + " t. ",10);
player.consoleMessage($totalRecovered + " t. Recovered",10);
if ($alloyTotal > 0) {
player.consoleMessage($alloyTotal + " t Alloys added to Cargo bay",10);
}
} else {
//equipment failed to operate - notify the player
if (player.alertCondition != 1) {
player.consoleMessage("Vacuum Pump can not be operated unless condition is Green",5);
} else {
player.consoleMessage("Unable to recover any cargo space",5);
}
}
}
this._pumpAct = function($commNo, $commData) {
//adding entire amount of the item to the manifest in one go should put it in the minimum number of containers.
player.ship.energy -= 48;
switch ($commNo) {
case 0:
manifest.gold -= $commData.inHold;
manifest.gold += $commData.inHold;
player.consoleMessage("Gold Consolidated",7);
break;
case 1:
manifest.platinum -= $commData.inHold;
manifest.platinum += $commData.inHold;
player.consoleMessage("Platinum Consolidated",7);
break;
case 2:
manifest.gemStones -=$commData.inHold;
manifest.gemStones +=$commData.inHold;
player.consoleMessage("Gem Stones Consolidated",7);
}
}
this._modeCycle = function() {
this.$mode++;
if (this.$mode == 8) {
this.$mode = 0;
}
switch (this.$mode) {
case 0:
player.consoleMessage("Vacuum Pump: Single Use Mode");
break;
case 1:
player.consoleMessage("Vacuum Pump: Gold Only");
break;
case 2:
player.consoleMessage("Vacuum Pump: Platinum Only");
break;
case 3:
player.consoleMessage("Vacuum Pump: Gold and Platinum");
break;
case 4:
player.consoleMessage("Vacuum Pump: Gem Stones Only");
break;
case 5:
player.consoleMessage("Vacuum Pump: Gold and Gem Stones");
break;
case 6:
player.consoleMessage("Vacuum Pump: Platinum and Gem Stones");
break;
case 7:
player.consoleMessage("Vacuum Pump: Everything");
}
}
|