public void LoadActionPlanStep(string actionName, OCAction.OCActionArgs arguments)
            {
                TreeType         treeType       = _ActionNameDictionary[actionName];
                Tree             tree           = _TreeTypeDictionary[treeType];
                OCActionPlanStep actionPlanStep = new OCActionPlanStep();

                actionPlanStep.Behaviour = tree;
                actionPlanStep.Arguments = arguments;
                _ActionPlanQueue.Enqueue(actionPlanStep);
                Debug.Log("Enqueued Action Step: " + actionPlanStep.Arguments.ActionName);
            }
示例#2
0
            // TODO: Implement / remove move to location function which can be called by OCConnector.ParseSingleActionElement.
            public void MoveToCoordinate(Vector3 desiredLocation)
            {
                OCAction.OCActionArgs args = new OCAction.OCActionArgs();
                args.Source      = _defaultSource;
                args.StartTarget = _defaultStartTarget;
                args.EndTarget   = _defaultEndTarget;

                args.StartTarget.transform.position = args.Source.transform.position;
                args.EndTarget.transform.position   = desiredLocation;

                LoadActionPlanStep("MoveToCoordinate", args);
            }
示例#3
0
            //---------------------------------------------------------------------------

            #endregion

            //---------------------------------------------------------------------------

            #region Private Member Functions

            //---------------------------------------------------------------------------

//	private BehaveResult DefaultActionTickHandler (OCAction action)
//	{
//		Vector3 robotPos = gameObject.transform.position;
//		Vector3 distanceVec = ((Vector3)TargetBlockPos) - robotPos;
//
//		if (action == null)
//			return BehaveResult.Failure;
//
//		if (action.ShouldTerminate ()) {
//			//action.Terminate();
//			//Debug.Log ("In OCRobotAgent.DefaultActionTickHandler, " + action.GetType () + " Failure");
//			return BehaveResult.Failure;
//		}
//
//		if (action.IsExecuting ()) {
//			//Debug.Log("In OCRobotAgent.DefaultActionTickHandler, " + action.GetType() + " Running");
//			return BehaveResult.Running;
//		}
//
//		if (TargetBlockPos != Vector3i.zero) {
//			//Debug.Log("In OCRobotAgent.DefaultActionTickHandler, Distance to TNT block is: " + distanceVec.magnitude + ", Vector is: " + distanceVec);
//		}
//
//		return BehaveResult.Success;
//	}

            //---------------------------------------------------------------------------

            #endregion

            //---------------------------------------------------------------------------

            #region Other Members

            //---------------------------------------------------------------------------



            // TODO: This cose is just a set of stubs to get rid of an error.
            //public static event ActionCompleteHandler globalActionCompleteEvent;
            //public delegate void ActionCompleteHandler(OCAction action);
            // Removed...due to the fact that OCConnector will be polling this class for action status updates.

            // TODO: Implement / remove build block function which can be called by OCConnector.ParseSingleActionElement. Will probably have to be amended with material / blockdata.
            public void BuildBlockAtPosition(Vector3i desiredBlockLocation)
            {
                OCAction.OCActionArgs args = new OCAction.OCActionArgs();
                args.Source      = _defaultSource;
                args.StartTarget = _defaultStartTarget;
                args.EndTarget   = _defaultEndTarget;

                args.StartTarget.transform.position = args.Source.transform.position;
                args.EndTarget.transform.position   = desiredBlockLocation;

                LoadActionPlanStep("BuildBlockAtPosition", args);
            }
示例#4
0
            public void LoadActionPlanStep(string actionName, OCAction.OCActionArgs arguments)
            {
                Debug.Log("OCActionController::LoadActionPlanStep: " + actionName);
                TreeType         treeType       = _ActionNameDictionary[actionName];
                Tree             tree           = _TreeTypeDictionary[treeType];
                OCActionPlanStep actionPlanStep = OCScriptableObject.CreateInstance <OCActionPlanStep>();

                actionPlanStep.Behaviour = tree;
                actionPlanStep.Arguments = arguments;
                _ActionPlanQueue.AddLast(actionPlanStep);
                Debug.Log("Enqueued Action Step: " + actionPlanStep.Arguments.ActionName);
            }
