void Start()
 {
     rg = GetComponent <Rigidbody2D>();
     perceptionComponent = GetComponentInChildren <Perception>();
     patrol      = GetComponent <Patrol>();
     enemyFollow = GetComponent <EnemyFollow>();
 }
Example #2
0
 public void InitializePerception(PerceptionData perceptionData)
 {
     if (perceptionData != null)
     {
         _perception = new Perception(perceptionData);
     }
 }
Example #3
0
        protected override void WriteDataXML(XElement ele, ElderScrollsPlugin master)
        {
            XElement subEle;

            ele.TryPathTo("Strength", true, out subEle);
            subEle.Value = Strength.ToString();

            ele.TryPathTo("Perception", true, out subEle);
            subEle.Value = Perception.ToString();

            ele.TryPathTo("Endurance", true, out subEle);
            subEle.Value = Endurance.ToString();

            ele.TryPathTo("Charisma", true, out subEle);
            subEle.Value = Charisma.ToString();

            ele.TryPathTo("Intelligence", true, out subEle);
            subEle.Value = Intelligence.ToString();

            ele.TryPathTo("Agility", true, out subEle);
            subEle.Value = Agility.ToString();

            ele.TryPathTo("Luck", true, out subEle);
            subEle.Value = Luck.ToString();
        }
Example #4
0
    private void OnSceneGUI()
    {
        //Reference to Perception script and target obj
        Perception prc = (Perception)target;

        //Sets color of circle
        Handles.color = Color.black;
        //Draws circle from position of obj, dir circle will rotate around obj, angle begins, rotates 360, actual radius
        Handles.DrawWireArc(prc.transform.position, Vector3.forward, Vector3.left, 360, prc.pRadius);
        //Declare variables for Line of SIght. angleInDegrees, angleIsGlobal
        Vector3 losAngleA = prc.DirFromAngle(-prc.pAngle / 2, false);
        Vector3 losAngleB = prc.DirFromAngle(prc.pAngle / 2, false);

        //Draws the Line of Sight cone
        Handles.DrawLine(prc.transform.position, prc.transform.position + losAngleA * prc.pRadius);
        Handles.DrawLine(prc.transform.position, prc.transform.position + losAngleB * prc.pRadius);
        //Handles.DrawWireArc(prc.transform.position, Vector3.forward, losAngleB, prc.pAngle, prc.pRadius / 2);

        //Creates a red line between targets
        Handles.color = Color.red;
        foreach (Transform visibleTarget in prc.visibleTargets)
        {
            Handles.DrawLine(prc.transform.position, visibleTarget.position);
        }
    }
 void Start()
 {
     percepcion    = GetComponentInChildren <Perception>();
     posjug        = jugador.GetComponent <Transform>();
     rb            = GetComponent <Rigidbody2D>();
     speedAuxiliar = pteranodonSpeed;
 }
Example #6
0
    public override void Execute(Agent owner)
    {
        GameObject[] gameObjects = owner.perception.GetGameObjects();
        GameObject   player      = Perception.GetGameObjectFromTag(gameObjects, "Player");

        //player seen
        if (player != null)
        {
            lastTargetPosition = player.transform.position;
            timer = 1;

            attackTimer -= Time.deltaTime;
            if (attackTimer <= 0)
            {
                float distance = Vector3.Distance(owner.transform.position, player.transform.position);
                if (distance < meleeDistance)
                {
                    ((StateAgent)owner).stateMachine.SetState("AttackMeleeState");
                }
                else
                {
                    ((StateAgent)owner).stateMachine.SetState("IdleState");
                }
            }
        }

        owner.movement.MoveTowards(lastTargetPosition);
    }
