Back to Index Page generated: Apr 20, 2026, 4:52:51 AM

Expansion Cargo Space Refit

Content

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description A complete dismantling and refurbishment of a ship's utilizable interior, this radical refit has been found to double the hold capacity of most vessels. A complete dismantling and refurbishment of a ship's utilizable interior, this radical refit has been found to double the hold capacity of most vessels.
Identifier oolite.oxp.Reval.Cargo_Space_Refit oolite.oxp.Reval.Cargo_Space_Refit
Title Cargo Space Refit Cargo Space Refit
Category Equipment Equipment
Author Reval Reval
Version 1.1 1.1
Tags
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL http://wiki.alioth.net/index.php/Cargo_Space_Refit_OXZ n/a
Download URL https://wiki.alioth.net/img_auth.php/1/1e/Cargo_Space_Refit.oxz n/a
License CC-BY-NC-SA 4.0 CC-BY-NC-SA 4.0
File Size n/a
Upload date 1776019679

Documentation

Also read http://wiki.alioth.net/index.php/Cargo%20Space%20Refit

Equipment

Name Visible Cost [deci-credits] Tech-Level
Cargo Space Refit yes 5000 5+

Ships

This expansion declares no ships.

Models

This expansion declares no models.

Scripts

Path
Scripts/csr_conditions.js
// conditions for award of Cargo Space Refit
"use strict";
this.name = "CSR Conditions";
this.author = "Reval";
this.licence = "CC BY-NC-SA 4.0";
this.version = "1.0";

this.allowAwardEquipment = function(equipment, ship, context) {
	
	if (equipment == "EQ_CARGO_REFIT") {
		var p = player.ship;
		var charges = 0, csc = 0;
		// reset csr globals and note new capacity
		var shipDef = Ship.shipDataForKey(p.dataKey);
		// get the base values for this ship type
		if (shipDef["max_cargo"] != undefined) csc = parseInt(shipDef["max_cargo"]);
		// if containers are fitted, this will include their capacity
		// so the refit should be ordered before fitting them
		for (var i=1; i<=csc; i++) charges += 500;
		if (player.credits>=charges) return true;
			else return false;
	}
	return true;
}
Scripts/csr_script.js
"use strict";
this.name = "Cargo Space Refit";
this.author = "Reval";
this.licence = "CC BY-NC-SA 4.0";
this.version = "1.1";


this.playerBoughtEquipment = function(equipment, paid) {
	var pc = player.consoleMessage;
	if (equipment == "EQ_CARGO_REFIT") {
		if (this.$csrFitted=="no") {
			// increase space by ship's nominal capacity
			player.ship.cargoSpaceCapacity += this.$csrNominal;
			var pcc=player.ship.cargoSpaceCapacity;
			pc("Refitting ship to "+pcc+" TC capacity...",9);
			this.$csrSpace = pcc;
			// charge refit fee according to ship size
			for (var i=1; i<= this.$csrNominal; i++)
				this.$csrCharges += 500;
			// debit customer's account
			// note: player.credits won't go into the red!
			player.credits -= this.$csrCharges;
			// reimburse deposit
			var pd = paid/10; // decicredits, so convert
			this.$csrDeposit = pd;
			player.credits += pd;
			pc("Total cost: "+this.$csrCharges+" cr",9);
			pc("F4 to check your invoice.",9);
			this.$csrFitted = "yes";
			// prepare Invoice Interface
			var sta = player.ship.dockedStation;			
			this._csrPrepInv(sta);
		} else pc("Ship already refitted.",7);
	}	
}


this.equipmentRemoved = function(equipmentKey) {
    var pc=player.consoleMessage;
	if (equipmentKey == "EQ_CARGO_REFIT") {
		pc("We cannot un-refit your ship!",7);
	}
}


this.playerBoughtNewShip = function(ship, price) {
    var p = player.ship;
	// reset csr globals and note new capacity
    var shipDef = Ship.shipDataForKey(p.dataKey);
    // get the base values for this ship type
    if (shipDef["max_cargo"] != undefined) this.$csrNominal = parseInt(shipDef["max_cargo"]);
	this.$csrSpace = 0;
	this.$csrFitted = "no";
	this.$csrCharges = 0;
	this.$csrDeposit = 0;	
}


