Back to Index Page generated: Dec 20, 2024, 7:22:09 AM

Expansion Deposed

Content

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description This is a series of missions starting in galaxy 4. Needs 1700 kills to start. This is a series of missions starting in galaxy 4. Needs 1700 kills to start.
Identifier oolite.oxp.CmdrWombat.Deposed oolite.oxp.CmdrWombat.Deposed
Title Deposed Deposed
Category Missions Missions
Author Cmdr. Wombat Cmdr. Wombat
Version 2.0 2.0
Tags
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL https://wiki.alioth.net/index.php/Deposed_OXP n/a
Download URL https://wiki.alioth.net/img_auth.php/e/ef/Deposed_2.0.oxz n/a
License CC-BY-NC-SA 3.0 CC-BY-NC-SA 3.0
File Size n/a
Upload date 1709981273

Documentation

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

README.txt

Deposed
=======
v.1.4.0, September 2013.

by Cmdr. Wombat
(revisions by Eric Walch and Commander McLane)


Requirements:

Version 1.77 (or higher) of Oolite is required.


To install:

Move the deposed.oxp file into the AddOns folder in your Oolite folder. The Oolite folder is where the Oolite program resides. The deposed.oxp file is in the Deposed folder along with this README.txt file. DO NOT move the entire Deposed folder into the AddOns folder - you only need the deposed.oxp folder. (Seen as a single file on Mac systems)


Description:

This is a series of Oolite missions connected by a plot of sorts. The plot is not resolved, leaving open the possibility that I, or someone else, will write a sequel series of missions. I have borrowed liberally from various threads on the Oolite bulletin board. Hopefully no one will be offended if they see something they suggested at some point.

These missions start in Galaxy 4. There are no prior mission requirements, but the Naval energy unit from the Thargoid mission could come in handy. For the mission series to start you need ~1700 kills and must be docked at a station. Your location in Galaxy 4 is not important. Note that there are slightly different plot threads in Deposed depending upon your legal status when you start.

It doesn't matter whether you have completed the Nova mission or not. I tried to tailor parts of the scripts to handle both possibilities. However, it is important that you don't start the Nova mission part way through this series unless you have no interest in completing the series, or are happy to make your way back to Galaxy 4. There is a point towards the end of the Deposed series where you will trigger the Nova mission if you haven't already done it - that's okay, it's planned to happen that way.

v.2.0 Release November 2023 by phkb
- Updated models to use Griffs Sidewinder, Fer de Lance, and Asp Mk2 ships.
- Updated textures on factory.
- Removed plist script. Minimum version is now 1.80.
- Updated pseudo random number method to use latest, preferred method.
- Added links into Library PAD (if installed)
- Switch Peldorian Asps to be escorts for the Tarantula, rather than just individual ships that spawn with it.
- Moved drug factory further away from witchpoint to prevent clashes with other OXPs (eg Constores)

v.1.4.0 Released september 2013 by Eric Walch
- Converted all legacy scripts into JavaScript. 
- The hints for the blackwidows location are no longer on the Systemdata screen (F7) but at the new Interface screen (F4).
- Tuned down the strength of some ships in the first battle as they became stronger through changes in Oolite since Deposed's original release.
- Tuned up the ship strength of the 2nd and 3th battles, as they seemed to weak in comparison to the first one.
- Added some mission info strings with mission updates.
- The code disables itself after the mission ended, so it does not waste cpu power if the player does not remove the oxp.
- Raised minimum Oolite version to 1.77 to use of the new Interface screen.

v.1.3.4 Released March 2009 by Eric Walch
- Added mission destinations on the long range map.
- Fixed one missing short description.
- Replaced tarantulaAI.plist by pirateAI.plist. tarantulaAI was an exact copy of the old oolite 1.55 pirateAI. That AI evolved, so better use always the current pirateAI.
- For three missions the target ships were only added on entering the system by a jump, but not when loading a saved game in that system. Fixed now.

v.1.3.3 Released August 2008 by Commander McLane
- Fixed a bug that would not recognize the elimination of the tarantula or the drug factory.

v.1.3.2 Released February 2008 by Commander McLane
- Fixed a bug that would not recognize the elimination of the three blackwidows.

v.1.3.1 Released January 2008 by Commander McLane
- Fixed a bug that lead to entering in a loop when the mission is first offered.