Example #7
0
        void Awake()
        {
            // Initialize components
            Perception.InitializePerception();
            Body.InitializeBody();
            AI.InitializeAI();

            // Flag agent type
            switch (AgentType)
            {
            case AGENT_TYPE.FEMALE:
                Body.DoGesture(GESTURE_CODE.FEMALE_FLAG, true);
                break;

            case AGENT_TYPE.ANIMAL:
                // TODO - add GESTURE flag
                break;

            case AGENT_TYPE.BEAST:
                // TODO - add GESTURE flag
                break;
            }

            // Handle main agent flag
            SetSelected(MainAgent);

            // Set up controller update time
            g_NextUpdateTime = Time.time + UpdateTime;

            // handle agent's tags
            g_NPCTags = new HashSet <string>();

            foreach (string tag in AgentTags)
            {
                g_NPCTags.Add(tag);
            }

            // Add agent audio source
            if (EnableAudio)
            {
                AudioSource aSource = GetComponent <AudioSource>();
                if (aSource != null && aSource.name.Equals("Agent_Audio_Source"))
                {
                    g_AgentAudioSource = aSource;
                }
                else
                {
                    g_AgentAudioSource = gameObject.AddComponent <AudioSource>();
                }
            }

            // Generate individual materials
            foreach (Renderer r in GetComponentsInChildren <Renderer>())
            {
                r.sharedMaterial = Instantiate(r.material) as Material;
            }

            // Initialize all loaded modules
            LoadNPCModules();
        }
        /// <summary>
        /// Finds the target.
        /// </summary>
        public virtual GameObject FindTarget()
        {
            if (Owner.GetComponent <IHasPerception>() == null)
            {
                return(null);
            }
            TargetSkill skill = Skill as TargetSkill;

            if (skill == null)
            {
                return(null);
            }

            Perception perception = Owner.GetComponent <IHasPerception> ().Perception;

            GameObject target = null;

            foreach (var key in perception.Percepts.Keys)
            {
                if ((perception.Percepts [key].Entity != null) &&
                    ((skill.IncludeSelf && (perception.Percepts[key].Entity == Owner)) || (perception.Percepts[key].Entity != Owner)) &&
                    ((perception.Percepts[key].Entity.GetComponent <IPerceivable>().Tag & skill.TargetType) != 0))
                {
                    target = perception.Percepts [key].Entity;
                    break;
                }
            }

            return(target);
        }
Example #9
0
 public void Perceive(Perception perception)
 {
     if (onPerceive != null)
     {
         onPerceive(perception);
     }
 }
Example #10
0
    /// <summary>
    /// Creates a transition between one <see cref="BehaviourTreeEngine"/>, the submachine; and another <see cref="BehaviourTreeEngine"/>, the supermachine.
    /// </summary>
    /// <param name="name">The name of the transition</param>
    /// <param name="nodeFrom">The exit node of the transition</param>
    /// <param name="stateTo">The node where the Behaviour tree is coming back</param>
    /// <param name="superMachine">The supermachine</param>
    /// <param name="subMachine">The submachine</param>
    public Transition(string name, TreeNode nodeFrom, LeafNode stateTo, BehaviourTreeEngine superMachine, BehaviourTreeEngine subMachine)
    {
        this.Name       = name;
        this.StateFrom  = nodeFrom.StateNode;
        this.StateTo    = stateTo.StateNode;
        this.Perception = new OrPerception(new BehaviourTreeStatusPerception(subMachine, ReturnValues.Succeed, subMachine),
                                           new BehaviourTreeStatusPerception(subMachine, ReturnValues.Failed, subMachine),
                                           subMachine);
        this.type = TRANSITION_TYPE.SUPER_TRANSITION;

        if (StateFrom.BehaviourEngine == superMachine)   // Exits from the super-machine
        {
            this.BehaviourEngine = superMachine;
            Perception.SetBehaviourMachine(superMachine);
            superMachine.Configure(StateFrom)
            .OnExit(this.Name, () => Perception.Reset())
            .InternalTransition(Perception, this.Name, () => ExitTransition(StateFrom, stateTo, subMachine.GetRootNode().ReturnValue, subMachine.GetState("Entry_Machine"), superMachine, subMachine));
        }
        else   // Exits from the sub-machine
        {
            this.BehaviourEngine = subMachine;
            Perception.SetBehaviourMachine(subMachine);
            subMachine.Configure(StateFrom)
            .OnExit(this.Name, () => Perception.Reset())
            .InternalTransition(Perception, this.Name, () => ExitTransition(StateFrom, stateTo, subMachine.GetRootNode().ReturnValue, subMachine.GetState("Entry_Machine"), superMachine, subMachine));
        }
    }
