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

Expansion Missile Beep

Content

Warnings

  1. Information URL mismatch between OXP Manifest and Expansion Manager string length at character position 0

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description Plays beeps whenever a missile is targeted at you Plays beeps whenever a missile is targeted at you
Identifier oolite.oxp.hoqllnq.missile-beep oolite.oxp.hoqllnq.missile-beep
Title Missile Beep Missile Beep
Category Ambience Ambience
Author hoqllnq hoqllnq
Version 1.3 1.3
Tags
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL n/a
Download URL https://wiki.alioth.net/img_auth.php/f/f8/Oolite.oxp.hoqllnq.missile_beep-1.3.oxz n/a
License CC-BY-NC-SA 3.0 CC-BY-NC-SA 3.0
File Size n/a
Upload date 1610873517

Documentation

Also read http://wiki.alioth.net/index.php/Missile%20Beep

README.txt

Missile Beeps
=============
Version 1.3
(C) 2017 cmdr. hoqllnq



* Description:

Plays high pitched beeps while a missile is targeted at the player. Rather than only having a warning when the missile is fired, you now get alerted the entire time a missile is coming for you. The beeps become faster when the distance to the nearest incoming missile gets smaller. 



* Installation: 

Install the OXP by putting the .oxz file in your Oolite Addons folder.



* Instructions:

There are no instructions. 
This OXP does not add buyable equipment. There is no way/need to activate/deactivate/configure it.



* Version History:

1.3 - 27-03-2017
Increase timer frequency (to 2/sec) while incoming missiles are detected.
Added shipAttackedWithMissile event handler to trigger faster.

1.2 - 27-03-2017
Beeps get faster when missile gets closer

1.1 - 26-03-2017
Gets rid of exception (when player has no ship?)

1.0 - 26-03-2017
First working incarnation



* License: CC BY-NC-SA 3.0

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.

Equipment

This expansion declares no equipment. This may be related to warnings.

Ships

This expansion declares no ships. This may be related to warnings.

Models

This expansion declares no models. This may be related to warnings.

Scripts

Path
Scripts/missile_beep.js
// This is the world script for Missile Beep OXP
"use strict";
this.name        = "Missile Beep";
this.description = "Missile Beep World Script";
this.version     = "1.3";
this.author      = "hoqllnq";
this.copyright   = "2017 hoqllnq";
this.licence     = "CC-BY-NC-SA 3.0";

this._timer = null;			// To periodically check for incoming missiles
this._fcb = null;			// To time the beeps
this._sound_source = null;	// To play the beeps
this._beep_time = 0;		// How long beep (or silence) has been playing
this._beep_interval = 0;	// How long beep (or silence) should last
this._beep_on = false;		// Currently beeping?

this._debug = false;		// Logging


// Initialize the timer and the sound source
this.startUp = function()
{
	if (!this._timer)
	{
		this._timer = new Timer(this, this._timer_hook.bind(this),1,1);
	}
	
	if (!this._sound_source)
	{
		this._sound_source = new SoundSource();
		this._sound_source.loop = false;
		this._sound_source.sound = "[missile_beep]";
	}
	
	if (this._debug)
		log(this.name,"Started");
}

// A missile was fired at us, it could be the nearest one,
// don't wait for timer to fire, call timer hook now to check
this.shipAttackedWithMissile = function(missile,whom)
{
	if (this._debug)
		log(this.name,"Missile fired");
	
	this._timer_hook();
}

// Periodic check for presence and distance of incoming missiles
this._timer_hook = function()
{
	var things;
	var dist;
 
	if (player && player.ship)
	{	// Find all missiles in scanner range
		things = system.entitiesWithScanClass("CLASS_MISSILE",player.ship,25600);
		
		// See if any of them are targeted at us
		for (var i = 0;i < things.length;i++)
		{
			if (things[i].target == player.ship)
			{	// Yes.
				// This is the nearest one, since the list is ordered by distance
				dist = things[i].position.distanceTo(player.ship.position);
				if (this._debug)
					log(this.name,"Missile at " + dist);
				
				// Beep duration based on distance
				this._beep_interval = 0.05 + dist / 51200.0;
				
				// If we weren't beeping yet, start now
				if(!isValidFrameCallback(this._fcb))
				{
					this._fcb = addFrameCallback(this._fcb_hook.bind(this));
					this._timer.interval = 0.5;
				}
				
				return;
			}
		}
	}
	
	// No incoming missiles
	// If we were beeping, stop now.
	if (isValidFrameCallback(this._fcb))
	{
		if (this._debug)
			log(this.name,"No more incoming missiles");
		
		removeFrameCallback(this._fcb);
		this._timer.interval = 1.0;
	}
	
	if (this._sound_source.isPlaying)
		this._sound_source.stop();
	
	this._beep_time = 0;
	this._beep_on = false;
}

// Frame callback to turn beep on/off
// This does the timing for the beeping speed
this._fcb_hook = function(delta)
{
	this._beep_time += delta;
	
	// Time for next beep/silence?
	if (this._beep_time < this._beep_interval)
		return; // No.
	
	// Reset time
	this._beep_time -= this._beep_interval;
	
	// Toggle beep
	if (this._beep_on)
	{
		if (this._sound_source.isPlaying)
			this._sound_source.stop();
		
		this._beep_on = false;
	}
	else
	{
		if (this._debug)
			log(this.name,"Beep!");
		
		if (!this._sound_source.isPlaying)
			this._sound_source.play();
		
		this._beep_on = true;
	}
}