Example #1
0
        public static void TickLineOfSightTest(IHTNAgent npc, ref NpcPlayerInfo info)
        {
            BearDomain aiDomain = npc.AiDomain as BearDomain;

            if (Object.op_Equality((Object)aiDomain, (Object)null))
            {
                return;
            }
            bool isStanding = aiDomain.BearContext.IsFact(Rust.Ai.HTN.Bear.Facts.IsStandingUp);

            info.HeadVisible = false;
            info.BodyVisible = false;
            if ((double)info.SqrDistance >= (double)aiDomain.BearDefinition.SqrAggroRange(isStanding) || (double)info.ForwardDotDir <= (double)npc.AiDefinition.Sensory.FieldOfViewRadians)
            {
                return;
            }
            float maxDistance = aiDomain.BearDefinition.AggroRange(isStanding);
            Ray   ray1        = BearEnemyPlayersLineOfSightSensor.AimAtBody(npc, ref info);

            if (info.Player.IsVisible(ray1, maxDistance))
            {
                info.BodyVisible = true;
                npc.AiDomain.NpcContext.EnemyPlayersInLineOfSight.Add(info);
            }
            else
            {
                Ray ray2 = BearEnemyPlayersLineOfSightSensor.AimAtHead(npc, ref info);
                if (!info.Player.IsVisible(ray2, maxDistance))
                {
                    return;
                }
                info.HeadVisible = true;
                npc.AiDomain.NpcContext.EnemyPlayersInLineOfSight.Add(info);
            }
        }
