Difference between revisions of "Modding:Weather data"

m (Changed the indent during the weather generation phsudocode section as it was causing some confusion as to what is was referencing)
 
(17 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__TOC__
+
← [[Modding:Index|Index]]
  
== Overview ==
+
This page documents how the game generates [[weather]] in the game.
  
Weather in Stardew Valley is set within the '''newDayAfterFade()''' function. For those using '''SMAPI''', this function runs before the '''AfterNewDayStarted''' event.
+
==Data==
 
+
The weather is controlled by the integer field <samp>Game1::weatherForTomorrow</samp>. The possible values are:
The weather is controlled by the variable '''weatherForTomorrow''', an integer. It takes one of the following arguments (For a description of each weather as the player sees it, look at [[Weather]])
 
  
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
!style="width: 225px;"|Variable (Weather)
+
! value
!Value
+
! constant
 +
! weather
 
|-
 
|-
|weather_sunny (Sunny)
+
| 0
|0
+
| <samp>weather_sunny</samp>
 +
| sunny
 
|-
 
|-
| weather_rain  (Rain)
 
 
| 1
 
| 1
 +
| <samp>weather_rain</samp>
 +
| rain
 
|-
 
|-
| weather_debris (Windy)
 
 
| 2
 
| 2
 +
| <samp>weather_debris</samp>
 +
| windy
 
|-
 
|-
|weather_lightning (Lightning)
 
 
| 3
 
| 3
 +
| <samp>weather_lightning</samp>
 +
| lightning
 
|-
 
|-
|weather_festival (Festival)
 
 
| 4
 
| 4
 +
| <samp>weather_festival</samp>
 +
| festival
 
|-
 
|-
|weather_snow (Snow)
 
 
| 5
 
| 5
 +
| <samp>weather_snow</samp>
 +
| snow
 
|-
 
|-
|weather_wedding (Wedding)
 
 
| 6
 
| 6
 +
| <samp>weather_wedding</samp>
 +
| wedding
 
|}
 
|}
  
===How Weather Is Set ===
+
==Algorithm==
 +
===Forced weather===
 +
Certain dates always have the same weather:
  
To determine how it's set, and what debris is set, the following steps are followed:
+
{| class="wikitable"
 +
|-
 +
! date
 +
! weather
 +
! overridden by
 +
|-
 +
| spring 1
 +
| <samp>weather_sunny</samp>
 +
| <samp>newday</samp> and <samp>tv</samp>
 +
|-
 +
| spring 2 (year 1)
 +
| <samp>weather_sunny</samp>
 +
| <samp>newday</samp>
 +
|-
 +
| spring 3 (year 1)
 +
| <samp>weather_rain</samp>
 +
| <samp>newday</samp>
 +
|-
 +
| spring 4 (year 1)
 +
| <samp>weather_sunny</samp>
 +
| <samp>newday</samp>
 +
|-
 +
| spring 13
 +
| <samp>weather_festival</samp>
 +
| <samp>newday</samp>
 +
|-
 +
| spring 24
 +
| <samp>weather_festival</samp>
 +
| <samp>newday</samp>
 +
|-
 +
| summer 1
 +
| <samp>weather_sunny</samp>
 +
| <samp>newday</samp> and <samp>tv</samp>
 +
|-
 +
| summer 11
 +
| <samp>weather_festival</samp>
 +
| <samp>newday</samp>
 +
|-
 +
| summer 13
 +
| <samp>weather_lightning</samp>
 +
| <samp>newday</samp>
 +
|-
 +
| summer 26
 +
| <samp>weather_lightning</samp>
 +
| <samp>newday</samp>
 +
|-
 +
| summer 28
 +
| <samp>weather_festival</samp>
 +
| <samp>newday</samp>
 +
|-
 +
| fall 1
 +
| <samp>weather_sunny</samp>
 +
| <samp>newday</samp> and <samp>tv</samp>
 +
|-
 +
| fall 16
 +
| <samp>weather_festival</samp>
 +
| <samp>newday</samp>
 +
|-
 +
| fall 27
 +
| <samp>weather_festival</samp>
 +
| <samp>newday</samp>
 +
|-
 +
| winter 1
 +
| <samp>weather_sunny</samp>
 +
| <samp>newday</samp> and <samp>tv</samp>
 +
|-
 +
| winter 8
 +
| <samp>weather_festival</samp>
 +
| <samp>newday</samp>
 +
|-
 +
| winter 14
 +
| <samp>weather_sunny</samp>
 +
| <samp>newday</samp>
 +
|-
 +
| winter 15
 +
| <samp>weather_sunny</samp>
 +
| <samp>newday</samp>
 +
|-
 +
| winter 16
 +
| <samp>weather_sunny</samp>
 +
| <samp>newday</samp>
 +
|-
 +
| winter 25
 +
| <samp>weather_festival</samp>
 +
| <samp>newday</samp>
 +
|}
 +
 
 +