v.1.3 Released January 2008 by Commander McLane
Made two changes to avoid clashes with other OXPs, and three cosmetic changes:
- Inserted queries before bringing up mission screens according to the method proposed by Eric Walch (see http://wiki.alioth.net/index.php/OXP_mission_offering).
- Changed file-names to make them more unique.
- Inserted a reset of all mission_variables except mission_deposed on finishing the OXP, in order to clean out the save-file.
- Inserted a missing condition-clause on refusal of the initial offering. In this case mission_deposed is set to NOT_PLAYED. No further offers are made.
- Fixed typos in the missiontexts.
- Raised minimum requirement to Oolite 1.65, because I'm not sure when 'oneof' was introduced in conditions. I guess there are not many players left who use versions prior to 1.65, anyway.

v.1.2.1 Released 29th December 2007.
Additions by Eric Walch: 
Restructuring the scripting for faster code handling.
Added code to make it compatible with the nova mission. It is advisable to do this mission before you encountered the native nova mission. Starting deposed after the nova mission leaves a possibility that deposed has no ending (removed spoiler about this from the readme file).

v.1.2 Released June 2006.
In response to various pieces of equipment now available to players, I have made some of the opponents encountered in Deposed a little tougher.

v.1.1.1 Released March 2006.
Minor AI bug fix (thanks again to Rxke).

v.1.1 Released March 2006.
Minor bug fixes (thanks Rxke for unearthing them!).

v.1.0 Released May 2005.

Disclaimer:

Feel free to copy, share, alter, mutilate or do whatever you like with these scripts. If there are elements you want to use in your own expansion packs, go right ahead. However, selling or otherwise profiting from them is simply not on. Don't do it.

If you find any bugs, and there are sure to be some, please send me all the gory details in a Private Message  to Cmdr. Wombat on the Oolite bulletin board. Alternatively, simply make a post there detailing the problem. Note that I am in no way responsible for any clashes with existing or future Oolite expansion packs, although this was play tested without issue with most of the expansion packs from Oosat (up to April, 2005) installed and with Oolite version 1.46 up to 1.48.


<a href="https://www.flaticon.com/free-icons/black-widow" title="black widow icons">Black widow icons created by Freepik - Flaticon</a>
<a href="https://www.flaticon.com/free-icons/spider" title="spider icons">Spider icons created by Freepik - Flaticon</a>

Equipment

This expansion declares no equipment.

Ships

Name
Peldorian Asp
Bien Naval Interceptor
Black Widow
Drug Factory
Tarantula

Models

This expansion declares no models.

Scripts

Path
Scripts/deposed-blackwidow.js
"use strict";
this.name = "deposed-blackwidow";
this.author = "eric walch";
this.description = "ship script for Deposed";
this.license = "CC-BY-NC-SA 3.0";

/*  The original ships had military aft lasers. But, with the original Oolite they only fired once
	during a fly-away run. They are now replaced with pulse lasers, that are still more dangerous
	than the military ones in the Oolite version during the original oxp development.
*/

this.shipSpawned = function () {
	if (player.score < 2560) {
		// Make the mission easier for players when less than Deadly
		// Minimum score to start this part of the mission is 1823
		this.ship.removeEquipment("EQ_SHIELD_ENHANCER");
	}
	if (this.ship.accuracy < 0) this.ship.accuracy *= -1; // exclude the stupid versions.
};


this.shipDied = function () {
	// don't check who killed the ship.
	if (this.ship.primaryRole == "deposed-blackwidow1") missionVariables.depblk1 = "DESTROYED";
	if (this.ship.primaryRole == "deposed-blackwidow2") missionVariables.depblk2 = "DESTROYED";
	if (this.ship.primaryRole == "deposed-blackwidow3") missionVariables.depblk3 = "DESTROYED";

	if (missionVariables.depblk1 == "DESTROYED"
		&& missionVariables.depblk2 == "DESTROYED"
		&& missionVariables.depblk3 == "DESTROYED") {
		mission.setInstructionsKey("deposed2_desc2b", "deposed");
		worldScripts.deposed.$markSystem(83);
		worldScripts.deposed.$unmarkSystem(10);
	}
};

Scripts/deposed-medical-drug-factory.js
"use strict";
this.name = "deposed-medical-drug-factory";
this.author = "eric walch";
this.description = "ship script for Deposed";
this.license = "CC-BY-NC-SA 3.0";

this.shipBeingAttacked = function (who) {
    if (this.ship.missiles.length > 0) this.ship.fireMissile();
}

this.shipDied = function () {
    missionVariables.depdrug = "DESTROYED";
    worldScripts.deposed.$markSystem(83);
    worldScripts.deposed.$unmarkSystem(111);
    mission.setInstructionsKey("deposed2_desc4b", "deposed");
};

Scripts/deposed-tarantula.js
"use strict";
this.name = "deposed-tarantula";
this.author = "eric walch";
this.description = "ship script for Deposed";
this.license = "CC-BY-NC-SA 3.0";

this.shipSpawned = function () {
    var missilesAvailable = ["EQ_MISSILE", "EQ_MISSILE", "EQ_HARDENED_MISSILE"]; //33% are hardheads
    var missileCount = missilesAvailable.length;
    var capacity = this.ship.missileCapacity;
    var start = this.ship.missiles.length; // should be zero.

    for (var i = start; i < capacity; i++) {
        // The ship is defined with an empty missile bay, now fill the bay randomly with above missiles
        this.ship.awardEquipment(missilesAvailable[Math.floor(Math.random() * missileCount)]);
    }
};


this.shipDied = function () {
    missionVariables.deptaran = "DEAD";
    worldScripts.deposed.$markSystem(83);
    worldScripts.deposed.$unmarkSystem(255);
    mission.setInstructionsKey("deposed2_desc3b", "deposed");
};
Scripts/deposed.js
"use strict";
this.name = "deposed";
this.author = "Cmdr. Wombat, JS translation by Eric Walch";
this.description = "Script used for the Deposed mission.";
this.license = "CC-BY-NC-SA 3.0";

this._logging = false;

//-------------------------------------------------------------------------------------------------------------
this.startUp = function () {
    var deposed = missionVariables.deposed;
    if (deposed == "MISSION_COMPLETE" || deposed == "ABANDONED" || deposed == "NOT_PLAYED") {
        // mission is over, no need to evaluate any code in the future.
        this.$clearHandlers();
    }
    this.firstLaunch = true;

    var vx = worldScripts.VimanaX_HUD;
    if (vx) {
        // update vimana to use a different model to the original
        vx._gameShips["Bien Naval Interceptor"] = "sidewinder";
        vx._gameShips["Black Widow"] = "ferdelance";
        vx._gameShips["Tarantula"] = "boa_cruiser";
        vx._gameShips["Drug Factory"] = "deposed_factory";
    }
    this.log_variables_to_log("startUp");
};

//-------------------------------------------------------------------------------------------------------------
this.missionScreenOpportunity = function () {
    var deposed = missionVariables.deposed;
    if (player.ship.dockedStation.isMainStation && galaxyNumber == 3) {

        if (!deposed && !missionVariables.deposed_started && player.score > 1693) {
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed_teaser", choicesKey: "deposed_bien" },
                function (choice) {
                    if (choice == "YES") {
                        missionVariables.deposed = "PRELUDE";
                        missionVariables.depask = "DRILE";
                        missionVariables.depbien = "OKAY";
                        missionVariables.deposed_started = "YES";
                        mission.setInstructionsKey("deposed_desc0");
                        this.$markSystem(11);
                    }
                    if (choice == "NO") {
                        missionVariables.deposed = "NOT_PLAYED";
                        this.$missionEnded();
                    }
                });
        }

        if (system.ID == 11 && deposed == "PRELUDE") {
            this.$unmarkSystem(11);
            missionVariables.deposed = "PART1_1";
            missionVariables.depbien = "BUGGERED";
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed_part1_1" });
            if (player.bounty == 0) {
                missionVariables.depstat = "CLEAN";
            } else if (player.bounty > 31) {
                missionVariables.depstat = "FUGITIVE";
            } else {
                missionVariables.depstat = "OFFENDER";
            };
            this.$markSystem(119);
            mission.setInstructionsKey("deposed_desc1");
            this.$addPadCharacter({name:"Ruben Drile", gender:"Male", t1:67});
        }

        if (system.ID == 119 && deposed == "PART1_1") {
            this.$unmarkSystem(119);
            missionVariables.deposed = "PART1_2";
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed_part1_2" });
            this.$markSystem(42);
            mission.setInstructionsKey("deposed_desc2");
        }

        if (system.ID == 42 && deposed == "PART1_2") {
            this.$unmarkSystem(42);
            missionVariables.deposed = "PART1_3";
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed_part1_3" });
            player.credits += 5000;
            mission.setInstructionsKey(null);
            this.$addPadLogEntry("Got 5k Cr for delivering Ruben Drile to Zadige successfully.");
        }

        if (system.ID != 42 && deposed == "PART1_3" && System.infoForSystem(galaxyNumber, 42).distanceToSystem(System.infoForSystem(galaxyNumber, system.ID)) > 7 && system.scrambledPseudoRandomNumber(system.ID) > 0.5) {
            // the random value excludes all systems in 7LY range. Edbire is probably the closest system
            if (missionVariables.depstat == "CLEAN") {
                missionVariables.deposed = "PART1_4";
                missionKey = "deposed_part1_4c"
            } else if (missionVariables.depstat == "OFFENDER") {
                missionVariables.deposed = "PART1_4";
                missionKey = "deposed_part1_4o";
                player.bounty |= 5;
            } else { // = FUGITIVE
                missionVariables.deposed = "PART1_6A";
                missionKey = "deposed_part1_4f";
                player.bounty |= 90;
            }
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: missionKey, overlay: "deposed_iNews.png" });
            this.$updatePadCharacterRank("Ruben Drile", "Former President of Bien");
            this.$addInfoToPadCharacter("Ruben Drile", "", "Former President of Bien, ousted in uprising.");
            this.$addInfoToPadCharacter("Ruben Drile", "", "Stole 1.2 Billion credits from people.");
            this.$addInfoToPadCharacter("Ruben Drile", "", "Escaped offworld - with your help.");
        }

        if (deposed == "PART1_4" && missionVariables.depask == "DRILE" && system.scrambledPseudoRandomNumber(system.ID) < 0.3) {
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed_part1_5", overlay: "deposed_GalCop.png", choicesKey: "deposed_galcop" },
                function (choice) {
                    if (choice == "YES") {
                        missionVariables.deposed = "PART1_5A";
                        mission.setInstructionsKey("deposed_desc3");
                        this.$markSystem(197);
                    }
                    if (choice == "NO") {
                        missionVariables.deposed = "PART1_6A";
                        missionVariables.depstat = "FUGITIVE";
                    }
                    missionVariables.depask = "ZSKTHAK";
                });
                
            this.$addPadLogEntry("Have been asked to report to GalCop Police in Dicebe. Not good.");
        }

        if (system.ID == 197 && deposed == "PART1_5") {
            var missionKey;
            if (missionVariables.depstat == "CLEAN") {
                missionKey = "deposed_part1_6c";
            } else {
                missionVariables.depstat = "CLEAN";
                missionKey = "deposed_part1_6o";
            }
            missionVariables.deposed = "PART1_6A";
            mission.runScreen({ title: "Deposed", screenID: "deposed", overlay: "deposed_GalCop.png", messageKey: missionKey });
            var amt = 5000;
            if (player.credits >= 5000) {
                player.credits -= 5000;
            } else {
                amt = player.credits;
                player.credits = 0;
            }
            this.$unmarkSystem(197);
            mission.setInstructionsKey(null);
            this.$addPadCharacter({name:"Lieutenant Rider", rank:"Lieutenant", gender:"Male", age:37, t1:11, t2:7});
            this.$addPadLogEntry("Had " + formatCredits(amt, false, true) + " of stolen funds taken back by Police.");
        }

        if (deposed == "PART1_6B") missionVariables.deposed = "PART1_6C";

        if (deposed == "PART1_6D") missionVariables.deposed = "PART1_6E";

        if (system.ID == 42 && deposed == "PART1_6") {
            // there is no hint leading to Zadige. Player has to remember old locations.
            mission.runScreen({ title: "Deposed", screenID: "deposed", overlay: "deposed_iNews.png", messageKey: "deposed_part1_7" });
            missionVariables.deposed = "PART1_8A";
        }

        if (deposed == "PART1_8E") {
            mission.runScreen({ title: "Deposed", screenID: "deposed", overlay: "deposed_iNews.png", messageKey: "deposed_inews1" });
            missionVariables.deposed = "PART1_8EE";
        }

        if (deposed == "PART2" && missionVariables.depask == "ZSKTHAK" && system.ID > 149 && player.score > 1823) {
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_pirate1", choicesKey: "deposed_esarqure" },
                function (choice) {
                    if (choice == "YES") {
                        missionVariables.deposed = "PIRATE1";
                        mission.setInstructionsKey("deposed2_desc1");
                        this.$markSystem(83);
                        missionVariables.depask = "SPIDERS";
                    }
                    if (choice == "NO") {
                        missionVariables.deposed = "ABANDONED";
                        this.$missionEnded(); // clear variables that are no longer needed.
                    }
                });
        }

        if (deposed == "PIRATE2" && missionVariables.depask == "SPIDERS" && missionVariables.depstat == "CLEAN") {
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_contactcops", choicesKey: "deposed_contact" },
                function (choice) {
                    if (choice == "YES") {
                        mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_cops1", overlay: "deposed_GalCop.png" })
                        worldScripts.deposed.$addPadCharacter({name:"Isabelle Lalury", rank:"Commissioner", gender:"Female", origin:"Unknown", species:"Unknown", t2:12});
                    }
                    if (choice == "NO") {
                        missionVariables.depstat = "FUGITIVE";
                    }
                });
            missionVariables.depask = "OFFWEGO";
            missionVariables.deposed = "PIRATE3";
        }

        if (deposed == "PIRATE3" && system.ID == 83) {
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_pirate2" });
            missionVariables.deposed = "PIRATE4";
            this.$addPadCharacter({name:"Zskthak", rank:"", origin:"Laqusoed", species:"Blue Horned Lobster", t1:84});
            this.$addPadLogEntry("Need to eliminate some Peldorian ships in Edorqu.");
        }

        if (deposed == "PIRATE4" && system.ID == 83) {
            if (missionVariables.depstat == "CLEAN") {
                // Give the clean player a hint.
                mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_cops2", overlay: "deposed_GalCop.png" });
            }
            missionVariables.deposed = "PIRATE5";
            missionVariables.depblk1 = "BLACK";
            missionVariables.depblk2 = "BLACK";
            missionVariables.depblk3 = "BLACK";
            this.$unmarkSystem(83);
            this.$markSystem(10);
            mission.setInstructionsKey("deposed2_desc2");
        }

        if (deposed == "PIRATE5" && missionVariables.depblk1 == "DESTROYED" && missionVariables.depblk2 == "DESTROYED" && missionVariables.depblk3 == "DESTROYED") {
            this.$addPadLogEntry("Destroyed the Peldorian pirates in Edorqu.");
            this.$markSystem(83);
            mission.setInstructionsKey("deposed2_desc2b");
            if (missionVariables.depstat == "CLEAN") {
                // Give the clean player a hint.
                mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_cops3", overlay: "deposed_GalCop.png" });
            }
            missionVariables.deposed = "PIRATE7";
        }

        if (deposed == "PIRATE7" && system.ID == 83) {
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_pirate3" });
            missionVariables.deposed = "PIRATE8";
            this.$unmarkSystem(83);
            mission.setInstructionsKey(null);
            player.credits += 9000;
        }

        if (deposed == "PIRATE8") {
            if (missionVariables.depstat == "CLEAN" && system.ID == 83) {
                // Give the clean player a hint.
                mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_cops4", overlay: "deposed_GalCop.png" });
                missionVariables.deposed = "PIRATE8_1";
            }
            if (missionVariables.depstat == "FUGITIVE") {
                missionVariables.deposed = "PIRATE8_1";
            }
        }

        if (deposed == "PIRATE8E") {
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed_inews2", overlay: "deposed_iNews.png" });
            missionVariables.deposed = "PIRATE8EE";
        }

        if (deposed == "PIRATE9" && system.ID < 255) {
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_pirate4" });
            missionVariables.deposed = "PIRATE10";
            this.$markSystem(255);
            mission.setInstructionsKey("deposed2_desc3");
            missionVariables.deptaran = "ALIVE";
        }

        if (deposed == "PIRATE10") {
            if (missionVariables.depstat == "CLEAN" && system.ID < 255) {
                mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_cops5", overlay: "deposed_GalCop.png" });
                missionVariables.deposed = "PIRATE11";
            }
            if (missionVariables.depstat == "FUGITIVE") {
                missionVariables.deposed = "PIRATE11";
            }
        }

        if (deposed == "PIRATE11" && system.ID == 83 && missionVariables.deptaran == "DEAD") {
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_pirate5" });
            missionVariables.deposed = "PIRATE12";
            this.$unmarkSystem(83);
            player.credits += 5000;
            mission.setInstructionsKey(null);
            missionVariables.deptaran = null;
        }

        if (deposed == "PIRATE12") {
            if (missionVariables.depstat == "CLEAN") {
                // hint for clean players
                mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_cops6", overlay: "deposed_GalCop.png" });
            }
            missionVariables.deposed = "PIRATE13";
        }

        if (deposed == "PIRATE13A") {
            missionVariables.deposed = "PIRATE13B";
        }

        if (deposed == "PIRATE13C") {
            missionVariables.deposed = "PIRATE13D";
        }

        if (deposed == "PIRATE13E") {
            missionVariables.deposed = "PIRATE13F";
        }

        if (deposed == "PIRATE14") {
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_pirate6" });
            missionVariables.deposed = "PIRATE15";
            this.$markSystem(111);
            mission.setInstructionsKey("deposed2_desc4");
            missionVariables.depdrug = "ALIVE";
        }

        if (deposed == "PIRATE15") {
            if (missionVariables.depstat == "CLEAN") {
                // hint for clean players
                mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_cops7", overlay: "deposed_GalCop.png" });
                missionVariables.deposed = "PIRATE11";
            }
            missionVariables.deposed = "PIRATE16";
        }

        if (deposed == "PIRATE16" && missionVariables.depdrug == "DESTROYED") {
            missionVariables.deposed = "PIRATE17";
            deposed = "PIRATE17";
            missionVariables.depdrug = null;
        }

        if (deposed == "PIRATE17" && system.ID == 83) {
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_pirate7" });
            missionVariables.deposed = "PIRATE18";
            this.$unmarkSystem(83);
            mission.setInstructionsKey(null);
            player.credits += 10000;
        }

        if (deposed == "PIRATE18") {
            if (missionVariables.depstat == "CLEAN") {
                // hint for clean players
                mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_cops8", overlay: "deposed_GalCop.png" });
            }
            missionVariables.deposed = "PIRATE19";
        }

        if (deposed == "PIRATE20" && system.ID != 83 && system.scrambledPseudoRandomNumber(system.ID) > 0.7) {  // this also excludes offering at the target system no83.
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_pirate8" });
            missionVariables.deposed = "PIRATE21";
            this.$markSystem(83);
        }

        if (deposed == "PIRATE21" && system.ID == 83) {
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_pirate9" });
            missionVariables.deposed = "PIRATE22";
            this.$unmarkSystem(83);
            this.$markSystem(138);
            mission.setInstructionsKey("deposed2_desc5");
            player.credits += 5000;
        }

        if (deposed == "PIRATE22") {
            if (missionVariables.depstat == "CLEAN") {
                // hint for clean players
                mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_cops9", overlay: "deposed_GalCop.png" });
            }
            missionVariables.deposed = "PIRATE23";
        }

        if (deposed == "PIRATE23") {
            if (!missionVariables.nova && missionVariables.deposed_started == "YES") {
                // Allow the native Oolite nova mission from now on.
                missionVariables.novacount = 2;
                missionVariables.deposed_started = "NOVACHANCE";
            }
            if (system.ID == 138) {
                mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_pirate10" });
                missionVariables.deposed = "PIRATE24";
                mission.setInstructionsKey("deposed2_desc5b");
                this.$unmarkSystem(138);
            }
        }

        if (missionVariables.nova_deposed_bug == "YES") {
            // One of the key systems is a nova system, so there is no solution for the mission.
            // tell this the player.
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "nova_deposed_newsflash", overlay: "solar.png" });
            missionVariables.nova_deposed_bug = null;
        }

    }

    if (player.ship.dockedStation.isMainStation && galaxyNumber == 4) {

        if (deposed == "PIRATE23" && missionVariables.deposed_started == "NOVACHANCE" && missionVariables.nova == "NOVA_HERO") {
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_pirate9" });
            this.$markSystem(70);
            missionVariables.deposed = "PIRATE25";
        }

        if (deposed == "PIRATE25" && system.ID == 70) {
            missionVariables.deposed = "PIRATE26";
            this.$unmarkSystem(70);
            mission.setInstructionsKey(null);
            var messageKey = (missionVariables.deposed_started == "NOVA_HAPPENED" ? "deposed2_delivery2" : "deposed2_delivery1");
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: messageKey });
            player.credits += 5000;
        }

        if (deposed == "PIRATE26") {
            if (missionVariables.depstat == "CLEAN") {
                // hint for clean players
                mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed2_cops10", overlay: "deposed_GalCop.png" });
                worldScripts.deposed.$addPadCharacter({name:"Dreewok", rank:"Commissioner", gender:"Male", origin:"Unknown", species:"Unknown", t2:12});
            }
            missionVariables.deposed = "PIRATE27";
        }

        if (deposed == "PIRATE28") {
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed_inews3", overlay: "deposed_iNews.png" });
            missionVariables.deposed = "PIRATE29";
        }

        if (deposed == "PIRATE29" && system.scrambledPseudoRandomNumber(system.ID) < 0.1) {
            mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: "deposed_inews_the_end", overlay: "deposed_iNews.png" });
            missionVariables.deposed = "MISSION_COMPLETE";
            this.$missionEnded(); // clear variables that are no longer needed.
        }
    }

    if (this.firstLaunch && (galaxyNumber == 3 || galaxyNumber == 4)) {
        this.$addShips();
        this.firstLaunch = false;
    }
    this.log_variables_to_log("missionScreenOpportunity")
};

