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

Expansion Cataclysm

Content

Warnings

  1. http://wiki.alioth.net/index.php/Cataclysm -> 404 Not Found
  2. Low hanging fuit: Information URL exists...

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description A galaxy-spanning mission, continuing the war against the Thargoids. A galaxy-spanning mission, continuing the war against the Thargoids.
Identifier oolite.oxp.Commander_McLane.Cataclysm oolite.oxp.Commander_McLane.Cataclysm
Title Cataclysm Cataclysm
Category Missions Missions
Author Commander McLane Commander McLane
Version 2.1 2.1
Tags
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL https://wiki.alioth.net/index.php/Cataclysm_OXP n/a
Download URL https://wiki.alioth.net/img_auth.php/5/58/Cataclysm_2.1.oxz n/a
License CC-BY-NC-SA 3.0 CC-BY-NC-SA 3.0
File Size n/a
Upload date 1709981240

Documentation

readme.txt

Cataclysm v 2.0
===============
by "Commander McLane"

featuring models by "Griff"
and scripting help by "Eric Walch"
Updates by phkb

an Expansion Pack for Oolite by Giles Williams

based on "Elite" by Ian Bell and David Braben


Introduction
------------
Things aren't looking too good at the Thargoid front. The Thargoids don't confine themselves to intercepting ships in witchspace anymore. Attacks on the space lanes, on main stations, even on planets themselves have become more frequent.

The Galactic Navy has tried to keep on par with the threat. The Behemoth and Leviathan class of capital ships—together with new and capable fighters—have been introduced, new and powerful anti Thargoid weapons have been developed, Navy Sector Commands are sending battle groups on the space lanes and in interstellar space.

But it seems the Thargoids are always one step ahead. The introduction of the Behemoths saw the advent of new classes of Thargoid Battleships, gigantic Thargoid Carriers have started threatening the GalCop worlds, and the Navy Frigates and their battle groups are now being countered by what seems to be a second wave of completely new Thargoid Ships, together with new and fearsome variants of Thargons.

A while ago the Navy had obtained and—with the help of a certain fearless space commander—securely delivered some secret defense plans of the Thargoid Hive Worlds, and Naval Intelligence was confident that these would give the troops the means for a push against the Thargoid home system. But what has come out of that? Nothing seems to have happened since, no news of a main strike against a Thargoid home world have made it to the public. Or did it all end in a disaster, and this new and unprecedentedly angry wave of Thargoid attacks on GalCop worlds was only triggered by a failed invasion attempt on their space? The Tionisla Chronicle does certainly not know.

But now we are on the very brink of new and important developments. The atmosphere is highly charged with anxiety and anticipation, and somehow it is going to discharge violently. Veteran spacefarers can sense a cataclysmic event at the horizon. The future of the Galactic Co-operative of Worlds is at stake. Something has to happen, ... and indeed something has happened.

It all starts when—after a particularly vicious wave of Thargoid attacks in the middle of Galaxy 1—a well known officer of Her Imperial Majesty's Space Navy contacts a certain fearless space commander, and asks for help. Captain Curruthers has made a rapid career and become Rear Admiral since the Constrictor incident, and he hasn't forgotten who got him out of the trouble with the stolen prototype. Nor have Captain Fortesque and Agent Blake—their unaltered ranks perhaps indicating that the Thargoid Plans plan didn't turn out as a huge success. But this new thing has all the prospect to become one...

Technical Overview
------------------
Cataclysm.oxp is a mission OXP that takes up the threads of the native Constrictor Hunt and Thargoid Plans missions, and sends you on a mission far bigger than anything you have done for the Navy so far. It gives you the opportunity to re-visit places you have visited before, and re-meet people you had contact with during these missions. And of course it will let you meet various other people, and lead you to a lot of new places, some of which you probably haven't visited before.

The mission starts in the middle of Galaxy 1, roughly in the area where the first part of the Constrictor Hunt took place. After a ruthless Thargoid attack on a main station, during which you once again excelled in the defense force, it is time for Rear Admiral Curruthers to contact you with an important news. (If you don't excel, you won't be contacted unless you excel.) From there on you are in the service of Her Imperial Majesty's Space Navy again, and soon find yourself on a quest that will lead you through most parts of the known Ooniverse. What are you going to find in the end? Only %R knows!

The mission requires an able commander with an equally able ship. Therefore it is not suited for a beginner. Anyway, you will have to have finished both the Constrictor Hunt and the Thargoid Plans missions, and be in Galaxy 1 in order to get Cataclysm started, which means that you have to have cycled the eight galaxies at least once before you are offered this mission. So you will probably have been ☆ Deadly ☆ for quite a while before the events depicted here start to unfold. The OXP requires you to be 'twice deadly'—having at least 5120 kills—to get started. At the end of it you may well have come close to ★★★ E L I T E ★★★ ...

Minimum Requirements
--------------------
Cataclysm.oxp (v2.0) requires at least Oolite 1.82.

The OXP doesn't require any other OXP for running; however your experience will get more varied, more exciting, and probably more difficult as well, if you play with some other OXPs installed (most of those mentioned in the introduction):

Thorgorn Threat and Second Wave will give you a greater variety of Thargoid ships involved in the action.

If you play with Thargoid Wars installed, the beginning of Cataclysm.oxp will blend naturally into the scenario you are used to from that OXP.

Behemoth and Military Fiasco will at some points add valuable reinforcements on your side.

Missiles and Bombs will give you a greater choice of weaponry.

Asteroid Storm will give you a greater variety in asteroid fields.

Galactic Navy will not be used in any specific way by this OXP, but may add to the atmosphere of being at war with the Thargoids. (Although there seems to be a strange bug in Oolite 1.72.1 that may lead to ships from Cataclysm not being created when Galactic Navy is installed as well. See below.)

Thargoidcarrier will also not interact specifically with this OXP, but may add to the atmosphere as well.

PAGroove_Stations will give you many more stations that look like the added stations in this OXP (because these were ripped off there), thereby unifying the design.

System Redux will just enhance the scenery. (If you usually play with System Redux, you will perhaps notice changes in a couple of systems. This is because the additional planets and moons have been partially disabled by this OXP, in order to prevent possible location clashes.)

Known Problems
--------------
(v1.1) Due to a not-yet-fully-understood bug in either Oolite or some OXPs there are some OXPs that will prevent other scripts from creating additional ships with role 'police'. Cataclysm wants to create a couple of those ships at one point in the story. However, the police ships are not a story necessity. The two OXPs that cause this behaviour on my own system are Commies and Galactic Navy. I hope the developers find and eliminate the problem.

(v2.0) This issue has not been observed as yet, but please let me (phkb) know if you encounter it.

Download Location
-----------------
This OXP is available for download through the Elite Wiki.

Installation
------------
Move or copy the file Cataclysm.oxp from this folder to the AddOns folder inside the Oolite main folder. Restart Oolite.

Acknowledgements
----------------
Thanks to Griff for his willingness to allow me to use his model of a burning station, and other models as well. As always, all his models improve the look and feel of this OXP substantially. Also thanks to another_commander for his very encouraging feedback after looking at a halfway ready preview version of Cataclysm. Of course thanks to Eric Walch for some invaluable help in the early stages of the JS-scripting of this OXP, and for the very enlightening exchange of ideas time and again. And—last but not least—my thanks go to Aegidian, Ahruman, and the development commOonity of Oolite, the people who are making OXPs like this possible in the first place.

(v2.0) Additional thanks to KillerWolf for his marvelous "Wrecked" Coriolis station.

License
-------
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License version 3.0. For more information see the ReadMe of Oolite or the Creative Commons' website.

Practically this means that you may rip it apart and use whatever seems useful to you, as long as you credit the original author. It would be nice—although by no means necessary—to give me a note, if you intend to use parts of it.

History
-------
version 2.1 (March 9, 2024) (phkb)
- Tweaked text in one of the final mission screens, to ensure it will fit on the screen in all formats.
- Updated Tetier vista image.
- Updated mark/unmark system method, to use latest Oolite standards.
- Updated normal maps for Hydra and Rattlecutter, and added specular maps as well.

version 2.0 (October 20, 2023) (phkb)
- updated to work with the latest version of Oolite.
- updated textures and models, added normal maps for a better alignment with a "Griff-ified" universe. Wolf Mark II taken from Griff's Wolf Mark II. Viper Interceptor taken from Griff's Viper Interceptor. Asp Mark II taken from HIMSN. 
- switched "burning station" model for KillerWolf's "Wrecked" station.
- interaction with "Additional Planets" (ie System Redux) has been updated to use the latest version.
- added characters and events to Library PAD, as they happen.
- fixed some spelling and grammar mistakes.

version 1.1 (January 7th, 2009)
- incorporated two more ships from Military Fiasco, in order to resolve a like_ship error-message

version 1.0 (January 6th, 2009)
- fully functional version
- requires Oolite 1.72.1

TODO:
Check - why do we have to purchase the replica?

Equipment

Name Visible Cost [deci-credits] Tech-Level
All extras you can think of.. yes 1000000 1+
Experimental Galactic Hyperdrive Modification yes 10000 11+

Ships

Name
Ambassador Ship
Ambassador Escort
Defector
cataclysm-defector-thargoid
Recovered Thargoid Warship
cataclysm-disabled-warship-2
Recovered Thargoid Warship
cataclysm-disabled-warship-escape-pod
Enrece Research Station
cataclysm-explosive-alloy
Thargoid Hive Sub 1
Thargoid Hive Sub 2
Thargoid Hive Sub 3
Thargoid Hive Sub 4
Thargoid Hive Sub 5
Thargoid Hive Sub 6
Naval Asp Mark II-a
Military Hydra 2
cataclysm-military-hydraspike
Military Rattle Cutter
cataclysm-military-rattlefang
Navy Viper Interceptor
Wolf Mark II Paragon
Ribilebi Research Station
Docking Bay
Navy Station Buoy
Asteroid (Target 1)
Asteroid (Target 2)
Asteroid (Target 3)
Asteroid (Target 4)
Tetier Military Station
Unknown Structure
Thargoid Hive
Hive Core
Navy Viper
Warship Replica
Warship Replica
cataclysm-warship-replica-2
cataclysm-wreckage
cataclysm_KW_CoriDamage
cataclysm_KW_CoriFace
Griff Coriolis test
Wreck Dock

Models

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

Scripts

Path
Scripts/cataclysm-ambassador.js
"use strict";
/*

cataclysm-ambassador.js

Ship script for ambassador ship.


Oolite
Copyright © 2008 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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.

*/


this.name = "cataclysm-ambassador";
this.author = "Commander McLane";
this.copyright = "© 2009 Commander McLane";
this.version = "1.1";

this.shipDockedWithStation = function () {
	if (missionVariables.cataclysm_missions == "ESCORT_AMBASSADOR") {
		system.mainStation.commsMessage("The ambassador has arrived safely. Please dock with the station.");
		missionVariables.cataclysm_missions = "AMBASSADOR_SUCCESS";
	}
}

this.shipDied = function (whom, why) {
	this.ship.commsMessage("Noooooooooooooooo!!!");
	missionVariables.cataclysm_missions = "AMBASSADOR_FAILURE";
	if (whom == system.mainStation && why == "scrape damage" && this.ship.alertCondition < 3) {
		// probably docking failure - not the players fault
		missionVariables.cataclysm_missions = "AMBASSADOR_FAILURE2";
	}
}
Scripts/cataclysm-conditions.js
"use strict";
this.name = "cataclysm-conditions";
this.author = "phkb";
this.copyright = "© 2023 phkb";
this.description = "Condition script for equipment.";
this.licence = "CC BY-NC-SA 4.0";

//-------------------------------------------------------------------------------------------------------------
this.allowAwardEquipment = function (equipment, ship, context) {
    if (context === "scripted") return true;
    if (equipment == "EQ_GAL_DRIVE_MOD") {
        if (["STAGE9A", "STAGE9B", "STAGE9Aa", "STAGE9Ba"].indexOf(missionVariables.cataclysm) >= 0) return true;
    }
    return false;
}

//-------------------------------------------------------------------------------------------------------------
this.allowOfferShip = function(shipKey) {
    if (shipKey == "cataclysm-warship-player") {
        if (missionVariables.cataclysm_replica == "AVAILABLE") return true;
    }
    return false;
}
Scripts/cataclysm-defector.js
"use strict";
/*

cataclysm-defector.js

Ship script for defector ship.


Oolite
Copyright © 2008 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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.

*/


this.name = "cataclysm-defector";
this.author = "Commander McLane";
this.copyright = "© 2009 Commander McLane";
this.version = "1.1";


this.countdownStarted = function () {
	var agent = system.shipsWithPrimaryRole("police", player.ship, 25000)[0];
	if (!agent) agent = player;
	agent.commsMessage("Initiation of witchspace countdown sequence detected. Hurry up!");
}

this.enteringWitchspace = function () {
	this.ship.fuel = 7;
	var agent = system.shipsWithPrimaryRole("police", player.ship, 25000)[0];
	if (!agent) agent = player;
	agent.commsMessage("The defector has escaped. Don't follow him into witchspace. Return to the station.");
	missionVariables.cataclysm_missions = "DEFECTOR_ESCAPED";
}

this.shipDied = function (whom, why) {
	if (missionVariables.cataclysm_missions == "DEFECTOR_HUNT") {
		this.ship.commsMessage(expandDescription("%R! %R! %R!"));
		missionVariables.cataclysm_missions = "DEFECTOR_KILLED";
	}
}
Scripts/cataclysm-disabled-warship-1.js
"use strict";
/*

cataclysm-disabled-warship-1.js

Ship script for disabled captured thargoid warship.


Oolite
Copyright © 2008 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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.

*/


this.name = "cataclysm-disabled-warship-1";
this.author = "Commander McLane";
this.copyright = "© 2009 Commander McLane";
this.version = "1.1";


this.shipDied = function () {
	player.commsMessage("We've lost the warship's transponder sign. It seems to have been destroyed. All our effort was in vain!", 6);
	missionVariables.cataclysm = "DESTROYED";
}

