Пример #1
0
        protected override ERunningStatus OnExecute(IAgent agent, BlackboardMemory workingMemory)
        {
            Tank       t = (Tank)agent;
            var        missiles = Match.instance.GetOppositeMissiles(t.Team);
            Missile    missile = Functions.GetLatestMissile(missiles, t.Team);
            Vector3    normal = Vector3.Cross(Vector3.up, missile.Velocity).normalized;
            RaycastHit hitInfo1, hitInfo2;
            float      hitDistance1 = 0, hitDistance2 = 0;

            if (Physics.Linecast(t.Position, t.Position + normal * 100, out hitInfo1, PhysicsUtils.LayerMaskScene))
            {
                hitDistance1 = hitInfo1.distance;
            }
            if (Physics.Linecast(t.Position, t.Position - normal * 100, out hitInfo2, PhysicsUtils.LayerMaskScene))
            {
                hitDistance2 = hitInfo2.distance;
            }
            if (Mathf.Max(hitDistance1, hitDistance2) < 3)
            {
                return(ERunningStatus.Failed);
            }
            if (hitDistance1 > hitDistance2)
            {
                workingMemory.SetValue((int)EBBKey.MovingTargetPos, t.Position + Vector3.ClampMagnitude(normal, hitDistance1 - 1));
                return(ERunningStatus.Finished);
            }
            workingMemory.SetValue((int)EBBKey.MovingTargetPos, t.Position - Vector3.ClampMagnitude(normal, hitDistance2 - 1));
            return(ERunningStatus.Finished);
        }
Пример #2
0
        public override void Update(BlackboardMemory sensorMemory)
        {
            Tank t = (Tank)Agent;
            //check if can see other tank
            int  targetOppKey = (int)EBBKey.TargetOppTank;
            Tank oppTank      = Match.instance.GetOppositeTank(t.Team);

            if (oppTank != null && oppTank.IsDead == false && TrySightingTest(oppTank.Position))
            {
                sensorMemory.SetValue(targetOppKey, oppTank);
            }
            else
            {
                sensorMemory.SetValue(targetOppKey, null);
            }
            //check if star still exists
            int cachedStarID = sensorMemory.GetValue <int>((int)EBBKey.CaredStar, -1);

            if (cachedStarID >= 0) //has star
            {
                //move to star position it heard
                Vector3 starPos = sensorMemory.GetValue <Vector3>((int)EBBKey.TargetStarPos, default(Vector3));
                if (TrySightingTest(starPos))
                {
                    Star cachedStar = Match.instance.GetStarByID(cachedStarID);
                    if (cachedStar == null)
                    {
                        sensorMemory.DelValue((int)EBBKey.CaredStar);
                        sensorMemory.DelValue((int)EBBKey.TargetStarPos);
                    }
                }
            }
        }
Пример #3
0
        public override void StimulusReceived(Stimulus stim, BlackboardMemory sensorMemory)
        {
            Tank    t        = (Tank)Agent;
            Vector3 toTarget = stim.EmitterPos - t.Position;

            if (toTarget.sqrMagnitude > m_HearingRadius * m_HearingRadius)
            {
                return;
            }
            //star jingle
            if (stim.StimulusType == (int)EStimulusType.StarJingle)
            {
                bool needUpdateCachedStar = false;
                int  cachedStarKey        = (int)EBBKey.CaredStar;
                Star star         = (Star)stim.TargetObject;
                int  cachedStarID = sensorMemory.GetValue <int>(cachedStarKey, -1);
                if (cachedStarID < 0)
                {
                    needUpdateCachedStar = true;
                }
                else
                {
                    Star cachedStar = Match.instance.GetStarByID(cachedStarID);
                    if (cachedStar == null) //no star found, use current
                    {
                        needUpdateCachedStar = true;
                    }
                    else
                    {
                        //check if need update cached star
                        if ((cachedStar.Position - t.Position).sqrMagnitude > toTarget.sqrMagnitude)
                        {
                            needUpdateCachedStar = true;
                        }
                    }
                }
                if (needUpdateCachedStar)
                {
                    //update target to nearer one
                    sensorMemory.SetValue(cachedStarKey, star.ID);
                    sensorMemory.SetValue((int)EBBKey.TargetStarPos, star.Position);
                }
            }
            else if (stim.StimulusType == (int)EStimulusType.StarTaken)
            {
                //if hears star taken, remove it from memory
                int  cachedStarKey = (int)EBBKey.CaredStar;
                Star star          = (Star)stim.TargetObject;
                int  cachedStarID  = sensorMemory.GetValue <int>(cachedStarKey, -1);
                if (star.ID == cachedStarID)
                {
                    sensorMemory.DelValue(cachedStarKey);
                    sensorMemory.DelValue((int)EBBKey.TargetStarPos);
                }
            }
        }