===Generated weather===
 +
Weather in Stardew Valley is set within the <samp>Game1::newDayAfterFade()</samp> function (after the day change code, but before SMAPI's <samp>SaveEvents.BeforeSave</samp> event).
 +
 
 +
The game follows these steps to decide which weather and debris to set for the next day:
  
# After it handles day chance code, it checks for force weather (which is in the table at the bottom)
+
# Check for [[#Forced weather|forced weather]].
# It checks if today is a festival, and if it is, it sets the weather to 4. ('''weather_festival''')
+
# If today is a festival, set the weather to <samp>weather_festival</samp>.
# If today is a wedding, it sets the weather to 6. ('''weather_wedding''').
+
# If today is a wedding, set the weather to <samp>weather_wedding</samp>.
# It then updates if it was raining yesterday by checking the isRaining or isLightning flags.
+
# Set <samp>Game1::wasRainingYesterday</samp> based on whether it was raining or storming.
# It then clears all the flags, and sets them in the following pattern
+
# Reset all weather flags, and sets them in the following pattern
 
## If it is going to rain or storm, set the rain flag to true
 
## If it is going to rain or storm, set the rain flag to true
 
## If it is going to storm, set the storm flag to true
 
## If it is going to storm, set the storm flag to true
Line 57: Line 156:
 
#### If it's not, the rain chance is .183
 
#### If it's not, the rain chance is .183
 
#### Else, it's .63  
 
#### Else, it's .63  
### If it is, it uses the following: Check if it's day 1.
+
## If it is, it uses the following: Check if it's day 1.
#### If it's not, the chance is .12 + '''dayOfMonth''' * 3/1000
+
### If it's not, the chance is .12 + <samp>Game1::dayOfMonth</samp> * 3/1000
#### If it is, the chance is 0. Which.. is kinda redundant, as the force days take care of this.
+
### If it is, the chance is 0. Which.. is kinda redundant, as the force days take care of this.
 
# Check to see if a random number is less than the odds. If it is, it follows the following algorithm
 
# Check to see if a random number is less than the odds. If it is, it follows the following algorithm
## Set '''weatherForTomorrow''' to 1. ('''weather_rain''')
+
## Set <samp>Game1::weatherForTomorrow</samp> to <samp>weather_rain</samp>
 
## If:
 
## If:
 
### It's summer, and if a random number is less than .85
 
### It's summer, and if a random number is less than .85
 
### Or If it's not winter, and if a random number is less than .25 AND the day of the month is more than 2 and more than 27 days have been played
 
### Or If it's not winter, and if a random number is less than .25 AND the day of the month is more than 2 and more than 27 days have been played
### Set '''weatherForTomorrow''' to 3. ('''weather_lightning''')
+
### Set <samp>Game1::weatherForTomorrow</samp> to <samp>weather_lightning</samp>
 
## If it is winter
 
## If it is winter
### Set '''weatherForTomorrow''' to 5. ('''weather_snow''')
+
### Set <samp>Game1::weatherForTomorrow</samp> to <samp>weather_snow</samp>
 
# Else, if it's over the rain odds.
 
# Else, if it's over the rain odds.
 
## If you've played less than 3 days.  
 
## If you've played less than 3 days.  
Line 74: Line 173:
 
### And it's not fall or a random number is greater than or equal to .6 (so 40%) and fall.
 
### And it's not fall or a random number is greater than or equal to .6 (so 40%) and fall.
 
### Or: If there is a wedding today
 
### Or: If there is a wedding today
#### Set '''weatherForTomorrow''' to 0. ('''weather_sunny''') if true
+
#### Set <samp>Game1::weatherForTomorrow</samp> to <samp>weather_sunny</samp> if true
#### Set '''weatherForTomorrow''' to 2. ('''weather_debris''') if false
+
#### Set <samp>Game1::weatherForTomorrow</samp> to <samp>weather_debris</samp> if false
## Check if tomorrow is a festival, and set weather to 4 ('''weather_festival''') if true.
+
## Check if tomorrow is a festival, and set weather to <samp>weather_festival</samp> if true.
## Again force the 3rd day to be 1. ('''weather_rain''').
+
## Again force the 3rd day to be <samp>weather_rain</samp>
  
 
At this point, the main function is done setting weather.
 
At this point, the main function is done setting weather.
  
=== TV Channel ===
+
===TV Channel===
 
 
 
The TV checks the weather, but will occasionally set it on certain days. It follows the following chart:
 
The TV checks the weather, but will occasionally set it on certain days. It follows the following chart:
  
Line 89: Line 187:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
!day
+
! date
!season
+
! weather
!year
 
!weather
 
 
|-
 
|-
|1
+
| spring 1
|spring
+
| <samp>weather_sunny</samp>¹
|any
 
|weather_sunny[1]
 
 
|-
 
|-
|1
+
| spring 3
|summer
+
| <samp>weather_rainy</samp>¹
|any
 
|weather_sunny[1]
 
 
|-
 
|-
|13
+
| summer 1
|summer
+
| <samp>weather_sunny</samp>¹
|any
 
|weather_lightning[2]
 
 
|-
 
|-
|25
+
| fall 1
|summer
+
| <samp>weather_sunny</samp>¹
|any
 
|weather_lightning[2]
 
 
|-
 
|-
|1
+
| winter 1
|fall
+
| <samp>weather_sunny</samp>¹
|any
 
|weather_sunny[1]
 
|-
 
|1
 
|winter
 
|any
 
|weather_sunny[1]
 
 
|}
 
