Exemple #1
0
        protected override void ReadEntry(JObject entry)
        {
            var name     = entry.ReadString("name");
            var unitTime = entry.ReadUInt("unitTime");             // number of hours
            var seed     = entry.ReadUInt("seed");
            var baseTime = entry.ReadString("baseTime");

            var data = new WeatherTableData();

            DateTime dt;

            DateTime.TryParseExact(baseTime, "yyyyMMddhhmm", null, DateTimeStyles.AssumeLocal, out dt);
            data.BaseTime = dt.Ticks;

            var rnd   = new CRandom(seed);
            var count = (int)(3600000 * unitTime / 1200000);             // number of 20 min periods

            foreach (var cols in entry["rows"].Select(row => row.ToObject <float[]>()))
            {
                for (var i = 0; i < count; ++i)
                {
                    data.Values.Add(this.ComputeWeather(cols, rnd));
                }
            }

            this.Entries[name] = data;
        }
Exemple #2
0
        private float ComputeWeather(float[] cols, CRandom rnd)
        {
            var result    = 2.0f;
            var addedCols = new float[4];

            addedCols[0] = cols[0];
            for (var i = 1; i < 4; ++i)
            {
                addedCols[i] += addedCols[i - 1] + cols[i];
            }

            float randFloat;

            try
            {
                randFloat = rnd.RandomF32(0.0f, addedCols[3]);
            }
            catch (CRandomException)
            {
                return(-1.0f);
            }

            if (addedCols[1] >= randFloat)
            {
                if (addedCols[0] >= randFloat)
                {
                    if (cols[0] <= 0.0)
                    {
                        result = 0.5f;
                    }
                    else
                    {
                        result = randFloat / cols[0];
                    }
                }
                else
                {
                    result = (randFloat - addedCols[0]) * 0.95f / cols[1] + 1.0f;
                }
            }
            else
            {
                result = (randFloat - addedCols[1]) * 0.05f / cols[2] + 1.95f;
            }

            return(result);
        }