Example #11
0
    /// <summary>
    /// Creates a transition between two <see cref="BehaviourEngine"/>, one is the submachine the other the supermachine
    /// </summary>
    /// <param name="name">The name of the transition</param>
    /// <param name="stateFrom">The exit state of the transition</param>
    /// <param name="perception">The perception that activates the transition</param>
    /// <param name="stateTo">the entry state of the transition</param>
    /// <param name="superMachine">The supermachine</param>
    /// <param name="subMachine">The submachine</param>
    public Transition(string name, State stateFrom, Perception perception, State stateTo, BehaviourEngine superMachine, BehaviourEngine subMachine)
    {
        this.Name       = name;
        this.StateFrom  = stateFrom;
        this.Perception = perception;
        this.StateTo    = stateTo;
        this.type       = TRANSITION_TYPE.SUPER_TRANSITION;

        if (stateFrom.BehaviourEngine == superMachine)   // Exits from the super-machine
        {
            this.BehaviourEngine = superMachine;
            Perception.SetBehaviourMachine(superMachine);
            superMachine.Configure(StateFrom)
            .OnExit(this.Name, () => Perception.Reset())
            .InternalTransition(Perception, this.Name, () => ExitTransition(StateFrom, StateTo, subMachine.GetState("Entry_Machine"), superMachine, subMachine));
        }
        else   // Exits from the sub-machine
        {
            this.BehaviourEngine = subMachine;
            Perception.SetBehaviourMachine(subMachine);
            subMachine.Configure(StateFrom)
            .OnExit(this.Name, () => Perception.Reset())
            .InternalTransition(Perception, this.Name, () => ExitTransition(StateFrom, StateTo, subMachine.GetState("Entry_Machine"), superMachine, subMachine));
        }
    }
Example #12
0
    public Map.Side Run(Snake snake)
    {
        var forward    = Map.Neighbour(snake.Head(), snake.Direction());
        var right      = Map.Neighbour(snake.Head(), Map.Right(snake.Direction()));
        var left       = Map.Neighbour(snake.Head(), Map.Left(snake.Direction()));
        var neighbours = new Field[] { forward, right, left };
        var dist       = new Perception(snake).DistanceToFood();

        var desired = this.GetDesiredDirection(dist);

        if (CanDirectionBeFollowed(snake.Head(), neighbours, desired))
        {
            return(desired);
        }

        var alternative = this.GetAlternativeDirection(dist);

        if (CanDirectionBeFollowed(snake.Head(), neighbours, alternative))
        {
            return(alternative);
        }
        else
        {
            foreach (var neighbour in neighbours)
            {
                if (neighbour.IsWalkable())
                {
                    return(Map.Direction(snake.Head(), neighbour));
                }
            }
        }


        return(snake.Direction());
    }
Example #13
0
        public async Task <IActionResult> Edit(int id, [Bind("Perceptionid,Perceptionprof")] Perception perception)
        {
            if (id != perception.Perceptionid)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(perception);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PerceptionExists(perception.Perceptionid))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(perception));
        }
Example #14
0
    private void Awake()
    {
        FixedView fixedView = delegate(DrawPath player)
        {
            player.KillViewInMove();
        };

        Mortier mortier = delegate(Vector3 position)
        {
            var ammo = Instantiate(prefAmmoMortier, position, Quaternion.identity);
            Destroy(ammo);
        };

        Mine mine = delegate(Vector3 position)
        {
            Instantiate(prefMine, position.WithY(0.55f), Quaternion.identity);
        };

        Perception perception = delegate(FieldOfView viewPlayer)
        {
        };


        skills = new List <Delegate>();
        skills.Add(fixedView);
        skills.Add(mortier);
        skills.Add(mine);
        skills.Add(perception);
    }