Example #2
0
        public static void TickLineOfSightTest(IHTNAgent npc, ref NpcPlayerInfo info)
        {
            BearDomain aiDomain = npc.AiDomain as BearDomain;

            if (aiDomain == null)
            {
                return;
            }
            bool flag = aiDomain.BearContext.IsFact(Facts.IsStandingUp);

            info.HeadVisible = false;
            info.BodyVisible = false;
            if (info.SqrDistance < aiDomain.BearDefinition.SqrAggroRange(flag) && info.ForwardDotDir > npc.AiDefinition.Sensory.FieldOfViewRadians)
            {
                float single = aiDomain.BearDefinition.AggroRange(flag);
                Ray   ray    = BearEnemyPlayersLineOfSightSensor.AimAtBody(npc, ref info);
                if (info.Player.IsVisible(ray, single))
                {
                    info.BodyVisible = true;
                    npc.AiDomain.NpcContext.EnemyPlayersInLineOfSight.Add(info);
                    return;
                }
                ray = BearEnemyPlayersLineOfSightSensor.AimAtHead(npc, ref info);
                if (info.Player.IsVisible(ray, single))
                {
                    info.HeadVisible = true;
                    npc.AiDomain.NpcContext.EnemyPlayersInLineOfSight.Add(info);
                }
            }
        }
        public BearContext(HTNAnimal body, BearDomain domain)
        {
            int length = System.Enum.GetValues(typeof(Facts)).Length;

            if (this._worldState == null || this._worldState.Length != length)
            {
                this._worldState         = new byte[length];
                this._previousWorldState = new byte[length];
                if (BearContext._worldStateChanges == null)
                {
                    BearContext._worldStateChanges = new Stack <WorldStateInfo> [length];
                    for (int index = 0; index < length; ++index)
                    {
                        BearContext._worldStateChanges[index] = new Stack <WorldStateInfo>(5);
                    }
                }
            }
            this._decompositionScore = int.MaxValue;
            this.Body      = body;
            this.Domain    = domain;
            this.PlanState = (PlanStateType)0;
            if (this.Memory != null && this.Memory.BearContext == this)
            {
                return;
            }
            this.Memory = new BearMemory(this);
        }
        public BearContext(HTNAnimal body, BearDomain domain)
        {
            int length = Enum.GetValues(typeof(Facts)).Length;

            if (this._worldState == null || (int)this._worldState.Length != length)
            {
                this._worldState         = new byte[length];
                this._previousWorldState = new byte[length];
                if (BearContext._worldStateChanges == null)
                {
                    BearContext._worldStateChanges = new Stack <WorldStateInfo> [length];
                    for (int i = 0; i < length; i++)
                    {
                        BearContext._worldStateChanges[i] = new Stack <WorldStateInfo>(5);
                    }
                }
            }
            this._decompositionScore = 2147483647;
            this.Body      = body;
            this.Domain    = domain;
            this.PlanState = PlanStateType.NoPlan;
            if (this.Memory == null || this.Memory.BearContext != this)
            {
                this.Memory = new BearMemory(this);
            }
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            BearDomain aiDomain = npc.AiDomain as BearDomain;

            if (Object.op_Equality((Object)aiDomain, (Object)null) || aiDomain.BearContext == null)
            {
                return;
            }
            AnimalsInRangeSensor.QueryResultCount = BaseEntity.Query.Server.GetInSphere(npc.transform.get_position(), npc.AiDefinition.Engagement.MediumRange, (BaseEntity[])AnimalsInRangeSensor.QueryResults, (Func <BaseEntity, bool>)(entity =>
            {
                BaseNpc baseNpc = entity as BaseNpc;
                return(!Object.op_Equality((Object)baseNpc, (Object)null) && baseNpc.isServer && (!baseNpc.IsDestroyed && !Object.op_Equality((Object)((Component)baseNpc).get_transform(), (Object)null)) && !baseNpc.IsDead());
            }));
            List <AnimalInfo> animalsInRange = npc.AiDomain.NpcContext.AnimalsInRange;

            if (AnimalsInRangeSensor.QueryResultCount > 0)
            {
                for (int index1 = 0; index1 < AnimalsInRangeSensor.QueryResultCount; ++index1)
                {
                    BaseNpc queryResult  = AnimalsInRangeSensor.QueryResults[index1];
                    Vector3 vector3      = Vector3.op_Subtraction(((Component)queryResult).get_transform().get_position(), npc.transform.get_position());
                    float   sqrMagnitude = ((Vector3) ref vector3).get_sqrMagnitude();
                    if ((double)sqrMagnitude <= (double)npc.AiDefinition.Engagement.SqrMediumRange)
                    {
                        bool flag = false;
                        for (int index2 = 0; index2 < animalsInRange.Count; ++index2)
                        {
                            AnimalInfo animalInfo = animalsInRange[index2];
                            if (Object.op_Equality((Object)animalInfo.Animal, (Object)queryResult))
                            {
                                animalInfo.Time        = time;
                                animalInfo.SqrDistance = sqrMagnitude;
                                animalsInRange[index2] = animalInfo;
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            animalsInRange.Add(new AnimalInfo()
                            {
                                Animal      = queryResult,
                                Time        = time,
                                SqrDistance = sqrMagnitude
                            });
                        }
                    }
                }
            }
            for (int index = 0; index < animalsInRange.Count; ++index)
            {
                AnimalInfo animalInfo = animalsInRange[index];
                if ((double)time - (double)animalInfo.Time > (double)npc.AiDefinition.Memory.ForgetAnimalInRangeTime)
                {
                    animalsInRange.RemoveAt(index);
                    --index;
                }
            }
        }
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            BearContext npcContext = npc.AiDomain.NpcContext as BearContext;

            if (npcContext == null)
            {
                return;
            }
            BearDomain aiDomain = npc.AiDomain as BearDomain;

            if (aiDomain == null)
            {
                return;
            }
            npcContext.SetFact(Facts.CanSeeEnemy, npcContext.EnemyPlayersInLineOfSight.Count > 0, true, true, true);
            bool          flag          = aiDomain.BearContext.IsFact(Facts.IsStandingUp);
            float         single        = 0f;
            NpcPlayerInfo npcPlayerInfo = new NpcPlayerInfo();

            foreach (NpcPlayerInfo enemyPlayersInLineOfSight in npc.AiDomain.NpcContext.EnemyPlayersInLineOfSight)
            {
                float forwardDotDir = (enemyPlayersInLineOfSight.ForwardDotDir + 1f) * 0.5f;
                float sqrDistance   = (1f - enemyPlayersInLineOfSight.SqrDistance / aiDomain.BearDefinition.SqrAggroRange(flag)) * 2f + forwardDotDir;
                if (sqrDistance > single)
                {
                    single        = sqrDistance;
                    npcPlayerInfo = enemyPlayersInLineOfSight;
                }
                NpcPlayerInfo npcPlayerInfo1 = enemyPlayersInLineOfSight;
                npcPlayerInfo1.VisibilityScore = sqrDistance;
                npcContext.Memory.RememberEnemyPlayer(npc, ref npcPlayerInfo1, time, 0f, "SEE!");
            }
            npcContext.PrimaryEnemyPlayerInLineOfSight = npcPlayerInfo;
            if (npcPlayerInfo.Player != null && (npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player == null || npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.AudibleScore < single))
            {
                npcContext.Memory.RememberPrimaryEnemyPlayer(npcPlayerInfo.Player);
                npcContext.IncrementFact(Facts.Alertness, 2, true, true, true);
            }
        }
