Esempio n. 1
0
        public override void Print(SectionLayer layer)
        {
            Vector3 a = this.TrueCenter();

            Rand.PushState();
            Rand.Seed = base.Position.GetHashCode();
            int num = Mathf.CeilToInt(this.growthInt * (float)this.def.plant.maxMeshCount);

            if (num < 1)
            {
                num = 1;
            }
            float   num2   = this.def.plant.visualSizeRange.LerpThroughRange(this.growthInt);
            float   num3   = this.def.graphicData.drawSize.x * num2;
            Vector3 vector = Vector3.zero;
            int     num4   = 0;

            int[] positionIndices = PlantPosIndices.GetPositionIndices(this);
            bool  flag            = false;

            foreach (int num5 in positionIndices)
            {
                if (this.def.plant.maxMeshCount == 1)
                {
                    vector = a + Gen.RandomHorizontalVector(0.05f);
                    float num6 = (float)base.Position.z;
                    if (vector.z - num2 / 2f < num6)
                    {
                        vector.z = num6 + num2 / 2f;
                        flag     = true;
                    }
                }
                else
                {
                    int num7         = 1;
                    int maxMeshCount = this.def.plant.maxMeshCount;
                    switch (maxMeshCount)
                    {
                    case 1:
                        num7 = 1;
                        break;

                    default:
                        if (maxMeshCount != 9)
                        {
                            if (maxMeshCount != 16)
                            {
                                if (maxMeshCount != 25)
                                {
                                    Log.Error(this.def + " must have plant.MaxMeshCount that is a perfect square.", false);
                                }
                                else
                                {
                                    num7 = 5;
                                }
                            }
                            else
                            {
                                num7 = 4;
                            }
                        }
                        else
                        {
                            num7 = 3;
                        }
                        break;

                    case 4:
                        num7 = 2;
                        break;
                    }
                    float num8 = 1f / (float)num7;
                    vector    = base.Position.ToVector3();
                    vector.y  = this.def.Altitude;
                    vector.x += 0.5f * num8;
                    vector.z += 0.5f * num8;
                    int num9  = num5 / num7;
                    int num10 = num5 % num7;
                    vector.x += (float)num9 * num8;
                    vector.z += (float)num10 * num8;
                    float max = num8 * 0.3f;
                    vector += Gen.RandomHorizontalVector(max);
                }
                bool     @bool     = Rand.Bool;
                Material matSingle = this.Graphic.MatSingle;
                GenPlant.SetWindExposureColors(Plant.workingColors, this);
                Vector2  vector2 = new Vector2(num3, num3);
                Vector3  center  = vector;
                Vector2  size    = vector2;
                Material mat     = matSingle;
                bool     flipUv  = @bool;
                Printer_Plane.PrintPlane(layer, center, size, mat, 0f, flipUv, null, Plant.workingColors, 0.1f, (float)(this.HashOffset() % 1024));
                num4++;
                if (num4 >= num)
                {
                    break;
                }
            }
            if (this.def.graphicData.shadowData != null)
            {
                Vector3 center2 = a + this.def.graphicData.shadowData.offset * num2;
                if (flag)
                {
                    center2.z = base.Position.ToVector3Shifted().z + this.def.graphicData.shadowData.offset.z;
                }
                center2.y -= 0.046875f;
                Vector3 volume = this.def.graphicData.shadowData.volume * num2;
                Printer_Shadow.PrintShadow(layer, center2, volume, Rot4.North);
            }
            Rand.PopState();
        }
