Example #1
0
        public EngageState(AgentBehaviour agentContext, BehaviourStateMachine stateMachine)
        {
            _agentContext = agentContext;
            _stateMachine = stateMachine;

            _attack = _agentContext.gameObject.GetComponentInChildren <EnemyAttack>();
        }
Example #2
0
        /// <summary>
        /// Method called when another scenario element has been selected
        /// </summary>
        /// <param name="selectedElement">Scenario element that has been selected</param>
        private void OnSelectedOtherElement(ScenarioElement selectedElement)
        {
            //Detach from current agent events
            if (behaviourExtension != null)
            {
                behaviourExtension.BehaviourChanged -= BehaviourExtensionOnBehaviourChanged;
            }

            selectedAgent = selectedElement as ScenarioAgent;
            //Attach to selected agent events
            if (selectedAgent != null)
            {
                behaviourExtension = selectedAgent.GetExtension <AgentBehaviour>();
                if (behaviourExtension == null)
                {
                    Hide();
                }
                else
                {
                    behaviourExtension.BehaviourChanged += BehaviourExtensionOnBehaviourChanged;
                    Show();
                }
            }
            else
            {
                Hide();
            }
        }
Example #3
0
    private void OnEnable()
    {
        agentBehaviour = GetComponent <AgentBehaviour>();
        aiBehaviour    = GetComponent <AIBehaviour>();
        layerMask      = LayerMask.NameToLayer("Elemnet");
        m_Ai.AddBehaviours(
            BT.Selector().AddBehaviours(
                BT.Sequence().AddBehaviours(
                    BT.Condition(() => { return(aiBehaviour.getCircleElementsNum() > 2); }),
                    //如果没有发现敌人和方块则自由移动
                    BT.Sequence().AddBehaviours(
                        //如果没有发现
                        BT.If(() => { return(!isFindElement && !isFindPlayer); }).AddBehaviours(
                            //进行随机移动
                            BT.Call(agentBehaviour.RandomWalk)
                            //进行随搜
                            //BT.Call(CheckForAround)
                            ),
                        //如果有发现
                        BT.If(() => { return(isFindElement); }).AddBehaviours(

                            BT.Call(agentBehaviour.Pursue)

                            )

                        )
                    )
                )

            );
    }