|}
  
[1] also set (and therefore overriden) by the '''newDayAfterFade()''' function<br>
+
<small>¹ Also set (and thus overridden) by the <samp>Game1::newDayAfterFade()</samp> method.</small><br />
[2] These are set by current_day mod 12, which results in the 13th and 25th.
 
  
Description:
+
The TV will check the weather and show the following message:
  
It will check the weather, and do the following:
+
{| class="wikitable"
 
+
|-
* Sunny or Wedding: A 50% chance of one of two strings: "It's going to be clear and sunny all day." or "It's going to be a beautiful, sunny day tommorow!"
+
! weather
* Rain: "It's going to rain all day tomorrow"
+
! message
* Debris: Spring: "Partially cloudy with a light breeze. Expect lots of pollen!" Not Fall: "It's going to snow all day. Make sure you bundle up, folks!" and defaults with: "It's going to be cloudy, with gusts of wind throught the day."
+
|-
* Storm: "Looks like a storm is approaching. Thunder and lightning is expected."
+
| sunny or wedding
* Festival: It attempts to read the festival data, will spit out an amusing "Um... that's odd. My information sheet just says 'null'. This is embarrassing..." if it fails to read the data, other wise will read out where it is and when it is.
+
| 50% chance each:
* Snow: A 50% chance of one of two strings: "Expect a few inches of snow tomorrow" or "Bundle up, folks. It's going to snow tomorrow!"
+
* "It's going to be clear and sunny all day."
 
+
* "It's going to be a beautiful, sunny day tommorow!"
It returns an empty string for all other weathers. (which should be none, but.)
+
|-
 
+
| rain
==== Notes: ====
+
| "It's going to rain all day tomorrow"
 
+
|-
The TV will not necessarily be accurate for Summer 13,26 or Spring 2,4. Those are force set within the newDayAfterFade() function.
+
| debris
 
+
| Per conditions:
== Weather Icon ==
+
# If spring: "Partially cloudy with a light breeze. Expect lots of pollen!"
Thanks to Entoarox, the logic for this is pretty simple:
+
# If not fall: "It's going to snow all day. Make sure you bundle up, folks!" and defaults with: "It's going to be cloudy, with gusts of wind throught the day."
 
+
# If storm: "Looks like a storm is approaching. Thunder and lightning is expected."
This is set by Game1::updateWeatherIcon().
+
# If festival, it attempts to read the festival data. If it fails, it will say "Um... that's odd. My information sheet just says 'null'. This is embarrassing..." If it succeeds, it will read out where it is and when it is.
 
+
# If snow, a 50% chance of one of two strings: "Expect a few inches of snow tomorrow" or "Bundle up, folks. It's going to snow tomorrow!"
The following will always apply: snowing sets '''7''', sunny '''2''', wedding '''0''', festival '''1''',
+
|-
raining '''4''', stormy '''5'''
+
| ''any other''
<br>
+
| Returns an empty string (should never happen).
In spring, debris weather is '''3''', summer will be '''unset''' (this defaults to sunny), fall '''6''', and winter '''7''' (the same as snowing)
+
|}
<br>
 
