public Vector3 GetBestPositionNear(Vector3 targetPosition, Vector3 fromPosition, float minRange, float maxRange, bool checkLOS = false)
    {
        AIMovePoint aIMovePoint = null;
        float       single      = -1f;

        foreach (AIMovePoint movePoint in this.movePoints)
        {
            float   single1 = 0f;
            Vector3 vector3 = movePoint.transform.position;
            float   single2 = Vector3.Distance(targetPosition, vector3);
            if (single2 > maxRange || !movePoint.transform.parent.gameObject.activeSelf)
            {
                continue;
            }
            single1 = single1 + (1f - Mathf.InverseLerp(minRange, maxRange, single2)) * 100f;
            if (checkLOS && Physics.Linecast(targetPosition + (Vector3.up * 1f), vector3 + (Vector3.up * 1f), 1218650369, QueryTriggerInteraction.Ignore) || single1 <= single)
            {
                continue;
            }
            aIMovePoint = movePoint;
            single      = single1;
        }
        if (aIMovePoint == null)
        {
            return(targetPosition);
        }
        return(aIMovePoint.transform.position);
    }
Beispiel #2
0
    public AIMovePoint GetBestMovePointNear(
        Vector3 targetPosition,
        Vector3 fromPosition,
        float minRange,
        float maxRange,
        bool checkLOS        = false,
        BaseEntity forObject = null)
    {
        AIMovePoint aiMovePoint = (AIMovePoint)null;
        float       num1        = -1f;

        foreach (AIMovePoint movePoint in this.movePoints)
        {
            float   num2     = 0.0f;
            Vector3 position = ((Component)movePoint).get_transform().get_position();
            float   num3     = Vector3.Distance(targetPosition, position);
            if ((double)num3 <= (double)maxRange && ((Component)((Component)movePoint).get_transform().get_parent()).get_gameObject().get_activeSelf())
            {
                float num4 = num2 + (movePoint.CanBeUsedBy(forObject) ? 100f : 0.0f) + (float)((1.0 - (double)Mathf.InverseLerp(minRange, maxRange, num3)) * 100.0);
                if ((double)num4 >= (double)num1 && (!checkLOS || !Physics.Linecast(Vector3.op_Addition(targetPosition, Vector3.op_Multiply(Vector3.get_up(), 1f)), Vector3.op_Addition(position, Vector3.op_Multiply(Vector3.get_up(), 1f)), 1218519297, (QueryTriggerInteraction)1)) && (double)num4 > (double)num1)
                {
                    aiMovePoint = movePoint;
                    num1        = num4;
                }
            }
        }
        return(aiMovePoint);
    }
Beispiel #3
0
 public override StateStatus StateThink(float delta)
 {
     base.StateThink(delta);
     if (status == StateStatus.Error)
     {
         return(status);
     }
     if (!brain.Navigator.Moving)
     {
         if (currentWaitTime <= 0f && currentTargetPoint.HasLookAtPoints())
         {
             Transform randomLookAtPoint = currentTargetPoint.GetRandomLookAtPoint();
             if (randomLookAtPoint != null)
             {
                 brain.Navigator.SetFacingDirectionOverride(Vector3Ex.Direction2D(randomLookAtPoint.transform.position, GetEntity().ServerPosition));
             }
         }
         if (currentTargetPoint.WaitTime > 0f)
         {
             currentWaitTime += delta;
         }
         if (currentTargetPoint.WaitTime <= 0f || currentWaitTime >= currentTargetPoint.WaitTime)
         {
             brain.Navigator.ClearFacingDirectionOverride();
             currentWaitTime = 0f;
             AIMovePoint aIMovePoint = currentTargetPoint;
             currentTargetPoint = path.GetNextPoint(currentTargetPoint, ref pathDirection);
             if ((!(currentTargetPoint != null) || !(currentTargetPoint == aIMovePoint)) && (currentTargetPoint == null || !brain.Navigator.SetDestination(currentTargetPoint.transform.position, BaseNavigator.NavigationSpeed.Slow)))
             {
                 return(StateStatus.Error);
             }
         }
     }
     return(StateStatus.Running);
 }
