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

Expansion Bounty Informer

Content

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description This device gives you access to the bounty registry of police criminal database. This device gives you access to the bounty registry of police criminal database.
Identifier oolite.oxp.AndreyBelov.BountyInformer oolite.oxp.AndreyBelov.BountyInformer
Title Bounty Informer Bounty Informer
Category Equipment Equipment
Author Andrey Belov aka timer Andrey Belov aka timer
Version 2.0 2.0
Tags
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL http://wiki.alioth.net/index.php/Bounty_Informer_OXP n/a
Download URL https://wiki.alioth.net/img_auth.php/b/b7/BountyInformer.oxz n/a
License CC-BY-NC-SA 3.0 CC-BY-NC-SA 3.0
File Size n/a
Upload date 1677574456

Documentation

Also read http://wiki.alioth.net/index.php/Bounty%20Informer

Readme.txt

Bounty Informer OXP
===================

== Overview ==

This device gives you access to the bounty registry of the GalCop (Police) criminal database.


== Requires ==

- Oolite 1.81
- You must have bought the "Scanner Targeting Enhancement" before this becomes available.


== About original version ==

The original idea and implementation of this useful OXP was written by Frame - Bounty Scanner.
In this version of the OXP a different code base has been used.


== History ==

2023-02-28 v2.0 - Total refactoring and use another API for display bounty.
                  Now compatible with "Randomshipnames OXP"

2014-08-31 v1.0 - Initial release


== Links ==

https://wiki.alioth.net/index.php/Bounty_Informer_OXP
http://aegidian.org/bb/viewtopic.php?p=233763


== Licence ==

CC BY-NC-SA 3.0
see http://creativecommons.org/licenses/by-nc-sa/3.0/ for more info.

Equipment

Name Visible Cost [deci-credits] Tech-Level
Bounty Informer yes 18500 10+
Sell Bounty Informer yes 150 10+

Ships

This expansion declares no ships.

Models

This expansion declares no models.

Scripts

Path
Scripts/bounty-informer.js
(function(){
'use strict';

this.name        = 'Bounty Informer';
this.author      = 'Andrey Belov';
this.copyright   = '© 2023 Andrey Belov aka timer [ TiNe Corp. ]';
this.licence     = 'CC BY-NC-SA 3.0'; // see http://creativecommons.org/licenses/by-nc-sa/3.0/ for more info.
this.description = 'This device gives you access to the bounty registry of police criminal database.';
this.version     = '2.0';


let _binf_disabled = false;
let _binf_timer    = false;
let _binf_bountyRE = /((?:Bounty )? )([\d\.]+)( ₢)/;


this.$disableBountyInformer = function() {
    _binf_disabled = true;
    this._binf_stopPeriodicalCheck( player.ship.target );
};

this.$enableBountyInformer = function() {
    _binf_disabled = false;
};

this.shipWillDockWithStation = function(station) {
    this._binf_stopPeriodicalCheck(false);
};

this.shipTargetLost = this.shipTargetCloaked = function(target) {
    this._binf_stopPeriodicalCheck(target);
};

this._binf_stopPeriodicalCheck = function(target) {
    if ( _binf_timer && _binf_timer.isRunning ) {
        _binf_timer.stop();
    }
    if (target) {
        this._binf_removeBountyInfo(target);
    }
};

this._binf_startPeriodicalCheck = function(delay) {
    if ( _binf_timer ) {
        if ( ! _binf_timer.isRunning ) _binf_timer.start();
    }
    else {
        _binf_timer = new Timer( this, this._binf_scanAndUpdate, delay||0, 5 );
    }
};

this.shipTargetAcquired = function(target) {
    if ( _binf_disabled ) return;
    if ( this._binf_scanAndUpdate(target) ) this._binf_startPeriodicalCheck(5);
};

this._binf_scanAndUpdate = function(target) {
    let pship = player.ship;
    target = target || pship.target;

    if ( ! target || _binf_disabled
         || pship.equipmentStatus('EQ_BOUNTY_INFORMER') !== 'EQUIPMENT_OK'
         || pship.status === 'STATUS_DOCKED'
         || ! target.isShip
         || target.isCloaked
         || target.isJamming
         || target.isCargo ) {

        this._binf_stopPeriodicalCheck(target);
        return false;
    }

    let bounty = this.$getBounty(target);

    if ( bounty > 0 ) {
        let desc  = target.scanDescription || this.$initialScanDescription( target, bounty );
        let found = desc.match(_binf_bountyRE);
        if ( found && found.length === 4 ) {
            if ( (+found[2]) !== bounty ) {
                target.scanDescription = desc.replace( _binf_bountyRE, '$1'+bounty+'$3' );
            }
        }
        else {
            target.scanDescription = desc+' '+bounty+' ₢';
        }
    }
    else {
        this._binf_removeBountyInfo(target);
    }

    if ( target.scanClass === 'CLASS_ROCK' ) return false;

    return true;
};

this._binf_removeBountyInfo = function(target) {
    if ( ! target || target.scanDescription === null ) return;
    let initDesc = target.scanDescription;
    target.scanDescription = initDesc.replace( _binf_bountyRE, '' ) || null;
}

this.$getBounty = function(ship) {
    let bounty = ship.bounty;
    let sc = ship.scanClass;

    return sc === 'CLASS_BUOY' || sc === 'CLASS_ROCK'
        ? bounty / 10
        : bounty;
};

this.playerBoughtEquipment = function(equipment) {
    if ( equipment !== 'EQ_BOUNTY_INFORMER_REMOVER' ) return;

    this._binf_stopPeriodicalCheck(false);
    player.ship.removeEquipment('EQ_BOUNTY_INFORMER_REMOVER');
    player.ship.removeEquipment('EQ_BOUNTY_INFORMER');
    player.credits += ( EquipmentInfo.infoForKey('EQ_BOUNTY_INFORMER').price * 0.06 );
};

this.$initialScanDescription = function( ship, bounty ) {
    let sc = ship.scanClass;
    if ( sc === 'CLASS_NEUTRAL' ) {
        return bounty > 0
            ? ( bounty > 50 ? 'Fugitive' : 'Offender' )
            : 'Clean';
    }
    let tmp = sc === 'CLASS_THARGOID' ? 'legal-desc-alien'
            : sc === 'CLASS_POLICE'   ? 'legal-desc-system-vessel'
            : sc === 'CLASS_MILITARY' ? 'legal-desc-military-vessel'
            : false;
    return tmp ? expandDescription('['+tmp+']')
               : bounty > 0 ? 'Bounty'
               : '';
}

}).call(this);