Example #7
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            BearContext npcContext = npc.AiDomain.NpcContext as BearContext;

            if (npcContext == null)
            {
                return;
            }
            BearDomain aiDomain = npc.AiDomain as BearDomain;

            if (Object.op_Equality((Object)aiDomain, (Object)null))
            {
                return;
            }
            npcContext.SetFact(Facts.CanSeeEnemy, npcContext.EnemyPlayersInLineOfSight.Count > 0, true, true, true);
            bool          isStanding     = aiDomain.BearContext.IsFact(Facts.IsStandingUp);
            float         num1           = 0.0f;
            NpcPlayerInfo npcPlayerInfo1 = new NpcPlayerInfo();

            foreach (NpcPlayerInfo npcPlayerInfo2 in npc.AiDomain.NpcContext.EnemyPlayersInLineOfSight)
            {
                float num2 = (float)((1.0 - (double)npcPlayerInfo2.SqrDistance / (double)aiDomain.BearDefinition.SqrAggroRange(isStanding)) * 2.0) + (float)(((double)npcPlayerInfo2.ForwardDotDir + 1.0) * 0.5);
                if ((double)num2 > (double)num1)
                {
                    num1           = num2;
                    npcPlayerInfo1 = npcPlayerInfo2;
                }
                NpcPlayerInfo info = npcPlayerInfo2;
                info.VisibilityScore = num2;
                npcContext.Memory.RememberEnemyPlayer(npc, ref info, time, 0.0f, "SEE!");
            }
            npcContext.PrimaryEnemyPlayerInLineOfSight = npcPlayerInfo1;
            if (!Object.op_Inequality((Object)npcPlayerInfo1.Player, (Object)null) || !Object.op_Equality((Object)npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.Player, (Object)null) && (double)npcContext.Memory.PrimaryKnownEnemyPlayer.PlayerInfo.AudibleScore >= (double)num1)
            {
                return;
            }
            npcContext.Memory.RememberPrimaryEnemyPlayer(npcPlayerInfo1.Player);
            npcContext.IncrementFact(Facts.Alertness, 2, true, true, true);
        }
Example #8
0
        public void Tick(IHTNAgent npc, float deltaTime, float time)
        {
            BearDomain aiDomain = npc.AiDomain as BearDomain;

            if (aiDomain == null || aiDomain.BearContext == null)
            {
                return;
            }
            AnimalsInRangeSensor.QueryResultCount = BaseEntity.Query.Server.GetInSphere(npc.transform.position, npc.AiDefinition.Engagement.MediumRange, AnimalsInRangeSensor.QueryResults, (BaseEntity entity) => {
                BaseNpc baseNpc = entity as BaseNpc;
                if (!(baseNpc == null) && baseNpc.isServer && !baseNpc.IsDestroyed && !(baseNpc.transform == null) && !baseNpc.IsDead())
                {
                    return(true);
                }
                return(false);
            });
            List <AnimalInfo> animalsInRange = npc.AiDomain.NpcContext.AnimalsInRange;

            if (AnimalsInRangeSensor.QueryResultCount > 0)
            {
                for (int i = 0; i < AnimalsInRangeSensor.QueryResultCount; i++)
                {
                    BaseNpc queryResults = AnimalsInRangeSensor.QueryResults[i];
                    Vector3 vector3      = queryResults.transform.position - npc.transform.position;
                    float   single       = vector3.sqrMagnitude;
                    if (single <= npc.AiDefinition.Engagement.SqrMediumRange)
                    {
                        bool flag = false;
                        int  num  = 0;
                        while (num < animalsInRange.Count)
                        {
                            AnimalInfo item = animalsInRange[num];
                            if (item.Animal != queryResults)
                            {
                                num++;
                            }
                            else
                            {
                                item.Time           = time;
                                item.SqrDistance    = single;
                                animalsInRange[num] = item;
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            AnimalInfo animalInfo = new AnimalInfo()
                            {
                                Animal      = queryResults,
                                Time        = time,
                                SqrDistance = single
                            };
                            animalsInRange.Add(animalInfo);
                        }
                    }
                }
            }
            for (int j = 0; j < animalsInRange.Count; j++)
            {
                if (time - animalsInRange[j].Time > npc.AiDefinition.Memory.ForgetAnimalInRangeTime)
                {
                    animalsInRange.RemoveAt(j);
                    j--;
                }
            }
        }