//-------------------------------------------------------------------------------------------------------------
this.log_variables_to_log = function (from) {
    if (!this._logging) return;
    log(this.name, "============================================");
    log(this.name, "Source = " + from);
    log(this.name, "============================================");
    log(this.name, "MV.deposed           = " + missionVariables.deposed);
    log(this.name, "MV.depask            = " + missionVariables.depask);
    log(this.name, "MV.depbien           = " + missionVariables.depbien);
    log(this.name, "MV.depstat           = " + missionVariables.depstat);
    log(this.name, "MV.depblk1           = " + missionVariables.depblk1);
    log(this.name, "MV.depblk2           = " + missionVariables.depblk2);
    log(this.name, "MV.depblk3           = " + missionVariables.depblk3);
    log(this.name, "MV.deptaran          = " + missionVariables.deptaran);
    log(this.name, "MV.depdrug           = " + missionVariables.depdrug);
    log(this.name, "MW.nova_deposed_bug  = " + missionVariables.nova_deposed_bug);
    log(this.name, "MV.deposed_started   = " + missionVariables.deposed_started);
}

//-------------------------------------------------------------------------------------------------------------
this.shipLaunchedFromStation = function (station) {
    if (galaxyNumber == 3 && system.ID == 11 && missionVariables.deposed == "PIRATE11" && missionVariables.depbien == "BUGGERED") {
        // ******* change this to only happen once
        system.addShips("bienfighter", 6, station.position, 10000);
    }
};

