| Scripts/Breakable_Shield_Generators.js | this.name        = "Breakable_Shield_Generators"; 
this.author      = "capt murphy"; 
this.copyright   = "2012 capt murphy";
this.licence     = "CC BY-NC-SA 3.0"; // see http://creativecommons.org/licenses/by-nc-sa/3.0/ for more info.
this.description = "Script to simulate combat damage to the Shield Generators"; 
this.version     = "1.2";
// event handler driven function for functions at startup - awards equipment to existing ship if first run with OXP.
this.startUp = function()
{
	this.warning = new SoundSource;
	this.warning.sound = "warning.ogg";
	this.getShieldSize();
	if (player.ship.equipmentStatus(this.foreShieldEQ) === "EQUIPMENT_UNAVAILABLE"){missionVariables.bsg_foreshieldstatus = this.foreShieldEQ; player.ship.awardEquipment(this.foreShieldEQ); missionVariables.bsg_foreshieldstatus = "OK";}
	if (player.ship.equipmentStatus(this.aftShieldEQ) === "EQUIPMENT_UNAVAILABLE"){missionVariables.bsg_aftshieldstatus = this.aftShieldEQ; player.ship.awardEquipment(this.aftShieldEQ); missionVariables.bsg_aftshieldstatus = "OK";}	
}
this.getShieldSize = function()
{
	var sizeVar = (player.ship.maxEnergy + player.ship.cargoSpaceCapacity);
	if (player.ship.equipmentStatus("EQ_CARGO_BAY")==="EQUIPMENT_OK"){sizeVar -= 15;}
	if (sizeVar < 256){this.foreShieldEQ = "EQ_BREAKABLE_SHIELD_FORE_SMALL";this.aftShieldEQ = "EQ_BREAKABLE_SHIELD_AFT_SMALL";}
	else if (sizeVar < 512){this.foreShieldEQ = "EQ_BREAKABLE_SHIELD_FORE_MEDIUM";this.aftShieldEQ = "EQ_BREAKABLE_SHIELD_AFT_MEDIUM";}
	else {this.foreShieldEQ = "EQ_BREAKABLE_SHIELD_FORE_LARGE";this.aftShieldEQ = "EQ_BREAKABLE_SHIELD_AFT_LARGE";}
}
	