Example #15
0
 public AndPerception(Perception perceptionLeft, Perception perceptionRight, BehaviourEngine behaviourEngine) : base()
 {
     this.PerceptionLeft  = perceptionLeft;
     this.PerceptionRight = perceptionRight;
     this.reseter         = true;
     base.behaviourEngine = behaviourEngine;
 }
Example #16
0
    void VisibleTargets()
    {
        visibleTargets.Clear();
        Collider[] targets = Physics.OverlapSphere(transform.position, viewRadius, TargetLayer);

        foreach (Collider target in targets)
        {
            Vector3 toTarget         = (target.transform.position - transform.position);
            Vector3 targetNormalized = toTarget.normalized;

            if (Vector3.Angle(transform.forward, targetNormalized) < viewAngle / 2 &&
                !Physics.Raycast(transform.position, targetNormalized, toTarget.magnitude, obstacleLayer))
            {
                visibleTargets.Add(target.transform);
            }
        }


        Perception perception = GetComponent <Perception>();

        perception.clearView();
        foreach (Transform target in visibleTargets)
        {
            perception.addMemory(target.gameObject);
        }
    }
Example #17
0
    /// <summary>
    /// Creates a new <see cref="Perception"/> of a type created by the user
    /// </summary>
    /// <param name="perception">The perception created by the user</param>
    /// <returns></returns>
    public PerceptionType CreatePerception <PerceptionType>(PerceptionType perception)
    {
        Perception perceptionBase = perception as Perception;

        perceptionBase.SetBehaviourMachine(this);

        return(perception);
    }
Example #18
0
    public void Init(Perception newPerception,  GameInstance newInstance)
    {
        myGameInstance = newInstance;
        myPerception = newPerception;

        init = true;
        AssessPerceivables();
    }
Example #19
0
 public ConditionalDecoratorNode(string name, TreeNode child, Perception condition, BehaviourTreeEngine behaviourTree)
 {
     this.conditionPerception = condition;
     base.Child         = child;
     Child.ParentNode   = this;
     base.StateNode     = new State(name, () => { }, behaviourTree); // Empty action to prevent errors (going to child too early)
     base.behaviourTree = behaviourTree;
 }
Example #20
0
        public override void updateBelief(List <Perception> perceptions)
        {
            Perception candidate = perceptions.Find(p => p.target.Equals(Subject));

            if (candidate != null)
            {
                attributes[Elements.RESOURCE] = candidate.attributes[Elements.RESOURCE];
            }
        }
Example #21
0
 public StateConfigurator InternalTransition(Perception perception, String name, Action method)
 {
     /* TODO ¿Es necesaria la percepción?*/
     if (!internalTransition.ContainsKey(name))
     {
         internalTransition.Add(name, method);
     }
     return(this);
 }
Example #22
0
        public void Run()
        {
            // Move all the way up
            var perceptions = new Perception[] {};

            while (!perceptions.Contains(Perception.Bump))
            {
                perceptions = game.Move(Direction.North).Perceptions;
            }

            // Move all the way to the left
            perceptions = new Perception[] {};

            while (!perceptions.Contains(Perception.Bump))
            {
                perceptions = game.Move(Direction.West).Perceptions;
            }

            // Zigzag through the game
            var direction = Direction.East;

            // First move
            perceptions = game.Move(direction).Perceptions;

            while (true)
            {
                // We lost
                if (perceptions.Contains(Perception.Death))
                {
                    return;
                }

                // We won
                if (perceptions.Contains(Perception.Win))
                {
                    return;
                }

                // We ran into the left or right wall, go south one and reverse direction
                if (perceptions.Contains(Perception.Bump))
                {
                    direction   = direction == Direction.East ? Direction.West : Direction.East;
                    perceptions = game.Move(Direction.South).Perceptions;
                    continue; // Reevaluate perceptions after move
                }

                // We stepped on the gold
                if (perceptions.Contains(Perception.Glitter))
                {
                    perceptions = game.Pickup().Perceptions;
                    continue; // Reevaluate perceptions after pickup
                }

                // No special perception -> Move on
                perceptions = game.Move(direction).Perceptions;
            }
        }