this.checkThargoids = function () {
	if (system.countShipsWithRole("thargoid") < 3) {
		this.ship.AIState = "PREPARE_TO_LEAVE";
		worldScripts.Cataclysm.wormholeCollapseTimer = new Timer(worldScripts.Cataclysm, worldScripts.Cataclysm.wormholeCollapsed, 245);
	}
}

this.defuseCascadeWeapons = function () {
	function isCascadingWeapon(ship) {
		return ship.primaryRole == "EQ_QC_MINE" || ship.primaryRole == "EQ_CASCADE_MISSILE" || ship.name == "Thargoid Robot Mine";
	}
	var cascadeWeapons = system.filteredEntities(this, isCascadingWeapon, this.ship, 100000);
	cascadeWeapons.forEach(function (ship) { ship.explode(); })
}

this.weHaveLeft = function () {
	player.commsMessage("The Warship has successfully jumped out. Hurry to follow through its wormhole.", 6);
}

this.spawnSubstitute = function () {
	this.ship.spawnOne("cataclysm_disabled_warship_2");
	missionVariables.cataclysm = "STAGE7a";
} 
Scripts/cataclysm-disabled-warship-3.js
"use strict";
/*

cataclysm-disabled-warship-3.js

Ship script for exploding disabled captured thargoid warship.


Oolite
Copyright © 2008 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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.

*/


this.name = "cataclysm-disabled-warship-3";
this.author = "Commander McLane";
this.copyright = "© 2009 Commander McLane";
this.version = "1.1";


this.checkForPlayer = function () {
	if (this.ship.position.distanceTo(player.ship.position) < 3500)
		this.ship.AIState = "PLAYER_IN_REACH";
}

Scripts/cataclysm-disabled-warship-escape-pod.js
"use strict";
/*

cataclysm-disabled-warship-escape-pod.js

Ship script for disabled captured thargoid warship.


Oolite
Copyright © 2008 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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.

*/


this.name = "cataclysm-disabled-warship-escape-pod";
this.author = "Commander McLane";
this.copyright = "© 2009 Commander McLane";
this.version = "1.1";


this.shipWasScooped = function (scooper) {
	if (scooper.isPlayer) {
		this.ship.commsMessage("Engineer: Thank you for rescuing me!");
		missionVariables.cataclysm = "E_RESCUED";
	}
}
Scripts/cataclysm-military.js
"use strict";
/*

cataclysm-military.js

Ship script for military ships.


Oolite
Copyright © 2008 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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.

*/


this.name = "cataclysm-military";
this.author = "Commander McLane";
this.copyright = "© 2009 Commander McLane";
this.version = "1.1";


this.shipBeingAttacked = function (whom) {
	if (whom.primaryRole == "cataclysm_military" || whom.primaryRole == "cataclysm_tetier_station" || whom.isPlayer) return;
	this.ship.reactToAIMessage("ATTACKED_BY_HOSTILE");
}

this.shipAttackedWithMissile = function (missile, whom) {
	if (whom.primaryRole == "cataclysm_military" || whom.primaryRole == "cataclysm_tetier_station" || whom.isPlayer) return;
	this.ship.reactToAIMessage("INCOMING_HOSTILE_MISSILE");
}

this.groupAttackTarget = function () {
	var target = this.ship.target;
	this.ship.reactToAIMessage("GROUP_ATTACK_TARGET");
	system.shipsWithRole("cataclysm_military", this.ship, 8000).forEach(function (ship) {
		if (ship.AI == "cataclysm_militaryAI.plist") {
			ship.target = target;
			ship.reactToAIMessage("GROUP_ATTACK_TARGET");
		}
	})
	system.shipsWithPrimaryRole("cataclysm_tetier_station")[0].target = target;
	system.shipsWithPrimaryRole("cataclysm_tetier_station")[0].reactToAIMessage("GROUP_ATTACK_TARGET");
}

this.checkOffender = function () {
	var target = this.ship.target;
	if (target.primaryRole == "cataclysm_military" || target.primaryRole == "cataclysm_tetier_station" || target.primaryRole == "cataclysm_warship_replica" || target.isPlayer) return;
	this.groupAttackTarget();
}
Scripts/cataclysm-populator.js
"use strict";
/*

cataclysm-populator.js

Script for populating systems.


Oolite
Copyright © 2008 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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.

*/


this.name = "cataclysm-populator";
this.author = "phkb";
this.copyright = "© 2023 phkb";
this.version = "1.0";

this.$addHive2Ships = function () {
    system.sendAllShipsAway();
    system.addShips("cataclysm_thargoid_hive_2", 1, Vector3D(0, 0, 300000).fromCoordinateSystem("wpm"));
    system.addShips("thargoid", 10, Vector3D(0, 0, 30000).fromCoordinateSystem("wpm"), 50000);
    system.addShips("thargoid", 10, Vector3D(0, 0, 100000).fromCoordinateSystem("wpm"), 50000);
    system.addShips("thargoid", 10, Vector3D(0, 0, 170000).fromCoordinateSystem("wpm"), 50000);
    system.addShips("thargoid", 10, Vector3D(0, 0, 240000).fromCoordinateSystem("wpm"), 50000);
    system.addShips("police", 8, Vector3D(0, 0, 20000).fromCoordinateSystem("wpm"), 30000);
    system.addShips("military-ship", 6, Vector3D(0, 0, 60000).fromCoordinateSystem("wpm"), 30000);
    // in case the behemoths OXP is installed
    var beh = system.addShips("behemoth", 1, Vector3D(0, 0, 60000).fromCoordinateSystem("wpm"), 30000);    
}

this.$interstellarPopulator_hive0 = function () {
    if (missionVariables.cataclysm_hivemission == "DESTROY_HIVE" && missionVariables.cataclysm_hive_location == 0) {
        this.$addHive2Ships();
    }
}

this.$interstellarPopulator_hive1 = function () {
    if (missionVariables.cataclysm_hivemission == "DESTROY_HIVE" && missionVariables.cataclysm_hive_location == 1) {
        this.$addHive2Ships();
    }
}

this.$interstellarPopulator_hive2 = function () {
    if (missionVariables.cataclysm_hivemission == "DESTROY_HIVE" && missionVariables.cataclysm_hive_location == 2) {
        this.$addHive2Ships();
    }
}

this.$interstellarPopulator_hive3 = function () {
    if (missionVariables.cataclysm_hivemission == "DESTROY_HIVE" && missionVariables.cataclysm_hive_location == 3) {
        this.$addHive2Ships();
    }
}

this.$interstellarPopulator_hive4 = function () {
    if (missionVariables.cataclysm_hivemission == "DESTROY_HIVE" && missionVariables.cataclysm_hive_location == 4) {
        this.$addHive2Ships();
    }
}

this.$interstellarPopulator_hive5 = function () {
    if (missionVariables.cataclysm_hivemission == "DESTROY_HIVE" && missionVariables.cataclysm_hive_location == 5) {
        this.$addHive2Ships();
    }
}

this.$interstellarPopulator_hive6 = function () {
    if (missionVariables.cataclysm_hivemission == "DESTROY_HIVE" && missionVariables.cataclysm_hive_location == 6) {
        this.$addHive2Ships();
    }
}

this.$interstellarPopulator_investigate = function () {
    if (missionVariables.cataclysm_hivemission == "INVESTIGATE") {
        system.sendAllShipsAway();
        system.addShips("cataclysm_thargoid_hive_1", 1, Vector3D(0, 0, 300000).fromCoordinateSystem("wpm"));
        system.addShips("thargoid", 5, Vector3D(0, 0, 30000).fromCoordinateSystem("wpm"), 50000);
        system.addShips("thargoid", 5, Vector3D(0, 0, 100000).fromCoordinateSystem("wpm"), 50000);
        system.addShips("thargoid", 5, Vector3D(0, 0, 170000).fromCoordinateSystem("wpm"), 50000);
        system.addShips("thargoid", 5, Vector3D(0, 0, 240000).fromCoordinateSystem("wpm"), 50000);

        /*"addShipsAtPrecisely: cataclysm_thargoid_hive_1 1 wpm 0 0 300000", 
        "addShipsWithinRadius: thargoid 5 wpm 0 0 30000 50000", 
        "addShipsWithinRadius: thargoid 5 wpm 0 0 100000 50000", 
        "addShipsWithinRadius: thargoid 5 wpm 0 0 170000 50000", 
        "addShipsWithinRadius: thargoid 5 wpm 0 0 240000 50000"*/
    }
    if (missionVariables.cataclysm_hivemission == "DESTROY_HIVE") {
        this.$addHive2Ships();
    }
}
Scripts/cataclysm-tetier-station.js
"use strict";
/*

cataclysm-tetier-station.js

Ship script for military station at Tetier.


Oolite
Copyright © 2008 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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.

*/


this.name = "cataclysm-tetier-station";
this.author = "Commander McLane";
this.copyright = "© 2009 Commander McLane";
this.version = "1.1";


this.shipBeingAttacked = function (whom) {
	if (whom.primaryRole == "cataclysm_military" || whom.primaryRole == "cataclysm_warship_replica" || whom.isPlayer) return;
	this.ship.reactToAIMessage("ATTACKED_BY_HOSTILE");
}

this.shipAttackedWithMissile = function (missile, whom) {
	if (whom.primaryRole == "cataclysm_military" || whom.primaryRole == "cataclysm_warship_replica" || whom.isPlayer) return;
	this.ship.reactToAIMessage("INCOMING_HOSTILE_MISSILE");
}

this.groupAttackTarget = function () {
	var target = this.ship.target;
	this.ship.reactToAIMessage("GROUP_ATTACK_TARGET");
	system.shipsWithPrimaryRole("cataclysm_military").forEach(function (ship) {
		if (ship.AI != "interceptAI.plist") {
			ship.target = target;
			ship.reactToAIMessage("GROUP_ATTACK_TARGET");
		}
	})
}

this.checkOffender = function () {
	var target = this.ship.target;
	if (target.primaryRole == "cataclysm_military" || target.primaryRole == "cataclysm_tetier_station" || target.primaryRole == "cataclysm_warship_replica" || target.isPlayer) return;
	this.groupAttackTarget();
}

this.defuseCascadeWeapons = function () {
	function isCascadingWeapon(ship) {
		return ship.primaryRole == "EQ_QC_MINE" || ship.primaryRole == "EQ_CASCADE_MISSILE" || ship.name == "Thargoid Robot Mine";
	}
	var cascadeWeapons = system.filteredEntities(this, isCascadingWeapon, this.ship, 100000);
	cascadeWeapons.forEach(function (ship) { ship.explode(); })
}
Scripts/cataclysm-thargoid-hive-1.js
"use strict";
/*

cataclysm-thargoid-hive-1.js

Ship script for thargoid hive (first clone).


Oolite
Copyright © 2008 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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.

*/


this.name = "cataclysm-thargoid-hive-1";
this.author = "Commander McLane";
this.copyright = "© 2009 Commander McLane";
this.version = "1.1";


this.startScan = function () {
	player.consoleMessage("Scan started...", 1);
	this.time = 15;
	this.scanTimer = new Timer(this, this.informPlayer, 1, 1);
}

this.informPlayer = function () {
	if (this.time < 0) {
		player.consoleMessage("Scan complete.");
		this.scanTimer.stop();
		missionVariables.cataclysm_hivemission = "SCANNED";
		player.consoleMessage("Proceed to Onrace to report your findings.");
		mission.setInstructionsKey("cataclysm_report_scan_findings", "Cataclysm");
		return;
	}
	player.consoleMessage("Scan complete in " + this.time + " s.", 1);
	this.time--;
}
Scripts/cataclysm-thargoid-hive-2.js
"use strict";
/*

cataclysm-thargoid-hive-2.js

Ship script for thargoid hive (second clone).


Oolite
Copyright © 2008 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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.

*/


this.name = "cataclysm-thargoid-hive-2";
this.author = "Commander McLane";
this.copyright = "© 2009 Commander McLane";
this.version = "1.1";


this.startCountdown = function () {
	player.consoleMessage("Strong energy fluctuations detected. Get out of here!", 3);
	this.time = 15;
	this.countdownTimer = new Timer(this, this.countDown, 1, 1);
}

this.countDown = function () {
	if (this.time < 0) {
		this.countdownTimer.stop();
		//system.legacy_addShipsAtPrecisely("cataclysm_explosive_alloy", 1, "abs", this.ship.position);
		system.addShips("cataclysm_explosive_alloy", 1, this.ship.position);
		return;
	}
	player.consoleMessage("Hive unstable in " + this.time + " s.", 1);
	this.time--;
}

this.shipAttackedWithMissile = function (missile, whom) {
	missile.explode();
}

this.shipDied = function () {
	this.ship.reactToAIMessage("DEAL_ENERGY_DAMAGE");
	missionVariables.cataclysm_hivemission = "HIVE_DESTROYED";
}
Scripts/cataclysm-thargoid-hive-core.js
"use strict";
/*

cataclysm-thargoid-hive-core.js

Ship script for thargoid hive core.


Oolite
Copyright © 2008 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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.

*/


this.name = "cataclysm-thargoid-hive-core";
this.author = "Commander McLane";
this.copyright = "© 2009 Commander McLane";
this.version = "1.1";


this.shipEnergyIsLow = function () {
	player.consoleMessage("Warning! Energy fluctuations detected.", 3);
}

this.shipDied = function () {
	system.shipsWithPrimaryRole("cataclysm_thargoid_hive_2")[0].AIState = "CORE_EXPLODED";
}
Scripts/cataclysm-warship-replica-1.js
"use strict";
/*

cataclysm-warship-replica-1.js

Ship script for warship replica during flight test.


Oolite
Copyright © 2008 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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.

*/


this.name = "cataclysm-warship-replica-1";
this.author = "Commander McLane";
this.copyright = "© 2009 Commander McLane";
this.version = "1.1";