// event handler driven function to fit equipment to newly purchased ship.
this.playerBoughtNewShip = function()
{
	this.getShieldSize();
	missionVariables.bsg_foreshieldstatus = this.foreShieldEQ;
	missionVariables.bsg_aftshieldstatus = this.aftShieldEQ;
	player.ship.awardEquipment(this.foreShieldEQ);
	player.ship.awardEquipment(this.aftShieldEQ);
	missionVariables.bsg_foreshieldstatus = "OK";
	missionVariables.bsg_aftshieldstatus = "OK";
}
// event handler driven function to control actions if equipment damaged in combat.
this.equipmentDamaged = this.equipmentDestroyed = function(equipment)
{
    if (this.shipRestore && (equipment === this.foreShieldEQ || equipment === this.aftShieldEQ))
	{
		if (equipment === this.foreShieldEQ)
		{	 
			missionVariables.bsg_foreshieldstatus = this.foreShieldEQ;
		}
		if (equipment === this.aftShieldEQ)
		{
			missionVariables.bsg_aftshieldstatus = this.aftShieldEQ;
		}
		return;
	}
	if ((equipment === this.foreShieldEQ || equipment === this.aftShieldEQ) && (player.ship.equipmentStatus("EQ_NAVAL_SHIELD_BOOSTER") === "EQUIPMENT_OK" || player.ship.equipmentStatus("EQ_SHIELD_BOOSTER") === "EQUIPMENT_OK"))//if Military Shield Enhancement or Shield Boosters fitted these will be damaged first.
	{
	player.ship.setEquipmentStatus(equipment,"EQUIPMENT_OK");
	if (player.ship.equipmentStatus("EQ_NAVAL_SHIELD_BOOSTER") === "EQUIPMENT_OK")
		{
			player.ship.setEquipmentStatus("EQ_NAVAL_SHIELD_BOOSTER","EQUIPMENT_DAMAGED");
		    this.consoleMessageTimer = new Timer(this, this.consoleMessage1, 0.25);//delayed message in case other OXP (Shield Equaliser) prevents damage.
			return;
		}
	else
		{ 
			player.ship.setEquipmentStatus("EQ_SHIELD_BOOSTER","EQUIPMENT_DAMAGED");
			this.consoleMessageTimer = new Timer(this, this.consoleMessage2, 0.25);//delayed message in case other OXP (Shield Equaliser) prevents damage.
			return;
		}
	}
	if (equipment === this.foreShieldEQ || equipment === this.aftShieldEQ)
	{
		if (player.ship.equipmentStatus("EQ_SC_SHIELD_CYCLER_INTERNAL") === "EQUIPMENT_OK" && !worldScripts["Shield Cycler"].deactivated)// disables Shield Cycler if fitted and active to prevent catastrophic shield/energy loss.
		{
			if (worldScripts["Shield Cycler"].sc_stop())
			{
			 this.stoppedSC = true;
			 player.consoleMessage("All Shield Cycler functionality disabled pending Primary Shield Generator repair.",4);
			}
		}
	if (player.ship.equipmentStatus("EQ_SHIELD_EQUALIZER") === "EQUIPMENT_OK" && worldScripts["shieldequalizercapacitors"].shieldCheckTimer.isRunning)// disables Shield Equaliser (and Capacitors) if fitted to prevent catastrophic Shield Loss.
		{
			worldScripts["shieldequalizercapacitors"].shieldCheckTimer.stop();
			this.stoppedSEC = true;
			player.consoleMessage("All Shield Equalizer functionality disabled pending Primary Shield Generator repair.",4);
		}
	if (equipment === this.foreShieldEQ)
		{	 
			missionVariables.bsg_foreshieldstatus = this.foreShieldEQ;
		}
	if (equipment === this.aftShieldEQ)
		{
			missionVariables.bsg_aftshieldstatus = this.aftShieldEQ;
		}
	this.setupTimerFC();
	}
}
//delayed console messages.
this.consoleMessage1 = function()
{
 if (player.ship.equipmentStatus("EQ_NAVAL_SHIELD_BOOSTER") === "EQUIPMENT_OK")
 {return;}
 player.consoleMessage ("Military Shield Enhancement is damaged!", 2);
}
this.consoleMessage2 = function()
{
 if (player.ship.equipmentStatus("EQ_SHIELD_BOOSTER") === "EQUIPMENT_OK")
 {return;}
 player.consoleMessage ("Shield Booster is damaged!", 2);
}
	