Beispiel #4
0
        public override StateStatus StateThink(float delta)
        {
            base.StateThink(delta);
            bool flag   = UnityEngine.Time.time - lastDestinationTime > 25f;
            T    entity = GetEntity();

            if ((Vector3.Distance(GetDestination(), entity.transform.position) < 2f || flag) && nextRoamPositionTime == -1f)
            {
                nextRoamPositionTime = UnityEngine.Time.time + UnityEngine.Random.Range(5f, 10f);
            }
            if (nextRoamPositionTime != -1f && UnityEngine.Time.time > nextRoamPositionTime)
            {
                AIMovePoint bestRoamPoint = brain.PathFinder.GetBestRoamPoint(GetRoamAnchorPosition(), entity.ServerPosition, GetForwardDirection(), brain.Navigator.MaxRoamDistanceFromHome, brain.Navigator.BestRoamPointMaxDistance);
                if ((bool)bestRoamPoint)
                {
                    float num = Vector3.Distance(bestRoamPoint.transform.position, entity.transform.position) / 1.5f;
                    bestRoamPoint.SetUsedBy(entity, num + 11f);
                }
                lastDestinationTime = UnityEngine.Time.time;
                Vector3 insideUnitSphere = UnityEngine.Random.insideUnitSphere;
                insideUnitSphere.y = 0f;
                insideUnitSphere.Normalize();
                Vector3 destination = ((bestRoamPoint == null) ? entity.transform.position : (bestRoamPoint.transform.position + insideUnitSphere * bestRoamPoint.radius));
                SetDestination(destination);
                nextRoamPositionTime = -1f;
            }
            return(StateStatus.Running);
        }
Beispiel #5
0
        public override void StateEnter()
        {
            base.StateEnter();
            status = StateStatus.Error;
            brain.Navigator.SetBrakingEnabled(false);
            path = brain.Navigator.Path;
            T entity = GetEntity();

            if (path == null)
            {
                AIInformationZone forPoint = AIInformationZone.GetForPoint(entity.ServerPosition);
                if (forPoint == null)
                {
                    return;
                }
                path = forPoint.GetNearestPath(entity.ServerPosition);
                if (path == null)
                {
                    return;
                }
            }
            currentTargetPoint = path.FindNearestPoint(entity.ServerPosition);
            if (!(currentTargetPoint == null))
            {
                status          = StateStatus.Running;
                currentWaitTime = 0f;
                brain.Navigator.SetDestination(currentTargetPoint.transform.position, BaseNavigator.NavigationSpeed.Slow);
            }
        }