this.newPhase = function () {
	if (missionVariables.cataclysm == "STAGE10") {
		this.ship.commsMessage("Launch sequence complete. Initiating phase 1: Acceleration and deceleration.");
		missionVariables.cataclysm = "STAGE10a";
		this.ship.AIState = "ACCELERATE";
	}
	else if (missionVariables.cataclysm == "STAGE10c") {
		missionVariables.cataclysm = "STAGE10d";
		this.ship.AIState = "MANOEUVRE_2";
	}
	else if (missionVariables.cataclysm == "STAGE10d") {
		missionVariables.cataclysm = "STAGE10e";
		this.ship.AIState = "MANOEUVRE_3";
	}
	else if (missionVariables.cataclysm == "STAGE10g") {
		this.ship.commsMessage("Target 1 destroyed. Targeting target 2.");
		missionVariables.cataclysm = "STAGE10h";
		this.ship.target = system.shipsWithPrimaryRole("cataclysm_target_asteroid_2")[0];
		this.ship.target.target = this.ship;
		this.ship.AIState = "ATTACK_TARGET";
		this.ship.reactToAIMessage("ATTACKED");
	}
	else if (missionVariables.cataclysm == "STAGE10h") {
		this.ship.commsMessage("Target 2 destroyed. Targeting target 3.");
		missionVariables.cataclysm = "STAGE10i";
		this.ship.target = system.shipsWithPrimaryRole("cataclysm_target_asteroid_3")[0];
		this.ship.target.target = this.ship;
		this.ship.AIState = "ATTACK_TARGET";
		this.ship.reactToAIMessage("ATTACKED");
	}
	else if (missionVariables.cataclysm == "STAGE10i") {
		this.ship.commsMessage("Phase 5 complete. Initiating phase 6: Missile practice.");
		missionVariables.cataclysm = "STAGE10j";
		this.ship.target = system.shipsWithPrimaryRole("cataclysm_target_asteroid_4")[0];
		this.ship.AIState = "ATTACK_WITH_MISSILE";
		this.ship.reactToAIMessage("ATTACKED");
	}
	else if (missionVariables.cataclysm == "STAGE10j") {
		this.ship.commsMessage("Phase 6 complete. Initiating phase 7: Full combat practice.");
		missionVariables.cataclysm = "STAGE10k";
		this.ship.target = player.ship;
		this.ship.AIState = "ATTACK_PLAYER";
		if (worldScripts.BountySystem_Core) {
			worldScripts.BountySystem_Core._changing = true;
		}
	}
	else if (missionVariables.cataclysm == "STAGE10k") {
		this.ship.commsMessage("Phase 7 complete. Test complete. Returning to base.");
		this.ship.bounty = 0;
		player.bounty = 0;
		missionVariables.cataclysm = "STAGE10l";
		this.ship.fuel = 7;
		this.ship.target = system.shipsWithPrimaryRole("cataclysm_tetier_station")[0];
		this.ship.AIState = "RETURN_TO_STATION";
		// turn on the repurchase function again, if it was turned off
		if (worldScripts.ShipRepurchase) {
			var sr = worldScripts.ShipRepurchase;
			sr.shipTakingDamage = sr.$hide_shipTakingDamage;
			delete sr.$hide_shipTakingDamage;
		}
	}
	else if (this.ship.position.distanceTo(player.ship.position) < 2200) {
		if (missionVariables.cataclysm == "STAGE10a") {
			this.ship.commsMessage("Phase 1 complete. Initiating phase 2: Pitch and roll.");
			missionVariables.cataclysm = "STAGE10b";
			this.ship.AIState = "TUMBLE";
		}
		else if (missionVariables.cataclysm == "STAGE10b") {
			this.ship.commsMessage("Phase 2 complete. Initiating phase 3: Manoeuvring through the asteroid belt.");
			missionVariables.cataclysm = "STAGE10c";
			this.ship.AIState = "MANOEUVRE_1";
		}
		else if (missionVariables.cataclysm == "STAGE10e") {
			this.ship.commsMessage("Phase 3 complete. Initiating phase 4: Fuel injectors.");
			missionVariables.cataclysm = "STAGE10f";
			this.ship.AIState = "INJECTORS";
		}
		else if (missionVariables.cataclysm == "STAGE10f") {
			this.ship.commsMessage("Phase 4 complete. Initiating phase 5: Laser practice.");
			missionVariables.cataclysm = "STAGE10g";
			this.ship.fuel = 0;
			this.ship.target = system.shipsWithPrimaryRole("cataclysm_target_asteroid_1")[0];
			this.ship.target.target = this.ship;
			this.ship.AIState = "ATTACK_TARGET";
			this.ship.reactToAIMessage("ATTACKED");
		}
	}
}

this.checkForDestroyedTarget = function () {
	if (!this.ship.target) this.ship.reactToAIMessage("DESTROYED_TARGET");
}

this.checkForMissileFired = function () {
	if (!this.ship.target) {
		this.ship.reactToAIMessage("DESTROYED_TARGET");
		return;
	}
	function isMyMissile(missile) {
		return missile.owner == this.ship;
	}
	if (system.filteredEntities(this, isMyMissile, this.ship, 25000).length == 0)
		this.ship.reactToAIMessage("TARGET_FOUND");
}

this.startCombatTimer = function () {
	this.combatTimer = new Timer(this, this.stopCombat, 120);
}

this.stopCombat = function () {
	this.combatTimer.stop();
	if (worldScripts.BountySystem_Core) {
		worldScripts.BountySystem_Core._changing = false;
	}
	// make sure there aren't any missiles in transit that could destroy a low energy player/replica
	var s = this.ship.checkScanner(true);
	var sl = s.length;
	while (sl--) {
		if (s[sl].isMissile) s[sl].explode();
	}
	this.ship.reactToAIMessage("COMBAT_ENDED");
}

this.shipBeingAttacked = function (whom) {
	if (whom.isPlayer) player.bounty = 0;
}

this.shipEnergyIsLow = function () {
	if (missionVariables.cataclysm == "STAGE10k") this.ship.energy *= 1.5;
}

this.sendTestCompleteMessage = function () {
	if (this.ship.target.position.distanceTo(player.ship.position) < 25000)
		this.ship.target.commsMessage("Congratulations for the successful test to both of you! Commander Cunynghame, please come in first.");
	else
		player.commsMessage("Congratulations for the successful test to both of you! Commander Cunynghame, please come in first.", 6);
}

this.shipDockedWithStation = function (station) {
	if (missionVariables.cataclysm == "STAGE10l") {
		station.commsMessage("Docking sequence complete. Please dock as well, Commander " + expandDescription("[commander_name]") + ".");
		missionVariables.cataclysm = "STAGE10m";
	}
}

this.shipDied = function (whom, why) {
	if (whom.isPlayer) {
		player.commsMessage("Commander, the replica was not to be harmed. Expect full retaliation!", 6);
		if (worldScripts.BountySystem_Core) {
			worldScripts.BountySystem_Core._changing = false;
		}
		player.setBounty(500, "war crimes");
		system.shipsWithPrimaryRole("cataclysm_military").forEach(function (ship) {
			ship.target = player.ship;
			ship.reactToAIMessage("GROUP_ATTACK_TARGET");
		})
		system.shipsWithPrimaryRole("cataclysm_tetier_station")[0].target = player.ship;
		system.shipsWithPrimaryRole("cataclysm_tetier_station")[0].reactToAIMessage("GROUP_ATTACK_TARGET");
	}
	else {
		this.AI_State = this.ship.AIState;
		var newGame = this.ship.spawnOne("cataclysm_warship_replica_1");
		newGame.AIState = this.AI_State;
	}
	var stns = system.stations;
	var i = stns.length;
	while (i--) {
		stns[i].abortDockingForShip(this.ship);
	}
}
Scripts/cataclysm-warship-replica-2.js
"use strict";
/*

cataclysm-warship-replica-2.js

Ship script for warship replica during fight.


Oolite
Copyright © 2008 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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.

*/


this.name = "cataclysm-warship-replica-2";
this.author = "Commander McLane";
this.copyright = "© 2009 Commander McLane";
this.version = "1.1";


this.shipEnergyIsLow = function () {
	this.ship.energy *= 2;
}

this.shipDied = function () {
	this.ship.spawnOne("cataclysm_warship_replica_2");
	var stns = system.stations;
	var i = stns.length;
	while (i--) {
		stns[i].abortDockingForShip(this.ship);
	}
}

this.shipSpawned = this.shipLaunchedFromStation = function () {
	this.ship.primaryRole = "cataclysm_military";
}

this.shipBeingAttacked = function (whom) {
	if (whom.primaryRole == "cataclysm_military" || whom.primaryRole == "cataclysm_tetier_station" || whom.isPlayer) return;
	this.ship.reactToAIMessage("ATTACKED_BY_HOSTILE");
}

this.shipAttackedWithMissile = function (missile, whom) {
	if (whom.primaryRole == "cataclysm_military" || whom.primaryRole == "cataclysm_tetier_station" || whom.isPlayer) return;
	this.ship.reactToAIMessage("INCOMING_HOSTILE_MISSILE");
}

this.groupAttackTarget = function () {
	var target = this.ship.target;
	this.ship.reactToAIMessage("GROUP_ATTACK_TARGET");
	system.shipsWithRole("cataclysm_military", this.ship, 8000).forEach(function (ship) {
		if (ship.AI == "cataclysm_militaryAI.plist") {
			ship.target = target;
			ship.reactToAIMessage("GROUP_ATTACK_TARGET");
		}
	})
	system.shipsWithPrimaryRole("cataclysm_tetier_station")[0].target = target;
	system.shipsWithPrimaryRole("cataclysm_tetier_station")[0].reactToAIMessage("GROUP_ATTACK_TARGET");
}

this.checkOffender = function () {
	var target = this.ship.target;
	if (target.primaryRole == "cataclysm_military" || target.primaryRole == "cataclysm_tetier_station" || target.isPlayer) return;
	this.groupAttackTarget();
}
Scripts/cataclysm.js
"use strict";
/*

Cataclysm.js

Script for Cataclysm.oxp.


Oolite
Copyright © 2008 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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.

*/

this.name = "Cataclysm";
this.author = "Commander McLane";
this.copyright = "© 2009 Commander McLane";
this.version = "2.0";

/*variables*/

this.hiveLocations = new Array()
this.hiveLocations[0] = [134, 176, 22, 195, 4, 184, 44, 228, 48, 144, 68, 211]
this.hiveLocations[1] = [20, 63, 207, 241, 28, 177, 30, 210, 5, 229, 61, 92]
this.hiveLocations[2] = [115, 196, 13, 159, 17, 218, 219, 233, 58, 76, 65, 79]
this.hiveLocations[3] = [131, 180, 175, 225, 20, 152, 48, 167, 56, 238, 83, 114]
this.hiveLocations[4] = [158, 212, 18, 186, 187, 207, 77, 246, 78, 125, 97, 108]
this.hiveLocations[5] = [116, 221, 153, 241, 26, 169, 43, 175, 5, 194, 85, 99]
this.hiveLocations[6] = [109, 215, 12, 174, 39, 44, 40, 158, 48, 120, 85, 99, 27, 153]
this.hiveLocations[7] = [173, 179, 237, 245, 33, 78, 44, 70, 61, 138, 66, 165]

this.systemList = {
	"0": [16, 28, 36, 56, 62, 83, 91, 110, 145, 150, 179, 198, 200, 230, 237],
	"4": [24, 26, 35, 41, 111, 112, 180, 181, 183, 210, 216, 222, 231],
	"5": [33, 41, 55, 202],
	"6": [15, 17, 27, 30, 61, 79, 97, 110, 115, 125, 130, 134, 137, 139, 153, 161, 173, 178, 186, 191, 205, 214, 218, 228, 229, 237, 248],
};

this.choice = null;

/* functions */

//-------------------------------------------------------------------------------------------------------------
this.turnStationToPlanet = function (station) {
	var type = "Research";
	if (station.name.indexOf("Military") >= 0) type = "Military";
	var targetVector = system.mainPlanet.position.subtract(station.position).direction();
	station.orientation = targetVector.rotationTo([0, 0, 1]);
	var buoy = system.addShips("cataclysm_stn_buoy", 1, station.position.add(station.vectorForward.multiply(10E3)), 0)[0];
	buoy.beaconLabel = buoy.beaconLabel.replace("Navy", type);
	buoy.displayName = buoy.displayName.replace("Navy", type);
	// TODO: work out why buoy isn't directly in line with station exit in some cases
}

//-------------------------------------------------------------------------------------------------------------
this.blockSystemRedux = function () {
	if (worldScripts["System Redux"]) {
		var sr = worldScripts["System Redux"];
		// make sure system redux startup script has been run before we try to add moon exclusions
		if (!sr.excl) {
			sr.startUp();
		}
		delete sr.startUp;
		//system_info[0 * 256 + 164] = system_info[0 * 256 + 164] & 0xFFF0
		if (sr.excl[0].indexOf(164) == -1) sr.excl[0].push(164);
		//system_info[2 * 256 + 86] = system_info[2 * 256 + 86] & 0xFFF0
		if (sr.excl[2].indexOf(86) == -1) sr.excl[2].push(86);
		//system_info[5 * 256 + 33] = system_info[5 * 256 + 33] & 0xFF00
		if (sr.excl[5].indexOf(33) == -1) sr.excl[5].push(33);
	}
}

//-------------------------------------------------------------------------------------------------------------
this.advanceJumpCounters = function () {
	if (galaxyNumber == 0) {
		if (missionVariables.cataclysm == "STAGE1")
			missionVariables.cataclysm = "STAGE1a";
		if (missionVariables.cataclysm == "STAGE1b")
			missionVariables.cataclysm = "STAGE1c";
	}
}

//-------------------------------------------------------------------------------------------------------------
this.checkForGalDriveMod = function () {
	if (player.ship.hasEquipmentProviding("EQ_GAL_DRIVE_MOD")) {
		this.defaultGalacticHyperspaceBehaviour = player.ship.galacticHyperspaceBehaviour;
		player.ship.galacticHyperspaceBehaviour = "BEHAVIOUR_ALL_SYSTEMS_REACHABLE";
	}
}

//-------------------------------------------------------------------------------------------------------------
this.resetGalHyperspaceBehaviour = function () {
	if (player.ship.hasEquipmentProviding("EQ_GAL_DRIVE_MOD")) {
		player.ship.removeEquipment("EQ_GAL_DRIVE_MOD");
		player.ship.galacticHyperspaceBehaviour = this.defaultGalacticHyperspaceBehaviour;
	}
}

