| Scripts/as_script.js | "use strict"
this.name = "Auto S.O.S.";
this.author = "Reval";
this.license = "CC-BY-NC-SA 4.0";
this.version = "1.1";
this.description = "This simple transponder will automatically broadcast an S.O.S. distress signal when your ship comes under direct attack or Red Alert condition - and... 'S.O.S.' does mean *help*, doesn't it?";
this.startUp = function() {
	this.$asConds = ["DOCKED","GREEN","YELLOW","RED"];
	this.$asTesting = false;
	this.$asHasEQ = false;
	this.$asMaxHens = 8;
	this.$asHens = 0;
	this.$asAttackMsg = "Under attack. Under attack.";
	this.$asAlertMsg = "RED alert. RED alert. RED alert.";
}
this.shipWillLaunchFromStation = function() {
	var ps = player.ship;
	this.$asHasEQ = (ps.equipmentStatus ("EQ_AUTO_SOS") === "EQUIPMENT_OK");
	this.$asHens = 0;
}
this.playerBoughtEquipment = function(equipment, paid) {
	var pc = player.consoleMessage;
	if (equipment == "EQ_AUTO_SOS") 
		pc("Auto S.O.S. installed and monitoring.",9);
}
this.shipBeingAttacked = function(whom) {
	if (this.$asHasEQ) { 
		if (this.$asHens<this.$asMaxHens) {
			var hen = system.addShips("police", 1, whom.position);
			this.$asHens++;
		}
		this._asDistress(this.$asAttackMsg);
	}
}
this.shipAttackedWithMissile = function(missile, whom) {
	if (this.$asHasEQ) {
		if (this.$asHens<this.$asMaxHens) {
			var hen = system.addShips("police", 1, whom.position);
			this.$asHens++;
		}
		this._asDistress(this.$asAttackMsg);
	}
}
this.alertConditionChanged = function(newCondition, oldCondition) {
	if (this.$asHasEQ) {	
		var ps = player.ship;
		var psa = newCondition;
		var pc  = player.consoleMessage;
		// TEST
		if (this.$asTesting) this._asDoCond(psa);
		// condition Red - send SOS
		if (psa==3)  {
			if (this.$asHens<this.$asMaxHens) {
				var hens = system.addShips("interceptor", 3, ps.position);
				this.$asHens+=3;
			}
			this._asDistress(this.$asAlertMsg);
		} else this.$asHens=0;
	}
}
// report condition status
this._asDoCond = function(cond) {
	var ps = player.ship;
	var pc  = player.consoleMessage;
	var c = ps.messageGuiTextColor;
	if (cond==0) ps.messageGuiTextColor = "blueColor"; else
	if (cond==1) ps.messageGuiTextColor = "greenColor"; else
	if (cond==2) ps.messageGuiTextColor = "yellowColor"; else
	if (cond==3) ps.messageGuiTextColor = "redColor";
	pc("Condition "+this.$asConds[cond],3);
	ps.messageGuiTextColor = c;
}
// put out the distress call
this._asDistress = function(msg) {
	var ps = player.ship;
	var pc = player.consoleMessage;
	var c = ps.messageGuiTextColor;
	ps.messageGuiTextColor = "redColor";
	pc(msg,9);
	ps.broadcastDistressMessage();	
	pc("Transmitting S.O.S.",9);
	ps.messageGuiTextColor = c;
}	
 |