"use strict";
this.name = "black-monk-gunship-AI";

this.aiStarted = function () {
	var ai = new worldScripts["oolite-libPriorityAI"].PriorityAIController(this.ship);
	var ws = worldScripts["blackmonks"];
	ai.setWaypointGenerator(ai.waypointsSpacelanePatrol);
	ai.setPriorities([
		//hurt them plenty, fight them till the bitter end
		{
			condition: ai.conditionInCombat,
			configuration: ai.configurationAcquireCombatTarget,
			behaviour: ai.behaviourDestroyCurrentTarget,
			reconsider: 5
		},
		//look for the player who is late
		{
			condition: function () {
				if (ai.conditionPlayerNearby() && ws.$contract && (clock.seconds > ws.$contract["dealine"])) {
					return true;
				}
				return false;
			},
			behaviour: function () {
				ai.configurationAcquirePlayerAsTarget();
				ship.commsMessage("[monk-threat]");
				ai.behaviourDestroyCurrentTarget();
			},
			reconsider: 5
		},
		{
			preconfiguration: ai.configurationCheckScanner,
			condition: function () {
				function $findDebtor(entity) {
					return entity.$monkDebtor;
				}
				var debtors = system.filteredEntities(this, $findDebtor, ship, 25600);
				if (debtors.length > 0) {
					ai.setParameter("oolite_scanResultSpecific", debtors[0]);
					return true;
				}
				return false;
			},
			behaviour: function () {
				ship.commsMessage("[monk-threat]");
				ai.configurationAcquireScannedTarget();
				ai.behaviourDestroyCurrentTarget();
			},
			reconsider: 20
		},
		//patrol the lanes
		{
			condition: ai.conditionHasWaypoint,
			configuration: ai.configurationSetDestinationToWaypoint,
			behaviour: ai.behaviourApproachDestination,
			reconsider: 30
		},
		{
			configuration: ai.configurationSetWaypoint,
			behaviour: ai.behaviourApproachDestination,
			reconsider: 30
		}
	]);
}