//-------------------------------------------------------------------------------------------------------------
this.switchMilitaryAI = function () {
	system.shipsWithPrimaryRole("military-ship").forEach(
		function (ship) {
			ship.switchAI("route1patrolAI.plist");
			ship.fuel = 15;
		}
	)
}

//-------------------------------------------------------------------------------------------------------------
this.setupThargoidShipScript = function () {
	this.livingThargoids = system.shipsWithPrimaryRole("thargoid", system.mainStation, 60000);
	this.thargoidsKilledByPlayer = 0;
	this.livingThargoids.forEach(
		function (ship) {
			ship.script.shipDied = function (whom, why) {
				if (whom == player.ship) {
					worldScripts.Cataclysm.thargoidsKilledByPlayer++;
				}
			}
		}
	)
}

//-------------------------------------------------------------------------------------------------------------
this.startThargoidsRemainingTimer = function () {
	if (!this.thargoidsRemainingTimer)
		this.thargoidsRemainingTimer = new Timer(this, this.countRemainingThargoids, 0, 10);
	else
		this.thargoidsRemainingTimer.start();
}

//-------------------------------------------------------------------------------------------------------------
this.countRemainingThargoids = function () {
	var stn = system.mainStation;
	if (this.currentSystem == "Tetier") {
		this.tetierStation = system.shipsWithPrimaryRole("cataclysm_tetier_station")[0];
		stn = this.tetierStation;
	}
	var thargoidsNearStation = system.countShipsWithPrimaryRole("thargoid", stn, 50000);

	if (this.currentSystem == "Galaxy1") {
		if (thargoidsNearStation == 0) {
			this.$findNearestStation().commsMessage("The attack is over. Thanks for your help, Commander. Please return to the station.");
			missionVariables.cataclysm = "STAGE2a";
			this.thargoidsRemainingTimer.stop();
		}
	} else if (this.currentSystem == "Ribilebi") {
		if (thargoidsNearStation < 3) {
			this.$findNearestStation().commsMessage("Well done, Commander! We can clear up the rest. You head for the Research Station. 'R' on your compass.");
			var stn = system.shipsWithPrimaryRole("cataclysm_ribilebi_station")[0];
			// only turn the beacon on now.
			stn.beaconCode = "R";
			stn.beaconLabel = "Ribilebi Research Station";
			missionVariables.cataclysm = "STAGE4a";
			this.thargoidsRemainingTimer.stop();
		} else
			player.consoleMessage(expandDescription("[cataclysm_defend_Ribilebi_hail]"), 3);
	} else if (this.currentSystem == "Galaxy3") {
		if (thargoidsNearStation == 0) {
			this.$findNearestStation().commsMessage("The attack is over. Thanks for your help, Commander. Please return to the station.");
			missionVariables.cataclysm_missions = "STATION_DEFENDED";
			this.thargoidsRemainingTimer.stop();
		}
	} else if (this.currentSystem == "Tetier") {
		if (thargoidsNearStation == 0) {
			this.$findNearestStation().commsMessage("We smashed them! Return to the station, Commander.");
			missionVariables.cataclysm = "STAGE11c";
			this.thargoidsRemainingTimer.stop();
			var replica = system.shipsWithRole("cataclysm_warship_replica_2")[0];
			if (replica) {
				replica.target = this.tetierStation;
				replica.setAI("dockingAI.plist");
			}
		}
	}
}

//-------------------------------------------------------------------------------------------------------------
// returns the nearest station to the player
this.$findNearestStation = function () {
	function _stations(entity) {
		return entity.isShip && entity.isStation;
	}
	return system.filteredEntities(this, _stations, player.ship)[0];
}

//-------------------------------------------------------------------------------------------------------------
this.$findNearestGalCopShip = function () {
	function _galcop(entity) {
		return entity.isShip && (entity.isStation || entity.isPolice);
	}
	return system.filteredEntities(this, _galcop, player.ship)[0];
}

//-------------------------------------------------------------------------------------------------------------
// I'm not sure why we're doing these next two functions
// basically, we're removing three pieces of equipment when the system is populated
// and then giving them back once you dock at a station.
// in the case of the cloak, it's only removed if you haven't completed the mission, so an anti-cheat?
// or is this to make the missions harder because with these items the missions would be super easy? not sure.
this.dealWithIllicitEquipment1 = function () {
	if (player.ship.hasEquipmentProviding("EQ_CLOAKING_DEVICE") && missionVariables.cloak != "COMPLETE") {
		player.ship.removeEquipment("EQ_CLOAKING_DEVICE");
		this.illicitEquipment |= 1;
	}
	if (player.ship.hasEquipmentProviding("EQ_MILITARY_JAMMER") && !this.MJlegal) {
		player.ship.removeEquipment("EQ_MILITARY_JAMMER");
		this.illicitEquipment |= 2;
	}
	if (player.ship.hasEquipmentProviding("EQ_MILITARY_SCANNER_FILTER") && !this.MSFlegal) {
		player.ship.removeEquipment("EQ_MILITARY_SCANNER_FILTER");
		this.illicitEquipment |= 4;
	}
}

//-------------------------------------------------------------------------------------------------------------
this.dealWithIllicitEquipment2 = function () {
	if ((this.illicitEquipment & 1) == 1) {
		player.ship.awardEquipment("EQ_CLOAKING_DEVICE");
		this.illicitEquipment -= 1;
	}
	if ((this.illicitEquipment & 2) == 2) {
		player.ship.awardEquipment("EQ_MILITARY_JAMMER");
		this.illicitEquipment -= 2;
	}
	if ((this.illicitEquipment & 4) == 4) {
		player.ship.awardEquipment("EQ_MILITARY_SCANNER_FILTER");
		this.illicitEquipment -= 4;
	}
}

//-------------------------------------------------------------------------------------------------------------
this.stopWaiting = function () {
	missionVariables.cataclysm_hivemission = "WAIT_ENDED";
	delete this.waitTimer;
	this.missionScreens();
}

//-------------------------------------------------------------------------------------------------------------
this.wormholeCollapsed = function () {
	if (missionVariables.cataclysm == "STAGE7") {
		var commsSrc = this.$findNearestGalCopShip();
		if (!commsSrc) commsSrc = player;
		commsSrc.commsMessage("The crew on board the Warship escaped successfully. You have to search for them in the adjacent systems.");
		mission.setInstructionsKey("cataclysm_search_for_warship");
		this.searchWarshipTimer = new Timer(this, this.warshipSearchOver, 360);
	}
	delete this.wormholeCollapseTimer;
}

//-------------------------------------------------------------------------------------------------------------
this.warshipSearchOver = function () {
	missionVariables.cataclysm = "STAGE7c";
	delete this.searchWarshipTimer;
}