Example #23
0
    void DoAIBehaviour()
    {
        if (myEntity.isInNest)
        {
            //We are in a nest, so nothing to return.
            return;
        }

        if (Entities.entitiesByType.ContainsKey(entityType) == false)
        {
            //Nothing to eat.
            wander.ChooseDirection();
            return;
        }

        //Finds theclosest target.
        Entities   closest = null;
        Perception prc     = new Perception();
        float      dist    = Mathf.Infinity;

        foreach (Entities c in Entities.entitiesByType[entityType])
        {
            float d = Vector2.Distance(this.transform.position, c.transform.position);

            if (closest == null && d < dist)
            {
                closest = c;
                dist    = d;
            }
        }

        if (closest == null)
        {
            //No valid targets exist.
            wander.ChooseDirection();
            return;
        }

        //If the predator is close have high weight
        float weight = 100 / (dist * dist);

        if (dist < 20)
        {
            //Move toward closest existing target.
            Vector2 dir = closest.transform.position - this.transform.position;
            //Rather than swapping the above vectors this method allows for smoother transitions between targets.
            dir *= -1;

            WeightedDirection wd = new WeightedDirection(dir, weight);

            myEntity.desiredDirections.Add(wd);
        }
        else
        {
            wander.ChooseDirection();
        }
    }
Example #24
0
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     ai            = animator.GetComponent <Pterodactyl>();
     perception    = animator.GetComponent <Perception>();
     _Animator     = animator;
     movementSpeed = ai.movementSpeed;
     transform     = animator.transform;
     rigidbody     = animator.GetComponent <Rigidbody2D>();
     retreatSpeed  = ai.retreatSpeed;
 }
Example #25
0
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     ai             = animator.GetComponent <Trex>();
     perception     = animator.GetComponent <Perception>();
     shootTimer     = ai.attackCooldown;
     aiProjectile   = ai.projectile;
     rigidbody      = ai.GetComponent <Rigidbody2D>();
     spriteRenderer = ai.GetComponent <SpriteRenderer>();
     aimOrigin      = ai.aimOrigin;
 }
Example #26
0
        public void Bonus_PerceptionSpecified_ShouldWork()
        {
            SetupCharacter();

            Skills perception = new Perception(true, true);

            Assert.AreEqual(-5, perception.Bonus);
            Assert.IsTrue(perception.Proficiency);
            Assert.IsTrue(perception.Expertise);
        }
Example #27
0
        public void ShouldReturnName()
        {
            //assign
            ISkill actualSkillBase = new Perception();
            //act
            ITextObj name = actualSkillBase.Name();

            //assert
            name.Should().Be(new TextObj("Perception"));
        }
Example #28
0
    private bool CanSeeTarget()
    {
        if (Time.time - lastRaycastTime > MaxRaycastInterval)
        {
            cachedCanSeeTargetResult = Perception.CanSeeTarget(owner, target.transform.position);
            lastRaycastTime          = Time.time;
        }

        return(cachedCanSeeTargetResult);
    }
 /// <Summary>
 /// Every frame, updates the position of every member in the group if the agent sees them
 /// </Summary>
 /// <param name="p"> The agent perception during this frame </param>
 public void UpdateGroup(Perception p)
 {
     foreach (Agent a in group.Keys)          // for each member of this group
     {
         if (p.AgentsInSight.Contains(a))     // if the given agent sees this member
         {
             group[a] = a.transform.position; // updates the position of this member for the given agent
         }
     }
 }
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        ai         = animator.GetComponent <JumpRaptor>();
        perception = animator.GetComponent <Perception>();
        transform  = animator.transform;

        targetTimer = ai.targetResetTime;

        ai.SetRandomGoal();
    }
