示例#1
0
        protected override void NewPath(ManagerHelper mH)
        {
            List <Vector2> sniperSpots = mH.GetLevel().GetSniperSpots();
            Vector2        endPoint    = GetOriginPosition();

            foreach (Vector2 v in sniperSpots)
            {
                bool validPoint = true;

                foreach (NPC agent in mH.GetNPCManager().GetNPCs())
                {
                    if (agent.GetAffiliation() != affiliation &&
                        NPCManager.IsNPCInRadius(agent, GetOriginPosition(), 200))
                    {
                        validPoint = false;
                        break;
                    }
                }

                if (validPoint)
                {
                    endPoint = v;
                    break;
                }
            }

            mH.GetPathHelper().FindClearPath(GetOriginPosition(), endPoint, mH, path);
        }
示例#2
0
        public void FindEscapePath(Vector2 pA, Vector2 pGTFA, float mD, ManagerHelper mH, float aw, Path path)
        {
            //Add blockers for enemies
            foreach (NPC n in mH.GetNPCManager().GetAllies(NPC.AffliationTypes.black))
            {
                if (NPCManager.IsNPCInRadius(n, pA, aw))
                {
                    int x = -1;
                    int y = -1;

                    for (int adjX = -32; adjX < 32; adjX += 32)
                    {
                        for (int adjY = -32; adjY < 32; adjY += 32)
                        {
                            x = (int)(n.GetOriginPosition().X / nodeSize.X) + adjX;
                            y = (int)(n.GetOriginPosition().Y / nodeSize.Y);

                            if ((y > 0 && y < mH.GetLevel().GetSizeOfLevel().Y) &&
                                (x > 0 && y < mH.GetLevel().GetSizeOfLevel().X))
                            {
                                field[x, y].SetBlocker(true);
                            }
                        }
                    }
                }
            }

            float   farthest = 0;
            float   convenience = mD * mD; //forces dot to go to furtherest location that is easiest to get to
            Vector2 pointB = pA;
            int     nodeX, nodeY;

            //Find best end point
            for (int x = (int)(pA.X - mD) / 32; x < (pA.X + mD); x += 32)
            {
                if (x > 32 && x < mH.GetLevel().GetSizeOfLevel().X)
                {
                    for (var y = (int)(pA.Y - mD); y < (pA.Y + mD); y += 32)
                    {
                        if (y > 0 && y < mH.GetLevel().GetSizeOfLevel().Y - 32)
                        {
                            nodeX = x / 32;
                            nodeY = y / 32;

                            if (!field[nodeX, nodeY].GetBlocker())
                            {
                                var   currentPoint = new Vector2(x, y);
                                float dist         = DistanceSquared(pGTFA, currentPoint);
                                float tempCon      = DistanceSquared(pA, currentPoint);

                                if (convenience > tempCon && dist > farthest)
                                {
                                    farthest    = dist;
                                    convenience = tempCon;
                                    pointB      = currentPoint;
                                }
                            }
                        }
                    }
                }
            }

            FindClearPath(pA, pointB, mH, path);
        }