//-------------------------------------------------------------------------------------------------------------
this.missionScreens = function () {
	if (guiScreen == "GUI_SCREEN_MISSION" || !player.ship.docked) return;

	if (galaxyNumber == 0) {
		if (player.ship.dockedStation.isMainStation) {
			if (!missionVariables.cataclysm &&
				player.score > 5119 &&
				missionVariables.thargplans == "MISSION_COMPLETE" && this.systemList["0"].indexOf(system.ID) >= 0
				&& !missionVariables.offering) {
				this.runMissionScreen("cataclysm_intro_inews", "iNews.png");
				missionVariables.cataclysm = "STAGE1";
			}
			else if (missionVariables.cataclysm == "STAGE1a") {
				missionVariables.cataclysm = "STAGE1b";
			}
			else if (missionVariables.cataclysm == "STAGE1c" && player.ship.bounty == 0 && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_station_attack", null, "cataclysm_launch", null, "siren.ogg");
				mission.setInstructionsKey("cataclysm_defend_station");
				//system.legacy_addSystemShips("thargoid", 6, 0.98);
				system.addShips("thargoid", 6, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.98), 10000);
				//system.legacy_addSystemShips("trader", 4, 0.985);
				system.addShips("trader", 4, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.985), 10000);
				//system.legacy_addSystemShips("police", 3, 0.985);
				system.addShips("police", 3, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.985), 10000);
				this.setupThargoidShipScript();
				this.currentSystem = "Galaxy1";
				this.startThargoidsRemainingTimer();
				missionVariables.offering = "CATACLYSM";
				missionVariables.cataclysm = "STAGE1d";
			}
			else if (missionVariables.cataclysm == "STAGE1d" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_LAUNCH") {
				this.choice = null;
				player.ship.launch();
				delete missionVariables.offering;
				missionVariables.cataclysm = "STAGE2";
			}
			else if (missionVariables.cataclysm == "STAGE2a" && !missionVariables.offering) {
				this.$addPadLogEntry("Helped defend the main station in " + system.name + " from a Thargoid attack.");
				if (this.thargoidsKilledByPlayer > 2) {
					this.runMissionScreen("cataclysm_station_attack_debrief", "cataclysm_navy_star.png");
					this.$updateCurruthers();
					mission.setInstructionsKey("cataclysm_goto_Ribilebi");
					mission.markSystem({system:164, name:this.name});
					player.credits += 2000;
					missionVariables.cataclysm = "STAGE3";
				}
				else {
					this.runMissionScreen("cataclysm_station_attack_debrief_alt");
					mission.setInstructionsKey(null);
					player.credits += 500;
					missionVariables.cataclysm = "STAGE1";
				}
				delete this.livingThargoids;
				delete this.thargoidsKilledByPlayer;
			}
			else if (missionVariables.cataclysm == "STAGE3" && system.ID == 164 && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_ribilebi_brief_1", "cataclysm_navy_star.png", "cataclysm_continue");
				mission.unmarkSystem({system:164, name:this.name});
				missionVariables.offering = "CATACLYSM";
				missionVariables.cataclysm = "STAGE3a";
			}
			else if (missionVariables.cataclysm == "STAGE3a" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_CONT") {
				this.choice = null;
				this.runMissionScreen("cataclysm_ribilebi_brief_2", null, "cataclysm_continue", "cataclysm_disabled_warship_1");
				missionVariables.cataclysm = "STAGE3b";
			}
			else if (missionVariables.cataclysm == "STAGE3b" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_CONT") {
				this.choice = null;
				this.runMissionScreen("cataclysm_ribilebi_attack", null, "cataclysm_launch", null, "siren.ogg");
				mission.setInstructionsKey("cataclysm_defend_Ribilebi");
				var pos = Vector3D(86294, -48749, 73138).fromCoordinateSystem("pwm");
				//system.legacy_addShipsWithinRadius("thargoid", 8, "pwm", [86294, -48749, 73138], 25000);
				system.addShips("thargoid", 8, pos, 25000);
				//system.legacy_addShipsWithinRadius("trader", 5, "pwm", [86294, -48749, 73138], 25000);
				system.addShips("trader", 5, pos, 25000);
				//system.legacy_addShipsWithinRadius("police", 4, "pwm", [86294, -48749, 73138], 25000);
				system.addShips("police", 4, pos, 25000);
				missionVariables.cataclysm = "STAGE3c";
			}
			else if (missionVariables.cataclysm == "STAGE3c" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_LAUNCH") {
				player.ship.fuel += 3;
				this.currentSystem = "Ribilebi";
				this.startThargoidsRemainingTimer();
				player.ship.launch();
				delete missionVariables.offering;
				this.choice = null;
				missionVariables.cataclysm = "STAGE4";
			}
		}
		else if (player.ship.dockedStation.name == "Ribilebi Research Station") {
			if (missionVariables.cataclysm == "STAGE4a" && !missionVariables.offering) {
				this.$addPadLogEntry("Helped defend the main station in " + system.name + " from a Thargoid attack.");
				this.runMissionScreen("cataclysm_ribilebi_brief_3", null, "cataclysm_continue", "cataclysm_disabled_warship_1");
				missionVariables.offering = "CATACLYSM";
				missionVariables.cataclysm = "STAGE4b";
			}
			else if (missionVariables.cataclysm == "STAGE4b" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_CONT") {
				this.runMissionScreen("cataclysm_ribilebi_brief_4", null, null, "cataclysm_disabled_warship_1");
				this.choice = 0;
				if (player.ship.hasEquipmentProviding("EQ_GAL_DRIVE")) {
					mission.addMessageTextKey("cataclysm_ribilebi_brief_4a");
					player.credits += 5000;
				}
				else {
					mission.addMessageTextKey("cataclysm_ribilebi_brief_4b");
					player.ship.awardEquipment("EQ_GAL_DRIVE");
				}
				mission.addMessageTextKey("cataclysm_ribilebi_brief_4c");
				mission.setInstructionsKey("cataclysm_goto_Galaxy3");
				delete missionVariables.offering;
				missionVariables.cataclysm = "STAGE5";
			}
		}
	}
	else if (galaxyNumber == 2) {
		if (player.ship.dockedStation.isMainStation) {
			if (missionVariables.cataclysm == "STAGE5" && system.ID != 36 && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_galaxy3_brief", "cataclysm_navy_star.png");
				mission.setInstructionsKey("cataclysm_meet_Agent_Blake");
				mission.markSystem({system:36, name:this.name});
				missionVariables.cataclysm = "STAGE6";
			}
			else if (missionVariables.cataclysm == "STAGE6" &&
				system.ID != 36 &&
				!missionVariables.cataclysm_missions &&
				!missionVariables.offering) {
				if (missionVariables.cataclysm_trigger > 11 && missionVariables.cataclysm_trigger < 20) {
					this.runMissionScreen("cataclysm_defector_brief", null, null, "[ferdelance]");
					mission.setInstructionsKey("cataclysm_kill_defector");
					//system.legacy_addShipsAt("cataclysm_defector", 1, "pwm", [1000, -1000, 150000]);
					system.addShips("cataclysm_defector", 1, Vector3D(1000, -1000, 150000).fromCoordinateSystem("pwm"));
					//system.legacy_addShipsAt("police", 2, "pwm", [1000, -1000, 145000]);
					system.addShips("police", 2, Vector3D(1000, -1000, 145000).fromCoordinateSystem("pwm"));
					//system.legacy_addSystemShips("thargoid", 2, 0.95);
					system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.95));
					missionVariables.cataclysm_missions = "DEFECTOR_HUNT";
				}
				else if (missionVariables.cataclysm_trigger > 88 && missionVariables.cataclysm_trigger < 98) {
					missionVariables.cataclysm_ambassador_name = expandDescription("[nom11]");
					this.runMissionScreen("cataclysm_ambassador_brief", null, null, "[boa-mk2]");
					mission.setInstructionsKey("cataclysm_escort_ambassador");
					//system.legacy_addSystemShips("cataclysm_ambassador", 1, 0.8);
					system.addShips("cataclysm_ambassador", 1, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.8));
					//system.legacy_addSystemShips("thargoid", 2, 0.92);
					system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.92));
					//system.legacy_addSystemShips("thargoid", 2, 0.85);
					system.addShips("thargoid", 1, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.85));
					missionVariables.cataclysm_missions = "ESCORT_AMBASSADOR";
				}
				else if (missionVariables.cataclysm_trigger > 33 && missionVariables.cataclysm_trigger < 49) {
					this.runMissionScreen("cataclysm_station_attack", null, "cataclysm_launch", null, "siren.ogg");
					mission.setInstructionsKey("cataclysm_defend_station_2");
					//system.legacy_addSystemShips("thargoid", 6, 0.98);
					system.addShips("thargoid", 6, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.98), 10000);
					//system.legacy_addSystemShips("trader", 4, 0.985);
					system.addShips("trader", 4, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.985), 10000);
					//system.legacy_addSystemShips("police", 3, 0.985);
					system.addShips("police", 3, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.985), 10000);
					this.currentSystem = "Galaxy3";
					this.startThargoidsRemainingTimer();
					missionVariables.offering = "CATACLYSM";
					missionVariables.cataclysm_missions = "STATION_ATTACK";
				}
				else if (missionVariables.cataclysm_trigger > 55 && missionVariables.cataclysm_trigger < 71) {
					this.runMissionScreen("cataclysm_evacuation_brief");
					player.ship.removeAllCargo();
					missionVariables.cataclysm_sourceplanet = expandDescription("%I");
					player.ship.useSpecialCargo("A hold full of " + missionVariables.cataclysm_sourceplanet + " refugees");
					mission.setInstructionsKey("cataclysm_evacuation");
					missionVariables.cataclysm_sourceplanet_nr = system.ID;
					missionVariables.cataclysm_missions = "EVACUATION";
				}
			}
			else if (missionVariables.cataclysm_missions == "DEFECTOR_KILLED" && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_defector_debrief");
				this.$addPadLogEntry("Managed to kill a defector in the " + system.name + " system.");
				player.credits += 1250;
				mission.setInstructionsKey("cataclysm_meet_Agent_Blake");
				missionVariables.cataclysm_missions = "DONE";
			}
			else if (missionVariables.cataclysm_missions == "DEFECTOR_ESCAPED" && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_defector_escaped");
				this.$addPadLogEntry("Wasn't able to capture a defector in the " + system.name + " system.");
				mission.setInstructionsKey("cataclysm_meet_Agent_Blake");
				missionVariables.cataclysm_missions = "DONE";
			}
			else if (missionVariables.cataclysm_missions == "AMBASSADOR_SUCCESS" && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_ambassador_success");
				this.$addPadCharacter("ambassador", expandDescription("%N") + " " + missionVariables.cataclysm_ambassador_name);
				this.$addPadLogEntry("Rescued Ambassador " + missionVariables.cataclysm_ambassador_name + " from a Thargoid attack.");
				player.credits += 1000;
				mission.setInstructionsKey("cataclysm_meet_Agent_Blake");
				delete missionVariables.cataclysm_ambassador_name;
				missionVariables.cataclysm_missions = "DONE";
			}
			else if (missionVariables.cataclysm_missions == "AMBASSADOR_FAILURE" && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_ambassador_failure");
				this.$addPadCharacter("ambassador", expandDescription("%N") + " " + missionVariables.cataclysm_ambassador_name, null, null, "Died " + clock.clockStringForTime(clock.adjustedSeconds) + " in the " + system.name + " system.");
				this.$addPadLogEntry("Couldn't save Ambassador " + missionVariables.cataclysm_ambassador_name + " from a Thargoid attack.");
				mission.setInstructionsKey("cataclysm_meet_Agent_Blake");
				delete missionVariables.cataclysm_ambassador_name;
				missionVariables.cataclysm_missions = "DONE";
			}
			else if (missionVariables.cataclysm_missions == "AMBASSADOR_FAILURE2" && !missionVariables.offering) {
				this.$addPadLogEntry("Couldn't save Ambassador " + missionVariables.cataclysm_ambassador_name + " from bad piloting.");
				this.$addPadCharacter("ambassador", expandDescription("%N") + " " + missionVariables.cataclysm_ambassador_name, null, null, "Died " + clock.clockStringForTime(clock.adjustedSeconds) + " in the " + system.name + " system.");
				this.runMissionScreen("cataclysm_ambassador_failure2");
				mission.setInstructionsKey("cataclysm_meet_Agent_Blake");
				delete missionVariables.cataclysm_ambassador_name;
				missionVariables.cataclysm_missions = "DONE";
			}
			else if (missionVariables.cataclysm_missions == "STATION_ATTACK" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_LAUNCH") {
				this.choice = null;
				player.ship.launch();
				delete missionVariables.offering;
				missionVariables.cataclysm_missions = "DEFEND_STATION";
			}
			else if (missionVariables.cataclysm_missions == "DEFEND_STATION" && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_station_attack_continues", null, "cataclysm_launch", null, "siren.ogg");
				missionVariables.offering = "CATACLYSM";
				missionVariables.cataclysm_missions = "STATION_ATTACK";
			}
			else if (missionVariables.cataclysm_missions == "STATION_DEFENDED" && !missionVariables.offering) {
				missionVariables.clockDays = clock.days;
				this.runMissionScreen("cataclysm_station_attack_thanks");
				this.$addPadLogEntry("Defended the main station in " + system.name + " from a Thargoid attack.");
				delete missionVariables.clockDays;
				mission.setInstructionsKey("cataclysm_meet_Agent_Blake");
				missionVariables.cataclysm_missions = "DONE";
			}
			else if (missionVariables.cataclysm_missions == "EVACUATION" && system.ID != missionVariables.cataclysm_sourceplanet_nr && !missionVariables.offering) {
				this.$addPadLogEntry("Delivered evacuees from " + System.systemNameForID(missionVariables.cataclysm_sourceplanet_nr) + " the main station in " + system.name + ".");
				this.runMissionScreen("cataclysm_evacuation_debrief");
				mission.setInstructionsKey("cataclysm_meet_Agent_Blake");
				player.ship.removeAllCargo();
				player.credits += 1000;
				delete missionVariables.cataclysm_sourceplanet;
				delete missionVariables.cataclysm_sourceplanet_nr;
				missionVariables.cataclysm_missions = "DONE";
			}
			else if (missionVariables.cataclysm == "STAGE6" && system.ID == 36 && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_birera_brief", null, null, "cataclysm_disabled_warship_1");
				mission.unmarkSystem({system:36, name:this.name});
				delete missionVariables.cataclysm_trigger;
				mission.markSystem({system:86, name:this.name});
				mission.setInstructionsKey("cataclysm_goto_Enrece");
				missionVariables.cataclysm = "STAGE6a";
			}
			else if (missionVariables.cataclysm == "STAGE7a" && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_post_enrece_brief_1", null, "cataclysm_wait", "cataclysm_disabled_warship_1");
				missionVariables.offering = "CATACLYSM";
				missionVariables.cataclysm = "STAGE7b";
			}
			else if (missionVariables.cataclysm == "STAGE7b" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_WAIT") {
				this.runMissionScreen("cataclysm_post_enrece_brief_2", null, null, "cataclysm_disabled_warship_1");
				this.$addPadLogEntry("Prevented the Thargoids from stealing the disabled warship in the " + system.name + " system.");
				player.credits += 5000;
				mission.setInstructionsKey("cataclysm_goto_Aquxein");
				this.choice = null;
				delete missionVariables.offering;
				missionVariables.cataclysm_hivemission = "WAITING";
				missionVariables.cataclysm = "STAGE8A";
			}
			else if (missionVariables.cataclysm == "STAGE7c" && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_post_enrece_brief_3", null, null, "cataclysm_disabled_warship_1");
				this.$addPadLogEntry("Prevented the Thargoids from stealing the disabled warship in the " + system.name + " system.");
				player.credits += 5000;
				mission.setInstructionsKey("cataclysm_goto_Aquxein");
				this.choice = null;
				delete missionVariables.offering;
				missionVariables.cataclysm_hivemission = "WAITING";
				missionVariables.cataclysm = "STAGE8A";
			}
			else if (missionVariables.cataclysm == "DESTROYED" && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_warship_destroyed_brief_1", null, null, "cataclysm_disabled_warship_1");
				this.$addPadLogEntry("Couldn't stop the Thargoids from destroying the disabled warship in the " + system.name + " system.");
				player.credits += 5000;
				mission.setInstructionsKey(null);
				missionVariables.cataclysm_delay_counter = 0;
				missionVariables.cataclysm = "DELAY";
			}
			else if (missionVariables.cataclysm == "E_RESCUED" && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_engineer_rescued_brief", null, null, "[escape-capsule]");
				this.$addPadLogEntry("Couldn't stop the Thargoids from destroying the disabled warship in the " + system.name + " system.");
				this.$addPadLogEntry("Rescued the engineer from the disabled warship, though.");
				player.credits += 5000;
				mission.setInstructionsKey(null);
				missionVariables.cataclysm_engineer = "RESCUED";
				missionVariables.cataclysm_delay_counter = 6;
				missionVariables.cataclysm = "DELAY";
			}
		}
		else if (player.ship.dockedStation.name == "Enrece Research Station") {
			if (missionVariables.cataclysm == "STAGE6a" && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_enrece_brief", null, null, "[thargoid]");
				mission.unmarkSystem({system:86, name:this.name});
				mission.setInstructionsKey("cataclysm_pursue_Thargoids");
				//system.legacy_addShips("thargoid", 5);
				system.addShips("thargoid", 5);
				//system.legacy_addShips("trader", 2);
				system.addShips("trader", 2);
				//system.legacy_addShips("cataclysm_disabled_warship_1", 1);
				system.addShips("cataclysm_disabled_warship_1", 1);
				missionVariables.cataclysm = "STAGE7";
			}
			else if (missionVariables.cataclysm == "DESTROYED" && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_warship_destroyed_brief_2", null, null, "cataclysm_disabled_warship_1");
				this.$addPadLogEntry("Couldn't stop the Thargoids from destroying the disabled warship in the " + system.name + " system.");
				player.credits += 5000;
				mission.setInstructionsKey(null);
				missionVariables.cataclysm_delay_counter = 0;
				missionVariables.cataclysm = "DELAY";
			}
		}
	}
	else if (player.ship.dockedStation.isMainStation && missionVariables.cataclysm == "DELAY" &&
		system.ID != 216 && missionVariables.cataclysm_delay_counter > 18 && !missionVariables.offering) {
		this.runMissionScreen("cataclysm_delay_end_brief_1", null, null, "[thargoid]");
		if (missionVariables.cataclysm_engineer == "RESCUED") {
			mission.addMessageTextKey("cataclysm_delay_end_brief_2");
			missionVariables.cataclysm_engineer = "YES";
		}
		if (galaxyNumber == 4)
			missionVariables.cataclysm_aquxein_string = "Report immediately";
		else
			missionVariables.cataclysm_aquxein_string = "Proceed immediately to Galaxy 5 and report";
		if (galaxyNumber < 4) {
			missionVariables.cataclysm_galdrive_string = "5000 \U20a2 for your expenses have been deposited to your account. H";
			player.credits += 5000;
		}
		else if (galaxyNumber > 4) {
			missionVariables.cataclysm_galdrive_string = "Sorry for the inconvenience, but h";
			player.credits += 20000;
		}
		mission.addMessageTextKey("cataclysm_delay_end_brief_3");
		delete missionVariables.cataclysm_delay_counter;
		delete missionVariables.cataclysm_aquxein_string;
		delete missionVariables.cataclysm_galdrive_string;
		mission.setInstructionsKey("cataclysm_goto_Aquxein");
		missionVariables.cataclysm_hivemission = "WAITING";
		missionVariables.cataclysm = "STAGE8B";
	}
	else if (galaxyNumber == 4) {
		if (player.ship.dockedStation.isMainStation) {
			if ((missionVariables.cataclysm == "STAGE8A" || missionVariables.cataclysm == "STAGE8B") &&
				missionVariables.cataclysm_hivemission == "WAITING" && this.systemList["4"].indexOf(system.ID) >= 0 &&
				!missionVariables.offering) {
				missionVariables.cataclysm_species = expandDescription("[cataclysm_species]");
				this.runMissionScreen("cataclysm_hive_brief_1", "cataclysm_blurry_scan.png", "cataclysm_continue");
				this.$addPadCharacter("urquhart", expandDescription("%N") + " Urquhart", null, missionVariables.cataclysm_species);
				delete missionVariables.cataclysm_species;
				missionVariables.offering = "CATACLYSM";
				missionVariables.cataclysm_hivemission = "WAITING1";
			}
			else if (missionVariables.cataclysm_hivemission == "WAITING1" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_CONT") {
				this.runMissionScreen("cataclysm_hive_brief_2");
				mission.setInstructionsKey("cataclysm_scan_unknown_structure");
				mission.unmarkSystem({system:216, name:this.name});
				mission.markSystem({system:51, name:this.name}, {system:73, name:this.name});
				this.choice = null;
				delete missionVariables.offering;
				missionVariables.cataclysm_hivemission = "INVESTIGATE";
			}
			else if (missionVariables.cataclysm_hivemission == "SCANNED" && system.ID == 73 && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_hive_brief_3", null, null, "cataclysm_thargoid_hive_1");
				this.$addPadLogEntry("Scanned a massive Thargoid structure in interstellar space!");
				mission.setInstructionsKey("cataclysm_wait_a_minute");
				missionVariables.cataclysm_hivemission = "WAIT_A_MINUTE";
			}
			else if (missionVariables.cataclysm_hivemission == "WAIT_ENDED" && system.ID == 73 && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_hive_brief_4", null, "cataclysm_continue", "cataclysm_thargoid_hive_1");
				missionVariables.offering = "CATACLYSM";
				missionVariables.cataclysm_hivemission = "WAITING2";
			}
			else if (missionVariables.cataclysm_hivemission == "WAITING2" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_CONT") {
				this.runMissionScreen("cataclysm_hive_brief_5", null, null, "cataclysm_thargoid_hive_core");
				mission.setInstructionsKey("cataclysm_destroy_hive");
				this.choice = null;
				delete missionVariables.offering;
				missionVariables.cataclysm_hivemission = "DESTROY_HIVE";
			}
			else if (missionVariables.cataclysm_hivemission == "HIVE_DESTROYED" && (missionVariables.cataclysm == "STAGE8A" || missionVariables.cataclysm == "STAGE8B") && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_hive_debrief", null, null, "cataclysm_thargoid_hive_1");
				this.$addPadLogEntry("Destroyed a Thargoid Hive in interstellar space!");
				mission.setInstructionsKey("cataclysm_goto_Aquxein");
				mission.unmarkSystem({system:51, name:this.name}, {system:73, name:this.name});
				mission.markSystem({system:216, name:this.name});
				player.credits += 25000;
				missionVariables.cataclysm_hivemission = "COMPLETE";
			}
			else if (missionVariables.cataclysm == "STAGE8A" && missionVariables.cataclysm_hivemission == "COMPLETE" && system.ID == 216 && !missionVariables.offering) {
				this.runAltMissionScreen("cataclysm_aquxein_brief_A_1", { name: "cataclysm_chart6.png", height: 546 }, "cataclysm_continue", null, null, 5, 19);
				missionVariables.offering = "CATACLYSM";
				missionVariables.cataclysm = "STAGE8Aa";
			}
			else if (missionVariables.cataclysm == "STAGE8B" && missionVariables.cataclysm_hivemission == "COMPLETE" && system.ID == 216 && !missionVariables.offering) {
				this.runAltMissionScreen("cataclysm_aquxein_brief_B_1", { name: "cataclysm_chart6.png", height: 546 }, "cataclysm_continue", null, null, 5, 19);
				missionVariables.offering = "CATACLYSM";
				delete missionVariables.cataclysm_hivemission;
				missionVariables.cataclysm = "STAGE8Ba";
			}
			else if ((missionVariables.cataclysm == "STAGE8Aa" || missionVariables.cataclysm == "STAGE8Ba") && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_CONT") {
				this.runAltMissionScreen("cataclysm_aquxein_brief_2", { name: "cataclysm_chart5.png", height: 546 }, null, null, null, 5, 19);
				mission.setInstructionsKey("cataclysm_goto_Inbe");
				mission.unmarkSystem({system:216, name:this.name});
				mission.markSystem({system:129, name:this.name});
				this.choice = null;
				delete missionVariables.offering;
				if (missionVariables.cataclysm == "STAGE8Aa") missionVariables.cataclysm = "STAGE9A";
				else missionVariables.cataclysm = "STAGE9B";
			}
		}
	}
	else if (galaxyNumber == 5) {
		if (player.ship.dockedStation.isMainStation) {
			if (missionVariables.cataclysm == "STAGE9A" && system.ID == 55 && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_estebiin_brief_A", null, null, "cataclysm_disabled_warship_1");
				mission.setInstructionsKey("cataclysm_goto_Tetier");
				mission.markSystem({system:33, name:this.name});
				missionVariables.cataclysm = "STAGE9Aa";
			}
			else if (missionVariables.cataclysm == "STAGE9B" && system.ID == 55 && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_estebiin_brief_B", null, null, "cataclysm_disabled_warship_1");
				mission.setInstructionsKey("cataclysm_goto_Tetier");
				mission.markSystem({system:33, name:this.name});
				missionVariables.cataclysm = "STAGE9Ba";
			}
			else if (missionVariables.cataclysm == "STAGE11e" && system.ID == 55 && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_estebiin_brief_2");
				mission.unmarkSystem({system:55, name:this.name});
				mission.markSystem({system:33, name:this.name});
				player.ship.removeAllCargo();
				player.ship.useSpecialCargo("A load full of supplies for Tetier Military Station");
				missionVariables.cataclysm_replica = "AVAILABLE";
				missionVariables.cataclysm = "STAGE12";
			}
		}
		else if (player.ship.dockedStation.name == "Tetier Military Station") {
			if (missionVariables.cataclysm == "STAGE9Aa" && !missionVariables.offering) {
				missionVariables.cataclysm_species = expandDescription("[cataclysm_species]");
				this.runMissionScreen("cataclysm_tetier_brief_A_1", null, "cataclysm_continue");
				this.$addPadCharacter("arbuthnot", expandDescription("%N") + " Arbuthnot", null, missionVariables.cataclysm_species);
				delete missionVariables.cataclysm_species;
				missionVariables.offering = "CATACLYSM";
				missionVariables.cataclysm = "STAGE9Ab";
			}
			else if (missionVariables.cataclysm == "STAGE9Ab" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_CONT") {
				this.runMissionScreen("cataclysm_tetier_brief_A_2", null, "cataclysm_continue");
				this.choice = null;
				missionVariables.cataclysm = "STAGE9Ac";
			}
			else if (missionVariables.cataclysm == "STAGE9Ac" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_CONT") {
				missionVariables.cataclysm_species = expandDescription("[cataclysm_species]");
				this.runMissionScreen("cataclysm_tetier_brief_A_3", null, "cataclysm_continue");
				this.$addPadCharacter("cunynghame", expandDescription("%N") + " Cunynghame", null, missionVariables.cataclysm_species);
				delete missionVariables.cataclysm_species;
				this.choice = null;
				missionVariables.cataclysm = "STAGE9d";
			}
			else if (missionVariables.cataclysm == "STAGE9Ba" && !missionVariables.offering) {
				missionVariables.cataclysm_species = expandDescription("[cataclysm_species]");
				this.runMissionScreen("cataclysm_tetier_brief_B_1", null, "cataclysm_continue");
				this.$addPadCharacter("arbuthnot", expandDescription("%N") + " Arbuthnot", null, missionVariables.cataclysm_species);
				delete missionVariables.cataclysm_species;
				missionVariables.offering = "CATACLYSM";
				if (missionVariables.cataclysm_engineer == "YES") {
					mission.addMessageTextKey("cataclysm_tetier_brief_B_1a");
					delete missionVariables.cataclysm_engineer;
				}
				else {
					mission.addMessageTextKey("cataclysm_tetier_brief_B_1b");
				}
				this.$addPadCharacter("farquharson", expandDescription("%N") + " Farquharson", null, "Humanoid");
				missionVariables.cataclysm = "STAGE9Bb";
			}
			else if (missionVariables.cataclysm == "STAGE9Bb" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_CONT") {
				missionVariables.cataclysm_species = expandDescription("[cataclysm_species]");
				this.runMissionScreen("cataclysm_tetier_brief_B_2", null, "cataclysm_continue");
				this.$addPadCharacter("cunynghame", expandDescription("%N") + " Cunynghame", null, missionVariables.cataclysm_species);
				delete missionVariables.cataclysm_species;
				this.choice = null;
				missionVariables.cataclysm = "STAGE9d";
			}
			else if (missionVariables.cataclysm == "STAGE9d" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_CONT") {
				this.runMissionScreen("cataclysm_tetier_brief_4", null, "cataclysm_continue");
				this.choice = null;
				missionVariables.cataclysm = "STAGE9e";
			}
			else if (missionVariables.cataclysm == "STAGE9e" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_CONT") {
				this.runMissionScreen("cataclysm_tetier_brief_5", "cataclysm_warship_blueprint.png", "cataclysm_continue")
				this.choice = null;
				missionVariables.cataclysm = "STAGE9f";
			}
			else if (missionVariables.cataclysm == "STAGE9f" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_CONT") {
				this.runMissionScreen("cataclysm_tetier_brief_6");
				mission.setInstructionsKey("cataclysm_test_replica");
				mission.unmarkSystem({system:33, name:this.name});
				this.choice = null;
				delete missionVariables.offering;
				missionVariables.cataclysm = "STAGE10";
			}
			else if (missionVariables.cataclysm == "STAGE10m" && !missionVariables.offering) {
				// repair any damaged equipment for the player
				this.$repairPlayerEquipment();
				this.runMissionScreen("cataclysm_tetier_brief_7", null, "cataclysm_continue");
				this.$addPadLogEntry("Helped to successfully test the Warship Replica.");
				missionVariables.offering = "CATACLYSM";
				missionVariables.cataclysm = "STAGE11";
			}
			else if (missionVariables.cataclysm == "STAGE11" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_CONT") {
				this.runMissionScreen("cataclysm_tetier_brief_8", null, "cataclysm_launch", null, "siren.ogg");
				this.choice = null;
				mission.setInstructionsKey("cataclysm_defend_tetier_station");
				//system.legacy_addShipsWithinRadius("thargoid", 20, "abs", [-460295, 1925320, 350817], 25000);
				system.addShips("thargoid", 20, Vector3D(-460295, 1925320, 350817), 25000);
				this.currentSystem = "Tetier";
				this.startThargoidsRemainingTimer();
				missionVariables.cataclysm = "STAGE11a";
			}
			else if (missionVariables.cataclysm == "STAGE11a" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_LAUNCH") {
				this.choice = null;
				player.ship.launch();
				delete missionVariables.offering;
				missionVariables.cataclysm = "STAGE11b";
				system.shipsWithPrimaryRole("cataclysm_tetier_station")[0].reactToAIMessage("LAUNCH_WARSHIP_REPLICA_2");
			}
			else if (missionVariables.cataclysm == "STAGE11c" && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_tetier_debrief_1", {name:"cataclysm_tetier_station_view.png", height:546}, "cataclysm_continue");
				this.$addPadLogEntry("Successfully defended the Tetier Military station from a massive Thargoid attack!");
				missionVariables.offering = "CATACLYSM";
				missionVariables.cataclysm = "STAGE11d";
			}
			else if (missionVariables.cataclysm == "STAGE11d" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_CONT") {
				this.runMissionScreen("cataclysm_tetier_debrief_2");
				mission.setInstructionsKey("cataclysm_goto_Estebiin_2");
				mission.markSystem({system:55, name:this.name});
				this.choice = null;
				delete missionVariables.offering;
				missionVariables.cataclysm = "STAGE11e";
			}
			else if (missionVariables.cataclysm == "STAGE12" && !missionVariables.offering) {
				this.runMissionScreen("cataclysm_reward_brief_1", "cataclysm_navy_star.png", "cataclysm_continue");
				this.$addPadLogEntry("Received a huge reward for helping the Navy!");
				missionVariables.offering = "CATACLYSM";
				player.ship.removeAllCargo();
				mission.setInstructionsKey(null);
				mission.unmarkSystem({system:33, name:this.name});
				player.credits += 100000;
				missionVariables.cataclysm = "STAGE12a";
			}
			else if (missionVariables.cataclysm == "STAGE12a" && missionVariables.offering == "CATACLYSM" && this.choice == "cataclysm_CONT") {
				this.runMissionScreen("cataclysm_reward_brief_2", null, null, "cataclysm_warship_replica_1");
				this.choice = null;
				delete missionVariables.offering;
				missionVariables.cataclysm = "MISSION_COMPLETE";
			}
		}
	}
	else if (missionVariables.cataclysm == "MISSION_COMPLETE" && missionVariables.cataclysm_hivemission == "COMPLETE" && player.bounty == 0 && !missionVariables.offering) {
		var getHiveMission = Math.random();
		if (getHiveMission <= 0.532 || getHiveMission > 0.555) return;
		if (galaxyNumber == 2 && (system.ID == 133 || system.ID == 206)) return;
		if (galaxyNumber == 5 && this.systemList["5"].indexOf(system.ID)) return;
		if (galaxyNumber == 7 && system.ID == 162) return;
		this.hiveLocation = Math.floor(Math.random() * 6);
		if (galaxyNumber == 6 && this.systemList["6".indexOf(system.ID) >= 0]) this.hiveLocation = 6;
		missionVariables.cataclysm_hive_location = this.hiveLocation;
		missionVariables.cataclysm_hive_location_1 = system.systemNameForID(this.hiveLocations[galaxyNumber][this.hiveLocation * 2]);
		missionVariables.cataclysm_hive_location_2 = system.systemNameForID(this.hiveLocations[galaxyNumber][this.hiveLocation * 2 + 1]);
		this.runMissionScreen("cataclysm_another_hive_brief", null, null, "cataclysm_thargoid_hive_1");
		mission.setInstructionsKey("cataclysm_destroy_another_hive");
		mission.markSystem({system:this.hiveLocations[galaxyNumber][this.hiveLocation * 2], name:this.name}, {system:this.hiveLocations[galaxyNumber][this.hiveLocation * 2 + 1], name:this.name});
		missionVariables.cataclysm_hivemission = "DESTROY_HIVE";
	}
	else if (missionVariables.cataclysm == "MISSION_COMPLETE" && missionVariables.cataclysm_hivemission == "HIVE_DESTROYED" && !missionVariables.offering) {
		this.runMissionScreen("cataclysm_another_hive_debrief", "cataclysm_navy_star.png");
		this.$addPadLogEntry("Destroyed another Thargoid Hive in interstellar space!");
		mission.setInstructionsKey(null);
		mission.unmarkSystem({system:this.hiveLocations[galaxyNumber][missionVariables.cataclysm_hive_location * 2], name:this.name}, {system:this.hiveLocations[galaxyNumber][missionVariables.cataclysm_hive_location * 2 + 1], name:this.name});
		player.credits += 5000;
		delete missionVariables.cataclysm_hive_location;
		delete missionVariables.cataclysm_hive_location_1;
		delete missionVariables.cataclysm_hive_location_2;
		missionVariables.cataclysm_hivemission = "COMPLETE";
	}
}