Esempio n. 2
0
        public override void Print(SectionLayer layer)
        {
            Vector3 trueCenter = this.TrueCenter();

            Rand.PushState();
            Rand.Seed = Position.GetHashCode();    //So our random generator makes the same numbers every time

            //Determine how many meshes to print
            int meshCount = Mathf.CeilToInt(growthInt * def.plant.maxMeshCount);

            if (meshCount < 1)
            {
                meshCount = 1;
            }

            //Determine plane size
            float size        = def.plant.visualSizeRange.LerpThroughRange(growthInt);
            float graphicSize = def.graphicData.drawSize.x * size;     //Plants don't support non-square drawSizes

            //Shuffle up the position indices and place meshes at them
            //We do this to get even mesh placement by placing them roughly on a grid
            Vector3 adjustedCenter            = Vector3.zero;
            int     meshesYielded             = 0;
            var     posIndexList              = PlantPosIndices.GetPositionIndices(this);
            bool    clampedBottomToCellBottom = false;

            for (int i = 0; i < posIndexList.Length; i++)
            {
                int posIndex = posIndexList[i];

                //Determine center position
                if (def.plant.maxMeshCount == 1)
                {
                    //Determine random local position variance
                    const float PositionVariance = 0.05f;

                    adjustedCenter = trueCenter + Gen.RandomHorizontalVector(PositionVariance);

                    //Clamp bottom of plant to square bottom
                    //So tall plants grow upward
                    float squareBottom = Position.z;
                    if (adjustedCenter.z - size / 2f < squareBottom)
                    {
                        adjustedCenter.z          = squareBottom + size / 2f;
                        clampedBottomToCellBottom = true;
                    }
                }
                else
                {
                    //Grid width is the square root of max mesh count
                    int gridWidth = 1;
                    switch (def.plant.maxMeshCount)
                    {
                    case 1: gridWidth = 1; break;

                    case 4: gridWidth = 2; break;

                    case 9: gridWidth = 3; break;

                    case 16: gridWidth = 4; break;

                    case 25: gridWidth = 5; break;

                    default: Log.Error(def + " must have plant.MaxMeshCount that is a perfect square."); break;
                    }
                    float gridSpacing = 1f / gridWidth;         //This works out to give half-spacings around the edges

                    adjustedCenter   = Position.ToVector3();    //unshifted
                    adjustedCenter.y = def.Altitude;            //Set altitude

                    //Place this mesh at its randomized position on the submesh grid
                    adjustedCenter.x += 0.5f * gridSpacing;
                    adjustedCenter.z += 0.5f * gridSpacing;
                    int xInd = posIndex / gridWidth;
                    int zInd = posIndex % gridWidth;
                    adjustedCenter.x += xInd * gridSpacing;
                    adjustedCenter.z += zInd * gridSpacing;

                    //Add a random offset
                    float gridPosRandomness = gridSpacing * GridPosRandomnessFactor;
                    adjustedCenter += Gen.RandomHorizontalVector(gridPosRandomness);
                }

                //Randomize horizontal flip
                bool flipped = Rand.Bool;

                //Randomize material
                var mat = Graphic.MatSingle;         //Pulls a random material

                //Set wind exposure value at each vertex by setting vertex color
                PlantUtility.SetWindExposureColors(workingColors, this);

                var planeSize = new Vector2(graphicSize, graphicSize);

                Printer_Plane.PrintPlane(layer,
                                         adjustedCenter,
                                         planeSize,
                                         mat,
                                         flipUv: flipped,
                                         colors:  workingColors,
                                         topVerticesAltitudeBias: TopVerticesAltitudeBias,                                      // need to beat walls corner filler (so trees don't get cut by mountains)
                                         uvzPayload: Gen.HashOffset(this) % 1024);


                meshesYielded++;
                if (meshesYielded >= meshCount)
                {
                    break;
                }
            }

            if (def.graphicData.shadowData != null)
            {
                //Start with a standard shadow center
                var shadowCenter = trueCenter + def.graphicData.shadowData.offset * size;

                //Clamp center of shadow to cell bottom
                if (clampedBottomToCellBottom)
                {
                    shadowCenter.z = Position.ToVector3Shifted().z + def.graphicData.shadowData.offset.z;
                }

                shadowCenter.y -= Altitudes.AltInc;

                var shadowVolume = def.graphicData.shadowData.volume * size;

                Printer_Shadow.PrintShadow(layer, shadowCenter, shadowVolume, Rot4.North);
            }

            Rand.PopState();
        }
