from unity import *

from System.Collections.Generic import Stack

import ComponentUtil
import SteeringControl

class BaseAIController(object):
	def __init__(self):
		self.currentAction = None
		self.steeringStack = Stack[SteeringControl]()

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

	def push(self, steering):
		if self.currentAction != None:
			if self.currentAction.name == steering.name or steering.priority < self.currentAction.priority:
				return False
			self.steeringStack.Push(self.currentAction)

			# Debug.LogError("New Action.. %s  --> %s " % (steering.name, self.currentAction.name))
		steering.controller = self
		steering.gameObject = self.gameObject
		self.currentAction = steering
		return True

	def pop(self, expected):
		if self.currentAction != None and self.currentAction.name == expected.name:
			if self.steeringStack.Count:
				self.currentAction = self.steeringStack.Peek()
				self.steeringStack.Pop()
			# else:
				# self.push(Patrol())
			return True
		return False

	def popIfActive(self, expected):
		return self.pop(expected)

