/* oolite-primable-equipment-manager.js Allocate primable equipment to the two 'fast activate' buttons. Oolite Copyright © 2004-2013 Giles C Williams and contributors This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /*jslint white: true, undef: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */ /*global missionVariables, player*/ "use strict"; this.name = "oolite-primable-equipment-register"; this.author = "cim"; this.copyright = "© 2008-2013 the Oolite team."; this.version = "1.79"; this.startUpComplete = this.shipDockedWithStation = this.playerBoughtNewShip = function() { this._initialiseInterface(); } this.playerBoughtEquipment = function(eqkey) { this._initialiseInterface(); this._updatePrimableEquipmentSettings(eqkey,false); } this._updatePrimableEquipmentSettings = function(eqkey,quiet) { /* If the player has gained some equipment which is recommended * for fast activation, and the activation slot has nothing in it, * assign to that slot. */ var info = EquipmentInfo.infoForKey(eqkey); if (info.fastAffinityDefensive && player.ship.equipmentStatus(player.ship.fastEquipmentA) != "EQUIPMENT_OK" && player.ship.equipmentStatus(player.ship.fastEquipmentA) != "EQUIPMENT_DAMAGED") { // no installed equipment in fast slot A, so assign this player.ship.fastEquipmentA = eqkey; if (!quiet) { player.consoleMessage(expandDescription("[oolite-primablemanager-notify-assign]",{ "oolite-primable-equipment": info.name, "oolite-primable-slot": expandDescription("[oolite-primablemanager-slot-defensive]") }),7.5); player.consoleMessage(expandDescription("[oolite-primablemanager-notify-setup]"),7.5); } } else if (info.fastAffinityOffensive && player.ship.equipmentStatus(player.ship.fastEquipmentB) != "EQUIPMENT_OK" && player.ship.equipmentStatus(player.ship.fastEquipmentB) != "EQUIPMENT_DAMAGED") { // no installed equipment in fast slot B, so assign this player.ship.fastEquipmentB = eqkey; if (!quiet) { player.consoleMessage(expandDescription("[oolite-primablemanager-notify-assign]",{ "oolite-primable-equipment": info.name, "oolite-primable-slot": expandDescription("[oolite-primablemanager-slot-offensive]") }),7.5); player.consoleMessage(expandDescription("[oolite-primablemanager-notify-setup]"),7.5); } } } this._initialiseInterface = function() { if (player.ship.dockedStation) { var definition = null; if (this._equipmentWithScripts().length > 0) { definition = { title: expandMissionText("oolite-primablemanager-interface-title"), category: expandMissionText("oolite-primablemanager-interface-category"), summary: expandMissionText("oolite-primablemanager-interface-summary"), callback: this._configurePrimableEquipment.bind(this) }; } player.ship.dockedStation.setInterface("oolite-primable-equipment-manager",definition); } } this._equipmentWithScripts = function() { var result = []; var equipment = player.ship.equipment; for (var i=0;i