| 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 = expandDescription("[igt_rescuee]").split("|");
//======================================================================================================================
// 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: expandDescription("[igt_amnesty_intergalactic]"), messageKey: "offer_mission" });
			if (missionVariables.ig_currentmission == "standard") {
				// email system interface
				var w = worldScripts.EmailSystem;
				if (w) {
					w.$createEmail({
						sender: expandDescription("[igt_email_amnesty]"),
						subject: expandDescription("[igt_email_subject]"),
						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: expandDescription("[igt_gratitude]"), messageKey: "end_mission_noemail" });
				} else {
					mission.runScreen({ screenID: "igt_endmission", title: expandDescription("[igt_gratitude]"), messageKey: "end_mission_withemail" });
					w.$createEmail({
						sender: missionVariables.ig_contactname,
						subject: expandDescription("[igt_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: expandDescription("[igt_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: expandDescription("[igt_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: expandDescription("[igt_gratitude]"), messageKey: "end_mission_special3" });
				this.$ig_cleanupmissionvariables();
				break;
			case "special4":
				player.credits += missionVariables.ig_missionreward;
				mission.runScreen({ screenID: "igt_endmission", title: expandDescription("[igt_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: expandDescription("[igt_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: expandDescription("[igt_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: expandDescription("[igt_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: expandDescription("[igt_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: expandDescription("[igt_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: expandDescription("[igt_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: expandDescription("[igt_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;
					// add some ships outside the base, so the player will have to fight them first
					var waiting = system.addShips("pirate", 3, pos, player.ship.scannerRange);
					worldScripts.illegal_goods_missions.$setWaitingPirates(sb[0], waiting);
				}
				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
		});
	}
}
//======================================================================================================================
this.$setWaitingPirates = function (sb, shps) {
	this._slaverBase = sb;
	for (var i = 0; i < shps.length; i++) {
		// turn ships "off" until the player is closer
		shps[i].switchAI("nullAI.plist");
	}
	this._waitingShips = shps;
	this._waitForPlayer = new Timer(this, this.$waitingForPlayer.bind(this), 20, 20);
}
//======================================================================================================================
this.$waitingForPlayer = function () {
	if (!this._sb) {
		this._waitForPlayer.stop();
		return;
	}
	if (player.ship.position.distanceTo(this._sb) < (player.ship.scannerRange * 2)) {
		this._waitForPlayer.stop();
		// switch the waiting ships over to the pirate AI.
		for (var i = 0; i < this._waitingShips.length; i++) {
			this._waitingShips[i].switchAI("pirateAI.plist");
		}
	}
}
//======================================================================================================================
// 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(expandDescription("[igt_insurance_policy]"), 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._onlySlaves = false;		// if true, and Smugglers is not installed, will only deal with slaves. Ignored if Smugglers is installed
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;
this._manualReleases = [];
this.runScreens = [];
//======================================================================================================================
// OXPConfig2 attributes
this.oxpcSettings = {
	Info: {
		Name: this.name,
		Display: expandDescription("[igt_config_alias]"),
		Notify: true,
		InfoB: expandDescription("[igt_oxpc_infob]")
	},
	Bool0: { Name: "_alwaysDetect", Def: true, Desc: expandDescription("[igt_contraband_rate]") },
	Bool1: { Name: "_loggingEnabled", Def: false, Desc: expandDescription("[igt_log_messages]") },
	Bool2: { Name: "_ncOXPStations", Def: true, Desc: expandDescription("[igt_check_oxp_stations]") },
	Bool3: { Name: "_onlySlaves", Def: false, Desc: "Only consider slaves as illegal" }
}
// configuration settings for use in Lib_Config
this._igtConfig = {
	Name: this.name,
	Alias: expandDescription("[igt_config_alias]"),
	Display: expandDescription("[igt_config_display]"),
	Alive: "_igtConfig",
	Notify: "oxpcNotifyOnChange",
	Bool: {
		B0: { Name: "_alwaysDetect", Def: true, Desc: expandDescription("[igt_contraband_rate]") },
		B1: { Name: "_loggingEnabled", Def: false, Desc: expandDescription("[igt_log_messages]") },
		B2: { Name: "_ncOXPStations", Def: true, Desc: expandDescription("[igt_check_oxp_stations]") },
		B3: { Name: "_onlySlaves", Def: false, Desc: expandDescription("[igt_only_slaves]") },
		Info: expandDescription("[igt_config_bool_info]")
	},
};
//======================================================================================================================
this.oxpcNotifyOnChange = function () {
	if (this._onlySlaves == false && this._smugglers == true) this._onlySlaves = true;
}
//======================================================================================================================
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;
	}
	if (missionVariables.ig_ncoxp) {
		if (missionVariables.ig_ncoxp === "no") this._ncOXPStations = false;
		delete missionVariables.ig_ncoxp;
	}
	if (missionVariables.ig_only_slaves) {
		if (missionVariables.ig_only_slaves === "yes") this._onlySlaves = true;
		delete missionVariables.ig_only_slaves;
	}
	if (missionVariables.ig_manual_releases) {
		this._manualReleases = JSON.parse(missionVariables.ig_manual_releases);
		delete missionVariables.ig_manual_releases;
	}
	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 += expandDescription("[igt_incompatible_nc]", { version: version });
		if (worldScripts["HyperCargo"]) {
			version = worldScripts["HyperCargo"].version;
			if (Number(version) < 1.07) this._compatibilityMessage += expandDescription("[igt_incompatible_hc]", { version: version });
		}
		if (worldScripts["vortex_player.js"]) {
			version = worldScripts["vortex_player.js"].version;
			if (Number(version) < 1.23) this._compatibilityMessage += expandDescription("[igt_incompatible_vortex]", { version: version });
		}
	}
	if (worldScripts.Smugglers_Illegal) { this._smugglers = true; this._onlySlaves = true; }
	if (worldScripts.BountySystem_Core) {
		worldScripts.BountySystem_Core._offenceTypes["freeing slaves"] = {
			description: expandDescription("[igt_offence]"),
			severity: 1
		};
	}
	// register our settings, if Lib_Config is present
	if (worldScripts.Lib_Config) worldScripts.Lib_Config._registerSet(this._igtConfig);
}
//======================================================================================================================
this.playerWillSaveGame = function () {
	missionVariables.ig_always_detect = (this._alwaysDetect ? "yes" : "no");
	missionVariables.ig_ncoxp = (this._ncOXPStations ? "yes" : "no");
	missionVariables.ig_only_slaves = (this._onlySlaves ? "yes" : "no");
	if (this._manualReleases.length > 0) {
		missionVariables.ig_manual_releases = JSON.stringify(this._manualReleases);
	} else {
		if (missionVariables.ig_manual_releases) delete missionVariables.ig_manual_releases;
	}
}
//======================================================================================================================
this.shipDockedWithStation = function () { // will check for contraband if just docked
	this.runScreens = [];
	this._runContrabandCheck = true;
	if (this._manualReleases.length >= 2) {
		var instr = ["Freeing Slaves Penalties:"];
		for (var i = 1; i < this._manualReleases.length; i++) {
			if ((clock.adjustedSeconds - this._manualReleases[i][2]) / 86400 > 2 && this._manualReleases[i][3] == 0) {
				this._manualReleases[i][3] = clock.adjustedSeconds + (7 * 86400); // default 7 days to comply
				// set up mini mission parameters
				missionVariables.ig_date = clock.clockStringForTime(this._manualReleases[i][2]).substring(0, 13);
				missionVariables.ig_expiry = clock.clockStringForTime(this._manualReleases[i][3]).substring(0, 13);
				missionVariables.ig_freed_at_system = System.systemNameForID(this._manualReleases[i][0]);
				missionVariables.ig_credits = (Math.floor(Math.random() * 15) + 10) * this._manualReleases[i][1];
				this.runScreens.push({
					screenID: "igt_penalty",
					title: expandDescription("[igt_message_galcop]"),
					message: expandMissionText("freeing_slaves_message2")
				});
				mission.markSystem({ system: this._manualReleases[i][0], name: "ig_freeingslaves" })
				delete missionVariables.ig_date;
				delete missionVariables.ig_freed_at_system;
				delete missionVariables.ig_expiry;
				delete missionVariables.ig_credits;
			}
			// rebuild any freeing slaves mini missions
			if (this._manualReleases[i][3] > 0) {
				if (player.ship.dockedStation.isMainStation && system.ID == this._manualReleases[i][0]) {
					// pay fine
					var fine = (Math.floor(Math.random() * 15) + 10) * this._manualReleases[i][1];
					if (fine > player.credits) fine = player.credits;
					player.credits -= fine;
					player.addMessageToArrivalReport("You have been fined " + formatCredits(fine, true, false) + " for releasing slaves into the station population without proper documentation.");
					mission.unmarkSystem({ system: system.ID, name: "ig_freeingslaves" });
					this._manualReleases[i][3] = -1;
				} else if ((clock.adjustedSeconds - this._manualReleases[i][3]) / 86400 > 7) {
					this.runScreens.push({
						screenID: "igt_penalty",
						title: expandDescription("[igt_message_galcop]"),
						message: expandMissionText("freeing_slaves_penalty")
					});
					// apply penalty
					player.setBounty(player.bounty + 40, "freeing slaves");
					this._manualReleases[i][3] = -1;
					mission.unmarkSystem({ system: this._manualReleases[i][0], name: "ig_freeingslaves" });
				} else {
					// still ongoing
					instr.push(expandDescription("[igt_report_mainstation]", { sysname: System.systemNameForID(this._manualReleases[i][0]), time: clock.clockStringForTime(this._manualReleases[i][3]).substring(0, 13) }));
				}
			}
		}
		if (instr.length > 1) {
			mission.setInstructions(instr, this.name);
		} else {
			mission.setInstructions(null, this.name);
		}
	}
}
//======================================================================================================================
this.missionScreenOpportunity = function () {
	if (this._compatibilityMessage) {
		mission.runScreen({ screenID: "igt_compatibility", title: "Warning" });
		mission.addMessageText(this._compatibilityMessage);
		delete this._compatibilityMessage;
		return;
	}
	// look for the ai warning
	if (this._manualReleases.length >= 1 && this._manualReleases[0][2] != 0 && (clock.adjustedSeconds - this._manualReleases[0][2]) / 86400 > 2) {
		this._manualReleases[0][2] = 0;
		missionVariables.ig_freed_at_system = System.systemNameForID(this._manualReleases[0][0]);
		missionVariables.ig_representative = expandDescription("%N [nom11]");
		mission.runScreen({
			screenID: "igt_warning1",
			title: expandDescription("[igt_amnesty_intergalactic]"),
			messageKey: "freeing_slaves_message",
			overlay: (this._smugglers ? { name: "stgu-candle.png", height: 546 } : null),
		});
		delete missionVariables.ig_freed_at_system;
		delete missionVariables.ig_representative;
		return;
	}
	// if we got a couple of freed slaves messages, show them now, one at a time
	if (this.runScreens.length > 0) {
		var obj = this.runScreens.shift();
		mission.runScreen(obj);
		return;
	}
	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.shipWillEnterWitchspace = function (cause) {
	if (cause == "galactic jump") {
		for (var i = 1; i < this._manualReleases.length; i++) {
			mission.unmarkSystem({ system: this._manualReleases[i][0], name: "ig_freeingslaves" })
		}
		this._manualReleases.length = 0;
		mission.setInstructions(null, this.name);
	}
}
//======================================================================================================================
this.playerEnteredNewGalaxy = function () {
}
//======================================================================================================================
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._onlySlaves == 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._onlySlaves == 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._onlySlaves == 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._onlySlaves == 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 === "0_RELEASE") {
		this.$commonRelease();
	}
	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: expandDescription("[igt_bribery]"), 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: expandDescription("[igt_sender_galcop]"),
					subject: expandDescription("[igt_bribery_subject]"),
					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: expandDescription("[igt_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: expandDescription("[igt_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._onlySlaves == false) {
		mission.runScreen({
			screenID: "igt_warning",
			title: expandDescription("[igt_customs_warning]"),
			messageKey: "contraband_warning",
			model: "police",
			choicesKey: "detected_yesnobribe"
		},
			this.$detectedChoice);
	} else {
		mission.runScreen({
			screenID: "igt_warning",
			title: expandDescription("[igt_slaves_hold]"),
			messageKey: "contraband_warning_alt",
			//overlay:{name:"stgu-candle.png", height:546}, 
			choicesKey: "detected_yesno"
		},
			this.$detectedChoice);
	}
	this.$appendDetectedContraband();
}
//======================================================================================================================
this.$appendDetectedContraband = function () {
	mission.addMessageText(expandDescription("[igt_contraband_detected]"));
	var counter;
	this._detectedContraband = "";
	var slavesDetected = this._manSlaves - this._manNCSlavesIgnore + this._hcSlaves - this._hcNCSlavesIgnore - this._mBSlavesIgnored;
	if (slavesDetected > 0) {
		var slavesMessage = expandDescription("[igt_slaves]", { count: slavesDetected });
		if (this._slavesNoPermit.length > 0) {
			slavesMessage += expandDescription("[igt_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._onlySlaves == false) {
		var narcsDetected = this._manNarcs - this._manNCNarcsIgnore + this._hcNarcs - this._hcNCNarcsIgnore - this._mBNarcsIgnored;
		if (narcsDetected > 0) {
			var narcsMessage = expandDescription("[igt_narcotics]", { count: narcsDetected });
			if (this._narcsNoPermit.length > 0) {
				narcsMessage += expandDescription("[igt_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 = expandDescription("[igt_firearms]", { count: armsDetected });
			if (this._armsNoPermit.length > 0) {
				armsMessage += expandDescription("[igt_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: expandDescription("[igt_slipped_past]"), 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.$commonRelease = function () {
	// remove the slaves
	if (this._ncStatus.length > 0) { this.$updateNCStatus("manifest"); }
	// put the system ID and the number of slaves released into an array
	this._manualReleases.push([system.ID, (this._manSlaves - this._manNCSlavesIgnore), clock.adjustedSeconds, 0]);
	player.ship.manifest.slaves = this._manNCSlavesIgnore;
	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];
			this.$loadMB(bayCounter);
		}
		this.$restoreCurrentManifest();
	}
	player.consoleMessage(expandDescription("[igt_slaves_released]", { count: (this._manSlaves - this._manNCSlavesIgnore) }), 6);
}
//======================================================================================================================
this.$commonHandover = function () {
	if (this._ncStatus.length > 0) { this.$updateNCStatus("manifest"); }
	player.ship.manifest.slaves = this._manNCSlavesIgnore;
	if (this._onlySlaves == 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._onlySlaves == 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._onlySlaves == 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 = expandDescription("[igt_credits]");
	if (missionVariables.ig_amnestyreward == 1) missionVariables.ig_credittype = expandDescription("[igt_credit]");
	// show the mission screen
	if (this._onlySlaves == false) {
		mission.runScreen({ screenID: "igt_contraband", title: expandDescription("[igt_contraband_removed]"), messageKey: "amnesty_reward", model: "police" });
	} else {
		mission.runScreen({
			screenID: "igt_contraband",
			title: expandDescription("[igt_slaves_rescued]"),
			messageKey: "amnesty_reward_alt",
			overlay: (this._smugglers ? { name: "stgu-candle.png", height: 546 } : null)
		});
		if (worldScripts.Smugglers_Equipment) worldScripts.Smugglers_Equipment._doCargoCheck = true;
	}
	// email system interface
	var w = worldScripts.EmailSystem;
	if (w) {
		var ga = worldScripts.GalCopAdminServices;
		if (this._onlySlaves == false) {
			w.$createEmail({
				sender: expandDescription("[igt_sender_galcop]"),
				subject: expandDescription("[igt_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: expandDescription("[igt_email_amnesty]"),
				subject: expandDescription("[igt_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: expandDescription("[igt_penalised]"), messageKey: "legal_penalty", model: "police" });
	// email system interface
	var w = worldScripts.EmailSystem;
	if (w) {
		var ga = worldScripts.GalCopAdminServices;
		w.$createEmail({
			sender: expandDescription("[igt_sender_galcop]"),
			subject: expandDescription("[igt_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/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;
};
 |