Beispiel #6
0
    public Vector3 GetBestPositionNear(
        Vector3 targetPosition,
        Vector3 fromPosition,
        float minRange,
        float maxRange,
        bool checkLOS = false)
    {
        AIMovePoint aiMovePoint = (AIMovePoint)null;
        float       num1        = -1f;

        foreach (AIMovePoint movePoint in this.movePoints)
        {
            float   num2     = 0.0f;
            Vector3 position = ((Component)movePoint).get_transform().get_position();
            float   num3     = Vector3.Distance(targetPosition, position);
            if ((double)num3 <= (double)maxRange && ((Component)((Component)movePoint).get_transform().get_parent()).get_gameObject().get_activeSelf())
            {
                float num4 = num2 + (float)((1.0 - (double)Mathf.InverseLerp(minRange, maxRange, num3)) * 100.0);
                if ((!checkLOS || !Physics.Linecast(Vector3.op_Addition(targetPosition, Vector3.op_Multiply(Vector3.get_up(), 1f)), Vector3.op_Addition(position, Vector3.op_Multiply(Vector3.get_up(), 1f)), 1218650369, (QueryTriggerInteraction)1)) && (double)num4 > (double)num1)
                {
                    aiMovePoint = movePoint;
                    num1        = num4;
                }
            }
        }
        if (Object.op_Inequality((Object)aiMovePoint, (Object)null))
        {
            return(((Component)aiMovePoint).get_transform().get_position());
        }
        return(targetPosition);
    }
    public AIMovePoint GetBestMovePointNear(Vector3 targetPosition, Vector3 fromPosition, float minRange, float maxRange, bool checkLOS = false, BaseEntity forObject = null)
    {
        AIMovePoint aIMovePoint = null;
        float       single      = -1f;

        foreach (AIMovePoint movePoint in this.movePoints)
        {
            float   single1 = 0f;
            Vector3 vector3 = movePoint.transform.position;
            float   single2 = Vector3.Distance(targetPosition, vector3);
            if (single2 > maxRange || !movePoint.transform.parent.gameObject.activeSelf)
            {
                continue;
            }
            single1 = single1 + (movePoint.CanBeUsedBy(forObject) ? 100f : 0f);
            single1 = single1 + (1f - Mathf.InverseLerp(minRange, maxRange, single2)) * 100f;
            if (single1 < single || checkLOS && Physics.Linecast(targetPosition + (Vector3.up * 1f), vector3 + (Vector3.up * 1f), 1218519297, QueryTriggerInteraction.Ignore) || single1 <= single)
            {
                continue;
            }
            aIMovePoint = movePoint;
            single      = single1;
        }
        return(aIMovePoint);
    }
Beispiel #8
0
 private void AddMovePoint(AIMovePoint point)
 {
     if (!movePoints.Contains(point))
     {
         movePoints.Add(point);
         MarkDirty();
     }
 }
Beispiel #9
0
    public AIMovePoint GetNextPoint(AIMovePoint current, ref PathDirection pathDirection)
    {
        int num = 0;

        foreach (AIMovePoint point in Points)
        {
            if (point == current)
            {
                return(GetNextPoint(num, ref pathDirection));
            }
            num++;
        }
        return(null);
    }