//-------------------------------------------------------------------------------------------------------------
this.shipExitedWitchspace = function () {
    if (galaxyNumber < 3 || galaxyNumber > 4 || system.isInterstellarSpace) return;
    var deposed = missionVariables.deposed;
    if (galaxyNumber == 3) {
        // Next lines are very inefficient delays, but needed to stay compatible with old save games by the legacy script version.
        if (deposed == "PART1_4A") missionVariables.deposed = "PART1_4";
        if (deposed == "PART1_5A") missionVariables.deposed = "PART1_5";
        if (deposed == "PART1_6A") missionVariables.deposed = "PART1_6B";
        if (deposed == "PART1_6C") missionVariables.deposed = "PART1_6D";
        if (deposed == "PART1_6E") missionVariables.deposed = "PART1_6";
        if (deposed == "PART1_8G") missionVariables.deposed = "PART2";
        if (deposed == "PART1_8F") missionVariables.deposed = "PART1_8G";
        if (deposed == "PART1_8EE") missionVariables.deposed = "PART1_8F";
        if (deposed == "PART1_8D") missionVariables.deposed = "PART1_8E";
        if (deposed == "PART1_8C") missionVariables.deposed = "PART1_8D";
        if (deposed == "PART1_8B") missionVariables.deposed = "PART1_8C";
        if (deposed == "PART1_8A") missionVariables.deposed = "PART1_8B";
        if (deposed == "PIRATE1") missionVariables.deposed = "PIRATE2";
        if (deposed == "PIRATE8G") missionVariables.deposed = "PIRATE9";
        if (deposed == "PIRATE8F") missionVariables.deposed = "PIRATE8G";
        if (deposed == "PIRATE8EE") missionVariables.deposed = "PIRATE8F";
        if (deposed == "PIRATE8D") missionVariables.deposed = "PIRATE8E";
        if (deposed == "PIRATE8C") missionVariables.deposed = "PIRATE8D";
        if (deposed == "PIRATE8B") missionVariables.deposed = "PIRATE8C";
        if (deposed == "PIRATE8A") missionVariables.deposed = "PIRATE8B";
        if (deposed == "PIRATE8_1") missionVariables.deposed = "PIRATE8A";
        if (deposed == "PIRATE13") missionVariables.deposed = "PIRATE13A";
        if (deposed == "PIRATE13B") missionVariables.deposed = "PIRATE13C";
        if (deposed == "PIRATE13D") missionVariables.deposed = "PIRATE13E";
        if (deposed == "PIRATE13F") missionVariables.deposed = "PIRATE14";
        if (deposed == "PIRATE19A") missionVariables.deposed = "PIRATE20";
        if (deposed == "PIRATE19") missionVariables.deposed = "PIRATE19A";

        if (system.sun && system.sun.hasGoneNova && [11, 30, 42, 43, 49, 54, 75, 83, 111, 119, 138, 255].indexOf(system.ID) > -1) {
            // one of the mission systems is a nova system.
            missionVariables.nova_deposed_bug == "YES";
        }
        if (!missionVariables.nova && missionVariables.deposed_started == "YES") {
            missionVariables.novacount = 0; // suppress the nova mission.
        }
    }

    if (galaxyNumber == 4) {
        if (deposed == "PIRATE27C") missionVariables.deposed = "PIRATE28";
        if (deposed == "PIRATE27B") missionVariables.deposed = "PIRATE27C";
        if (deposed == "PIRATE27A") missionVariables.deposed = "PIRATE27B";
        if (deposed == "PIRATE27") missionVariables.deposed = "PIRATE27A";
    }

    this.$addShips();
    this.log_variables_to_log("shipExitedWitchspace");
};

