public override void OnPoll(int value, int x, int y, int z, int pollPass)
        {
            if (Terrain.ExtractData(value) != 0 || m_subsystemGameInfo.WorldSettings.EnvironmentBehaviorMode != 0)
            {
                return;
            }
            int num = Terrain.ExtractLight(base.SubsystemTerrain.Terrain.GetCellValue(x, y + 1, z));

            if (num == 0)
            {
                m_toUpdate[new Point3(x, y, z)] = Terrain.ReplaceContents(value, 8);
            }
            if (num < 13)
            {
                return;
            }
            for (int i = x - 1; i <= x + 1; i++)
            {
                for (int j = z - 1; j <= z + 1; j++)
                {
                    for (int k = y - 2; k <= y + 1; k++)
                    {
                        int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(i, k, j);
                        if (Terrain.ExtractContents(cellValue) != 2)
                        {
                            continue;
                        }
                        int cellValue2 = base.SubsystemTerrain.Terrain.GetCellValue(i, k + 1, j);
                        if (KillsGrassIfOnTopOfIt(cellValue2) || Terrain.ExtractLight(cellValue2) < 13 || !(m_random.Float(0f, 1f) < 0.1f))
                        {
                            continue;
                        }
                        int num2 = Terrain.ReplaceContents(cellValue, 8);
                        m_toUpdate[new Point3(i, k, j)] = num2;
                        if (Terrain.ExtractContents(cellValue2) == 0)
                        {
                            int temperature = base.SubsystemTerrain.Terrain.GetTemperature(i, j);
                            int humidity    = base.SubsystemTerrain.Terrain.GetHumidity(i, j);
                            int num3        = PlantsManager.GenerateRandomPlantValue(m_random, num2, temperature, humidity, k + 1);
                            if (num3 != 0)
                            {
                                m_toUpdate[new Point3(i, k + 1, j)] = num3;
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        public void MatureSapling(SaplingData saplingData)
        {
            if (!(m_subsystemGameInfo.TotalElapsedGameTime >= saplingData.MatureTime))
            {
                return;
            }
            int          x            = saplingData.Point.X;
            int          y            = saplingData.Point.Y;
            int          z            = saplingData.Point.Z;
            TerrainChunk chunkAtCell  = base.SubsystemTerrain.Terrain.GetChunkAtCell(x - 6, z - 6);
            TerrainChunk chunkAtCell2 = base.SubsystemTerrain.Terrain.GetChunkAtCell(x - 6, z + 6);
            TerrainChunk chunkAtCell3 = base.SubsystemTerrain.Terrain.GetChunkAtCell(x + 6, z - 6);
            TerrainChunk chunkAtCell4 = base.SubsystemTerrain.Terrain.GetChunkAtCell(x + 6, z + 6);

            if (chunkAtCell != null && chunkAtCell.State == TerrainChunkState.Valid && chunkAtCell2 != null && chunkAtCell2.State == TerrainChunkState.Valid && chunkAtCell3 != null && chunkAtCell3.State == TerrainChunkState.Valid && chunkAtCell4 != null && chunkAtCell4.State == TerrainChunkState.Valid)
            {
                int cellContents = base.SubsystemTerrain.Terrain.GetCellContents(x, y - 1, z);
                if (cellContents == 2 || cellContents == 8)
                {
                    if (base.SubsystemTerrain.Terrain.GetCellLight(x, y + 1, z) >= 9)
                    {
                        bool flag = false;
                        for (int i = x - 1; i <= x + 1; i++)
                        {
                            for (int j = z - 1; j <= z + 1; j++)
                            {
                                int cellContents2 = base.SubsystemTerrain.Terrain.GetCellContents(i, y - 1, j);
                                if (BlocksManager.Blocks[cellContents2] is WaterBlock)
                                {
                                    flag = true;
                                    break;
                                }
                            }
                        }
                        float num = 0f;
                        if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative)
                        {
                            num = 1f;
                        }
                        else
                        {
                            int num2 = base.SubsystemTerrain.Terrain.GetTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(y);
                            int num3 = base.SubsystemTerrain.Terrain.GetHumidity(x, z);
                            if (flag)
                            {
                                num2 = (num2 + 10) / 2;
                                num3 = MathUtils.Max(num3, 12);
                            }
                            num = 2f * PlantsManager.CalculateTreeProbability(saplingData.Type, num2, num3, y);
                        }
                        if (m_random.Bool(num))
                        {
                            base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(0, 0, 0));
                            if (!GrowTree(x, y, z, saplingData.Type))
                            {
                                base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(28, 0, 0));
                            }
                        }
                        else
                        {
                            base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(28, 0, 0));
                        }
                    }
                    else if (m_subsystemGameInfo.TotalElapsedGameTime > saplingData.MatureTime + 1200.0)
                    {
                        base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(28, 0, 0));
                    }
                }
                else
                {
                    base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.MakeBlockValue(28, 0, 0));
                }
            }
            else
            {
                saplingData.MatureTime = m_subsystemGameInfo.TotalElapsedGameTime;
            }
        }