Beispiel #10
0
    public AIMovePoint FindNearestPoint(Vector3 position)
    {
        float       num    = float.MaxValue;
        AIMovePoint result = null;

        foreach (AIMovePoint point in Points)
        {
            float num2 = Vector3.SqrMagnitude(position - point.transform.position);
            if (num2 < num)
            {
                num    = num2;
                result = point;
            }
        }
        return(result);
    }
        public override void StateThink(float delta)
        {
            base.StateThink(delta);
            if (Object.op_Equality((Object)this.GetEntity().currentTarget, (Object)null))
            {
                return;
            }
            float num1 = Vector3.Distance(this.GetEntity().currentTarget.ServerPosition, this.GetEntity().ServerPosition);

            if ((double)num1 < 5.0)
            {
                this.GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.SlowWalk);
            }
            else if ((double)num1 < 10.0)
            {
                this.GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Walk);
            }
            else
            {
                this.GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Sprint);
            }
            if ((double)Time.get_time() <= (double)this.nextPositionUpdateTime)
            {
                return;
            }
            double  num2           = (double)Random.Range(1f, 2f);
            Vector3 newDestination = this.GetEntity().ServerPosition;

            if (Object.op_Equality((Object)this.GetEntity().GetInformationZone(), (Object)null))
            {
                return;
            }
            AIMovePoint bestMovePointNear = this.GetEntity().GetInformationZone().GetBestMovePointNear(this.GetEntity().currentTarget.ServerPosition, this.GetEntity().ServerPosition, 0.0f, 35f, true, (BaseEntity)null);

            if (Object.op_Implicit((Object)bestMovePointNear))
            {
                bestMovePointNear.MarkUsedForEngagement(5f, (BaseEntity)this.GetEntity());
                newDestination = this.GetEntity().GetRandomPositionAround(((Component)bestMovePointNear).get_transform().get_position(), 0.0f, bestMovePointNear.radius - 0.3f);
            }
            else
            {
                this.GetEntity().GetRandomPositionAround(this.GetEntity().currentTarget.ServerPosition, 1f, 2f);
            }
            this.GetEntity().SetDestination(newDestination);
        }
    public AIMovePoint GetBestRoamPosition(Vector3 start)
    {
        AIInformationZone informationZone = this.GetInformationZone();

        if (informationZone == null)
        {
            return(null);
        }
        float       single      = -1f;
        AIMovePoint aIMovePoint = null;

        foreach (AIMovePoint movePoint in informationZone.movePoints)
        {
            if (!movePoint.transform.parent.gameObject.activeSelf)
            {
                continue;
            }
            float single1 = 0f;
            float single2 = Vector3.Dot(this.eyes.BodyForward(), Vector3Ex.Direction2D(movePoint.transform.position, this.eyes.position));
            single1 = single1 + Mathf.InverseLerp(-1f, 1f, single2) * 100f;
            float single3 = Vector3.Distance(this.ServerPosition, movePoint.transform.position);
            if (movePoint.IsUsedForRoaming())
            {
                continue;
            }
            float single4 = Mathf.Abs(this.ServerPosition.y - movePoint.transform.position.y);
            single1 = single1 + (1f - Mathf.InverseLerp(1f, 10f, single4)) * 100f;
            if (single4 > 5f)
            {
                continue;
            }
            if (single3 > 5f)
            {
                single1 = single1 + (1f - Mathf.InverseLerp(5f, 20f, single3)) * 50f;
            }
            if (single1 <= single)
            {
                continue;
            }
            aIMovePoint = movePoint;
            single      = single1;
        }
        return(aIMovePoint);
    }
        public override void StateThink(float delta)
        {
            base.StateThink(delta);
            if (base.GetEntity().currentTarget == null)
            {
                return;
            }
            float single = Vector3.Distance(base.GetEntity().currentTarget.ServerPosition, base.GetEntity().ServerPosition);

            if (single < 5f)
            {
                base.GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.SlowWalk);
            }
            else if (single >= 10f)
            {
                base.GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Sprint);
            }
            else
            {
                base.GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Walk);
            }
            if (Time.time > this.nextPositionUpdateTime)
            {
                UnityEngine.Random.Range(1f, 2f);
                Vector3 serverPosition = base.GetEntity().ServerPosition;
                if (base.GetEntity().GetInformationZone() == null)
                {
                    return;
                }
                AIMovePoint bestMovePointNear = base.GetEntity().GetInformationZone().GetBestMovePointNear(base.GetEntity().currentTarget.ServerPosition, base.GetEntity().ServerPosition, 0f, 35f, true, null);
                if (!bestMovePointNear)
                {
                    base.GetEntity().GetRandomPositionAround(base.GetEntity().currentTarget.ServerPosition, 1f, 2f);
                }
                else
                {
                    bestMovePointNear.MarkUsedForEngagement(5f, base.GetEntity());
                    serverPosition = bestMovePointNear.transform.position;
                    serverPosition = base.GetEntity().GetRandomPositionAround(serverPosition, 0f, bestMovePointNear.radius - 0.3f);
                }
                base.GetEntity().SetDestination(serverPosition);
            }
        }
Beispiel #14
0
    private AIMovePoint GetClosestRaw(Vector3 pos, bool onlyIncludeWithCover = false)
    {
        AIMovePoint result = null;
        float       num    = float.PositiveInfinity;

        foreach (AIMovePoint movePoint in movePoints)
        {
            if (!onlyIncludeWithCover || movePoint.distancesToCover.Count != 0)
            {
                float num2 = Vector3.Distance(movePoint.transform.position, pos);
                if (num2 < num)
                {
                    num    = num2;
                    result = movePoint;
                }
            }
        }
        return(result);
    }