// event handler driven function for actions on launching and exiting witchspace.
this.shipLaunchedFromStation = this.shipExitedWitchspace = function()
{
	if ((player.ship.equipmentStatus(this.foreShieldEQ) === "EQUIPMENT_OK" && missionVariables.bsg_foreshieldstatus !== "OK") || (player.ship.equipmentStatus(this.aftShieldEQ) === "EQUIPMENT_OK" && missionVariables.bsg_aftshieldstatus !== "OK")){this.reset();}
	if (missionVariables.bsg_foreshieldstatus !== "OK" || missionVariables.bsg_aftshieldstatus !== "OK"){this.setupTimerFC();}
}
// event handler driven function to stop timers on docking or player death.
this.shipWillDockWithStation = this.shipDied = function()
{
	if (this.updateTimer && this.warningTimer.isRunning){this.updateTimer.stop();delete this.updateTimer;}
	if (this.warningTimer && this.warningTimer.isRunning){this.warningTimer.stop();delete this.warningTimer;}
}
// creates timers if not already in existance otherwise restarts existing timers.
this.setupTimerFC = function()
{
	if (this.updateTimer && this.updateTimer.isRunning){this.updateTimer.stop();delete this.updateTimer;}
	this.updateTimer = new Timer (this,this.updateShield,0,0.25);
	if (this.warningTimer && this.warningTimer.isRunning){this.warningTimer.stop();delete this.warningTimer;}
	this.warningTimer = new Timer(this,this.warningSound,0,10);
}
// called by timer every 0.25 seconds when player is in flight to set damaged shield to 0.
this.updateShield = function()
{	
	if ((player.ship.equipmentStatus(this.foreShieldEQ) === "EQUIPMENT_OK" && missionVariables.bsg_foreshieldstatus !== "OK")||(player.ship.equipmentStatus(this.aftShieldEQ) === "EQUIPMENT_OK" && missionVariables.bsg_aftshieldstatus !== "OK")) // check to see if something has repaired the shields on the fly e.g. Thargoid's Repair Bots OXP.
	{
		this.reset();
		return;
	}
	if (missionVariables.bsg_aftshieldstatus !== "OK")
	{
		player.ship.aftShield = 0;
	}
	if (missionVariables.bsg_foreshieldstatus !== "OK")
	{
		player.ship.forwardShield = 0;
	}
	if (player.ship.equipmentStatus("EQ_SHIELD_EQUALIZER") === "EQUIPMENT_OK" && worldScripts["shieldequalizercapacitors"].shieldCheckTimer.isRunning)
		{
		    worldScripts["shieldequalizercapacitors"].shieldCheckTimer.stop();
			this.stoppedSEC = true;
			player.consoleMessage("All Shield Equaliser functionality disabled pending Primary Shield Generator repair.",4);
		}
	if (player.ship.equipmentStatus("EQ_SC_SHIELD_CYCLER_INTERNAL") === "EQUIPMENT_OK" && !worldScripts["Shield Cycler"].deactivated)
		{
			if (worldScripts["Shield Cycler"].sc_stop())
			{
			 this.stoppedSC = true;
			 player.consoleMessage("All Shield Cycler functionality disabled pending Primary Shield Generator repair.",4);
			}
		}
}
// called by timer every 10 seconds when player in flight to give warning noise whilst a shield is damaged.
this.warningSound = function()
{
	this.warning.play(1);
	if (missionVariables.bsg_foreshieldstatus !== "OK")
	{
		player.consoleMessage("Forward Shield Generator Damaged!", 3);
	}
	if (missionVariables.bsg_aftshieldstatus !== "OK")
	{
		player.consoleMessage("Aft Shield Generator Damaged!", 3);
	}
}
// function to reset the shields once equipment fixed and restart Shield Cycler and Shield Equaliser functionality.
this.reset = function()
{
	if (player.ship.equipmentStatus(this.foreShieldEQ) === "EQUIPMENT_OK" && missionVariables.bsg_foreshieldstatus !== "OK"){missionVariables.bsg_foreshieldstatus = "OK";}
	if (player.ship.equipmentStatus(this.aftShieldEQ) === "EQUIPMENT_OK" && missionVariables.bsg_aftshieldstatus !== "OK"){missionVariables.bsg_aftshieldstatus = "OK";}
	if (missionVariables.bsg_foreshieldstatus === "OK" && missionVariables.bsg_aftshieldstatus === "OK")
	{
		if (this.updateTimer && this.warningTimer.isRunning){this.updateTimer.stop();delete this.updateTimer;}
		if (this.warningTimer && this.warningTimer.isRunning){this.warningTimer.stop();delete this.warningTimer;}
		if (this.stoppedSC && worldScripts["Shield Cycler"].deactivated)
			{
				if (worldScripts["Shield Cycler"].sc_start())
				{
					delete this.stoppedSC;
					if (player.ship.equipmentStatus("EQ_SC_SHIELD_CYCLER_INTERNAL") === "EQUIPMENT_OK")
					{player.consoleMessage("All Shield Cycler functionality re-enabled.",4);}
				}
			}
		if (this.stoppedSEC && worldScripts["shieldequalizercapacitors"].shieldCheckTimer)
			{
				worldScripts["shieldequalizercapacitors"].shieldCheckTimer.start();
				delete this.stoppedSEC;
				if (player.ship.equipmentStatus("EQ_SHIELD_EQUALIZER") === "EQUIPMENT_OK")
				{player.consoleMessage("All Shield Equalizer functionality re-enabled.",4);}
			}
	}
} |