//-------------------------------------------------------------------------------------------------------------
this.thargoidsKillThePlayer = function () {
	player.ship.fuelLeakRate = 10;
	system.shipsWithPrimaryRole("cataclysm_defector")[0].remove();
	//system.legacy_addShipsWithinRadius("cataclysm_defector_thargoid", 1, "abs", player.ship.position, 15000);
	system.addShips("cataclysm_defector_thargoid", 1, player.ship.position, 15000);
	//system.legacy_addShipsWithinRadius("thargoid", 15, "abs", player.ship.position, 10000);
	system.addShips("thargoid", 15, player.ship.position, 10000);
	system.shipsWithPrimaryRole("thargoid", player.ship, 15000).forEach(
		function (ship) {
			ship.target = player.ship;
			ship.reactToAIMessage("ATTACKED");
		}
	)
}

/* event handlers */

//-------------------------------------------------------------------------------------------------------------
this.startUp = function () {
	this.illicitEquipment = 0;
	this.blockSystemRedux();

	// check for hathor - it can spawn in the same place as the ribilebi research station
	if (worldScripts["Hathor-Nephthys-populator.js"]) {
		var hth = worldScripts["Hathor-Nephthys-populator.js"];
		hth.$hold_systemWillPopulate = hth.systemWillPopulate;
		delete hth.systemWillPopulate;
	}
}

