Back to Index Page generated: Nov 12, 2024, 11:02:04 PM

Expansion Maintenance Tune Up

Content

Warnings

  1. Information URL mismatch between OXP Manifest and Expansion Manager string length at character position 0

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description Provides the ability to do a maintenance tune up, even when the normal overhaul is not available. Provides the ability to do a maintenance tune up, even when the normal overhaul is not available.
Identifier oolite.oxp.phkb.MaintenanceTuneUp oolite.oxp.phkb.MaintenanceTuneUp
Title Maintenance Tune Up Maintenance Tune Up
Category Equipment Equipment
Author phkb phkb
Version 0.4 0.4
Tags
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL n/a
Download URL https://wiki.alioth.net/img_auth.php/8/80/MaintenanceTuneUp.oxz n/a
License CC-BY-NC-SA 4.0 CC-BY-NC-SA 4.0
File Size n/a
Upload date 1656910538

Documentation

Also read http://wiki.alioth.net/index.php/Maintenance%20Tune%20Up

readme.txt

Maintenance Tune Up
By Nick Rogers

Overview
========
This OXP provides the facility for pilots to further tune up their ships, getting closer to brand-new performance. A tune up will only be offered at the same stations a maintenance overhaul is offered, and similar rules will apply (that is, you'll get a better tune up at higher tech level systems).

Operations
==========
The "Maintenance Tune Up" will be offered if the tech level of the system is high enough (ie. TL7 or greater). If an overhaul is currently due, the tune up will not be offered, although once the overhaul is performed, you may have an additional opportunity to purchase the tune up.

License
=======
This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 4.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/

Version History
===============
0.4
- Turned off debug flag to reduce messages in log file.

0.3
- Tune Up will now generate a maintenance-related email if the Email System is installed.
- Code refactoring.

0.2
- Correction to the minimum cost check.
- Reset variables after overhaul to ensure tune up will reappear.

0.1
- Initial release.

Equipment

Name Visible Cost [deci-credits] Tech-Level
Maintenance Tune Up no 1000 7+

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
Config/script.js
"use strict";
this.name					= "MaintenanceTuneUp_Core";
this.author					= "phkb";
this.copyright              = "2019 phkb";
this.description			= "Core operational script for Maintenance Tune Up";
this.licence                = "CC BY-NC-SA 4.0";

this._storedServiceLevel = 0;
this._storedTechLevel = 0;
this._debug = false;
this._cost = 0;

//-------------------------------------------------------------------------------------------------------------
this.startUpComplete = function() {
    if (!missionVariables.MaintenanceTuneUp_SL) missionVariables.MaintenanceTuneUp_SL = 0;
    if (!missionVariables.MaintenanceTuneUp_TL) missionVariables.MaintenanceTuneUp_TL = 0;
    this._storedServiceLevel = missionVariables.MaintenanceTuneUp_SL;
    this._storedTechLevel = missionVariables.MaintenanceTuneUp_TL;

    if (worldScripts.GalCopAdminServices) {
        var ga = worldScripts.GalCopAdminServices;
        ga._purchase_ignore_equip.push("EQ_MAINTENANCE_TUNEUP"); // don't sent a normal purchase email for this one
    }
}

//-------------------------------------------------------------------------------------------------------------
this.shipDockedWithStation = function(station) {
    if (this._debug) log(this.name, "Servicelevel when docking = " + player.ship.serviceLevel);
    if (this._debug) log(this.name, "Station TL = " + (station.equivalentTechLevel + 1));
}

//-------------------------------------------------------------------------------------------------------------
this.guiScreenChanged = function(to, from) {
    if (to === "GUI_SCREEN_EQUIP_SHIP") {
        this._cost = player.ship.renovationCost;
    }
}

//-------------------------------------------------------------------------------------------------------------
this.playerBoughtEquipment = function(equipment) {
    if (equipment === "EQ_RENOVATION") {
        if (this._debug) log(this.name, "Servicelevel after overhaul = " + player.ship.serviceLevel);
        if (this._debug) log(this.name, "Station TL = " + (player.ship.dockedStation.equivalentTechLevel + 1));
        // reset tune up observation variables
        this._storedServiceLevel = 0;
        this._storedTechLevel = 0;
    }
    if (equipment === "EQ_MAINTENANCE_TUNEUP") {
        // normal service level range is 75-84
        // calc for addition to service level is 5 + techLevel (of station or system, whichever applies)
        // worst service level is 75, best tech level is 14, lowest tech level is 6

        // in best scenario, for a normal renovation, the player would get back to a service level of 103 (84 + 19) but reduced to max 100.
        // in worst scenario, the player would get back to a service level of 86 (75 + 11)

        // so, if the player has servicelevel of 93, best would be +7, worst reno would be +1
        // if player has a servicelevel of 85, best would be +15, worst would be +1
        var diff = Math.floor((100 - player.ship.serviceLevel) * ((player.ship.dockedStation.equivalentTechLevel + 1) / 15));
        if (diff < 1) diff = 1;
        player.ship.serviceLevel += diff;
        this._storedServiceLevel = player.ship.serviceLevel;
        this._storedTechLevel = player.ship.dockedStation.equivalentTechLevel;
        player.ship.removeEquipment("EQ_MAINTENANCE_TUNEUP");

        if (worldScripts.GalCopAdminServices) {
            var ga = worldScripts.GalCopAdminServices;
            ga._maintCost = this._cost / 10;
            ga.$setupRepNames();
            ga.$sendMaintenanceEmail();
        }
    }
}

//-------------------------------------------------------------------------------------------------------------
this.playerWillSaveGame = function() {
    missionVariables.MaintenanceTuneUp_SL = this._storedServiceLevel;
    missionVariables.MaintenanceTuneUp_TL = this._storedTechLevel;
}
Scripts/maintenance_tuneup_conditions.js
"use strict";
this.name					= "MaintenanceTuneUp_Conditions";
this.author					= "phkb";
this.copyright              = "2019 phkb";
this.description			= "Condition script for Maintenance Tune Up";
this.licence                = "CC BY-NC-SA 4.0";

//-------------------------------------------------------------------------------------------------------------
this.allowAwardEquipment = function(equipment, ship, context) {
    if (context === "scripted") return true;
    if (equipment === "EQ_MAINTENANCE_TUNEUP") {
        if (ship.canAwardEquipment("EQ_RENOVATION") == true) return false;
        if (ship.serviceLevel >= 98) return false;
        var mtu = worldScripts.MaintenanceTuneUp_Core;
        var p = player.ship;
        if (p.serviceLevel.toFixed(0) == mtu._storedServiceLevel.toFixed(0) && p.dockedStation.equivalentTechLevel <= mtu._storedTechLevel) {
            return false;
        }
    
        return true;
    }
    return false;
}

//-------------------------------------------------------------------------------------------------------------
this.updateEquipmentPrice = function(equipment, price) {
    var newprice = price;
    var p = player.ship;
    if (equipment === "EQ_MAINTENANCE_TUNEUP") {
        newprice = p.renovationCost;
        if (newprice < 10000) newprice = 10000; // set a minimum price
    }
    return newprice;
}