//-------------------------------------------------------------------------------------------------------------
this.playerEnteredNewGalaxy = function (galaxy) {
    if (galaxy == 4) {
        var deposed = missionVariables.deposed;
        if (deposed == "PIRATE23" && missionVariables.deposed_started == "NOVACHANCE" && missionVariables.nova == "NOVA_HERO") {
            // mission was interrupted by the nova mission without change to pick up the passenger from Usesri. Add one extra message on the next docking.
            this.$markSystem(70);
            mission.setInstructionsKey("deposed2_desc6b");
            missionVariables.deposed_started = "NOVA_HAPPENED"
        }

        if (deposed == "PIRATE24") {
            mission.setInstructionsKey("deposed2_desc6");
            this.$markSystem(70);
            missionVariables.deposed = "PIRATE25";
        }
    }
    this.log_variables_to_log("playerEnteredNewGalaxy");
}

//-------------------------------------------------------------------------------------------------------------
this.$searchPeldorianShips = function () {
    var messageKey = "deposed2_any_system";
    if (system.ID == 10) {
        messageKey = "deposed2_edorqu10";
    }
    if (system.ID == 30) {
        messageKey = "deposed2_atbitela30";
    }
    if (system.ID == 54) {
        messageKey = "deposed2_quisbe54";
    }
    if (system.ID == 95) {
        messageKey = "deposed2_zamaso95";
    }
    if (system.ID == 148) {
        messageKey = "deposed2_teisen148";
    }
    if (system.ID == 119) {
        messageKey = "deposed2_esisraan119";
    }
    if (system.ID == 34) {
        messageKey = "deposed2_lequteor34";
    }
    if (system.ID == 49) {
        messageKey = "deposed2_beesed49";
    }
    if (system.ID == 75) {
        messageKey = "deposed2_inve75";
    }
    if (missionVariables.depblk1 == "DESTROYED" && missionVariables.depblk2 == "DESTROYED" && missionVariables.depblk3 == "DESTROYED") {
        messageKey = "deposed2_blackwidowsdestroyed";
    }
    mission.runScreen({ title: "Deposed", screenID: "deposed", messageKey: messageKey });
}

