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

Expansion Illegal Goods Tweak

Content

Warnings

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

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description Introduces interaction with Galcop customs when docking at a main station with contraband in the hold. Introduces interaction with Galcop customs when docking at a main station with contraband in the hold.
Identifier oolite.oxp.capt_murphy.Illegal_Goods_Tweak oolite.oxp.capt_murphy.Illegal_Goods_Tweak
Title Illegal Goods Tweak Illegal Goods Tweak
Category Mechanics Mechanics
Author Capt Murphy Capt Murphy
Version 2.2.6 2.2.6
Tags Mechanics Mechanics
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL n/a
Download URL https://wiki.alioth.net/img_auth.php/8/82/Illegal_Goods_Tweak.oxz n/a
License CC-BY-NC-SA 3.0 CC-BY-NC-SA 3.0
File Size n/a
Upload date 1610873350

Documentation

Also read http://wiki.alioth.net/index.php/Illegal%20Goods%20Tweak

readme.txt

Illegal Goods Tweak version 2.2.4 (22/02/2018)
By Capt Murphy 2012
Licence: CC BY-NC-SA 3.0
Requires Oolite version 1.80

Description
===========

This OXP introduces interaction with Galcop customs for players who dock at main stations (and some OXP stations if New Cargoes OXP is installed) with Narcotics, Firearms or Slaves in the hold. Players can ignore warnings, in which case a legal penalty is applied, but they can go on to sell the contraband on the open market. Alternatively they can voluntarily hand over contraband in which case a nominal reward is given; or attempt to bribe the customs officer to turn a blind eye (this could be risky - attempted bribery of a Galcop official can bring it's own legal penalties).

Slaves that are handed over to Galcop customs are rehabilitated by Amnesty Intergalactic before being released. There is a small chance that after handing over slaves the player may be contacted by an ex-slave who may offer an additional reward for their rescue. This will generally involve a trip to the ex-slave's home system to receive a financial reward, although there are a few surprises in the code. If you don't like surprises or are simply curious please see spoilers.txt included in this download for more info.

This OXP does not interfere with the treatment of scooped escape pods, although they do appear in the manifest as slaves. Oolite automatically removes slaves from scooped escape pods from the manifest, and pays appropriate bounty/insurance payments before this OXP runs. 

Compatibility Information
=========================

This release introduces compatibility with New Cargoes OXP (1.1.0 or above) and it's permit system. Contraband which is a New Cargoes Special Cargo is ignored by Illegal Goods Tweak if a valid New Cargoes permit is held. Otherwise it is treated in the same way as standard contraband. Also Illegal Goods Tweak will run on docking at certain OXP stations defined by New Cargoes OXP if installed (this option can be turned off).

Compatibility with HyperCargo OXP (1.07 or above) and Vortex OXP (1.23 or above) has also been updated to take into account New Cargoes and it's permit system. 

This release introduces optional OXPconfig compatibility(version 2.0.9 or above) as a method to set some options.

Options that can be set via OXPConfig are (line numbers given for those who just wish to edit the script "illegal_goods_tweak.js"):

alwaysDetect (default true) (line 9); If set to false a variable contraband detection rate is used, dependent on tech level and government type of the system. Low Tech Anarchies will have the lowest detection rate, High Tech Corporate States the highest. High Tech Anarchies and Low Tech Corporate States will fall somewhere in between. If not detected players carrying contraband still have an opportunity to voluntarily handover contraband for a small reward.

loggingEnabled (default false) (line 10) : if set to true enables some debug log messages.

ncOXPStations (default true) (line 11) : ignored unless New Cargoes OXP installed. If true customs are also active at certain OXP stations (defined via New Cargoes).

Why
===

Vanilla Oolite follows Elite in that by default penalties are only applied when launching from a main station with contraband in the hold. There is no penalty for docking with a main station with illegal commodities in the hold.

In the original game this had the effect of making trade in such commodities illegal as the only place they could be bought was main stations. Oolite on the other hand can have many OXP added dockable objects that are not main stations some of which sell illegal items cheaply, in bulk, and with no penalty attached to launching with them from that dockable object (e.g. Random Hit's Seedy Space Bars). 

This allows for some very lucrative trading opportunities in illegal commodities from OXP dockables to main stations with no impact on the players legal status. This OXP goes someway to redressing the balance and increasing the risks of this strategy.

Initially (with version 1 of this OXP) Galcop simply introduced penalties for docking with illegal substances. Following intense lobbying from Amnesty Intergalactic and various Bounty Hunter interest groups Galcop agreed to give pilots the opportunity to hand over the goods to avoid penalties and for a small reward.


Version history
===============
2.2.6
- Updated all commodity references to using post-1.82 naming conventions.

2.2.5
- Spelling corrections.

2.2.4 - 22/02/18
- Will use GNN oxp for news reporting (if installed). If both GNN and Snoopers are installed, GNN will be used in preference.

2.2.3 - 31/03/17
- Removed hard-coded scanner range value, and made compatible with Library for configuration options.

2.2.2 - 18/12/15
- Improved integration with Smugglers to correct sequencing issue. Upon docking with slaves, the IGT Amnesty screen will now always be displayed before the Smugglers screen.

2.2.1 - 8/10/15
- Further tweaks to the screens and email sent when handling over slaves, to make it more like an Amnesty Intergalactic interface and message.

2.2.0 - 7/10/15
- Made illegal goods check occur at any GalCop-aligned station, rather than just the main station. 
- Better integration with Smugglers OXP (v0.5.0) - the screen when docking with slaves now looks like an Amnesty Intergalactic screen, rather than a GalCop Customs screen. If the player doesn't want to hand over the slaves to AI, they can chose to work with GalCop directly, at which point the Smugglers OXP will deal with the importation of illegal goods (slaves), and the player can attempt to bribe the docking officials if they choose.

2.1.1 - 1/9/15
- Minor text changes only.

2.1.0 - 30/8/15
- Made compatible with the 'Smugglers' OXP, by limiting the goods IGT deals with to just slaves when both are installed.

2.0.3 - 3/7/15
- Fixed issue with Slaverbase getting accidentally destroyed by asteroid collisions.

2.0.2 - 30/4/15
- Removed TL99 from equipment, added a condition script instead, for better 1.81 compatibility. 
- Added "has_npc_traffic" = no; to slaverbase, so it doesn't get NPC traffic

2.0.1 - 3/3/15
- Code improvements as suggested by Wildeblood. 
- Updated markSystem and unmarkSystem to use objects rather than system ID's only. 
- Fixed bug with link to email system.

2.0.0 - 28/2/15: Requires Oolite 1.80 (phkb) 
- Updated legacy code to use new functions and system populator, making Oolite 1.80 a requirement. 
- Updated slaver base shipdata.plist for 1.81 compatibility, added allegiance and markets, removed additional entry (because in 1.80 everything uses the cool griff models). 
- Turned off arrival reports on slaver base, so, when you dock to rescue slaves, and you have a scooped escape pod, the police don't "magically" turn up to haul the prisoner away. 
- Added interfaces to email system for general notifications (email system is not required, though), and added some data hooks for external referencing. 
- When the slaver base is destroyed, a GNN news item will be show (if Snoopers is installed). 
- Small bug fixes, spelling corrections and cosmetic code layout changes.

1.7.3 - 30/5/12
- Fixed minor bug introduced in last release. Thanks to Tricky for reporting.

1.7.2 - 25/5/12
- Update to maintain compatibilty with HyperCargo version 1.08 and above. Continues to work with HyperCargo v1.07. 
- Minor tweaks in preperation for Oolite 1.77. 
- Raised compatibility limit for new Cargoes to 1.1.0.
- Fixed non-critical typo in missions script (thanks Switeck).

1.7.1 - 28/4/12
- Raised compatibility limits for New Cargoes to 1.0.6 and HyperCargo to 1.07. 
- Fixed some bugs in the special slaves mission set-up. Thanks to richard.a.p.smith for reporting. 

1.7 19/4/12
- Added compatibility for New Cargoes 1.0.5 or above. 
- Updated Compatibility for HyperCargo 1.06 or above and Vortex 1.23 and above in light of changes to those OXPs for New Cargoes compatibility. 
- Vortex update includes bugfix that affected Maelstrom pilots only. 
- Added optional compatibility for OXPConfig (v2.09 or above). 
- Added detected contraband info to mission screens.

1.6 05/02/12: Requires Oolite 1.76. 
- Made JS strict mode compatible. 
- Made Save Anywhere OXP compatible. 
- Fixed bug in parsing of equipment.plist on mac systems. 
- Reduced unnecessary missionVariable storage. 
- Found and fixed several other minor bugs. 
- One of special missions now uses Griff model for station if installed.

1.5 07/08/11 
- Added code to check that target system for any missions offered after release of slaves is not post Nova. 
- Fixed minor bug that could rarely result in a cosmetic issue with the mission offer screens. 
- Fixed minor bug that could rarely result in mission target not being cleared correctly.

1.4 16/06/11
- General code tidy up with lessons learnt from making Escort Contracts OXP.
- Reduced max delay between releasing slaves and being offered mission. 
- Fixed a small bug on withupdating mission variables on intergalactic jump. 
- Updated Hypercargo compatibility code and Vortex compatibility code in light of a bug that showed up in Vortex version 1.11. This release compatible with Vortex 1.12.

1.3 - 11/4/11
- Added some simple missions which may be offered some time after slaves have been released.

1.2.1 - 5/4/11
- Fixed a bug with event handling on docking that could interfere with another OXP's mission screens. Thanks to Gimi for reporting and Eric Walch for advice on the fix.

1.2 - 03/4/11
- Made compatible with Thargoid's HyperCargo 1.04 and Vortex 1.11 OXP's. 
- Added option to attempt to bribe customs if detected. 
- Added option to make detection rate variable. 

1.1 - 26/3/11: Requires Oolite 1.75.1 
- Introduced interaction with customs and option to voluntarily handover contraband to avoid penalties and get a reward.

1.0 - 24/3/11
- Simply applies penalties if player docks at main station with contraband. No player interaction.

License
=======
This OXP is released under the Creative Commons Attribution - Non-Commercial - Share Alike 3.0 license. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/

Acknowledgements
================
Thanks to Thargoid for advice on the method to interact with another script/OXP's variables.
Thanks to Eric Walch for advice on avoiding conflicts with other OXP's, and Gimi for reporting the bug in version 1.2
Thanks to cim for making New Cargoes easy to interact with.
An additional acknowledgement can be found in spoilers.txt.
Thanks to all contributors to the thread on the Oolite BB for suggesting improvements to the original very basic idea.
Thanks to spara for developing the code to translate old commodity values into the new 1.81 format.
Thanks to wildeblood for his code improvement suggestions.

Equipment

Name Visible Cost [deci-credits] Tech-Level
TianveDirect Ship Maintenance Insurance yes 1000 1+
Legal-Record Backdoor Hack Chip yes 1000 1+

Ships

Name
Slaver Base

Models

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

Scripts

Path
Scripts/ig_conditions.js
"use strict";
this.name        = "IG_Equipment_Conditions";
this.author      = "phkb";
this.copyright   = "2015 phkb";
this.licence     = "CC BY-NC-SA 3.0";

this.allowAwardEquipment = function(equipment, ship, context) {
	// ig equipment cannot be bought -- it will be given to the player after a mission
	if ((equipment == "EQ_IG_INSURANCE" || equipment == "EQ_IG_LEGAL_HACK") && context != "scripted") {
		return false;
	}
	return true;
}
Scripts/ig_legal_hack.js
"use strict";

this.activated = function() {
	if(player.bounty > 0) {
		player.bounty = 0;
		player.ship.removeEquipment("EQ_IG_LEGAL_HACK");
		player.consoleMessage("Legal Status set to Clean. Hack chip removed.",5);
	} else {
		player.consoleMessage("You already have a clean record.",5);
	}
}
Scripts/illegal_goods_missions.js
"use strict";
this.name        = "illegal_goods_missions";
this.author      = "capt murphy";
this.copyright   = "2011 capt murphy";
this.licence     = "CC BY-NC-SA 3.0";
this.description = "Missions worldscript for illegal_goods_tweak.";

// "my son" must always be in array position 1 for a particular mission
this._rescueeArray = ["me", "my son", "my daughter", "my partner", "my spouse", "my brother", "my sister", "my father", "my mother"];

//======================================================================================================================
// clears up missionVariables from previous versions,
this.startUp = function() {
	if (missionVariables.ig_pendingmission === "no") {delete missionVariables.ig_pendingmission; delete missionVariables.ig_rescuetime; delete missionVariables.ig_missionlaunchtime; delete missionVariables.ig_rescuelocation;}
	if (missionVariables.ig_currentmission === "no"){this.$ig_cleanupmissionvariables();}
	delete missionVariables.ig_rescuelocation1;
	if (!worldScripts.snoopers && !worldScripts.GNN) {
		delete this.shipExitedWitchSpace;
	}
}

//======================================================================================================================
// existing missions cleared on galactic jump
this.playerEnteredNewGalaxy = function() {
    delete missionVariables.ig_pendingmission;
	delete missionVariables.ig_rescuelocation;
	delete missionVariables.ig_rescuetime;
	delete missionVariables.ig_missionlaunchtime;
    this.$ig_cleanupmissionvariables();
	mission.setInstructionsKey (null, "illegal_goods_missions");
}

//======================================================================================================================
// used at startUp to clean old missionVariables and at the end of a mission.
this.$ig_cleanupmissionvariables = function() {
	delete missionVariables.ig_currentmission;
	delete missionVariables.ig_contactname;
	delete missionVariables.ig_rescuee;
	delete missionVariables.ig_rescuedwhen;
	delete missionVariables.ig_missionsystem;
	delete missionVariables.ig_missionsystemname;
	delete missionVariables.ig_rescuelocationcurrent;
	delete missionVariables.ig_missionreward;
	delete missionVariables.ig_slaverbasedestroyed;
	delete missionVariables.ig_special5end;
	delete missionVariables.ig_special5slavecount;
}

//======================================================================================================================
this.missionScreenOpportunity = function() { // don't run if save anywhere scripted dock.
	if (player.ship.docked && player.ship.dockedStation.isMainStation) {
		this.$igmissionsetup();
		this.$igmissionfinish();
		delete missionVariables.ig_special5end; // needed to allow mission screen to run after handing over slaves at end of this mission.
	}
}

// send a news item out after the slaver base is destroyed
this.shipExitedWitchspace = function() {
	if (missionVariables.ig_slaverbasenewsitem && global.clock.seconds > parseInt(missionVariables.ig_slaverbasenewsitem)) {
		var news = {ID:this.name,
			Message:expandMissionText("special5_newsitem"),
			Agency:1,
			Priority:1
		};
		var g = worldScripts.GNN;
		if (g) g._insertNews(news);
		if (!g) {
			var w = worldScripts.snoopers;
			if (w) w.insertNews(news);
		}
		delete missionVariables.ig_slaverbasenewsitem;
		delete missionVariables.ig_slaverbasesystem;
	}
}

//======================================================================================================================
// if pending mission is true, mission launch time has passed and no current mission set up new mission,
this.$igmissionsetup = function() {
	if (missionVariables.ig_pendingmission && !missionVariables.ig_currentmission && clock.days >= missionVariables.ig_missionlaunchtime) {
		if (Math.random() < 0.4) {
			this.$igspecialmissionsetup(); // set up one of 4 special missions
		} else {
			this.$igstandardmissionsetup(); // set up standard mission.
		}
		if (missionVariables.ig_currentmission) { // possible that no mission results from set-up
			mission.runScreen({screenID: "igt_aimission", title: "Message from Amnesty Intergalactic", messageKey: "offer_mission"});
			if (missionVariables.ig_currentmission == "standard") {
				// email system interface
				var w = worldScripts.EmailSystem;
				if (w) {
					w.$createEmail({sender:"Amnesty Intergalactic",
						subject:"Meeting request",
						date:global.clock.seconds,
						message:expandMissionText("offer_mission"),
						isRead:true
					});
				}
			}
			delete missionVariables.ig_pendingmission;
			delete missionVariables.ig_missionlaunchtime;
			delete missionVariables.ig_rescuedwhen;
			delete missionVariables.ig_rescuetime;
			delete missionVariables.ig_rescuelocation;
		}
	}
}

//======================================================================================================================
// sets up standard mission.
this.$igstandardmissionsetup = function() {

	missionVariables.ig_contactname = (randomName() + " " + randomName());

	var rescuee = (Math.floor(Math.random() * this._rescueeArray.length));
	missionVariables.ig_rescuee = this._rescueeArray[rescuee];
	missionVariables.ig_rescuedwhen = (clock.days - missionVariables.ig_rescuetime);

	var targetsystemsID = new Array;
	var targetsystems = SystemInfo.systemsInRange(35);
	var potentialmissionsystem;

    if (targetsystems.length > 0) {
		var counter = 0;
		for (counter = 0; counter < targetsystems.length; counter++) {
			targetsystemsID[counter] = targetsystems[counter].systemID;
		}
		var thisGalaxy = system.info.galaxyID;
		var thisSystem = system.ID;
		// selects a system at random from systems within 35 light years of current system. If selected system is within 7 light years, or is post nova, or there is no possible route to the system will try and select another. If fails to find a suitable system within 100 iterations, mission is cancelled.
		counter = 0
		while (counter < 100) {
			potentialmissionsystem = targetsystemsID[(Math.floor(Math.random() * targetsystemsID.length))];
			if (!System.infoForSystem(thisGalaxy, thisSystem).routeToSystem(System.infoForSystem(thisGalaxy, potentialmissionsystem)) ||
				System.infoForSystem(thisGalaxy, potentialmissionsystem).sun_gone_nova ||
				System.infoForSystem(thisGalaxy, thisSystem).distanceToSystem(System.infoForSystem(thisGalaxy, potentialmissionsystem)) < 7) {
					potentialmissionsystem = -1;
			}
			counter++;
			if (potentialmissionsystem !== -1) {break;}
		}
	}

	if (potentialmissionsystem === -1) {return;}

	missionVariables.ig_missionsystem = potentialmissionsystem;
	missionVariables.ig_missionsystemname = System.infoForSystem(thisGalaxy, potentialmissionsystem).name;

	var distance = System.infoForSystem(thisGalaxy, thisSystem).routeToSystem(System.infoForSystem(system.info.galaxyID, potentialmissionsystem)).distance;

	missionVariables.ig_missionreward = (500 + (Math.floor(distance / 7) * 250));
	mission.markSystem({system:potentialmissionsystem, name:"ig_mission"});
	mission.setInstructionsKey ("mission_summary", "illegal_goods_missions");
	missionVariables.ig_currentmission = "standard";
	missionVariables.ig_rescuelocationcurrent = missionVariables.ig_rescuelocation;
}

//======================================================================================================================
// sets up special mission - runs standard mission set-up then overwrites some missionvariables.
this.$igspecialmissionsetup = function() {
	this.$igstandardmissionsetup();
	if (!missionVariables.ig_currentmission) {return;}

	var ig_switchvar =  (Math.floor(Math.random() * 4));

	switch(ig_switchvar) {
		case 0:
			missionVariables.ig_currentmission = "special1";
			missionVariables.ig_rescuee = this._rescueeArray[1];
			break;
		case 1:
			if (player.ship.equipmentStatus("EQ_IG_INSURANCE") !== "EQUIPMENT_OK") {
				missionVariables.ig_currentmission = "special2";
			}
			break;
		case 2:
			if (player.ship.equipmentStatus("EQ_IG_LEGAL_HACK") !== "EQUIPMENT_OK") {
				missionVariables.ig_currentmission = "special3";
			}
			break;
		case 3:
			missionVariables.ig_currentmission = "special4";
	}
}

//======================================================================================================================
// checks for current mission and correct system before running mission success screens.
this.$igmissionfinish = function () {
	if (missionVariables.ig_currentmission && system.info.systemID === missionVariables.ig_missionsystem) {
		switch (missionVariables.ig_currentmission) {
			case "standard":
				player.credits += missionVariables.ig_missionreward;
				mission.unmarkSystem({system:system.info.systemID, name:"ig_mission"});
				mission.setInstructionsKey (null, "illegal_goods_missions");
				var w = worldScripts.EmailSystem;
				if (!w) {
					mission.runScreen({screenID:"igt_endmission", title: "Eternal Gratitude.", messageKey: "end_mission_noemail"});
				} else {
					mission.runScreen({screenID:"igt_endmission", title: "Eternal Gratitude.", messageKey: "end_mission_withemail"});
					w.$createEmail({sender:missionVariables.ig_contactname,
						subject:"Eternal Gratitude",
						date:global.clock.seconds,
						message:expandMissionText("end_mission_email")
					});
				}
				clock.addSeconds (43200);
				this.$ig_cleanupmissionvariables();
				break;
			case "special1":
				mission.runScreen ({screenID:"igt_endmission", title: "Eternal Gratitude.", messageKey: "end_mission_special1", choicesKey: "ship_visit_agree"}, this.$ig_shipvisitchoice);
				break;
			case "special2":
				player.ship.awardEquipment("EQ_IG_INSURANCE");
				mission.setInstructionsKey (null, "illegal_goods_missions");
				mission.unmarkSystem({system:system.info.systemID, name:"ig_mission"});
				mission.runScreen ({screenID:"igt_endmission", title: "Eternal Gratitude.", messageKey: "end_mission_special2"});
				this.$ig_cleanupmissionvariables();
				break;
			case "special3":
				player.ship.awardEquipment("EQ_IG_LEGAL_HACK");
				mission.setInstructionsKey (null, "illegal_goods_missions");
				mission.unmarkSystem({system:system.info.systemID, name:"ig_mission"});
				mission.runScreen ({screenID:"igt_endmission", title: "Eternal Gratitude.", messageKey: "end_mission_special3"});
				this.$ig_cleanupmissionvariables();
				break;
			case "special4":
				player.credits += missionVariables.ig_missionreward;
				mission.runScreen ({screenID:"igt_endmission", title: "Eternal Gratitude.", messageKey: "end_mission_special4", choicesKey: "special4_mission_agree"}, this.$ig_special4choice);
				break;
			case "special5":
				if (missionVariables.ig_slaverbasedestroyed && missionVariables.ig_special5end !== "not yet") {
					mission.runScreen ({screenID:"igt_endmission", title: "Eternal Gratitude.", messageKey: "end_mission_special5", choicesKey: "special5_slaves_left"}, this.$ig_special5choice);
				}
		}
	}
}

//======================================================================================================================
this.$ig_shipvisitchoice = function(choice) {
	if (choice === "1_VISITAGREE") {
		player.credits += missionVariables.ig_missionreward;
		mission.setInstructionsKey (null, "illegal_goods_missions");
		mission.unmarkSystem({system:system.info.systemID, name:"ig_mission"});
		clock.addSeconds (43200);
		mission.runScreen ({screenID:"igt_endmission", title: "Eternal Gratitude.", messageKey: "end_mission_special1a"});
		player.ship.awardEquipment("EQ_TRUMBLE");
	} else {
		missionVariables.ig_missionreward = (missionVariables.ig_missionreward / 2);
		player.credits += missionVariables.ig_missionreward;
		mission.setInstructionsKey (null, "illegal_goods_missions");
		mission.unmarkSystem({system:system.info.systemID, name:"ig_mission"});
		mission.runScreen ({screenID:"igt_endmission", title: "Eternal Gratitude.", messageKey: "end_mission_special1b"});
	}
	this.$ig_cleanupmissionvariables();
}

//======================================================================================================================
this.$ig_special4choice = function(choice) {
	if (choice === "1_AGREESPECIAL5") {
		missionVariables.ig_currentmission = "special5"
		mission.setInstructionsKey ("special5_instructions", "illegal_goods_missions");
		missionVariables.ig_special5slavecount = 0;
		mission.runScreen ({screenID:"igt_endmission", title: "Eternal Gratitude.", messageKey: "end_mission_special4b"});
	} else {
		mission.setInstructionsKey (null, "illegal_goods_missions");
		mission.unmarkSystem({system:system.info.systemID, name:"ig_mission"});
		mission.runScreen ({screenID:"igt_endmission", title: "Eternal Gratitude.", messageKey: "end_mission_special4a"});
		this.$ig_cleanupmissionvariables();
	}
}

//======================================================================================================================
this.$ig_special5choice = function(choice) {
	if(choice === "1_YESSLAVES") {
		missionVariables.ig_special5end = "not yet";
		mission.runScreen ({screenID:"igt_endmission", title: "Eternal Gratitude.", messageKey: "end_mission_special5b"});
	} else {
		mission.setInstructionsKey (null, "illegal_goods_missions");
		mission.unmarkSystem({system:system.info.systemID, name:"ig_mission"});
		missionVariables.ig_missionreward = (1000 + (missionVariables.ig_special5slavecount * 50));
		mission.runScreen ({screenID:"igt_endmission", title: "Eternal Gratitude.", messageKey: "end_mission_special5a"});
		player.credits += missionVariables.ig_missionreward;
		this.$ig_cleanupmissionvariables();
	}
}

//======================================================================================================================
// used in special5 mission
this.systemWillPopulate = function() {

	// we put the slaver base in regardless of whether the player chooses to access the mission
	// it's on the other side of the sun, so they are unlikely to find it without notification
	// if they do, well, that's just a bonus for the player
	if ((missionVariables.ig_currentmission === "special4" || missionVariables.ig_currentmission === "special5") &&
		system.info.systemID === missionVariables.ig_missionsystem &&
		system.countShipsWithRole("slaver_base") === 0 &&
		!missionVariables.ig_slaverbasedestroyed) {

		// set the position of the base
		//log(this.name, "Adding slaver base to system");
		var position = Vector3D(0, 0, 1.2 + Math.random() * 0.2).fromCoordinateSystem("psu");
		// add base with populator
		system.setPopulator("slaver base", {
			callback: function(pos) {
				//log(this.name, "adding...");
				var sb = system.addShips("slaver_base", 1, pos);
				//log(this.name, "result: " + sb);
				// adjust properties of slaver base
				if (sb.length > 0) sb[0].suppressArrivalReports = true;
				if (!sb || sb.length == 0) log(this.name, "ERROR - slaser base not created!");
			}.bind(this),
			location:"COORDINATES",
			coordinates:position});

		// add some asteroids around the base
		system.setPopulator("sb_asteroid", {
			callback: function(pos) {
				system.addShips("asteroid", 8, pos, player.ship.scannerRange);
			}.bind(this),
			location:"COORDINATES",
			coordinates:position});

	}
}

//======================================================================================================================
// used for free maintenace equipment.
this.guiScreenChanged = function(to, from) {
	if(to === "GUI_SCREEN_EQUIP_SHIP" && player.ship.equipmentStatus("EQ_IG_INSURANCE") === "EQUIPMENT_OK") {
		this._ig_playercredits = player.credits;
	}
}

//======================================================================================================================
this.playerBoughtEquipment = function(equipment) {
	if(player.ship.equipmentStatus("EQ_IG_INSURANCE") === "EQUIPMENT_OK") {
		if(equipment === "EQ_RENOVATION") {
			player.credits = this._ig_playercredits;
			player.ship.removeEquipment("EQ_IG_INSURANCE");
			player.consoleMessage("TianveDirect Insurance Policy redeemed - No charge for Maintenance Overhaul",5);
		} else {
			this._ig_playercredits = player.credits;
		}
	}
}
Scripts/illegal_goods_tweak.js
"use strict";
this.name        = "illegal_goods_tweak";
this.author      = "Capt. Murphy";
this.copyright   = "2012 Capt. Murphy";
this.licence     = "CC BY-NC-SA 3.0";
this.description = "Introduces interaction with GalCop customs when docking at a main station with contraband in the hold.";

this._alwaysDetect = true;		// Change this to false if you want a chance that Galcop customs don't notice your Contraband.
this._loggingEnabled = false;	// enables log entries
this._ncOXPStations = true;		// if true and New Cargoes installed docking penalties will apply at some OXP stations (as defined by New Cargoes)
this._cargoNameArray = ["food", "textiles", "radioactives", "slaves", "liquor_wines", "luxuries", "narcotics", "computers", "machinery", "alloys", "firearms", "furs", "minerals", "alien_items"]; // used by Hypercargo/Vortex code
this._cargoType = ["food", "textiles", "radioactives", "slaves", "liquor_Wines", "luxuries", "narcotics", "computers", "machinery", "alloys", "firearms", "furs", "minerals", "gold", "platinum", "gem_stones", "alien_items"]; // used by New Cargoes code.
this._smugglers = false;
this._runContrabandCheck = false;

//======================================================================================================================
// OXPConfig2 attributes
this.oxpcSettings =
{
	Info: {Name:"illegal_goods_tweak",Display:"Illegal Goods Tweak",Notify:false,InfoB:"Note _ncOXPStations ignored if New Cargoes OXP is not installed. Default is main stations only."},
	Bool0: {Name:"_alwaysDetect",Def:true,Desc:"100% contraband detection rate."},
	Bool1: {Name:"_loggingEnabled",Def:false,Desc:"Enable Log Messages."},
	Bool2: {Name:"_ncOXPStations",Def:true,Desc:"Contraband checks at OXP stations."}
}

// configuration settings for use in Lib_Config
this._igtConfig = {Name:this.name, Alias:"Illegal Goods Tweak", Display:"Config", Alive:"_igtConfig",
	Bool:{
		B0:{Name:"_alwaysDetect", Def:true, Desc:"100% detection rate"},
		B1:{Name:"_loggingEnabled", Def:false, Desc:"Enable log messages"},
		B2:{Name:"_ncOXPStations", Def:true, Desc:"Check at OXP stations"},
		Info:"0 - 100% contraband detection rate.\n1 - Output debug messages to the log.\n2 - Enable contraband check at OXP stations."},
};

//======================================================================================================================
this.startUp = function() { // clean up old missionVariable from previous versions.

	if (missionVariables.ig_always_detect){
		if (missionVariables.ig_always_detect === "no"){this._alwaysDetect = false;}
		delete missionVariables.ig_always_detect;
	}
	delete missionVariables.ig_amnestyreward;
	delete missionVariables.ig_bribe;
	// compatibility checks....
	if (worldScripts["CargoTypeExtension"]) {
		this._compatibilityMessage = "";
		var version = worldScripts["CargoTypeExtension"].version;
		if (version.localeCompare("1.2.3") < 0)	{this._compatibilityMessage += "Illegal Goods Tweak is not compatible with New Cargoes version "+version+". Please upgrade to New Cargoes verson 1.2.3 or later.\n\n";}
		if (worldScripts["HyperCargo"]) {
			version = worldScripts["HyperCargo"].version;
			if (Number(version) < 1.07) {this._compatibilityMessage += "Illegal Goods Tweak and New Cargoes not compatible with HyperCargo version "+version+". Please upgrade to HyperCargo version 1.07 or later.\n\n";}
		}
		if (worldScripts["vortex_player.js"]) {
			version = worldScripts["vortex_player.js"].version;
			if (Number(version) < 1.23) {this._compatibilityMessage += "Illegal Goods Tweak and New Cargoes not compatible with Vortex version "+version+". Please upgrade to Vortex version 1.23 or later.";}
		}
	}
	if (worldScripts.Smugglers_Illegal) this._smugglers = true;

	// register our settings, if Lib_Config is present
	if (worldScripts.Lib_Config) worldScripts.Lib_Config._registerSet(this._igtConfig);
}

//======================================================================================================================
this.shipDockedWithStation = function() { // will check for contraband if just docked
	this._runContrabandCheck = true;
}

//======================================================================================================================
this.missionScreenOpportunity = function() {
	if (this._compatibilityMessage) {
		mission.runScreen ({screenID:"igt_compatibility", title: "Warning"});
		mission.addMessageText(this._compatibilityMessage);
		delete this._compatibilityMessage;
	}
	if (this._runContrabandCheck && player.ship.docked &&
		(player.ship.dockedStation.allegiance == "galcop" || (this._ncOXPStations && worldScripts["CargoTypeExtension"] && worldScripts["CargoTypeExtension"].checkImports(player.ship.dockedStation)))) {
		delete this._runContrabandCheck;
		this.$contrabandCheck();
	}
}

//======================================================================================================================
this.$contrabandCheck = function () {
    //reset persistent variables.
	this._manNCSlavesIgnore = 0;
	this._manNCNarcsIgnore = 0;
	this._manNCArmsIgnore = 0;
	this._hcNCSlavesIgnore = 0;
	this._hcNCNarcsIgnore = 0;
	this._hcNCArmsIgnore = 0;
	this._mbNCSlavesIgnore = new Array;
	this._mbNCNarcsIgnore = new Array;
	this._mbNCArmsIgnore = new Array;
	this._mBSlavesIgnored = 0;
	this._mBNarcsIgnored = 0;
	this._mBArmsIgnored = 0;
	this._hcSlaves = 0;
	this._hcNarcs = 0;
	this._hcArms = 0;
	this._slavesNoPermit = new Array;
	this._narcsNoPermit = new Array;
	this._armsNoPermit = new Array;
	this._slavesTypeNoPermit = new Array;
	this._narcsTypeNoPermit = new Array;
	this._armsTypeNoPermit = new Array;

    // detect contraband in normal hold
	this._manSlaves = player.ship.manifest.slaves;
	this._manNarcs = player.ship.manifest.narcotics;
	this._manArms = player.ship.manifest.firearms;

	// check for special cargos and permits from New Cargoes OXP in manifest
	this._ncStatus = new Array;
	if (worldScripts["CargoTypeExtension"]){this.$checkNC("manifest");}
	if (this._ncStatus.length > 0) {this.$checkNCPermits("manifest","checkManifest");}
	if (this._smugglers == false) {
		var illegals = this._manSlaves - this._manNCSlavesIgnore + this._manNarcs - this._manNCNarcsIgnore + this._manArms - this._manNCArmsIgnore;
	} else {
		var illegals = this._manSlaves - this._manNCSlavesIgnore;
		this._manNarcs = 0;
		this._manNCNarcsIgnore = 0;
		this._manArms = 0;
		this._manNCArmsIgnore;
	}

	// detect contraband in hypercargo if fitted.
	if(player.ship.equipmentStatus("EQ_HYPERCARGO") === "EQUIPMENT_OK" && worldScripts["HyperCargo"]) {
		this._hcUsed = this.$checkHyperCargo();
		if (worldScripts["CargoTypeExtension"] && missionVariables.hyperCargoNewCargoes) {
			var tempCurrentManifest = worldScripts["CargoTypeExtension"].suspendPlayerManifest();
			worldScripts["CargoTypeExtension"].restorePlayerManifest(missionVariables.hyperCargoNewCargoes);
			this.$checkNC("hypercargo");
			if (this._ncStatus.length > 0) {this.$checkNCPermits("hypercargo","checkHyperCargo");}
			missionVariables.hyperCargoNewCargoes = worldScripts["CargoTypeExtension"].suspendPlayerManifest();
			worldScripts["CargoTypeExtension"].restorePlayerManifest(tempCurrentManifest);
		}
		if (this._hcUsed) {
			if (this._smugglers == false) {
				var illegalsHC = this._hcSlaves - this._hcNCSlavesIgnore + this._hcNarcs - this._hcNCNarcsIgnore + this._hcArms - this._hcNCArmsIgnore;
			} else {
				var illegalsHC = this._hcSlaves - this._hcNCSlavesIgnore;
			}
			// if hypercargo is hacked, has contraband and no contraband in main hold go to slipped past customs.
			if (missionVariables.hyperCargoFailChance === 0.05 && illegalsHC > 0 && illegals === 0){this.$slippedPastCustoms();}
			// other wise include hypercargo contraband in total count
			else if (missionVariables.hyperCargoFailChance !== 0.05){illegals += illegalsHC;}
		}
	}
	if (illegals > 0) { // if contraband is present...
		if (!this._alwaysDetect) { // if false random chance of detection
			if((Math.floor(Math.random() * 100) + 1) > ((system.techLevel + (system.government * 2) + 4)*3)){
				this.$slippedPastCustoms();
			} else {
				this.$warningScreen();
			}
		} else {
			this.$warningScreen();
		}
	} else {// if no illegals in main hold and no hypercargo check for vortex/maelstrom/multiBay and call multiBay code.
		if(player.ship.equipmentStatus("EQ_MULTIBAY") === "EQUIPMENT_OK") {
			this._manNarcs = 0;
			this._manSlaves = 0;
			this._manArms = 0;
			if(player.ship.name === "Maelstrom") {this._multiBayNo = 3;}
			if(player.ship.name === "Vortex") {this._multiBayNo = 5;}
			this.$suspendCurrentManifest();
			var bayCounter;
			for (bayCounter = 0; bayCounter < this._multiBayNo; bayCounter++) {
				if (bayCounter === missionVariables.multiBay_currentCargo) {continue;}
				this.$unloadMB(bayCounter);
				if (worldScripts["CargoTypeExtension"]) {this.$checkNC("multibay"+bayCounter);}
				if (this._ncStatus.length > 0) {this.$checkNCPermits("multibay"+bayCounter,"checkMultiBay",bayCounter);}
				if (this._smugglers == false) {
					this._manNarcs += player.ship.manifest.narcotics;
					this._manArms +=player.ship.manifest.firearms;
					this._mBNarcsIgnored += this._mbNCNarcsIgnore[bayCounter];
					this._mBArmsIgnored += this._mbNCArmsIgnore[bayCounter];
				}
				this._manSlaves += player.ship.manifest.slaves;
				if (this._smugglers == false) {
					illegals += player.ship.manifest.narcotics + player.ship.manifest.slaves + player.ship.manifest.firearms - this._mbNCNarcsIgnore[bayCounter]- this._mbNCSlavesIgnore[bayCounter]- this._mbNCArmsIgnore[bayCounter];
				} else {
					illegals += player.ship.manifest.slaves - this._mbNCSlavesIgnore[bayCounter];
				}
				this._mBSlavesIgnored += this._mbNCSlavesIgnore[bayCounter];
				this.$loadMB(bayCounter);
			}
			this.$restoreCurrentManifest();
			if (illegals > 0) {
				this._mbUsed = true;
				this.$slippedPastCustoms();
			}
		}
	}
}

//======================================================================================================================
// function to check if any contraband is a New Cargoes special cargo. Results are stored in this._ncStatus
this.$checkNC = function (location) {
	var counter;
	var arrayLength;
	var genericType;
	var quantity;
	var permitLevel;
	var tempArray = new Array;
	var index;
	var specificType;
	var specialCargoCarried = worldScripts["CargoTypeExtension"].specialCargoesCarried();
	if (specialCargoCarried.length > 0) {
		arrayLength = specialCargoCarried.length;
		for (counter = 0; counter < arrayLength; counter++) {
			genericType = worldScripts["CargoTypeExtension"].cargoDefinition(specialCargoCarried[counter],"genericType");
			if (genericType !== "slaves" && genericType !== "narcotics" && genericType !== "firearms") {continue;}

			specificType = worldScripts["CargoTypeExtension"].cargoDefinition(specialCargoCarried[counter],"specificType");
			quantity = worldScripts["CargoTypeExtension"].hasSpecialCargo(specialCargoCarried[counter]);
			permitLevel = worldScripts["CargoTypeExtension"].importPermitDetails(specialCargoCarried[counter],quantity);
			tempArray = [location,specialCargoCarried[counter],genericType,quantity,permitLevel,specificType];
			index = this._ncStatus.length;
			this._ncStatus[index] = tempArray;
			if (this._loggingEnabled) {log (this.name,"checkNC output: " + this._ncStatus);}
		}
	}
}

//======================================================================================================================
// function that checks this._ncStatus for contraband Special Cargo with a valid permit.
this.$checkNCPermits = function(location,context,bayCounter) {
	var counter;
	var arrayLength = this._ncStatus.length;
	var slaveCount = 0;
	var narcCount = 0;
	var armCount = 0;
	for (counter = 0; counter < arrayLength; counter++) {
		if (this._ncStatus[counter][0] !== location) {continue;}
		if (this._ncStatus[counter][2] === "slaves") {
			if (this._ncStatus[counter][4][0] !== 0 ||
				this._ncStatus[counter][4][1] !== 0 ||
				this._ncStatus[counter][4][2] !== 0) {
				slaveCount += this._ncStatus[counter][3];
				continue;
			} else {
				this._slavesNoPermit.push(this._ncStatus[counter][3]);
				this._slavesTypeNoPermit.push(this._ncStatus[counter][5]);
				continue;
			}
		}
		if (this._ncStatus[counter][2] === "narcotics") {
			if (this._ncStatus[counter][4][0] !== 0 ||
				this._ncStatus[counter][4][1] !== 0 ||
				this._ncStatus[counter][4][2] !== 0) {
				narcCount += this._ncStatus[counter][3];
				continue;
			} else {
				this._narcsNoPermit.push(this._ncStatus[counter][3]);
				this._narcsTypeNoPermit.push(this._ncStatus[counter][5]);
				continue;
			}
		}
		if (this._ncStatus[counter][2] === "firearms") {
			if (this._ncStatus[counter][4][0] !== 0 ||
				this._ncStatus[counter][4][1] !== 0 ||
				this._ncStatus[counter][4][2] !== 0) {
				armCount += this._ncStatus[counter][3];
			} else {
				this._armsNoPermit.push(this._ncStatus[counter][3]);
				this._armsTypeNoPermit.push(this._ncStatus[counter][5]);
				continue;
			}
		}
	}
	if (this._loggingEnabled) {log (this.name,"checkNCPermits context: "+context+", location: "+location+", Slaves Ignored: "+ slaveCount+ ", Narcs Ignored: "+narcCount+", Firearms ignored: "+armCount);}
	if (context === "checkManifest") {
		this._manNCSlavesIgnore = slaveCount;
		this._manNCNarcsIgnore = narcCount;
		this._manNCArmsIgnore = armCount;
		return;
	}
	if (context === "checkHyperCargo") {
		this._hcNCSlavesIgnore= slaveCount;
		this._hcNCNarcsIgnore = narcCount;
		this._hcNCArmsIgnore = armCount;
		return;
	}
	if (context === "checkMultiBay") {
		this._mbNCSlavesIgnore[bayCounter] = slaveCount;
		this._mbNCNarcsIgnore[bayCounter] = narcCount;
		this._mbNCArmsIgnore[bayCounter] = armCount;
		return;
	}
}

//======================================================================================================================
// function called when removing contraband to update New Cargoes records when necessary.
this.$updateNCStatus = function(location) {
  if (this._loggingEnabled) {log(this.name,"updateNCStatus called with param.: "+location);}
  var counter;
  var arrayLength = this._ncStatus.length;
  var iterations;
  for (counter = 0; counter < arrayLength; counter++) {
	if (this._ncStatus[counter][0] !== location) {continue;}
	if (location === "hypercargo") {
		var tempCurrentManifest = worldScripts["CargoTypeExtension"].suspendPlayerManifest();
		worldScripts["CargoTypeExtension"].restorePlayerManifest(missionVariables.hyperCargoNewCargoes);
	}
	if (this._ncStatus[counter][4][0] === 0 && this._ncStatus[counter][4][1] === 0 && this._ncStatus[counter][4][2] === 0) {
		iterations = this._ncStatus[counter][3];
		var counter1;
		for (counter1 = 0; counter1 < iterations; counter1++) {
			worldScripts["CargoTypeExtension"].removeSpecialCargo(this._ncStatus[counter][1])
		};
	}
	if (location === "hypercargo") {
		missionVariables.hyperCargoNewCargoes = worldScripts["CargoTypeExtension"].suspendPlayerManifest();
		worldScripts["CargoTypeExtension"].restorePlayerManifest(tempCurrentManifest);
	}
	if (this._loggingEnabled) {log(this.name,"tempCurrentmainifest: "+tempCurrentManifest+"missionVariables.hyperCargoNewCargoes: " +missionVariables.hyperCargoNewCargoes);}
  }
}

//======================================================================================================================
this.$checkHyperCargo = function() {
	var returnFlag = false;
	if (missionVariables.hyperCargoMemory === "EMPTY") {return returnFlag;}
	if (worldScripts["HyperCargo"].storedArray[3] > 0) {this._hcSlaves = worldScripts["HyperCargo"].storedArray[3]; returnFlag = true;}
	if (worldScripts["HyperCargo"].storedArray[6] > 0) {this._hcNarcs = worldScripts["HyperCargo"].storedArray[6]; returnFlag = true;}
	if (worldScripts["HyperCargo"].storedArray[10] > 0) {this._hcArms = worldScripts["HyperCargo"].storedArray[10]; returnFlag = true;}
	return returnFlag;
}

//======================================================================================================================
this.$updateHyperCargo = function() {
	worldScripts["HyperCargo"].storedArray[3] = this._hcNCSlavesIgnore;
	worldScripts["HyperCargo"].storedArray[6] = this._hcNCNarcsIgnore;
	worldScripts["HyperCargo"].storedArray[10] = this._hcNCArmsIgnore;
	var counter;
	var contents = 0;
	missionVariables.hyperCargoMemory = "";
	for(counter = 0; counter < 14; counter++) {
		contents += worldScripts["HyperCargo"].storedArray[counter];
		missionVariables.hyperCargoMemory = missionVariables.hyperCargoMemory + worldScripts["HyperCargo"].storedArray[counter] + ":";
	}
	if (contents === 0) {missionVariables.hyperCargoMemory = "EMPTY";}
}

//======================================================================================================================
this.$suspendCurrentManifest = function() {
    if (worldScripts["CargoTypeExtension"]) {this._tempNCManifest = worldScripts["CargoTypeExtension"].suspendPlayerManifest();}
	this._tempManifestArray = new Array(17);
	var counter;
    for (counter = 0; counter < 17; counter++) {
		this._tempManifestArray[counter] = manifest[this._cargoType[counter]];
		manifest[this._cargoType[counter]] = 0;
	}
}

//======================================================================================================================
this.$restoreCurrentManifest = function() {
	var counter;
	for(counter = 0; counter < 17; counter++) {
		manifest[this._cargoType[counter]] = this._tempManifestArray[counter];
	}
	delete this._tempManifestArray;
	if (worldScripts["CargoTypeExtension"]) {worldScripts["CargoTypeExtension"].restorePlayerManifest(this._tempNCManifest);}
}

//======================================================================================================================
this.$unloadMB = function(bay) {
	if (worldScripts["CargoTypeExtension"] && missionVariables["multiBay_ncBay" + bay]) {
		worldScripts["CargoTypeExtension"].restorePlayerManifest(missionVariables["multiBay_ncBay" + bay]);
	}
	var tempArray = missionVariables["multiBay_cargoBay" + bay].split(":");
	var cargoCounter;
	for (cargoCounter = 0; cargoCounter < 14; cargoCounter++) {
		manifest[this._cargoNameArray[cargoCounter]] = tempArray[cargoCounter];
	}
}

//======================================================================================================================
this.$loadMB = function(bay) {
	var tempArray = new Array(14);
	var loadCounter;
	for(loadCounter = 0; loadCounter < 14; loadCounter++) {
		tempArray[loadCounter] = manifest[this._cargoNameArray[loadCounter]];
		manifest[this._cargoNameArray[loadCounter]] = 0;
	}
	missionVariables["multiBay_cargoBay" + bay] = tempArray.join(":");
	if(worldScripts["CargoTypeExtension"]) {
		missionVariables["multiBay_ncBay" + bay] = worldScripts["CargoTypeExtension"].suspendPlayerManifest();
	}
}

//======================================================================================================================
this.$detectedChoice = function(choice) {
	if (choice === "1_YES") {// handover contraband
		this.$commonHandover();
	}
	if (choice === "2_NO") {// ignore warning
		this.$commonPenalty();
	}
	if (choice === "4_NO") {// switch to smugglers
		worldScripts.Smugglers_Equipment._doCargoCheck = true;
	}
	if (choice === "3_BRIBE") { // attempt bribe
		if((Math.floor(Math.random() * 100) + 1) < (system.government + (7 - system.economy) + 5 * 5)) {
			missionVariables.ig_legalpenalty = 25;
			player.ship.setBounty(player.bounty + missionVariables.ig_legalpenalty, "attempted bribe");
			mission.runScreen ({screenID:"igt_bribe", title: "Bribery Is An Offence!", messageKey: "failed_bribe", model: "police", choicesKey: "failedbribe_handover_yesno"}, this.$failedBribeChoice);
			// email system interface
			var w = worldScripts.EmailSystem;
			if (w) {
				var ga = worldScripts.GalCopAdminServices;
				w.$createEmail({sender:"GalCop Customs",
					subject:"Attempt to bribe official",
					date:global.clock.seconds,
					message:expandMissionText("failed_bribe_email", {stationname:player.ship.dockedStation.displayName, systemname:System.systemNameForID(global.system.ID)}),
					expiryDays:ga._defaultExpiryDays
				});
			}
			delete missionVariables.ig_legalpenalty;
		} else {
			missionVariables.ig_bribe = Math.round(((this._manArms - this._manNCArmsIgnore + this._hcArms - this._hcNCArmsIgnore) * (49.6 +(Math.random() * 39.2))) + ((this._manNarcs - this._manNCNarcsIgnore + this._hcNarcs - this._hcNCNarcsIgnore) * (0.4 +(Math.random() * 101.2))) + ((this._manSlaves - this._manNCSlavesIgnore + this._hcSlaves - this._hcNCSlavesIgnore) * (2 +(Math.random() * 26.4))));
			if(missionVariables.ig_bribe > player.credits) {
				missionVariables.ig_bribe = player.credits;
			}
			mission.runScreen({screenID:"igt_bribe", title: "Interesting...", messageKey: "offered_bribe", model: "police", choicesKey: "bribe_accept_yesno"}, this.$bribeChoice);
		}
	}
}

//======================================================================================================================
this.$failedBribeChoice = function(choice) {
	if (choice === "1_YES") { // handover after failed bribe attempt
		this.$commonHandover();
	} else { // ignore warnings
		this.$commonPenalty();
	}
}

//======================================================================================================================
this.$bribeChoice = function(choice) {
	if (choice === "1_PAY") { // pay bribe
		player.credits -= missionVariables.ig_bribe;
		mission.runScreen ({screenID:"igt_bribe", title: "All Clear.", messageKey: "paid_bribe", model: "police"});
		delete missionVariables.ig_bribe;
	}
	if (choice === "2_NO") { // don't pay bribe and accept legal penalty
		delete missionVariables.ig_bribe;
		this.$commonPenalty();
	}
	if (choice === "3_YES") { // don't pay bribe and handover contraband
	    delete missionVariables.ig_bribe;
		this.$commonHandover();
	}
}

//======================================================================================================================
this.$warningScreen = function() {
	if (this._smugglers == false) {
		mission.runScreen({
			screenID:"igt_warning", 
			title: "GalCop Customs Warning", 
			messageKey: "contraband_warning", 
			model: "police", 
			choicesKey: "detected_yesnobribe"}, 
		this.$detectedChoice);
	} else {
		mission.runScreen({
			screenID:"igt_warning", 
			title: "Amnesty Intergalactic", 
			messageKey: "contraband_warning_alt", 
			overlay:{name:"stgu-candle.png", height:546}, 
			choicesKey: "detected_yesno"}, 
		this.$detectedChoice);
	}
	this.$appendDetectedContraband();
}

//======================================================================================================================
this.$appendDetectedContraband = function() {
	mission.addMessageText("Contraband Detected:\n");
	var counter;
	this._detectedContraband = "";

	var slavesDetected = this._manSlaves - this._manNCSlavesIgnore + this._hcSlaves - this._hcNCSlavesIgnore - this._mBSlavesIgnored;
	if (slavesDetected > 0) {
		var slavesMessage = "Slaves : "+slavesDetected+" units";
		if (this._slavesNoPermit.length > 0) {
			slavesMessage += " including ";
			for (counter = 0; counter < this._slavesNoPermit.length; counter++) {
				slavesMessage += this._slavesNoPermit[counter] + " ";
				if ((this._slavesNoPermit.length - counter) === 1){
					slavesMessage += this._slavesTypeNoPermit[counter]+".";
				} else {
					slavesMessage += this._slavesTypeNoPermit[counter]+", ";
				}
			}
		} else {
			slavesMessage += ".";
		}
		mission.addMessageText(slavesMessage);
		this._detectedContraband += slavesMessage + "\n";
	}
	if (this._smugglers == false) {
		var narcsDetected = this._manNarcs - this._manNCNarcsIgnore + this._hcNarcs - this._hcNCNarcsIgnore - this._mBNarcsIgnored;
		if (narcsDetected > 0) {
			var narcsMessage = "Narcotics : "+narcsDetected+" tons";
			if (this._narcsNoPermit.length > 0) {
				narcsMessage += " including ";
				for (counter = 0; counter < this._narcsNoPermit.length; counter++) {
					narcsMessage += this._narcsNoPermit[counter]+" ";
					if ((this._narcsNoPermit.length - counter) === 1) {
						narcsMessage += this._narcsTypeNoPermit[counter]+".";
					} else {
						narcsMessage = narcsMessage +this._narcsTypeNoPermit[counter]+", ";
					}
				}
			} else {
				narcsMessage += ".";
			}
			mission.addMessageText(narcsMessage);
			this._detectedContraband += narcsMessage + "\n";
		}
		var armsDetected = this._manArms - this._manNCArmsIgnore + this._hcArms - this._hcNCArmsIgnore - this._mBArmsIgnored;
		if (armsDetected > 0) {
			var armsMessage = "Firearms : "+armsDetected+" tons";
			if (this._armsNoPermit.length > 0) {
				armsMessage += " including ";
				for (counter = 0; counter < this._armsNoPermit.length; counter++) {
					armsMessage += this._armsNoPermit[counter]+" ";
					if ((this._armsNoPermit.length - counter) === 1) {
						armsMessage += this._armsTypeNoPermit[counter]+".";
					} else {
						armsMessage = armsMessage +this._armsTypeNoPermit[counter]+", ";
					}
				}
			} else {
				armsMessage += ".";
			}
			mission.addMessageText(armsMessage);
			this._detectedContraband += armsMessage + "\n";
		}
	}
}

//======================================================================================================================
this.$slippedPastCustoms = function() {
	mission.runScreen ({screenID:"igt_slipcustoms", title: "You Slipped Past Customs.", messageKey: "handover_voluntary", choicesKey: "handover_vol_yesno"}, this.$volHandoverChoice);
	this.$appendDetectedContraband();
}

//======================================================================================================================
this.$volHandoverChoice = function (choice) {
	if(choice === "1_YES") { // if slipped past customs handover voluntarily.
		this.$commonHandover();
	} else {
		delete this._hcUsed;
		delete this._mbUsed;
	}
}

//======================================================================================================================
this.$commonHandover = function() {
	if (this._ncStatus.length > 0) {this.$updateNCStatus("manifest");}
	player.ship.manifest.slaves = this._manNCSlavesIgnore;
	if (this._smugglers == false) {
		player.ship.manifest.narcotics = this._manNCNarcsIgnore;
		player.ship.manifest.firearms = this._manNCArmsIgnore;
	}
	if (this._hcUsed) {
		this.$updateHyperCargo();
		if (this._ncStatus.length > 0){this.$updateNCStatus("hypercargo");}
		delete this._hcUsed;
	}
	if (this._mbUsed) {
		delete this._mbUsed;
		this.$suspendCurrentManifest();
		var bayCounter = 0;
		for (bayCounter = 0; bayCounter < this._multiBayNo; bayCounter++) {
			if (bayCounter === missionVariables.multiBay_currentCargo) {continue;}
			this.$unloadMB(bayCounter);
			if (this._ncStatus.length > 0) {this.$updateNCStatus("multibay"+bayCounter);}
			player.ship.manifest.slaves = this._mbNCSlavesIgnore[bayCounter];
			if (this._smugglers == false) {
				player.ship.manifest.narcotics = this._mbNCNarcsIgnore[bayCounter];
				player.ship.manifest.firearms = this._mbNCArmsIgnore[bayCounter];
			}
			this.$loadMB(bayCounter);
		}
		this.$restoreCurrentManifest();
	}
	// keep track of how many slaves rescued, for use externally
	if ((this._manSlaves - this._manNCSlavesIgnore - this._mBSlavesIgnored + this._hcSlaves - this._hcNCSlavesIgnore) > 0) {
		missionVariables.ig_rescued_slaves += (this._manSlaves - this._manNCSlavesIgnore - this._mBSlavesIgnored + this._hcSlaves - this._hcNCSlavesIgnore);
	}
	// set the reward amount
	if (this._smugglers == false) {
		missionVariables.ig_amnestyreward = this._manNarcs - this._manNCNarcsIgnore - this._mBNarcsIgnored + this._hcNarcs - this._hcNCNarcsIgnore + this._manArms - this._manNCArmsIgnore - this._mBArmsIgnored + this._hcArms - this._hcNCArmsIgnore + ((this._manSlaves - this._manNCSlavesIgnore - this._mBSlavesIgnored + this._hcSlaves - this._hcNCSlavesIgnore) * 5);
	} else {
		missionVariables.ig_amnestyreward = ((this._manSlaves - this._manNCSlavesIgnore - this._mBSlavesIgnored + this._hcSlaves - this._hcNCSlavesIgnore) * 5);
	}
	// add the reward to the player's account
	player.credits += missionVariables.ig_amnestyreward;
	// determine how to display the amount (either "credits" or "credit")
	missionVariables.ig_credittype = "credits";
	if (missionVariables.ig_amnestyreward == 1) missionVariables.ig_credittype = "credit";
	// show the mission screen
	if (this._smugglers == false) {
		mission.runScreen ({screenID:"igt_contraband", title: "Contraband Removed", messageKey: "amnesty_reward", model: "police"});
	} else {
		mission.runScreen ({screenID:"igt_contraband", title: "Slaves Rescued", messageKey: "amnesty_reward_alt", overlay:{name:"stgu-candle.png", height:546}});
		worldScripts.Smugglers_Equipment._doCargoCheck = true;
	}

	// email system interface
	var w = worldScripts.EmailSystem;
	if (w) {
		var ga = worldScripts.GalCopAdminServices;
		if (this._smugglers == false) {
			w.$createEmail({sender:"GalCop Customs",
				subject:"Contraband removal",
				date:global.clock.seconds,
				message:expandMissionText("amnesty_reward_email", {contraband:this._detectedContraband, stationname:player.ship.dockedStation.displayName, systemname:System.systemNameForID(global.system.ID)}),
				expiryDays:ga._defaultExpiryDays
			});
		} else {
			w.$createEmail({sender:"Amnesty Intergalactic",
				subject:"Slaves Rescued",
				date:global.clock.seconds,
				message:expandMissionText("amnesty_reward_email_alt", {contraband:this._detectedContraband, stationname:player.ship.dockedStation.displayName, systemname:System.systemNameForID(global.system.ID)}),
				expiryDays:ga._defaultExpiryDays
			});
		}
	}
	delete missionVariables.ig_credittype;
	delete missionVariables.ig_amnestyreward;
	if ((this._manSlaves - this._manNCSlavesIgnore - this._mBSlavesIgnored + this._hcSlaves - this._hcNCSlavesIgnore) > 0) {
		this.$missionInitialise();
	}
}

//======================================================================================================================
this.$commonPenalty = function() {
	missionVariables.ig_legalpenalty = this._manArms - this._manNCArmsIgnore + this._hcArms - this._hcNCArmsIgnore + this._manSlaves - this._manNCSlavesIgnore + this._hcSlaves - this._hcNCSlavesIgnore + ((this._manNarcs - this._manNCNarcsIgnore + this._hcNarcs - this._hcNCNarcsIgnore) * 2);
	player.ship.setBounty(player.bounty + missionVariables.ig_legalpenalty, "illegal imports");
	mission.runScreen ({screenID:"igt_penalised", title: "You Have Been Penalised!", messageKey: "legal_penalty", model: "police"});
	// email system interface
	var w = worldScripts.EmailSystem;
	if (w) {
		var ga = worldScripts.GalCopAdminServices;
		w.$createEmail({sender:"GalCop Customs",
			subject:"Contraband Penalty",
			date:global.clock.seconds,
			message:expandMissionText("legal_penalty_email", {stationname:player.ship.dockedStation.displayName, systemname:System.systemNameForID(global.system.ID)}),
			expiryDays:ga._defaultExpiryDays
		});
	}
	delete missionVariables.ig_legalpenalty;
}

//======================================================================================================================
// if slaves are handed over sets up potential mini missions.
this.$missionInitialise = function() {
	if (!missionVariables.ig_pendingmission) {
		var tempCounter = 0;
		var iterations = this._manSlaves - this._manNCSlavesIgnore - this._mBSlavesIgnored + this._hcSlaves - this._hcNCSlavesIgnore;
		for(tempCounter =0;tempCounter<iterations;tempCounter++) {
			if (Math.random() < 0.1) {
				missionVariables.ig_pendingmission = true;
				missionVariables.ig_rescuelocation = ("" + system.name);
				missionVariables.ig_rescuetime = clock.days;
				missionVariables.ig_missionlaunchtime = (clock.days + 7 + Math.floor(Math.random()*8));
				break;
			}
		}
	}
	// tacked on here - if slaves are handed over at end of special5 mission increment counter for special reward.
	if (missionVariables.ig_currentmission === "special5" && missionVariables.ig_missionsystem === system.info.systemID && missionVariables.ig_slaverbasedestroyed) {
		missionVariables.ig_special5slavecount += this._manSlaves - this._manNCSlavesIgnore - this._mBSlavesIgnored + this._hcSlaves - this._hcNCSlavesIgnore;
	}
}
Scripts/slaverbase.js
"use strict";
this.name        = "Slaver Base";
this.author      = "capt. murphy adapted from work by eric walch";
this.description = "Script for the Slaver Base included in illegal goods tweak OXP.";

//======================================================================================================================
this.shipBeingAttacked = function(attacker) {
    if (attacker.owner && attacker.owner === this.ship && attacker.target && attacker.target === this.ship)	{
		attacker.reactToAIMessage("TARGET_LOST");
	}
}

//======================================================================================================================
this.stationLaunchedShip = function(ship) {
    if (ship.primaryRole === "defense_ship") ship.switchAI("slaverbaseSlaverAI.plist");
	if (ship.primaryRole === "scavenger" && !ship.bounty) ship.bounty = Math.random() * 30;
}

//======================================================================================================================
this.shipDied = function(whom, cause) {
	missionVariables.ig_slaverbasedestroyed = true;
	// set up time for news item in 5 days time
	missionVariables.ig_slaverbasenewsitem = global.clock.seconds + (5 * 86400);
	missionVariables.ig_slaverbasesystem = system.name;
}
Scripts/slavermarket.js
"use strict";
this.name = "slaver-market";
this.author = "spara";
this.copyright = "2014 spara";
this.license     = "CC BY-NC-SA 4.0";

this.$originalDefs = {
      "food" : [0, 0, 20, -1, 0, 0, 1, 0, 0],
      "textiles" : [0, 0, 20, -1, 0, 0, 3, 0, 0],
      "radioactives" : [0, 0, 42, -3, -3, 0, 7, 3, 0],
      "slaves" : [0, 0, 2, 1, 0, 20, 1, 0, 0],
      "liquor_wines" : [0, 0, 105, -5, 0, 0, 15, 0, 0],
      "luxuries" : [0, 0, 236, 8, 0, 0, 3, 0, 0],
      "narcotics" : [0, 0, 10, 1, 0, 20, 120, 0, 0],
      "computers" : [0, 0, 150, 14, 0, 0, 3, 0, 0],
      "machinery" : [0, 0, 120, 6, 0, 0, 7, 0, 0],
      "alloys" : [0, 0, 70, 1, 0, 0, 31, 2, 0],
      "firearms" : [0, 0, 50, 1, 0, 29, 7, 0, 0],
      "furs" : [0, 0, 160, -9, 0, 0, 63, 0, 0],
      "minerals" : [0, 0, 16, -1, -1, 85, 3, 3, 0],
      "gold" : [0, 0, 73, -1, -1, 5, 7, 3, 1],
      "platinum" : [0, 0, 145, -2, -2, 6, 31, 7, 1],
      "gem_stones" : [0, 0, 25, -1, -1, 250, 15, 15, 2],
      "alien_items" : [0, 0, 140, 1, 0, 0, 3, 0, 0]
};

this.updateLocalCommodityDefinition = function(goodDefinition) {
	var commodity = goodDefinition.key;
	var oldDefs = this.$originalDefs[commodity];
	//old style definition found for the good. calculate it the old way
	if (oldDefs) {
		var market_base_price = oldDefs[2];
		var market_eco_adjust_price = oldDefs[3];
		var market_eco_adjust_quantity = oldDefs[4];
		var market_base_quantity = oldDefs[5];
		var market_mask_price = oldDefs[6];
		var market_mask_quantity = oldDefs[7];
		var market_rnd = Math.floor(Math.random() * 256);

		var economy = system.economy;

		var price = (market_base_price + (market_rnd & market_mask_price) + (economy * market_eco_adjust_price)) & 255;
		price *= 0.4;

		var quantity = (market_base_quantity + (market_rnd & market_mask_quantity) - (economy * market_eco_adjust_quantity)) & 255;
		if (quantity > 127) quantity = 0;
		quantity &= 63;

		goodDefinition.price = price * 10;
		goodDefinition.quantity = quantity;
	}
	//no definition found. nullify the goods.
	else {
		goodDefinition.price = 0;
		goodDefinition.quantity = 0;
	}
	return goodDefinition;
};