//-------------------------------------------------------------------------------------------------------------
this.startUpComplete = function () {
	var vx = worldScripts.VimanaX_HUD;
	if (vx) {
		// update vimana to use a different model to the original
		vx._gameShips["Enrece Research Station"] = "coriolis_wreck";
		vx._gameShips["Recovered Thargoid Warship"] = "thargoid";
		vx._gameShips["Warship Replica"] = "thargoid";
		vx._gameShips["Navy Station Buoy"] = "buoy";
		vx._gameShips["Navy Viper Interceptor"] = "interceptor";
	}
	// add new penalty type to the bounty system
	if (worldScripts.BountySystem_Core) {
		var b = worldScripts.BountySystem_Core;
		b._offenceTypes["war crimes"] = "An act carried out during the conduct of a war that violates accepted galactic rules of war.";
	}
	// tell ShipConfig not to apply rules to the replica ships
	if (worldScripts.ShipConfiguration_NPCShips) {
		var npc = worldScripts.ShipConfiguration_NPCShips;
		npc._excludeRoles.push("cataclysm_warship_replica_1");
		npc._excludeRoles.push("cataclysm_warship_replica_2");
	}
	this.dealWithIllicitEquipment2();
}

//-------------------------------------------------------------------------------------------------------------
this.systemWillPopulate = function () {
	this.dealWithIllicitEquipment1();
	var popRef = 0;

	if (worldScripts["Hathor-Nephthys-populator.js"]) {
		if ((galaxyNumber == 0 && system.ID == 164) || (galaxyNumber == 2 && system.ID == 86) || (galaxyNumber == 5 && system.ID == 33)) {
			// skip the hathor populator, so do nothing
			// logic is easier to understand this way
		} else {
			// if we disabled it, run the hathor populator now, but only if we're not in one of the above systems
			worldScripts["Hathor-Nephthys-populator.js"].$hold_systemWillPopulate();
		}
	}

	if (galaxyNumber == 0) {
		if (system.ID == 164) {
			popRef++;
			var stnPos = Vector3D(-93000, 53000, -79000).fromCoordinateSystem("pwm");
			system.setPopulator("cataclysm_" + popRef.toString(), {
				callback: function (pos) {

					//system.legacy_addShipsAtPrecisely("cataclysm_ribilebi_station", 1, "pwm", [-93000, 53000, -79000]);
					var station = system.addShips("cataclysm_ribilebi_station", 1, pos, 0)[0];
					//var station = system.shipsWithPrimaryRole("cataclysm_ribilebi_station")[0];
					worldScripts.Cataclysm.turnStationToPlanet(station);
					var hideBeaconStages = ["STAGE3c", "STAGE3b", "STAGE3a", "STAGE3", "STAGE2", "STAGE2a", "STAGE1a", "STAGE1b", "STAGE1c", "STAGE1d"];
					if (hideBeaconStages.indexOf(missionVariables.cataclysm) >= 0) {
						station.beaconCode = null;
						station.beaconLabel = null;
					}
				},
				location: "COORDINATES",
				coordinates: stnPos,
				deterministic: true
			});
		} else {
			if (missionVariables.cataclysm == "STAGE3") {
				popRef++;
				system.setPopulator("cataclysm_" + popRef.toString(), {
					callback: function (pos) {
						if (Math.random() < 0.5) {
							//system.legacy_addShips("thargoid", 2);
							system.addShips("thargoid", 2);
							if (Math.random() < 0.6) {
								//system.legacy_addShips("thargoid", 1);
								system.addShips("thargoid", 1);
								if (Math.random() < 0.75) {
									//system.legacy_addShips("thargoid", 1);
									system.addShips("thargoid", 1);
								}
							}
						}
						if (Math.random() < 0.4) {
							//system.legacy_addSystemShips("thargoid", 2, 0.3);
							system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.3));
						}
						if (Math.random() < 0.3) {
							//system.legacy_addSystemShips("thargoid", 2, 0.7);
							system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.7));
						}
					},
					location: "WITCHPOINT",
				});
			}
		}
	} else if (missionVariables.cataclysm == "STAGE5") {
		popRef++;
		system.setPopulator("cataclysm_" + popRef.toString(), {
			callback: function (pos) {
				if (Math.random() < 0.4) {
					//system.legacy_addShips("thargoid", 2);
					system.addShips("thargoid", 2);
					if (Math.random() < 0.5) {
						//system.legacy_addShips("thargoid", 1);
						system.addShips("thargoid", 1);
						if (Math.random() < 0.6) {
							//system.legacy_addShips("thargoid", 1);
							system.addShips("thargoid", 1);
						}
					}
				}
				if (Math.random() < 0.4) {
					//system.legacy_addSystemShips("thargoid", 2, 0.3);
					system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.3));
				}
				if (Math.random() < 0.3) {
					//system.legacy_addSystemShips("thargoid", 2, 0.7);
					system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.7));
				}
			},
			location: "WITCHPOINT",
		});

	} else if (galaxyNumber == 2) {
		// create the station regardless of the missionVariables
		if (system.ID == 86) {
			system.addMoon("cataclysm_enrece_moon");
			var stnPos = Vector3D(-99221.3, -20562.3, 468026);

			popRef++;
			system.setPopulator("cataclysm_" + popRef.toString(), {
				callback: function (pos) {
					if (system.countShipsWithPrimaryRole("cataclysm_enrece_station") == 0) {
						//system.legacy_addShipsAtPrecisely("cataclysm_enrece_station", 1, "abs", [-99221.3, -20562.3, 453026]);
						var station = system.addShips("cataclysm_enrece_station", 1, pos, 0)[0];
						//var station = system.shipsWithPrimaryRole("cataclysm_enrece_station")[0];
						worldScripts.Cataclysm.turnStationToPlanet(station);
						//system.legacy_addShipsWithinRadius("cataclysm_wreckage", 30, "abs", station.position, 12000);
						system.addShips("cataclysm_wreckage", 30, pos, 12000);
						//system.legacy_addShipsWithinRadius("cataclysm_viper_wreck", 4, "abs", station.position, 5000);
						var wrecks = system.addShips("cataclysm_viper_wreck", 4, pos, 5000);
						for (var i = 0; i < wrecks.length; i++) {
							worldScripts.Cataclysm.$makeShipDerelict(wrecks[i]);
							wrecks.orientation = Vector3D.random();
						}
					}
				},
				location: "COORDINATES",
				coordinates: stnPos,
				deterministic: true
			});
		}
		if (missionVariables.cataclysm == "STAGE6") {
			missionVariables.cataclysm_trigger = Math.floor(Math.random() * 100);
			if (missionVariables.cataclysm_missions == "DONE")
				delete missionVariables.cataclysm_missions;

			popRef++;
			system.setPopulator("cataclysm_" + popRef.toString(), {
				callback: function (pos) {

					if (missionVariables.cataclysm_missions == "EVACUATION") {
						//system.legacy_addSystemShips("thargoid", 2, 0);
						system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0));
						//system.legacy_addSystemShips("thargoid", 2, 0.5);
						system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.5));
					}
					if (Math.random() < 0.4) {
						//system.legacy_addShips("thargoid", 2);
						system.addShips("thargoid", 2);
						if (Math.random() < 0.5) {
							//system.legacy_addShips("thargoid", 1);
							system.addShips("thargoid", 1);
						}
					}
					if (Math.random() < 0.35) {
						//system.legacy_addSystemShips("thargoid", 2, 0.3);
						system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.3));
					}
					if (Math.random() < 0.25) {
						//system.legacy_addSystemShips("thargoid", 2, 0.7);
						system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.7));
					}
				},
				location: "WITCHPOINT",
			});

			//} else if (missionVariables.cataclysm == "STAGE6a") {

		} else if (missionVariables.cataclysm == "STAGE7" && system.countShipsWithPrimaryRole("cataclysm_disabled_warship_2") == 0) {
			popRef++;
			system.setPopulator("cataclysm_" + popRef.toString(), {
				callback: function (pos) {

					if (Math.random() < 0.8) {
						//system.legacy_addShips("thargoid", 2);
						system.addShips("thargoid", 2);
						if (Math.random() < 0.6) {
							//system.legacy_addShips("thargoid", 1);
							system.addShips("thargoid", 1);
							if (Math.random() < 0.4) {
								//system.legacy_addShips("thargoid", 1);
								system.addShips("thargoid", 1);
							}
						}
					}
					if (Math.random() < 0.75) {
						//system.legacy_addSystemShips("thargoid", 2, 0.3);
						system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.3));
					}
					if (Math.random() < 0.5) {
						//system.legacy_addSystemShips("thargoid", 2, 0.7);
						system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.7));
					}
				},
				location: "WITCHPOINT",
			});
		}

	} else if (missionVariables.cataclysm == "STAGE8A" || missionVariables.cataclysm == "STAGE8B") {
		popRef++;
		system.setPopulator("cataclysm_" + popRef.toString(), {
			callback: function (pos) {
				if (Math.random() < 0.4) {
					//system.legacy_addShips("thargoid", 2);
					system.addShips("thargoid", 2);
					if (Math.random() < 0.5) {
						//system.legacy_addShips("thargoid", 1);
						system.addShips("thargoid", 1);
						if (Math.random() < 0.6) {
							//system.legacy_addShips("thargoid", 1);
							system.addShips("thargoid", 1);
						}
					}
				}
				if (Math.random() < 0.3) {
					//system.legacy_addSystemShips("thargoid", 2, 0.3);
					system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.3));
				}
				if (Math.random() < 0.25) {
					//system.legacy_addSystemShips("thargoid", 2, 0.7);
					system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.7));
				}
			},
			location: "WITCHPOINT",
		});

	} else if (galaxyNumber == 5) {
		if (system.ID == 33) {
			system.addMoon("cataclysm_tetier_moon");
			var stnPos = Vector3D(-460295, 1925320, 350817);
			popRef++;
			system.setPopulator("cataclysm_" + popRef.toString(), {
				callback: function (pos) {

					//system.legacy_addShipsAtPrecisely("cataclysm_tetier_station", 1, "abs", [-460295, 1925320, 350817]);
					var station = system.addShips("cataclysm_tetier_station", 1, pos, 0)[0];
					//var station = system.shipsWithPrimaryRole("cataclysm_tetier_station")[0];
					worldScripts.Cataclysm.turnStationToPlanet(station);

					//system.legacy_addShipsWithinRadius("asteroid", 12, "abs", [-464763, 1919432, 350817], 10000);
					system.addShips("asteroid", 12, Vector3D(-464763, 1919432, 350817), 10000);
					//system.legacy_addShipsWithinRadius("asteroid", 12, "abs", [-461784, 1923357, 341125], 10000);
					system.addShips("asteroid", 12, Vector3D(-461784, 1923357, 341125), 10000);
					//system.legacy_addShipsWithinRadius("asteroid", 12, "abs", [-458806, 1927283, 360509], 10000);
					system.addShips("asteroid", 12, Vector3D(-458806, 1927283, 360509), 10000);
					//system.legacy_addShipsWithinRadius("asteroid", 12, "abs", [-455827, 1931208, 379892], 10000);
					system.addShips("asteroid", 12, Vector3D(-455827, 1931208, 379892), 10000);
					//system.legacy_addShipsAtPrecisely("asteroid", 1, "abs", [-463561, 1917933, 342665]);
					system.addShips("asteroid", 1, Vector3D(-463561, 1917933, 342665));
					//system.legacy_addShipsAtPrecisely("asteroid", 1, "abs", [-461556, 1933831, 358793]);
					system.addShips("asteroid", 1, Vector3D(-461556, 1933831, 358793));
				},
				location: "COORDINATES",
				coordinates: stnPos,
				deterministic: true
			});
		}
		if ((missionVariables.cataclysm == "STAGE9A" || missionVariables.cataclysm == "STAGE9B") && system.ID == 55) {
			mission.setInstructionsKey("cataclysm_goto_Estebiin");

			popRef++;
			system.setPopulator("cataclysm_" + popRef.toString(), {
				callback: function (pos) {
					//system.legacy_addSystemShips("thargoid", 2, 0);
					system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.0));
					//system.legacy_addSystemShips("thargoid", 1, 0.65);
					system.addShips("thargoid", 1, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.65));
				},
				location: "WITCHPOINT",
			});

		} else if (missionVariables.cataclysm == "STAGE9Ba" || missionVariables.cataclysm_replica || missionVariables.cataclysm == "STAGE9Aa") {
			popRef++;
			system.setPopulator("cataclysm_" + popRef.toString(), {
				callback: function (pos) {
					if (missionVariables.cataclysm == "STAGE9Aa") {
						//system.legacy_addShipsAtPrecisely("cataclysm_disabled_warship_3", 1, "abs", [-459741, 1923775, 351249]);
						system.addShips("cataclysm_disabled_warship_3", 1, Vector3D(-459741, 1923775, 351249));
					}
					//system.legacy_addShipsWithinRadius("cataclysm_military", 8, "abs", [-460295, 1925320, 350817], 30000);
					system.addShips("cataclysm_military", 8, Vector3D(-460295, 1925320, 350817), 30000);
				},
				location: "COORDINATES",
				coordinates: stnPos,
			});
		}
	}
	if (missionVariables.cataclysm == "DELAY") {
		missionVariables.cataclysm_delay_counter++;
		popRef++;
		system.setPopulator("cataclysm_" + popRef.toString(), {
			callback: function (pos) {
				if (Math.random() >= 0.75) {
					//system.legacy_addShips("thargoid", 1);
					system.addShips("thargoid", 1);
					//system.legacy_addSystemShips("thargoid", 1, 0.65);
					system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.65));
				}
				if (Math.random() < 0.25) {
					//system.legacy_addShips("thargoid", 1);
					system.addShips("thargoid", 1);
					//system.legacy_addSystemShips("thargoid", 1, 0.35);
					system.addShips("thargoid", 2, Vector3D.interpolate(Vector3D(0, 0, 0), system.mainStation.position, 0.35));
				}
			},
			location: "WITCHPOINT",
		});
	}
}