//-------------------------------------------------------------------------------------------------------------
this.$addShips = function () {
    if (galaxyNumber == 3) {
        var deposed = missionVariables.deposed;
        if (system.ID == 30 && deposed == "PIRATE5") {
            if (missionVariables.depblk1 == "BLACK") system.addShipsToRoute("deposed-blackwidow1", 1, 0.1, "wp");
            if (missionVariables.depblk2 == "BLACK") system.addShipsToRoute("deposed-blackwidow2", 1, 0.1, "wp");
            if (missionVariables.depblk3 == "BLACK") system.addShipsToRoute("deposed-blackwidow3", 1, 0.1, "wp");
        }

        if (system.ID == 255 && deposed == "PIRATE11" && missionVariables.deptaran == "ALIVE") {
            // asps are now defined as escorts for the tarantula.
            system.addShipsToRoute("deposed-tarantula", 1, 0.01, "wp");
        }

        if (system.ID == 111 && deposed == "PIRATE16" && missionVariables.depdrug == "ALIVE") {
            var drugFactory = system.addShips("deposed-medical-drug-factory", 1, [0, 0, -200000], 1000)[0];
            var pirates = system.addShips("pirate", 15, [0, 0, -200000], 10000);
            system.addShips("asteroid", 20, [0, 0, -200000], 10000);
            drugFactory.group = new ShipGroup("Peldorian Clan", drugFactory);

            // Now add the pirates to the factory group so the factory can signal for help.
            // don't add the group to each individual pirate, so you still can kill them individually.
            for (var i = 0; i < pirates.length; i++) {
                drugFactory.group.addShip(pirates[i]);
            }
        }

        if (system.ID == 11 && missionVariables.depbien == "BUGGERED") {
            system.addShipsToRoute("bienfighter", 4, 0.05, "wp");
        }

        if (deposed == "PART1_1" || (deposed == "PART1_2" && system.ID != 42)) {
            var count = Math.floor(Math.random() * 6);  // 0 till 5;
            if (count) system.addGroupToRoute("bienfighter", count, Math.random(), "wp");

            if (deposed == "PART1_1" && count) {
                system.addShipsToRoute("bienfighter", count, 0.05, "wp");
            }
        }

        if (deposed == "PIRATE5" && system.mainStation) {
            // add hints at the main station
            system.mainStation.setInterface("Deposed",
                {
                    title: expandMissionText("deposed2_inquiries_title"),
                    category: "Inquiries",
                    summary: expandMissionText("deposed2_inquiries_body"),
                    callback: this.$searchPeldorianShips.bind(this)
                });
        }
    }
};

