Beispiel #1
0
        public void UpdateGoal()
        {
            //List3D<OCChunk> chunks = _map.GetChunks ();

            // Since this is probably bogging down the gameplay, switch it to block creation only.
            //FindGoalBlockPositionInChunks(chunks);

            Vector3 sourcePos   = gameObject.transform.position;
            Vector3 distanceVec = ((Vector3)GoalBlockPos) - sourcePos;

            float integrityChange = _goalNameToChangeRatePerSecond["Integrity"] / (distanceVec.magnitude * _distanceAttenuation);

            integrityChange = integrityChange / 10;

            UnityEngine.GameObject[] agiArray = UnityEngine.GameObject.FindGameObjectsWithTag("OCAGI");

            if (integrityChange > 0.04)
            {
                for (int iAGI = 0; iAGI < agiArray.Length; iAGI++)
                {
                    UnityEngine.GameObject agiObject = agiArray[iAGI];

                    OpenCog.Embodiment.OCPhysiologicalModel agiPhysModel = agiObject.GetComponent <OpenCog.Embodiment.OCPhysiologicalModel>();

                    OpenCog.Embodiment.OCPhysiologicalEffect nearHomeEffect = OCPhysiologicalEffect.CreateInstance <OCPhysiologicalEffect>();
                    nearHomeEffect.CostLevelProp = OpenCog.Embodiment.OCPhysiologicalEffect.CostLevel.NONE;

                    nearHomeEffect.FitnessChange = integrityChange;

                    //UnityEngine.Debug.Log ("Increasing Integrity by '" + integrityChange.ToString() + "'");

                    agiPhysModel.ProcessPhysiologicalEffect(nearHomeEffect);
                }
            }

            if (GoalBlockPos != Vector3i.zero && _map.GetBlock(GoalBlockPos).IsEmpty())
            {
                OpenCog.Utility.Console.Console console = OpenCog.Utility.Console.Console.Instance;
                console.AddConsoleEntry("I perceive no more " + _goalBlockType.GetName() + " blocks in my world.", "AGI Robot", OpenCog.Utility.Console.Console.ConsoleEntry.Type.SAY);
                System.Console.WriteLine(OCLogSymbol.RUNNING + "No more " + _goalBlockType.GetName() + " are reported");

                GoalBlockPos = Vector3i.zero;

                OCAction[] actions = gameObject.GetComponentsInChildren <OCAction>();

                foreach (OCAction action in actions)
                {
                    if (action.EndTarget != null)
                    {
                        action.EndTarget.transform.position = Vector3.zero;
                    }
                    if (action.StartTarget != null)
                    {
                        action.StartTarget.transform.position = Vector3.zero;
                    }
                }
            }
        }
            private ActionStatus EndAction()
            {
                //OCLogger.Debugging("Ending the " + FullName + " Action.");

                OCActionArgs args = null;

                if (_ActionController.Step != null)
                {
                    args = _ActionController.Step.Arguments;
                }

                if (_blockOnFail && _blockOnRunning)
                {
                    _ActionController.RunningActions.Remove(FullName);
                }

                // End animation effects
//		foreach(OCAnimationEffect afx in _AnimationEffects)
//		{
//			afx.Stop();
//		}

                foreach (OCDestroyBlockEffect dbfx in _DestroyBlockEffects)
                {
                    Vector3i forward     = VectorUtil.Vector3ToVector3i(_Source.transform.position + _Source.transform.forward);
                    Vector3i forwardUp   = VectorUtil.Vector3ToVector3i(_Source.transform.position + _Source.transform.forward + _Source.transform.up);
                    Vector3i forwardUp2x = VectorUtil.Vector3ToVector3i(_Source.transform.position + _Source.transform.forward + 2 * _Source.transform.up);

                    OCBlockData forwardBlock     = _Map.GetBlock(forward);
                    OCBlockData forwardUpBlock   = _Map.GetBlock(forwardUp);
                    OCBlockData forwardUp2xBlock = _Map.GetBlock(forwardUp2x);

                    dbfx.DestroyBlock(forward);
                    dbfx.DestroyBlock(forwardUp);
                    dbfx.DestroyBlock(forwardUp2x);

                    args.EndTarget.transform.position   = Vector3.zero;
                    args.StartTarget.transform.position = Vector3.zero;

                    // This is just some example code for you Lake, that you can use to give energy to the robot after consuming a battery.
                    if ((forwardBlock.block != null && forwardBlock.block.GetName() == "Battery") || (forwardUpBlock.block != null && forwardUpBlock.block.GetName() == "Battery") || (forwardUp2xBlock.block != null && forwardUp2xBlock.block.GetName() == "Battery"))
                    {
                        UnityEngine.GameObject[] agiArray = UnityEngine.GameObject.FindGameObjectsWithTag("OCAGI");

                        for (int iAGI = 0; iAGI < agiArray.Length; iAGI++)
                        {
                            UnityEngine.GameObject agiObject = agiArray[iAGI];

                            //args.EndTarget = agiObject;

                            OCPhysiologicalModel agiPhysModel = agiObject.GetComponent <OCPhysiologicalModel>();

                            OCPhysiologicalEffect batteryEatEffect = new OCPhysiologicalEffect(OCPhysiologicalEffect.CostLevel.NONE);

                            batteryEatEffect.EnergyIncrease = 0.2f;

                            agiPhysModel.ProcessPhysiologicalEffect(batteryEatEffect);

                            break;
                        }
                    }
                }

                //@TODO: Fix this hack...
                if (Descriptors.Contains("Jump") || Descriptors.Contains("Climb") || Descriptors.Contains("Fall"))
                {
                    OCCharacterMotor motor = _Source.GetComponent <OCCharacterMotor>();
                    motor.enabled = true;
                }

                if (!Descriptors.Contains("Idle"))
                {
                    Debug.LogWarning("Ending Action: " + FullName);
                }

//		if(args.ActionPlanID != null)
//			OCConnectorSingleton.Instance.SendActionStatus(args.ActionPlanID, args.SequenceID, args.ActionName, true);

                return(ActionStatus.SUCCESS);
            }