Back to Index Page generated: May 8, 2024, 6:16:03 AM

Expansion ShipVersion

Content

Warnings

  1. Required Expansions mismatch between OXP Manifest and Expansion Manager at character position 0073 (DIGIT ZERO vs LATIN SMALL LETTER N)
  2. No version in dependency reference to oolite.oxp.CaptMurphy.ShipStorageHelper:null

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description All ship get version numbers and bonuses with the version, NPCs get extra equipments scaled with the version. All ship get version numbers and bonuses with the version, NPCs get extra equipments scaled with the version.
Identifier oolite.oxp.Norby.ShipVersion oolite.oxp.Norby.ShipVersion
Title ShipVersion ShipVersion
Category Activities Activities
Author Norby Norby
Version 1.24 1.24
Tags
Required Oolite Version
Maximum Oolite Version
Required Expansions
  • oolite.oxp.CaptMurphy.ShipStorageHelper:0
  • oolite.oxp.CaptMurphy.ShipStorageHelper:
  • Optional Expansions
    Conflict Expansions
    Information URL http://wiki.alioth.net/index.php/ShipVersion n/a
    Download URL https://wiki.alioth.net/img_auth.php/6/64/ShipVersion_1.24.oxz n/a
    License CC BY-NC-SA 4.0 CC BY-NC-SA 4.0
    File Size n/a
    Upload date 1610873315

    Documentation

    Also read http://wiki.alioth.net/index.php/ShipVersion

    ShipVersion 1.24 readme.txt

    ShipVersion OXP
    
    All piloted ships got a version number from 1.0 to 10.0 when manufactured.
    This means the age of the ship, so it is not changeable like an equipment, this represents the era when the ship created and affect many parts of the ship.
    
    In this way there is a reason to buy another ship from the same type which you have if you get enough money and create a new goal to earn more money after you bought your favourite ship to get another with higher version.
    Be cautious, you may need to avoid stronger enemies and retreat from the combat if the situation is hard.
    
    
    The 1.0 is the normal ship, others get bonuses for:
    -Energy and shield recharge (max. +1.8/seconds, NPC shield recharges affected also with CustomShields OXP),
    -Missile reload time.
    
    NPCs get also:
    -Accuracy bonus,
    -Equipments (mainly combat related, see below), awarded more with the higher version.
    
    Player get:
    -Service Level Repair Bot if ShipVersion >= 8.0 which can increase 1% in every 5 minutes of flying but limited to fix Bad levels only.
    
    
    Ship details screen
    
    If you hit the enter key in the shipyard with this OXP then you will not get the ship instantly but can read ship details including the version number in the heading.
    
    Do not buy the first available ship when you have enough money, watch the version number and wait until a good ship will be sold.
    Unfortunately if you throw back a ship then the game remove it from the shipyard, but you can get back if reload a saved game.
    If there are more copy from the wanted ship in the Shipyard then save the game, check the ship versions and if the last is not the best then load the game and choose the best, the versions will not change.
    
    The awarded Ship Version Equipment show the version of the ship in the status screen (F5).
    If this equipment damaged then the recharge bonus lost until repaired.
    
    If you are attacked by more ship then watch the version numbers at the end of the names and fight with the strongest first.
    
    NPCs show the main number of the version only (1 - 10 instead of 1.0 - 10.0) due to the limited detection.
    
    The version numbers comes from the read-only entityPersonality value of the ships willfully.
    In this way a script can set it when creating a new player ship only and can not change afterwards, so you must find and buy another ship if you want to upgrade to higher version.
    
    NPCs get:
     Version	Equipments
     1	Escape Pod
     2	E.C.M. System
     3	Extra Energy Unit
     4	Shield Boosters
     5	ECM Hardened Missiles and Shield Cycler if the OXP with same name is present
     6	Witchdrive Fuel Injectors and Q-Charger if the related OXP is present and at least v1.21
     7	Military Scanner Filtering, Shield Equalizer and Capacitors if the same OXP is present
     8	Military Shield Enhancement
     9	Military Scanner Jammer and Naval Energy Unit
     10	Cloaking Device and Quirium Cascade Mine (the top 1% of the ships)
    
    You can set the maximum level of the awards with $ShipVersion_AwardMax in the Scripts/shipversion.js, the default is 10.
    These awarded in addition, so a ship with small version may have advanced equipments if start with it or got it from somewhere else than this OXP.
    
    
    HardShips support
    
    If both HardShips OXP and IronHide OXP present then the HardShips OXP will award an equivalent of the IronHide Armour to NPCs to compensate the originally player-only IronHide Armour, and award more armour to the ships with high version.
    
    Awarded with HardShips OXP and IronHide OXP:
     Version	Equipments
     1	Life Box
     2	Dummy Equipments depending on cargo space and Electronics Box
     3	Equipment Box
     4	Additional Core Hull, Shield Box and if not clean then Renewable Energy Generator
     5	IronHide Armour and Hard Nose
     6	Additional Front Armour, Emergency Energy Generator and Injector Box
     7	Additional Aft Armour and Emergency Shield Generator
     8	Military IronHide Armour and Very Hard Nose
     9	High-Tech Catalyst if clean and Big Shield Capacitors with ShieldEqualizer+Capacitors OXP
     10	1.5x Military IronHide Armour and Anti-Sapper Shield
    
    For example a Viper v8 get 490 armour and 384 shield points over the basic 180 energy, which is 6x more but only 20% of the ships has v8 or above.
    A zealous player can make tables to all NPC ships from Version 1 to 10 with energy, front-aft-side armour, shield and recharge values modified by the awarded equipments. Please publish if you can do it.
    
    ShipVersion OXP can not award the player-only Ironhide Armour to NPCs without HardShips OXP.
    But without ShipVersion OXP the HardShips OXP can award it due to the armour-making code simulate the NPC IronHide Armour and use the same entityPersonality-based formula to determine the NPCs who can get this.
    
    If HardShips OXP present then all ship get equal level Hard Shield with the version number also.
    
    The Hard Armour (which is the strongest addition of the HardShips OXP) is not awardable by version due to it is not an equipment.
    Very large and heavy in real, need additional reinforced holders within the ship so can not added easily to an existing ship, must be made a different subtype to hold.
    It is something beyond the ship version: a new ship with modified name (for example "Hard Cobra"), smaller thrust and orange tiled textures to make visible the very Hard Armour.
    But Hard Ships will get version numbers also with the bonuses described above.
    
    
    Ship sizes
    
    Ships with less than 30t mass can not get the following equipments due to the small inner space:
    IronHide Armour, Shield Boosters and Capacitors and none from HardShips OXP nor labelled as Military/Naval.
    Small ships: Adder (11t), Gecko (23t), Mamba (27t), Sidewinder (25t) and Viper (23t).
    
    Ships under 130t can not get Big Shield Capacitors, Very Hard Nose and nothing labelled as Military/Naval.
    Restricted ships: Asp (59t), Cobra I (47t), Constrictor (33t), Fer-de-Lance (51t), Krait (80t), Moray (40t), Viper Interceptor (43t) and the previous small ships.
    
    Large ships can get all (be wise): Anaconda, Boa, Boa Mk2, Cobra III and Python.
    
    The bounty of ships over 30t is increased with version*10 credits so v1-v10 add 10-100.
    Large non-clean ships get more at high levels: v8 get 100, v9 get 150 and v10 get 200 additional credits.
    
    Player get similar restrictions so can not buy some equipments into small ships:
    Under 30t no Galactic Drive, IronHide Armour, Medium Railgun, Military and Mining Laser, Shield Booster and Shield Capacitor.
    Under 130t no Heavy and Mining Railgun, Military IronHide Armour and Naval Shield Booster.
    
    Drones in HardShips OXP and custom ships under 3t are not awarded with equipments at all (no room for anything), but get recharge and accuracy bonuses as others.
    
    
    Service Level
    
    The Service Level equipment show the status of the ship hull based on the following data.
    
     Perfect 100%
     Good	 90-99%
     Weak	 80-89%
     Bad	 76-79%
     Minimal 75%
    
    This affect the ship value when you want to sell it to buy another ship so always worth to fix it before.
    
    You will get message from the changes and the name of the equipment show these words to can check it on the status screen (F5).
    If the version of your ship is at least 8.0 then this equipment contain a repair bot also which can increase 1% in every 5 minutes of flying but can reach at best the bottom of the Weak level (80%).
    The repair will allocate 100 credits during fly for the spare parts to produce 1% repair and will stop if not enough money left.
    
    Below 8.0 also usable to partially protect your other equipments with these spare parts to take out an equipment damage.
    Can show the level even if damaged but can not defend other equipments nor repair the ship so worth to fix it.
    
    You can buy "Small Fix" in any dock to increase Service Level.
    The full Maintenance Overhaul is cheaper and faster to do large repairs: can level up from Minimal to Good in 19 days and almost half in price than many small fixes which need 50 days.
    But if a tiny Maintenance cost 1% of the ship then Small Fix do the same for 0,5% and both need 5 days equally.
    Bad levels can be fixed in 5 minutes/level and cost 100 credits so it is the same if fix it during fly.
    You can make small fixes if you are short in money, most importantly if your weapons broken apart then must to fix at least once to leave the minimal level before buy weapons.
    You can reach the perfect level with repeated fixes if you want to get the best price for your ship when buy another.
    
    
    Recover Turrets
    
    If you lost your turrets then choose this in the equipment shop from techlevel 5 to fix a turret for 1000 credits.
    
    
    Colors in Scanner
    
    * Red mean a ship targeting the player, light red if small escort ship below 130t mass.
    * Orange flag mean a ship with bounty, lighter orange if escort.
    * Yellow is a neutral ship with clean status.
    * Green mean station, if changed to red then targeted you and send defensive ships.
    * Purple mean police ship.
    
    These color changes can be turned off in the Scripts/shipversion.js if set $ShipVersion_Colors to false.
    
    
    
    Dependencies:
    Oolite v1.77 or later.
    
    Instructions:
    Unzip the file, and then move the folder named ".oxp" in the end to the AddOns directory of your Oolite installation.
    
    Recommended OXPs:
    * CustomShields OXP to put shields into NPC ships.
    * Detectors OXP to see about how many bonuses has the NPCs in different versions.
    * HardShips OXP if you want armoured enemies with extra awards.
    * IronHide OXP to NPCs get extra strong armour (need HardShips OXP also to work).
    * Q-Charger OXP from v1.21 awardable to NPC ships also, you will see some very fast enemy.
    * Shield Cycler OXP help to the NPCs also with transferring shield energy to the weaker side.
    * Shield Equalizer and Capacitors OXP to help NPCs a bit more.
    * Ship Storage Helper OXP is an alternate way to save the ship before check the version of a new one in the Shipyard Screen. Use if another OXP (especially if made later than this OXP) cause problems with the default method but supported by the SSH OXP. If present then the ShipVersion OXP using it instead of the built-in method, which working also, so SSH is not needed currently.
    * Skilled NPCs OXP to get harder residents in the bad governments.
    * ToughGuys OXP to get even more hard enemies, new ships and ambushes.
    
    Settings in Scripts/shipversion.js:
    
    * $ShipVersion_AwardMax = 10; //Additional equipments awarded to NPCs in shipSpawned function, level 0-10
    * $ShipVersion_BasicRulesOnly = false; //if true then default rules get versions only (trader, pirate...)
    * $ShipVersion_Colors = true; //flag color adjustments on the IFF scanner
    * $ShipVersion_Debug = false; //show extra messages to help developing
    
    Script_info support:
    
    OXP makers can set fixed version from 1 to 10 to any ship in shipdata.plist.
    Set to 1 is equal with the original ship, but NPCs over 3t get an Escape Pod due to nobody dare to fly without insurance.
    No version number in NPC names if set to -1.
    
     script_info = {
     	shipversion = 1;
     };
    
    
    License:
    This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License version 4.0
    If you are re-using any piece of this OXP, please let me know by sending an e-mail to norbylite@gmail.com .
    
    Changelog:
     2020.06.23. v1.24 Fixed compatibility issue with Hyperspace Hangar, plus some performance improvements
                       (courtesy of dybal)
     2016.05.22. v1.23 No version number in NPC names if shipversion is -1 in script_info.
                       Small fix in scanner color restore.
     2016.05.08. v1.22 Minimal service level will not cause loss of weapons anymore.
                       Fixing a bad service level by 1% is cheaper, only 100 Cr.
                       Scanner colors refined: red mean a ship targeting the player, orange mean bounty.
                       Fixed a bug at automatic bad service level repair after 5 minutes.
     2013.08.24. v1.21 Boxes added.
     2013.07.31. v1.2  Small Fix buyable in any dock to increase service level.
                       Repair bot using up credits to refill spare parts and limited to Weak level.
                       Laser will break when buy a hauler in Start Choices OXP, not after undock only.
     2013.07.28. v1.11 Skip mission ships with ccl_missionShip=true.
                       $ShipVersion_BasicRulesOnly can restrict further to the default rules.
     2013.07.27. v1.1  More bounty for large ships with high versions.
                       Player get equipments restrictions in small ships.
                       Script_info support to give fixed version.
                       Minimal service level cause weapon loss.
     2013.06.24. v1.0  First betatest version.
     2013.06.10. v0.3  HardShips support added.
     2013.04.07. v0.2  First working version.
     2013.03.31. v0.1  First test files.
    

    Equipment

    Name Visible Cost [deci-credits] Tech-Level
    Service Level Perfect yes 0 100+
    Service Level Minimal! yes 0 100+
    Service Level Bad yes 0 100+
    Service Level Bad yes 0 100+
    Service Level Bad yes 0 100+
    Service Level Bad yes 0 100+
    Service Level Weak yes 0 100+
    Service Level Weak yes 0 100+
    Service Level Weak yes 0 100+
    Service Level Weak yes 0 100+
    Service Level Weak yes 0 100+
    Service Level Weak yes 0 100+
    Service Level Weak yes 0 100+
    Service Level Weak yes 0 100+
    Service Level Weak yes 0 100+
    Service Level Weak yes 0 100+
    Service Level Good yes 0 100+
    Service Level Good yes 0 100+
    Service Level Good yes 0 100+
    Service Level Good yes 0 100+
    Service Level Good yes 0 100+
    Service Level Good yes 0 100+
    Service Level Good yes 0 100+
    Service Level Good yes 0 100+
    Service Level Good yes 0 100+
    Service Level Good yes 0 100+
    Service Level Repair Kit renewal yes 10000 2+
    Small Fix on Minimal Service Level yes 1000 2+
    Small Fix on Bad Service Level yes 1000 2+
    Small Fix on Weak Service Level yes 0 2+
    Small Fix on Good Service Level yes 0 2+
    Ship Version 1.0 yes 0 100+
    Ship Version 10.0 yes 0 100+
    Ship Version 1.1 yes 0 100+
    Ship Version 1.2 yes 0 100+
    Ship Version 1.3 yes 0 100+
    Ship Version 1.4 yes 0 100+
    Ship Version 1.5 yes 0 100+
    Ship Version 1.6 yes 0 100+
    Ship Version 1.7 yes 0 100+
    Ship Version 1.8 yes 0 100+
    Ship Version 1.9 yes 0 100+
    Ship Version 2.0 yes 0 100+
    Ship Version 2.1 yes 0 100+
    Ship Version 2.2 yes 0 100+
    Ship Version 2.3 yes 0 100+
    Ship Version 2.4 yes 0 100+
    Ship Version 2.5 yes 0 100+
    Ship Version 2.6 yes 0 100+
    Ship Version 2.7 yes 0 100+
    Ship Version 2.8 yes 0 100+
    Ship Version 2.9 yes 0 100+
    Ship Version 3.0 yes 0 100+
    Ship Version 3.1 yes 0 100+
    Ship Version 3.2 yes 0 100+
    Ship Version 3.3 yes 0 100+
    Ship Version 3.4 yes 0 100+
    Ship Version 3.5 yes 0 100+
    Ship Version 3.6 yes 0 100+
    Ship Version 3.7 yes 0 100+
    Ship Version 3.8 yes 0 100+
    Ship Version 3.9 yes 0 100+
    Ship Version 4.0 yes 0 100+
    Ship Version 4.1 yes 0 100+
    Ship Version 4.2 yes 0 100+
    Ship Version 4.3 yes 0 100+
    Ship Version 4.4 yes 0 100+
    Ship Version 4.5 yes 0 100+
    Ship Version 4.6 yes 0 100+
    Ship Version 4.7 yes 0 100+
    Ship Version 4.8 yes 0 100+
    Ship Version 4.9 yes 0 100+
    Ship Version 5.0 yes 0 100+
    Ship Version 5.1 yes 0 100+
    Ship Version 5.2 yes 0 100+
    Ship Version 5.3 yes 0 100+
    Ship Version 5.4 yes 0 100+
    Ship Version 5.5 yes 0 100+
    Ship Version 5.6 yes 0 100+
    Ship Version 5.7 yes 0 100+
    Ship Version 5.8 yes 0 100+
    Ship Version 5.9 yes 0 100+
    Ship Version 6.0 yes 0 100+
    Ship Version 6.1 yes 0 100+
    Ship Version 6.2 yes 0 100+
    Ship Version 6.3 yes 0 100+
    Ship Version 6.4 yes 0 100+
    Ship Version 6.5 yes 0 100+
    Ship Version 6.6 yes 0 100+
    Ship Version 6.7 yes 0 100+
    Ship Version 6.8 yes 0 100+
    Ship Version 6.9 yes 0 100+
    Ship Version 7.0 yes 0 100+
    Ship Version 7.1 yes 0 100+
    Ship Version 7.2 yes 0 100+
    Ship Version 7.3 yes 0 100+
    Ship Version 7.4 yes 0 100+
    Ship Version 7.5 yes 0 100+
    Ship Version 7.6 yes 0 100+
    Ship Version 7.7 yes 0 100+
    Ship Version 7.8 yes 0 100+
    Ship Version 7.9 yes 0 100+
    Ship Version 8.0 yes 0 100+
    Ship Version 8.1 yes 0 100+
    Ship Version 8.2 yes 0 100+
    Ship Version 8.3 yes 0 100+
    Ship Version 8.4 yes 0 100+
    Ship Version 8.5 yes 0 100+
    Ship Version 8.6 yes 0 100+
    Ship Version 8.7 yes 0 100+
    Ship Version 8.8 yes 0 100+
    Ship Version 8.9 yes 0 100+
    Ship Version 9.0 yes 0 100+
    Ship Version 9.1 yes 0 100+
    Ship Version 9.2 yes 0 100+
    Ship Version 9.3 yes 0 100+
    Ship Version 9.4 yes 0 100+
    Ship Version 9.5 yes 0 100+
    Ship Version 9.6 yes 0 100+
    Ship Version 9.7 yes 0 100+
    Ship Version 9.8 yes 0 100+
    Ship Version 9.9 yes 0 100+
    Repair Ship Version yes 10000 2+
    Recover Turrets yes 0 5+

    Ships

    This expansion declares no ships. This may be related to warnings.

    Models

    This expansion declares no models. This may be related to warnings.

    Scripts

    Path
    Scripts/servicelevelrepair.js
    "use strict";
    this.name        = "servicelevelrepair";
    this.author      = "Norby";
    this.copyright   = "2013 Norbert Nagy";
    this.licence     = "CC BY-NC-SA 3.0";
    this.description = "Service Level Repair Kit appear if damaged only.";
    this.version     = "1.2";
    
    this.allowAwardEquipment = function(eqKey, ship, context)
    {
    	if( ship === player.ship && context === "purchase" ) {
    		if(eqKey==="EQ_SERVICE_LEVEL_REPAIR" &&
    			player.ship.equipmentStatus("EQ_SERVICE_LEVEL_"+player.ship.serviceLevel)
    				== "EQUIPMENT_DAMAGED" ) {
    			return true;
    		}
    		var sl = player.ship.serviceLevel;
    		if(eqKey==="EQ_SERVICE_LEVEL_SMALL_FIX_1" && sl < 76 ) return true;
    		if(eqKey==="EQ_SERVICE_LEVEL_SMALL_FIX_2" && sl >= 76 && sl < 80 ) return true;
    		if(eqKey==="EQ_SERVICE_LEVEL_SMALL_FIX_3" && sl >= 80 && sl < 90 ) return true;
    		if(eqKey==="EQ_SERVICE_LEVEL_SMALL_FIX_4" && sl >= 90 && sl < 100 ) return true;
    	}
    	return false;
    }
    
    Scripts/shipversion.js
    "use strict";
    this.name        = "shipversion";
    this.author      = "Norby";
    this.copyright   = "2013 Norbert Nagy";
    this.licence     = "CC BY-NC-SA 3.0";
    this.description = "Give rechage and other bonuses to all ships based on the random personality value.";
    
    //customizable properties
    this.$ShipVersion_AwardMax = 10; //Additional equipments awarded to NPCs in shipSpawned function, level 0-10
    this.$ShipVersion_BasicRulesOnly = false; //if true then default rules get versions only (trader, pirate...)
    this.$ShipVersion_Colors = true; //flag color adjustments on the IFF scanner
    this.$ShipVersion_Debug = false; //show extra messages to help developing
    
    //internal properties, should not touch
    this.$ShipVersion_PlayerCredits = null; //store the current money
    this.$ShipVersion_PlayerShip = null; //store the ship
    this.$ShipVersion_PlayerShipDataKey = null; //store the ship type
    this.$ShipVersion_PlayerShipEqs = []; //store equipments
    this.$ShipVersion_PlayerShipEqDmg = []; //store equipment damage status
    this.$ShipVersion_PlayerShipFuel = 0; //store fuel
    this.$ShipVersion_PlayerShipMan = null; //store manifest (cargo)
    this.$ShipVersion_PlayerShipServiceLevel = 100; //store serviceLevel
    this.$ShipVersion_PlayerShipPass = []; //store passengers
    this.$ShipVersion_PlayerShipPCap = 0; //store passenger capacity
    this.$ShipVersion_PlayerShipPersonality = 16384; //store personality which is the source of the ship version
    this.$ShipVersion_PlayerShipWeapons = []; //store weapons
    this.$ShipVersion_ReplaceShip = false; //to avoid buy loop
    this.$ShipVersion_ServiceLevelCounter = 0; //count seconds to repair 1% in every 5 minutes
    this.$ShipVersion_ServiceLevelPrev = 0; //to detect changes
    this.$ShipVersion_Ships = [ player.ship ]; //this array will contain all version-equipped ships, the 0. is the player
    this.$ShipVersion_Simple = true; //show main NPC versions only, 1 - 10 instead of 1.0 - 10.0
    this.$ShipVersion_SLCr = 0; //cost of increasing sercive level on current player ship
    this.$ShipVersion_storedShipString = null;//store the current ship into this string
    this.$ShipVersion_Timer = null;
    /*** begin dybal ***/
    this.$hyperspaceHangarRestoredShip = false; // for HyperspaceHangar to set when restoring a ship, so playerBoughtNewShip can be ignored
    /*** end dybal ***/
    
    this.startUp = function() {
        this.$ShipVersion_ServiceLevelCounter = 0;
        this.$ShipVersion_ServiceLevelPrev = player.ship.serviceLevel;
        player.ship.awardEquipment("EQ_SERVICE_LEVEL_"+player.ship.serviceLevel);
        if( this.$ShipVersion_Debug )
            log("ShipVersion", "Service level in startUp: "+player.ship.serviceLevel+"%"); //debug
            this.$ShipVersion_SLCost();//save cost of increasing sercive level on current player ship
        this.$ShipVersion_Timer = new Timer(this, this.$ShipVersion_Timed, 1, 1);//run in every second
    }
    
    this.equipmentDestroyed = function(equipment) {//run only for player, not for NPCs
        var shipVersion = this.$ShipVersion_Int(player.ship);
        if(equipment === "EQ_SHIP_VERSION_"+shipVersion) {//do not destroy because it is not a buyable equipment
            if(player.ship.equipmentStatus(equipment) == "EQUIPMENT_UNAVAILABLE" )
                player.ship.awardEquipment(equipment); 
            player.ship.setEquipmentStatus(equipment, "EQUIPMENT_DAMAGED");//but set to damaged
        }
        if(equipment.indexOf("EQ_SERVICE_LEVEL_") > -1 ) {//do not destroy because it is not a buyable equipment
            if(player.ship.equipmentStatus(equipment) == "EQUIPMENT_UNAVAILABLE" )
                player.ship.awardEquipment(equipment); 
            player.ship.setEquipmentStatus(equipment, "EQUIPMENT_DAMAGED");//but set to damaged
        }
    }
    
    this.guiScreenWillChange = function(to, from) {
        if(to === "GUI_SCREEN_STATUS") {//fix a bug when the player got new ship without shipSpawned
    //      if( this.$ShipVersion_Debug ) player.consoleMessage(this.$ShipVersion_PlayerShipName());
            var shipVersion = this.$ShipVersion_Int(player.ship);
    //      player.consoleMessage(shipVersion+player.ship.equipmentStatus("EQ_SHIP_VERSION_"+shipVersion)+Math.random());//debug
            if(player.ship.equipmentStatus("EQ_SHIP_VERSION_"+shipVersion) == "EQUIPMENT_UNAVAILABLE" )
    //&& shipVersion > 10 ) //it was a bugfix for the doubled eq if v=1.0 - founded: was doubled in equipment.plist
                player.ship.awardEquipment("EQ_SHIP_VERSION_"+shipVersion); 
        }
        if(to === "GUI_SCREEN_SHIPYARD") {//store the current ship
    //player.ship.setEquipmentStatus("EQ_SERVICE_LEVEL_"+player.ship.serviceLevel, "EQUIPMENT_DAMAGED");//debug
            this.$ShipVersion_PlayerCredits = player.credits;
            if(worldScripts["Ship_Storage_Helper.js"]) { //another method
                this.$ShipVersion_storedShipString = worldScripts["Ship_Storage_Helper.js"].storeCurrentShip();
                worldScripts["Ship_Storage_Helper.js"].disableVortexPBNSFunc("delete");
                worldScripts["Ship_Storage_Helper.js"].disableMaelstromPBNSFunc("delete");
                worldScripts["Ship_Storage_Helper.js"].disableTCATPBNSFunc();
    //            if( this.$ShipVersion_Debug ) player.consoleMessage("Your "+this.$ShipVersion_PlayerShipName()+" stored.", 10);
            } else { //store the current ship - original method
                this.$ShipVersion_PlayerShip = player.ship; 
                this.$ShipVersion_PlayerShipDataKey = player.ship.dataKey;
                delete this.$ShipVersion_PlayerShipEqs;
                this.$ShipVersion_PlayerShipEqs = [];
                this.$ShipVersion_PlayerShipFuel = player.ship.fuel;
                this.$ShipVersion_PlayerShipMan = player.ship.manifest.list;
                delete this.$ShipVersion_PlayerShipPass;
                this.$ShipVersion_PlayerShipPass = [];
                var i=-1;
                var pa = player.ship.passengers; //local variable, faster
                while(pa[++i]) {
                    this.$ShipVersion_PlayerShipPass[i] = [];
                    this.$ShipVersion_PlayerShipPass[i][1] = pa[i].name;
                    this.$ShipVersion_PlayerShipPass[i][2] = pa[i].start;
                    this.$ShipVersion_PlayerShipPass[i][3] = pa[i].destination;
                    this.$ShipVersion_PlayerShipPass[i][4] = pa[i].eta;
                    this.$ShipVersion_PlayerShipPass[i][5] = pa[i].fee;
                    this.$ShipVersion_PlayerShipPass[i][6] = pa[i].premium;
                }
                this.$ShipVersion_PlayerShipPCap = player.ship.passengerCapacity;
                var i=-1;//index in the old eq array
                var p=-1;//index in the new eq array
                var eq = player.ship.equipment; //local variable, faster
                while(eq[++i]) {
                    if( eq[i].name.length > 0 ) {
                        if( this.$ShipVersion_Debug )
                            log("ShipVersion", "i:"+i+" name:"+eq[i].name);
                        this.$ShipVersion_PlayerShipEqs[++p] = eq[i];
                        if(player.ship.equipmentStatus(eq[i].equipmentKey) ==="EQUIPMENT_DAMAGED")
                            this.$ShipVersion_PlayerShipEqDmg[p] = true;
                        else this.$ShipVersion_PlayerShipEqDmg[p] = false;
                    } else {//skip noname eqs awarded by NumericHUD to avoid timeLimit error
                        for( var j = i + 10; j < eq.length; j+=10 ) {
                            if( eq[j].name.length != 0 ) {
                                i = j - 10; //end of skip
                                j = eq.length;
                            }
                        }
                        while( i < eq.length && eq[i].name.length == 0 ) i++;
                        i--;
                    }
                }
                this.$ShipVersion_PlayerShipServiceLevel = player.ship.serviceLevel;
                this.$ShipVersion_PlayerShipPersonality = player.ship.entityPersonality;
                this.$ShipVersion_PlayerShipWeapons[0] = player.ship.forwardWeapon;
                this.$ShipVersion_PlayerShipWeapons[1] = player.ship.aftWeapon;
                this.$ShipVersion_PlayerShipWeapons[2] = player.ship.portWeapon;
                this.$ShipVersion_PlayerShipWeapons[3] = player.ship.starboardWeapon;
                if( this.$ShipVersion_Debug )
                    log("ShipVersion", "Your "+this.$ShipVersion_PlayerShipName()+" has been stored.");
            }
        }
    }
    
    this.playerBoughtEquipment = function(equipmentKey) {
        if(equipmentKey === ("EQ_RENOVATION")) {
            if( this.$ShipVersion_ServiceLevelPrev != player.ship.serviceLevel ) {
                var st = player.ship.equipmentStatus("EQ_SERVICE_LEVEL_"+this.$ShipVersion_ServiceLevelPrev);
                player.ship.removeEquipment("EQ_SERVICE_LEVEL_"+this.$ShipVersion_ServiceLevelPrev);
                player.ship.awardEquipment("EQ_SERVICE_LEVEL_"+player.ship.serviceLevel);
                if( st == "EQUIPMENT_DAMAGED" ) //set to damaged
                    player.ship.setEquipmentStatus("EQ_SERVICE_LEVEL_"+player.ship.serviceLevel, st);
                if( this.$ShipVersion_Debug )
                    log("ShipVersion", "Service level renovated to "+player.ship.serviceLevel+"%"); //debug
                this.$ShipVersion_ServiceLevelPrev = player.ship.serviceLevel; //save
                player.consoleMessage("Service level changed to "+
                    this.$ShipVersion_SL(player.ship.serviceLevel),10);
            }
        }
        if(equipmentKey === "EQ_SERVICE_LEVEL_SMALL_FIX_1" //1% fix
            || equipmentKey === "EQ_SERVICE_LEVEL_SMALL_FIX_2"
            || equipmentKey === "EQ_SERVICE_LEVEL_SMALL_FIX_3"
            || equipmentKey === "EQ_SERVICE_LEVEL_SMALL_FIX_4") {
            player.ship.removeEquipment(equipmentKey);
            var cost = this.$ShipVersion_SLCost();
                    if( player.ship.serviceLevel < 80 ) cost = 0; //cost of bad levels is already deducted by equipment.plist
            if( player.credits < cost )
                player.consoleMessage("Not enough money: need "+cost+" credits.");
            else {
                player.credits -= cost;
                            if( player.ship.serviceLevel < 80 ) cost = 100; //display cost of bad levels below
                            //installation_time is set in equipment.plist from Oolite 1.82 instead of the next lines
                            if( 0 < oolite.compareVersion("1.82") ) {
                                if( player.ship.serviceLevel < 80 )
                                    ; //clock.addSeconds ("300"); //5 minutes as the repair bot, but core already add 10min
                                else clock.addSeconds ("432000"); //5 days, like about an original 1% maintenance overhaul
                            }
                player.ship.serviceLevel++;
                var st = player.ship.equipmentStatus("EQ_SERVICE_LEVEL_"+this.$ShipVersion_ServiceLevelPrev);
                player.ship.removeEquipment("EQ_SERVICE_LEVEL_"+this.$ShipVersion_ServiceLevelPrev);
                player.ship.awardEquipment("EQ_SERVICE_LEVEL_"+player.ship.serviceLevel);
                if( st == "EQUIPMENT_DAMAGED" ) //set to damaged
                    player.ship.setEquipmentStatus("EQ_SERVICE_LEVEL_"+player.ship.serviceLevel, st);
                if( this.$ShipVersion_Debug )
                    log("ShipVersion", "Service level fixed for "+cost+" credits to "+
                        player.ship.serviceLevel+"%"); //debug
                this.$ShipVersion_ServiceLevelPrev = player.ship.serviceLevel; //save
                player.consoleMessage("Payed "+cost+" credits for fix, service level now "+
                    this.$ShipVersion_SL(player.ship.serviceLevel),10);
            }
        }
        if(equipmentKey === ("EQ_SERVICE_LEVEL_REPAIR")) {
            var shipVersion = this.$ShipVersion_Int(player.ship);
            if(player.ship.equipmentStatus("EQ_SERVICE_LEVEL_"+player.ship.serviceLevel) === "EQUIPMENT_UNAVAILABLE")
                player.ship.awardEquipment("EQ_SERVICE_LEVEL_"+player.ship.serviceLevel);//for sure
            else player.ship.setEquipmentStatus("EQ_SERVICE_LEVEL_"+player.ship.serviceLevel, "EQUIPMENT_OK");
            player.ship.removeEquipment("EQ_SERVICE_LEVEL_REPAIR");
            clock.addSeconds ("3600");
    //          player.credits += 0;
        }
        if(equipmentKey === ("EQ_SHIP_VERSION_REPAIR")) {
            var shipVersion = this.$ShipVersion_Int(player.ship);
            if(player.ship.equipmentStatus("EQ_SHIP_VERSION_"+shipVersion) === "EQUIPMENT_UNAVAILABLE")
                player.ship.awardEquipment("EQ_SHIP_VERSION_"+shipVersion);//for sure
            else player.ship.setEquipmentStatus("EQ_SHIP_VERSION_"+shipVersion, "EQUIPMENT_OK");
            player.ship.removeEquipment("EQ_SHIP_VERSION_REPAIR");
            clock.addSeconds ("3600");
    //          player.credits += 0;
        }
        var mass = 30000;//below:Adder, Viper, Rocket Fighter and Gunship but not the Rocket Corvette
        if( !this.$ShipVersion_EQLimiter("EQ_WEAPON_MILITARY_LASER", equipmentKey, mass ) )
            player.ship.forwardWeapon = null;
        if( !this.$ShipVersion_EQLimiter("EQ_WEAPON_MINING_LASER", equipmentKey, mass ) )
            player.ship.forwardWeapon = null;
        this.$ShipVersion_EQLimiter("EQ_GAL_DRIVE", equipmentKey, mass );
        this.$ShipVersion_EQLimiter("EQ_IRONHIDE", equipmentKey, mass );
        this.$ShipVersion_EQLimiter("EQ_RAILGUN_2", equipmentKey, mass );
        this.$ShipVersion_EQLimiter("EQ_FORWARD_SHIELD_CAPACITOR", equipmentKey, mass );
        this.$ShipVersion_EQLimiter("EQ_AFT_SHIELD_CAPACITOR", equipmentKey, mass );
        this.$ShipVersion_EQLimiter("EQ_SHIELD_BOOSTER", equipmentKey, mass );//for sure only
        
        mass = 130000;//Cobra3, Rocket Miner and above
        this.$ShipVersion_EQLimiter("EQ_IRONHIDE_MIL", equipmentKey, mass );
        this.$ShipVersion_EQLimiter("EQ_NAVAL_ENERGY_UNIT", equipmentKey, mass );
        this.$ShipVersion_EQLimiter("EQ_NAVAL_SHIELD_BOOSTER", equipmentKey, mass );
        this.$ShipVersion_EQLimiter("EQ_RAILGUN_3", equipmentKey, mass );
        this.$ShipVersion_EQLimiter("EQ_RAILGUN_4", equipmentKey, mass );
    
        if(equipmentKey === "EQ_TURRET_RECOVER") {
            player.ship.removeEquipment("EQ_TURRET_RECOVER");
            var sub = 0;
            if(player.ship.subEntities && player.ship.subEntities.length > 0)
                for(var i=0; i < player.ship.subEntities.length; i++)
                    if(player.ship.subEntities[i] && player.ship.subEntities[i].energy > 0)
                        sub++; //count remaining turrets (assuming all subEntities are turrets)
            var missingturrets = 0;
            if((!player.ship.subEntities || sub === 0) && player.ship.subEntityCapacity > 0)
                missingturrets = player.ship.subEntityCapacity;
            if(player.ship.subEntities && player.ship.subEntityCapacity > sub)
                missingturrets = player.ship.subEntityCapacity - sub;
            if(missingturrets < 1 )    player.consoleMessage("No missing turrets.");
            else if(player.credits < 1000 * missingturrets) {
                var ts = "";
                if(missingturrets > 1) ts = "s";
                var nopart = "";
                if(player.credits >= 1000) nopart = " (and no partial recovery)";
                player.consoleMessage("Not enough money: "+missingturrets+" missing turret"+ts+" need "+
                    (1000*missingturrets)+" credits to recover"+nopart+".");
            } else {
                clock.addSeconds ( 3600 * missingturrets );
                player.credits -= 1000 * missingturrets;
                player.ship.restoreSubEntities();
                var ts = "";
                if(missingturrets > 1) ts = "s";
                player.consoleMessage(missingturrets+" turret"+ts+" recovered for "+(1000*missingturrets)+" credits.");
            }
        }
    }
    
    /*** begin dybal ***/
    //this.playerBoughtNewShip = function(ship) {
    this.playerBoughtNewShip = function(ship, price) {
        /*** this could have a (Oolite_version < X.XX) test whenever playerReplaceShip stops firing this event handler ***/
        if (this.$hyperspaceHangarRestoredShip) {
            // HyperSpaceHangar indicated it's restoring a ship, so this event isn't consequence of a ship purchase
            this.$hyperspaceHangarRestoredShip = false;
            return;
        }
    /*** end dybal ***/
        this.$ShipVersion_SLCost();//save cost of increasing sercive level on current player ship
        player.ship.awardEquipment("EQ_SERVICE_LEVEL_"+player.ship.serviceLevel);
        this.$ShipVersion_ServiceLevelPrev = player.ship.serviceLevel;
        if( this.$ShipVersion_Debug )
            log("ShipVersion", "Service level when bought: "+player.ship.serviceLevel+"%"); //debug
        var shname = this.$ShipVersion_PlayerShipName();
        if( (this.$ShipVersion_PlayerShipDataKey && this.$ShipVersion_PlayerShipDataKey.length > 0
            || this.$ShipVersion_storedShipString && this.$ShipVersion_storedShipString.length > 0)
            && !this.$ShipVersion_ReplaceShip ) { //there are stored old ship and not in buy loop
            var options = {
                "1_NO" : "No",
                "2_YES" : "Yes, I Confirm"
            };
            var desc = "";
            if(worldScripts["rocketmenu"]) //detailed ship info newest version
                desc=worldScripts["rocketmenu"].$RocketMenu_GetPlayerShipData();
            else if(worldScripts["hardmenu"]) //detailed ship info new version
                desc=worldScripts["hardmenu"].$HardMenu_GetPlayerShipData();
            else desc=this.$ShipVersion_GetPlayerShipData(); //old version
            if(desc.length > 0) desc+="\n\n";
            mission.runScreen({
                title: shname ,
                      message: desc+"You have "+formatCredits(this.$ShipVersion_PlayerCredits, false, true)+", "+
                          "if you buy you will have "+formatCredits(player.credits, false, true)+".\n"+
                          "Are you sure to buy "+shname+" ?",
                choices: options,
                model: "["+ship.dataKey+"]",
                background: "start_choices_bg.png"
            },
            function (choice) {
                if (choice === "1_NO") { //get back the old ship and money
                    player.credits = this.$ShipVersion_PlayerCredits;
                    this.$ShipVersion_ReplaceShip = true;//prevent buy loop
                    if(worldScripts["Ship_Storage_Helper.js"]) { //new restore method
                        worldScripts["Ship_Storage_Helper.js"].restoreStoredShip(this.$ShipVersion_storedShipString);
                    } else { //old restore method
                        player.replaceShip( this.$ShipVersion_PlayerShipDataKey, //the old ship
                            this.$ShipVersion_PlayerShipPersonality ); //and old version
                        var i=-1;
                        var eq = player.ship.equipment; //local variable, faster
                        while(eq[++i]) {
                            if( eq[i].name.length > 0 ) {
                                player.ship.removeEquipment(eq[i].equipmentKey);
                            } else {//skip noname eqs awarded by NumericHUD to avoid timeLimit error
                                for( var j = i + 10; j < eq.length; j+=10 ) {
                                    if( eq[j].name.length != 0 ) {
                                        i = j - 10; //end of skip
                                        j = eq.length;
                                    }
                                }
                                while( i < eq.length && eq[i].name.length == 0 ) i++;
                                i--;
                            }
                        }
                        i=-1;
                        while(this.$ShipVersion_PlayerShipEqs[++i]) {//give back equipments
                            player.ship.awardEquipment(this.$ShipVersion_PlayerShipEqs[i]);
                            if(this.$ShipVersion_PlayerShipEqDmg[i])
                                player.ship.setEquipmentStatus(
                                    this.$ShipVersion_PlayerShipEqs[i],
                                    "EQUIPMENT_DAMAGED");
                        }
                        i=this.$ShipVersion_PlayerShipPCap;
                        while(i-- > 1) player.ship.awardEquipment("EQ_PASSENGER_BERTH");
                        player.ship.fuel = this.$ShipVersion_PlayerShipFuel;
                        i=-1;
                        while(this.$ShipVersion_PlayerShipPass[++i]) //give back passengers
                            player.ship.addPassenger(this.$ShipVersion_PlayerShipPass[i][1],
                                this.$ShipVersion_PlayerShipPass[i][2],
                                this.$ShipVersion_PlayerShipPass[i][3],
                                this.$ShipVersion_PlayerShipPass[i][4] + clock.seconds,
                                this.$ShipVersion_PlayerShipPass[i][5],
                                this.$ShipVersion_PlayerShipPass[i][6]);
                        var c;
                        for (i = 0; i < this.$ShipVersion_PlayerShipMan.length; i++) {
                            c = this.$ShipVersion_PlayerShipMan[i].commodity;
                            player.ship.manifest[c] = this.$ShipVersion_PlayerShipMan[i].quantity;
                        }
                        player.ship.serviceLevel = this.$ShipVersion_PlayerShipServiceLevel;
                        player.ship.forwardWeapon = this.$ShipVersion_PlayerShipWeapons[0];
                        player.ship.aftWeapon = this.$ShipVersion_PlayerShipWeapons[1];
                        player.ship.portWeapon = this.$ShipVersion_PlayerShipWeapons[2];
                        player.ship.starboardWeapon = this.$ShipVersion_PlayerShipWeapons[3];
                    }
                    this.$ShipVersion_ReplaceShip = false;//end of replace
                    shname = this.$ShipVersion_PlayerShipName();
                    mission.exitScreen = "GUI_SCREEN_SHIPYARD";//back to the shipyard if not bought
                } else {
                    var shipVersion = this.$ShipVersion_Int(player.ship);
                    if(player.ship.equipmentStatus("EQ_SHIP_VERSION_"+shipVersion) === "EQUIPMENT_UNAVAILABLE")
                        player.ship.awardEquipment("EQ_SHIP_VERSION_"+shipVersion);
    /*** begin dybal ***/
                    // if HyperSpaceHangar is installed, call its $offerOldShipStorage function
                    // that function would have been be called in its playerBoughtNewShip event handler if we 
                    // had not "hijacked" its screen opportunity
                    if (worldScripts.HyperspaceHangar) {
                        // first we must setup what was cleaned by HH up while the player looked at our ship buying detail screen
                        worldScripts.HyperspaceHangar._actuallyBought = 1;
                        var _oldShip = JSON.parse(this.$ShipVersion_storedShipString);
                        _oldShip[8].length = 0; // clear ship's Cargo Hold
                        _oldShip[10].length = 0; // "space" ship's passengers :-)
                        _oldShip[31] = ""; // clear ship's Smuggler Hold
                        worldScripts.HyperspaceHangar._currentShip = JSON.stringify(_oldShip);
                        worldScripts.HyperspaceHangar.$offerOldShipStorage(ship, price);
                    }
    /*** end dybal ***/
                }
            });
            
        }
    //    if( this.$ShipVersion_Debug ) player.consoleMessage("The "+shname+" is yours!", 10);
        this.$ShipVersion_Ships[0] = player.ship;
        this.$ShipVersion_ServiceLevelCounter = 0;
        if( worldScripts["detectors"] ) worldScripts["detectors"].$Detectors_NameSave(player.ship);
        else if( ship.script ) ship.script.$Detectors_Origname = shname; //log support without Detectors
    
    }
    
    this.shipSpawned = function(ship) {  //do not give version numbers to cargo, etc.
    /*** begin dybal ***/
        /*** small performance improvement, worthwhile since this de-referencing would be done a lot of times when
             this event triggers, and it triggers a lot and in a bunch at system populating time ***/
        var wsHardShips = worldScripts["hardships"]; // de-referencing hardShips worldScript just once
    /*** end dybal ***/
    
        if( !ship.isPiloted || ship.isStation || ship.isThargoid || ship.primaryRole === "escape-capsule" ) return;
            if( ship.scriptInfo ) {
                    if(ship.scriptInfo.ccl_missionShip ) return;//mission ship by Svengali
                    var v = parseInt( ship.scriptInfo.shipversion );
                    if( v && v < 0 ) return; //disabled by shipversion = -1
            }
        if( this.$ShipVersion_BasicRulesOnly //skip custom roles
            && ship.primaryRole != "trader" && ship.primaryRole != "scavenger"
            && ship.primaryRole != "hunter" && ship.primaryRole != "miner"
            && ship.primaryRole != "pirate" && ship.primaryRole != "police"
            && ship.primaryRole != "wingman" && ship.primaryRole != "interceptor"
            && ship.primaryRole != "escort" && ship.primaryRole != "shuttle" ) return;
    
        var shipVersion = this.$ShipVersion_Int(ship); // 10-100
        if(ship.equipmentStatus("EQ_SHIP_VERSION_"+shipVersion) === "EQUIPMENT_UNAVAILABLE")
            ship.awardEquipment("EQ_SHIP_VERSION_"+shipVersion); //need to made damageable the timed bonuses
    //    if( this.$ShipVersion_Debug )
    //        player.consoleMessage(ship.name+" "+ship.equipmentStatus("EQ_SHIP_VERSION_"+shipVersion));
        
        if( !ship.isPlayer && this.$ShipVersion_Ships.indexOf(ship) < 0) {//only new NPC ships
            this.$ShipVersion_Ships[this.$ShipVersion_Ships.length] = ship;//store the new ship
            if( !worldScripts["detectors"] ) {//detectors use different function to show the version number
                ship.displayName += this.$ShipVersion_Show(ship); // 1 - 10 or 1.0 - 10.0
                //support to show (and log) names with version number without Detectors OXP also
                if( ship.script ) ship.script.$Detectors_Origname = ship.displayName;
            }
            //Ship Version one-time changes, do only once
            ship.accuracy += shipVersion / 20; //AI level tweak, +0.5 - +5
            //ship.thrust = ship.maxThrust*(0.5+shipVersion/100); //only weakenable, 0.1:half, 5.0-10.0:normal
            var v = Math.floor( shipVersion / 10 );//the first number of the version
            v = Math.min( v, this.$ShipVersion_AwardMax ); //limit the award
            if( ship.mass < 3000 ) v = 0; //drones not awarded with eqs, but get recharge and AI bonus
            var small = true; //Adder, Rocket Fighter and Gunship, but Runner and Corvette is not small
            if( ship.mass >= 30000 ) small = false;
            var largebounty = 0;
            var large = true; //from Cobra III and Rocket Miner
            if( ship.mass < 130000 ) large = false;
            else switch( v ) {  //add more bounty for large ships with high versions
                case 10: largebounty = 100; break; //100 from v10 and 100 from large means 200 in total
                case 9: largebounty = 60; break; //90+60=150 in total
                case 8: largebounty = 20; break; //80+20=100 in total
            }
            if( !small && ship.bounty > 0 ) //add version*10% for non-small ships
                ship.setBounty( ship.bounty + v * 10 + largebounty, "ShipVersion" + v );
    /*** begin dybal ***/
            //if( !small && worldScripts["hardships"] )
            if( !small && wsHardShips )
    /*** end dybal ***/
                ship.awardEquipment("EQ_HARDSHIELD_"+v);//but do not award Hard Armour
            switch( v ) {
            case 10:
                ship.awardEquipment("EQ_CLOAKING_DEVICE");
                ship.cloakAutomatic = true;
                if(ship.missiles && ship.missiles.length == ship.missileCapacity)
                        ship.removeEquipment("EQ_MISSILE"); //make room for QC_Mine
                if(ship.missiles && ship.missiles.length >= ship.missileCapacity - 1)
                        ship.removeEquipment("EQ_MISSILE");
                if(ship.missiles && ship.missiles.length == ship.missileCapacity)
                        ship.removeEquipment("EQ_HARDENED_MISSILE");
                if(ship.missiles && ship.missiles.length >= ship.missileCapacity - 1)
                        ship.removeEquipment("EQ_HARDENED_MISSILE");
                ship.awardEquipment("EQ_QC_MINE"); 
                ship.awardEquipment("EQ_QC_MINE"); 
                //NPCs often destroy yourself by your own QC_Mine so do not award to lower versions
                //will get 1.5x Military IronHide Armour from HardShips OXP directly, not here
    /*** begin dybal ***/
                //if( !small && worldScripts["hardships"])
                if( !small && wsHardShips)
    /*** end dybal ***/
                    ship.awardEquipment("EQ_ANTISAPPER"); //required HardShield10, awarded above
                //no break means get all of the following equipments also
            case 9:
                if( large ) ship.awardEquipment("EQ_MILITARY_JAMMER");
                if( large ) ship.awardEquipment("EQ_NAVAL_ENERGY_UNIT");
    /*** begin dybal ***/
                //if( !small && worldScripts["hardships"] ) {
                if( !small && wsHardShips ) {
    /*** end dybal ***/
                    if( ship.bounty > 0 ) {
                        ship.awardEquipment("EQ_EEG");
                        ship.awardEquipment("EQ_HTCAT"); //requires EEG and clean status
                    }
                    if( large && worldScripts["shieldequalizercapacitors"]
                        && worldScripts["customshields"] )
                        ship.awardEquipment("EQ_BIGSHCAP");
                }
            case 8:
                if( large && worldScripts["customshields"] )
                    ship.awardEquipment("EQ_SHIELD_ENHANCER"); //give increased recharge rate also
                //will get Military IronHide Armour from HardShips OXP automatically, do not award here
    /*** begin dybal ***/
                //if( large && worldScripts["hardships"]) ship.awardEquipment("EQ_VERYHARDNOSE");
                if( large && wsHardShips) ship.awardEquipment("EQ_VERYHARDNOSE");
    /*** end dybal ***/
            case 7:
                if( large ) ship.awardEquipment("EQ_MILITARY_SCANNER_FILTER");
                //ship.awardEquipment("EQ_NAVAL_SHIELD_BOOSTER"); //not used by CustomShields OXP
    /*** begin dybal ***/
                //if( !small && worldScripts["hardships"] ) {
                if( !small && wsHardShips ) {
    /*** end dybal ***/
                    ship.awardEquipment("EQ_ADDITIONAL_AFT_ARMOUR");
                    if(ship.equipmentStatus("EQ_EEG")!="EQUIPMENT_OK") ship.awardEquipment("EQ_EEG");
                    ship.awardEquipment("EQ_ESG"); //requires EEG
                }
                if( worldScripts["shieldequalizercapacitors"] ) {
                    ship.awardEquipment("EQ_SHIELD_EQUALIZER");
                    if( !small ) {
                        ship.awardEquipment("EQ_FORWARD_SHIELD_CAPACITOR");
                        ship.awardEquipment("EQ_AFT_SHIELD_CAPACITOR");
                    }
                }
            case 6:
                ship.awardEquipment("EQ_FUEL_INJECTION");
    /*** begin dybal ***/
                //if( !small && worldScripts["hardships"]) {
                if( !small && wsHardShips) {
    /*** end dybal ***/
                    ship.awardEquipment("EQ_ADDITIONAL_FRONT_ARMOUR");
                    ship.awardEquipment("EQ_INJECTOR_BOX");
                    if( ship.equipmentStatus("EQ_EEG")!="EQUIPMENT_OK")
                        ship.awardEquipment("EQ_EEG");
                }
                if( !small && worldScripts["Q-Charger"]) worldScripts["Q-Charger"].awardQCharger(ship);
            case 5:
                if(worldScripts["Shield Cycler"]) ship.awardEquipment("EQ_SC_SHIELD_CYCLER_INTERNAL");
                //will get IronHide Armour from HardShips OXP automatically, do not award here
    /*** begin dybal ***/
                //if( !small && worldScripts["hardships"] &&
                if( !small && wsHardShips &&
    /*** end dybal ***/
                    ship.equipmentStatus("EQ_VERYHARDNOSE") != "EQUIPMENT_OK" )
                    ship.awardEquipment("EQ_HARDNOSE");
                var i = 0;
                while(i++ < ship.missileCapacity) //missiles get ECM hardening
                    if(ship.equipmentStatus("EQ_MISSILE") == "EQUIPMENT_OK")
                        ship.removeEquipment("EQ_MISSILE");
                i = 0;
                if(ship.missiles) i = ship.missiles.length;
                if( !small ) while (i++ < ship.missileCapacity) ship.awardEquipment("EQ_HARDENED_MISSILE");
            case 4:
                if( !small && worldScripts["customshields"] ) ship.awardEquipment("EQ_SHIELD_BOOSTER");
    /*** begin dybal ***/
                //if( !small && worldScripts["hardships"] ) {
                if( !small && wsHardShips ) {
    /*** end dybal ***/
                    ship.awardEquipment("EQ_ADDITIONAL_CORE_HULL");
                    ship.awardEquipment("EQ_SHIELD_BOX");
                    if( ship.bounty > 0 ) ship.awardEquipment("EQ_REG"); //requires not clean status
                }
            case 3:
                ship.awardEquipment("EQ_ENERGY_UNIT");
    /*** begin dybal ***/
                //if( !small && worldScripts["hardships"] ) ship.awardEquipment("EQ_EQUIPMENT_BOX");
                if( !small && wsHardShips ) ship.awardEquipment("EQ_EQUIPMENT_BOX");
    /*** end dybal ***/
            case 2:
                ship.awardEquipment("EQ_ECM");
    /*** begin dybal ***/
                //if( !small && worldScripts["hardships"]) {
                if( !small && wsHardShips ) {
    /*** end dybal ***/
                    ship.awardEquipment("EQ_ELECTRONICS_BOX");
                    if( ship.cargoSpaceCapacity > 1660 ) ship.awardEquipment("EQ_DUMMY100"); //and smallers also
                    if( ship.cargoSpaceCapacity > 660 ) ship.awardEquipment("EQ_DUMMY50");
                    if( ship.cargoSpaceCapacity > 150 ) ship.awardEquipment("EQ_DUMMY10");
                    if( ship.cargoSpaceCapacity > 50 ) ship.awardEquipment("EQ_DUMMY5");
                    if( ship.cargoSpaceCapacity > 10 ) ship.awardEquipment("EQ_DUMMY1");
                }
            case 1:
    //            ship.awardEquipment("EQ_MILITARY_JAMMER");//debug
                ship.awardEquipment("EQ_ESCAPE_POD");
    /*** begin dybal ***/
                //if( !small && worldScripts["hardships"]) ship.awardEquipment("EQ_LIFE_BOX");
                if( !small && wsHardShips ) ship.awardEquipment("EQ_LIFE_BOX");
    /*** end dybal ***/
            default: //do not give anything if AwardMax 0
            }
            
            var br = shipVersion * 2 / 256; //higher version brighter (0 - 0.78)
            var br2 = 0.5 + br / 2; //brighter purple and orange (0.5 - 0.89)
            if( this.$ShipVersion_Colors ) { //color adjustments on IFF
                if(ship.primaryRole === "police" || ship.primaryRole === "interceptor"
                    || ship.primaryRole === "wingman" || ship.isPolice) { //police ship
                    ship.scannerDisplayColor1 = br2+" 0 "+br2; //bright purple
                            if(ship.target === player.ship) {//works automatic, not needed
                                ship.scannerDisplayColor2 = null;//not flashing
                            } else ship.scannerDisplayColor2 = "1 0 1";//magenta flash
                } else this.$ShipVersion_TimedColors(ship, shipVersion);
            }
        }
        ship.missileLoadTime /= ( shipVersion + 5 ) / 50; //10.0: half, 4.5: normal, 2.0: double
    //    if( worldScripts["customshields"] ) worldScripts["customshields"].shipSpawned(ship); //surely add shield bonuses - removed due to cause InternalError: too much recursion
    //    if( this.$ShipVersion_Debug ) player.consoleMessage(ship.displayName+" spawned.", 5);
    }
    
    this.shipWillEnterWitchspace = function(cause) {
        if( this.$ShipVersion_Debug )
            player.consoleMessage("Deleted "+this.$ShipVersion_Ships.length+" ship, doing "+cause+".", 10);
        delete this.$ShipVersion_Ships;
        this.$ShipVersion_Ships = [ player.ship ]; //start a new array in the new system
    }
    
    this.$ShipVersion_EQLimiter = function( eq, equipmentKey, mass ) {
    //    player.consoleMessage( equipmentKey+" "+mass+" "+player.ship.mass );//debug
        if( equipmentKey == eq && player.ship.mass < mass ) {
            player.ship.removeEquipment( eq );
            player.consoleMessage("Your ship can not hold "+
                EquipmentInfo.infoForKey( eq ).name+", removed.", 5);
            player.credits += EquipmentInfo.infoForKey( eq ).price/10;
            return false;
        }
        return true;
    }
    
    this.$ShipVersion_GetPlayerShipData = function() {
        //detailed ship info old version, new can be found in rocketmenu.js of the RocketShips OXP
        var equip="";
        var s=""; 
        s=player.ship.forwardWeapon;
        if(s!=null) equip+="Forward "+s.name;
        s=player.ship.aftWeapon;
        if(s!=null) equip+=", Aft "+s.name;
        s=player.ship.portWeapon;
        if(s!=null) equip+="\nPort "+s.name;
        s=player.ship.starboardWeapon;
        if(s!=null) equip+=", Starboard "+s.name;
        if(equip.length > 0) equip+="\n";
        else equip+="No Laser\n";
        var eqs = "";
        var n = "";
        var eq = player.ship.equipment;
        var i=-1;
        while(eq[++i]) {
            n = eq[i].name;
            if( n.length > 0 ) eqs += n + ", ";
            else {    //skip noname eqs awarded by NumericHUD to avoid timeLimit error
                for( var j = i + 10; j < eq.length; j+=10 ) {
                    if( eq[j].name.length != 0 ) {
                        i = j - 10; //end of skip
                        j = eq.length;
                    }
                }
                while( i < eq.length && eq[i].name.length == 0 ) i++;
                i--;
            }
        }
        eqs = eqs.substr(0, eqs.length - 2); //cut last comma
        if(eqs.length > 0) equip+=eqs+"\n\n";
        else equip+="\n";//empty line before desc if no eqs
        var desc = "";
        if(player.ship.scriptInfo && player.ship.scriptInfo.buydesc)//show ship description if any
            desc="\""+player.ship.scriptInfo.buydesc+"\"\n\n";
        var sh = player.ship.maxForwardShield;
        if( worldScripts["shieldequalizercapacitors"] ) {
            if( player.ship.equipmentStatus("EQ_BIGSHCAP") == "EQUIPMENT_OK"
                && player.ship.equipmentStatus("EQ_FORWARD_SHIELD_CAPACITOR") == "EQUIPMENT_OK" )
                sh = sh + "+256";
            else if( player.ship.equipmentStatus("EQ_FORWARD_SHIELD_CAPACITOR") == "EQUIPMENT_OK" )
                sh = sh + "+64";
        }
        var psd = "";//player.ship.displayName+
        psd += "Speed: "+(player.ship.maxSpeed)+" mLS  Thrust: "+player.ship.maxThrust+
            "  Pitch: "+Math.round(player.ship.maxPitch*100)/100+
            "  Roll: "+Math.round(player.ship.maxRoll*100)/100+
            "  Yaw: "+Math.round(player.ship.maxYaw*100)/100+
    //        "  Version: "+this.$shipVersion(player.ship)+
    //        "  Service "+player.ship.serviceLevel+
            "\nCargo Space: "+player.ship.cargoSpaceCapacity;
        if(player.ship.scriptInfo && player.ship.scriptInfo.cargoext && parseInt(player.ship.scriptInfo.cargoext) > 0)
            psd += "+"+parseInt(player.ship.scriptInfo.cargoext);
        psd += "t  Mass: "+Math.max(Math.round(player.ship.mass/1000), 10)+ //min.10t
            "t  Size: "+Math.round(player.ship.boundingBox.x)+"*"+
            Math.round(player.ship.boundingBox.y)+"*"+Math.round(player.ship.boundingBox.z)+"m Radius:"+
            Math.round(player.ship.collisionRadius)+
            "m\nEnergy: "+player.ship.maxEnergy+"  Shield: "+sh+"  Max.Missile: "+player.ship.missileCapacity;
        psd += "\n"+equip+desc+"Price: "+formatCredits(player.ship.price, false, true);
        return(psd);
    }
    
    this.$ShipVersion_Int = function(ship) { //integer version number
        if( !ship ) return( 10 ); //default
        if( ship.scriptInfo ) {
            var v = parseInt( ship.scriptInfo.shipversion );
            if( v ) {
                if( v <= 1 ) return( 10 );
                if( v >= 10 ) return( 100 );
                if( v > 1 && v < 10 ) return( 10 * v );
            }
        }
        return( Math.max( 10, Math.floor( ship.entityPersonality/328 ) + 1 ) ); // 10 - 100
    }
    
    this.$ShipVersion_Display = function(shipVersion, simple) { //format the integer version to displayable string
        var st = shipVersion / 10;
        var sv = " "; //start with a space to easily add to the original name
        if( simple )  sv += Math.floor( st ); // 1 - 10
        else {
            sv += st;
            if( st ==  Math.floor( st ) )  sv += ".0";
        }
        return( sv ); // 1.0 - 10.0
    }
    
    this.$ShipVersion_PlayerShipName = function() { //with full version number
        return(player.ship.displayName + this.$ShipVersion_Display( this.$ShipVersion_Int( player.ship ), false ));
    }
    
    this.$ShipVersion_Show = function(ship) { //string version number of a ship
        if( this.$ShipVersion_Simple )
            return( this.$ShipVersion_Display( this.$ShipVersion_Int( ship ), true ) );
        else
            return( this.$ShipVersion_Display( this.$ShipVersion_Int( ship ), false ) );
    }
    
    this.$ShipVersion_SL = function( sl ) { //name of the service level
        if( sl >= 100 ) return("Perfect");
        if( sl >= 90 ) return("Good");
        if( sl >= 80 ) return("Weak");
        if( sl >= 76 ) return("Bad");
        if( sl < 76 ) return("Minimal");
        return("Unknown");
    }
    
    this.$ShipVersion_SLCost = function() { //cost of 1% service level repair
            if(player.ship.docked) { //next line works in docks only
                this.$ShipVersion_SLCr = Math.round( player.ship.price * 0.005 ); //0.5% of the new price
            }
        return( this.$ShipVersion_SLCr );
    }
    
    this.$ShipVersion_Timed = function() { //Ship Version repeated changes, called once in a second
    //    player.ship.setEquipmentStatus("EQ_SHIP_VERSION_"+this.$ShipVersion_Int(player.ship), "EQUIPMENT_DAMAGED");//debug
        if( !player.ship || !player.ship.isValid ) return;
    
        if( this.$ShipVersion_ServiceLevelPrev == 0 ) {
            player.ship.awardEquipment("EQ_SERVICE_LEVEL_"+player.ship.serviceLevel);
            this.$ShipVersion_ServiceLevelPrev = player.ship.serviceLevel; //save
            if( this.$ShipVersion_Debug )
                log("ShipVersion", "Service level "+player.ship.serviceLevel+"%"); //debug
        }
        
        if( this.$ShipVersion_ServiceLevelPrev != player.ship.serviceLevel ) {
            var st = player.ship.equipmentStatus("EQ_SERVICE_LEVEL_"+this.$ShipVersion_ServiceLevelPrev);
            player.ship.removeEquipment("EQ_SERVICE_LEVEL_"+this.$ShipVersion_ServiceLevelPrev);
            player.ship.awardEquipment("EQ_SERVICE_LEVEL_"+player.ship.serviceLevel);
            if( st == "EQUIPMENT_DAMAGED" ) //set to damaged
                player.ship.setEquipmentStatus("EQ_SERVICE_LEVEL_"+player.ship.serviceLevel, st);
            if( this.$ShipVersion_ServiceLevelPrev > player.ship.serviceLevel
                && !player.ship.docked ) { //to avoid message when buy new ship with different SL
                //if( player.ship.serviceLevel > 76) {
                    player.consoleMessage("Service level degraded ("+
                        this.$ShipVersion_SL(player.ship.serviceLevel)+")", 5);
                //} else if( player.ship.serviceLevel > 75)
                            //    player.consoleMessage("Weapons almost destroyed, repair the ship!", 5);
            } //if SL increased then no message to avoid it when another OXP increase it
              //for example HardShips OXP after hauler is not confirmed in the start menu
            if( this.$ShipVersion_Debug )
                log("ShipVersion", "Service level changed from "+
                    this.$ShipVersion_ServiceLevelPrev+"% to "+
                    player.ship.serviceLevel+"%"); //debug
            else {
                var c = "decreased";
                if( this.$ShipVersion_ServiceLevelPrev < player.ship.serviceLevel )
                    c = "increased";
                log("ShipVersion", "Service level "+c+" ("+
                    this.$ShipVersion_SL(player.ship.serviceLevel)+")");
            }
            this.$ShipVersion_ServiceLevelPrev = player.ship.serviceLevel; //save
        }
        
    //    if( player.ship.serviceLevel > 86 ) player.ship.serviceLevel = 76; //debug
        
        if( player.ship.serviceLevel <= 75 ) {
            var w1 = player.ship.forwardWeapon;
            var w2 = player.ship.aftWeapon;
            var w3 = player.ship.portWeapon;
            var w4 = player.ship.starboardWeapon;
        //    if( w1 ) player.ship.forwardWeapon = null;
        //    if( w2 ) player.ship.aftWeapon = null;
        //    if( w3 ) player.ship.portWeapon = null;
        //    if( w4 ) player.ship.starboardWeapon = null;
        //    if(player.ship.subEntities)
            //            for(var i = 0; i < player.ship.subEntities.length; i++) //remove turrets
        //        player.ship.subEntities[i].remove();
            //      for(var j = 0; j < player.ship.subEntities.length; j++) { //remove missiles
        //        player.ship.removeEquipment("EQ_MISSILE");
        //        player.ship.removeEquipment("EQ_HARDENED_MISSILE");
        //        player.ship.removeEquipment("EQ_QC_MINE");
        //    }
        //    if( w1 || w2 || w3 || w4 || i > 0 || j > 0 ) //no docked check, need to show in dock also
        //        player.consoleMessage("Weapons destroyed! Do ship maintenance before buy anothers!", 5);
        }
        
        if( player.ship.docked ) return; //no recharges in dock
        for( var i = 0; i < this.$ShipVersion_Ships.length; i++) {
            var ship = this.$ShipVersion_Ships[i];//all version-equipped ship
            if( ship && ship.isValid && ship.isVisible && ship.isPiloted
                && !ship.isThargoid  && !ship.isDerelict ) { //to save CPU time
                var shipVersion = this.$ShipVersion_Int(ship); // 10-100
                if( this.$ShipVersion_Colors ) this.$ShipVersion_TimedColors(ship, shipVersion);
                if( ship.equipmentStatus("EQ_SHIP_VERSION_"+shipVersion)!="EQUIPMENT_OK") return;
                var recharge = ( shipVersion - 10 ) / 100; // 0 - +0.9/s
                if( ship.energy < ship.maxEnergy )  ship.energy += recharge * 2; // 0 - +1.8/s
                            //if( ship.temperature > recharge && shipVersion > 10 )  ship.temperature -= recharge;
                            //0 - -0.9/s, removed because cause buggy temperature drops with RocketShips OXP
                if( ship.isPlayer ) { //player only
                    if( ship.forwardShield < ship.maxForwardShield )  ship.forwardShield += recharge;
                    if( ship.aftShield < ship.maxAftShield )  ship.aftShield += recharge;
                    if( shipVersion > 79 //repair bot working from v8.0, only integer possible
                        && ship.equipmentStatus("EQ_SERVICE_LEVEL_"+ship.serviceLevel)
                            == "EQUIPMENT_OK" )  {
                        if( ship.serviceLevel < 80 ) {//Bad levels only
                                                    var cost = 100; //must be equal with cost of small fix in equipment.plist
                            this.$ShipVersion_ServiceLevelCounter++;
    //                        player.consoleMessage(this.$ShipVersion_ServiceLevelCounter);//debug
                            if( this.$ShipVersion_ServiceLevelCounter > 300
                                && cost <= player.credits ) {
                                ship.serviceLevel++; //+1% in every 5 minutes of flying
                                player.credits -= cost;
                                this.$ShipVersion_ServiceLevelCounter = 0;
                                ship.removeEquipment("EQ_SERVICE_LEVEL_"
                                    +this.$ShipVersion_ServiceLevelPrev);
                                ship.awardEquipment("EQ_SERVICE_LEVEL_"
                                    +ship.serviceLevel);
                                this.$ShipVersion_ServiceLevelPrev = ship.serviceLevel; //save
                                var msg = "Service level repaired a bit for "+cost+" credits ("+
                                    this.$ShipVersion_SL(ship.serviceLevel)+
                                    ")";
                                if( this.$ShipVersion_Debug )
                                    log("ShipVersion", "Service level repaired to "
                                        +ship.serviceLevel+"% for "
                                        +cost+" credits"); //debug
                                else log("ShipVersion", msg);
                                player.consoleMessage(msg, 10);
                            } else if( this.$ShipVersion_ServiceLevelCounter > 300 ) {
                                this.$ShipVersion_ServiceLevelCounter = 0;
                                var msg = "Service level "+
                                    this.$ShipVersion_SL(ship.serviceLevel)+
                                    " but repair need "+cost+" credits";
                                if( this.$ShipVersion_Debug )
                                    log("ShipVersion", "Service level "
                                        +ship.serviceLevel+"% but repair need "
                                        +cost+" credits");
                                else log("ShipVersion", msg);
                                player.consoleMessage(msg, 10);
                            }
                        }
                    }
                } else { //NPC only
                    if(worldScripts["customshields"]) { //check if CustomShields installed
                        if( ship.script.customshieldsforwardshieldlevel <
                            ship.script.customshieldsmaxforwardshieldlevel )
                            ship.script.customshieldsforwardshieldlevel += recharge + 1;
                        if( ship.script.customshieldsaftshieldlevel <
                            ship.script.customshieldsmaxaftshieldlevel )
                            ship.script.customshieldsaftshieldlevel += recharge + 1;
                    }
                }
            }
        }
    }
    
    this.$ShipVersion_TimedColors = function(ship, shipVersion) {
        //must check continually to turn a yellow netural ship to red when decided to attack the player
        if( !ship || ship.isPolice || ship.isDerelict ) return; //not need to refresh
        //var br = shipVersion * 2 / 256; //higher version brighter (0 - 0.78)
        //var br2 = 0.5 + br / 2; //brighter purple and orange (0.5 - 0.89)
            if( ship.hasHostileTarget && ship.target === player.ship ) { //hostile ship
                    if(!ship.script) si.script = "oolite-default-ship-script.js"; //for sure
                    if(ship.script && !ship.script.$SV_oldscannerDisplayColor1)
                        ship.script.$SV_oldscannerDisplayColor1 = ship.scannerDisplayColor1;
            if( ship.mass >= 130000 ) ship.scannerDisplayColor1 = "1 0 0";//(2*br+0.2)+" 0 0"; //red
                    else ship.scannerDisplayColor1 = "1 0.2 0.2";//"1 "+(br-0.39)+" "+(br-0.39); //bright red
        } else if( ship.bounty > 0 ) {
                    if( ship.mass >= 130000 ) ship.scannerDisplayColor1 = "1 0.5 0";//dark orange
                    else ship.scannerDisplayColor1 = "1 0.6 0";//"1 "+br2+" "+br; //orange
        } else if( ship.isStation ) //friendly base
            ship.scannerDisplayColor1 = greenColor;
            else if( ship.script && ship.script.$SV_oldscannerDisplayColor1 ) {
                ship.scannerDisplayColor1 = ship.script.$SV_oldscannerDisplayColor1; //restore non-hostile color
                ship.script.$SV_oldscannerDisplayColor1 = null;
            }
    
        //else if( shipVersion >= 5 )
        //    ship.scannerDisplayColor1 = "1 1 "+(br-0.39); //bright yellow
        //else ship.scannerDisplayColor1 = (2*br+0.2)+" "+(2*br+0.2)+" 0"; //dark yellow
    }
    
    Scripts/shipversionrepair.js
    "use strict";
    this.name        = "shipversionrepair";
    this.author      = "Norby";
    this.copyright   = "2013 Norbert Nagy";
    this.licence     = "CC BY-NC-SA 3.0";
    this.description = "Repair Detectors equipment if damaged only.";
    this.version     = "1.0";
    
    this.allowAwardEquipment = function(eqKey, ship, context)
    {
    //	log("shipversionrepair", eqKey+ship.name+context+"EQ_SHIP_VERSION_"+
    //		worldScripts["shipversion"].$ShipVersion_Int(player.ship)+player.ship.equipmentStatus("EQ_SHIP_VERSION_"+
    //		worldScripts["shipversion"].$ShipVersion_Int(player.ship)) );//debug
    	if(eqKey==="EQ_SHIP_VERSION_REPAIR" && ship === player.ship && context === "purchase"
    		&& player.ship.equipmentStatus("EQ_SHIP_VERSION_"+
    			worldScripts["shipversion"].$ShipVersion_Int(player.ship)) != "EQUIPMENT_OK") {
    //		log("shipversionrepair", eqKey+ship.name+context+" true");
    		return true;
    	}
    //	log("shipversionrepair", eqKey+ship.name+context+" false");
    	return false;
    }
    
    Scripts/turretrecover.js
    "use strict";
    this.name        = "turretrecover";
    this.author      = "Norby";
    this.copyright   = "2013 Norbert Nagy";
    this.licence     = "CC BY-NC-SA 3.0";
    this.description = "Recover a turret if lost any.";
    this.version     = "1.0";
    
    this.allowAwardEquipment = function(eqKey, ship, context)
    {
    	if(eqKey==="EQ_TURRET_RECOVER" && ship === player.ship && context === "purchase"
    		&& ( !player.ship.subEntities && player.ship.subEntityCapacity > 0
    		|| player.ship.subEntities && player.ship.subEntityCapacity > player.ship.subEntities.length))
    			return true;
    	return false;
    }