Back to Index Page generated: Nov 12, 2024, 11:02:03 PM

Expansion Breakable Energy Unit

Content

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description This OXP make the ships core energy unit an equipment item that can be damaged in combat. This OXP make the ships core energy unit an equipment item that can be damaged in combat.
Identifier oolite.oxp.CaptMurphy.BreakableEnergyUnit oolite.oxp.CaptMurphy.BreakableEnergyUnit
Title Breakable Energy Unit Breakable Energy Unit
Category Equipment Equipment
Author Capt Murphy Capt Murphy
Version 1.1 1.1
Tags Equipment Equipment
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL http://wiki.alioth.net/index.php/Breakable_%27Standard%27_Equipment_OXPs n/a
Download URL https://wiki.alioth.net/img_auth.php/b/b7/Oolite.oxp.CaptMurphy.BreakableEnergyUnit.oxz n/a
License CC BY-NC-SA 3.0 CC BY-NC-SA 3.0
File Size n/a
Upload date 1610873451

Documentation

Also read http://wiki.alioth.net/index.php/Breakable%20Energy%20Unit

readme.rtf

{\rtf1\ansi\ansicpg1252\deff0\deflang2057\deflangfe2057{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}}
{\colortbl ;\red0\green0\blue255;}
{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\nowidctlpar\f0\fs20 Breakable Energy Unit Version 1.1 (05/05/12)\par
By Capt Murphy 2012\par
Licence: CC BY-NC-SA 3.0 : Please visit {\field{\*\fldinst{HYPERLINK "http://creativecommons.org/licenses/by-nc-sa/3.0/"}}{\fldrslt{\ul\cf1 http://creativecommons.org/licenses/by-nc-sa/3.0/}}}\f0\fs20  for more info.\par
Requires Oolite 1.76\par
\par
Overview: \par
\par
An OXP intended for the experienced Commander who wishes to make their Oolife a little more difficult. This OXP make the ships core energy unit an equipment item that can be damaged in combat. This unit is installed in the heart of the ship, and is well protected so chances of damage are reduced when compared to other equipment items.\par
\par
However if damaged the ships energy banks will remain at minimum level until repaired. This prevents the player using lasers, and prevents shields from recharging. Auxiliary emergency systems allow the ships engines and drives (if working) and the ships computer to continue to operate.\par
\par
Repairs can be conducted at a station of any tech level. Costs vary between 375 credits and 1500 credits depending on the size of the ship's energy banks. The equipment can also be repaired by OXP repair technology such as Thargoid\rquote s Repair Bots.\par
\par
Technical:\par
\par
This OXP creates a new equipment item \ldblquote Core Energy Unit\rdblquote  which is listed on the equipment manifest and can be damaged in combat. It automatically fits the equipment to the current ship on first run, and it is also automatically fitted when the player purchases a new ship. The equipment can't be damaged when there is a working Naval Energy Unit or Extra Energy unit installed (but these items may be damaged instead). Even if these items are damaged, the chance of the Core Energy Unit being damaged is reduced compared with other equipment items.\par
\par
ChangeLog: \par
\par
Version 1  \tab 22/4/12 \endash  Initial release.\par
Version 1.1       05/5/12 - Minor update for compatibility with Ship_Storage_Helper.oxp\par
\par
Tested and built using Oolite 1.76\par
}

Equipment

Name Visible Cost [deci-credits] Tech-Level
Core Energy Unit yes 30000 1+
Core Energy Unit yes 15000 1+
Core Energy Unit yes 7500 1+

Ships

This expansion declares no ships.

Models

This expansion declares no models.

Scripts

Path
Scripts/Breakable_Energy_Unit.js
this.name        = "Breakable_Energy_Unit"; 
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 standard energy unit"; 
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()
{
	this.warning = new SoundSource;
	this.warning.sound = "warning.ogg";
	this.getUnitSize();
	if (player.ship.equipmentStatus(this.energyUnitEQ) === "EQUIPMENT_UNAVAILABLE"){missionVariables.beu_status = this.energyUnitEQ; player.ship.awardEquipment(this.energyUnitEQ); missionVariables.beu_status = "OK"}
}
// choses which variant of equipment to install bases on ships maxEnergy. Repair price varies between variants.
this.getUnitSize = function()
{
	if (player.ship.maxEnergy < 256){this.energyUnitEQ = "EQ_BREAKABLE_ENERGY_UNIT_SMALL";}
	else if (player.ship.maxEnergy < 384){this.energyUnitEQ = "EQ_BREAKABLE_ENERGY_UNIT_MEDIUM";}
	else {this.energyUnitEQ = "EQ_BREAKABLE_ENERGY_UNIT_LARGE";}
}
	
// event handler driven function to fit equipment to newly purchased ship.
this.playerBoughtNewShip = function()
{
	this.getUnitSize();
	missionVariables.beu_status = this.energyUnitEQ;
	player.ship.awardEquipment(this.energyUnitEQ);
	missionVariables.beu_status = "OK";
}

// event handler driven function to control actions if equipment damaged in combat.
this.equipmentDamaged = this.equipmentDestroyed = function(equipment)
{
	if (this.shipRestore && equipment === this.energyUnitEQ) {missionVariables.beu_status = this.energyUnitEQ; return;}
	if ((equipment === this.energyUnitEQ) && (player.ship.equipmentStatus("EQ_NAVAL_ENERGY_UNIT") === "EQUIPMENT_OK" || player.ship.equipmentStatus("EQ_ENERGY_UNIT") === "EQUIPMENT_OK"))
	{
	player.ship.setEquipmentStatus(equipment,"EQUIPMENT_OK");
	if (player.ship.equipmentStatus("EQ_NAVAL_ENERGY_UNIT") === "EQUIPMENT_OK")
		{
			player.ship.setEquipmentStatus("EQ_NAVAL_ENERGY_UNIT","EQUIPMENT_DAMAGED");
		    player.consoleMessage ("Naval Energy Unit is damaged!", 2);
			return;
		}
	else
		{ 
			player.ship.setEquipmentStatus("EQ_ENERGY_UNIT","EQUIPMENT_DAMAGED");
			player.consoleMessage ("Extra Energy Unit is damaged!", 2);  
			return;
		}
	}
	if (equipment === this.energyUnitEQ)
	{
		var EQarray = player.ship.equipment;
		var EQdamaged = new Array;
		var counter;
		for(counter = 0; counter < EQarray.length; counter++)
		{
			if (player.ship.equipmentStatus(EQarray[counter])==="EQUIPMENT_DAMAGED")
			{EQdamaged.push(EQarray[counter]);EQarray.splice(counter,1);counter--;continue;}
			if (!EQarray[counter].isVisible || EQarray[counter] === equipment || !EQarray[counter].canBeDamaged)
			{EQarray.splice(counter,1);counter--;}
		}
		if (EQdamaged.length < 6 || Math.random() > 0.167) // reduced chance of equipment damage.
		{
			if (EQarray.length > 0) // damage an alternative equipment item if available.
			{
				var index = Math.floor(Math.random() * EQarray.length);
				player.ship.setEquipmentStatus(EQarray[index],"EQUIPMENT_DAMAGED");
				this.damagedEQ = EQarray[index];
				this.delayTimer = new Timer (this, this.delayMessage,0.25);
			}
			player.ship.setEquipmentStatus(equipment,"EQUIPMENT_OK");
			return;
		}
		missionVariables.beu_status = this.energyUnitEQ; // set status to equipment name so repair option will show.
		this.setupTimerFB();
	}
}

this.delayMessage = function()
{
 if (this.damagedEQ && player.ship.equipmentStatus(this.damagedEQ) === "EQUIPMENT_DAMAGED")
 {player.consoleMessage(this.damagedEQ.name + " damaged!"); delete this.damagedEQ;}
}
		
// event handler driven function for actions on launching and exiting witchspace.
this.shipLaunchedFromStation = this.shipExitedWitchspace = function()
{
	if (player.ship.equipmentStatus(this.energyUnitEQ) === "EQUIPMENT_OK" && missionVariables.beu_status !== "OK")
	{
		this.reset();	
	}
	if (missionVariables.beu_status !== "OK")
	{
		this.setupTimerFB();
	}
}

// event handler driven function to stop timers on docking or player death.
this.shipWillDockWithStation = this.shipDied = function()
{
	if (this.updateCallback)
		{
			removeFrameCallback(this.updateCallback);
			delete this.updateCallback;
		}
	if (this.warningTimer && this.warningTimer.isRunning)
		{
			this.warningTimer.stop();
			delete this.warningTimer;
		}
}

// creates timers if not already in existance otherwise restarts existing timers.
this.setupTimerFB = function()
{
	if (!this.updateCallback)
		{
			this.updateCallback = addFrameCallback(this.updateEnergy.bind(this));
		}
	if (!this.warningTimer)
		{
			this.warningTimer = new Timer(this,this.warningSound,0,10);
		}
		else
		{
			this.warningTimer.start();
		}
}

this.updateEnergy = function()
{	
	if (player.ship.equipmentStatus(this.energyUnitEQ) === "EQUIPMENT_OK" && missionVariables.beu_status !== "OK") 
	{
		this.reset();
		return;
	}
	if (missionVariables.beu_status !== "OK")
	{
		player.ship.energy = 0.1;
	}
}
	

// called by timer every 10 seconds when player in flight to give warning noise while equipment is damaged.
this.warningSound = function()
{
	this.warning.play(1);
	player.consoleMessage("Core Energy Unit Damaged!", 2);
}

// function to reset equipment once fixes
this.reset = function()
{
	if (player.ship.equipmentStatus(this.energyUnitEQ) === "EQUIPMENT_OK" && missionVariables.beu_status !== "OK")
	{
		missionVariables.beu_status = "OK";
		if (this.updateCallback)
			{
				removeFrameCallback(this.updateCallback);
				delete this.updateCallback;
			}
		if (this.warningTimer && this.warningTimer.isRunning)
			{
				this.warningTimer.stop();
				delete this.warningTimer;
			}
	}
}