These icons are located in '''LooseSprite/Cursors.xnb'''
 
 
 
== Rain Totem ==
 
 
 
The rain totem item is (681), and is controlled by Object::rainTotem (invoked by Object::performUseAction)
 
 
 
It makes sure you aren't in multiplayer and that tomorrow isn't a festival day. If so, it sets the weather for tomorrow to weather_rain and displays the message. Of a note, the item is still used up and every other animation is played even if it's not set if you're in MP or if tomorrow is a festival day.
 
  
== Breakdown of Weather Chances by Type ==
+
'''Note:''' the TV will not necessarily be accurate for any other day than non festival days, the first of the month and the 3rd of spring, which are force-set by the <samp>Game1::newDayAfterFade</samp> method. Farmhands (and not host players) may not even get that accuracy for the first of the month and 3rd of spring.
  
Now that we've broken down the flow, here's a (long winded) breakdown of each weather's chances.
+
'''Note 2:''' The Night Market is not considered a festival for the purposes of weather.
  
=== Sunny Weather (Weather Variables: 0,4,6) ===
+
===Weather Icon===
 +
The weather icon is set in <samp>Game1::updateWeatherIcon</samp>, which sets an index in <samp>LooseSprite/Cursors.xnb</samp>:
  
In ''Spring'', there is first an 18.3% base chance that it rains assuming that it's not overridden. (81.7% chance remaining for other weathers). If it doesn't rain, it has an 80% chance to remain sunny. (except on Spring 3, which will always be rainy.). This means in _Spring_, there is a 66.4% chance of it being sunny.
+
# If snowing: 7.
 +
# If sunny: 2.
 +
# If wedding: 0.
 +
# If festival: 1.
 +
# If raining: 4.
 +
# If stormy: 5.
 +
# If spring: debris weather is 3.
 +
# If summer: unset (defaults to sunny).
 +
# If fall: 6.
 +
# If winter: 7 (same as snowing).
  
In ''Summer'', there is a diminishing chance daily of sunny weather, but generally, you have a 86% chance on the second day, to 79.9% chance on the last day. The precise chance is: 1 - [13% + (.3 * day of the month)] per day, and it's a 0% chance on day 1. Bear in mind that Summer 12,13,24 and 26 will be stormy.
+
===Rain Totem===
 +