Beispiel #15
0
    // Pointを配列に格納する
    void SetPoints()
    {
        // ステージ上のチェックポイントをすべて取得
        GameObject[] obj = GameObject.FindGameObjectsWithTag("AI_CheckPoint");
        PointT     = new Transform[obj.Length];
        S_AImoveP  = new AIMovePoint[obj.Length];
        myMoveCost = new float[obj.Length];
        myMoveFlag = new bool[obj.Length];

        // チェックポイントの情報を保存しておく
        for (int i = 0; i < obj.Length; i++)
        {
            AIMovePoint scr = obj[i].GetComponent <AIMovePoint>(); // スクリプト
            int         num = scr.MyNumber;                        // そのポイントに振り分けられた番号
            // Pointを番号順になるように配列に格納
            PointT[num]     = obj[i].transform;                    // ポイントの座標
            S_AImoveP[num]  = scr;                                 // ポイントのスクリプト
            myMoveCost[num] = 0f;                                  // コスト
        }
    }
Beispiel #16
0
        public override StateStatus StateThink(float delta)
        {
            base.StateThink(delta);
            if (GetEntity().currentTarget == null)
            {
                return(StateStatus.Error);
            }
            float num = Vector3.Distance(GetEntity().currentTarget.transform.position, GetEntity().transform.position);

            if (num < 5f)
            {
                GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.SlowWalk);
            }
            else if (num < 10f)
            {
                GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Walk);
            }
            else
            {
                GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Sprint);
            }
            if (Time.time > nextPositionUpdateTime)
            {
                Random.Range(1f, 2f);
                Vector3     position    = GetEntity().transform.position;
                AIMovePoint aIMovePoint = GetEntity().GetInformationZone(GetEntity().currentTarget.transform.position).GetBestMovePointNear(maxRange: Mathf.Min(35f, GetEntity().EngagementRange() * 0.75f), targetPosition: GetEntity().currentTarget.transform.position, fromPosition: GetEntity().transform.position, minRange: 0f, checkLOS: true, forObject: GetEntity(), returnClosest: true);
                if ((bool)aIMovePoint)
                {
                    aIMovePoint.SetUsedBy(GetEntity(), 5f);
                    position = aIMovePoint.transform.position;
                    position = GetEntity().GetRandomPositionAround(position, 0f, aIMovePoint.radius - 0.3f);
                }
                else
                {
                    position = GetEntity().GetRandomPositionAround(GetEntity().currentTarget.transform.position, 1f);
                }
                GetEntity().SetDestination(position);
                nextPositionUpdateTime = Time.time + 1f;
            }
            return(StateStatus.Running);
        }
        public override void StateThink(float delta)
        {
            base.StateThink(delta);
            if ((double)Vector3.Distance(this.GetEntity().finalDestination, this.GetEntity().ServerPosition) < 2.0 | (double)Time.get_time() - (double)this.lastDestinationTime > 25.0 && (double)this.nextRoamPositionTime == -1.0)
            {
                this.nextRoamPositionTime = Time.get_time() + Random.Range(5f, 10f);
            }
            if ((double)this.nextRoamPositionTime == -1.0 || (double)Time.get_time() <= (double)this.nextRoamPositionTime)
            {
                return;
            }
            AIMovePoint bestRoamPosition = this.GetEntity().GetBestRoamPosition(this.GetEntity().ServerPosition);

            if (Object.op_Implicit((Object)bestRoamPosition))
            {
                float num = Vector3.Distance(((Component)bestRoamPosition).get_transform().get_position(), this.GetEntity().ServerPosition) / 1.5f;
                bestRoamPosition.MarkUsedForRoam(num + 11f, (BaseEntity)null);
            }
            this.lastDestinationTime = Time.get_time();
            this.GetEntity().SetDestination(Object.op_Equality((Object)bestRoamPosition, (Object)null) ? this.GetEntity().ServerPosition : ((Component)bestRoamPosition).get_transform().get_position());
            this.nextRoamPositionTime = -1f;
        }
