WorldMgr and GameDataMgr: Difference between pages

From ZeldaMods (Breath of the Wild)
(Difference between pages)
Jump to navigation Jump to search
imported>Leoetlino
 
imported>Leoetlino
 
Line 1: Line 1:
{{Subsystem infobox|name=GameDataMgr|is_name_official=1|description=Manages game data flags|init_addr_switch150=0000007100DCE964}}
{{stub}}
{{stub}}
{{Subsystem infobox|name=WorldMgr|init_addr_switch150=00000071010F2920|is_name_official=1|description=Manages world state (time, blood moons, climates, weather, 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.


Because of the massive amount of state to handle, functionality is split across the main WorldMgr and 9 sub-managers.
GameDataMgr holds the date of all game data flags and provides functions to get, set and reset them. It is also responsible for keeping track of "shop sold out" flags and resetting them regularly.


== WorldMgr ==
Flag data is loaded from [[bgdata]] files and stored in [[TriggerParam]] objects. Transferring data from and to save files is done by interacting with the [[SaveSystem]] and [[SaveMgr]] subsystems.
=== Sub-managers ===
Sub-managers are created in WorldMgr::init (0x71010F43C0) and inserted into a pointer array (@WorldMgr+0x5c0). All names below are unofficial.


{|class="wikitable"
In debug versions, GameDataMgr is able to sync save data from and to a computer.
|+ Sub-managers by ID
! ID !! Description
|-
| 0 || TimeMgr
|-
| 1 || CloudPr? Handles cloud procedural generation.
|-
| 2 || ShootingStarMgr: Manages shooting stars and (in 1.3.3+) special shooting stars for the Xenoblade 2 quest.
|-
| 3 || Weather? Handles "rain splash" and climate weathers.
|-
| 4 || TemperatureMgr? (Reasonably sure about this one.)
|-
| 5 || ?
|-
| 6 || Sky and fog? Holds the configuration for all EnvPalettes, EnvAttributes, WeatherInfluences, Remains palettes, Indoor palettes and dungeon fogs.
|-
| 7 || DofMgr? Holds depth of field related parameters.
|-
| 8 || ?
|}


== TimeMgr ==
== TriggerParams ==
TimeMgr handles everything to do with time, including Blood Moons and the Lord of the Mountain's apparition.
There are at least two sets of TriggerParams at all times and up to four (param1, param, ???, GimmickResetBuffer). The exact purpose of each TriggerParam is currently unknown.


Internally, time of day is stored as a float in the [0.0, 360.0] range.
After all GameData flag info has been loaded into this->triggerParam from the GameData archive ([[gamedata.sarc]]), another TriggerParam instance called param1 (this->triggerParam1) is constructed and data is copied from this->triggerParam. The copy function also builds the lists of flags that need to be reset (with a non-zero ResetType) and of boolean flags with (initialValue >> 1) != 0.


=== TimeMgr::init ===
== Flags ==
* Time is set to 78.75 (05:15).
* Time for TotS environment is set to 78.75 (05:15) as well.
* "Bloody Moon end reserve timer" is set to 0.


=== TimeMgr::reset ===
== GameDataMgr::Flags ==
This is called whenever a stage is unloaded (essentially every time the loading screen is shown).
Stored at GameDataMgr+0xC18 on Switch 1.5.0. Most flags are still poorly understood.
* Blood Moon checks are delayed.
* The AnimalMaster_Appearance flag is cleared, meaning the Lord of the Mountain will not appear.


=== TimeMgr::calc ===
Flags are checked in the main update function (GameDataMgr::calc). Some flags are used to request actions such as resetting all flags to their initial value; these are automatically unset after GameDataMgr has processed the request.
This is called every frame.


* (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.)
<source lang="c++">
* If both [[Demo]]103_0 and Demo997_0 have not been played, time of day is reset to 78.75 (05:15).
enum GameDataMgr::Flags
* If [[AIDef:Action/AdvanceTime]] or anything else that changes time of day was called, the actual time is updated at this moment.
{
* [[#Midnight checks]].
  GameDataMgr::Flags_1 = 0x1,
  GameDataMgr::Flags_2 = 0x2,
  /// Causes GameDataMgr to call TriggerParam::resetToInitialValues(this->triggerParam1),
  /// clear some values of this->triggerParam and invoke reset callbacks
  GameDataMgr::Flags_NeedResetAllToInitial = 0x4,
  /// Causes GameDataMgr to call TriggerParam::reset(this->triggerParam1) (see below)
  GameDataMgr::Flags_NeedReset = 0x8,
  /// [Debug only] Creates a TriggerParam instance called "GimmickResetBuffer" (if needed)
  /// and copies data from param1.
  /// A pointer to the instance is stored in GameDataMgr.
  GameDataMgr::Flags_NeedGimmickReset = 0x10,
  /// If this->gimmickResetBufferParam is non-null, copy it to triggerParam and to triggerParam1 (args: 1, 0, 0).
  GameDataMgr::Flags_NeedCopyGimmickParam = 0x20,
  /// If this->gimmickResetBufferParam is non-null, copy it to triggerParam and to triggerParam1 (args: 1, 1, 0).
  GameDataMgr::Flags_40 = 0x40,
  GameDataMgr::Flags_80 = 0x80,
  GameDataMgr::Flags_100 = 0x100,
  GameDataMgr::Flags_200 = 0x200,
  GameDataMgr::Flags_400 = 0x400,
  /// Set from flag setter functions. The name is based on the fact that IsChangedByDebug gets set at the same time.
  GameDataMgr::Flags_IsChangedByDebugMaybe = 0x800,
  GameDataMgr::Flags_1000 = 0x1000,
  GameDataMgr::Flags_2000 = 0x2000,
  GameDataMgr::Flags_4000 = 0x4000,
  GameDataMgr::Flags_ChangeOnlyOnceMode = 0x8000,
  GameDataMgr::Flags_10000 = 0x10000,
  GameDataMgr::Flags_20000 = 0x20000,
  /// If set, GameDataMgr::calc will skip copying param1 to param (args: 0, 0, 0)
  GameDataMgr::Flags_DisableParam1ToParamSync = 0x40000,
  GameDataMgr::Flags_IsRestartFromGameOverMaybe = 0x80000,
  GameDataMgr::Flags_DoNotResetToInitialFromRadarMgr = 0x100000,
};
</source>


* '''Update time of day''': there are several possible update modes. In most cases, the update mode is 0.
== Reset flags ==
Stored at GameDataMgr+0xC1C on Switch 1.5.0.
{|class="wikitable"
{|class="wikitable"
! Mode !! Description
! Flag !! Description
|-
| 0 || If Demo103_0 or Demo997_0 have been played, and if there is no active event (cutscene):
* Add (0.0083333 * elapsed frames) to the Time of Day timer. Effectively, this means that 1 in-game minute = 1 real-life second.
* If the timer is >= 360.0, which means that a day has passed, the game subtracts 360 from the timer and then performs midnight checks.
* If FindDungeon_Activated is false (if the player hasn't received the ''The Isolated Plateau'' quest) and if the current time is >= 165.0 (11:00), the time is forcefully set to 11:00. Effectively, this means that time will not get past 11:00 until the Great Plateau Tower is activated and the Old Man cutscene is triggered.
* The Blood Moon timer is updated too.
|-
| 1, 13, 35 || Freeze time to 04:00
|-
| 2, 14 || Freeze time to 05:00
|-
| 3, 16, 36 || Freeze time to 07:00
|-
| 4, 19, 37 || Freeze time to 10:00
|-
| 5, 26, 39 || Freeze time to 17:00
|-
| 6, 28, 40 || Freeze time to 19:00
|-
| 7, 30, 41 || Freeze time to 21:00
|-
| 8, 11 || Freeze time to 02:00
|-
| 9, 42 || Freeze time to 00:00
|-
| 10 || Freeze time to 01:00
|-
| 12 || Freeze time to 03:00
|-
| 15 || Freeze time to 06:00
|-
| 17 || Freeze time to 08:00
|-
|-
| 18 || Freeze time to 09:00
| 1 || ?
|-
|-
| 20 || Freeze time to 11:00
| 2 || Corresponds to reset type 1.
|-
|-
| 21 || Freeze time to 12:00
| 4 || Corresponds to reset type 2.
|-
|-
| 22, 38 || Freeze time to 13:00
| 8 || Corresponds to reset type 3.
|-
|-
| 23 || Freeze time to 14:00
| 0x10 || Corresponds to reset type 4.
|-
| 24 || Freeze time to 15:00
|-
| 25 || Freeze time to 16:00
|-
| 27 || Freeze time to 18:00
|-
| 29 || Freeze time to 20:00
|-
| 31 || Freeze time to 22:00
|-
| 32 || Freeze time to 23:00
|-
| 34 ||
* Add (0.0083333 * elapsed frames) to the Time of Day timer.
* If the timer is >= 360.0, which means that a day has passed, the game subtracts 360 from the timer.
 
'''Note''': In this state, the blood moon timer is never updated and its value is never checked either.  
|}
|}


* Update the [[#Day/night time flag]], the [[#Time division, IsMorning, IsNoon, etc.]]
== Reset process ==
* If the "Bloody Moon end reserve timer" is non zero, decrement it. If the new value is zero, the WM_BloodyDay flag is cleared.
All game data flags for which <code>(1 << resetType) & resetFlags</code> is true are reset to their initial values.
* Update [[#Lord of the Mountain]] flags.


=== Midnight checks ===
TriggerParam::reset processes up to 1024 flags at a time. The function returns the number of remaining flags to reset and flag 0x08 (GameDataMgr::Flags_NeedReset) is only cleared when all flags have been reset.
The following actions happen every time the timer reaches 360.0 (midnight).


WM_NumberOfDays is incremented.
=== bool and s32 flags with reset type 3 ===
bool and s32 flags with reset type 3, and with a flag name hash that is listed in ShopAreaInfo (in [[ShopGameDataInfo.byml]]) receive special treatment.


'''If a Blood Moon is scheduled''' (WM_BloodyDay is true):
If:
*If Blood Moons are prohibited (see conditions below), set the Blood Moon timer to 2880.0.
* the player is in none of the shop areas that are associated with the flag (or in the Dealer's area for area-less flags); or if the player is not on MainField
*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.
* '''and''', for items with the <code>Arrow</code> tag: if the player has fewer than {itemSaleRevivalCount} arrows in their inventory
 
Then:
'''Scheduling new Blood Moons''':
* The flag is reset to its initial value.
*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):
* For bool flags: All associated sold out flags are reset to their initial values.
**WM_BloodyDay is set to true, which means that a Blood Moon is scheduled for the next night.
**The Blood Moon timer is reset to 0.0.
* 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 ====
If any of the following conditions are true, the Blood Moon cutscene will not be triggered.
 
* Not on MainField (main overworld)
* IsInHyruleCastleArea is set
* LastBossGanonBeastGenerateFlag is set (fighting Dark Beast Ganon)
* BloodyMoonProhibition is set
* Wind_Relic_BattleStart is set (Vah Medoh battle)
* Electric_Relic_Battle is set (Vah Naboris battle)
* Water_Relic_BattleTime is set (Vah Ruta battle)
* SkyMgr's field_2B4 is set to 15 and field_2B8 >= 1.0
 
However, these do not prevent the Blood Moon timer from advancing, or the WM_BloodyDay flag from being set.
 
=== Day/night time flag ===
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.
 
In any other case, WM_DaytimeFlag is set to true and WM_NighttimeFlag to false.
 
=== Time division, IsMorning, IsNoon, etc. ===
{|class="wikitable"
! Start !! End !! Division !! Time type (1) !! Time type (2)
|-
| 04:00 || 05:00 || 0 || MorningA || Morning_A1
|-
| 05:00 || 07:00 || 0 || MorningA || Morning_A2
|-
| 07:00 || 10:00 || 1 || MorningB || Morning_B
|-
| 10:00 || 13:00 || 2 || NoonA || Noon_A
|-
| 13:00 || 17:00 || 3 || NoonB || Noon_B
|-
| 17:00 || 19:00 || 4 || EveningA || Evening_A
|-
| 19:00 || 21:00 || 5 || EveningB || Evening_B
|-
| 21:00 || 00:00 || 6 || NightA || Night_A
|-
| 00:00 || 04:00 || 7 || NightB || Night_B
|}
Note: all intervals include the start time and exclude the end time.
 
=== Moon type ===
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.
 
If a moon type was set manually (for instance using [[AIDef:Action/EventSetMoonType]]), that value will be used as the moon type.
 
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 ===
The Lord of the Mountain appears whenever the AnimalMaster_Appearance flag is set. Its value is managed by a simple state machine.
 
Note that whenever a stage is unloaded, the AnimalMaster_Appearance flag is reset to false.
 
====State 0 - Wait for conditions====
If the following three conditions are true:
* The [[#Moon type]] is 5 (waxing crescent)
* The AnimalMaster_Existence flag is false (the LotM must not already be spawned)
* The current [[map area]] number is not 64 ("HyruleHill", presumably the Satori Mountain area)
 
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====
If the player is in map area 64, the state is reset back to 0.
 
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====
After one hour has elapsed, the current day of the week is stored and the state is set to 3.
 
====State 3====
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====
The game waits for the moon type to be 5, before going back to state 0.
 
== WeatherMgr ==
{{expand section}}
=== Weather types ===
{|class="wikitable"
! Value !! Name
|-
| 0 || Bluesky
|-
| 1 || Cloudy
|-
| 2 || Rain
|-
| 3 || HeavyRain
|-
| 4 || Snow
|-
| 5 || HeavySnow
|-
| 6 || ThunderStorm
|-
| 7 || ThunderRain
|-
| 8 || BlueskyRain
|}


[[Category:Internals]]
[[Category: Internals]]
[[Category:Subsystems (BotW)]]
[[Category: Subsystems (BotW)]]

Revision as of 09:47, 31 December 2018

GameDataMgr
Subsystem
Official name Yes
Description Manages game data flags
Init function Switch 1.5.0: 0000007100DCE964
Wii U 1.5.0: ???
Debug only No


GameDataMgr holds the date of all game data flags and provides functions to get, set and reset them. It is also responsible for keeping track of "shop sold out" flags and resetting them regularly.

Flag data is loaded from bgdata files and stored in TriggerParam objects. Transferring data from and to save files is done by interacting with the SaveSystem and SaveMgr subsystems.

In debug versions, GameDataMgr is able to sync save data from and to a computer.

TriggerParams

There are at least two sets of TriggerParams at all times and up to four (param1, param, ???, GimmickResetBuffer). The exact purpose of each TriggerParam is currently unknown.

After all GameData flag info has been loaded into this->triggerParam from the GameData archive (gamedata.sarc), another TriggerParam instance called param1 (this->triggerParam1) is constructed and data is copied from this->triggerParam. The copy function also builds the lists of flags that need to be reset (with a non-zero ResetType) and of boolean flags with (initialValue >> 1) != 0.

Flags

GameDataMgr::Flags

Stored at GameDataMgr+0xC18 on Switch 1.5.0. Most flags are still poorly understood.

Flags are checked in the main update function (GameDataMgr::calc). Some flags are used to request actions such as resetting all flags to their initial value; these are automatically unset after GameDataMgr has processed the request.

enum GameDataMgr::Flags
{
  GameDataMgr::Flags_1 = 0x1,
  GameDataMgr::Flags_2 = 0x2,
  /// Causes GameDataMgr to call TriggerParam::resetToInitialValues(this->triggerParam1),
  /// clear some values of this->triggerParam and invoke reset callbacks
  GameDataMgr::Flags_NeedResetAllToInitial = 0x4,
  /// Causes GameDataMgr to call TriggerParam::reset(this->triggerParam1) (see below)
  GameDataMgr::Flags_NeedReset = 0x8,
  /// [Debug only] Creates a TriggerParam instance called "GimmickResetBuffer" (if needed)
  /// and copies data from param1.
  /// A pointer to the instance is stored in GameDataMgr.
  GameDataMgr::Flags_NeedGimmickReset = 0x10,
  /// If this->gimmickResetBufferParam is non-null, copy it to triggerParam and to triggerParam1 (args: 1, 0, 0).
  GameDataMgr::Flags_NeedCopyGimmickParam = 0x20,
  /// If this->gimmickResetBufferParam is non-null, copy it to triggerParam and to triggerParam1 (args: 1, 1, 0).
  GameDataMgr::Flags_40 = 0x40,
  GameDataMgr::Flags_80 = 0x80,
  GameDataMgr::Flags_100 = 0x100,
  GameDataMgr::Flags_200 = 0x200,
  GameDataMgr::Flags_400 = 0x400,
  /// Set from flag setter functions. The name is based on the fact that IsChangedByDebug gets set at the same time.
  GameDataMgr::Flags_IsChangedByDebugMaybe = 0x800,
  GameDataMgr::Flags_1000 = 0x1000,
  GameDataMgr::Flags_2000 = 0x2000,
  GameDataMgr::Flags_4000 = 0x4000,
  GameDataMgr::Flags_ChangeOnlyOnceMode = 0x8000,
  GameDataMgr::Flags_10000 = 0x10000,
  GameDataMgr::Flags_20000 = 0x20000,
  /// If set, GameDataMgr::calc will skip copying param1 to param (args: 0, 0, 0)
  GameDataMgr::Flags_DisableParam1ToParamSync = 0x40000,
  GameDataMgr::Flags_IsRestartFromGameOverMaybe = 0x80000,
  GameDataMgr::Flags_DoNotResetToInitialFromRadarMgr = 0x100000,
};

Reset flags

Stored at GameDataMgr+0xC1C on Switch 1.5.0.

Flag Description
1 ?
2 Corresponds to reset type 1.
4 Corresponds to reset type 2.
8 Corresponds to reset type 3.
0x10 Corresponds to reset type 4.

Reset process

All game data flags for which (1 << resetType) & resetFlags is true are reset to their initial values.

TriggerParam::reset processes up to 1024 flags at a time. The function returns the number of remaining flags to reset and flag 0x08 (GameDataMgr::Flags_NeedReset) is only cleared when all flags have been reset.

bool and s32 flags with reset type 3

bool and s32 flags with reset type 3, and with a flag name hash that is listed in ShopAreaInfo (in ShopGameDataInfo.byml) receive special treatment.

If:

  • the player is in none of the shop areas that are associated with the flag (or in the Dealer's area for area-less flags); or if the player is not on MainField
  • and, for items with the Arrow tag: if the player has fewer than {itemSaleRevivalCount} arrows in their inventory

Then:

  • The flag is reset to its initial value.
  • For bool flags: All associated sold out flags are reset to their initial values.