public void VerySimpleExample() { // This code is used as the example in the NamespaceDoc for Fudge.Serialization // Create a context and a serializer var context = new FudgeContext(); var serializer = new FudgeSerializer(context); // Our object to serialize var temperatureRange = new TemperatureRange { High = 28.3, Low = 13.2, Average = 19.6 }; // Serialize it to a MemoryStream var stream = new MemoryStream(); var streamWriter = new FudgeEncodedStreamWriter(context, stream); serializer.Serialize(streamWriter, temperatureRange); // Reset the stream and deserialize a new object from it stream.Position = 0; var streamReader = new FudgeEncodedStreamReader(context, stream); var range2 = (TemperatureRange)serializer.Deserialize(streamReader); // Just check a value matches Assert.Equal(temperatureRange, range2); }
public TemperatureRange AdjustTemperatureExposure(TemperatureRange temp) { //clothing has a heat and cold protection value //neither one results in a penalty (possible hard mode setting) //if it's cold, the cold protection is applied //if it's warm, the warm protection is applied //clothing will never make the player too hot or too cold int coldProtectValue = Mathf.FloorToInt(NormalizedRangeColdProtection * 5); //temps range from 0 to 4 int heatProtectValue = Mathf.FloorToInt(NormalizedRangeHeatProtection * 5); int adjustedTempValue = (int)temp; switch (temp) { case TemperatureRange.A_DeadlyCold: case TemperatureRange.B_Cold: adjustedTempValue = Mathf.Clamp(adjustedTempValue + coldProtectValue, (int)TemperatureRange.A_DeadlyCold, (int)TemperatureRange.C_Warm); //we can't get warmer than warm break; case TemperatureRange.C_Warm: default: break; case TemperatureRange.D_Hot: case TemperatureRange.E_DeadlyHot: adjustedTempValue = Mathf.Clamp(adjustedTempValue - heatProtectValue, (int)TemperatureRange.C_Warm, (int)TemperatureRange.E_DeadlyHot); //we can't get colder than warm break; } return((TemperatureRange)adjustedTempValue); }
private TemperatureRange GetRandomDayTemperature(TemperatureRange averageMonthTemperature) { TemperatureUnit unit = averageMonthTemperature.Min.Unit; int rnd1 = 0, rnd2 = 0; while(rnd1 == rnd2) { rnd1 = this.random.Next(averageMonthTemperature.Min.Value - 2, averageMonthTemperature.Min.Value + 2); rnd2 = this.random.Next(averageMonthTemperature.Max.Value - 2, averageMonthTemperature.Max.Value + 2); } return new TemperatureRange(unit, Math.Min(rnd1, rnd2), Math.Max(rnd1, rnd2)); }
public override int GetHashCode() { unchecked { var hashCode = (Inner != null ? Inner.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (TemperatureRange != null ? TemperatureRange.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Text != null ? Text.GetHashCode() : 0); return(hashCode); } }
private TemperatureRange GetRandomDayTemperature(TemperatureRange averageMonthTemperature) { TemperatureUnit unit = averageMonthTemperature.Min.Unit; int rnd1 = 0, rnd2 = 0; while (rnd1 == rnd2) { rnd1 = this.random.Next(averageMonthTemperature.Min.Value - 2, averageMonthTemperature.Min.Value + 2); rnd2 = this.random.Next(averageMonthTemperature.Max.Value - 2, averageMonthTemperature.Max.Value + 2); } return(new TemperatureRange(unit, Math.Min(rnd1, rnd2), Math.Max(rnd1, rnd2))); }
public WeatherInfo GetWeatherInfo(DateTime dateValue) { WeatherInfo info = weatherInfoCache[dateValue] as WeatherInfo; if (info == null) { Month month = (Month)(dateValue.Month - 1); TemperatureRange temperature = GetRandomDayTemperature(averageMonthTemperatures[month]); Cloudiness cloudiness = GetRandomCloudiness(); Rain rain = GetRandomRain(month, cloudiness); info = new WeatherInfo(dateValue, TemperatureUnit.Celsius, temperature.Min.Value, temperature.Max.Value, cloudiness, rain, GetRandomSnow(month), GetRandomFog(month), GetRandomHail(rain)); weatherInfoCache[dateValue] = info; } return(info); }
public void VerySimpleExample() { // This code is used as the example in the NamespaceDoc for Fudge.Serialization // Create a context and a serializer var context = new FudgeContext(); var serializer = new FudgeSerializer(context); // Our object to serialize var temperatureRange = new TemperatureRange { High = 28.3, Low = 13.2, Average = 19.6 }; // Serialize it to a MemoryStream var stream = new MemoryStream(); var streamWriter = new FudgeEncodedStreamWriter(context, stream); serializer.Serialize(streamWriter, temperatureRange); // Reset the stream and deserialize a new object from it stream.Position = 0; var streamReader = new FudgeEncodedStreamReader(context, stream); var range2 = (TemperatureRange)serializer.Deserialize(streamReader); // Just check a value matches Debug.Assert(range2.Average == 19.6); }
public bool TemperatureAndHumidityValid(Hex.TemperatureLevel temperature, Hex.HumidityLevel humidity) { return(TemperatureRange.Contains(temperature) && HumidityRange.Contains(humidity)); }
public void AddTemperature(Hex.TemperatureLevel temperature) { TemperatureRange.Add(temperature); }
protected bool Equals(TemperatureRange other) { return High.Equals(other.High) && Low.Equals(other.Low) && Average.Equals(other.Average); }
protected bool Equals(TemperatureRange other) { return(High.Equals(other.High) && Low.Equals(other.Low) && Average.Equals(other.Average)); }
private void FillWithDummyData() { CurrentConditions = new CurrentConditionsModel { ApparentTemperature = "18", ApparentTemperatureUnit = " C", Temperature = "15", TemperatureUnit = " C", ShortPhrase = "Overwegend bewolkt", WindDirection = "zzo", WindSpeed = "50", WindSpeedUnit = "km/u", GustSpeed = "56", GustSpeedUnit = "km/u", Precip1hr = "10", Precip1hrUnit = "mm/h", UpdatedDateTime = DateTime.Now }; HourlyModels = new ObservableCollection <HourlyModel>() { new HourlyModel { Date = DateTime.Now, PrecipationAmountRain = "10", ProbabilityOfPrecipation = "10%", PredictedRealFeel = "-10", PredictedTemperature = "-8", UVIndex = 0, WeatherCode = 1 }, new HourlyModel { Date = DateTime.Now.AddHours(1), PrecipationAmountRain = "10", ProbabilityOfPrecipation = "10%", PredictedRealFeel = "-10", PredictedTemperature = "-8", UVIndex = 1, WeatherCode = 2 }, new HourlyModel { Date = DateTime.Now.AddHours(2), PrecipationAmountRain = "20", ProbabilityOfPrecipation = "20%", PredictedRealFeel = "0", PredictedTemperature = "4", UVIndex = 2, WeatherCode = 3 }, new HourlyModel { Date = DateTime.Now.AddHours(3), PrecipationAmountRain = "5", ProbabilityOfPrecipation = "30%", PredictedRealFeel = "10", PredictedTemperature = "0", UVIndex = 3, WeatherCode = 4 }, new HourlyModel { Date = DateTime.Now.AddHours(4), PrecipationAmountRain = "7", ProbabilityOfPrecipation = "40%", PredictedRealFeel = "10", PredictedTemperature = "8", UVIndex = 3, WeatherCode = 5 }, }; try { StorageFile _storageFile = Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Weather/Icon/01.png")).GetResults(); IBuffer readbuffer = FileIO.ReadBufferAsync(_storageFile).GetResults(); CurrentConditions.WeatherIcon = readbuffer.ToArray(); } catch (Exception ex) { string message = ex.Message; } UVIndexList = new ObservableCollection <UVIndex> { new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/00.png"), "Ga gerust buiten tennissen.", "SPF15+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/01.png"), "Ga gerust buiten tennissen." + Environment.NewLine + "Rust in de schaduw.", "SPF15+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/02.png"), "Ga gerust buiten tennissen." + Environment.NewLine + "Rust in de schaduw.", "SPF15+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/03.png"), "Niet langer dan 40 minuten tennissen of in de zon." + Environment.NewLine + "Rust in de schaduw.", "SPF15+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/04.png"), "Niet langer dan 40 minuten tennissen of in de zon." + Environment.NewLine + "Rust in de schaduw.", "SPF15+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/05.png"), "Niet langer dan 40 minuten tennissen of in de zon." + Environment.NewLine + "Rust in de schaduw.", "SPF15+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/06.png"), "Niet langer dan 20 minuten in de zon." + Environment.NewLine + "Ga niet tennissen.", "SPF30+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/07.png"), "Niet langer dan 20 minuten in de zon." + Environment.NewLine + "Ga niet tennissen.", "SPF30+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/08.png"), "Niet langer dan 20 minuten in de zon." + Environment.NewLine + "Ga niet tennissen.", "SPF30+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/09.png"), "Zeer Hoog, ga niet buiten tennissen", "SPF50+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/10.png"), "Zeer Hoog, ga niet buiten tennissen", "SPF50+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/11.png"), "Extreem Hoog, ga niet buiten tennissen", "SPF50+"), }; try { StorageFile _storageFile = Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Weather/UV/01.png")).GetResults(); IBuffer readbuffer = FileIO.ReadBufferAsync(_storageFile).GetResults(); CurrentConditions.UVIcon = readbuffer.ToArray(); } catch (Exception ex) { string message = ex.Message; } TemperatureRange = new TemperatureRange { Maximum = new Measurement { Value = 20 }, Minimum = new Measurement { Value = -10 } }; }
public TemperatureRangeViewModel(TemperatureRange tempRange) { this.tempRange = tempRange; }
//we keep an active state list of strings in addition to our local settings //this is make it easy for modders who want to add new states that affect the player //status keepers use this list to determine their active state //this picks apart our current location info and figures out what states to apply to status keepers protected IEnumerator CheckActiveStateList() { //state order //0 - Sleeping - general / outside or in unowned/unsafe structure //1 - SleepingSafely - in campsite or in bed in owned structure //3 - ExposedCold - outside in cold weather //4 - ExposedWarm - outside in warm weather //2 - InSafeLocation - includes owned structures //3 - InCivilization - most structures and cities, campsites, path connected to civ //4 - Traveling - fast travel //5 - InWild - default state //6 - InDanger - maybe when there are hostiles around, gives temporary strength boost (?) haven't decided mCheckingActiveStateList = true; while (!mInitialized) { yield return(null); } while (mCheckingActiveStateList) //this is the info we need to build the state list { while (!GameManager.Is(FGameState.InGame)) { yield return(null); } if (player.IsDead) { //wait until we're not dead yield return(null); } bool insideStructure = false; bool isUnderground = false; bool isExposedCold = false; bool isExposedWarm = false; bool sleeping = false; bool inSafeLocation = false; bool inCivilization = false; bool sleepingSafely = false; bool traveling = false; bool inDanger = false; bool isWarmedByFire = false; traveling = State.IsTraveling; if (!traveling) //we can rule a few things out if we're not travling... { sleeping = State.IsSleeping; insideStructure = player.Surroundings.IsInsideStructure || (sleeping && mLastBed.IsEnclosed); inCivilization = player.Surroundings.IsInCivilization; inSafeLocation = player.Surroundings.IsInSafeLocation; isUnderground = player.Surroundings.IsUnderground; sleepingSafely = sleeping && (inSafeLocation); // || (inCivilization && player.Surroundings.CurrentLocation.State.Type == "Campsite"));//TODO potentially unsafe } bool checkForFire = false; //check our termperature - the biome will return the correct temperature based on tiem of day / season //this is the 'raw' temperature before we apply clothing and other modifiers to it LatestTemperatureRaw = GameWorld.Get.StatusTemperature(player.Position, WorldClock.TimeOfDayCurrent, WorldClock.TimeOfYearCurrent, isUnderground, insideStructure, inCivilization); LatestTemperatureAdjusted = LatestTemperatureRaw; if (player.Surroundings.HasNearbyFires) { //fires make our temperature higher if (player.Surroundings.HeatExposure > 1f) { //we're exposed to burning temperatures! LatestTemperatureAdjusted = TemperatureRange.E_DeadlyHot; //check to see if we're on fire later checkForFire = true; } else { isWarmedByFire = true; //we're not burning but we are warmer than usual //if it's deadly cold or cold bump up the temperature switch (LatestTemperatureRaw) { case TemperatureRange.A_DeadlyCold: case TemperatureRange.B_Cold: //no penalty for being near a fire, ever //case TemperatureRange.C_Warm: LatestTemperatureAdjusted = (TemperatureRange)((int)LatestTemperatureRaw + 1); break; default: break; } } } //finally, use our clothing to determine our temperature exposure LatestTemperatureExposure = player.Wearables.AdjustTemperatureExposure(LatestTemperatureAdjusted); //now that we've adjusted for clothing, if we were supposed to check for fire, do it now //TEMP disabled /*if (checkForFire && LatestTemperatureExposure == TemperatureRange.E_DeadlyHot) { * AddCondition("BurnedByFire"); * }*/ //we've given the player a million chances to get their temp up / down to 'Warm' //so at this point if they haven't done it they're going to suffer a penalty switch (LatestTemperatureExposure) { case TemperatureRange.A_DeadlyCold: case TemperatureRange.B_Cold: isExposedCold = true; break; default: break; case TemperatureRange.D_Hot: case TemperatureRange.E_DeadlyHot: isExposedWarm = true; break; } inDanger = player.Surroundings.IsInDanger; mNewStateList.Clear(); if (sleeping) { mNewStateList.Add("Sleeping"); } if (sleepingSafely) { mNewStateList.Add("SleepingSafely"); } if (inSafeLocation) { mNewStateList.Add("InSafeLocation"); } if (inCivilization) { mNewStateList.Add("InCivilization"); } if (traveling) { mNewStateList.Add("Traveling"); } mNewStateList.Add("Default"); //always add default state (in the wild) if (inDanger) { mNewStateList.Add("InDanger"); } if (insideStructure) { mNewStateList.Add("InsideStructure"); } else { if (isUnderground) { mNewStateList.Add("Underground"); } else { mNewStateList.Add("Outside"); } } if (isExposedCold) { mNewStateList.Add("ExposedCold"); } if (isExposedWarm) { mNewStateList.Add("ExposedWarm"); } if (isWarmedByFire) { mNewStateList.Add("WarmedByFire"); } //check whether we were in civilization last frame if (mInCivilizationLastFrame && !inCivilization) { //if we were in civ last frame and aren't now Player.Get.AvatarActions.ReceiveAction(AvatarAction.SurvivalCivilizationLeave, WorldClock.AdjustedRealTime); } else if (!mInCivilizationLastFrame && inCivilization) { //if we weren't in civ last frame and are now Player.Get.AvatarActions.ReceiveAction(AvatarAction.SurvivalCivilizationEnter, WorldClock.AdjustedRealTime); } mInCivilizationLastFrame = inCivilization; //automatically apply if we have more states than before bool applyState = (mNewStateList.Count != ActiveStateList.Count); if (!applyState) //if we have the same number, verify that they're actually the same { for (int i = 0; i < mNewStateList.Count; i++) //if there's a different state in there { if (mNewStateList[i] != ActiveStateList[i]) //apply the stae { applyState = true; break; } } } //wait a tick yield return(null); if (applyState) { ActiveStateList.Clear(); ActiveStateList.AddRange(mNewStateList); ActiveStateList.AddRange(CustomStateList); for (int i = 0; i < StatusKeepers.Count; i++) //they'll apply the states in the order provided { StatusKeepers[i].SetState(ActiveStateList); } CheckForFlows(); } double waitUntil = WorldClock.AdjustedRealTime + 0.05f; while (WorldClock.AdjustedRealTime > waitUntil) { yield return(null); } yield return(null); } mCheckingActiveStateList = false; yield break; }