示例#1
0
        public void AddTombstoneIfNeeded()
        {
            if (!this.m_ejected && this.m_level.GetTombStoneCount() < 40)
            {
                int tileX = this.GetTileX();
                int tileY = this.GetTileY();

                LogicTileMap tileMap = this.m_level.GetTileMap();
                LogicTile    tile    = tileMap.GetTile(tileX, tileY);

                if (!this.TileOkForTombstone(tile))
                {
                    int minDistance  = 0;
                    int closestTileX = -1;
                    int closestTileY = -1;

                    for (int i = -1; i < 2; i++)
                    {
                        int offsetX = ((i + tileX) << 9) | 256;
                        int offsetY = 256 - (tileY << 9);

                        for (int j = -1; j < 2; j++, offsetY -= 512)
                        {
                            tile = tileMap.GetTile(tileX + i, tileY + j);

                            if (this.TileOkForTombstone(tile))
                            {
                                int distanceX = this.GetX() - offsetX;
                                int distanceY = this.GetY() + offsetY;
                                int distance  = distanceX * distanceX + distanceY * distanceY;

                                if (minDistance == 0 || distance < minDistance)
                                {
                                    minDistance  = distance;
                                    closestTileX = tileX + i;
                                    closestTileY = tileY + j;
                                }
                            }
                        }
                    }

                    if (minDistance == 0)
                    {
                        return;
                    }

                    tileX = closestTileX;
                    tileY = closestTileY;
                }

                LogicObstacleData tombstoneData = this.GetCharacterData().GetTombstone();

                if (tombstoneData != null)
                {
                    LogicObstacle tombstone = (LogicObstacle)LogicGameObjectFactory.CreateGameObject(tombstoneData, this.m_level, this.m_villageType);
                    tombstone.SetInitialPosition(tileX << 9, tileY << 9);
                    this.GetGameObjectManager().AddGameObject(tombstone, -1);
                }
            }
        }
        private void Spawn()
        {
            int free = LogicMath.Min(LogicMath.Min(this.m_spawnCount, this.m_maxSpawned - this.m_spawned.Size()), this.m_maxLifetimeSpawns - this.m_lifeTimeSpawns);

            if (free > 0)
            {
                int x           = this.m_parent.GetX();
                int y           = this.m_parent.GetY();
                int tileX       = this.m_parent.GetTileX();
                int tileY       = this.m_parent.GetTileY();
                int width       = this.m_parent.GetWidthInTiles();
                int height      = this.m_parent.GetHeightInTiles();
                int levelWidth  = this.m_parent.GetLevel().GetWidthInTiles();
                int levelHeight = this.m_parent.GetLevel().GetHeightInTiles();

                int startTileX = LogicMath.Clamp(tileX - this.m_radius, 0, levelWidth);
                int startTileY = LogicMath.Clamp(tileY - this.m_radius, 0, levelHeight);
                int endTileX   = LogicMath.Clamp(tileX + this.m_radius + width, 0, levelWidth);
                int endTileY   = LogicMath.Clamp(tileY + this.m_radius + height, 0, levelHeight);

                int radius      = (this.m_radius << 9) * (this.m_radius << 9);
                int possibility = (endTileX - startTileX) * (endTileY - startTileY);

                LogicArrayList <LogicTile> spawnPoints = new LogicArrayList <LogicTile>(possibility);
                LogicTileMap tileMap = this.m_parent.GetLevel().GetTileMap();

                int spawnPointUpStartX = x + (width << 9);
                int spawnPointUpStartY = y + (height << 9);

                int tmp4 = y - 256 - (startTileY << 9);

                int startMidX = (startTileX << 9) | 256;
                int startMidY = (startTileY << 9) | 256;

                for (int i = startTileX, j = startMidX; i < endTileX; i++, j += 512)
                {
                    int tmp1 = j >= spawnPointUpStartX ? -spawnPointUpStartX + j + 1 : 0;
                    int tmp2 = j >= x ? tmp1 : x - j;

                    tmp2 *= tmp2;

                    for (int k = startTileY, l = startMidY, m = tmp4; k < endTileY; k++, l += 512, m -= 512)
                    {
                        LogicTile tile = tileMap.GetTile(i, k);

                        if (tile.GetGameObjectCount() == 0)
                        {
                            int tmp3 = y <= l ? l < spawnPointUpStartY ? 0 : -spawnPointUpStartY + l + 1 : m;

                            tmp3 *= tmp3;

                            if (tmp2 + tmp3 <= radius)
                            {
                                spawnPoints.Add(tile);
                            }
                        }
                    }
                }

                for (int i = free; i > 0 && spawnPoints.Size() > 0; i--, ++this.m_lifeTimeSpawns)
                {
                    int idx = this.m_randomizer.Rand(spawnPoints.Size());

                    LogicTile       tile       = spawnPoints[idx];
                    LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(this.m_spawnData, this.m_parent.GetLevel(), this.m_parent.GetVillageType());

                    gameObject.SetInitialPosition(tile.GetX() << 9, tile.GetY() << 9);

                    this.m_parent.GetGameObjectManager().AddGameObject(gameObject, -1);
                    this.m_spawned.Add(gameObject.GetGlobalID());

                    spawnPoints.Remove(idx);
                }
            }
        }
示例#3
0
        public void SetPosition(int x, int y)
        {
            if (this.m_parent != null)
            {
                if (!this.m_parent.IsFlying() &&
                    !this.m_parent.IsUnderground() &&
                    this.m_parent.GetJump() <= 0 &&
                    !this.m_ignorePush)
                {
                    this.ValidatePos();

                    if (this.m_position.m_x >> 8 == x >> 8)
                    {
                        if ((this.m_position.m_y ^ (uint)y) < 256)
                        {
                            goto set;
                        }
                    }

                    LogicTileMap tileMap = this.m_parent.GetParent().GetLevel().GetTileMap();

                    int pathFinderX = x >> 8;
                    int pathFinderY = y >> 8;

                    if (!tileMap.IsPassablePathFinder(pathFinderX, pathFinderY))
                    {
                        LogicTile tile = tileMap.GetTile(pathFinderX / 2, pathFinderY / 2);

                        if (LogicDataTables.GetGlobals().JumpWhenHitJumpable())
                        {
                            bool allowJump = false;

                            for (int i = 0; i < tile.GetGameObjectCount(); i++)
                            {
                                LogicGameObject gameObject = tile.GetGameObject(i);

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

                                    if (building.GetHitWallDelay() > 0)
                                    {
                                        allowJump = true;
                                    }
                                }
                            }

                            if (allowJump)
                            {
                                this.m_position.m_x = x;
                                this.m_position.m_y = y;

                                this.m_parent.EnableJump(128);

                                return;
                            }
                        }

                        if (LogicDataTables.GetGlobals().SlideAlongObstacles())
                        {
                            throw new NotImplementedException(); // TODO: Implement this.
                        }
                        else
                        {
                            x = LogicMath.Clamp(x, (int)(this.m_position.m_x & 0xFFFFFF00), this.m_position.m_x | 0xFF);
                            y = LogicMath.Clamp(y, (int)(this.m_position.m_y & 0xFFFFFF00), this.m_position.m_y | 0xFF);
                        }

                        this.m_position.m_x = x;
                        this.m_position.m_y = y;

                        this.ValidatePos();
                        return;
                    }
                }
            }

set:

            this.m_position.m_x = x;
            this.m_position.m_y = y;
        }