Exemple #1
0
        public virtual float GetPerishRate()
        {
            BlockPos sealevelpos = pos.Copy();

            sealevelpos.Y = api.World.SeaLevel;

            ClimateCondition cond = api.World.BlockAccessor.GetClimateAt(sealevelpos);

            Cellar cellar = api.ModLoader.GetModSystem <CellarRegistry>().GetCellarForPosition(pos);

            float soilTempWeight = 0f;

            if (cellar != null)
            {
                soilTempWeight = 0.5f + 0.5f * (1 - GameMath.Clamp((float)cellar.NonCoolingWallCount / Math.Max(1, cellar.CoolingWallCount), 0, 1));
            }

            int lightlevel = api.World.BlockAccessor.GetLightLevel(pos, EnumLightLevelType.OnlySunLight);

            // light level above 12 makes it additionally warmer, especially when part of a cellar
            float airTemp = cond.Temperature + GameMath.Clamp(lightlevel - 11, 0, 10) * (1f + 5 * soilTempWeight);


            // Lets say deep soil temperature is a constant 5°C
            float cellarTemp = 5;

            // How good of a cellar it is depends on how much rock or soil was used on he cellars walls
            float hereTemp = GameMath.Lerp(airTemp, cellarTemp, soilTempWeight);

            // For fairness lets say if its colder outside, use that temp instead
            hereTemp = Math.Min(hereTemp, airTemp);

            // Some neat curve to turn the temperature into a spoilage rate
            // http://fooplot.com/#W3sidHlwZSI6MCwiZXEiOiJtYXgoMC4xLG1pbigyLjUsM14oeC8xOS0xLjIpKS0wLjEpIiwiY29sb3IiOiIjMDAwMDAwIn0seyJ0eXBlIjoxMDAwLCJ3aW5kb3ciOlsiLTIwIiwiNDAiLCIwIiwiMyJdLCJncmlkIjpbIjIuNSIsIjAuMjUiXX1d
            // max(0.1, min(2.5, 3^(x/15 - 1.2))-0.1)
            float rate = Math.Max(0.1f, Math.Min(2.4f, (float)Math.Pow(3, hereTemp / 19 - 1.2) - 0.1f));

            return(rate);
        }
Exemple #2
0
        public Cellar GetCellarForPosition(BlockPos pos)
        {
            long index3d = MapUtil.Index3dL(pos.X / chunksize, pos.Y / chunksize, pos.Z / chunksize, chunkMapSizeX, chunkMapSizeZ);

            ChunkCellars cellars = null;
            Cellar       cellar  = null;

            if (CellarsByChunkIndex.TryGetValue(index3d, out cellars))
            {
                if (cellars.CellarByPosition.TryGetValue(pos, out cellar))
                {
                    return(cellar);
                }

                cellar = FindCellarForPosition(pos);
                cellars.CellarByPosition[pos] = cellar;
                return(cellar);
            }

            cellar = FindCellarForPosition(pos);
            CellarsByChunkIndex[index3d] = new ChunkCellars();
            CellarsByChunkIndex[index3d].CellarByPosition[pos] = cellar;
            return(cellar);
        }