WorldMgr: Difference between revisions

471 bytes added ,  3 years ago
Marked this version for translation
No edit summary
(Marked this version for translation)
Line 1: Line 1:
<translate>
<translate>
<!--T:1-->
{{Subsystem infobox|name=WorldMgr|init_addr_switch150=00000071010F2920|is_name_official=1|description=Manages world state (time, blood moons, climates, weather, etc.)}}
{{Subsystem infobox|name=WorldMgr|init_addr_switch150=00000071010F2920|is_name_official=1|description=Manages world state (time, blood moons, climates, weather, etc.)}}


<!--T:2-->
The '''World Manager''' (WorldMgr) is responsible for managing time, blood moons, climates, weather, fog, wind, lighting, procedural generation of clouds, whether the Lord of the Mountain appears, etc.
The '''World Manager''' (WorldMgr) is responsible for managing time, blood moons, climates, weather, fog, wind, lighting, procedural generation of clouds, whether the Lord of the Mountain appears, etc.


<!--T:3-->
Because of the massive amount of state to handle, functionality is split across the main WorldMgr and 9 sub-managers.
Because of the massive amount of state to handle, functionality is split across the main WorldMgr and 9 sub-managers.


== WorldMgr ==
== WorldMgr == <!--T:4-->
=== Sub-managers ===
=== Sub-managers ===
Sub-managers are created in WorldMgr::init (0x71010F43C0) and inserted into a pointer array (@WorldMgr+0x5c0). All names below are unofficial.
Sub-managers are created in WorldMgr::init (0x71010F43C0) and inserted into a pointer array (@WorldMgr+0x5c0). All names below are unofficial.


<!--T:5-->
{|class="wikitable"
{|class="wikitable"
|+ Sub-managers by ID
|+ Sub-managers by ID
Line 33: Line 37:
|}
|}


=== Climate ===
=== Climate === <!--T:6-->
The main WorldMgr class is responsible for keeping climate related parameters and determining which set of climate settings to use. Strangely enough, WorldMgr uses the position of the Camera actor to figure out which map area the player is in (and thus what climate to use), not the Player actor.
The main WorldMgr class is responsible for keeping climate related parameters and determining which set of climate settings to use. Strangely enough, WorldMgr uses the position of the Camera actor to figure out which map area the player is in (and thus what climate to use), not the Player actor.


== TimeMgr ==
== TimeMgr == <!--T:7-->
TimeMgr handles everything to do with time, including Blood Moons and the Lord of the Mountain's apparition.
TimeMgr handles everything to do with time, including Blood Moons and the Lord of the Mountain's apparition.


<!--T:8-->
Internally, time of day is stored as a float in the [0.0, 360.0] range.
Internally, time of day is stored as a float in the [0.0, 360.0] range.


=== TimeMgr::init ===
=== TimeMgr::init === <!--T:9-->
* Time is set to 78.75 (05:15).
* Time is set to 78.75 (05:15).
* Time for TotS environment is set to 78.75 (05:15) as well.
* Time for TotS environment is set to 78.75 (05:15) as well.
* "Bloody Moon end reserve timer" is set to 0.
* "Bloody Moon end reserve timer" is set to 0.


=== TimeMgr::reset ===
=== TimeMgr::reset === <!--T:10-->
This is called whenever a stage is unloaded (essentially every time the loading screen is shown).
This is called whenever a stage is unloaded (essentially every time the loading screen is shown).
* Blood Moon checks are delayed.
* Blood Moon checks are delayed.
* The AnimalMaster_Appearance flag is cleared, meaning the Lord of the Mountain will not appear.
* The AnimalMaster_Appearance flag is cleared, meaning the Lord of the Mountain will not appear.


=== TimeMgr::calc ===
=== TimeMgr::calc === <!--T:11-->
This is called every frame.
This is called every frame.


