| Scripts/MassTrans_FruitBat_events.js | this.name			= "MassTrans_FruitBat_events";
this.author			= "Montana05";
this.description	= "Event handler for Fruit Bat and Flying Fox";
this.version		= "1.10";
this.copyright		= "2021 Montana05";
this.licence		= "CC BY-NC-SA 3.0";
"use strict";
this.shipSpawned = function(ship)
{
	this.$MassTrans_FruitBat_shipType = this.ship.dataKey;
	this.$MassTrans_FruitBat_shipRole = this.ship.primaryRole;
	if(this.ship.hasRole("escape-capsule"))
	{
		var crewName = expandDescription("[nom]");
		var crewDescription = "a crew member of an evacuated ship";
		var crewRole = "hunter";  // not perfect but somewhere in the middle
		var crewRank = "Pilot";
		var crewRace = expandDescription("[MassTrans_FruitBat_GalCop_races_scientific]");  // add a race to the crew members
		var crewBounty = 0;
		var crewInsurance = this.$getRndInteger(90, 450);
		// based on an crew of 1 to 2 person
		this.$MassTrans_FruitBat_crew_ranks_array = 
		["Gunner", "Co-Pilot", "Pilot", "Commander"];
		crewRank = 
		$MassTrans_FruitBat_crew_ranks_array[Math.floor(Math.random() * $MassTrans_FruitBat_crew_ranks_array.length)];
		switch(this.$MassTrans_FruitBat_shipType) 
		{
			case "MassTrans_FruitBat_escape_capsule_std":
				crewName = ("the " + crewRace + " " + crewRank + " " + expandDescription("[nom]"));
				crewDescription = "a ship crew member";
				crewInsurance = crewInsurance;
				crewRole = "hunter";
				break;
			case "MassTrans_FruitBat_escape_capsule_MT":
				crewName = ("the " + crewRace + " " + crewRank + " " + expandDescription("[nom]"));
				crewDescription = "a MT Sec ship crew member";
				crewInsurance = (crewInsurance * 1.20);  // MT Sec got better insurance conditions
				crewRole = "hunter";
				break;
			
			case "MassTrans_FruitBat_escape_capsule_pirate":
				
				crewName = ("the " + crewRace + " " + expandDescription("[MassTrans_FruitBat_pirate_nicknames]") + expandDescription("[nom]"));
				crewDescription = "a " + expandDescription("[MassTrans_FruitBat_criminals]") +  "wanted by GalCop police";
				crewRole = "pirate";
				crewBounty = crewInsurance + (15 * system.government);  // stable governments pay extra bonus
				crewInsurance = 0;
				break;
	
			case "MassTrans_FruitBat_escape_capsule_MT_pirate":
				crewName = ("the " + crewRace + " " + crewRank + " " + expandDescription("[nom]"));
				crewDescription = "a rouge MT Sec ship crew member";
				crewBounty = (crewInsurance * 1.20) + (15 * system.government);  // stable governments pay extra bonus
				crewInsurance = 0;
				crewRole = "pirate";
				break;
				
			default: 
				break;
		};
		this.ship.setCrew
		(
			{
				name: crewName,
				short_description: crewDescription,
				role: crewRole,
				species: crewRace,
				insurance: crewInsurance,
				bounty: crewBounty
			}
		);
		
		// removes individual roles
		this.ship.primaryRole = "escape-capsule";
	}
	else
	{
		var cargoSpace = this.ship.cargoSpaceCapacity;
		var cargoLoad = this.ship.cargoSpaceUsed;
		var cargoLeft = cargoSpace - cargoLoad;
		
		// removes individual roles of the ships, this roles will only be called from other OXP's
		// adds some cargo to all ships
		switch(this.$MassTrans_FruitBat_shipRole) 
		{
			case "MassTrans_FruitBat":
			case "MassTrans_FlyingFox_MT":
			
				this.ship.primaryRole = "escort-medium";
				break;
			case "MassTrans_FruitBat_pirate":
				this.ship.primaryRole = "pirate-medium-fighter";
				break;
			default: 
				break;
		};
		if(cargoLeft >= 3)
		{
			for(var i = this.$getRndInteger(1, 3) - 1 ; i >= 0 ; --i)
			{
				this.ship.adjustCargo(this.$MassTrans_FruitBat_space_jockeyCargo(), 1);
			};
		};
	};
};	
this.shipDied = function(whom, why)
{
	if(this.ship.hasRole("escape-capsule"))
	{
		return;
	}
	else
	{
		// neutral inits first
		var podType = "escape-capsule";
		var podCount = 1;
		var criminalCrew = "N";
		var cargoType = "";
		var cargoPod = "cargopod";
		var cargoCount = 0;
		if(this.ship.bounty > 7 || this.$MassTrans_FruitBat_shipType == "MassTrans_FruitBat_pirate")
		{
			criminalCrew = "Y";
		};
					
		switch(this.$MassTrans_FruitBat_shipType) 
		{
			case "MassTrans_FruitBat":
			case "MassTrans_FruitBat_pirate":
			
				if(criminalCrew == "Y")
				{
					podType = "MassTrans_FruitBat_escape_capsule_pirate";
				}	
				else
				{
					podType = "MassTrans_FruitBat_escape_capsule_std";
				};
				break;
			
			case "MassTrans_FlyingFox_MT":
			
				if(criminalCrew == "Y")
				{
					podType = "MassTrans_FruitBat_escape_capsule_MT_pirate";
				}	
				else
				{
					podType = "MassTrans_FruitBat_escape_capsule_MT";
				};
				break;
			default: 
				break;
		};
		// emergency crafts
		system.addShips(podType, podCount, this.ship.position);
		
		// cargopods
		if(this.ship.cargoSpaceUsed > 0)
		{
			for(var i = this.ship.cargoList.length - 1 ; i >= 0 ; --i)
			{
				cargoType = this.ship.cargoList[i].commodity;
				cargoPod = ("MassTrans_FruitBat_cargo_" + cargoType);
				cargoCount = this.ship.cargoList[i].quantity;
							
				if(cargoType == "firearms" || cargoType == "food" || cargoType == "liquor_wines" || cargoType == "witchfire_whiskey")
				{
					system.addShips(cargoPod, cargoCount, this.ship.position);
				};
			};
		};
	};
};
// food, booze and guns, what else you need for your trip ? :P
this.$MassTrans_FruitBat_space_jockeyCargo = function()
{
	this.$MassTrans_FruitBat_space_jockey_cargo_array = ["firearms", "food", "liquor_wines"];
	if(worldScripts["witchfire-populator"])  // Darkside Moonshine Distillery OXP
	{
		this.$MassTrans_FruitBat_space_jockey_cargo_array.push("witchfire_whiskey");
	};
	var space_jockey_cargo = 
	$MassTrans_FruitBat_space_jockey_cargo_array[Math.floor(Math.random() * $MassTrans_FruitBat_space_jockey_cargo_array.length)];
	return (space_jockey_cargo);
};
this.$getRndInteger = function(min, max)
{
	return Math.floor(Math.random() * (max - min + 1) ) + min;
};
 |