this.shipDockedWithStation = function(station) {
	// conditionally, prepare Invoice Interface
	if (this.$csrFitted=="yes")	this._csrPrepInv(station);
}


this.startUpComplete = function () {
	if (missionVariables.csrSpace != null) 
		player.ship.cargoSpaceCapacity += missionVariables.csrSpace;
	if (missionVariables.csrFitted != null) 
		this.$csrFitted = missionVariables.csrFitted;
	if (missionVariables.csrCharges != null) 
		this.$csrCharges = missionVariables.csrCharges;
	if (missionVariables.csrDeposit != null) 
		this.$csrDeposit = missionVariables.csrDeposit;
}


this.startUp = function() {
    var p = player.ship;
    var shipDef = Ship.shipDataForKey(p.dataKey);
    // get the base values for this ship type
    if (shipDef["max_cargo"] != undefined) this.$csrNominal = parseInt(shipDef["max_cargo"]);
    log(this.name, "Initialising OXP " + this.name);
	this.$csrSpace = 0;
	this.$csrFitted = "no";
	// initialize charges
	this.$csrCharges = 0;
	// initialize deposit
	this.$csrDeposit = 0;	
}


this.playerWillSaveGame = function(message) {
	missionVariables.csrSpace = this.$csrSpace;
	missionVariables.csrFitted = this.$csrFitted;
	missionVariables.csrCharges = this.$csrCharges;
	missionVariables.csrDeposit = this.$csrDeposit;
}


// create F.E.S. Cargo Space Invoice sheet  
this._csrPrepInv = function(station) {
	station.setInterface("csrInv",{
	title: "Your FE Shipyards Invoice for CSR work",
	category: "Your FE Shipyards",
	summary: "FE Shipyards invites you to check your Invoice for the recent Cargo Space Refit undertaken on your behalf." ,
	callback: this._csrShowInv.bind(this)
	});	
}


// show F.E.S. Invoice for Cargo Space Refit
this._csrShowInv = function() {
	
	var parameters = new Object();
	
	parameters.title = "FE Shipyards Invoice for Cargo Space Refit";
	
	parameters.message = "Dear customer, \n\n";
	
	parameters.message += "This constitutes your invoice for our successful cargo space refit recently undertaken on your "+player.ship.name+" with nominal capacity "+this.$csrNominal+"  TC.\n\n";
	
	parameters.message += "Total Charges: "+this.$csrCharges+" cr \n\n";
	
	parameters.message += "The amount debited from your account includes your initial deposit of "+ this.$csrDeposit + " cr. \n\n";
	
	parameters.message += "We count, as always, on your satisfaction with our service.\n\n";
	
	parameters.message += "Yours attentively,\n\n";
	
	parameters.message += "Siri Chodrum, for Dor Reval (Technical Director)\n";
	

	parameters.choicesKey = "csrAcknowlege";
	
	mission.runScreen(parameters, callback);	

	function callback(choice) {
		if (choice === "1_YES")
			player.commsMessage("FE Shipyards thanks you for your custom.");
	}	
}

Scripts/csrc_script.js
"use strict";
this.name = "CSR Correction";
this.author = "phkb";
this.copyright = "2024 phkb";
this.description = "Makes sure all cargo space changes are processed correctly, in order, and no cargo is lost when restoring a game";
this.license = "CC BY-NC-SA 4.0";

this._debug = false;

//-------------------------------------------------------------------------------------------------------------
this.guiScreenChanged = function(to, from) {
    if (from == "GUI_SCREEN_LOAD" && to == "GUI_SCREEN_STATUS") {
        // only do the recalculation process if the game has been saved once since this OXP was installed
        if (missionVariables.CargoSpace_Initialised == "yes") {
            this.$recalculateCargoSpace();
            this.$restoreManifest();
        }
    }
}

//-------------------------------------------------------------------------------------------------------------
this.playerWillSaveGame = function() {
    // this will let us know we have saved the game at least once
    missionVariables.CargoSpace_Initialised = "yes";
    // we're going to make a note of what the player current has in their hold
    // so when the game is restored, we can make sure no cargo is lost
    var hold = player.ship.manifest.list;
    var i = hold.length;
    var saved = {};
    while (i--) {
        saved[hold[i].commodity] = hold[i].quantity;
    }
    missionVariables.CargoSpace_Manifest = JSON.stringify(saved);
}