Example #31
0
 public void CopyData(Perception other)
 {
     if (other == null)
     {
         return;
     }
     this.targetsCanBePercept = other.targetsCanBePercept;
     this.hostsCanBeSeen      = other.hostsCanBeSeen;
     this.hostsCanBeListened  = other.hostsCanBeListened;
 }
Example #32
0
 // Use this for initialization
 public BDI(Agent agent)
 {
     myAgent    = agent;
     belief     = new Belief();
     desire     = new Desire(agent.GetType());
     intention  = null;
     perception = new Perception(myAgent);
     feelings   = new Feelings();
     reasoning  = new Reasoning();
 }
    public void Perceive(Perception perception)
    {
        //Debug.Log("PerceptionListener.Perceive()" + name + " is perceiving!");
        GameObject source = perception.GetSource();
        ImpressionAdjuster adjuster = perception.GetImpressionAdjuster();
        Action action = perception.GetAction(gameObject);

        if (adjuster != null){
            impressionMemory.ImpressionAdjusted(source, adjuster);
        }

        if (action != null){
            actionRunner.ResetRoutine(action, false);
        }
    }
Example #34
0
    //The function that handles the initialization-step of the Learning system.
    void InitializeAgent()
    {
        //Initialize the objects needed in the system's loop and put reference to this class where necessary.
        perception = gameObject.GetComponentInChildren<Perception>();
        perception.agentController = this;
        perception.InitializePerception();
        learn = new Learn();
        learn.agentController = this;
        decisionSystem = new DecisionSystem();
        decisionSystem.agentController = this;

        //Find the actions defined in the Actions child of the agent and put them in a list for referencing.
        actions = transform.FindChild("Actions").gameObject.GetComponents<BasicAction>().ToList();
        // initializes the agentcontroller in each action
        actions.ForEach(a => a.agentController = this);
    }
 //private PerceptionManager instance;
 /*public void Start(){
     //instance = this;
     enabled=false;
 }*/
 public static void BroadcastPerception(Perception perception)
 {
     //Debug.Log("Broadcasting perception.");
     foreach (GameObject npc in CharacterManager.GetMajorNPCs()){
         //Debug.Log("Iterating broadcast: " + npc.name);
         CharacterState sourceState = perception.GetSource().GetComponent(typeof(CharacterState)) as CharacterState;
         Area sourceArea = sourceState.GetCurrentArea();
         PerceptionListener perceptionListener = npc.GetComponent(typeof(PerceptionListener)) as PerceptionListener;
         float distance = Vector3.Distance(perception.GetPosition(), npc.transform.position);
         //Debug.Log("Distance okay? " + (distance < sourceArea.GetPerceptionDistance()));
         //Debug.Log("Vision okay?" + (perceptionListener.CanSee(perception.GetPosition())));
         if (distance < sourceArea.GetEasyPerceptionDistance() || (distance < sourceArea.GetPerceptionDistance() && perceptionListener.CanSee(perception.GetPosition()))){
             //Debug.Log("PerceptionManager.BroadcastPerception(): " + npc.name);
             perceptionListener.Perceive(perception);
         }
     }
 }
Example #36
0
    //Use this for initialization
    void Start()
    {
        currentHealth = maxHealth;
        currentStamina = maxStamina;
        currentMS = 0;

        strength = GetComponent<Strength>();
        agility = GetComponent<Agility>();
        haste = GetComponent<Haste>();
        perception = GetComponent<Perception>();
        intelligence = GetComponent<Intelligence>();
        wisdom = GetComponent<Wisdom>();

        cont = GetComponent<CharacterController>();
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
        cameraReference = GameObject.FindWithTag("cameraReference");
        lookTarget = GameObject.FindWithTag("LookTarget");
    }
Example #37
0
 public override void start(BaseBehaviour baseBehaviour)
 {
     m_Perception = GetComponentInParent<Perception> ();
 }