| Scripts/Breakable_TorusDrive.js | this.name        = "Breakable_TorusDrive"; 
this.author      = "capt murphy"; 
this.copyright   = "2011 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 Torus Drive."; 
this.version     = "1.1";
// event handler driven function for functions at startup - awards equipment to existing ship if first run with OXP.
this.startUp = function()
{
	if (!missionVariables.btd_status)
	{
		missionVariables.btd_status = "OK";
	}
	this.btd_status = missionVariables.btd_status;
	if (player.ship.equipmentStatus("EQ_BREAKABLE_TORUSDRIVE") != "EQUIPMENT_OK" && this.btd_status == "OK")
	{
		player.ship.awardEquipment("EQ_BREAKABLE_TORUSDRIVE");	
	}
		
}
// event handler driven function to fit equipment to newly purchased ship.
this.playerBoughtNewShip = function()
{
		player.ship.awardEquipment("EQ_BREAKABLE_TORUSDRIVE");
		this.btd_status = "OK";
}
// event handler driven function to control actions if equipment damaged in combat.
this.equipmentDamaged = this.equipmentDestroyed = function(equipment)
{
	if (this.shipRestore && equipment === "EQ_BREAKABLE_TORUSDRIVE") {this.btd_status = "DAMAGED"; return;}
	if (equipment == "EQ_BREAKABLE_TORUSDRIVE")
	{
		this.btd_status = "DAMAGED";
		player.consoleMessage("Torus Drive Damaged!",3);
		this.btd_setupTimer();
	}
}
// event handler driven function for actions on save game.
this.playerWillSaveGame = function()
{
	missionVariables.btd_status = this.btd_status;
}
// event handler driven function for actions on launching.
this.shipLaunchedFromStation = this.shipExitedWitchspace = function()
{
	if (player.ship.equipmentStatus("EQ_BREAKABLE_TORUSDRIVE") == "EQUIPMENT_OK" && this.btd_status != "OK")
	{
		this.btd_status = "OK";
		this.btd_stopTimer();
		return;
	}
	if (this.btd_status != "OK")
	{
		this.btd_setupTimer();
	}
}
// creates timers if not already in existance otherwise restarts existing timers.
this.btd_setupTimer = function()
{
	if (!this.btd_updateTimer)
		{
			this.btd_updateTimer = new Timer(this, this.btd_speedcheck, 0, 3);
		}
		else
		{
			this.btd_updateTimer.start();
		}
}
// called by timer every 3 seconds.
this.btd_speedcheck = function()
{	
	if (player.ship.equipmentStatus("EQ_BREAKABLE_TORUSDRIVE") == "EQUIPMENT_OK" && this.btd_status != "OK") // check to see if something has repaired the witch drive on the fly e.g. Thargoid's Repair Bots OXP.
	{
		this.btd_status = "OK";
		this.btd_stopTimer();
		return;
	}
	if (player.ship.speed > (player.ship.maxSpeed * 10) && Math.random () < 0.5)
	{
		system.addShips("btd_dummy_entity", 1, player.ship.position);
		var delay = (Math.random()*10)+5;
		this.btd_removedummyTimer = new Timer(this,this.btd_removedummy,delay);
		player.consoleMessage("Torus Drive Malfunction - Repairs needed!",4);
	}
}
// called by timer to remove dummy masslocking entity after random delay.
this.btd_removedummy = function ()
{
		function btd_finddummy(entity)
	{
		return (entity.primaryRole == "btd_dummy_entity");
	}
	var targets = system.filteredEntities(this, btd_finddummy);
	if (targets.length > 0)
	{
		let counter = 0;
		for (counter = 0; counter < targets.length;counter++)
			{
				targets[counter].remove(true);
			}
	}
}
 
// event handler driven function to stop Timers on player's death or on docking.
this.shipDied = this.shipWillDockWithStation = this.btd_stopTimer = function()
{
	if (this.btd_updateTimer && this.btd_updateTimer.isRunning)
		{
			this.btd_updateTimer.stop();
			delete this.btd_updateTimer;
		}
} | 
                
                    | Scripts/btd_dummy_entity.js | this.name        = "btd_dummy_entity"; 
this.author      = "capt murphy"; 
this.copyright   = "2011 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 = "Breakable Torus Drive Dummy Entity Shipscript"; 
this.version     = "1.0";
this.shipSpawned = function()
{
	 this.ship.bounty = 0;
     this.ship.scannerDisplayColor1 = "clearColor";
	 this.ship.scannerDisplayColor2 = "clearColor";
	 this.btd_dummyentitycontrolTimer = new Timer (this, this.btd_dummyentitycontrol,0,1);
}
this.btd_dummyentitycontrol = function()
{
	this.ship.position = player.ship.position.add(player.ship.vectorUp.multiply(300));
}
this.playerWillEnterWitchspace = this.shipRemoved = this.entityDestroyed = function()
{
  if (this.btd_dummyentitycontrolTimer && this.btd_dummyentitycontrolTimer.isRunning)
  {
	this.btd_dummyentitycontrolTimer.stop();
	delete this.btd_dummyentitycontrolTimer;
  }
}
 |