//-------------------------------------------------------------------------------------------------------------
this.$recalculateCargoSpace = function () {
    var p = player.ship;
    var shipDef = Ship.shipDataForKey(p.dataKey);

    var cargo = 0;
    var nom = 0;
    // get the base values for this ship type
    if (shipDef["max_cargo"] != undefined) cargo = parseInt(shipDef["max_cargo"]);
    nom = cargo;

    var exp = "";
    if (shipDef["extra_cargo"] != undefined) {
        exp = parseInt(shipDef["extra_cargo"]);
    }
    if (exp === "") {
        if (shipDef._oo_shipyard) {
            if ((shipDef._oo_shipyard.standard_equipment.extras && shipDef._oo_shipyard.standard_equipment.extras.indexOf("EQ_CARGO_BAY") >= 0) ||
                (shipDef._oo_shipyard.optional_equipment && shipDef._oo_shipyard.optional_equipment.indexOf("EQ_CARGO_BAY") >= 0))
                exp = 15;
        }
    }
    if (this._debug) log(this.name, "initial cargo space " + cargo);
    if (p.hasEquipmentProviding("EQ_CARGO_BAY")) cargo += exp;

    // take away the amount used by any equipment with "requires_cargo_space"
    var eqlist = p.equipment;
    var i = eqlist.length;
    while (i--) {
        var eq = eqlist[i];
        if (eq.requiredCargoSpace > 0) cargo -= eq.requiredCargoSpace;
    }

    // first, set the base value
    if (this._debug) log(this.name, "1 - cargo space now " + cargo);

    // next, look for a refit
    if (p.hasEquipmentProviding("EQ_CARGO_REFIT")) cargo += nom;
    if (this._debug) log(this.name, "2 - cargo space now " + cargo);

    // then look for cargo pods (only one of these can be added)
    if (p.hasEquipmentProviding("EQ_10TC_POD")) cargo += 10;
    if (p.hasEquipmentProviding("EQ_20TC_POD")) cargo += 20;
    if (p.hasEquipmentProviding("EQ_30TC_POD")) cargo += 30;
    if (p.hasEquipmentProviding("EQ_40TC_POD")) cargo += 40;
    if (p.hasEquipmentProviding("EQ_50TC_POD")) cargo += 50;
    if (p.hasEquipmentProviding("EQ_60TC_POD")) cargo += 60;
    if (this._debug) log(this.name, "3 - cargo space now " + cargo);

    // finally, look for any goods containers (added as mines in the missile array)
    // multiple can installed
    if (p.missileCapacity > 0) {
        var flag = false;
        try {
            var miss = p.missiles;
            flag = true;
        } catch (err) {
            if (this._debug) log(this.name, "!!ERROR: " + err);
        }
        if (flag === true) {
            var i = miss.length;
            while (i--) {
                var mk = miss[i].equipmentKey;
                if (mk == "EQ_GC1_MINE") cargo += 10;
                if (mk == "EQ_GC2_MINE") cargo += 20;
                if (mk == "EQ_GC3_MINE") cargo += 30;
                if (mk == "EQ_GC4_MINE") cargo += 40;
                if (mk == "EQ_GC5_MINE") cargo += 50;
            }
        }
        if (this._debug) log(this.name, "4 - cargo space now " + cargo);
    }
    p.cargoSpaceCapacity = cargo;
}

//-------------------------------------------------------------------------------------------------------------
this.$restoreManifest = function () {
    if (missionVariables.CargoSpace_Manifest) {
        var pm = player.ship.manifest;
        var saved = JSON.parse(missionVariables.CargoSpace_Manifest);
        var cm = Object.keys(saved);
        var i = cm.length;
        if (this._debug) log(this.name, "redoing cargo manifest...");
        while (i--) {
            if (this._debug) log(this.name, "setting " + cm[i] + " to " + saved[cm[i]]);
            pm[cm[i]] = saved[cm[i]];
        }
        delete missionVariables.CargoSpace_Manifest;
    }
}