Пример #1
0
        public bool GrowTree(int x, int y, int z, TreeType treeType)
        {
            ReadOnlyList <TerrainBrush> treeBrushes = PlantsManager.GetTreeBrushes(treeType);

            for (int i = 0; i < 20; i++)
            {
                TerrainBrush        terrainBrush = treeBrushes[m_random.Int(0, treeBrushes.Count - 1)];
                bool                flag         = true;
                TerrainBrush.Cell[] cells        = terrainBrush.Cells;
                for (int j = 0; j < cells.Length; j++)
                {
                    TerrainBrush.Cell cell = cells[j];
                    if (cell.Y >= 0 && (cell.X != 0 || cell.Y != 0 || cell.Z != 0))
                    {
                        int cellContents = base.SubsystemTerrain.Terrain.GetCellContents(cell.X + x, cell.Y + y, cell.Z + z);
                        if (cellContents != 0 && !(BlocksManager.Blocks[cellContents] is LeavesBlock))
                        {
                            flag = false;
                            break;
                        }
                    }
                }
                if (flag)
                {
                    terrainBrush.Paint(base.SubsystemTerrain, x, y, z);
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
 public int?Paint(TerrainBrush terrainBrush, Point3 p)
 {
     if (m_handler1 != null)
     {
         return(m_handler1(terrainBrush.GetValue(p.X, p.Y, p.Z)));
     }
     if (m_handler2 != null)
     {
         return(m_handler2(p));
     }
     return(m_value);
 }
Пример #3
0
        public static TerrainBrush CreateTreeBrush(Random random, int woodIndex, int leavesIndex, int height, int branchesCount, Func <int, float> leavesProbabilityByHeight, Func <int, float> branchesLengthByHeight)
        {
            TerrainBrush terrainBrush = new TerrainBrush();

            terrainBrush.AddRay(0, -1, 0, 0, height, 0, 1, 1, 1, woodIndex);
            for (int i = 0; i < branchesCount; i++)
            {
                int     x       = 0;
                int     num     = random.Int(0, height);
                int     z       = 0;
                float   s       = branchesLengthByHeight(num);
                Vector3 vector  = Vector3.Normalize(new Vector3(random.Float(-1f, 1f), random.Float(0f, 0.33f), random.Float(-1f, 1f))) * s;
                int     x2      = (int)MathUtils.Round(vector.X);
                int     y       = num + (int)MathUtils.Round(vector.Y);
                int     z2      = (int)MathUtils.Round(vector.Z);
                int     cutFace = 0;
                if (MathUtils.Abs(vector.X) == MathUtils.Max(MathUtils.Abs(vector.X), MathUtils.Abs(vector.Y), MathUtils.Abs(vector.Z)))
                {
                    cutFace = 1;
                }
                else if (MathUtils.Abs(vector.Y) == MathUtils.Max(MathUtils.Abs(vector.X), MathUtils.Abs(vector.Y), MathUtils.Abs(vector.Z)))
                {
                    cutFace = 4;
                }
                terrainBrush.AddRay(x, num, z, x2, y, z2, 1, 1, 1, (Func <int?, int?>)((int?v) => v.HasValue ? null : new int?(Terrain.MakeBlockValue(woodIndex, 0, WoodBlock.SetCutFace(0, cutFace)))));
            }
            for (int j = 0; j < 3; j++)
            {
                terrainBrush.CalculateBounds(out Point3 min, out Point3 max);
                for (int k = min.X - 1; k <= max.X + 1; k++)
                {
                    for (int l = min.Z - 1; l <= max.Z + 1; l++)
                    {
                        for (int m = 1; m <= max.Y + 1; m++)
                        {
                            float num2 = leavesProbabilityByHeight(m);
                            if (random.Float(0f, 1f) < num2 && !terrainBrush.GetValue(k, m, l).HasValue&& (terrainBrush.CountNonDiagonalNeighbors(k, m, l, leavesIndex) != 0 || terrainBrush.CountNonDiagonalNeighbors(k, m, l, (Func <int?, int>)((int?v) => (v.HasValue && Terrain.ExtractContents(v.Value) == woodIndex) ? 1 : 0)) != 0))
                            {
                                terrainBrush.AddCell(k, m, l, 0);
                            }
                        }
                    }
                }
                terrainBrush.Replace(0, leavesIndex);
            }
            terrainBrush.AddCell(0, height, 0, leavesIndex);
            terrainBrush.Compile();
            return(terrainBrush);
        }
Пример #4
0
 public int Count(TerrainBrush terrainBrush, Point3 p)
 {
     if (m_handler1 != null)
     {
         return(m_handler1(terrainBrush.GetValue(p)));
     }
     if (m_handler2 != null)
     {
         return(m_handler2(p));
     }
     if (terrainBrush.GetValue(p) != m_value)
     {
         return(0);
     }
     return(1);
 }
Пример #5
0
        public static TerrainBrush CreateMimosaBrush(Random random, float size)
        {
            TerrainBrush terrainBrush = new TerrainBrush();
            int          value        = m_treeTrunksByType[4];
            int          value2       = m_treeLeavesByType[4];

            terrainBrush.AddRay(0, -1, 0, 0, 0, 0, 1, 1, 1, value);
            List <Point3> list = new List <Point3>();
            float         num  = random.Float(0f, (float)Math.PI * 2f);

            for (int i = 0; i < 3; i++)
            {
                float   radians = num + (float)i * MathUtils.DegToRad(120f);
                Vector3 v       = Vector3.Transform(Vector3.Normalize(new Vector3(1f, random.Float(1f, 1.5f), 0f)), Matrix.CreateRotationY(radians));
                int     num2    = random.Int((int)(0.7f * size), (int)size);
                Point3  p       = new Point3(0, 0, 0);
                Point3  item    = new Point3(Vector3.Round(new Vector3(p) + v * num2));
                terrainBrush.AddRay(p.X, p.Y, p.Z, item.X, item.Y, item.Z, 1, 1, 1, value);
                list.Add(item);
            }
            foreach (Point3 item2 in list)
            {
                float num3 = random.Float(0.3f * size, 0.45f * size);
                int   num4 = (int)MathUtils.Ceiling(num3);
                for (int j = item2.X - num4; j <= item2.X + num4; j++)
                {
                    for (int k = item2.Y - num4; k <= item2.Y + num4; k++)
                    {
                        for (int l = item2.Z - num4; l <= item2.Z + num4; l++)
                        {
                            int   num5 = MathUtils.Abs(j - item2.X) + MathUtils.Abs(k - item2.Y) + MathUtils.Abs(l - item2.Z);
                            float num6 = ((new Vector3(j, k, l) - new Vector3(item2)) * new Vector3(1f, 1.7f, 1f)).Length();
                            if (num6 <= num3 && (num3 - num6 > 1f || num5 <= 2 || random.Bool(0.7f)) && !terrainBrush.GetValue(j, k, l).HasValue)
                            {
                                terrainBrush.AddCell(j, k, l, value2);
                            }
                        }
                    }
                }
            }
            terrainBrush.Compile();
            return(terrainBrush);
        }
Пример #6
0
        static PlantsManager()
        {
            m_treeBrushesByType = new List <TerrainBrush> [EnumUtils.GetEnumValues(typeof(TreeType)).Max() + 1];
            m_treeTrunksByType  = new int[5]
            {
                9,
                10,
                11,
                11,
                255
            };
            m_treeLeavesByType = new int[5]
            {
                12,
                13,
                14,
                225,
                256
            };
            Random random = new Random(33);

            m_treeBrushesByType[0] = new List <TerrainBrush>();
            for (int i = 0; i < 16; i++)
            {
                int[] array = new int[16]
                {
                    5,
                    6,
                    7,
                    7,
                    8,
                    8,
                    9,
                    9,
                    9,
                    10,
                    10,
                    11,
                    12,
                    13,
                    14,
                    16
                };
                int          height4       = array[i];
                int          branchesCount = (int)MathUtils.Lerp(10f, 20f, (float)i / 16f);
                TerrainBrush item          = CreateTreeBrush(random, GetTreeTrunkValue(TreeType.Oak), GetTreeLeavesValue(TreeType.Oak), height4, branchesCount, delegate(int y)
                {
                    float num7 = 0.4f;
                    if ((float)y < 0.2f * (float)height4)
                    {
                        num7 = 0f;
                    }
                    else if ((float)y >= 0.2f * (float)height4 && y <= height4)
                    {
                        num7 *= 1.5f;
                    }
                    return(num7);
                }, delegate(int y)
                {
                    if ((float)y < (float)height4 * 0.3f || (float)y > (float)height4 * 0.9f)
                    {
                        return(0f);
                    }
                    float num6 = ((float)y < (float)height4 * 0.7f) ? (0.5f * (float)height4) : (0.35f * (float)height4);
                    return(random.Float(0.33f, 1f) * num6);
                });
                m_treeBrushesByType[0].Add(item);
            }
            m_treeBrushesByType[1] = new List <TerrainBrush>();
            for (int j = 0; j < 16; j++)
            {
                int[] array2 = new int[16]
                {
                    4,
                    5,
                    6,
                    6,
                    7,
                    7,
                    7,
                    8,
                    8,
                    8,
                    9,
                    9,
                    9,
                    10,
                    10,
                    11
                };
                int          height3        = array2[j];
                int          branchesCount2 = (int)MathUtils.Lerp(0f, 20f, (float)j / 16f);
                TerrainBrush item2          = CreateTreeBrush(random, GetTreeTrunkValue(TreeType.Birch), GetTreeLeavesValue(TreeType.Birch), height3, branchesCount2, delegate(int y)
                {
                    float num5 = 0.66f;
                    if (y < height3 / 2 - 1)
                    {
                        num5 = 0f;
                    }
                    else if (y > height3 / 2 && y <= height3)
                    {
                        num5 *= 1.5f;
                    }
                    return(num5);
                }, (int y) => ((float)y <(float)height3 * 0.35f || (float)y> (float) height3 * 0.75f) ? 0f : random.Float(0f, 0.33f * (float)height3));
                m_treeBrushesByType[1].Add(item2);
            }
            m_treeBrushesByType[2] = new List <TerrainBrush>();
            for (int k = 0; k < 16; k++)
            {
                int[] array3 = new int[16]
                {
                    7,
                    8,
                    9,
                    10,
                    10,
                    11,
                    11,
                    12,
                    12,
                    13,
                    13,
                    14,
                    14,
                    15,
                    16,
                    17
                };
                int          height2        = array3[k];
                int          branchesCount3 = height2 * 3;
                TerrainBrush item3          = CreateTreeBrush(random, GetTreeTrunkValue(TreeType.Spruce), GetTreeLeavesValue(TreeType.Spruce), height2, branchesCount3, delegate(int y)
                {
                    float num4 = MathUtils.Lerp(1.4f, 0.3f, (float)y / (float)height2);
                    if (y < 3)
                    {
                        num4 = 0f;
                    }
                    if (y % 2 == 0)
                    {
                        num4 *= 0.3f;
                    }
                    return(num4);
                }, delegate(int y)
                {
                    if (y < 3 || (float)y > (float)height2 * 0.8f)
                    {
                        return(0f);
                    }
                    return((y % 2 == 0) ? 0f : MathUtils.Lerp(0.3f * (float)height2, 0f, MathUtils.Saturate((float)y / (float)height2)));
                });
                m_treeBrushesByType[2].Add(item3);
            }
            m_treeBrushesByType[3] = new List <TerrainBrush>();
            for (int l = 0; l < 16; l++)
            {
                int[] array4 = new int[18]
                {
                    20,
                    21,
                    22,
                    23,
                    24,
                    24,
                    25,
                    25,
                    26,
                    26,
                    27,
                    27,
                    28,
                    28,
                    29,
                    29,
                    30,
                    30
                };
                int          height         = array4[l];
                int          branchesCount4 = height * 3;
                float        startHeight    = (0.3f + (float)(l % 4) * 0.05f) * (float)height;
                TerrainBrush item4          = CreateTreeBrush(random, GetTreeTrunkValue(TreeType.TallSpruce), GetTreeLeavesValue(TreeType.TallSpruce), height, branchesCount4, delegate(int y)
                {
                    float num2 = MathUtils.Saturate((float)y / (float)height);
                    float num3 = MathUtils.Lerp(1.5f, 0f, MathUtils.Saturate((num2 - 0.6f) / 0.4f));
                    if ((float)y < startHeight)
                    {
                        num3 = 0f;
                    }
                    if (y % 3 != 0 && y < height - 4)
                    {
                        num3 *= 0.2f;
                    }
                    return(num3);
                }, delegate(int y)
                {
                    float num = MathUtils.Saturate((float)y / (float)height);
                    if (y % 3 != 0)
                    {
                        return(0f);
                    }
                    return(((float)y < startHeight) ? ((!((float)y < startHeight - 4f)) ? (0.1f * (float)height) : 0f) : MathUtils.Lerp(0.18f * (float)height, 0f, MathUtils.Saturate((num - 0.6f) / 0.4f)));
                });
                m_treeBrushesByType[3].Add(item4);
            }
            m_treeBrushesByType[4] = new List <TerrainBrush>();
            for (int m = 0; m < 16; m++)
            {
                m_treeBrushesByType[4].Add(CreateMimosaBrush(random, MathUtils.Lerp(6f, 9f, (float)m / 15f)));
            }
        }
Пример #7
0
        public override void Load(ValuesDictionary valuesDictionary)
        {
            base.Load(valuesDictionary);
            Utils.Load(Project);
            //Utils.SubsystemItemsScanner.ItemsScanned += GarbageCollectItems;
            var arr = valuesDictionary.GetValue("AlloysData", "0").Split(',');

            AlloysData = new DynamicArray <Metal>(arr.Length);
            int i;

            for (i = 0; i < arr.Length; i++)
            {
                if (short.TryParse(arr[i], NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out short value))
                {
                    AlloysData.Add((Metal)value);
                }
            }
            SmallBrushes = new TerrainBrush[16];
            PtBrushes    = new TerrainBrush[16];
            BBrushes     = new TerrainBrush[16];
            ABrushes     = new TerrainBrush[16];
            //NaruralGasBrushes = new TerrainBrush[16];
            OilPocketCells = new TerrainBrush.Cell[16][];
            //MinCounts = new int[12, 16];
            var          random = new Random(17034);
            TerrainBrush brush;
            int          j, k;

            for (i = 0; i < 16; i++)
            {
                brush = new TerrainBrush();
                Vector3 v, vec;
                for (j = random.Int() & 1; j-- != 0;)
                {
                    v   = 0.5f * Vector3.Normalize(new Vector3(random.UniformFloat(-1f, 1f), random.UniformFloat(-1f, 1f), random.UniformFloat(-1f, 1f)));
                    vec = Vector3.Zero;
                    for (k = random.UniformInt(2, 5); k-- != 0;)
                    {
                        brush.AddBox((int)MathUtils.Floor(vec.X), (int)MathUtils.Floor(vec.Y), (int)MathUtils.Floor(vec.Z), 1, 1, 1, 1);                         //Ag
                        vec += v;
                    }
                }
                brush.Compile();
                SmallBrushes[i] = brush;
                brush           = new TerrainBrush();
                for (j = random.UniformInt(1, 3); j-- != 0;)
                {
                    v   = 0.5f * Vector3.Normalize(new Vector3(random.UniformFloat(-1f, 1f), random.UniformFloat(-2f, 2f), random.UniformFloat(-1f, 1f)));
                    vec = Vector3.Zero;
                    for (k = random.UniformInt(2, 3); k-- != 0;)
                    {
                        brush.AddBox((int)MathUtils.Floor(vec.X), (int)MathUtils.Floor(vec.Y), (int)MathUtils.Floor(vec.Z), 1, 1, 1, 2);                         //Pt
                        vec += v;
                    }
                }
                brush.Compile();
                PtBrushes[i] = brush;
                brush        = new TerrainBrush();
                for (j = random.UniformInt(2, 4); j-- != 0;)
                {
                    v   = 0.5f * Vector3.Normalize(new Vector3(random.UniformFloat(-1f, 1f), random.UniformFloat(-0.25f, 0.25f), random.UniformFloat(-1f, 1f)));
                    vec = Vector3.Zero;
                    for (k = random.UniformInt(3, 5); k-- != 0;)
                    {
                        brush.AddBox((int)MathUtils.Floor(vec.X), (int)MathUtils.Floor(vec.Y), (int)MathUtils.Floor(vec.Z), 1, 1, 1, 8);                         //Ti
                        vec += v;
                    }
                }
                brush.Compile();
                ABrushes[i] = brush;
                brush       = new TerrainBrush();
                for (j = random.UniformInt(3, 5); j-- != 0;)
                {
                    v   = 0.5f * Vector3.Normalize(new Vector3(random.UniformFloat(-1f, 1f), random.UniformFloat(-1f, 1f), random.UniformFloat(-1f, 1f)));
                    vec = Vector3.Zero;
                    for (k = random.UniformInt(2, 5); k-- != 0;)
                    {
                        brush.AddBox((int)MathUtils.Floor(vec.X), (int)MathUtils.Floor(vec.Y), (int)MathUtils.Floor(vec.Z), 1, 1, 1, 5);                         //Sn
                        vec += v;
                    }
                }
                brush.Compile();
                BBrushes[i] = brush;
                var cells = TerrainContentsGenerator.m_basaltPocketBrushes[i].Cells;
                OilPocketCells[i] = new TerrainBrush.Cell[j = cells.Length];
                while (j-- != 0)
                {
                    if ((cells[j].Value & random.Int()) != 0)
                    {
                        OilPocketCells[i][j]       = cells[j];
                        OilPocketCells[i][j].Value = RottenMeatBlock.Index | 1 << 4 << 14;
                    }
                }
            }
        }