Esempio n. 1
0
        private bool HasNewTarget(out FighterAgent targetAgent)
        {
            m_Sorted.Clear();

            var pos    = transform.position;
            var agents = m_AgentManager.AllAgents();

            foreach (var agent in agents)
            {
                if (HasLineOfSight(agent))
                {
                    m_Sorted.Add(new SortableAgent
                    {
                        Agent    = agent,
                        Distance = (pos - agent.WorldPosition).magnitude
                    });
                }
            }
            m_Sorted.Sort();

            foreach (var obj in m_Sorted)
            {
                if (HasOpponentInVicinity(obj.Agent))
                {
                    targetAgent = obj.Agent;
                    return(true);
                }
            }

            // None found.
            targetAgent = m_TargetAgent;
            return(false);
        }
Esempio n. 2
0
        // Team rewards are supposed to encourage team work, like pack-hunting.
        // Although I havent't seen such behaviour emerging yet.
        protected void AddTeamReward(FighterAgent agent, bool opponents, float reward)
        {
            var team = TeamAgents(agent, opponents, m_Radius);

            foreach (var other in team)
            {
                other.AddReward(reward);
            }
        }
Esempio n. 3
0
        protected virtual void OnEpisodeBegin(FighterAgent agent)
        {
            agent.SetAgentActive(false);

            if (++m_AgentCount == m_NumAgents)
            {
                m_AgentCount = 0;
                OnEpisodeBegin();
            }
        }
Esempio n. 4
0
        protected override void OnHealthDepleted(FighterAgent agent)
        {
            // Reward opponents in vicinity.
            AddTeamReward(agent, true, 1);
            // Penalize team members in vicinity.
            AddTeamReward(agent, false, -1f);

            // Back to default pos, episode continues.
            agent.ResetAgent();
        }
Esempio n. 5
0
        protected override void Initialize()
        {
            m_AgentManager = FindObjectOfType <AgentManager>();
            m_Sorted       = new List <SortableAgent>();

            m_TargetAgent = FindObjectOfType <FighterAgent>();
            m_TargetPos   = m_TargetAgent.transform.position;
            m_LookPos     = m_TargetPos;

            InvokeRepeating("CheckState", 1, 1);
        }
Esempio n. 6
0
        public void OnBulletHitSuffered(FighterAgent agent)
        {
            var pos = cam.WorldToScreenPoint(agent.WorldPosition);

            if (pos.z > 0 && pos.z <= m_MaxDistance)
            {
                m_Opacity = 1;
                UpdatOpacity();
                SetValue(agent.Health);
                StopAllCoroutines();
                StartCoroutine(Dim(agent));
            }
        }
Esempio n. 7
0
        public IEnumerable <FighterAgent> TeamAgents(FighterAgent centerAgent, bool opponents, float radius)
        {
            var team = m_Agents[opponents ? Tag.OpponentTag(centerAgent.tag) : centerAgent.tag];
            var pos  = centerAgent.WorldPosition;

            foreach (var other in team)
            {
                if (other != centerAgent && (other.WorldPosition - pos).magnitude <= radius)
                {
                    yield return(other);
                }
            }
        }
Esempio n. 8
0
 private void TryTargetSwitch()
 {
     if (HasNewTarget(out FighterAgent targetAgent))
     {
         m_TargetAgent       = targetAgent;
         m_RepeatSelectCount = 0;
     }
     else
     {
         m_RepeatSelectCount++;
     }
     // Randomize anyway.
     m_Distance = Random.Range(m_DistanceRange.Min, m_DistanceRange.Max);
     m_Height   = Random.Range(m_HeightRange.Min, m_HeightRange.Max);
 }
Esempio n. 9
0
        protected IEnumerator Dim(FighterAgent agent)
        {
            SetPosition(cam.WorldToScreenPoint(agent.WorldPosition));

            float dt = Time.deltaTime;

            yield return(new WaitForSeconds(dt));

            m_Opacity = Mathf.Max(0, m_Opacity - dt * m_DimSpeed);
            UpdatOpacity();

            if (m_Opacity > 0)
            {
                StartCoroutine(Dim(agent));
            }
        }
Esempio n. 10
0
        private bool HasLineOfSight(FighterAgent agent)
        {
            var delta = agent.WorldPosition - transform.position;

            return(!Physics.Raycast(transform.position, delta, delta.magnitude, Layer.ObstacleMask));
        }
Esempio n. 11
0
        private bool HasOpponentInVicinity(FighterAgent agent)
        {
            var team = m_AgentManager.TeamAgents(agent, true, 10);

            return(team.ToArray().Length > 0);
        }
Esempio n. 12
0
 protected virtual void OnBulletHitScored(FighterAgent agent)
 {
     m_TeamHitsScoredCount[agent.tag]++;
 }
Esempio n. 13
0
 protected virtual void OnHealthDepleted(FighterAgent agent)
 {
 }