//-------------------------------------------------------------------------------------------------------------
this.$markSystem = function (ID) {
    mission.markSystem({
        system: ID,
        name: "deposed",
        markerColor: "redColor",
        markerScale: 1.1,
        markerShape: "MARKER_X"
    });
    missionVariables.deposedNewmarkers = "YES"; // added to deal with the legacy markers from an old saved game.
}

//-------------------------------------------------------------------------------------------------------------
this.$unmarkSystem = function (ID) {
    var ok = mission.unmarkSystem({
        system: ID,
        name: "deposed"
    });
    if (!ok && !missionVariables.deposedNewmarkers) mission.unmarkSystem(ID); // must be an old legacy marker.
}

//-------------------------------------------------------------------------------------------------------------
this.$missionEnded = function () {
    // clear all mission variables except the main one
    missionVariables.depbien = null;
    missionVariables.depask = null;
    missionVariables.depstat = null;
    missionVariables.depblk1 = null;
    missionVariables.depblk2 = null;
    missionVariables.depblk3 = null;
    missionVariables.deptaran = null;
    missionVariables.depdrug = null;
    missionVariables.deposed_started = null;
    missionVariables.deposedNewmarkers = null;
    this.$clearHandlers();
};

//-------------------------------------------------------------------------------------------------------------
this.$clearHandlers = function () {
    delete this.missionScreenOpportunity;
    delete this.shipLaunchedFromStation;
    delete this.shipWillDockWithStation;
    delete this.shipExitedWitchspace;
    delete this.missionScreenOpportunity;
    delete this.guiScreenChanged;
    delete this.playerEnteredNewGalaxy;
    delete this.shipWillLaunchFromStation;
    delete this.shipWillDockWithStation;
    delete this.shipWillEnterWitchspace;
};

