| Scripts/Taranis_outrider.js | this.name			= "Taranis_outrider";
this.author			= "Montana05";
this.description	= "event handler for the Taranis Outrider OXP";
this.version		= "2.00";
this.copyright		= "2022 Montana05";
this.licence   		= "CC BY-NC-SA 4.0";
"use strict";
this.shipSpawned = function(ship)
{
	if(ship.dataKey.search(/Taranis_outrider/i) < 0 || ship.isPlayer)
	{
		return;
	}
	else
	{
		var shipType = ship.dataKey;
		var shipRole = ship.primaryRole;
		
		// setup escape pods
		if(ship.hasRole("escape-capsule"))
		{
			let crewName = expandDescription("[nom]");
			let crewDescription = "a crew member of an evacuated ship";
			let crewRole = "hunter";  // the role is not particular important anymore, all data will be added by the script
			let crewRace = expandDescription("[Taranis_outrider_races_scientific]");  // adds a race to the crew members
			let crewRank = expandDescription("[Taranis_outrider_crew_civil_small]");
			let bhgRank = "Hunter";  // middle rank
			let crewInsurance = this.$getRndInteger(90, 450);
			let crewBounty = 0;
						
			// ranks for Bounty Hunter Guild taken from Random Hits OXP, all credits to LittleBear
			const Taranis_outrider_bhg_ranks_array = 
			["Outsider", "Recruit", "Vigilante", "Bailiff", "Deputy", "Tracker", "Hunter", "Sheriff", "Provost", "Marshal", "Enforcer", "Executioner", "Judge"];
			bhgRank = 
			Taranis_outrider_bhg_ranks_array[Math.floor(Math.random() * Taranis_outrider_bhg_ranks_array.length)];
			
			switch(shipType) 
			{
				case "Taranis_outrider_escape_capsule_std":
					crewName = ("the " + crewRace + " " + crewRank + " " + expandDescription("[nom]"));
					crewDescription = "a ship crew member";
					crewRole = "hunter";
					crewInsurance = this.$getRndInteger(90, 450);
					break;
				case "Taranis_outrider_escape_capsule_std_criminal":
					crewName = ("the " + crewRace + " " + expandDescription("[nom]"));
					crewDescription = "a " + expandDescription("[Taranis_outrider_criminals]") +  "wanted by GalCop police";
					crewRole = "pirate";
					crewBounty = crewInsurance + (15 * system.government);  // stable governments pay extra bonus
					crewInsurance = 0;
					break;
				case "Taranis_outrider_escape_capsule_std_pirate":
					crewName = ("the " + crewRace + " " + expandDescription("[Taranis_outrider_pirate_nicknames]") + expandDescription("[nom]"));
					crewDescription = "a " + expandDescription("[Taranis_outrider_criminals]") +  "wanted by GalCop police";
					crewRole = "pirate";
					crewBounty = (crewInsurance * 1.25) + (25 * system.government);  // stable governments pay extra bonus
					crewInsurance = 0;
					break;
					
				case "Taranis_outrider_escape_capsule_taranis_corp":
					crewName = ("the " + crewRace + " " + crewRank + " " + expandDescription("[nom]"));
					crewDescription = "an employee of Taranis Corporation";
					crewRole = "hunter";
					crewInsurance = (crewInsurance * 1.15);  // Taranis Corporation got better insurance conditions
					break;
					
				case "Taranis_outrider_escape_capsule_taranis_corp_criminal":
					crewName = ("the " + crewRace + " " + crewRank + " " + expandDescription("[nom]"));
					crewDescription = "a rogue employee of Taranis Corporation";
					crewRole = "pirate";
					crewBounty = (crewInsurance * 1.15) + (15 * system.government);  // stable governments pay extra bonus
					crewInsurance = 0;
					break;
	
				case "Taranis_outrider_escape_capsule_ssg":
					crewName = ("the " + crewRace + " " + crewRank + " " + expandDescription("[nom]"));
					crewDescription = "a SSG ship crew member";
					crewRole = "hunter";
					crewInsurance = (crewInsurance * 1.25);  // SSG got better insurance conditions
					break;
					
				case "Taranis_outrider_escape_capsule_ssg_criminal":
					crewName = ("the " + crewRace + " " + crewRank + " " + expandDescription("[nom]"));
					crewDescription = "a rogue SSG ship crew member";
					crewRole = "pirate";
					crewBounty = (crewInsurance * 1.25) + (15 * system.government);  // stable governments pay extra bonus
					crewInsurance = 0;
					break;
				case "Taranis_outrider_escape_capsule_bhg":
					crewName = ("the " + crewRace + " " + bhgRank + " " + expandDescription("[nom]"));
					crewDescription = "a member of the Bounty Hunter Guild";
					crewRole = "hunter";
					crewInsurance = (crewInsurance * 1.10);  // BHG got better insurance conditions
					break;
					
				case "Taranis_outrider_escape_capsule_bhg_criminal":
					crewName = ("the " + crewRace + " " + bhgRank + " " + expandDescription("[nom]"));
					crewDescription = "a rogue member of the Bounty Hunter Guild";
					crewRole = "pirate";
					crewBounty = (crewInsurance * 1.10) + (15 * system.government);  // stable governments pay extra bonus
					crewInsurance = 0;
					break;
				case "Taranis_outrider_escape_capsule_police":
					const Taranis_outrider_police_ranks_array = 
					["Ensign", "Space Junior Lieutenant", "Space Lieutenant", "Lt. Commander"];  // a crew of 1 to 2 person
					crewRank = 
					Taranis_outrider_police_ranks_array[Math.floor(Math.random() * Taranis_outrider_police_ranks_array.length)];
					crewName = ("the " + crewRace + " " + crewRank + " " + expandDescription("[nom]"));
					crewDescription = "an officer of GalCop Space Police";
					crewRole = "police";
					crewInsurance = (this.$getRndInteger(90, 450) + (15 * system.government));  // stable governments pay additional reward
					break;
					
				default: 
	
					break;	
			};
			ship.setCrew
			(
				{
					name: crewName,
					short_description: crewDescription,
					role: crewRole,
					species: crewRace,
					insurance: crewInsurance,
					bounty: crewBounty
				}
			);
			// removes individual roles
			ship.primaryRole = "escape-capsule";
		}
		else
		{
			let cargoSpace = ship.cargoSpaceCapacity;
			let cargoLoad = ship.cargoSpaceUsed;
			let cargoLeft = cargoSpace - cargoLoad;
			
			switch(shipRole) 
			{
				case "escort":
				case "escort-medium":
				case "Taranis_outrider_mark_I":
				case "Taranis_outrider_mark_II":
				case "Taranis_outrider_mark_II_ssg":
				
					if(shipRole.search(/Taranis_outrider/i) >= 0)
					{
						ship.primaryRole = "escort";
					};
				
					if(cargoLeft > 0)
					{
						for(var i = this.$getRndInteger(1, cargoLeft) - 1 ; i >= 0 ; --i)
						{
							ship.adjustCargo(this.$Taranis_outrider_space_jockey_cargo(), 1);
						};
					};
					break;
				case "taranis_defender":
				case "defense_ship":
				case "Taranis_outrider_mark_I_defender":
				case "Taranis_outrider_mark_II_defender":
				case "Taranis_outrider_mark_IIN_defender":
					
					if(shipRole.search(/Taranis_outrider/i) >= 0)
					{
						ship.primaryRole = "escort-medium";
						ship.switchAI("oolite-escortAI.js");
					};
				
					if(cargoLeft > 0)
					{
						for(var i = this.$getRndInteger(1, cargoLeft) - 1 ; i >= 0 ; --i)
						{
							ship.adjustCargo("firearms", 1);
						};
					};
					break;	
				case "hunter":
				case "hunter-medium":
				case "Taranis_outrider_mark_I_hunter":
				case "Taranis_outrider_mark_II_hunter":
				case "Taranis_outrider_mark_II_bhg":	
				case "Taranis_outrider_ssg_team_01":
				case "Taranis_outrider_bhg_team_01":
					if(shipRole.search(/Taranis_outrider/i) >= 0)
					{
						ship.primaryRole = "hunter";
					};
					if(cargoLeft > 0)
					{
						for(var i = this.$getRndInteger(1, cargoLeft) - 1 ; i >= 0 ; --i)
						{
							ship.adjustCargo(this.$Taranis_outrider_space_jockey_cargo(), 1);
						};
					};
					break;
				
				case "wingman":
				case "police":	
				case "Taranis_outrider_mark_IIN_bhg_deputy":
				case "Taranis_outrider_mark_IIN_police":	
					if(shipRole != "wingman")
					{
						ship.primaryRole = "police";
					};
					
					if(cargoLeft > 0)
					{
						for(var i = this.$getRndInteger(1, cargoLeft) - 1 ; i >= 0 ; --i)
						{
							ship.adjustCargo("firearms", 1);
						};
					};
					break;
								
				case "pirate":
				case "pirate-light-fighter":
				case "Taranis_outrider_mark_I_pirate":
				case "Taranis_outrider_mark_II_pirate":
					
					if(shipRole.search(/Taranis_outrider/i) >= 0)
					{
						ship.primaryRole = "pirate";
					};
					
					while(ship.cargoSpaceUsed == 0)  // makes sure that there is some cargo
					{
						if(this.$getRndInteger(1, 6) < 4)
						{
							ship.setCargoType("ILLEGAL_GOODS");
						}
						else
						{
							ship.setCargoType("PIRATE_GOODS");
						};
					};	
					break;
					
				default: 
	
					break;
			};
		};
		
		// if there is an existing script in shipDied time to move it
		ship.script.$Taranis_outrider_shipDied_old = ship.script.shipDied;
		ship.script.shipDied = this.$Taranis_outrider_shipDied;	
	};
};	
this.$Taranis_outrider_shipDied = function $Taranis_outrider_shipDied(whom, why) 
{
	if(this.ship.dataKey.search(/Taranis_outrider/i) < 0 || this.ship.hasRole("escape-capsule") || this.ship.isPlayer)
	{
		return;
	}
	else
	{
		this.name = "Taranis_outrider";
		
		let shipType = this.ship.dataKey;
		let shipBounty = this.ship.bounty;
		let shipPos = this.ship.position;
		let MRP01 = 0;
		let criminalCrew = 0;
		let pirateCrew = 0;
		if(worldScripts["MRP01_ressource_spawn"])  // Montanas Ressource Pack 01 OXP
		{
			MRP01 = 1;
		};
		
		if(shipBounty > 7 && shipBounty < 15)
		{
			criminalCrew = 1;
		};
		if(shipBounty > 14 || this.ship.isPirate)
		{
			pirateCrew = 1;
		};
		// if Montanas Ressource Pack 01 OXP is installed the containers from there are used, otherwise let the core-game handle it
		if(MRP01 == 1 && this.ship.cargoSpaceUsed > 0)
		{
			for(let i = this.ship.cargoList.length - 1 ; i >= 0 ; --i)
			{
				let cargoType = this.ship.cargoList[i].commodity;
				let cargoPod = ("MRP01_container_" + cargoType);
				let cargoCount = this.ship.cargoList[i].quantity;
				
				system.addShips(cargoPod, cargoCount, shipPos);
			};
		};
		switch(shipType) 
		{
			case "Taranis_outrider_mark_I_defender":
			case "Taranis_outrider_mark_II_defender":	
			case "Taranis_outrider_mark_IIN_defender":
				if(criminalCrew == 1 || pirateCrew == 1)
				{
					system.addShips("Taranis_outrider_escape_capsule_taranis_corp_criminal", 1, shipPos);
				}
				else
				{
					system.addShips("Taranis_outrider_escape_capsule_taranis_corp", 1, shipPos);
				};
				break;
			
			case "Taranis_outrider_mark_II_ssg":
			case "Taranis_outrider_ssg_team_01":
				if(criminalCrew == 1 || pirateCrew == 1)
				{
					system.addShips("Taranis_outrider_escape_capsule_ssg_criminal", 1, shipPos);
				}
				else
				{
					system.addShips("Taranis_outrider_escape_capsule_ssg", 1, shipPos);
				};
				break;
			case "Taranis_outrider_mark_II_bhg":
			case "Taranis_outrider_mark_IIN_bhg_deputy":
			case "Taranis_outrider_bhg_team_01":
				
				if(criminalCrew == 1 || pirateCrew == 1)
				{
					system.addShips("Taranis_outrider_escape_capsule_bhg_criminal", 1, shipPos);
				}
				else
				{
					system.addShips("Taranis_outrider_escape_capsule_bhg", 1, shipPos);
				};
				break;
			
			case "Taranis_outrider_mark_IIN_police":
			
				system.addShips("Taranis_outrider_escape_capsule_police", 1, shipPos);
				break;
				
			case "Taranis_outrider_mark_I_pirate":
			case "Taranis_outrider_mark_II_pirate":
								
				system.addShips("Taranis_outrider_escape_capsule_std_pirate", 1, shipPos);
				break;
				
			// escort, hunter
			default:
				
				if(criminalCrew == 1)
				{
					system.addShips("Taranis_outrider_escape_capsule_std_criminal", 1, shipPos);
				}
				else if(pirateCrew == 1)
				{
					system.addShips("Taranis_outrider_escape_capsule_std_pirate", 1, shipPos);
				}
				else
				{
					system.addShips("Taranis_outrider_escape_capsule_std", 1, shipPos);
				};
				break;	
		};
	};
	if(this.ship.script.$Taranis_outrider_shipDied_old)
	{
		this.ship.script.$Taranis_outrider_shipDied_old(whom, why);
	};
};
// food, medicine, booze and guns, what else you need for your trip ? :P
this.$Taranis_outrider_space_jockey_cargo = function()
{
	const space_jockey_cargo_array = ["firearms", "food", "liquor_wines"];
	 // Darkside Moonshine Distillery OXP
	if(worldScripts["witchfire-populator"] && space_jockey_cargo_array.indexOf("witchfire_whiskey") < 0)
	{
		space_jockey_cargo_array.push("witchfire_whiskey");
	};
	
	// medicine is part of several OXP's therefore a check of the market is required
	if(system.mainStation)
	{
		let goods = system.mainStation.market;
		for(let i in goods) 
		{
			if(goods[i].key == ["medicine"] && space_jockey_cargo_array.indexOf("medicine") < 0)
			{
				space_jockey_cargo_array.push("medicine");
			};
		};
	}; 
	let space_jockey_cargo = 
	space_jockey_cargo_array[Math.floor(Math.random() * space_jockey_cargo_array.length)];
	return (space_jockey_cargo);
};
this.$getRndInteger = function(min, max)
{
	return (Math.floor(Math.random() * (max - min + 1) ) + min);
};
 |