コード例 #1
0
        public void CreatePatrolArea(LogicGameObject patrolPost, LogicLevel level, bool unk, int idx)
        {
            LogicArrayList <LogicVector2> wayPoints = new LogicArrayList <LogicVector2>(8);

            if (this.m_patrolPost == null)
            {
                this.m_patrolPost = patrolPost;
            }

            int startX = 0;
            int startY = 0;
            int endX   = 0;
            int endY   = 0;
            int midX   = 0;
            int midY   = 0;

            int width  = 0;
            int height = 0;

            int radius = 0;

            if (patrolPost != null)
            {
                startX = patrolPost.GetX() - 128;
                startY = patrolPost.GetY() - 128;
                endX   = patrolPost.GetX() + (patrolPost.GetWidthInTiles() << 9) + 128;
                endY   = patrolPost.GetY() + (patrolPost.GetHeightInTiles() << 9) + 128;
                midX   = patrolPost.GetMidX();
                midY   = patrolPost.GetMidY();
                width  = patrolPost.GetWidthInTiles() << 8;
                height = patrolPost.GetHeightInTiles() << 8;
                radius = 1536;
            }

            if (radius * radius >= (uint)(width * width + height * height))
            {
                LogicVector2 tmp1 = new LogicVector2();
                LogicVector2 tmp2 = new LogicVector2();
                LogicVector2 tmp3 = new LogicVector2();
                LogicVector2 tmp4 = new LogicVector2();

                tmp2.Set(midX, midY);

                int rnd = patrolPost.GetLevel().GetLogicTime().GetTick() + idx;

                midX = midX + 127 * rnd % 1024 - 512;
                midY = midY + 271 * rnd % 1024 - 512;

                for (int i = 0, j = 45; i < 4; i++, j += 90)
                {
                    tmp1.Set(midX + LogicMath.Cos(j, radius), midY + LogicMath.Sin(j, radius));
                    LogicHeroBaseComponent.FindPoint(patrolPost.GetLevel().GetTileMap(), tmp3, tmp2, tmp1, tmp4);
                    wayPoints.Add(new LogicVector2(tmp4.m_x, tmp4.m_y));
                }

                tmp1.Destruct();
                tmp2.Destruct();
                tmp3.Destruct();
                tmp4.Destruct();
            }
            else
            {
                wayPoints.Add(new LogicVector2(endX, endY));
                wayPoints.Add(new LogicVector2(startX, endY));
                wayPoints.Add(new LogicVector2(startX, startY));
                wayPoints.Add(new LogicVector2(endX, startY));
            }

            this.ClearPatrolArea();

            this.m_wayPoints         = wayPoints;
            this.m_patrolAreaCounter = 0;

            if (this.m_wayPoints.Size() > 1)
            {
                int closestLength = 0x7FFFFFFF;

                for (int i = 1, size = this.m_wayPoints.Size(); i < size; i++)
                {
                    LogicVector2 wayPoint = this.m_wayPoints[i];

                    int length = (wayPoint.m_x - (this.m_position.m_x >> 16)) * (wayPoint.m_x - (this.m_position.m_x >> 16)) +
                                 (wayPoint.m_y - (this.m_position.m_y >> 16)) * (wayPoint.m_y - (this.m_position.m_y >> 16));

                    if (length < closestLength)
                    {
                        this.m_patrolAreaCounter = i;
                        closestLength            = length;
                    }
                }
            }

            this.MoveTo(this.m_wayPoints[this.m_patrolAreaCounter].m_x, this.m_wayPoints[this.m_patrolAreaCounter].m_y, level.GetTileMap(), true);
        }