| Scripts/GalTech_escort_fighter.js | this.name			= "GalTech_escort_fighter";
this.author			= "Montana05";
this.description	= "event handler for GalTech escort fighter OXP";
this.version		= "1.10";
this.copyright		= "2020 Montana05";
this.licence   		= "CC BY-NC-SA 4.0";
"use strict";
// new features for Escort Fighter (will be removed if Shipbuilder disagrees):
this.shipSpawned = function(ship)
{
	this.$GalTech_shipType = this.ship.dataKey;
	this.$GalTech_pod = 0;
	var dice = 0;
	
	if(this.ship.hasRole("escape-capsule"))
	{
		// neutral inits first
		var $GalTech_crewName = expandDescription("[nom]");
		var $GalTech_description = "a crew member of an evacuated ship";
		var $GalTech_crewRole = "hunter";  // not perfect but somewhere in the middle
		var $GalTech_crewRace = expandDescription("[GalTech_GalCop_races]");  // added a race to the crew members
				
		// now it's time to be more specific, based on an estimated crew of up to 2 person
		// every individual without insurance or bounty will be defined as a slave
		switch(this.$GalTech_shipType) 
		{
			case "GalTech_escort_fighter_escape_capsule":
			
				this.$GalTech_escort_fighter_crew_ranks_Array = 
				["Gunner", "Pilot", "Commander"];
				var $GalTech_crewRanks = 
				$GalTech_escort_fighter_crew_ranks_Array[Math.floor(Math.random() * $GalTech_escort_fighter_crew_ranks_Array.length)];
			
				$GalTech_crewName = ("the " + $GalTech_crewRace + " " + $GalTech_crewRanks + " " + expandDescription("[nom]"));
				$GalTech_description = "a fighter crew member";
				$GalTech_crewRole = "hunter"; 	
				break;
			
			case "GalTech_escort_fighter_escape_capsule_police":
				
				this.$GalTech_escort_fighter_police_ranks_Array = 
				["Ensign", "Space Junior Lieutenant", "Space Lieutenant", "Lt. Commander"];
				var $GalTech_policeRank = 
				$GalTech_escort_fighter_police_ranks_Array[Math.floor(Math.random() * $GalTech_escort_fighter_police_ranks_Array.length)];
			
				$GalTech_crewName = ("the " + $GalTech_crewRace + " " + $GalTech_policeRank + " " + expandDescription("[nom]"));
				$GalTech_description = "a crew member of a space police ship";
				$GalTech_crewRole = "police"; 		
				break;
			
			case "GalTech_escort_fighter_escape_capsule_pirate":
				
				$GalTech_crewName = 
				("the " + $GalTech_crewRace + " " + expandDescription("[GalTech_pirate_nicknames]") + expandDescription("[nom]"));
				
				$GalTech_description = "a criminal wanted by GalCop police";
				$GalTech_crewRole = "pirate";
				break;	
			
			default: 
				break;			
		};
		this.ship.setCrew
		(
			{
				name: $GalTech_crewName,
				short_description: $GalTech_description,
				role: $GalTech_crewRole,
				species: $GalTech_crewRace
			}
		);
	}
	else
	{
		// checks if the ship is equipped with an escape pod, if yes the pod is removed and a flag is set to true
		if(this.ship.hasEquipmentProviding("EQ_ESCAPE_POD"))
		{
			this.ship.removeEquipment("EQ_ESCAPE_POD");
			this.$GalTech_pod = 1;
		};
				
		var $GalTech_shipRole = this.ship.primaryRole;
		// if the ship got no cargo some containers are added
		if(this.ship.cargoSpaceUsed === 0)
		{
			switch($GalTech_shipRole) 
			{
				// group members of a pirate-medium-fighter still have role escort
				case "pirate":
				case "pirate-medium-fighter":
				// individual roles per ship, will only be called from other OXP's	
				case "GalTech_Escort_Fighter-pirate":
				case "GalTech_Escort_Fighter-pirate_team_01":	
					
					this.ship.setCargoType("ILLEGAL_GOODS");
					break;
					
				case "escort":
				case "hunter":
				case "hunter-medium":
				// individual roles per ship, will only be called from other OXP's
				case "GalTech_Escort_Fighter-escort":
				case "GalTech_Escort_Fighter-hunter":	
				case "GalTech_Escort_Fighter-hunter_team_01":		
									
					dice = this.$getRndInteger(1, 2);
						
					// added some diversity
					if(dice === 1)
						this.ship.setCargoType("SCARCE_GOODS");
					if(dice === 2)
						this.ship.setCargoType("PLENTIFUL_GOODS");
					break;
					
				// police most likely will have weapons, not goods
				case "police":
				case "wingman":
				// individual role of the ship, will only be called from other OXP's	
				case "GalTech_Escort_Fighter-police":	
									
					dice = this.$getRndInteger(1, 2);
					this.ship.adjustCargo("firearms", dice);
					break;
				default: 
					break;
			};
		};
	};
};
this.shipDied = function(whom, why)
{
	if(this.ship.hasRole("escape-capsule"))
	{
		return;
	}
	else
	{
		// neutral inits first
		var $GalTech_podType = "escape-capsule";
		var debrisCount = 1;  // for pods
		var $GalTech_cargoLoad = this.ship.cargoSpaceUsed;
				
		// time to eject the escape pods
		if(this.ship.bounty > 7)
		{
			this.ship.commsMessage(expandDescription("[GALTECH_ESCORT_FIGHTER_PIRATE_ROLE_KILLED_MESSAGE]"), player.ship);
			$GalTech_podType = "GalTech_escort_fighter_escape_capsule_pirate";
		}
		else
		{
			switch(this.$GalTech_shipType) 
			{
				case "GalTech_Escort_Fighter-escort":
					this.ship.commsMessage(expandDescription("[GALTECH_ESCORT_FIGHTER_ESCORT_ROLE_KILLED_MESSAGE]"), player.ship);
					$GalTech_podType = "GalTech_escort_fighter_escape_capsule";
					break;
				case "GalTech_Escort_Fighter-hunter":
				case "GalTech_Escort_Fighter-hunter_team_01":	
					this.ship.commsMessage(expandDescription("[GALTECH_ESCORT_FIGHTER_HUNTER_ROLE_KILLED_MESSAGE]"), player.ship);
					$GalTech_podType = "GalTech_escort_fighter_escape_capsule";
					break;
				case "GalTech_Escort_Fighter-police":
				
					this.ship.commsMessage(expandDescription("[GALTECH_ESCORT_FIGHTER_POLICE_ROLE_KILLED_MESSAGE]"), player.ship);
					$GalTech_podType = "GalTech_escort_fighter_escape_capsule_police";	
					break;	
				
				// for pirates with small bounty, unlikely but better make sure
				case "GalTech_Escort_Fighter-pirate":
				case "GalTech_Escort_Fighter-pirate_team_01":	
		
					this.ship.commsMessage(expandDescription("[GALTECH_ESCORT_FIGHTER_PIRATE_ROLE_KILLED_MESSAGE]"), player.ship);
					$GalTech_podType = "GalTech_escort_fighter_escape_capsule_pirate";
					break;
				default: 
					break;	
			};	
		};
						
		// if the flag for pods is true the correct capsule is spawned
		if(this.$GalTech_pod == 1)
		{
			debrisCount = this.$getRndInteger(1, 2);
			system.addShips($GalTech_podType, debrisCount, this.ship.position);
		};
		debrisCount = this.$getRndInteger(4, 6);
		// added explosive shrapnels similar to Constitution Class Heavy Cruiser
		system.addShips("GalTech_effects_explosive_shrapnel", debrisCount, this.ship.position);
		// added various depris as a new feature
		system.addShips("GalTech_ship_debris", debrisCount, this.ship.position);
		// added burning fuel as a new feature
		debrisCount = (this.ship.fuel.toFixed(0)) * 2;	
		system.addShips("GalTech_effects_burningFuel", debrisCount, this.ship.position);
		// added some cargopods as a new feature
		if($GalTech_cargoLoad > 0)
		{
			var cargoIndex = this.ship.cargoList;
			var cargoTotal = 0;
			
			// calculate all containers from ship.cargoList
			for (var i = cargoIndex.length - 1 ; i >= 0 ; --i)
			{
				cargoTotal = cargoTotal + this.ship.cargoList[i].quantity;
			};
			// shouldn't happen but better save than sorry
			if(cargoTotal > $GalTech_cargoLoad)
				$GalTech_cargoLoad = cargoTotal;
			
			// time to eject cargopods
			for(var i = cargoIndex.length - 1 ; i >= 0 ; --i)
			{
				var cargoType = this.ship.cargoList[i].commodity;
				var cargoPod = ("GalTech_container_" + cargoType);
				var cargoCount = this.ship.cargoList[i].quantity;
												
				// Warning: additional commodities from an OXP are not covered and therefore will not be ejected 
				// exceptions: witchfire_whiskey, holy_artifacts, quirium_crystal
				while(cargoCount > 0)
				{
					this.ship.ejectSpecificItem(cargoPod);
					cargoCount = cargoCount - 1;
				};
			};
		};
	};
};	
this.$getRndInteger = function(min, max)
{
	return Math.floor(Math.random() * (max - min + 1) ) + min;
};
 |