<!--T:12-->
* (If field 0x14A is set to 99, WM_BloodyDay is set to true. [[AIDef:Action/SetBloodyMoonEnv]] uses this to force a Blood Moon to be scheduled. This feature appears to be unused.)
* (If field 0x14A is set to 99, WM_BloodyDay is set to true. [[AIDef:Action/SetBloodyMoonEnv]] uses this to force a Blood Moon to be scheduled. This feature appears to be unused.)
* If both [[Demo]]103_0 and Demo997_0 have not been played, time of day is reset to 78.75 (05:15).
* If both [[Demo]]103_0 and Demo997_0 have not been played, time of day is reset to 78.75 (05:15).
Line 59: Line 65:
* [[#Midnight checks]].
* [[#Midnight checks]].


<!--T:13-->
* '''Update time of day''': there are several possible update modes. In most cases, the update mode is 0.
* '''Update time of day''': there are several possible update modes. In most cases, the update mode is 0.
{|class="wikitable"
{|class="wikitable"
Line 121: Line 128:
* If the timer is >= 360.0, which means that a day has passed, the game subtracts 360 from the timer.
* If the timer is >= 360.0, which means that a day has passed, the game subtracts 360 from the timer.


<!--T:14-->
'''Note''': In this state, the blood moon timer is never updated and its value is never checked either.  
'''Note''': In this state, the blood moon timer is never updated and its value is never checked either.  
|}
|}


<!--T:15-->
* Update the [[#Day/night time flag]], the [[#Time division, IsMorning, IsNoon, etc.]]
* Update the [[#Day/night time flag]], the [[#Time division, IsMorning, IsNoon, etc.]]
* If the "Bloody Moon end reserve timer" is non zero, decrement it. If the new value is zero, the WM_BloodyDay flag is cleared.
* If the "Bloody Moon end reserve timer" is non zero, decrement it. If the new value is zero, the WM_BloodyDay flag is cleared.
* Update [[#Lord of the Mountain]] flags.
* Update [[#Lord of the Mountain]] flags.


=== Midnight checks ===
=== Midnight checks === <!--T:16-->
The following actions happen every time the timer reaches 360.0 (midnight).
The following actions happen every time the timer reaches 360.0 (midnight).


<!--T:17-->
WM_NumberOfDays is incremented.
WM_NumberOfDays is incremented.


<!--T:18-->
'''If a Blood Moon is scheduled''' (WM_BloodyDay is true):
'''If a Blood Moon is scheduled''' (WM_BloodyDay is true):
*If Blood Moons are prohibited (see conditions below), set the Blood Moon timer to 2880.0.
*If Blood Moons are prohibited (see conditions below), set the Blood Moon timer to 2880.0.
*If they are allowed to happen, call [https://eventviewer.zeldamods.org/viewer.html?data=/d/Demo011_0.json&params=1 Demo011_0] and set the Blood Moon timer to 0.0.
*If they are allowed to happen, call [https://eventviewer.zeldamods.org/viewer.html?data=/d/Demo011_0.json&params=1 Demo011_0] and set the Blood Moon timer to 0.0.


<!--T:19-->
'''Scheduling new Blood Moons''':
'''Scheduling new Blood Moons''':
*If the FirstTouchdown flag is set (i.e. if the player has left the Great Plateau), and if the Blood Moon timer is > 2520.0 (7 in-game days):
*If the FirstTouchdown flag is set (i.e. if the player has left the Great Plateau), and if the Blood Moon timer is > 2520.0 (7 in-game days):
Line 143: Line 155:
* Otherwise, the "Bloody end reserve timer" is set to 150. This ensures that the WM_BloodyDay flag is cleared 5 in-game minutes (= 5 seconds in real life) after a Blood Moon occurs.
* Otherwise, the "Bloody end reserve timer" is set to 150. This ensures that the WM_BloodyDay flag is cleared 5 in-game minutes (= 5 seconds in real life) after a Blood Moon occurs.


==== Blood Moon inhibitors ====
==== Blood Moon inhibitors ==== <!--T:20-->
If any of the following conditions are true, the Blood Moon cutscene will not be triggered.
If any of the following conditions are true, the Blood Moon cutscene will not be triggered.


<!--T:21-->
* Not on MainField (main overworld)
* Not on MainField (main overworld)
* IsInHyruleCastleArea is set
* IsInHyruleCastleArea is set
Line 155: Line 168:
* SkyMgr's field_2B4 is set to 15 and field_2B8 >= 1.0
* SkyMgr's field_2B4 is set to 15 and field_2B8 >= 1.0


<!--T:22-->
However, these do not prevent the Blood Moon timer from advancing, or the WM_BloodyDay flag from being set.
However, these do not prevent the Blood Moon timer from advancing, or the WM_BloodyDay flag from being set.


<!--T:23-->
Note: Vah Rudania is missing from the list. This is normal and blood moons still cannot happen during the Vah Rudania battle sequence because the BloodyMoonProhibition flag is set during it.
Note: Vah Rudania is missing from the list. This is normal and blood moons still cannot happen during the Vah Rudania battle sequence because the BloodyMoonProhibition flag is set during it.


=== Day/night time flag ===
=== Day/night time flag === <!--T:24-->
From 00:00 to 06:00 (closed interval) and from 18:00 to 00:00 (closed interval), WM_DaytimeFlag is set to false and WM_NighttimeFlag is true.
From 00:00 to 06:00 (closed interval) and from 18:00 to 00:00 (closed interval), WM_DaytimeFlag is set to false and WM_NighttimeFlag is true.


<!--T:25-->
In any other case, WM_DaytimeFlag is set to true and WM_NighttimeFlag to false.
In any other case, WM_DaytimeFlag is set to true and WM_NighttimeFlag to false.


=== Time division, IsMorning, IsNoon, etc. ===
=== Time division, IsMorning, IsNoon, etc. === <!--T:26-->
{|class="wikitable"
{|class="wikitable"
! Start !! End !! Division !! Time type (1) !! Time type (2)
! Start !! End !! Division !! Time type (1) !! Time type (2)
Line 188: Line 204:
Note: all intervals include the start time and exclude the end time.
Note: all intervals include the start time and exclude the end time.


=== Moon type ===
=== Moon type === <!--T:27-->
The moon type is calculated based on the number of in-game days (WM_NumberOfDays). The exact formula is <code>(numberOfDays + x + 1) % 8</code><ref>0x71010E8200</ref>, where x is equal to 1 if the current time is > 180.0 (noon) and % is the modulo operator.
The moon type is calculated based on the number of in-game days (WM_NumberOfDays). The exact formula is <code>(numberOfDays + x + 1) % 8</code><ref>0x71010E8200</ref>, where x is equal to 1 if the current time is > 180.0 (noon) and % is the modulo operator.


<!--T:28-->
If a moon type was set manually (for instance using [[AIDef:Action/EventSetMoonType]]), that value will be used as the moon type.
If a moon type was set manually (for instance using [[AIDef:Action/EventSetMoonType]]), that value will be used as the moon type.


<!--T:29-->
The moon type is returned by [[AIDef:Query/WhatMoonName]], which some NPC event flows use to check the current moon phase. However, the moon schedule has nothing to do with the blood moon schedule.
The moon type is returned by [[AIDef:Query/WhatMoonName]], which some NPC event flows use to check the current moon phase. However, the moon schedule has nothing to do with the blood moon schedule.


=== Lord of the Mountain ===
=== Lord of the Mountain === <!--T:30-->
The Lord of the Mountain appears whenever the AnimalMaster_Appearance flag is set. Its value is managed by a simple state machine.
The Lord of the Mountain appears whenever the AnimalMaster_Appearance flag is set. Its value is managed by a simple state machine.


<!--T:31-->
Note that whenever a stage is unloaded, the AnimalMaster_Appearance flag is reset to false.
Note that whenever a stage is unloaded, the AnimalMaster_Appearance flag is reset to false.


====State 0 - Wait for conditions====
====State 0 - Wait for conditions==== <!--T:32-->
If the following three conditions are true:
If the following three conditions are true:
* The [[#Moon type]] is 5 (waxing crescent)
* The [[#Moon type]] is 5 (waxing crescent)
Line 206: Line 225:
* The current [[map area]] number is not 64 ("HyruleHill", presumably the Satori Mountain area)
* The current [[map area]] number is not 64 ("HyruleHill", presumably the Satori Mountain area)


<!--T:33-->
then the game generates a random "appearance hour" in the [0 .. 22] interval and goes into state 1.
then the game generates a random "appearance hour" in the [0 .. 22] interval and goes into state 1.


====State 1 - Wait for the appearance time====
====State 1 - Wait for the appearance time==== <!--T:34-->
If the player is in map area 64, the state is reset back to 0.
If the player is in map area 64, the state is reset back to 0.


<!--T:35-->
Otherwise, the game does nothing until the current hour matches the previously generated appearance hour, at which point it sets AnimalMaster_Appearance to true (which allows the LotM to spawn) and goes into state 2.
Otherwise, the game does nothing until the current hour matches the previously generated appearance hour, at which point it sets AnimalMaster_Appearance to true (which allows the LotM to spawn) and goes into state 2.


====State 2====
====State 2==== <!--T:36-->
After one hour has elapsed, the current day of the week is stored and the state is set to 3.
After one hour has elapsed, the current day of the week is stored and the state is set to 3.


====State 3====
====State 3==== <!--T:37-->
After two week day changes, ''or'' [after the in-game day of the week changes and the current hour is >= the generated appearance hour], the LotM will disappear and the state will be set to 4.
After two week day changes, ''or'' [after the in-game day of the week changes and the current hour is >= the generated appearance hour], the LotM will disappear and the state will be set to 4.


====State 4====
====State 4==== <!--T:38-->
The game waits for the moon type to be 5, before going back to state 0.
The game waits for the moon type to be 5, before going back to state 0.


== WeatherMgr ==
== WeatherMgr == <!--T:39-->
{{expand section}}
{{expand section}}
=== Weather types ===
=== Weather types ===
Line 247: Line 268:
|}
|}


<!--T:40-->
[[Category:Internals]]
[[Category:Internals]]
[[Category:Subsystems (BotW)]]
[[Category:Subsystems (BotW)]]
</translate>
</translate>