Пример #4
0
        protected override bool OnEvaluate(IAgent agent, BlackboardMemory workingMemory)
        {
            Tank    t              = (Tank)agent;
            bool    hasStar        = false;
            float   nearestDist    = float.MaxValue;
            Vector3 nearestStarPos = Vector3.zero;

            foreach (var pair in Match.instance.GetStars())
            {
                Star s = pair.Value;
                if (s.IsSuperStar)
                {
                    hasStar        = true;
                    nearestStarPos = s.Position;
                    break;
                }
                else
                {
                    float dist = (s.Position - t.Position).sqrMagnitude;
                    if (dist < nearestDist)
                    {
                        hasStar        = true;
                        nearestDist    = dist;
                        nearestStarPos = s.Position;
                    }
                }
            }
            if (hasStar)
            {
                workingMemory.SetValue((int)EBBKey.MovingTargetPos, nearestStarPos);
            }
            return(hasStar);
        }
Пример #5
0
        protected override bool OnEvaluate(IAgent agent, BlackboardMemory workingMemory)
        {
            Tank t = (Tank)agent;

            workingMemory.SetValue((int)EBBKey.MovingTargetPos, Match.instance.GetRebornPos(t.Team));
            return(true);
        }
Пример #6
0
        protected override bool OnEvaluate(IAgent agent, BlackboardMemory workingMemory)
        {
            Tank    t              = (Tank)agent;
            bool    hasStar        = false;
            float   nearestDist    = float.MaxValue;
            Vector3 nearestStarPos = Vector3.zero;

            foreach (var pair in Match.instance.GetStars())
            {
                Star s = pair.Value;
                if (s.IsSuperStar)
                {
                    hasStar        = true;
                    nearestStarPos = s.Position;
                    break;
                }
                else if (!Functions.Vector3EqualTo(t.NextDestination, s.Position))
                {
                    float dist = Functions.CalculatePathLength(t.CaculatePath(s.Position), t.Position, s.Position);
                    if (dist < nearestDist)
                    {
                        hasStar        = true;
                        nearestDist    = dist;
                        nearestStarPos = s.Position;
                    }
                }
            }
            if (hasStar)
            {
                workingMemory.SetValue((int)EBBKey.MovingTargetPos, nearestStarPos);
            }
            return(hasStar);
        }
Пример #7
0
        protected override bool OnEvaluate(IAgent agent, BlackboardMemory workingMemory)
        {
            //Tank t = (Tank)agent;
            foreach (var pair in Match.instance.GetStars())
            {
                Star s = pair.Value;
                if (s.IsSuperStar)
                {
                    workingMemory.SetValue((int)EBBKey.MovingTargetPos, Vector3.zero);
                    return(true);
                }
            }
            if (Time.time + 7 > 0.5f * Match.instance.GlobalSetting.MatchTime && Time.time - 1 < 0.5f * Match.instance.GlobalSetting.MatchTime)
            {
                workingMemory.SetValue((int)EBBKey.MovingTargetPos, Vector3.zero);
                return(true);
            }

            return(false);
        }
Пример #8
0
        protected override bool OnEvaluate(IAgent agent, BlackboardMemory workingMemory)
        {
            Vector3 targetPos;

            if (workingMemory.TryGetValue((int)EBBKey.MovingTargetPos, out targetPos))
            {
                Tank t = (Tank)agent;
                if (Vector3.Distance(targetPos, t.Position) >= 1f)
                {
                    return(false);
                }
            }
            workingMemory.SetValue((int)EBBKey.MovingTargetPos, GetNextDestination());
            return(true);
        }
Пример #9
0
        protected override bool OnEvaluate(IAgent agent, BlackboardMemory workingMemory)
        {
            Tank  t         = (Tank)agent;
            Tank  oppTank   = Match.instance.GetOppositeTank(t.Team);
            float SleepTime = 2f;
            float LastTime  = 0.2f;

            if (CanExecute() == false)
            {
                return(false);
            }
            else
            {
                lastExecuteTime = Time.time + SleepTime;
                nextExecuteTime = Time.time + LastTime;
                Vector3 link   = oppTank.Position - t.Position;
                Vector3 result = (Quaternion.AngleAxis(90, Vector3.up) * link).normalized * 5;
                workingMemory.SetValue((int)EBBKey.MovingTargetPos, t.Position + result);
                return(true);
            }
        }
Пример #10
0
        protected override bool OnEvaluate(IAgent agent, BlackboardMemory workingMemory)
        {
            Tank  t           = (Tank)agent;
            float nearestDist = float.MaxValue;

            foreach (var pair in Match.instance.GetStars())
            {
                Star s = pair.Value;

                float dist = (s.Position - t.Position).sqrMagnitude;
                if (dist < nearestDist)
                {
                    nearestDist = dist;
                }
            }
            if (t.HP <= 30 && nearestDist > 300)
            {
                workingMemory.SetValue((int)EBBKey.MovingTargetPos, Match.instance.GetRebornPos(t.Team));
                return(true);
            }
            return(false);
        }
Пример #11
0
 protected override ERunningStatus OnExecute(IAgent agent, BlackboardMemory workingMemory)
 {
     workingMemory.SetValue((int)EBBKey.MovingTargetPos, new Vector3(0, 0, 0));
     return(ERunningStatus.Finished);
 }
Пример #12
0
 protected override bool OnEvaluate(IAgent agent, BlackboardMemory workingMemory)
 {
     workingMemory.SetValue((int)EBBKey.MovingTargetPos, new Vector3(0, 0, 0));
     return(true);
 }