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

Expansion System Features: Solar Flares

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 Adds visible solar flares to systems with solar activity Adds visible solar flares to systems with solar activity
Identifier oolite.oxp.phkb.SolarFlares oolite.oxp.phkb.SolarFlares
Title System Features: Solar Flares System Features: Solar Flares
Category Ambience Ambience
Author phkb phkb
Version 1.1 1.1
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/2/25/SolarFlares.oxz n/a
License CC-BY-NC-SA 4.0 CC-BY-NC-SA 4.0
File Size n/a
Upload date 1656910318

Documentation

Also read http://wiki.alioth.net/index.php/System%20Features:%20Solar%20Flares

readme.txt

Solar Flares
by Nick Rogers

Overview
========
This OXP bring a small ambience change to systems that have "solar activity". The corona of the sun will occasionally increase for a brief period of time, and then return back to its normal state after another brief period.

Licence
=======
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/

Code borrowed from the the "Nova Mission" code in the code Oolite application.
Copyright © 2004-2018 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. To view information about this licence, visit https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html

Version History
===============
1.1
- System corona hue and flare values should now be restored correctly after a save game, so when the system is left no changes will be stored.

1.0
- Initial release.

Equipment

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

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 = "SolarFlares";
this.author = "phkb";
this.copyright = "2018 phkb";
this.description = "Adds visible solar flares to systems with solar activity";
this.licence = "CC BY-NC-SA 4.0";

//TODO: make ship heat up if inside a flare

// Flaring code borrowed from "oolite-nova-mission"
// Copyright © 2004-2018 Giles C Williams and contributors
this._debug = false;

//-------------------------------------------------------------------------------------------------------------
this.startUpComplete = function () {
    if (missionVariables.SolarFlares_Hues) {
        this._originalHue = missionVariables.SolarFlares_Hues;
        delete missionVariables.SolarFlares_Hues;
    }
    if (missionVariables.SolarFlares_Flare) {
        this._originalFlare = missionVariables.SolarFlares_Flare;
        delete missionVariables.SolarFlares_Flare;
    }

    this.shipExitedWitchspace();
}

//-------------------------------------------------------------------------------------------------------------
this.playerWillSaveGame = function() {
    if (system.sun && (this._debug === true || system.description.indexOf("solar activity") >= 0) && !system.sun.isGoingNova && !system.sun.hasGoneNova) {
        missionVariables.SolarFlares_Hues = this._originalHue;
        missionVariables.SolarFlares_Flare = this._originalFlare;
    }
}

//-------------------------------------------------------------------------------------------------------------
this.shipExitedWitchspace = function () {
    if (system.sun) {
        // don't do anything in a nova system
        if (system.sun.isGoingNova || system.sun.hasGoneNova) return;

        // turn on the flare timer in solar activity systems
        if (this._debug === true || system.description.indexOf("solar activity") >= 0) {
            this._originalHue = system.info.corona_hues;
            this._originalFlare = system.info.corona_flare
            if (system.info.corona_flare < 0.15) system.info.corona_flare = 0.15;
            // The first flare up will begin in between 4 and 8 minutes.
            this._flareTimer = new Timer(this, this.$flareUp, Math.random() * 240 + 240);
        }
    }
};

//-------------------------------------------------------------------------------------------------------------
this.shipWillEnterWitchspace = function() {
    if (system.sun) {
        // if we were running, stop the timer and frame callback
        if (this._flareTimer) {
            this._flareTimer.stop();
            delete this._flareTimer;
        }
        if (this._flareCallback) {
            removeFrameCallback(this._flareCallback);
            delete this._flareCallback;
        }

        // don't do anything in a nova system
        if (system.sun.isGoingNova || system.sun.hasGoneNova) return;

        // put everything back the way we found it
        if (this._debug === true || system.description.indexOf("solar activity") >= 0) {
            system.info.corona_hues = this._originalHue;
            system.info.corona_flare = this._originalFlare;
        }
    }
}

//-------------------------------------------------------------------------------------------------------------
this.$flareUp = function $flareUp() {
    system.info.corona_hues = 1;
    // This flare up (0.3 to 0.5 flare) will last between 4 and 8 minutes
    this._flareTarget = 0.3 + Math.random() * 0.2;
    this._flareCallback = addFrameCallback(this.$flareTransition.bind(this));
    this.$flareChange(this.$flareDown, Math.random() * 240 + 240);
};

//-------------------------------------------------------------------------------------------------------------
this.$flareDown = function $flareDown() {
    system.info.corona_hues = this._originalHue;
    // This quiet moment (0.1 to 0.25 flare) will last between 4 and 8 minutes
    this._flareTarget = 0.1 + Math.random() * 0.15;
    this._flareCallback = addFrameCallback(this.$flareTransition.bind(this));
    this.$flareChange(this.$flareUp, Math.random() * 240 + 240);
};


//-------------------------------------------------------------------------------------------------------------
this.$flareChange = function (callFunc, callDelay) {
    this._flareTimer.stop();
    delete this._flareTimer;
    this._flareTimer = new Timer(this, callFunc, callDelay);
};

//-------------------------------------------------------------------------------------------------------------
this.$flareTransition = function $flareTransition(delta) {
    var current = system.info.corona_flare;
    if (current < this._flareTarget) {
        current += delta / 20;
    } else {
        current -= delta / 20;
    }
    system.info.corona_flare = current;
    if (this._flareTarget > 0.275 && current > this._flareTarget) {
        removeFrameCallback(this._flareCallback);
        delete this._flareCallback;
    } else if (this._flareTarget < 0.275 && current < this._flareTarget) {
        removeFrameCallback(this._flareCallback);
        delete this._flareCallback;
    }
}