Scripts/berthControl-conditions.js |
/*jslint white: true, undef: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
/*global missionVariables, player*/
"use strict";
this.name = "berthControl-conditions";
this.author = "Nyarlatothep";
this.copyright = "This script is hereby placed in the public domain.";
this.version = "1.2";
/* contexts: npc, purchase, scripted, newShip, (loading), (damage), (portable) */
this.allowAwardEquipment = function(equipment, ship, context)
{
// OXP hook to allow stations to forbid specific equipment
if (context == "purchase" && player.ship.dockedStation && player.ship.dockedStation.scriptInfo["oolite-barred-equipment"])
{
if (player.ship.dockedStation.scriptInfo["oolite-barred-equipment"].indexOf(equipment) != -1)
{
return false;
}
}
// fixed berthts?
var fixedBerths = ship.scriptInfo.fixedBerths;
if (context == "purchase" && (fixedBerths === "Yes" || fixedBerths === "Y"))
{
player.consoleMessage(missionVariables.berthControl_marketMessage, 1.5);
return false;
}
if (context == "purchase" && equipment == "EQ_PASSENGER_BERTH_REMOVAL")
{
//var removableBerths = parseInt(missionVariables.berthControl_removableBerths);
if (missionVariables.berthControl_removableBerths === 0)
{
player.consoleMessage(missionVariables.berthControl_marketMessage, 1.5);
return false;
}
}
// otherwise allowed
return true;
}
|
Scripts/berthControl.js |
/*jslint white: true, undef: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
"use strict";
// Standard attributes
this.name = "BerthControl";
this.author = "Smivs, Nyarlatothep";
this.copyright = "This script is hereby placed in the public domain.";
this.version = "1.2";
this.description = "Passenger berths management script.";
this.playerBoughtNewShip = function(ship)
// set removable berth count when ship is bought
{
missionVariables.berthControl_removableBerths = null;
missionVariables.berthControl_marketMessage = null;
var msg = "";
var berths = ship.passengerCapacity; // !
var fixedBerths = ship.scriptInfo.fixedBerths;
// get bool value from string
fixedBerths = (fixedBerths === "Yes" || fixedBerths === "Y");
if (fixedBerths)
{
msg = "This ship cannot be equipped with standard Passenger Berths.";
}
var minBerths = parseInt(ship.scriptInfo.minBerths);
// ensure minBerth is a valid integer & it's > 0
if (fixedBerths || (!isNaN(minBerths) && minBerths > 0))
{
// no berths to start with? no need for minBerths!
if (berths > 0)
{
// calculate the actual number of permanent berths
if (fixedBerths || minBerths > berths) minBerths = berths;
// compose a nice formatted message...
msg = (minBerths === berths ? "The " + minBerths : minBerths + " of the" ) + " Passenger Berth" + (berths === 1 ? "" : "s");
msg += " that came with the ship cannot be " + (fixedBerths? "modified" : "removed") + " at this shipyard.";
// save the number of removable berths for later
missionVariables.berthControl_removableBerths = berths - minBerths;
}
}
if (msg !== "")
{
player.consoleMessage(msg, 5);
// save a message for later
if (berths > 0 && minBerths > 0)
{
msg = minBerths + " Passenger Berths cannot be modified at this shipyard."
}
missionVariables.berthControl_marketMessage = msg;
}
}
this.playerBoughtEquipment = function(equipment)
{
if (missionVariables.berthControl_removableBerths === null)
{
// no berthControl mission variable? do nothing
return;
}
if (equipment == "EQ_PASSENGER_BERTH")
{
missionVariables.berthControl_removableBerths++; // update counter
}
if (equipment == "EQ_PASSENGER_BERTH_REMOVAL")
{
missionVariables.berthControl_removableBerths--; // update counter
}
} |