示例#5
0
            public void LoadActionPlanStep(string actionName, OCAction.OCActionArgs arguments)
            {
                //Debug.Log("OCActionController::LoadActionPlanStep: " + actionName);
                TreeType         treeType       = _ActionNameDictionary[actionName];
                Tree             tree           = _TreeTypeDictionary[treeType];
                OCActionPlanStep actionPlanStep = OCScriptableObject.CreateInstance <OCActionPlanStep>();

                actionPlanStep.Behaviour = tree;
                actionPlanStep.Arguments = arguments;
                _ActionPlanQueue.AddLast(actionPlanStep);
                System.Console.WriteLine(OCLogSymbol.DETAILEDINFO + "Enqueued Action Step: " + actionPlanStep.Arguments.ActionName);
            }
	/**
	 * Parse action plan and append the result into action list.
	 *
	 * @param element meta action in xml format
	 */
	private void ParseActionPlanElement(XmlElement actionPlan)
	{
		// TODO: Determine if we need this:
		bool adjustCoordinate = false;
		
		OpenCog.Utility.Console.Console console = OpenCog.Utility.Console.Console.Instance;
		
		// Get the action performer id.
		string avatarId = actionPlan.GetAttribute(OCEmbodimentXMLTags.ENTITY_ID_ATTRIBUTE);
		if(avatarId != _brainID)
		{
			// Usually this would not happen.
			OCLogger.Warn("Avatar[" + _ID + "]: This action plan is not for me.");
			return;
		}
		
		// Cancel current action and clear old action plan in the list.
		if(_actionsList.Count > 0)
		{
			OCLogger.Warn("Stop all current actions");
			CancelAvatarActions();
		}
		
		GameObject endPointStub = GameObject.Find("EndPointStub");

		// Update current plan id and selected demand name.
		_currentPlanId = actionPlan.GetAttribute(OCEmbodimentXMLTags.ID_ATTRIBUTE);
		_currentDemandName = actionPlan.GetAttribute(OCEmbodimentXMLTags.DEMAND_ATTRIBUTE);
        
		// Get the action elements from the actionPlan
		XmlNodeList list = actionPlan.GetElementsByTagName(OCEmbodimentXMLTags.ACTION_ELEMENT);

		if(_actionController == null)
		{
			_actionController = GameObject.FindGameObjectWithTag("OCAGI").GetComponent<OCActionController>();
		}

		// list contains 'action' elements.
		foreach(XmlNode actionNode in list)
		{
			// Cast actionNode to actionElement (XmlElement)
			XmlElement actionElement = (XmlElement)actionNode;
			
			// Get attributes from actionElement (name, sequence)
			string actionName = actionElement.GetAttribute(OCEmbodimentXMLTags.NAME_ATTRIBUTE);
			int sequence = System.Int32.Parse(actionElement.GetAttribute(OCEmbodimentXMLTags.SEQUENCE_ATTRIBUTE));
			
			// Get the actionParameter nodes from the actionElement
			XmlNodeList actionParameters = actionElement.GetElementsByTagName(OCEmbodimentXMLTags.PARAMETER_ELEMENT);
			
			// Prepare a new actionArgs object
			OCAction.OCActionArgs actionArguments = new OCAction.OCActionArgs();
			
			actionArguments.StartTarget = GameObject.Find("StartPointStub");
			actionArguments.StartTarget.transform.position = GameObject.FindGameObjectWithTag("OCAGI").transform.position;		
			actionArguments.EndTarget = null;
			
			// 'action' elements contain 'params'
			foreach(XmlNode actionParameterNode in actionParameters)
			{
				// Cast actionParameterNode to an actionParameterElement (XmlElement)
				XmlElement actionParameterElement = (XmlElement)actionParameterNode;
				
				// Get attributes from actionParameterElement
				string actionParameterType = actionParameterElement.GetAttribute(OCEmbodimentXMLTags.TYPE_ATTRIBUTE);	
				
				switch(actionParameterType)
				{
				// If it's a vector, then it's a walk. So the target is a gameobject at the location of the vector.
				case "vector":


					XmlNodeList vectorParameterChildren = actionParameterElement.GetElementsByTagName(OCEmbodimentXMLTags.VECTOR_ELEMENT);
					XmlElement vectorElement = (XmlElement)vectorParameterChildren.Item(0);
						
					float x = float.Parse(vectorElement.GetAttribute(OCEmbodimentXMLTags.X_ATTRIBUTE), System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
					float y = float.Parse(vectorElement.GetAttribute(OCEmbodimentXMLTags.Y_ATTRIBUTE), System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
					float z = float.Parse(vectorElement.GetAttribute(OCEmbodimentXMLTags.Z_ATTRIBUTE), System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
					
//						if (adjustCoordinate)
//						{
//							x += 0.5f;
//							y += 0.5f;
//							z += 0.5f;
//						}
					
					string gameObjectString = "PLAN" + _currentPlanId.ToString().PadLeft(3, '0') + "_SEQ" + sequence.ToString().PadLeft(3, '0') + "_VECTOR";
							
					UnityEngine.GameObject vectorGameObject = (UnityEngine.GameObject)UnityEngine.GameObject.Instantiate(_map.WaypointPrefab);
					vectorGameObject.name = gameObjectString;
					vectorGameObject.transform.parent = _map.WaypointsSceneObject.transform;
					
						// Swapping Y and Z!!
					
						// ORIGINAL:
						// vectorGameObject.transform.position = new Vector3(x, y, z);
						// UnityEngine.Debug.Log ("A '" + actionName + "' command told me to go to [" + x + ", " + y + ", " + z + "]");
					
						// SWAPPED:
					vectorGameObject.transform.position = new Vector3(x, z, y);
					TextMesh textMesh = vectorGameObject.GetComponentInChildren<TextMesh>();
					textMesh.text = sequence.ToString();
						//UnityEngine.Debug.Log ("A '" + actionName + "' command (planID = " +  _currentPlanId + ", sequence = " + sequence + " told me to go to [" + x + ", " + z + ", " + y + "]");

					if(actionName == "walk" || actionName == "jump_toward")
					{

						console.AddConsoleEntry("A '" + actionName + "' command (planID = " + _currentPlanId + ", sequence = " + sequence + " told me to go to [" + x + ", " + z + ", " + y + "]", "AGI Robot", OpenCog.Utility.Console.Console.ConsoleEntry.Type.SAY);
					
						actionArguments.EndTarget = vectorGameObject;
						//actionArguments.EndTarget = GameObject.Find("EndPointStub");
						actionArguments.EndTarget.transform.position = new Vector3(x, z, y);
						

//						OCGoalController goalController = _actionController.gameObject.GetComponent<OCGoalController>();
//						goalController.BlockType = "Hearth";
//						goalController.FindGoalBlockPositionInChunks(_map.Chunks);
					
					} else if(actionName == "destroy" || actionName == "build_block")
					{
						console.AddConsoleEntry("A '" + actionName + "' command (planID = " + _currentPlanId + ", sequence = " + sequence + " told me to destroy/create block at [" + x + ", " + z + ", " + y + "]", "AGI Robot", OpenCog.Utility.Console.Console.ConsoleEntry.Type.SAY);
						
						actionArguments.EndTarget = vectorGameObject;
						//actionArguments.EndTarget = GameObject.Find("EndPointStub");
						actionArguments.EndTarget.transform.position = new Vector3(x, z, y);
					}
					
					break;	
				// If it's an entity, then it's a grab or a consume. So the target is the battery.
				case "entity":
					XmlNodeList entityParameterChildren = actionParameterElement.GetElementsByTagName(OCEmbodimentXMLTags.ENTITY_ELEMENT);
					XmlElement entityElement = (XmlElement)entityParameterChildren.Item(0);
						
					int entityID = System.Int32.Parse(entityElement.GetAttribute(OCEmbodimentXMLTags.ID_ATTRIBUTE));
					string entityType = entityElement.GetAttribute(OCEmbodimentXMLTags.TYPE_ATTRIBUTE);
					
					if(actionName == "grab" || actionName == "eat")
					{
						UnityEngine.GameObject[] batteryArray = UnityEngine.GameObject.FindGameObjectsWithTag("OCBattery");
					
						for(int iBattery = 0; iBattery < batteryArray.Length; iBattery++)
						{
							UnityEngine.GameObject batteryObject = batteryArray[iBattery];
								
							if(entityID == batteryObject.GetInstanceID())
							{
								endPointStub.transform.position = batteryObject.transform.position;
								
								// This is the one!	
								actionArguments.EndTarget = batteryObject;
									
								break;
							}
						}
						
						if(actionArguments.EndTarget != null)
						{
							// Then we can grab it, eat it, whatever...since it's a battery
							if(actionName == "grab")
							{
								//UnityEngine.Debug.Log ("A 'grab' command (planID = " +  _currentPlanId + ", sequence = " + sequence + " told me to grab an object with ID " + entityID);
								
								console.AddConsoleEntry("A 'grab' command (planID = " + _currentPlanId + ", sequence = " + sequence + " told me to grab an object with ID " + entityID, "AGI Robot", OpenCog.Utility.Console.Console.ConsoleEntry.Type.SAY);
							} else if(actionName == "eat")
							{
								//UnityEngine.Debug.Log ("An 'eat' command (planID = " +  _currentPlanId + ", sequence = " + sequence + " told me to eat an object with ID " + entityID);
								
								console.AddConsoleEntry("An 'eat' command (planID = " + _currentPlanId + ", sequence = " + sequence + " told me to eat an object with ID " + entityID, "AGI Robot", OpenCog.Utility.Console.Console.ConsoleEntry.Type.SAY);
								
							}	

							OCGoalController goalController = _actionController.gameObject.GetComponent<OCGoalController>();
							goalController.BlockType = "Battery";
							goalController.FindGoalBlockPositionInChunks(_map.Chunks);
						} else
						{
							// That's silly..we can only eat / grab batteries!
							UnityEngine.Debug.Log("Received a grab or eat command, but couldn't find the battery in Unity!");
						}
						
							
					} 
					// if (actionName == "grab" || actionName == "eat"
//						else
//						{
//							// I'll bet the section below does nothing. Go home 
////							UnityEngine.GameObject[] hearthArray = UnityEngine.GameObject.FindGameObjectsWithTag("OCHearth");
////					
////							for (int iHearth = 0; iHearth < hearthArray.Length; iHearth++)
////							{
////								UnityEngine.GameObject hearthObject = hearthArray[iHearth];
////								
////								if (entityID == hearthObject.GetInstanceID())
////								{
////									// This is the one!	
////									actionArguments.EndTarget = hearthObject;
////									
////									break;
////								}
////							}	
//						}

					break;
				case "string":
//						XmlNodeList stringParameterChildren = actionParameterElement.GetElementsByTagName(OCEmbodimentXMLTags.VECTOR_ELEMENT);
//						XmlElement stringElement = (XmlElement)stringParameterChildren.Item (0);
					
					if(actionName == "say")
					{
						string toSay = actionParameterElement.GetAttribute(OCEmbodimentXMLTags.VALUE_ATTRIBUTE);
						
						if(toSay != string.Empty)
						{
							UnityEngine.Debug.Log("Robot say: " + toSay + "(actionPlan = " + _currentPlanId + ", sequence = " + sequence);
												
							console.AddConsoleEntry(toSay, "AGI Robot", OpenCog.Utility.Console.Console.ConsoleEntry.Type.SAY);
						}

						// We need to set the target to the avatar I guess....
						UnityEngine.GameObject[] agiArray = UnityEngine.GameObject.FindGameObjectsWithTag("OCAGI");
						
						for(int iAGI = 0; iAGI < agiArray.Length; iAGI++)
						{
							UnityEngine.GameObject agiObject = agiArray[iAGI];
							
							endPointStub.transform.position = agiObject.transform.position;
							
							actionArguments.EndTarget = endPointStub;
						}
					}

					
					break;

				} // end switch actionParameterType
			} // end foreach actionParameterNode
			
			if(_actionController == null)
			{
				_actionController = GameObject.FindGameObjectWithTag("OCAGI").GetComponent<OCActionController>();
			}
			
			actionArguments.ActionName = actionName;
			actionArguments.ActionPlanID = _currentPlanId;
			actionArguments.SequenceID = sequence;
			actionArguments.Source = UnityEngine.GameObject.FindGameObjectWithTag("OCAGI");
			//actionArguments.Source.transform.SetY(actionArguments.Source.transform.position.y - 0.5f);
			
			// Lake's function here.
			if(actionName != "say")
			{
				_actionController.LoadActionPlanStep(actionName, actionArguments);
			}
			
			// Just for fun, I'm going to send success for everything for a while.
			
			//this.SendActionStatus(_currentPlanId, sequence, actionName, true);
			
			//actionPlan.Add((XmlElement)node);
		} // end foreach actionPlanElement 
		
		// And again for fun, send a whole action plan successful message:
		//this.SendActionPlanStatus(_currentPlanId, true);
				
		// Start to perform an action in front of the action list.
		//_actionController.ReceiveActionPlan(actionPlan);// SendMessage("receiveActionPlan", actionPlan);
		//processNextAvatarAction();
	}
	// TODO: Implement / remove move to location function which can be called by OCConnector.ParseSingleActionElement.
	public void MoveToCoordinate(Vector3 desiredLocation)
	{
		OCAction.OCActionArgs args = new OCAction.OCActionArgs();
		args.Source = _defaultSource;
		args.StartTarget = _defaultStartTarget;
		args.EndTarget = _defaultEndTarget;
		
		args.StartTarget.transform.position = args.Source.transform.position;
		args.EndTarget.transform.position = desiredLocation;
				
		LoadActionPlanStep("MoveToCoordinate", args);
	}
	//---------------------------------------------------------------------------

	#endregion

	//---------------------------------------------------------------------------

	#region Private Member Functions

	//---------------------------------------------------------------------------

//	private BehaveResult DefaultActionTickHandler (OCAction action)
//	{
//		Vector3 robotPos = gameObject.transform.position;
//		Vector3 distanceVec = ((Vector3)TargetBlockPos) - robotPos;
//		
//		if (action == null)
//			return BehaveResult.Failure;
//
//		if (action.ShouldTerminate ()) {
//			//action.Terminate();
//			//Debug.Log ("In OCRobotAgent.DefaultActionTickHandler, " + action.GetType () + " Failure");
//			return BehaveResult.Failure;
//		}
//
//		if (action.IsExecuting ()) {
//			//Debug.Log("In OCRobotAgent.DefaultActionTickHandler, " + action.GetType() + " Running");
//			return BehaveResult.Running;
//		}
//
//		if (TargetBlockPos != Vector3i.zero) {
//			//Debug.Log("In OCRobotAgent.DefaultActionTickHandler, Distance to TNT block is: " + distanceVec.magnitude + ", Vector is: " + distanceVec);
//		}
//
//		return BehaveResult.Success;
//	}
	
	//---------------------------------------------------------------------------

	#endregion

	//---------------------------------------------------------------------------

	#region Other Members

	//---------------------------------------------------------------------------
			
	
			
	// TODO: This cose is just a set of stubs to get rid of an error.
	//public static event ActionCompleteHandler globalActionCompleteEvent;
	//public delegate void ActionCompleteHandler(OCAction action);
	// Removed...due to the fact that OCConnector will be polling this class for action status updates.

	// TODO: Implement / remove build block function which can be called by OCConnector.ParseSingleActionElement. Will probably have to be amended with material / blockdata.
	public void BuildBlockAtPosition(Vector3i desiredBlockLocation)
	{
		OCAction.OCActionArgs args = new OCAction.OCActionArgs();
		args.Source = _defaultSource;
		args.StartTarget = _defaultStartTarget;
		args.EndTarget = _defaultEndTarget;
		
		args.StartTarget.transform.position = args.Source.transform.position;
		args.EndTarget.transform.position = desiredBlockLocation;
				
		LoadActionPlanStep("BuildBlockAtPosition", args);
	}
示例#9
0
            public void UpdateAI()
            {
                _ActionPlanList = _ActionPlanQueue.ToList();

                if (_step == null && _ActionPlanQueue.Count != 0)
                {
                    _step = _ActionPlanQueue.First();
                    _ActionPlanQueue.RemoveFirst();
                    Debug.LogWarning("In OCActionController.UpdateAI, starting action step: " + _step.Arguments.ActionName + ", retry: " + _step.Retry);
                }
                else if (_step == null && _ActionPlanQueue.Count == 0)
                {
                    _PlanSucceeded = true;
                    OCActionPlanStep step = OCScriptableObject.CreateInstance <OCActionPlanStep>();
                    step.Behaviour = _TreeTypeDictionary[_TreeType];
                    step.Arguments = new OCAction.OCActionArgs(_defaultSource, _defaultStartTarget, _defaultEndTarget);
                    KeyValuePair <string, TreeType> keyValuePair = _ActionNameDictionary.First(s => s.Value == _TreeType);
                    step.Arguments.ActionName = keyValuePair.Key;
                    _step = step;
                }

                BehaveResult result = _step.Behaviour.Tick();

//		if((_step.Behaviour.Name == _TreeTypeDictionary[TreeType.Character_IdleShow].Name) && result == BehaveResult.Success)
//		{
//			//iTween itween = _step.Arguments.Source.GetComponent<iTween>();
//			iTween.Stop(_step.Arguments.Source);
//		}

                if (result != BehaveResult.Running)
                {
                    OCAction.OCActionArgs args = _step.Arguments;

//			if((_step.Behaviour.Name != _TreeTypeDictionary[_TreeType].Name)
//				|| ((_step.Behaviour.Name == _TreeTypeDictionary[_TreeType].Name)
//					&& (GameObject.Find("EndPointStub").transform.position != Vector3.zero)))
                    {
                        // if we have a goal...
                        if (_step.Arguments.EndTarget != null)
                        {
                            if (_step.Arguments.EndTarget.transform.position != Vector3.zero)
                            {
                                _PlanSucceeded &= result == BehaveResult.Success;
                            }

                            Vector3 startPosition  = _step.Arguments.StartTarget.transform.position;
                            Vector3 endPosition    = _step.Arguments.EndTarget.transform.position;
                            Vector3 sourcePosition = _step.Arguments.Source.transform.position;
                            sourcePosition.y = sourcePosition.y - 0.5f;

                            Vector3 startToEnd  = endPosition - startPosition;
                            Vector3 sourceToEnd = endPosition - sourcePosition;

                            float startToEndManDist  = Math.Abs(endPosition.x - startPosition.x) + Math.Abs(endPosition.y - startPosition.y) + Math.Abs(endPosition.z - startPosition.z);
                            float sourceToEndManDist = Math.Abs(endPosition.x - sourcePosition.x) + Math.Abs(endPosition.y - sourcePosition.y) + Math.Abs(endPosition.z - sourcePosition.z);

                            if (_step.Behaviour.Name == "Character.Move" || _step.Arguments.ActionName == "walk" || _step.Arguments.ActionName == "jump_toward")
                            {
                                // don't use euclideon distance
                                //_PlanSucceeded |= sourceToEnd.sqrMagnitude < startToEnd.sqrMagnitude;

                                // use manhattan distance
                                //_PlanSucceeded = sourceToEndManDist <= startToEndManDist;

                                if (VectorUtil.AreVectorsEqual(sourcePosition, endPosition))
                                {
                                    _PlanSucceeded = true;
                                }
                                else
                                {
                                    _PlanSucceeded = false;
                                }
                            }

                            if (_step.Behaviour.Name == "Character.Destroy" || _step.Arguments.ActionName == "eat")
                            {
                                _PlanSucceeded = (endPosition == Vector3.zero || _step.Arguments.EndTarget == null);
                            }

                            if (_step.Arguments.ActionName == "grab")
                            {
                                _PlanSucceeded = OCAction.IsEndTargetCloseForward(null, _step.Arguments);
                            }

//					if(_step.Arguments.ActionName == "grab")
//					{
//						_PlanSucceeded = endPosition != startPosition && endPosition != null;
//					}

                            if (_step.Arguments.ActionPlanID != null && (_PlanSucceeded || _step.Retry > OCActionPlanStep.MaxRetries))
                            {
                                OCConnectorSingleton.Instance.SendActionStatus(args.ActionPlanID, args.SequenceID, args.ActionName, _PlanSucceeded);

                                if (_step.Behaviour.Name != "Character.IdleShow" && !_step.Behaviour.Name.Contains("Behaviour"))
                                {
                                    Debug.LogWarning("In OCActionController.UpdateAI, Result: " + (_PlanSucceeded ? "Success" : "Failure") + " for Action: " + (_step.Arguments.ActionName == null ? _step.Behaviour.Name : (_step.Arguments.ActionName + " & Sequence: " + _step.Arguments.SequenceID)));
                                }
                            }
                            else if (_step.Arguments.ActionPlanID == null && (_PlanSucceeded || _step.Retry > OCActionPlanStep.MaxRetries) && OCConnectorSingleton.Instance.IsEstablished)
                            {
                                OCConnectorSingleton.Instance.HandleOtherAgentActionResult(_step, _PlanSucceeded);
                            }
                        }

//				if(!_PlanSucceeded)
//					Debug.LogWarning(" -- Step Failed: " + (_step.Arguments.ActionName == null ? _step.Behaviour.Name : _step.Arguments.ActionName));



                        _step.Behaviour.Reset();

                        // if we failed, retry last step
                        if (_PlanSucceeded == false && OCActionPlanStep.MaxRetries > _step.Retry)
                        {
                            _ActionPlanQueue.AddFirst(_step);
                            _step.Retry += 1;
                        }
                        else if (_PlanSucceeded == false && OCActionPlanStep.MaxRetries <= _step.Retry)
                        {
                            _ActionPlanQueue.Clear();
                            _step = null;
                        }
                        else if (_step.Arguments.EndTarget)
                        {
                            OCFadeOutGameObject fadeOut = _step.Arguments.EndTarget.GetComponent <OCFadeOutGameObject>();

                            if (fadeOut != null)
                            {
                                fadeOut.enabled = true;
                            }
                        }

                        if (_ActionPlanQueue.Count == 0)
                        {
                            if (_LastPlanID != null)
                            {
//						if(result == BehaveResult.Failure)
//							OCConnectorSingleton.Instance.SendActionStatus(args.ActionPlanID, args.SequenceID, args.ActionName, true);

                                OCConnectorSingleton.Instance.SendActionPlanStatus(_LastPlanID, _PlanSucceeded);

                                if (_step != null && _step.Arguments.EndTarget != null)
                                {
                                    OCFadeOutGameObject fadeOut = _step.Arguments.EndTarget.GetComponent <OCFadeOutGameObject>();

                                    if (fadeOut != null)
                                    {
                                        fadeOut.enabled = true;
                                    }
                                }

                                _LastPlanID = null;
                            }
                            _step = null;
                        }
                        else if (_LastPlanID != null)
                        {
                            _step = _ActionPlanQueue.First();
                            _ActionPlanQueue.RemoveFirst();
                            Debug.LogWarning("In OCActionController.UpdateAI, starting action step: " + _step.Arguments.ActionName + ", retry: " + _step.Retry);
                            if (_LastPlanID != _step.Arguments.ActionPlanID)
                            {
                                Debug.LogError("We've changed plans without reporting back to OpenCog!");
                            }
                        }
                        else
                        {
                            _LastPlanID = _step.Arguments.ActionPlanID;
                            _step       = _ActionPlanQueue.First();
                            _ActionPlanQueue.RemoveFirst();
                            Debug.LogWarning("In OCActionController.UpdateAI, starting action step: " + _step.Arguments.ActionName + ", retry: " + _step.Retry);
                        }
                    }
                }
            }
            public void UpdateAI()
            {
                _ActionPlanList = _ActionPlanQueue.ToList();

                if (_step == null && _ActionPlanQueue.Count != 0)
                {
                    _step = _ActionPlanQueue.Dequeue();
                }
                else if (_step == null && _ActionPlanQueue.Count == 0)
                {
                    _PlanSucceeded = true;
                    OCActionPlanStep step = new OCActionPlanStep();
                    step.Behaviour = _TreeTypeDictionary[_TreeType];
                    step.Arguments = new OCAction.OCActionArgs(_defaultSource, _defaultStartTarget, _defaultEndTarget);
                    _step          = step;
                }

                BehaveResult result = _step.Behaviour.Tick();

//		if((_step.Behaviour.Name == _TreeTypeDictionary[TreeType.Character_IdleShow].Name) && result == BehaveResult.Success)
//		{
//			//iTween itween = _step.Arguments.Source.GetComponent<iTween>();
//			iTween.Stop(_step.Arguments.Source);
//		}

                if (result != BehaveResult.Running)
                {
                    OCAction.OCActionArgs args = _step.Arguments;

//			if((_step.Behaviour.Name != _TreeTypeDictionary[_TreeType].Name)
//				|| ((_step.Behaviour.Name == _TreeTypeDictionary[_TreeType].Name)
//					&& (GameObject.Find("EndPointStub").transform.position != Vector3.zero)))
                    {
                        // if we have a goal...
                        if (_step.Arguments.EndTarget != null)
                        {
                            if (_step.Arguments.EndTarget.transform.position != Vector3.zero)
                            {
                                _PlanSucceeded &= result == BehaveResult.Success;
                            }

                            Vector3 startPosition  = _step.Arguments.StartTarget.transform.position;
                            Vector3 endPosition    = _step.Arguments.EndTarget.transform.position;
                            Vector3 sourcePosition = _step.Arguments.Source.transform.position;

                            Vector3 startToEnd  = endPosition - startPosition;
                            Vector3 sourceToEnd = endPosition - sourcePosition;

                            float startToEndManDist  = Math.Abs(endPosition.x - startPosition.x) + Math.Abs(endPosition.y - startPosition.y) + Math.Abs(endPosition.z - startPosition.z);
                            float sourceToEndManDist = Math.Abs(endPosition.x - sourcePosition.x) + Math.Abs(endPosition.y - sourcePosition.y) + Math.Abs(endPosition.z - sourcePosition.z);

                            if (_step.Behaviour.Name == "Character.Move" || _step.Arguments.ActionName == "walk" || _step.Arguments.ActionName == "jump_toward")
                            {
                                // don't use euclideon distance
                                //_PlanSucceeded |= sourceToEnd.sqrMagnitude < startToEnd.sqrMagnitude;

                                // use manhattan distance
                                _PlanSucceeded = sourceToEndManDist <= startToEndManDist;

                                if (sourcePosition == endPosition)
                                {
                                    _PlanSucceeded = true;
                                }
                            }

                            if (_step.Behaviour.Name == "Character.Destroy" || _step.Arguments.ActionName == "eat")
                            {
                                _PlanSucceeded = endPosition == Vector3.zero;
                            }

                            if (_step.Arguments.ActionName == "grab")
                            {
                                _PlanSucceeded = endPosition != startPosition && endPosition != null;
                            }

                            if (_step.Arguments.ActionPlanID != null)
                            {
                                OCConnectorSingleton.Instance.SendActionStatus(args.ActionPlanID, args.SequenceID, args.ActionName, _PlanSucceeded);
                            }
                        }

//				if(!_PlanSucceeded)
//					Debug.LogWarning(" -- Step Failed: " + (_step.Arguments.ActionName == null ? _step.Behaviour.Name : _step.Arguments.ActionName));

                        if (_step.Behaviour.Name != "Character.IdleShow" && !_step.Behaviour.Name.Contains("Behaviour"))
                        {
                            Debug.LogWarning("In OCActionController.UpdateAI, Result: " + (_PlanSucceeded ? "Success" : "Failure") + " for Action: " + (_step.Arguments.ActionName == null ? _step.Behaviour.Name : (_step.Arguments.ActionName + " & Sequence: " + _step.Arguments.SequenceID)));
                        }

                        _step.Behaviour.Reset();

                        if (_ActionPlanQueue.Count == 0)
                        {
                            if (_LastPlanID != null)
                            {
//						if(result == BehaveResult.Failure)
//							OCConnectorSingleton.Instance.SendActionStatus(args.ActionPlanID, args.SequenceID, args.ActionName, true);

                                OCConnectorSingleton.Instance.SendActionPlanStatus(_LastPlanID, _PlanSucceeded);
                                _LastPlanID = null;
                            }
                            _step = null;
                        }
                        else if (_LastPlanID != null)
                        {
                            _step = _ActionPlanQueue.Dequeue();
                            if (_LastPlanID != _step.Arguments.ActionPlanID)
                            {
                                Debug.LogError("We've changed plans without reporting back to OpenCog!");
                            }
                        }
                        else
                        {
                            _LastPlanID = _step.Arguments.ActionPlanID;
                            _step       = _ActionPlanQueue.Dequeue();
                        }
                    }
                }
            }