Beispiel #18
0
    public AIMovePoint GetBestRoamPosition(Vector3 start)
    {
        AIInformationZone informationZone = this.GetInformationZone();

        if (Object.op_Equality((Object)informationZone, (Object)null))
        {
            return((AIMovePoint)null);
        }
        float       num1        = -1f;
        AIMovePoint aiMovePoint = (AIMovePoint)null;

        foreach (AIMovePoint movePoint in informationZone.movePoints)
        {
            if (((Component)((Component)movePoint).get_transform().get_parent()).get_gameObject().get_activeSelf())
            {
                float num2 = 0.0f + Mathf.InverseLerp(-1f, 1f, Vector3.Dot(this.eyes.BodyForward(), Vector3Ex.Direction2D(((Component)movePoint).get_transform().get_position(), this.eyes.position))) * 100f;
                float num3 = Vector3.Distance(this.ServerPosition, ((Component)movePoint).get_transform().get_position());
                if (!movePoint.IsUsedForRoaming())
                {
                    float num4 = Mathf.Abs((float)(this.ServerPosition.y - ((Component)movePoint).get_transform().get_position().y));
                    float num5 = num2 + (float)((1.0 - (double)Mathf.InverseLerp(1f, 10f, num4)) * 100.0);
                    if ((double)num4 <= 5.0)
                    {
                        if ((double)num3 > 5.0)
                        {
                            num5 += (float)((1.0 - (double)Mathf.InverseLerp(5f, 20f, num3)) * 50.0);
                        }
                        if ((double)num5 > (double)num1)
                        {
                            aiMovePoint = movePoint;
                            num1        = num5;
                        }
                    }
                }
            }
        }
        return(aiMovePoint);
    }
        public override void StateThink(float delta)
        {
            Vector3 vector3;

            base.StateThink(delta);
            if (Vector3.Distance(base.GetEntity().finalDestination, base.GetEntity().ServerPosition) < 2f | Time.time - this.lastDestinationTime > 25f && this.nextRoamPositionTime == -1f)
            {
                this.nextRoamPositionTime = Time.time + UnityEngine.Random.Range(5f, 10f);
            }
            if (this.nextRoamPositionTime != -1f && Time.time > this.nextRoamPositionTime)
            {
                AIMovePoint bestRoamPosition = base.GetEntity().GetBestRoamPosition(base.GetEntity().ServerPosition);
                if (bestRoamPosition)
                {
                    float single = Vector3.Distance(bestRoamPosition.transform.position, base.GetEntity().ServerPosition) / 1.5f;
                    bestRoamPosition.MarkUsedForRoam(single + 11f, null);
                }
                this.lastDestinationTime = Time.time;
                vector3 = (bestRoamPosition == null ? base.GetEntity().ServerPosition : bestRoamPosition.transform.position);
                base.GetEntity().SetDestination(vector3);
                this.nextRoamPositionTime = -1f;
            }
        }