//-------------------------------------------------------------------------------------------------------------
this.$updatePadCharacterRank = function (person, rank) {
    var pad = worldScripts.Lib_PAD;
    if (!pad) return;
    var id = person.split(" ")[0].toUpperCase() + (person.indexOf(" ") >= 0 ? " " + person.split(" ")[1].toUpperCase() : "");

    pad.$data.PERSONS[id].rank = rank;
}

//-------------------------------------------------------------------------------------------------------------
this.$addPadCharacter = function (obj) {
    var pad = worldScripts.Lib_PAD;
    if (!pad) return;
    var dta = {};
    var cat = [];

    dta.name = obj.name;
    dta.origin = (obj.origin ? obj.origin : system.name);
    dta.species = (obj.species ? obj.species : system.info.inhabitant);
    dta.gender = (obj.gender ? obj.gender : (Math.random() > 0.5 ? "Male" : "Female"));
    dta.age = (obj.age ? obj.age : Math.floor(Math.random() * 30) + 40);
    dta.ship = (obj.ship ? obj.ship : "None");
    dta.rank = (obj.rank ? obj.rank : "");
    dta.t0 = (obj.rank != "" ? "lib_pad_org_galcop.png" : 0);
    dta.t1 = (obj.t1 && obj.t1 > 0 ? "lib_ovc" + (obj.t1 < 10 ? "0" : "") + obj.t1 + ".png" : "");
    dta.t2 = (obj.t2 && obj.t2 > 0 ? obj.t2 : 0);
    dta.info = [];
    if (obj.info) {
        for (var i = 0; i < obj.info.length; i++) {
            dta.info.push(obj.info[i]);
        }
    }
    cat.push("GALCOP.GENERIC");

    var id = "PERSONS." + (dta.rank && dta.rank != "" ? dta.rank.toUpperCase() : dta.name.split(" ")[0].toUpperCase()) + (dta.name.indexOf(" ") >= 0 ? " " + dta.name.split(" ")[1].toUpperCase() : "");
    log(this.name, "id = " + id);
    pad._addPageInCategory(id, dta, cat, false);
}

//-------------------------------------------------------------------------------------------------------------
this.$addInfoToPadCharacter = function (person, rank, text) {
    var pad = worldScripts.Lib_PAD;
    if (!pad) return;
    var id = "PERSONS." + (rank && rank != "" ? rank.toUpperCase() : person.split(" ")[0].toUpperCase()) + (person.indexOf(" ") >= 0 ? " " + person.split(" ")[1].toUpperCase() : "");
    worldScripts.Lib_PAD._setPageEntry(id + ".info", text);
}

//-------------------------------------------------------------------------------------------------------------
this.$addPadLogEntry = function (text) {
    var pad = worldScripts.Lib_PAD;
    if (!pad) return;
    pad._setPageEntry("LOGS.GENERIC.list", text);
}