from unity import *

from System.Collections.Generic import Stack

import ComponentUtil
import SteeringControl
import Craft

from Patrol import Patrol
from Evade import Evade
from AvoidCollision import AvoidCollision

from BaseAIController import BaseAIController

class AIController(BaseAIController):
	def __init__(self):
		super(AIController, self).__init__()

	def Start(self):
		self.craft = ComponentUtil.findInLineage[Craft](self.gameObject)
		self.craft.damageEvent += self.tookSomeDamage
		self.craft.proximityEvent += self.proximityAlert

	def Update(self):
		if self.currentAction != None:
			self.currentAction.step()
		else:
			self.push(Patrol())

	def proximityAlert(self, otherGameObject):
		away = self.gameObject.transform.position - otherGameObject.transform.position
		self.push(AvoidCollision(away))

	def tookSomeDamage(self, damageEvent):
		self.push(Evade())

