Exemplo 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();
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
    public override void PrintOnto(SectionLayer layer)
    {
        Profiler.BeginSample("Plant.EmitMeshPieces " + this);

        Vector3 trueCenter = this.TrueCenter();

        Profiler.BeginSample("Meshes");

        Random.seed = Position.GetHashCode();        //So our random generator makes the same numbers every time

        //Determine random local position variance
        float positionVariance;

        if (def.plant.maxMeshCount == 1)
        {
            positionVariance = 0.05f;
        }
        else
        {
            positionVariance = 0.50f;
        }

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

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

        //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

        //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;
        Vector2 planeSize      = Vector2.zero;
        int     meshesYielded  = 0;
        int     posCount       = posIndexList.Count;

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

            //Determine plane size
            float size = def.plant.visualSizeRange.LerpThroughRange(growthPercent);

            //Determine center position
            if (def.plant.maxMeshCount == 1)
            {
                adjustedCenter = trueCenter + new Vector3(Random.Range(-positionVariance, positionVariance),
                                                          0,
                                                          Random.Range(-positionVariance, positionVariance));

                //Clamp bottom of plant to square bottom
                //So tall plants grow upward
                float squareBottom = Mathf.Floor(trueCenter.z);
                if ((adjustedCenter.z - (size / 2f)) < squareBottom)
                {
                    adjustedCenter.z = squareBottom + (size / 2f);
                }
            }
            else
            {
                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 += new Vector3(Random.Range(-gridPosRandomness, gridPosRandomness),
                                              0,
                                              Random.Range(-gridPosRandomness, gridPosRandomness));
            }

            //Randomize horizontal flip
            bool flipped = Random.value < 0.5f;

            //Randomize material
            Material mat = def.folderDrawMats.RandomListElement();

            //Set wind exposure value at each vertex by setting vertex color
            workingColors[1].a = workingColors[2].a = (byte)(255 * def.plant.topWindExposure);
            workingColors[0].a = workingColors[3].a = 0;

            if (def.overdraw)
            {
                size += 2f;
            }
            planeSize = new Vector2(size, size);
            Printer_Plane.PrintPlane(layer,
                                     adjustedCenter,
                                     planeSize,
                                     mat,
                                     flipUv: flipped,
                                     colors:  workingColors);


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

        Profiler.EndSample();

        Profiler.BeginSample("Shadow");

        if (def.sunShadowInfo != null)
        {
            //Brutal shadow positioning hack
            float shadowOffsetFactor = 0.85f;
            if (planeSize.y < 1)
            {
                shadowOffsetFactor = 0.6f;                 //for bushes
            }
            else
            {
                shadowOffsetFactor = 0.81f;                     //for cacti
            }
            Vector3 sunShadowLoc = adjustedCenter;
            sunShadowLoc.z -= (planeSize.y / 2f) * shadowOffsetFactor;
            sunShadowLoc.y -= Altitudes.AltInc;

            Printer_Shadow.PrintShadow(layer, sunShadowLoc, def.sunShadowInfo);
        }

        Profiler.EndSample();

        Profiler.EndSample();
    }
Exemplo n.º 4
0
        public void Print(Plant plant, SectionLayer layer, Graphic newGraphic, int curLevel, int baseLevel)
        {
            Vector3 a = plant.TrueCenter();

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

            if (num < 1)
            {
                num = 1;
            }
            float num2 = plant.def.plant.visualSizeRange.LerpThroughRange(plant.growthInt);
            float num3 = plant.def.graphicData.drawSize.x * num2;

            Vector3 center = Vector3.zero;
            int     num4   = 0;

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

            foreach (int num5 in positionIndices)
            {
                if (plant.def.plant.maxMeshCount == 1)
                {
                    center = a + Gen.RandomHorizontalVector(0.05f);
                    float num6 = plant.Position.z;
                    if (center.z - num2 / 2f < num6)
                    {
                        center.z = num6 + num2 / 2f;
                        flag     = true;
                    }
                }
                else
                {
                    int num7 = 1;
                    switch (plant.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(string.Concat(plant.def, " must have plant.MaxMeshCount that is a perfect square."));
                        break;
                    }
                    float num8 = 1f / (float)num7;
                    center    = plant.Position.ToVector3();
                    center.y  = plant.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 = newGraphic.MatSingle;
                PlantUtility.SetWindExposureColors(Plant.workingColors, plant);
                center.z -= (curLevel - baseLevel) / 1.5f;
                center.y -= curLevel - baseLevel;
                num3     *= 1f - (((float)(curLevel) - (float)baseLevel) / 5f);
                Printer_Plane.PrintPlane(size: new Vector2(num3, num3), layer: layer, center: center, mat: matSingle, rot: 0f, flipUv: @bool, uvs: null,
                                         colors: Plant.workingColors, topVerticesAltitudeBias: 0.1f, uvzPayload: plant.HashOffset() % 1024);
                num4++;
                if (num4 >= num)
                {
                    break;
                }
            }
            if (plant.def.graphicData.shadowData != null)
            {
                Vector3 center2 = a + plant.def.graphicData.shadowData.offset * num2;
                if (flag)
                {
                    center2.z = plant.Position.ToVector3Shifted().z + plant.def.graphicData.shadowData.offset.z;
                }
                center2.y -= 3f / 70f;
                center2.z -= (curLevel - baseLevel) / 2f;
                center2.y -= curLevel - baseLevel;
                Vector3 volume = plant.def.graphicData.shadowData.volume * num2;
                Printer_Shadow.PrintShadow(layer, center2, volume, Rot4.North);
            }
            Rand.PopState();
        }
Exemplo n.º 5
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();
        }