Пример #1
0
        public static TerrainDefault StretchTerrainFertility(TerrainDefault old, float min, float max)
        {
            oldTerrain = old;
            minMapFert = min;
            maxMapFert = max;

            newTerrain = new TerrainDefault();
            newTerrain.terrainsByFertility = new List <TerrainThreshold>(oldTerrain.terrainsByFertility);

            newTerrain.terrainPatchMakers = new List <TerrainPatchMaker>();
            for (int i = 0; i < oldTerrain.terrainPatchMakers.Count(); i++)
            {
                TerrainPatchMaker p = new TerrainPatchMaker();
                p.maxFertility      = oldTerrain.terrainPatchMakers[i].maxFertility;
                p.minFertility      = oldTerrain.terrainPatchMakers[i].minFertility;
                p.perlinFrequency   = oldTerrain.terrainPatchMakers[i].perlinFrequency;
                p.perlinLacunarity  = oldTerrain.terrainPatchMakers[i].perlinLacunarity;
                p.perlinOctaves     = oldTerrain.terrainPatchMakers[i].perlinOctaves;
                p.perlinPersistence = oldTerrain.terrainPatchMakers[i].perlinPersistence;
                p.thresholds        = new List <TerrainThreshold>(oldTerrain.terrainPatchMakers[i].thresholds);

                newTerrain.terrainPatchMakers.Add(p);
            }


            List <TerrainThreshold> oldTerrainsByFertility = oldTerrain.terrainsByFertility;

            List <TBF> listTbf = new List <TBF>();

            // convert to TBFs
            for (int i = 0; i < oldTerrainsByFertility.Count(); i++)
            {
                TBF item = new TBF()
                {
                    thresh = oldTerrainsByFertility[i],
                    size   = Math.Min(oldTerrainsByFertility[i].max, maxMapFert) - Math.Max(oldTerrainsByFertility[i].min, minMapFert)
                };
                listTbf.Add(item);
            }

            // the actual adjustments
            if (listTbf.Count() >= 1)
            {
                FertChangeTbf(listTbf);
            }

            // TerrainPatchMaker adjustments
            List <TerrainDef> patchTerrains = new List <TerrainDef>();

            foreach (TerrainPatchMaker p in newTerrain.terrainPatchMakers)
            {
                foreach (TerrainThreshold t in p.thresholds)
                {
                    patchTerrains.Add(t.terrain);
                }
            }

            // check that there are terrains
            if (patchTerrains.Count() >= 1)
            {
                FertChangePatchMakers(patchTerrains);
            }

            return(newTerrain);
        }
Пример #2
0
        private static void FertChangePatchMakers(List <TerrainDef> patchTerrains)
        {
            MapDesignerSettings settings = MapDesignerMod.mod.settings;
            float minAllowable           = -1.5f;
            float maxAllowable           = 1.5f;

            // find highest fert terrain overall
            patchTerrains.Sort((x, y) => x.fertility.CompareTo(y.fertility));

            float maxFert = patchTerrains.Max(t => t.fertility);

            for (int index = 0; index < newTerrain.terrainPatchMakers.Count; index++)
            {
                TerrainPatchMaker p = newTerrain.terrainPatchMakers[index];

                // sort terrains by min
                p.thresholds.Sort((x, y) => x.min.CompareTo(y.min));

                // Make new list:
                List <TBF> listTbf = new List <TBF>();
                float      current = -999f;

                for (int i = 0; i < p.thresholds.Count; i++)
                {
                    // if current == terrain min, add terrain to list
                    // set current = terrain max
                    // if terrain is the minFert or maxFert, change size appropriately
                    TBF tbf         = new TBF();
                    TBF placeholder = new TBF();
                    if (!Mathf.Approximately(current, p.thresholds[i].min))
                    {
                        //placeholder when needed
                        placeholder.size = Math.Min(p.thresholds[i].min, maxAllowable) - Math.Max(current, minAllowable);
                        current          = p.thresholds[i].min;
                        listTbf.Add(placeholder);
                    }

                    // real thing
                    current = p.thresholds[i].max;

                    tbf.thresh = p.thresholds[i];
                    tbf.size   = Math.Min(p.thresholds[i].max, maxAllowable) - Math.Max(p.thresholds[i].min, minAllowable);

                    if (tbf.thresh.terrain.fertility == maxFert)
                    {
                        tbf.size *= settings.terrainFert;
                    }

                    if (tbf.thresh.terrain.IsWater)
                    {
                        tbf.size *= settings.terrainWater;
                    }
                    else if (settings.flagTerrainWater && !tbf.thresh.terrain.affordances.Contains(TerrainAffordanceDefOf.Heavy))
                    {
                        tbf.size *= settings.terrainWater;
                    }
                    listTbf.Add(tbf);
                }

                // add extra placeholder at end if needed
                if (current < maxAllowable)
                {
                    listTbf.Add(new TBF()
                    {
                        size = maxAllowable - current
                    });
                }
                newTerrain.terrainPatchMakers[index].thresholds = SquishTerrain(listTbf, minAllowable, maxAllowable);
            }
        }