Пример #1
0
        public void GenerateUndergroundWaterGrid(Map map, MapComponent_WaterGrid waterGrid, int basePoolNum, int minWaterPoolNum, float baseRainFall, float basePlantDensity, float literPerCell, IntRange poolCellRange, FloatRange baseRegenRateRange, float rainRegenRatePerCell)
        {
            float rainRate  = map.TileInfo.rainfall / baseRainFall;
            float areaRate  = map.Area / BaseMapArea;
            float plantRate = map.Biome.plantDensity / basePlantDensity;

            int waterPoolNum = Mathf.RoundToInt(basePoolNum * rainRate * areaRate * plantRate);

            //Log.Message(string.Format("rain={0},area={1},plant={2},num={3}", rainRate.ToString("F3"), areaRate.ToString("F3"), plantRate.ToString("F3"), waterPoolNum));
            if (plantRate > 0.0f)
            {
                waterPoolNum = Mathf.Max(waterPoolNum, minWaterPoolNum);
            }

            for (int i = 0; i < waterPoolNum; i++)
            {
                IntVec3 result;
                if (CellFinderLoose.TryFindRandomNotEdgeCellWith(5, (c) => !waterGrid.GetCellBool(map.cellIndices.CellToIndex(c)), map, out result))
                {
                    int   numCells            = poolCellRange.RandomInRange;
                    float baseRegenRate       = baseRegenRateRange.RandomInRange;
                    UndergroundWaterPool pool = new UndergroundWaterPool(waterGrid, numCells * literPerCell, WaterType.RawWater, baseRegenRate, rainRegenRatePerCell);
                    pool.ID = i + 1;
                    waterGrid.AddWaterPool(pool, GridShapeMaker.IrregularLump(result, map, numCells));
                }
            }

            waterGrid.ModifyPoolGrid();
        }
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);

            pool = WaterGrid.GetPool(map.cellIndices.CellToIndex(Position));
            if (pool == null)
            {
                Log.Error("pool is null");
            }
        }
Пример #3
0
 public void MergePool(UndergroundWaterPool p, ushort[] idGrid)
 {
     this.MergeWaterVolume(p);
     for (int i = 0; i < idGrid.Length; i++)
     {
         if (idGrid[i] == p.ID)
         {
             idGrid[i] = (ushort)this.ID;
         }
     }
 }
Пример #4
0
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);

            var waterGrid = map.GetComponent <MapComponent_ShallowWaterGrid>();

            if (waterGrid == null)
            {
                Log.Error("waterGrid is null");
            }

            this.pool = waterGrid.GetPool(map.cellIndices.CellToIndex(this.Position));
            if (this.pool == null)
            {
                Log.Error("pool is null");
            }
        }
Пример #5
0
        public static void GenerateUndergroundWaterGrid(Map map, MapComponent_WaterGrid waterGrid, int basePoolNum = 30, int minWaterPoolNum = 3, float baseRainFall = 1000f, float basePlantDensity = 0.25f, float literPerCell = 10.0f, IntRange poolCellRange = default, FloatRange baseRegenRateRange = default, float rainRegenRatePerCell = 5.0f)
        {
            if (poolCellRange == default)
            {
                poolCellRange = new IntRange(30, 100);
            }

            if (baseRegenRateRange == default)
            {
                baseRegenRateRange = new FloatRange(10.0f, 20.0f);
            }

            var BaseMapArea = 250f * 250f;

            var rainRate  = map.TileInfo.rainfall / baseRainFall;
            var areaRate  = map.Area / BaseMapArea;
            var plantRate = map.Biome.plantDensity / basePlantDensity;

            var waterPoolNum = Mathf.RoundToInt(basePoolNum * rainRate * areaRate * plantRate);

            // Log.Message(string.Format("rain={0},area={1},plant={2},num={3}", rainRate.ToString("F3"), areaRate.ToString("F3"), plantRate.ToString("F3"), waterPoolNum));
            if (plantRate > 0.0f)
            {
                waterPoolNum = Mathf.Max(waterPoolNum, minWaterPoolNum);
            }

            for (var i = 0; i < waterPoolNum; i++)
            {
                if (!CellFinderLoose.TryFindRandomNotEdgeCellWith(5, c => !waterGrid.GetCellBool(map.cellIndices.CellToIndex(c)), map, out var result))
                {
                    continue;
                }

                var numCells      = poolCellRange.RandomInRange;
                var baseRegenRate = baseRegenRateRange.RandomInRange;
                var pool          = new UndergroundWaterPool(waterGrid, numCells * literPerCell, WaterType.RawWater, baseRegenRate, rainRegenRatePerCell)
                {
                    ID = i + 1
                };
                waterGrid.AddWaterPool(pool, GridShapeMaker.IrregularLump(result, map, numCells));
            }

            waterGrid.ModifyPoolGrid();
        }
        public void AddWaterPool(UndergroundWaterPool pool, IEnumerable <IntVec3> cells)
        {
            List <UndergroundWaterPool> mergePools = new List <UndergroundWaterPool>();

            mergePools.Add(pool);

            // 既存の水源と被るセルを調べる
            foreach (var c in cells)
            {
                if (this.GetID(c) != 0)
                {
                    var existPool = this.pools.Find((p) => p.ID == this.GetID(c));
                    if (existPool == null)
                    {
                        Log.Error("existPool is null");
                    }
                    if (!mergePools.Contains(existPool))
                    {
                        mergePools.Add(existPool);
                    }
                }
            }

            // 上書き覚悟でとりあえず追加
            this.pools.Add(pool);
            foreach (var c in cells)
            {
                this.SetID(c, pool.ID);
            }

            if (mergePools.Count >= 2)
            {
                // 最小の水源IDのものに統合する

                // 最小の水源IDを調べる
                UndergroundWaterPool minPool = null;
                foreach (var p in mergePools)
                {
                    if (minPool == null || minPool.ID > p.ID)
                    {
                        minPool = p;
                    }
                }

                // 統合される水源から最小IDのものを除き、消滅予定水源リストに変換
                mergePools.Remove(minPool);

                // 水源リストから消滅予定水源を除去しつつ水量を統合
                foreach (var p in mergePools)
                {
                    this.pools.Remove(p);
                    minPool.MergeWaterVolume(p);
                }

                // 全セルを調べ、消滅予定水源IDの場所を最小IDに変更
                for (int i = 0; i < this.poolIDGrid.Length; i++)
                {
                    //Log.Message("i=" + i.ToString());
                    if (mergePools.Find((p) => p.ID == this.GetID(i)) != null)
                    {
                        this.SetID(i, minPool.ID);
                    }
                }
            }
        }
Пример #7
0
 public void MergeWaterVolume(UndergroundWaterPool p)
 {
     this.maxWaterVolume     += p.maxWaterVolume;
     this.CurrentWaterVolume += p.CurrentWaterVolume;
 }