Beispiel #20
0
    public bool ProcessDistancesAttempt()
    {
        float realtimeSinceStartup = UnityEngine.Time.realtimeSinceStartup;
        float budgetSeconds        = AIThinkManager.framebudgetms / 1000f * 0.25f;

        if (realtimeSinceStartup < lastNavmeshBuildTime + 60f)
        {
            budgetSeconds = 0.1f;
        }
        int         areaMask    = 1 << NavMesh.GetAreaFromName("HumanNPC");
        NavMeshPath navMeshPath = new NavMeshPath();

        while (PassesBudget(realtimeSinceStartup, budgetSeconds))
        {
            AIMovePoint aIMovePoint = movePoints[processIndex];
            bool        flag        = true;
            int         num         = 0;
            for (int num2 = aIMovePoint.distances.Keys.Count - 1; num2 >= 0; num2--)
            {
                AIMovePoint aIMovePoint2 = aIMovePoint.distances.Keys[num2];
                if (!movePoints.Contains(aIMovePoint2))
                {
                    aIMovePoint.distances.Remove(aIMovePoint2);
                }
            }
            for (int num3 = aIMovePoint.distancesToCover.Keys.Count - 1; num3 >= 0; num3--)
            {
                AICoverPoint aICoverPoint = aIMovePoint.distancesToCover.Keys[num3];
                if (!coverPoints.Contains(aICoverPoint))
                {
                    num++;
                    aIMovePoint.distancesToCover.Remove(aICoverPoint);
                }
            }
            foreach (AICoverPoint coverPoint in coverPoints)
            {
                if (coverPoint == null || aIMovePoint.distancesToCover.Contains(coverPoint))
                {
                    continue;
                }
                float num4 = -1f;
                if (Vector3.Distance(aIMovePoint.transform.position, coverPoint.transform.position) > 40f)
                {
                    num4 = -2f;
                }
                else if (NavMesh.CalculatePath(aIMovePoint.transform.position, coverPoint.transform.position, areaMask, navMeshPath) && navMeshPath.status == NavMeshPathStatus.PathComplete)
                {
                    int num5 = navMeshPath.corners.Length;
                    if (num5 > 1)
                    {
                        Vector3 a    = navMeshPath.corners[0];
                        float   num6 = 0f;
                        for (int i = 0; i < num5; i++)
                        {
                            Vector3 vector = navMeshPath.corners[i];
                            num6 += Vector3.Distance(a, vector);
                            a     = vector;
                        }
                        num4 = num6;
                        pathSuccesses++;
                    }
                    else
                    {
                        num4 = Vector3.Distance(aIMovePoint.transform.position, coverPoint.transform.position);
                        halfPaths++;
                    }
                }
                else
                {
                    pathFails++;
                    num4 = -2f;
                }
                aIMovePoint.distancesToCover.Add(coverPoint, num4);
                if (!PassesBudget(realtimeSinceStartup, budgetSeconds))
                {
                    flag = false;
                    break;
                }
            }
            if (flag)
            {
                processIndex++;
            }
            if (processIndex >= movePoints.Count - 1)
            {
                break;
            }
        }
        return(processIndex == movePoints.Count - 1);
    }
Beispiel #21
0
 public void AddPoint(AIMovePoint point)
 {
     Points.Add(point);
 }
Beispiel #22
0
    // 経路を作る(Pointの番号指定)    0:赤に行くとき、1:青に行くとき
    public List <Vector3> SearchRoute(int num)
    {
        List <Vector3> _route = new List <Vector3>();

        // 自分の場所から一番近いPointを探す
        int myPPos = GetNearPoint(transform.position);


        //// 保持していたルートが使いまわせないか調べる
        //if(myRoute.Count > 0) {
        //    if (myRoute.LastIndexOf(0) == num) {    // 今回の目的地と前回の目的地が一緒だったら
        //        for(int i = 0; i < myRoute.Count; i++) {
        //            if(myRoute[i] == myPPos) {
        //                for (int j = i; j < myRoute.Count; j++) {
        //                    _route.Add(PointT[myRoute[j]].position);
        //                }
        //                return _route;
        //            }
        //        }
        //    }
        //}


        // 初期化
        myRoute.Clear();
        myRouteCount = 0;

        // 一番最初の目的地を自分の近くのpointにする
        myRoute.Add(myPPos);

        int  con   = 0;
        bool _flag = false;

        // 経路を探索する
        while (true)
        {
            // 目的地まで探索出来たら終了する
            if (S_AImoveP[myRoute[con]].MyNumber == num || _flag)
            {
                for (int i = 0; i < myRoute.Count; i++)
                {
                    _route.Add(PointT[myRoute[i]].position);
                }
                return(_route);
            }

            // 目的地別にルートを探す
            if (num == 0)           // 赤へ行くとき
            {
                AIMovePoint p = S_AImoveP[myRoute[con]];
                if (p.GoRed.Length == 0)
                {
                    _flag = true;
                    continue;
                }
                int n = Random.Range(0, p.GoRed.Length);
                myRoute.Add(p.GoRed[n].MyNumber);
            }
            else if (num == 1)      // 青へ行くとき
            {
                AIMovePoint p = S_AImoveP[myRoute[con]];
                if (p.GoBlue.Length == 0)
                {
                    _flag = true;
                    continue;
                }
                int n = Random.Range(0, p.GoBlue.Length);
                myRoute.Add(p.GoBlue[n].MyNumber);
            }

            con++;
        }
    }
