public LogicPathFinderOld(LogicTileMap tileMap) : base(tileMap)
        {
            if (tileMap != null)
            {
                this.m_mapWidth  = 2 * tileMap.GetSizeX();
                this.m_mapHeight = 2 * tileMap.GetSizeY();
            }
            else
            {
                this.m_mapWidth  = 3;
                this.m_mapHeight = 4;
            }

            this.m_savedPaths = new LogicSavedPath[LogicPathFinderOld.SAVED_PATHS];

            for (int i = 0, j = this.m_mapWidth * 4; i < LogicPathFinderOld.SAVED_PATHS; i++)
            {
                this.m_savedPaths[i] = new LogicSavedPath(j);
            }

            int size = this.m_mapWidth * this.m_mapHeight;

            this.m_pathState    = new int[size];
            this.m_heapBuffer   = new int[size];
            this.m_parentBuffer = new int[size];
            this.m_pathBuffer   = new int[size];
            this.m_pathCost     = new int[size];

            this.ResetCostStrategyToDefault();
        }
Esempio n. 2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="LogicPathFinderOld"/> class.
        /// </summary>
        public LogicPathFinderOld(LogicTileMap tileMap) : base(tileMap)
        {
            this._sizeX = 3;
            this._sizeY = 4;

            if (tileMap != null)
            {
                this._sizeX = 2 * tileMap.GetSizeX();
                this._sizeY = 2 * tileMap.GetSizeY();
            }

            int arraySize = this._sizeX * this._sizeY;

            this._heapBuffer = new int[arraySize];
            this._pathBuffer = new int[arraySize];
            this._savedPaths = new LogicSavedPath[30];

            for (int i = 0; i < 30; i++)
            {
                this._savedPaths[i] = new LogicSavedPath(4 * this._sizeX);
            }
        }
Esempio n. 3
0
        public bool MoveTo(int x, int y, LogicTileMap tileMap, bool defaultEndPoint)
        {
            this.ClearPath();

            if (this.m_parent != null)
            {
                if (this.m_parent.GetParent().IsFrozen())
                {
                    return(false);
                }
            }

            this.m_wall      = null;
            this.m_wallCount = 0;

            this.m_pathStartPosition.m_x = this.m_position.m_x >> 8;
            this.m_pathStartPosition.m_y = this.m_position.m_y >> 8;
            this.m_pathEndPosition.m_x   = x >> 8;
            this.m_pathEndPosition.m_y   = y >> 8;

            this.m_pathStartPosition.m_x = LogicMath.Clamp(this.m_pathStartPosition.m_x, 0, 99);
            this.m_pathStartPosition.m_y = LogicMath.Clamp(this.m_pathStartPosition.m_y, 0, 99);
            this.m_pathEndPosition.m_x   = LogicMath.Clamp(this.m_pathEndPosition.m_x, 0, 99);
            this.m_pathEndPosition.m_y   = LogicMath.Clamp(this.m_pathEndPosition.m_y, 0, 99);

            LogicPathFinder pathFinder;

            if (this.m_parent == null)
            {
                pathFinder = this.m_pathFinder;
                pathFinder.ResetCostStrategyToDefault();
            }
            else
            {
                bool resetStrategyCost = true;
                int  strategyCost      = 256;

                LogicGameObject        parent            = this.m_parent.GetParent();
                LogicHitpointComponent hitpointComponent = parent.GetHitpointComponent();

                if (hitpointComponent != null)
                {
                    if (hitpointComponent.GetTeam() == 1)
                    {
                        resetStrategyCost = false;
                        strategyCost      = 768;
                    }
                }

                if (this.m_parent.CanJumpWall())
                {
                    resetStrategyCost = false;
                    strategyCost      = 16;
                }

                if (parent.GetGameObjectType() == LogicGameObjectType.CHARACTER)
                {
                    LogicCharacter character = (LogicCharacter)parent;

                    if (character.IsWallBreaker())
                    {
                        resetStrategyCost = false;
                        strategyCost      = 128;
                    }
                }

                pathFinder = tileMap.GetPathFinder();

                if (resetStrategyCost)
                {
                    pathFinder.ResetCostStrategyToDefault();
                }
                else
                {
                    pathFinder.SetCostStrategy(true, strategyCost);
                }

                pathFinder.FindPath(this.m_pathStartPosition, this.m_pathEndPosition, true);
                pathFinder.GetPathLength();

                int pathLength = pathFinder.GetPathLength();

                this.m_path.EnsureCapacity(pathLength + 1);

                if (pathLength != 0 && defaultEndPoint)
                {
                    LogicVector2 pathPoint = new LogicVector2(x, y);

                    this.CheckWall(pathPoint);
                    this.m_path.Add(pathPoint);
                }

                if (LogicDataTables.GetGlobals().UseNewPathFinder())
                {
                    LogicTileMap pathFinderTileMap = pathFinder.GetTileMap();

                    int width  = 2 * pathFinderTileMap.GetSizeX();
                    int height = 2 * pathFinderTileMap.GetSizeY();

                    int startTileIdx = this.m_pathStartPosition.m_x + width * this.m_pathStartPosition.m_y;
                    int endTileIdx   = this.m_pathEndPosition.m_x + width * this.m_pathEndPosition.m_y;

                    if (!defaultEndPoint)
                    {
                        LogicVector2 pathPoint = new LogicVector2((endTileIdx % width) << 8, (endTileIdx / height) << 8);

                        this.CheckWall(pathPoint);
                        this.m_path.Add(pathPoint);
                    }

                    if (pathLength > 0 && !pathFinder.IsLineOfSightClear())
                    {
                        int iterationCount = 0;

                        while (endTileIdx != startTileIdx && endTileIdx != -1)
                        {
                            endTileIdx = pathFinder.GetParent(endTileIdx);

                            if (endTileIdx != startTileIdx && endTileIdx != -1)
                            {
                                LogicVector2 pathPoint = new LogicVector2((endTileIdx % width) << 8, (endTileIdx / height) << 8);

                                pathPoint.m_x += 128;
                                pathPoint.m_y += 128;

                                this.CheckWall(pathPoint);
                                this.m_path.Add(pathPoint);

                                if (iterationCount >= 100000)
                                {
                                    Debugger.Warning("LMSystem: iteration count > 100000");
                                    break;
                                }
                            }

                            iterationCount += 1;
                        }
                    }
                }
                else
                {
                    for (int i = -pathLength, j = 0; j + i != 0; j++)
                    {
                        LogicVector2 pathPoint = new LogicVector2();

                        pathFinder.GetPathPoint(pathPoint, i + j);

                        if (i + j == -1 && this.m_pathStartPosition.Equals(pathPoint))
                        {
                            pathPoint.Destruct();
                            pathPoint = null;
                        }
                        else
                        {
                            if (j != 0 || !this.m_pathStartPosition.Equals(pathPoint))
                            {
                                pathPoint.m_x = (pathPoint.m_x << 8) | 128;
                                pathPoint.m_y = (pathPoint.m_y << 8) | 128;
                            }
                            else
                            {
                                pathPoint.m_x = x;
                                pathPoint.m_y = y;
                            }

                            this.CheckWall(pathPoint);
                            this.m_path.Add(pathPoint);
                        }
                    }
                }
            }

            this.CalculatePathLength();

            if (this.m_path.Size() > 0)
            {
                this.CalculateDirection(this.m_pathDistance);
                return(true);
            }

            return(false);
        }