//-------------------------------------------------------------------------------------------------------------
this.shipDockedWithStation = function () {
	this.dealWithIllicitEquipment2();
}

//-------------------------------------------------------------------------------------------------------------
this.missionScreenEnded = function () {
	if (!player.ship.docked) return;
	if (missionVariables.cataclysm_hivemission == "WAIT_A_MINUTE" && (!this.waitTimer || !this.waitTimer.isRunning))
		this.waitTimer = new Timer(this, this.stopWaiting, 45);
}

//-------------------------------------------------------------------------------------------------------------
this.missionScreenOpportunity = function () {
	if (missionVariables.cataclysm_hivemission != "WAIT_A_MINUTE") {
		this.missionScreens();
	}
}

//-------------------------------------------------------------------------------------------------------------
this.guiScreenChanged = function (to, from) {
	if (!player.ship.docked) return;
	if (player.ship.hasEquipmentProviding("EQ_CATACLYSM_ALL_INCLUSIVE"))
		player.ship.removeEquipment("EQ_CATACLYSM_ALL_INCLUSIVE");
}

//-------------------------------------------------------------------------------------------------------------
this.shipLaunchedFromStation = function () {
	this.dealWithIllicitEquipment1();
	if (missionVariables.cataclysm == "STAGE10") {
		var p = player.ship;
		if (p.script.shipEnergyIsLow) p.script.$hold_sshipTakingDamage = p.script.shipTakingDamage;
		player.ship.script.shipTakingDamage = this.$player_shipTakingDamage;
		system.shipsWithPrimaryRole("cataclysm_tetier_station")[0].reactToAIMessage("LAUNCH_WARSHIP_REPLICA_1");
		missionVariables.cataclysm == "STAGE10a";
		//system.legacy_addShipsAtPrecisely("cataclysm_target_asteroid_1", 1, "abs", [-467902, 1998274, 365325]);
		system.addShips("cataclysm_target_asteroid_1", 1, Vector3D(-467902, 1998274, 365325), 0);
		//system.legacy_addShipsAtPrecisely("cataclysm_target_asteroid_2", 1, "abs", [-476866, 1995981, 365150]);
		system.addShips("cataclysm_target_asteroid_2", 1, Vector3D(-476866, 1995981, 365150), 0);
		//system.legacy_addShipsAtPrecisely("cataclysm_target_asteroid_3", 1, "abs", [-477147, 1996492, 359577]);
		system.addShips("cataclysm_target_asteroid_3", 1, Vector3D(-477147, 1996492, 359577), 0);
		//system.legacy_addShipsAtPrecisely("cataclysm_target_asteroid_4", 1, "abs", [-472985, 2000370, 358859]);
		system.addShips("cataclysm_target_asteroid_4", 1, Vector3D(-472985, 2000370, 358859), 0);

		// we need to turn off ShipRepurchase, because if the replica kills the player in the combat test, we want it to reload the game
		// not send the player to the main station for a repurchase
		if (worldScripts.ShipRepurchase) {
			var sr = worldScripts.ShipRepurchase;
			sr.$hide_shipTakingDamage = sr.shipTakingDamage;
			delete sr.shipTakingDamage;
		}
	}
}

//-------------------------------------------------------------------------------------------------------------
this.shipWillEnterWitchspace = function (cause) {
	if (cause == "galactic jump") {
		this.checkForGalDriveMod();
	}
	if (cause == "wormhole" && missionVariables.cataclysm_missions == "DEFECTOR_ESCAPED") {
		this.followingDefector = true;
	}
	if (missionVariables.cataclysm == "MISSION_COMPLETE" && missionVariables.cataclysm_replica) {
		delete missionVariables.cataclysm_replica;
	}
}

//-------------------------------------------------------------------------------------------------------------
this.shipWillExitWitchspace = function () {
	if (this.followingDefector) this.thargoidsKillThePlayer();
	if (system.isInterstellarSpace) return;
	this.advanceJumpCounters();
}

//-------------------------------------------------------------------------------------------------------------
this.shipExitedWitchspace = function () {
	if (system.isInterstellarSpace && missionVariables.cataclysm_hivemission == "DESTROY_HIVE")
		this.switchMilitaryAI();
}

//-------------------------------------------------------------------------------------------------------------
this.playerEnteredNewGalaxy = function (galaxyNumber) {
	this.resetGalHyperspaceBehaviour();
	if (galaxyNumber == 4 && missionVariables.cataclysm_hivemission == "WAITING")
		mission.markSystem({system:216, name:this.name});
}

//-------------------------------------------------------------------------------------------------------------
this.$player_shipTakingDamage = function (amount, whom, type) {
	if (this.ship.script.$hold_shipTakingDamage) this.ship.script.$hold_shipTakingDamage();
	if (missionVariables.cataclysm == "STAGE10k") {
		// if we get the player down to 40% energy - call it over
		if (this.ship.energy / this.ship.maxEnergy < 0.4) {
			var s = system.shipsWithRole("cataclysm_warship_replica_1");
			var w = null;
			if (s && s.length > 0) w = s[0];
			if (w) {
				w.script.stopCombat();
				delete this.ship.script.shipTakingDamage;
				if (this.ship.script.$hold_shipTakingDamage) {
					this.ship.script.shipTakingDamage = this.ship.script.$hold_shipTakingDamage;
					delete this.ship.script.$hold_shipTakingDamage;
				}
			}
		}
	}
}

//-------------------------------------------------------------------------------------------------------------
this.runMissionScreen = function (textKey, background, choicesKey, modelKey, musicFile) {
	var opts = {};
	opts.messageKey = textKey;
	opts.screenID = "cataclysm_mission";
	if (background) opts.overlay = background;
	if (choicesKey) opts.choicesKey = choicesKey;
	if (modelKey) opts.model = modelKey;
	if (musicFile) opts.music = musicFile;

	mission.runScreen(opts, function (choice) { this.choice = choice; });
}

//-------------------------------------------------------------------------------------------------------------
this.runAltMissionScreen = function (textKey, background, choicesKey, modelKey, musicFile, toplines, width) {
	var opts = {};

	opts.message = this.$reformatText(textKey, toplines, width);
	opts.screenID = "cataclysm_mission";
	if (background) opts.overlay = background;
	if (choicesKey) opts.choicesKey = choicesKey;
	if (modelKey) opts.model = modelKey;
	if (musicFile) opts.music = musicFile;

	mission.runScreen(opts, function (choice) { this.choice = choice; });
}

//-------------------------------------------------------------------------------------------------------------
this.$bigSpacer = function (width) {
	var hairSpace = String.fromCharCode(31);
	var hairSpaceLength = defaultFont.measureString(hairSpace);
	var output = "";
	var counter = 0;
	do {
		output += hairSpace;
		counter += 1;
	} while (counter * hairSpaceLength < width);
	return output;
}

//-------------------------------------------------------------------------------------------------------------
this.$reformatText = function (textkey, toplines, bigspacewidth) {
	var output = [];
	var text = expandMissionText(textkey);
	var words = text.split(' ');
	var bigspace = this.$bigSpacer(bigspacewidth);
	var word = 0;
	do {
		var line = "";
		if (output.length >= toplines) line = bigspace;
		do {
			if (defaultFont.measureString(line + words[word]) > 31.9) break;
			if (words[word].search(/\n/) >= 0) {
				word += 1;
				break;
			}
			line += words[word] + " ";
			word += 1;
		} while (word <= words.length - 1);
		output.push(line.trimRight());
	} while (word <= words.length - 1);
	var final = "";
	for (var i = 0; i < output.length; i++) {
		final += (final == "" ? "" : "\n") + output[i];
	}
	return final;
}

//-------------------------------------------------------------------------------------------------------------
this.$repairPlayerEquipment = function() {
	var p = player.ship;
	var eq = p.equipment;
	var eqLen = eq.length;
	while (eqLen--) {
		var item = eq[eqLen].equipmentKey;
		if (p.equipmentStatus(item) == "EQUIPMENT_DAMAGED") p.setEquipmentStatus(eq[eqLen].equipmentKey, "EQUIPMENT_OK");
	}
	if (worldScripts["Battle Damage"] && missionVariables.BattleDamage_status != "OK") {
		missionVariables.BattleDamage_status = "OK";
		p.awardEquipment("EQ_HULL_REPAIR");
	}
}

//-------------------------------------------------------------------------------------------------------------
this.$makeShipDerelict = function (shp) {
    shp.bounty = 0;
    // set script to default, to avoid a special script for the trader doing stuff. (like setting a new AI)
    shp.setScript("oolite-default-ship-script.js");
    shp.switchAI("oolite-nullAI.js");

    // remove any escorts that came with the ship
    if (shp.escorts) {
        for (var k = shp.escorts.length - 1; k >= 0; k--) shp.escorts[k].remove(true);
    }

    shp.script.shipLaunchedEscapePod = this.$cataclysm_derelict_shipLaunchedEscapePod; // function to remove the escapepod after launch.
    if (shp.equipmentStatus("EQ_ESCAPE_POD") === "EQUIPMENT_UNAVAILABLE") shp.awardEquipment("EQ_ESCAPE_POD");
    shp.abandonShip(); // make sure no pilot is left behind and this command turns the ship into cargo.
    shp.primaryRole = "cataclysm_derelict"; // to avoid pirate attacks
    shp.displayName = shp.displayName + " (derelict)";
    shp.lightsActive = false;
}

//-------------------------------------------------------------------------------------------------------------
this.$cataclysm_derelict_shipLaunchedEscapePod = function $himsn_derelict_shipLaunchedEscapePod(pod, passengers) {
    pod.remove(true); // we don't want floating escapepods around but need them initially to create the derelict.
}

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

//-------------------------------------------------------------------------------------------------------------
this.$updateCurruthers = function() {
	var pad = worldScripts.Lib_PAD;
	if (!pad) return;
	if (pad.$data.PERSONS["CAPTAIN CURRUTHERS"]) {
		delete pad.$data.PERSONS["CAPTAIN CURRUTHERS"];
		this.$addPadCharacter("curruthers");
	}
}

//-------------------------------------------------------------------------------------------------------------
this.$addPadCharacter = function(person, name, origin, species, info) {
    var pad = worldScripts.Lib_PAD;
	if (!pad) return;
	var dta = {};
	var cat = [];

	switch (person) {
		case "curruthers":
			dta.name = "James Curruthers";
			dta.origin = "Restricted data";
			dta.species = "Human colonial";
			dta.gender = "Male";
			dta.age = 45;
			dta.ship = "Viper";
			dta.rank = "Rear Admiral";
			dta.t0 = 21;
			dta.t1 = "lib_ovc_curruthers.png";
			dta.t2 = 11;
			cat.push("GALCOP.NAVY");
			break;
		case "ambassador":
			dta.name = name;
			dta.origin = (origin ? origin : system.name);
			dta.species = (species ? species : system.info.inhabitant);
			dta.gender = "Male";
			dta.age = Math.floor(Math.random() * 30) + 40;
			dta.ship = "Boa Class Cruiser";
			dta.rank = "Ambassador";
			dta.t0 = Math.floor(Math.random() * 4) + 28;
			dta.t1 = null;
			dta.t2 = 0;
			dta.info = [];
			if (info) dta.info.push(info);
			cat.push("GALCOP.GENERIC");
			break;
		case "urquhart":
			dta.name = name;
			dta.origin = "Restricted data";
			dta.species = "Restricted data";
			dta.gender = "Female";
			dta.age = Math.floor(Math.random() * 30) + 40;
			dta.ship = "Restricted data";
			dta.rank = "Commodore";
			dta.t0 = 21;
			dta.t1 = null;
			dta.t2 = 10;
			dta.info = [];
			if (info) dta.info.push(info);
			cat.push("GALCOP.NAVY");
			break;
		case "arbuthnot":
			dta.name = name;
			dta.origin = "Restricted data";
			dta.species = (species ? species : system.info.inhabitant);
			dta.gender = "Male";
			dta.age = Math.floor(Math.random() * 30) + 40;
			dta.ship = "Restricted data";
			dta.rank = "Admiral";
			dta.t0 = 21;
			dta.t1 = null;
			dta.t2 = 12;
			dta.info = [];
			if (info) dta.info.push(info);
			cat.push("GALCOP.NAVY");
			break;
		case "cunynghame":
			dta.name = name;
			dta.origin = "Restricted data";
			dta.species = (species ? species : system.info.inhabitant);
			dta.gender = "Male";
			dta.age = Math.floor(Math.random() * 30) + 40;
			dta.ship = "Restricted data";
			dta.rank = "Lieutenant Commander";
			dta.t0 = 21;
			dta.t1 = null;
			dta.t2 = 7;
			dta.info = [];
			if (info) dta.info.push(info);
			cat.push("GALCOP.NAVY");
			break;
		case "farquharson":
			dta.name = name;
			dta.origin = "Restricted data";
			dta.species = (species ? species : system.info.inhabitant);
			dta.gender = "Male";
			dta.age = Math.floor(Math.random() * 30) + 40;
			dta.ship = "Restricted data";
			dta.rank = "Doctor";
			dta.t0 = 21;
			dta.t1 = null;
			dta.t2 = null;
			dta.info = [];
			if (info) dta.info.push(info);
			cat.push("GALCOP.NAVY");
			break;
	}
	var id = "PERSONS." + dta.rank.toUpperCase() + " " + dta.name.split(" ")[1].toUpperCase();
	pad._addPageInCategory(id, dta, cat, false);
}