Beispiel #23
0
 private void RemoveMovePoint(AIMovePoint point)
 {
     movePoints.Remove(point);
     MarkDirty();
 }
Beispiel #24
0
    public AICoverPoint GetBestCoverPoint(Vector3 currentPosition, Vector3 hideFromPosition, float minRange = 0f, float maxRange = 20f, BaseEntity forObject = null, bool allowObjectToReuse = true)
    {
        AICoverPoint aICoverPoint = null;
        float        num          = 0f;
        AIMovePoint  closestRaw   = GetClosestRaw(currentPosition, true);
        int          pointCount;

        AICoverPoint[] coverPointsInRange = GetCoverPointsInRange(currentPosition, maxRange, out pointCount);
        if (coverPointsInRange == null || pointCount <= 0)
        {
            return(null);
        }
        for (int i = 0; i < pointCount; i++)
        {
            AICoverPoint aICoverPoint2 = coverPointsInRange[i];
            Vector3      position      = aICoverPoint2.transform.position;
            Vector3      normalized    = (hideFromPosition - position).normalized;
            float        num2          = Vector3.Dot(aICoverPoint2.transform.forward, normalized);
            if (num2 < 1f - aICoverPoint2.coverDot)
            {
                continue;
            }
            float num3 = -1f;
            if (UseCalculatedCoverDistances && closestRaw != null && closestRaw.distancesToCover.Contains(aICoverPoint2) && !isDirty)
            {
                num3 = closestRaw.distancesToCover[aICoverPoint2];
                if (num3 == -2f)
                {
                    continue;
                }
            }
            else
            {
                num3 = Vector3.Distance(currentPosition, position);
            }
            float num4 = 0f;
            if (aICoverPoint2.InUse())
            {
                bool flag = aICoverPoint2.IsUsedBy(forObject);
                if (!(allowObjectToReuse && flag))
                {
                    num4 -= 1000f;
                }
            }
            if (minRange > 0f)
            {
                num4 -= (1f - Mathf.InverseLerp(0f, minRange, num3)) * 100f;
            }
            float value = Mathf.Abs(position.y - currentPosition.y);
            num4 += (1f - Mathf.InverseLerp(1f, 5f, value)) * 500f;
            num4 += Mathf.InverseLerp(1f - aICoverPoint2.coverDot, 1f, num2) * 50f;
            num4 += (1f - Mathf.InverseLerp(2f, maxRange, num3)) * 100f;
            float num5   = 1f - Mathf.InverseLerp(4f, 10f, Vector3.Distance(currentPosition, hideFromPosition));
            float value2 = Vector3.Dot((aICoverPoint2.transform.position - currentPosition).normalized, normalized);
            num4 -= Mathf.InverseLerp(-1f, 0.25f, value2) * 50f * num5;
            if (num4 > num)
            {
                aICoverPoint = aICoverPoint2;
                num          = num4;
            }
        }
        if ((bool)aICoverPoint)
        {
            return(aICoverPoint);
        }
        return(null);
    }