The rain totem (item #681) and is controlled by <samp>Object::rainTotem</samp>, which is invoked by <samp>Object::performUseAction</samp>. If tomorrow is a festival day, the item is used up but nothing happens. Otherwise, it uses up the item and sets the weather for tomorrow to <samp>weather_rain</samp> and displays the message.
  
In ''Fall'', the odds are precisely the same as Spring. There's no forced weather though.
+
==Weather probability by type==
 +
This section explains the probability of each weather type. This only applies on dates with no [[#Forced weather|forced weather]].
  
In ''Winter'', there is a 63% chance of precipitation, so only a 37% chance of sunny weather.
+
===Sunny===
 +
Sunny weather covers weather variables 0, 4, and 6.
  
=== Rainy Weather (1) ===
+
* Spring: there's an 18.3% base chance of rain (81.7% chance remaining for other weathers). If it doesn't rain, there's an 80% chance to remain sunny (except on spring 3, which will always be rainy). That means that in spring there's a 66.4% chance of sunny weather.
 +
* Summer: The chance of sunny weather diminishes steadily per day from 87.4% on summer 1 to 79.9% on summer 28. The precise chance is 1 - [12% + (0.3% * day of the month)] per day, with a 0% chance on day 1.
 +
* Fall: identical to spring, but no forced weather.
 +
* Winter: there's a 63% chance of precipitation, so only a 37% chance of sunny weather.
  
In ''Spring'', you have a 18.3% chance of rain. If it rains, there's only a 25% chance of storms, _as long as it is not Year 1_. So the rain odds in Spring is a flat 18.3% in Year 1, and 13.725% in Year 2 and beyond. It will be rainy on Spring 3 Year 1.
+
===Rainy===
 +
* Spring: there's an 18.3% base chance of rain. If it rains, there's a 25% chance of storms ''except in year 1''. So the rain odds in Spring is a flat 18.3% in year 1, and 13.725% in year 2 or later. It will always rain on spring 3 (year 1).
 +
* Summer: the chance of rainy weather increases steadily per day from 12.6% on summer 2 to 20.1% on Summer 27. There's an 85% chance that rain becomes storms. So you have a scale of [12% + (0.3% * day of the month)] * .15 to determine your chances of rainfall.
 +
* Fall: same as spring, except fall in year 1 can be stormy so it's a flat 13.725% chance.
 +
* Winter: never rains.
  
In ''Summer'', you have a steadily increasing chance of rain starting at 14% on Summer 2 to a 21.1% chance on Summer 27. However, during ''Summer'', you have a 85% chance to make the rain into storms. So you have a scale of [13% + (.3 * day of the month)] * .85 to determine your chances of rainfall. (See the note about forced weather above.)
+
===Debris===
 +
Debris weather covers weather variable 2.
  
In ''Fall'', it's the same as ''Spring'', although Fall Year 1 can be stormy, so it's 13.725%.  
+
* Spring: there's a 20% chance of this after rain, so approximately 16.6% chance of debris weather.
 +
* Summer: no debris weather.
 +
* Fall: there's a 60% chance for this after rain, so approximately 49.8% chance of debris weather.
 +
* Winter: no debris weather.
  
In ''Winter'', it does not rain.
+
===Stormy===
 +
Stormy weather covers weather variable 3.
  
=== Debris Weather (2) ===
+
* Spring: 4.57% chance of storms.
 +
* Summer: variable chance of storms; starts at 10.71% and increases to 17.085%.
 +
* Fall: 4.57% chance of storms.
 +
* Winter: no stormy weather.
  
In ''Spring'', you have a 20% chance for this after rain, so approximately 16.6% chance of debris weather.
+
===Snowy===
 +
In winter, there's a 63% chance of snow. No other season has snow.
  
In ''Summer'' and ''Winter'' you cannot have debris weather.
+
==Save files==
 
+
The save file is a snapshot of the day at 0600 the next morning. The <samp>WeatherForTommorow</samp> field was used to calculate the weather, but changing it has no effect on the weather since the weather flags have already been set by this point. To change the weather, you need to set one of these combinations of flags:
In ''Fall'', you have a 60% chance for this after rain, so approximately 49.8% chance of debris weather.
 
 
 
=== Stormy Weather (3) ===
 
 
 
In ''Spring'', you have a 4.57% of storms.
 
 
 
In ''Summer'', you have a variable chance of storms. It starts at 11.9% and increases to 17.9% chance.
 
 
 
In ''Fall'', you have a 4.57% of storms.
 
 
 
In ''Winter'', you cannot have stormy weather.
 
 
 
=== Snowy Weather ===
 
 
 
In ''Winter'', you have a 63% chance of snow.
 
 
 
No other season has snow.
 
 
 
== Weather and Save Files ==
 
 
 
Your save file is a snapshot of the day at 0600 the next morning. As such, changing WeatherForTommorow in there will not affect the day loaded. If you really need to alter weather in the save file, you'll want to look at the following attributes: '''isRaining, isDebrisWeather, isLightning, isSnowing'''. For details of what to set which, look at the next section. This applies to trying to change weather in game, as well.
 
 
 
'''NB:''' Changing isDebrisWeather during an active game will not by itself create the array. You will need to call '''Game1::populateDebrisWeatherArray''' to get the debris populated. Corrospondingly, if you are removing the debris weather flag, remember to call '''Game1::debrisWeather::Clear'''
 
 
 
== Detecting Current Weather (in game) ==
 
 
 
This is a brief overview. While it's generally obvious, I'll lay it out
 
  
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
 
! weather  
 
! weather  
! isRaining  
+
! <samp>isRaining</samp>
! isDebrisWeather
+
! <samp>isDebrisWeather</samp>
! isLightning
+
! <samp>isLightning</samp>
! isSnowing
+
! <samp>isSnowing</samp>
 
|-
 
|-
| Sunny
+
| sunny
| F
+
|
| F
+
|
| F
+
|
| F
+
|
 
|-
 
|-
| Rainy
+
| rainy
|T
+
|
|F
+
|
|F
+
|
|F
+
|
 
|-
 
|-
|Storm
+
| stormy
|T
+
|
|F
+
|
|T
+
|
|F
+
|
 
|-
 
|-
|Debris
+
| debris
|F
+
|
|T
+
|
|F
+
|
|F
+
|
 
|-
 
|-
|Snowing
+
| snowy
|F
+
|
|F
+
|
|F
+
|
|T
+
|
 
|-
 
|-
|Festival
+
| festival
| F
+
|
| F
+
|
| F
+
|
| F
+
|
 
|-
 
|-
|Wedding
+
| wedding
| F
+
|
| F
+
|
| F
+
|
| F
+
|
 
|}
 
|}
  
== Notes/FAQ ==
+
'''Note:''' changing <samp>isDebrisWeather</samp> during an active game will not create the array. You'll need to call <samp>Game1::populateDebrisWeatherArray</samp> to get the debris populated. Correspondingly, if you're removing the debris weather flag, remember to call <samp>Game1::debrisWeather::Clear</samp>.
  
 +
==Notes/FAQ==
 
* The TV can be fixed by overriding it - or just by using Entoroax's Framework.
 
* The TV can be fixed by overriding it - or just by using Entoroax's Framework.
 
* You can set snow and debris at any time, the game just won't.
 
* You can set snow and debris at any time, the game just won't.
 +
* You cannot set debris and rain at the same time.
  
== Appendix: Override Table ==
+
[[Category:Modding]]
 
 
{| class="wikitable"
 
|-
 
!Day
 
!Season
 
!Year
 
!Forced Weather
 
!Overriden by
 
|-
 
|1
 
|spring
 
|any
 
|weather_sunny
 
|newday and tv
 
|-
 
|2
 
|spring
 
|1
 
|weather_sunny
 
|newday
 
|-
 
|3
 
|spring
 
|1
 
|weather_rain
 
|newday
 
|-
 
|4
 
|spring
 
|1
 
|weather_sunny
 
|newday
 
|-
 
|13
 
|spring
 
|any
 
|weather_festival
 
|newday
 
|-
 
|24
 
|spring
 
|any
 
|weather_festival
 
|newday
 
|-
 
|1
 
|summer
 
|any
 
|weather_sunny
 
|newday and tv
 
|-
 
|11
 
|summer
 
|any
 
|weather_festival
 
|newday
 
|-
 
|13
 
|summer
 
|any
 
|weather_lightning
 
|newday and tv
 
|-
 
|25
 
|summer
 
|any
 
|weather_lightning
 
|tv
 
|-
 
|26
 
|summer
 
|any
 
|weather_lightning
 
|newday
 
|-
 
|28
 
|summer
 
|any
 
|weather_festival
 
|newday
 
|-
 
|1
 
|fall
 
|any
 
|weather_sunny
 
|newday and tv
 
|-
 
|16
 
|fall
 
|any
 
|weather_festival
 
|newday
 
|-
 
|27
 
|fall
 
|any
 
|weather_festival
 
|newday
 
|-
 
|1
 
|winter
 
|any
 
|weather_festival
 
|newday and tv
 
|-
 
|8
 
|winter
 
|any
 
|weather_festival
 
|newday
 
|-
 
|25
 
|winter
 
|any
 
|weather_festival
 
|newday
 
|}
 
 
 
== Contributions ==
 
  
This was originally from canimod.com, written by me with contributions from Pathoschild. It has been rewritten by me for the wiki, with assistance from the modding channel on the stardew valley discord.
+
[[pt:Modificações:Dados climáticos]]
 +
[[ru:Модификации:Погодные явления]]

Latest revision as of 16:44, 14 May 2023

Index

This page documents how the game generates weather in the game.

Data

The weather is controlled by the integer field Game1::weatherForTomorrow. The possible values are:

value constant weather
0 weather_sunny sunny
1 weather_rain rain
2 weather_debris windy
3 weather_lightning lightning
4 weather_festival festival
5 weather_snow snow
6 weather_wedding wedding

Algorithm

Forced weather

Certain dates always have the same weather:

date weather overridden by
spring 1 weather_sunny newday and tv
spring 2 (year 1) weather_sunny newday
spring 3 (year 1) weather_rain newday
spring 4 (year 1) weather_sunny newday
spring 13 weather_festival newday
spring 24 weather_festival newday
summer 1 weather_sunny newday and tv
summer 11 weather_festival newday
summer 13 weather_lightning newday
summer 26 weather_lightning newday
summer 28 weather_festival newday
fall 1 weather_sunny newday and tv
fall 16 weather_festival newday
fall 27 weather_festival newday
winter 1 weather_sunny newday and tv
winter 8 weather_festival newday
winter 14 weather_sunny newday
winter 15 weather_sunny newday
winter 16 weather_sunny newday
winter 25 weather_festival newday

Generated weather

Weather in Stardew Valley is set within the Game1::newDayAfterFade() function (after the day change code, but before SMAPI's SaveEvents.BeforeSave event).

The game follows these steps to decide which weather and debris to set for the next day:

  1. Check for forced weather.
  2. If today is a festival, set the weather to weather_festival.
  3. If today is a wedding, set the weather to weather_wedding.
  4. Set Game1::wasRainingYesterday based on whether it was raining or storming.
  5. Reset all weather flags, and sets them in the following pattern
    1. If it is going to rain or storm, set the rain flag to true
    2. If it is going to storm, set the storm flag to true
    3. If the weather is (sunny, debris) or (festival || snowy || wedding), clear all the flags
    4. and then if it's snowy, set snowy to true
    5. It then sets the song based on this
    6. Clear the debris weather array and clear the flag
    7. if bloom isn't null, clear it's visibility
    8. If the wedding is debris, populate the debris array.
  6. If it's not raining, and the chance to rain tomorrow is less than .1, it will try to create a bloom day.
  7. It then calculates the rain chance for tomorrow. It follows the following algorithm
    1. Check to see if it's summer.
      1. If not, check to see if it's winter.
        1. If it's not, the rain chance is .183
        2. Else, it's .63
    2. If it is, it uses the following: Check if it's day 1.
      1. If it's not, the chance is .12 + Game1::dayOfMonth * 3/1000
      2. If it is, the chance is 0. Which.. is kinda redundant, as the force days take care of this.
  8. Check to see if a random number is less than the odds. If it is, it follows the following algorithm
    1. Set Game1::weatherForTomorrow to weather_rain
    2. If:
      1. It's summer, and if a random number is less than .85
      2. Or If it's not winter, and if a random number is less than .25 AND the day of the month is more than 2 and more than 27 days have been played
      3. Set Game1::weatherForTomorrow to weather_lightning
    3. If it is winter
      1. Set Game1::weatherForTomorrow to weather_snow
  9. Else, if it's over the rain odds.
    1. If you've played less than 3 days.
    2. Or: if
      1. It's not spring or a random number is greater than or equal to .2 (so 80%) and spring.
      2. And it's not fall or a random number is greater than or equal to .6 (so 40%) and fall.
      3. Or: If there is a wedding today
        1. Set Game1::weatherForTomorrow to weather_sunny if true
        2. Set Game1::weatherForTomorrow to weather_debris if false
    3. Check if tomorrow is a festival, and set weather to weather_festival if true.
    4. Again force the 3rd day to be weather_rain

At this point, the main function is done setting weather.

TV Channel

The TV checks the weather, but will occasionally set it on certain days. It follows the following chart:

The TV force sets by:

date weather
spring 1 weather_sunny¹
spring 3 weather_rainy¹
summer 1 weather_sunny¹
fall 1 weather_sunny¹
winter 1 weather_sunny¹

¹ Also set (and thus overridden) by the Game1::newDayAfterFade() method.

The TV will check the weather and show the following message:

weather message
sunny or wedding 50% chance each:
  • "It's going to be clear and sunny all day."
  • "It's going to be a beautiful, sunny day tommorow!"
rain "It's going to rain all day tomorrow"
debris Per conditions:
  1. If spring: "Partially cloudy with a light breeze. Expect lots of pollen!"
  2. If not fall: "It's going to snow all day. Make sure you bundle up, folks!" and defaults with: "It's going to be cloudy, with gusts of wind throught the day."
  3. If storm: "Looks like a storm is approaching. Thunder and lightning is expected."
  4. If festival, it attempts to read the festival data. If it fails, it will say "Um... that's odd. My information sheet just says 'null'. This is embarrassing..." If it succeeds, it will read out where it is and when it is.
  5. If snow, a 50% chance of one of two strings: "Expect a few inches of snow tomorrow" or "Bundle up, folks. It's going to snow tomorrow!"
any other Returns an empty string (should never happen).

Note: the TV will not necessarily be accurate for any other day than non festival days, the first of the month and the 3rd of spring, which are force-set by the Game1::newDayAfterFade method. Farmhands (and not host players) may not even get that accuracy for the first of the month and 3rd of spring.

Note 2: The Night Market is not considered a festival for the purposes of weather.

Weather Icon

The weather icon is set in Game1::updateWeatherIcon, which sets an index in LooseSprite/Cursors.xnb:

  1. If snowing: 7.
  2. If sunny: 2.
  3. If wedding: 0.
  4. If festival: 1.
  5. If raining: 4.
  6. If stormy: 5.
  7. If spring: debris weather is 3.
  8. If summer: unset (defaults to sunny).
  9. If fall: 6.
  10. If winter: 7 (same as snowing).

Rain Totem

The rain totem (item #681) and is controlled by Object::rainTotem, which is invoked by Object::performUseAction. If tomorrow is a festival day, the item is used up but nothing happens. Otherwise, it uses up the item and sets the weather for tomorrow to weather_rain and displays the message.

Weather probability by type

This section explains the probability of each weather type. This only applies on dates with no forced weather.

Sunny

Sunny weather covers weather variables 0, 4, and 6.

  • Spring: there's an 18.3% base chance of rain (81.7% chance remaining for other weathers). If it doesn't rain, there's an 80% chance to remain sunny (except on spring 3, which will always be rainy). That means that in spring there's a 66.4% chance of sunny weather.
  • Summer: The chance of sunny weather diminishes steadily per day from 87.4% on summer 1 to 79.9% on summer 28. The precise chance is 1 - [12% + (0.3% * day of the month)] per day, with a 0% chance on day 1.
  • Fall: identical to spring, but no forced weather.
  • Winter: there's a 63% chance of precipitation, so only a 37% chance of sunny weather.

Rainy

  • Spring: there's an 18.3% base chance of rain. If it rains, there's a 25% chance of storms except in year 1. So the rain odds in Spring is a flat 18.3% in year 1, and 13.725% in year 2 or later. It will always rain on spring 3 (year 1).
  • Summer: the chance of rainy weather increases steadily per day from 12.6% on summer 2 to 20.1% on Summer 27. There's an 85% chance that rain becomes storms. So you have a scale of [12% + (0.3% * day of the month)] * .15 to determine your chances of rainfall.
  • Fall: same as spring, except fall in year 1 can be stormy so it's a flat 13.725% chance.
  • Winter: never rains.

Debris

Debris weather covers weather variable 2.

  • Spring: there's a 20% chance of this after rain, so approximately 16.6% chance of debris weather.
  • Summer: no debris weather.
  • Fall: there's a 60% chance for this after rain, so approximately 49.8% chance of debris weather.
  • Winter: no debris weather.

Stormy

Stormy weather covers weather variable 3.

  • Spring: 4.57% chance of storms.
  • Summer: variable chance of storms; starts at 10.71% and increases to 17.085%.
  • Fall: 4.57% chance of storms.
  • Winter: no stormy weather.

Snowy

In winter, there's a 63% chance of snow. No other season has snow.

Save files

The save file is a snapshot of the day at 0600 the next morning. The WeatherForTommorow field was used to calculate the weather, but changing it has no effect on the weather since the weather flags have already been set by this point. To change the weather, you need to set one of these combinations of flags:

weather isRaining isDebrisWeather isLightning isSnowing
sunny
rainy
stormy
debris
snowy
festival
wedding

Note: changing isDebrisWeather during an active game will not create the array. You'll need to call Game1::populateDebrisWeatherArray to get the debris populated. Correspondingly, if you're removing the debris weather flag, remember to call Game1::debrisWeather::Clear.

Notes/FAQ

  • The TV can be fixed by overriding it - or just by using Entoroax's Framework.
  • You can set snow and debris at any time, the game just won't.
  • You cannot set debris and rain at the same time.