Example #4
0
 public FindTask(AgentBehaviour agent, Action <Transform, T> onSuccess = null, Action onFail = null)
 {
     _onSuccess = onSuccess;
     _onFail    = onFail;
     _agent     = agent;
     _completed = false;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="agentBehaviour">Scenario agent behaviour extension which behaviour was changed</param>
 public UndoChangeBehaviour(AgentBehaviour agentBehaviour)
 {
     this.agentBehaviour = agentBehaviour;
     behaviourName       = agentBehaviour.Behaviour;
     behaviourParameters = agentBehaviour.BehaviourParameters;
     agentBehaviour.BehaviourParameters = new JSONObject();
 }
Example #6
0
    private void UpdateGauge(AgentBehaviour p_agent, EDirection p_direction, float p_value)
    {
        DirectionGauge directionGauge = Gauges.Find(e => e.Direction == p_direction);

        directionGauge.Gauge.ChangeInfluence(p_value);
        p_agent.OnBeingEaten -= UpdateGauge;
    }
Example #7
0
 private void Awake()
 {
     //layerMask = LayerMask.NameToLayer("Element");
     agentBehaviour        = GetComponent <AgentBehaviour>();
     scanner               = GetComponentInChildren <Scanner>();
     scanner.TargetChange += TargetChanged;
 }
Example #8
0
        public override Steering GetSteering()
        {
            Steering steering          = new Steering();
            float    targetOrientation = target.GetComponent <IAgent>().GetOrientation();
            float    rotation          = targetOrientation - agent.GetOrientation();

            rotation = AgentBehaviour.MapToRange(rotation);
            float rotationSize = Mathf.Abs(rotation);

            if (rotationSize < targetRadius)
            {
                return(steering);
            }
            float targetRotation;

            if (rotationSize > slowRadius)
            {
                targetRotation = agent.GetMaxRotation();
            }
            else
            {
                targetRotation = agent.GetMaxRotation() * rotationSize / slowRadius;
            }
            targetRotation   *= rotation / rotationSize;
            steering.angular  = targetRotation - agent.GetRotation();
            steering.angular /= timeToTarget;
            float angularAccel = Mathf.Abs(steering.angular);

            if (angularAccel > agent.GetMaxAngularAccel())
            {
                steering.angular /= angularAccel;
                steering.angular *= agent.GetMaxAngularAccel();
            }
            return(steering);
        }
Example #9
0
 public void RemoveBehavior(AgentBehaviour behaviour)
 {
     if (!behaviours.Contains(behaviour))
     {
         throw new NoBehaviorException("The behaviour doesn't exist in the default strategy");
     }
     behaviours.Remove(behaviour);
 }
Example #10
0
 public void AddBehaviorAsHighestIndexed(AgentBehaviour behaviour)
 {
     if (behaviours.Contains(behaviour))
     {
         throw new DuplicateBehaviourException("The behaviour already exists");
     }
     behaviours.Add(behaviour);
 }
Example #11
0
        public ChaseState(AgentBehaviour agentContext, BehaviourStateMachine stateMachine)
        {
            _agentContext = agentContext;
            _stateMachine = stateMachine;

            _movement    = _agentContext.gameObject.GetComponent <EnemyMovement>();
            _enemyAttack = _agentContext.gameObject.GetComponentInChildren <EnemyAttack>();
        }
Example #12
0
 private void PlayFx(AgentBehaviour p_agent, EDirection p_direction, float p_value)
 {
     if (p_direction == m_direction)
     {
         Instantiate(m_fxPrefab, m_fxTransform.position, m_fxTransform.rotation);
     }
     SoundManager.Instance.PlayCreatureSound();
     p_agent.OnBeingEaten -= PlayFx;
 }
Example #13
0
        public PatrolState(AgentBehaviour agentContext, BehaviourStateMachine stateMachine)
        {
            _stateMachine = stateMachine;
            _agentContext = agentContext;

            _layerMask   = _agentContext.LayerMask;
            _waitTime    = _agentContext.WaitTime;
            _patrolSpots = _agentContext.PatrolSpots;
            _movement    = _agentContext.gameObject.GetComponent <EnemyMovement>();
        }
Example #14
0
 public StateMachine(AgentBehaviour agent)
 {
     // Inicializo los estados
     _states       = new State[4];
     _states[0]    = new IdleState(agent);
     _states[1]    = new AttackState(agent);
     _states[2]    = new DeathState(agent);
     _states[3]    = new CelebrateState(agent);
     _currentState = 0;
 }
Example #15
0
    private IEnumerator _GameStart()
    {
        while (!GameStateManager.Instance.IsGameOver)
        {
            int            rand  = Random.Range(0, AgentSettings.Instance.Agents.Count);
            AgentBehaviour agent = AgentSettings.Instance.Agents[rand];
            SpawnAgent(agent.gameObject);

            yield return(new WaitForSeconds(m_difficultyCurve.Evaluate(m_gameTime)));
        }
    }
Example #16
0
 public SeekTask(AgentBehaviour agent, Transform targetTransform, float seekForce, Action onSuccess = null, Action onFail = null)
 {
     _actorRigidbody    = agent.GetComponent <Rigidbody>();
     _actorTransform    = agent.GetComponent <Transform>();
     _targetTransform   = targetTransform;
     _seekForce         = seekForce;
     _onSuccess         = onSuccess;
     _onFail            = onFail;
     _steeringBehaviour = new Seek();
     _completed         = false;
 }
Example #17
0
    // Start is called before the first frame update
    void Start()
    {
        // Creating the default strategy behaviours
        walkNearHome = new WalkNearHomeBehaviour(GetComponent <NavMeshAgent>(), home);
        List <AgentBehaviour> behaviours = new List <AgentBehaviour>
        {
            walkNearHome
        };

        BehaviourStrategy defaultStrategy = new BehaviourStrategy(behaviours, (state) => { return(true); });

        ControlCenter = new ControlCenter(gameObject, defaultStrategy);
    }
Example #18
0
    /// <summary>
    /// Agrega un nuevo agente a su equipo.
    /// </summary>
    /// <param name="agent">Agente a agregar</param>
    /// <param name="team">Equipo al cual agregar</param>
    public void AddAgent(AgentBehaviour agent, Team team)
    {
        if (team == Team.TEAM_A)
        {
            teamA.Add(agent);
        }
        else
        {
            teamB.Add(agent);
        }

        displayInfo.text = "Team <color=#FF0000><b>RED</b></color>: " + teamA.Count + "\nTeam <color=#0000FF><b>BLUE</b></color>: " + teamB.Count;
    }
Example #19
0
        private void SwitchBehaviourOrder(AgentBehaviour behaviourOne, AgentBehaviour behaviourTwo)
        {
            if (!behaviours.Contains(behaviourOne) || !behaviours.Contains(behaviourTwo))
            {
                throw new NoBehaviorException("A behaviour is missing from the collection");
            }
            // Getting the index
            int indexOfFirst  = behaviours.IndexOf(behaviourOne);
            int indexOfSecond = behaviours.IndexOf(behaviourTwo);

            // Switching order
            behaviours[indexOfFirst]  = behaviourTwo;
            behaviours[indexOfSecond] = behaviourOne;
        }
Example #20
0
    private void sendNearestAgentsToRoom(RoomInformation room, int numberOfAgents)
    {
        for (int n = 0; n < numberOfAgents; n++)
        {
            AgentBehaviour nearestAgent = findNearestAgent(room.transform.position);

//            Debug.Log("nearest agent to room " + room.name + ": " + nearestAgent);
            if (nearestAgent != null)
            {
                nearestAgent.Pathfinding.StartJourney(room.name);
                //Debug.Log(nearestAgent.name + " to " + room.name);
            }
        }
    }
Example #21
0
        public void AddBehaviourBeforeSpecificBehaviour(AgentBehaviour toInsert, AgentBehaviour beforeThis)
        {
            if (!behaviours.Contains(beforeThis))
            {
                throw new NoBehaviorException("The behaviour doesn't exist in the default strategy");
            }
            if (behaviours.Contains(toInsert))
            {
                throw new DuplicateBehaviourException("The behaviour already exists");
            }
            int index = behaviours.IndexOf(beforeThis);

            behaviours.Insert(index, toInsert);
        }
Example #22
0
    /// <summary>
    /// Remueve al agente de la lista del equipo correspondiente
    /// </summary>
    /// <param name="agent">Agente a remover</param>
    public void RemoveAgent(AgentBehaviour agent)
    {
        if (agent.team == Team.TEAM_A)
        {
            teamA.Remove(agent);
        }
        else
        {
            teamB.Remove(agent);
        }

        displayInfo.text = "Team <color=#FF0000><b>RED</b></color>: " + teamA.Count + "\nTeam <color=#0000FF><b>BLUE</b></color>: " + teamB.Count;

        CheckGameStatus();
    }
Example #23
0
    // Start is called before the first frame update
    void Start()
    {
        // Creating the default strategy behaviours
        flyAround = new FlyAroundBehaviour(GetComponent <NavMeshAgent>(), tree, tree2, tree3, tree4);
        migrate   = new MigrateBehaviour(GetComponent <NavMeshAgent>(), palm);

        List <AgentBehaviour> behaviours = new List <AgentBehaviour>
        {
            flyAround,
            migrate
        };

        BehaviourStrategy defaultStrategy = new BehaviourStrategy(behaviours, (state) => { return(true); });

        ControlCenter = new ControlCenter(gameObject, defaultStrategy);
    }
Example #24
0
    private void stateSearch()
    {
        // Greedy algorithm to search through the whole house before trying to extinguish the fire
        for (int i = 0; i < rooms.Length; i++)
        {
            if (!rooms[i].IsDiscovered && !isRoomTargeted(rooms[i].name))
            {
                AgentBehaviour nearestAgent = findNearestAgent(rooms[i].transform.position);

                if (nearestAgent != null)
                {
                    nearestAgent.Pathfinding.StartJourney(rooms[i].name);
                }
            }
        }
    }
Example #25
0
        public override Steering GetSteering()
        {
            Steering steering          = new Steering();
            float    wanderOrientation = Random.Range(-1.0f, 1.0f) * rate;
            float    targetOrientation = wanderOrientation + agent.GetOrientation();
            Vector3  orientationVec    = AgentBehaviour.GetOriAsVec(agent.GetOrientation());
            Vector3  targetPosition    = (offset * orientationVec) + _transform.position;

            targetPosition = targetPosition + (AgentBehaviour.GetOriAsVec(targetOrientation) * radius);
            targetAux.transform.position = targetPosition;
            steering        = base.GetSteering();
            steering.linear = targetAux.transform.position - _transform.position;
            steering.linear.Normalize();
            steering.linear *= agent.GetMaxAccel();
            return(steering);
        }
Example #26
0
        public string communicationRequest(GameObject requestingAgent)         //communication request received, decide and do response (mood/social energy level)

        {
            if (infopointsVisited.Count == 0)
            {
                Debug.LogFormat("<color=red>{0} refused because it has not visited any infopoints</color>", gameObject.name);

                return("refuse");
            }


            AgentBehaviourScriptCommunicating = requestingAgent.GetComponent <AgentBehaviour>();

            Debug.LogFormat("{0} sent a request to {1}", requestingAgent.name, gameObject.name);

            if (agentEncapsulatorScript.socialEnergy > agentEncapsulatorScript.socialEnergyTreshold)
            {
                List <GameObject> possibleInfopoints = infopointsVisited.Except(AgentBehaviourScriptCommunicating.infopointsVisited).ToList();

                if (possibleInfopoints.Count != 0)
                {
                    GameObject closestInfopoint = FindClosestItem(possibleInfopoints);

                    Debug.LogFormat("<color=green>{0} had visited infopoints that {1} havent visited and its sending the information about {2}</color>", gameObject.name, requestingAgent.name, closestInfopoint.name);

                    AgentBehaviourScriptCommunicating.infopointRequest(closestInfopoint);

                    currentActionStatus = agentsActionStatus.Communicating;

                    updateSocial();

                    return("accept");
                }
                else
                {
                    Debug.LogFormat("<color=yellow>{0} had visited infopoints but {1} has already visited them</color>", gameObject.name, requestingAgent.name);

                    return("refuse");
                }
            }
            else
            {
                Debug.LogFormat("<color=red>{0} refused because of low social energy</color>", gameObject.name);

                return("refuse");
            }
        }
Example #27
0
    private void SpawnPrefab(int number)
    {
        float x = Random.Range(-_randomRotation, _randomRotation);
        float y = Random.Range(-_randomRotation, _randomRotation);
        float z = Random.Range(-_randomRotation, _randomRotation);

        Quaternion rotation = Quaternion.Euler(x, y, z);
        Vector3    position = UnityEngine.Random.insideUnitSphere * _spawnRadius;

        GameObject go = Instantiate(_prefab, position, rotation, transform);

        go.name = "Agent " + number;

        AgentBehaviour behaviour = go.GetComponent <AgentBehaviour>();

        behaviour.AddController(this);
    }
Example #28
0
    /// <summary>
    /// Busca y asigna un enemigo como objetivo.
    /// </summary>
    public void SearchEnemy()
    {
        var possibleEnemies = GameController.Instance.GetEnemies(team);

        float nearestDistance = float.MaxValue;
        float tempDistance    = 0;

        foreach (var enemy in possibleEnemies)
        {
            tempDistance = Vector3.Distance(transform.position, enemy.transform.position);
            if (tempDistance < nearestDistance)
            {
                nearestDistance = tempDistance;
                _targetEnemy    = enemy;
            }
        }
    }
Example #29
0
    private AgentBehaviour findNearestAgent(Vector3 position)
    {
        AgentBehaviour nearestAgent = null;
        var            minDistance  = float.MaxValue;

        for (int j = 0; j < agents.Length; j++)
        {
            var distance = Vector3.Distance(agents[j].transform.position, position);
            //Debug.Log("Agent " + j + " is " + (agents[j].Pathfinding.IsBusy ? "busy" : "not busy") + " with a distance of " + distance);
            if (!agents[j].Pathfinding.IsBusy && distance < minDistance)
            {
                minDistance  = distance;
                nearestAgent = agents[j];
            }
        }
        return(nearestAgent);
    }
Example #30
0
        private string communicateWithAgent(GameObject targetAgent)

        {
            string responseMessage = "";

            AgentBehaviourScript = targetAgent.GetComponent <AgentBehaviour>();

            currentActionStatus = agentsActionStatus.Communicating;

            responseMessage = AgentBehaviourScript.communicationRequest(gameObject);

            //targetAgent.transform.localScale = new Vector3 (5,5,5);

            //_unit.transform.localScale = new Vector3 (5,5,5);

            return(responseMessage);
        }
Example #31
0
        public Model()
        {
            // Initialize main form
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            this.mainForm = new MainForm(this);

            // Initialize other components
            persons.Add(new Person("A"));
            persons.Add(new Person("B"));
            receiver = new Receiver(this);
            receiver.start();
            interpreter = new Interpreter(this, getPersonA(), getPersonB());
            com = new COM(this);
            agentBehaviour = AgentBehaviour.OFF;

            // Run main form
            Application.Run(this.mainForm);
        }
Example #32
0
 public void setAgentBehaviour(AgentBehaviour value)
 {
     agentBehaviour = value;
 }