コード例 #1
0
        public override void Regenerate()
        {
            base.ClearSubMeshes(MeshParts.All);
            this.scats.RemoveAll((Scatterable scat) => !scat.IsOnValidTerrain);
            int num = 0;

            TerrainDef[] topGrid     = base.Map.terrainGrid.topGrid;
            CellRect     cellRect    = base.section.CellRect;
            CellIndices  cellIndices = base.Map.cellIndices;

            for (int i = cellRect.minZ; i <= cellRect.maxZ; i++)
            {
                for (int j = cellRect.minX; j <= cellRect.maxX; j++)
                {
                    if (topGrid[cellIndices.CellToIndex(j, i)].scatterType != null)
                    {
                        num++;
                    }
                }
            }
            num /= 40;
            int num2 = 0;

            while (this.scats.Count < num && num2 < 200)
            {
                num2++;
                IntVec3        randomCell   = base.section.CellRect.RandomCell;
                string         terrScatType = base.Map.terrainGrid.TerrainAt(randomCell).scatterType;
                ScatterableDef def2         = default(ScatterableDef);
                if (terrScatType != null && !randomCell.Filled(base.Map) && (from def in DefDatabase <ScatterableDef> .AllDefs
                                                                             where def.scatterType == terrScatType
                                                                             select def).TryRandomElement <ScatterableDef>(out def2))
                {
                    Vector3     loc         = new Vector3((float)randomCell.x + Rand.Value, (float)randomCell.y, (float)randomCell.z + Rand.Value);
                    Scatterable scatterable = new Scatterable(def2, loc, base.Map);
                    this.scats.Add(scatterable);
                    scatterable.PrintOnto(this);
                }
            }
            for (int k = 0; k < this.scats.Count; k++)
            {
                this.scats[k].PrintOnto(this);
            }
            base.FinalizeMesh(MeshParts.All);
        }
コード例 #2
0
        public override void Regenerate()
        {
            ClearSubMeshes(MeshParts.All);
            scats.RemoveAll((Scatterable scat) => !scat.IsOnValidTerrain);
            int num = 0;

            TerrainDef[] topGrid     = base.Map.terrainGrid.topGrid;
            CellRect     cellRect    = section.CellRect;
            CellIndices  cellIndices = base.Map.cellIndices;

            for (int i = cellRect.minZ; i <= cellRect.maxZ; i++)
            {
                for (int j = cellRect.minX; j <= cellRect.maxX; j++)
                {
                    if (topGrid[cellIndices.CellToIndex(j, i)].scatterType != null)
                    {
                        num++;
                    }
                }
            }
            num /= 40;
            int num2 = 0;

            while (scats.Count < num && num2 < 200)
            {
                num2++;
                IntVec3 randomCell   = section.CellRect.RandomCell;
                string  terrScatType = base.Map.terrainGrid.TerrainAt(randomCell).scatterType;
                if (terrScatType != null && !randomCell.Filled(base.Map) && DefDatabase <ScatterableDef> .AllDefs.Where((ScatterableDef def) => def.scatterType == terrScatType).TryRandomElement(out var result))
                {
                    Scatterable scatterable = new Scatterable(loc: new Vector3((float)randomCell.x + Rand.Value, randomCell.y, (float)randomCell.z + Rand.Value), def: result, map: base.Map);
                    scats.Add(scatterable);
                    scatterable.PrintOnto(this);
                }
            }
            for (int k = 0; k < scats.Count; k++)
            {
                scats[k].PrintOnto(this);
            }
            FinalizeMesh(MeshParts.All);
        }