コード例 #1
0
        public bool IsValidAttackPos(int x, int y)
        {
            for (int i = 0, posX = x - 1; i < 2; i++, posX++)
            {
                for (int j = 0, posY = y - 1; j < 2; j++, posY++)
                {
                    LogicTile tile = this.GetTile(posX + i, posY + j);

                    if (tile != null)
                    {
                        for (int k = 0; k < tile.GetGameObjectCount(); k++)
                        {
                            LogicGameObject gameObject = tile.GetGameObject(k);

                            if (!gameObject.IsPassable())
                            {
                                if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                {
                                    LogicBuilding building = (LogicBuilding)gameObject;

                                    if (!building.GetBuildingData().IsHidden())
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }
コード例 #2
0
        public void RemoveGameObject(LogicGameObject gameObject)
        {
            if (gameObject.IsStaticObject())
            {
                int tileX = gameObject.GetTileX();
                int tileY = gameObject.GetTileY();

                if (tileX >= 0 && tileY >= 0)
                {
                    int sizeX = gameObject.GetWidthInTiles();
                    int sizeY = gameObject.GetHeightInTiles();

                    for (int i = 0; i < sizeY; i++)
                    {
                        for (int j = 0; j < sizeX; j++)
                        {
                            this.m_tiles[(tileX + j) + this.m_sizeX * (tileY + i)].RemoveGameObject(gameObject);
                        }
                    }

                    if (!gameObject.IsPassable())
                    {
                        this.UpdateRoomIndices();
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        ///     Refreshes passable of the specified <see cref="LogicGameObject"/> instance..
        /// </summary>
        public void RefreshPassable(LogicGameObject gameObject)
        {
            if (gameObject.IsStaticObject())
            {
                int tileX = gameObject.GetTileX();
                int tileY = gameObject.GetTileY();

                if (tileX >= 0)
                {
                    if (tileY >= 0)
                    {
                        int sizeX = gameObject.GetWidthInTiles();
                        int sizeY = gameObject.GetHeightInTiles();

                        for (int i = 0; i < sizeY; i++)
                        {
                            for (int j = 0; j < sizeX; j++)
                            {
                                this.GetTile(tileX + j, tileY + i).RefreshPassableFlag();
                            }
                        }

                        if (!gameObject.IsPassable())
                        {
                            this.UpdateRoomIndices();
                        }
                    }
                }
            }
        }
コード例 #4
0
        /// <summary>
        ///     Called when the specified gameobject has been moved.
        /// </summary>
        public void GameObjectMoved(LogicGameObject gameObject, int oldTileX, int oldTileY)
        {
            if (gameObject.IsStaticObject())
            {
                int tileX = gameObject.GetTileX();
                int tileY = gameObject.GetTileY();

                if (tileX >= 0)
                {
                    if (tileY >= 0)
                    {
                        int sizeX = gameObject.GetWidthInTiles();
                        int sizeY = gameObject.GetHeightInTiles();

                        for (int i = 0; i < sizeY; i++)
                        {
                            for (int j = 0; j < sizeX; j++)
                            {
                                this.GetTile(oldTileX + j, oldTileY + i).RemoveGameObject(gameObject);
                                this.GetTile(tileX + j, tileY + i).AddGameObject(gameObject);
                            }
                        }

                        if (!gameObject.IsPassable())
                        {
                            this.UpdateRoomIndices();
                        }
                    }
                }
            }
        }
コード例 #5
0
        public void AddGameObject(LogicGameObject gameObject)
        {
            this.m_gameObjects.Add(gameObject);

            if (!gameObject.IsPassable())
            {
                this.m_passableFlag &= 0xEF;
            }

            this.RefreshSubTiles();
        }
コード例 #6
0
        public void RefreshSubTiles()
        {
            this.m_passableFlag  &= 0xF0;
            this.m_pathFinderCost = 0;

            for (int i = 0; i < this.m_gameObjects.Size(); i++)
            {
                LogicGameObject gameObject = this.m_gameObjects[i];

                this.m_pathFinderCost = LogicMath.Max(this.m_pathFinderCost, gameObject.PathFinderCost());

                if (!gameObject.IsPassable())
                {
                    int width  = gameObject.GetWidthInTiles();
                    int height = gameObject.GetWidthInTiles();

                    if (width == 1 || height == 1)
                    {
                        this.m_passableFlag |= 0xF;
                    }
                    else
                    {
                        int edge = gameObject.PassableSubtilesAtEdge();

                        int startX = 2 * (this.m_tileX - gameObject.GetTileX());
                        int startY = 2 * (this.m_tileY - gameObject.GetTileY());
                        int endX   = 2 * width - edge;
                        int endY   = 2 * height - edge;

                        for (int j = 0; j < 2; j++)
                        {
                            int offset = j;
                            int x      = startX + j;

                            for (int k = 0; k < 2; k++)
                            {
                                int y = startY + k;

                                if (y < endY && x < endX && x >= edge && y >= edge)
                                {
                                    this.m_passableFlag |= (byte)(1 << offset);
                                }

                                offset += 2;
                            }
                        }
                    }
                }
            }
        }
コード例 #7
0
        public bool IsBuildable(LogicGameObject gameObject)
        {
            for (int i = 0; i < this.m_gameObjects.Size(); i++)
            {
                LogicGameObject go = this.m_gameObjects[i];

                if (go != gameObject)
                {
                    if (!go.IsPassable() || go.IsUnbuildable())
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #8
0
ファイル: LogicTile.cs プロジェクト: NotHuza/Cerberus-v4
        /// <summary>
        ///     Refreshes sub tiles.
        /// </summary>
        public void RefreshSubTiles()
        {
            this._passableFlag &= 0xF0;

            for (int i = 0; i < this._gameObjects.Count; i++)
            {
                LogicGameObject gameObject = this._gameObjects[i];

                this._pathFinderCost = LogicMath.Max(this._pathFinderCost, gameObject.GetPathFinderCost());

                if (!gameObject.IsPassable())
                {
                    int width = gameObject.GetWidthInTiles();

                    if (width == 1)
                    {
                        this._passableFlag |= 0xF0;
                    }
                    else
                    {
                        int tileX  = gameObject.GetTileX();
                        int tileY  = gameObject.GetTileY();
                        int edge   = gameObject.PassableSubtilesAtEdge();
                        int startX = 2 * width - edge;
                        int startY = 2 * width - edge;
                        int endX   = 2 * (width - edge);
                        int endY   = 2 * (width - edge);

                        // RIP

                        /* do
                         * {
                         *     v11 = v20 + v19;
                         *     v12 = -1;
                         *     v13 = v20;
                         *     do
                         *     {
                         *         v14 = 2 * (v28 - v27) + v12 + 1;
                         *         v16 = __OFSUB__(v14, v9);
                         *         v15 = v14 - v9 < 0;
                         *         if ( v14 < v9 )
                         *         {
                         *             v16 = __OFSUB__(v11, v10);
                         *             v15 = v11 - v10 < 0;
                         *         }
                         *         if ( v15 ^ v16 )
                         *         {
                         *             v18 = __OFSUB__(v11, v8);
                         *             v17 = v11 - v8 < 0;
                         *             if ( v11 >= v8 )
                         *             {
                         *                 v18 = __OFSUB__(v14, v8);
                         *                 v17 = v14 - v8 < 0;
                         *             }
                         *              if ( !(v17 ^ v18) )
                         *(_BYTE *)(v1 + 8) |= 1 << v13;
                         *          }
                         ++v12;
                         *          v13 += 2;
                         *     }
                         *     while ( v12 < 1 );
                         *     v19 = v29;
                         *     v16 = __OFSUB__(v20, 1);
                         *     v15 = v20++ - 1 < 0;
                         * }
                         * while ( v15 ^ v16 );
                         */
                    }
                }
            }
        }