Esempio n. 3
0
        public override void Print(SectionLayer layer)
        {
            Vector3 a = this.TrueCenter();

            Rand.PushState();
            Rand.Seed = base.Position.GetHashCode();
            int num = Mathf.CeilToInt(this.growthInt * (float)base.def.plant.maxMeshCount);

            if (num < 1)
            {
                num = 1;
            }
            float   num2   = base.def.plant.visualSizeRange.LerpThroughRange(this.growthInt);
            float   num3   = base.def.graphicData.drawSize.x * num2;
            Vector3 vector = Vector3.zero;
            int     num4   = 0;

            int[] positionIndices = PlantPosIndices.GetPositionIndices(this);
            bool  flag            = false;
            int   num5            = 0;

            while (num5 < positionIndices.Length)
            {
                int num6 = positionIndices[num5];
                if (base.def.plant.maxMeshCount == 1)
                {
                    vector = a + Gen.RandomHorizontalVector(0.05f);
                    IntVec3 position = base.Position;
                    float   num7     = (float)position.z;
                    if (vector.z - num2 / 2.0 < num7)
                    {
                        vector.z = (float)(num7 + num2 / 2.0);
                        flag     = true;
                    }
                }
                else
                {
                    int num8 = 1;
                    switch (base.def.plant.maxMeshCount)
                    {
                    case 1:
                        num8 = 1;
                        break;

                    case 4:
                        num8 = 2;
                        break;

                    case 9:
                        num8 = 3;
                        break;

                    case 16:
                        num8 = 4;
                        break;

                    case 25:
                        num8 = 5;
                        break;

                    default:
                        Log.Error(base.def + " must have plant.MaxMeshCount that is a perfect square.");
                        break;
                    }
                    float num9 = (float)(1.0 / (float)num8);
                    vector    = base.Position.ToVector3();
                    vector.y  = base.def.Altitude;
                    vector.x += (float)(0.5 * num9);
                    vector.z += (float)(0.5 * num9);
                    int num10 = num6 / num8;
                    int num11 = num6 % num8;
                    vector.x += (float)num10 * num9;
                    vector.z += (float)num11 * num9;
                    float max = (float)(num9 * 0.30000001192092896);
                    vector += Gen.RandomHorizontalVector(max);
                }
                bool     @bool     = Rand.Bool;
                Material matSingle = this.Graphic.MatSingle;
                GenPlant.SetWindExposureColors(Plant.workingColors, this);
                Vector2  vector2 = new Vector2(num3, num3);
                Vector3  center  = vector;
                Vector2  size    = vector2;
                Material mat     = matSingle;
                bool     flipUv  = @bool;
                Printer_Plane.PrintPlane(layer, center, size, mat, 0f, flipUv, null, Plant.workingColors, 0.1f);
                num4++;
                if (num4 < num)
                {
                    num5++;
                    continue;
                }
                break;
            }
            if (base.def.graphicData.shadowData != null)
            {
                Vector3 center2 = a + base.def.graphicData.shadowData.offset * num2;
                if (flag)
                {
                    Vector3 center = base.Position.ToVector3Shifted();
                    center2.z = center.z + base.def.graphicData.shadowData.offset.z;
                }
                center2.y -= 0.046875f;
                Vector3 volume = base.def.graphicData.shadowData.volume * num2;
                Printer_Shadow.PrintShadow(layer, center2, volume, Rot4.North);
            }
            Rand.PopState();
        }
Esempio n. 4
0
        public override void Print(SectionLayer layer)
        {
            Vector3 a = this.TrueCenter();

            Rand.PushState();
            Rand.Seed = base.Position.GetHashCode();
            int num = Mathf.CeilToInt(growthInt * (float)def.plant.maxMeshCount);

            if (num < 1)
            {
                num = 1;
            }
            float   num2   = def.plant.visualSizeRange.LerpThroughRange(growthInt);
            float   num3   = def.graphicData.drawSize.x * num2;
            Vector3 center = Vector3.zero;
            int     num4   = 0;

            int[] positionIndices = PlantPosIndices.GetPositionIndices(this);
            bool  flag            = false;

            foreach (int num5 in positionIndices)
            {
                if (def.plant.maxMeshCount == 1)
                {
                    center = a + Gen.RandomHorizontalVector(0.05f);
                    float num6 = base.Position.z;
                    if (center.z - num2 / 2f < num6)
                    {
                        center.z = num6 + num2 / 2f;
                        flag     = true;
                    }
                }
                else
                {
                    int num7 = 1;
                    switch (def.plant.maxMeshCount)
                    {
                    case 1:
                        num7 = 1;
                        break;

                    case 4:
                        num7 = 2;
                        break;

                    case 9:
                        num7 = 3;
                        break;

                    case 16:
                        num7 = 4;
                        break;

                    case 25:
                        num7 = 5;
                        break;

                    default:
                        Log.Error(def + " must have plant.MaxMeshCount that is a perfect square.");
                        break;
                    }
                    float num8 = 1f / (float)num7;
                    center    = base.Position.ToVector3();
                    center.y  = def.Altitude;
                    center.x += 0.5f * num8;
                    center.z += 0.5f * num8;
                    int num9  = num5 / num7;
                    int num10 = num5 % num7;
                    center.x += (float)num9 * num8;
                    center.z += (float)num10 * num8;
                    float max = num8 * 0.3f;
                    center += Gen.RandomHorizontalVector(max);
                }
                bool     @bool     = Rand.Bool;
                Material matSingle = Graphic.MatSingle;
                PlantUtility.SetWindExposureColors(workingColors, this);
                Printer_Plane.PrintPlane(size: new Vector2(num3, num3), layer: layer, center: center, mat: matSingle, rot: 0f, flipUv: @bool, uvs: null, colors: workingColors, topVerticesAltitudeBias: 0.1f, uvzPayload: this.HashOffset() % 1024);
                num4++;
                if (num4 >= num)
                {
                    break;
                }
            }
            if (def.graphicData.shadowData != null)
            {
                Vector3 center2 = a + def.graphicData.shadowData.offset * num2;
                if (flag)
                {
                    center2.z = base.Position.ToVector3Shifted().z + def.graphicData.shadowData.offset.z;
                }
                center2.y -= 0.0454545468f;
                Vector3 volume = def.graphicData.shadowData.volume * num2;
                Printer_Shadow.PrintShadow(layer, center2, volume, Rot4.North);
            }
            Rand.PopState();
        }