"use strict";
this.name = "coyoteViperLeader";
this.author = "Okti";
this.copyright = "(C) Okti";
this.licence = "Creative Commons Attribution - Non-Commercial - Share Alike 3.0";
this.description = "Ship script for coyoteViperLeader.";

this.shipSpawned = function () {
	//this.ship.reportAIMessages = true;
	this.firstMessage = false;
	this.firstMessage1 = false;
	this.messageCount = 0;
}

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 == false) {
				this.ship.commsMessage(expandDescription("[COYOTE_S280_02]"), player.ship);
				this.firstMessage = true;
			}
		}
		if (this.ship.position.distanceTo(player.ship.position) < 1000) {
			if (player.ship.speed !== 0) {
				this.ship.reactToAIMessage("PLAYER_NOT_STOPED");
				return;
			}
		}
		if (this.ship.position.distanceTo(player.ship.position) < 200) {
			this.ship.reactToAIMessage("DESIRED_RANGE_ACHIEVED");
		} else {
			this.ship.reactToAIMessage("PLAYER_FOUND");
		}
	}
}

this.checkPlayer = function () {
	if (this.messageCount > 30) {
		if (system.ID !== 20) {
			this.ship.commsMessage(expandDescription("[COYOTE_S280_04]"), player.ship);
			this.ship.reactToAIMessage("INSPECTION_FINISHED");
			missionVariables.Coyote_status = "STAGE_290"
		} else {
			this.ship.commsMessage(expandDescription("[COYOTE_S280_04]"), player.ship);
			missionVariables.Coyote_status = "STAGE_340"
			worldScripts["Coyote-Main"].setMissionInstructions("CE_MI_S_310_09");
			this.ship.reactToAIMessage("INSPECTION_FINISHED");
		}
	} else {
		this.messageCount += 1;
		if (player.ship.speed == 0) {
			if (this.firstMessage1 == false) {
				this.ship.commsMessage(expandDescription("[COYOTE_S280_03]"), player.ship);
				this.firstMessage1 = true;
			}
			this.ship.reactToAIMessage("PLAYER_STOPPED");
		} else {
			this.ship.reactToAIMessage("PLAYER_NOT_STOPPED");
		}
	}
}