Пример #1
0
        public override void Print(SectionLayer layer)
        {
            Plant plant = this.Plant;

            if (plant != null)
            {
                PlantUtility.SetWindExposureColors(Blight.workingColors, plant);
            }
            else
            {
                Blight.workingColors[0].a = (Blight.workingColors[1].a = (Blight.workingColors[2].a = (Blight.workingColors[3].a = 0)));
            }
            float num = Blight.SizeRange.LerpThroughRange(this.severity);

            if (plant != null)
            {
                float a = plant.Graphic.drawSize.x * plant.def.plant.visualSizeRange.LerpThroughRange(plant.Growth);
                num *= Mathf.Min(a, 1f);
            }
            num = Mathf.Clamp(num, 0.5f, 0.9f);
            Vector3  center = this.TrueCenter();
            Vector2  size   = this.def.graphic.drawSize * num;
            Material mat    = this.Graphic.MatAt(base.Rotation, this);

            Color32[] colors = Blight.workingColors;
            Printer_Plane.PrintPlane(layer, center, size, mat, 0f, false, null, colors, 0.1f, 0f);
        }
Пример #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();
        }
Пример #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)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;

            for (int i = 0; i < positionIndices.Length; i++)
            {
                int num5 = positionIndices[i];
                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;
                        goto IL_19F;

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

                    case 4:
                        num7 = 2;
                        goto IL_19F;
                    }
                    goto IL_13C;
IL_19F:
                    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;
                PlantUtility.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();
        }
Пример #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();
        }