"use strict";
this.name = "coyoteCuervo";
this.author = "Captain Okti";
this.copyright = "(C) 2011 Oktay Sarioglu";
this.licence = "Creative Commons Attribution - Non-Commercial - Share Alike 3.0";
this.description = "Script for coyoteCuervo.";

this.shipSpawned = function () {
	//this.ship.reportAIMessages = true;
	this.firstMessage = false;
	this.ship.fuel = 7.0;
}


this.fMessage = function () {
	this.ship.commsMessage(expandDescription("[COYOTE_S225_14]"), player.ship);
	this.ship.reactToAIMessage("LOOKFOR_TARGET");
}

this.locatePlayer = function () {
	this.playerArray = system.shipsWithPrimaryRole("player");
	if (this.playerArray.length == 0) {
		this.ship.remove();
	} else {
		this.ship.target = this.playerArray[0];
		if (this.ship.position.distanceTo(player.ship.position) < 25000) {
			if (!this.firstMessage) {
				mission.setInstructionsKey("CE_MI_S_225_07", "Coyote-Main");
			}
		}
		if (this.ship.position.distanceTo(player.ship.position) < 3000) {
			this.ship.reactToAIMessage("DESIRED_RANGE_ACHIEVED");
		} else {
			this.ship.reactToAIMessage("PLAYER_FOUND");
		}
	}
}

this.scanFor200 = function () {
	this.shArray = system.shipsWithPrimaryRole("coyotepython230");
	if (this.shArray.length == 0) {
		this.ship.reactToAIMessage("NOTHING_FOUND");
	} else {
		if (this.ship.position.distanceTo(this.shArray[0].position) < 25000) {
			this.ship.target = this.shArray[0];
			this.ship.reactToAIMessage("TARGET_FOUND");
		} else {
			this.ship.reactToAIMessage("TARGET_FAR");
		}
	}
}

this.scanFor200E = function () {
	this.shArray = system.shipsWithRole("coyotepirateescort2");
	if (this.shArray.length == 0) {
		this.ship.reactToAIMessage("NOTHING_FOUND");
	} else {
		if (this.ship.position.distanceTo(this.shArray[0].position) < 25000) {
			this.ship.target = this.shArray[0];
			this.ship.reactToAIMessage("TARGET_FOUND");
		} else {
			this.ship.reactToAIMessage("TARGET_FAR");
		}
	}
}

this.scanFor201 = function () {
	this.shArray = system.shipsWithPrimaryRole("coyoteferdie230");
	if (this.shArray.length == 0) {
		this.ship.reactToAIMessage("NOTHING_FOUND");
	} else {
		if (this.ship.position.distanceTo(this.shArray[0].position) < 25000) {
			this.ship.target = this.shArray[0];
			this.ship.reactToAIMessage("TARGET_FOUND");
		} else {
			this.ship.reactToAIMessage("TARGET_FAR");
		}
	}
}

this.scanFor202 = function () {
	this.shArray = system.shipsWithPrimaryRole("coyoteasp230");
	if (this.shArray.length == 0) {
		this.ship.reactToAIMessage("NOTHING_FOUND");
	} else {
		if (this.ship.position.distanceTo(this.shArray[0].position) < 25000) {
			this.ship.target = this.shArray[0];
			this.ship.reactToAIMessage("TARGET_FOUND");
		} else {
			this.ship.reactToAIMessage("TARGET_FAR");
		}
	}
}

this.informPlayer = function () {
	this.ship.commsMessage(expandDescription("[COYOTE_S225_16]"), player.ship);
	this.shArray = system.shipsWithPrimaryRole("coyotesahana2");
	if (this.shArray.length !== 0) {
		this.shArray[0].reactToAIMessage("HEAD_FOR_PLANET");
	}
	mission.setInstructionsKey("CE_MI_S_225_08", "Coyote-Main");
}