AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
The World

Files

file  Weather.cpp
 
file  Weather.h
 
file  WeatherMgr.cpp
 
file  WeatherMgr.h
 
file  World.cpp
 
file  World.h
 

Namespaces

namespace  WeatherMgr
 

Classes

struct  WeatherSeasonChances
 
struct  WeatherData
 
class  Weather
 Weather for one zone. More...
 
struct  PetitionData
 
class  World
 The World. More...
 

Macros

#define WEATHER_SEASONS   4
 
#define sWorld   getWorldInstance()
 

Enumerations

enum  WeatherState : uint32 {
  WEATHER_STATE_FINE = 0 ,
  WEATHER_STATE_FOG = 1 ,
  WEATHER_STATE_LIGHT_RAIN = 3 ,
  WEATHER_STATE_MEDIUM_RAIN = 4 ,
  WEATHER_STATE_HEAVY_RAIN = 5 ,
  WEATHER_STATE_LIGHT_SNOW = 6 ,
  WEATHER_STATE_MEDIUM_SNOW = 7 ,
  WEATHER_STATE_HEAVY_SNOW = 8 ,
  WEATHER_STATE_LIGHT_SANDSTORM = 22 ,
  WEATHER_STATE_MEDIUM_SANDSTORM = 41 ,
  WEATHER_STATE_HEAVY_SANDSTORM = 42 ,
  WEATHER_STATE_THUNDERS = 86 ,
  WEATHER_STATE_BLACKRAIN = 90 ,
  WEATHER_STATE_BLACKSNOW = 106
}
 
enum  ShutdownMask : uint8 {
  SHUTDOWN_MASK_RESTART = 1 ,
  SHUTDOWN_MASK_IDLE = 2
}
 
enum  ShutdownExitCode : uint8 {
  SHUTDOWN_EXIT_CODE = 0 ,
  ERROR_EXIT_CODE = 1 ,
  RESTART_EXIT_CODE = 2
}
 
enum  WorldTimers {
  WUPDATE_WEATHERS ,
  WUPDATE_UPTIME ,
  WUPDATE_CORPSES ,
  WUPDATE_EVENTS ,
  WUPDATE_CLEANDB ,
  WUPDATE_AUTOBROADCAST ,
  WUPDATE_MAILBOXQUEUE ,
  WUPDATE_PINGDB ,
  WUPDATE_5_SECS ,
  WUPDATE_WHO_LIST ,
  WUPDATE_COUNT
}
 Timers for different object refresh rates. More...
 
enum  BillingPlanFlags {
  SESSION_NONE = 0x00 ,
  SESSION_UNUSED = 0x01 ,
  SESSION_RECURRING_BILL = 0x02 ,
  SESSION_FREE_TRIAL = 0x04 ,
  SESSION_IGR = 0x08 ,
  SESSION_USAGE = 0x10 ,
  SESSION_TIME_MIXTURE = 0x20 ,
  SESSION_RESTRICTED = 0x40 ,
  SESSION_ENABLE_CAIS = 0x80
}
 Can be used in SMSG_AUTH_RESPONSE packet. More...
 
enum  RealmZone {
  REALM_ZONE_UNKNOWN = 0 ,
  REALM_ZONE_DEVELOPMENT = 1 ,
  REALM_ZONE_UNITED_STATES = 2 ,
  REALM_ZONE_OCEANIC = 3 ,
  REALM_ZONE_LATIN_AMERICA = 4 ,
  REALM_ZONE_TOURNAMENT_5 = 5 ,
  REALM_ZONE_KOREA = 6 ,
  REALM_ZONE_TOURNAMENT_7 = 7 ,
  REALM_ZONE_ENGLISH = 8 ,
  REALM_ZONE_GERMAN = 9 ,
  REALM_ZONE_FRENCH = 10 ,
  REALM_ZONE_SPANISH = 11 ,
  REALM_ZONE_RUSSIAN = 12 ,
  REALM_ZONE_TOURNAMENT_13 = 13 ,
  REALM_ZONE_TAIWAN = 14 ,
  REALM_ZONE_TOURNAMENT_15 = 15 ,
  REALM_ZONE_CHINA = 16 ,
  REALM_ZONE_CN1 = 17 ,
  REALM_ZONE_CN2 = 18 ,
  REALM_ZONE_CN3 = 19 ,
  REALM_ZONE_CN4 = 20 ,
  REALM_ZONE_CN5 = 21 ,
  REALM_ZONE_CN6 = 22 ,
  REALM_ZONE_CN7 = 23 ,
  REALM_ZONE_CN8 = 24 ,
  REALM_ZONE_TOURNAMENT_25 = 25 ,
  REALM_ZONE_TEST_SERVER = 26 ,
  REALM_ZONE_TOURNAMENT_27 = 27 ,
  REALM_ZONE_QA_SERVER = 28 ,
  REALM_ZONE_CN9 = 29 ,
  REALM_ZONE_TEST_SERVER_2 = 30 ,
  REALM_ZONE_CN10 = 31 ,
  REALM_ZONE_CTC = 32 ,
  REALM_ZONE_CNC = 33 ,
  REALM_ZONE_CN1_4 = 34 ,
  REALM_ZONE_CN2_6_9 = 35 ,
  REALM_ZONE_CN3_7 = 36 ,
  REALM_ZONE_CN5_8 = 37
}
 

Functions

 Weather::Weather (uint32 zone, WeatherData const *weatherChances)
 Create the Weather object.
 
 Weather::~Weather ()=default
 
bool Weather::Update (uint32 diff)
 Launch a weather update.
 
bool Weather::ReGenerate ()
 Calculate the new weather.
 
bool Weather::UpdateWeather ()
 Send the new weather to all players in the zone.
 
void Weather::SendWeatherUpdateToPlayer (Player *player)
 
void Weather::SetWeather (WeatherType type, float grade)
 Set the weather.
 
uint32 Weather::GetZone () const
 For which zone is this weather?
 
uint32 Weather::GetScriptId () const
 
WeatherState Weather::GetWeatherState () const
 Get the sound number associated with the current weather.
 
void WeatherMgr::LoadWeatherData ()
 
WeatherWeatherMgr::FindWeather (uint32 id)
 Find a Weather object by the given zoneid.
 
WeatherWeatherMgr::AddWeather (uint32 zone_id)
 Add a Weather object to the list.
 
void WeatherMgr::RemoveWeather (uint32 id)
 Remove a Weather object for the given zoneid.
 
void WeatherMgr::SendFineWeatherUpdateToPlayer (Player *player)
 
void WeatherMgr::Update (uint32 diff)
 
std::unique_ptr< IWorld > & getWorldInstance ()
 

Variables

uint32 WeatherSeasonChances::rainChance
 
uint32 WeatherSeasonChances::snowChance
 
uint32 WeatherSeasonChances::stormChance
 
WeatherSeasonChances WeatherData::data [WEATHER_SEASONS]
 
uint32 WeatherData::ScriptId
 
uint32 Weather::m_zone
 
WeatherType Weather::m_type
 
float Weather::m_grade
 
IntervalTimer Weather::m_timer
 
WeatherData const * Weather::m_weatherChances
 
AC_GAME_API Realm realm
 

Detailed Description

Macro Definition Documentation

◆ sWorld

◆ WEATHER_SEASONS

#define WEATHER_SEASONS   4

Enumeration Type Documentation

◆ BillingPlanFlags

#include <azerothcore-wotlk/src/server/game/World/World.h>

Can be used in SMSG_AUTH_RESPONSE packet.

Enumerator
SESSION_NONE 
SESSION_UNUSED 
SESSION_RECURRING_BILL 
SESSION_FREE_TRIAL 
SESSION_IGR 
SESSION_USAGE 
SESSION_TIME_MIXTURE 
SESSION_RESTRICTED 
SESSION_ENABLE_CAIS 
76{
77 SESSION_NONE = 0x00,
78 SESSION_UNUSED = 0x01,
80 SESSION_FREE_TRIAL = 0x04,
81 SESSION_IGR = 0x08,
82 SESSION_USAGE = 0x10,
84 SESSION_RESTRICTED = 0x40,
86};
@ SESSION_NONE
Definition World.h:77
@ SESSION_TIME_MIXTURE
Definition World.h:83
@ SESSION_USAGE
Definition World.h:82
@ SESSION_RECURRING_BILL
Definition World.h:79
@ SESSION_ENABLE_CAIS
Definition World.h:85
@ SESSION_RESTRICTED
Definition World.h:84
@ SESSION_UNUSED
Definition World.h:78
@ SESSION_FREE_TRIAL
Definition World.h:80
@ SESSION_IGR
Definition World.h:81

◆ RealmZone

enum RealmZone

#include <azerothcore-wotlk/src/server/game/World/World.h>

Enumerator
REALM_ZONE_UNKNOWN 
REALM_ZONE_DEVELOPMENT 
REALM_ZONE_UNITED_STATES 
REALM_ZONE_OCEANIC 
REALM_ZONE_LATIN_AMERICA 
REALM_ZONE_TOURNAMENT_5 
REALM_ZONE_KOREA 
REALM_ZONE_TOURNAMENT_7 
REALM_ZONE_ENGLISH 
REALM_ZONE_GERMAN 
REALM_ZONE_FRENCH 
REALM_ZONE_SPANISH 
REALM_ZONE_RUSSIAN 
REALM_ZONE_TOURNAMENT_13 
REALM_ZONE_TAIWAN 
REALM_ZONE_TOURNAMENT_15 
REALM_ZONE_CHINA 
REALM_ZONE_CN1 
REALM_ZONE_CN2 
REALM_ZONE_CN3 
REALM_ZONE_CN4 
REALM_ZONE_CN5 
REALM_ZONE_CN6 
REALM_ZONE_CN7 
REALM_ZONE_CN8 
REALM_ZONE_TOURNAMENT_25 
REALM_ZONE_TEST_SERVER 
REALM_ZONE_TOURNAMENT_27 
REALM_ZONE_QA_SERVER 
REALM_ZONE_CN9 
REALM_ZONE_TEST_SERVER_2 
REALM_ZONE_CN10 
REALM_ZONE_CTC 
REALM_ZONE_CNC 
REALM_ZONE_CN1_4 
REALM_ZONE_CN2_6_9 
REALM_ZONE_CN3_7 
REALM_ZONE_CN5_8 
89{
90 REALM_ZONE_UNKNOWN = 0, // any language
91 REALM_ZONE_DEVELOPMENT = 1, // any language
92 REALM_ZONE_UNITED_STATES = 2, // extended-Latin
93 REALM_ZONE_OCEANIC = 3, // extended-Latin
94 REALM_ZONE_LATIN_AMERICA = 4, // extended-Latin
95 REALM_ZONE_TOURNAMENT_5 = 5, // basic-Latin at create, any at login
96 REALM_ZONE_KOREA = 6, // East-Asian
97 REALM_ZONE_TOURNAMENT_7 = 7, // basic-Latin at create, any at login
98 REALM_ZONE_ENGLISH = 8, // extended-Latin
99 REALM_ZONE_GERMAN = 9, // extended-Latin
100 REALM_ZONE_FRENCH = 10, // extended-Latin
101 REALM_ZONE_SPANISH = 11, // extended-Latin
102 REALM_ZONE_RUSSIAN = 12, // Cyrillic
103 REALM_ZONE_TOURNAMENT_13 = 13, // basic-Latin at create, any at login
104 REALM_ZONE_TAIWAN = 14, // East-Asian
105 REALM_ZONE_TOURNAMENT_15 = 15, // basic-Latin at create, any at login
106 REALM_ZONE_CHINA = 16, // East-Asian
107 REALM_ZONE_CN1 = 17, // basic-Latin at create, any at login
108 REALM_ZONE_CN2 = 18, // basic-Latin at create, any at login
109 REALM_ZONE_CN3 = 19, // basic-Latin at create, any at login
110 REALM_ZONE_CN4 = 20, // basic-Latin at create, any at login
111 REALM_ZONE_CN5 = 21, // basic-Latin at create, any at login
112 REALM_ZONE_CN6 = 22, // basic-Latin at create, any at login
113 REALM_ZONE_CN7 = 23, // basic-Latin at create, any at login
114 REALM_ZONE_CN8 = 24, // basic-Latin at create, any at login
115 REALM_ZONE_TOURNAMENT_25 = 25, // basic-Latin at create, any at login
116 REALM_ZONE_TEST_SERVER = 26, // any language
117 REALM_ZONE_TOURNAMENT_27 = 27, // basic-Latin at create, any at login
118 REALM_ZONE_QA_SERVER = 28, // any language
119 REALM_ZONE_CN9 = 29, // basic-Latin at create, any at login
120 REALM_ZONE_TEST_SERVER_2 = 30, // any language
121 REALM_ZONE_CN10 = 31, // basic-Latin at create, any at login
122 REALM_ZONE_CTC = 32,
123 REALM_ZONE_CNC = 33,
124 REALM_ZONE_CN1_4 = 34, // basic-Latin at create, any at login
125 REALM_ZONE_CN2_6_9 = 35, // basic-Latin at create, any at login
126 REALM_ZONE_CN3_7 = 36, // basic-Latin at create, any at login
127 REALM_ZONE_CN5_8 = 37 // basic-Latin at create, any at login
128};
@ REALM_ZONE_CN2
Definition World.h:108
@ REALM_ZONE_TEST_SERVER
Definition World.h:116
@ REALM_ZONE_TOURNAMENT_7
Definition World.h:97
@ REALM_ZONE_TOURNAMENT_5
Definition World.h:95
@ REALM_ZONE_LATIN_AMERICA
Definition World.h:94
@ REALM_ZONE_CN4
Definition World.h:110
@ REALM_ZONE_TOURNAMENT_25
Definition World.h:115
@ REALM_ZONE_SPANISH
Definition World.h:101
@ REALM_ZONE_OCEANIC
Definition World.h:93
@ REALM_ZONE_KOREA
Definition World.h:96
@ REALM_ZONE_UNKNOWN
Definition World.h:90
@ REALM_ZONE_TOURNAMENT_15
Definition World.h:105
@ REALM_ZONE_CNC
Definition World.h:123
@ REALM_ZONE_UNITED_STATES
Definition World.h:92
@ REALM_ZONE_CN5_8
Definition World.h:127
@ REALM_ZONE_CN2_6_9
Definition World.h:125
@ REALM_ZONE_CN1_4
Definition World.h:124
@ REALM_ZONE_CN8
Definition World.h:114
@ REALM_ZONE_ENGLISH
Definition World.h:98
@ REALM_ZONE_TOURNAMENT_13
Definition World.h:103
@ REALM_ZONE_FRENCH
Definition World.h:100
@ REALM_ZONE_CN9
Definition World.h:119
@ REALM_ZONE_QA_SERVER
Definition World.h:118
@ REALM_ZONE_CN3
Definition World.h:109
@ REALM_ZONE_CN10
Definition World.h:121
@ REALM_ZONE_CN3_7
Definition World.h:126
@ REALM_ZONE_TEST_SERVER_2
Definition World.h:120
@ REALM_ZONE_CHINA
Definition World.h:106
@ REALM_ZONE_CN5
Definition World.h:111
@ REALM_ZONE_CN7
Definition World.h:113
@ REALM_ZONE_TOURNAMENT_27
Definition World.h:117
@ REALM_ZONE_CTC
Definition World.h:122
@ REALM_ZONE_CN6
Definition World.h:112
@ REALM_ZONE_RUSSIAN
Definition World.h:102
@ REALM_ZONE_DEVELOPMENT
Definition World.h:91
@ REALM_ZONE_CN1
Definition World.h:107
@ REALM_ZONE_TAIWAN
Definition World.h:104
@ REALM_ZONE_GERMAN
Definition World.h:99

◆ ShutdownExitCode

#include <azerothcore-wotlk/src/server/game/World/World.h>

Enumerator
SHUTDOWN_EXIT_CODE 
ERROR_EXIT_CODE 
RESTART_EXIT_CODE 
52{
56};
@ RESTART_EXIT_CODE
Definition World.h:55
@ SHUTDOWN_EXIT_CODE
Definition World.h:53
@ ERROR_EXIT_CODE
Definition World.h:54

◆ ShutdownMask

#include <azerothcore-wotlk/src/server/game/World/World.h>

Enumerator
SHUTDOWN_MASK_RESTART 
SHUTDOWN_MASK_IDLE 
46{
49};
@ SHUTDOWN_MASK_RESTART
Definition World.h:47
@ SHUTDOWN_MASK_IDLE
Definition World.h:48

◆ WeatherState

#include <azerothcore-wotlk/src/server/game/Weather/Weather.h>

Enumerator
WEATHER_STATE_FINE 
WEATHER_STATE_FOG 
WEATHER_STATE_LIGHT_RAIN 
WEATHER_STATE_MEDIUM_RAIN 
WEATHER_STATE_HEAVY_RAIN 
WEATHER_STATE_LIGHT_SNOW 
WEATHER_STATE_MEDIUM_SNOW 
WEATHER_STATE_HEAVY_SNOW 
WEATHER_STATE_LIGHT_SANDSTORM 
WEATHER_STATE_MEDIUM_SANDSTORM 
WEATHER_STATE_HEAVY_SANDSTORM 
WEATHER_STATE_THUNDERS 
WEATHER_STATE_BLACKRAIN 
WEATHER_STATE_BLACKSNOW 
45{
60};
@ WEATHER_STATE_THUNDERS
Definition Weather.h:57
@ WEATHER_STATE_HEAVY_RAIN
Definition Weather.h:50
@ WEATHER_STATE_HEAVY_SANDSTORM
Definition Weather.h:56
@ WEATHER_STATE_MEDIUM_SNOW
Definition Weather.h:52
@ WEATHER_STATE_MEDIUM_RAIN
Definition Weather.h:49
@ WEATHER_STATE_MEDIUM_SANDSTORM
Definition Weather.h:55
@ WEATHER_STATE_BLACKSNOW
Definition Weather.h:59
@ WEATHER_STATE_FINE
Definition Weather.h:46
@ WEATHER_STATE_LIGHT_SNOW
Definition Weather.h:51
@ WEATHER_STATE_BLACKRAIN
Definition Weather.h:58
@ WEATHER_STATE_HEAVY_SNOW
Definition Weather.h:53
@ WEATHER_STATE_LIGHT_SANDSTORM
Definition Weather.h:54
@ WEATHER_STATE_FOG
Definition Weather.h:47
@ WEATHER_STATE_LIGHT_RAIN
Definition Weather.h:48

◆ WorldTimers

#include <azerothcore-wotlk/src/server/game/World/World.h>

Timers for different object refresh rates.

Enumerator
WUPDATE_WEATHERS 
WUPDATE_UPTIME 
WUPDATE_CORPSES 
WUPDATE_EVENTS 
WUPDATE_CLEANDB 
WUPDATE_AUTOBROADCAST 
WUPDATE_MAILBOXQUEUE 
WUPDATE_PINGDB 
WUPDATE_5_SECS 
WUPDATE_WHO_LIST 
WUPDATE_COUNT 
60{
72};
@ WUPDATE_COUNT
Definition World.h:71
@ WUPDATE_MAILBOXQUEUE
Definition World.h:67
@ WUPDATE_CLEANDB
Definition World.h:65
@ WUPDATE_CORPSES
Definition World.h:63
@ WUPDATE_PINGDB
Definition World.h:68
@ WUPDATE_5_SECS
Definition World.h:69
@ WUPDATE_AUTOBROADCAST
Definition World.h:66
@ WUPDATE_WHO_LIST
Definition World.h:70
@ WUPDATE_UPTIME
Definition World.h:62
@ WUPDATE_WEATHERS
Definition World.h:61
@ WUPDATE_EVENTS
Definition World.h:64

Function Documentation

◆ AddWeather()

Weather * WeatherMgr::AddWeather ( uint32  zone_id)

#include <azerothcore-wotlk/src/server/game/Weather/WeatherMgr.cpp>

Add a Weather object to the list.

67 {
68 WeatherData const* weatherChances = GetWeatherData(zone_id);
69
70 // zone does not have weather, ignore
71 if (!weatherChances)
72 return nullptr;
73
74 Weather* w = new Weather(zone_id, weatherChances);
75 m_weathers[w->GetZone()].reset(w);
76 w->ReGenerate();
77 w->UpdateWeather();
78
79 return w;
80 }
Weather for one zone.
Definition Weather.h:64
uint32 GetZone() const
For which zone is this weather?
Definition Weather.h:77
bool UpdateWeather()
Send the new weather to all players in the zone.
Definition Weather.cpp:194
bool ReGenerate()
Calculate the new weather.
Definition Weather.cpp:67
Definition Weather.h:39

References Weather::GetZone(), Weather::ReGenerate(), and Weather::UpdateWeather().

Referenced by misc_commandscript::HandleChangeWeather(), and Player::UpdateZone().

◆ FindWeather()

Weather * WeatherMgr::FindWeather ( uint32  id)

#include <azerothcore-wotlk/src/server/game/Weather/WeatherMgr.cpp>

Find a Weather object by the given zoneid.

50 {
51 WeatherMap::const_iterator itr = m_weathers.find(id);
52 return (itr != m_weathers.end()) ? itr->second.get() : 0;
53 }

Referenced by misc_commandscript::HandleChangeWeather(), and Player::UpdateZone().

◆ GetScriptId()

uint32 Weather::GetScriptId ( ) const
inline

#include <azerothcore-wotlk/src/server/game/Weather/Weather.h>

78{ return m_weatherChances->ScriptId; }
uint32 ScriptId
Definition Weather.h:41
WeatherData const * m_weatherChances
Definition Weather.h:86

References Weather::m_weatherChances, and WeatherData::ScriptId.

Referenced by ScriptMgr::OnWeatherChange(), and ScriptMgr::OnWeatherUpdate().

◆ GetWeatherState()

WeatherState Weather::GetWeatherState ( ) const
private

#include <azerothcore-wotlk/src/server/game/Weather/Weather.h>

Get the sound number associated with the current weather.

274{
275 if (m_grade < 0.27f)
276 return WEATHER_STATE_FINE;
277
278 switch (m_type)
279 {
281 if (m_grade < 0.40f)
283 else if (m_grade < 0.70f)
285 else
288 if (m_grade < 0.40f)
290 else if (m_grade < 0.70f)
292 else
295 if (m_grade < 0.40f)
297 else if (m_grade < 0.70f)
299 else
306 default:
307 return WEATHER_STATE_FINE;
308 }
309}
@ WEATHER_TYPE_RAIN
Definition SharedDefines.h:3139
@ WEATHER_TYPE_STORM
Definition SharedDefines.h:3141
@ WEATHER_TYPE_FINE
Definition SharedDefines.h:3138
@ WEATHER_TYPE_SNOW
Definition SharedDefines.h:3140
@ WEATHER_TYPE_THUNDERS
Definition SharedDefines.h:3142
@ WEATHER_TYPE_BLACKRAIN
Definition SharedDefines.h:3143
WeatherType m_type
Definition Weather.h:83
float m_grade
Definition Weather.h:84

References Weather::m_grade, Weather::m_type, WEATHER_STATE_BLACKRAIN, WEATHER_STATE_FINE, WEATHER_STATE_HEAVY_RAIN, WEATHER_STATE_HEAVY_SANDSTORM, WEATHER_STATE_HEAVY_SNOW, WEATHER_STATE_LIGHT_RAIN, WEATHER_STATE_LIGHT_SANDSTORM, WEATHER_STATE_LIGHT_SNOW, WEATHER_STATE_MEDIUM_RAIN, WEATHER_STATE_MEDIUM_SANDSTORM, WEATHER_STATE_MEDIUM_SNOW, WEATHER_STATE_THUNDERS, WEATHER_TYPE_BLACKRAIN, WEATHER_TYPE_FINE, WEATHER_TYPE_RAIN, WEATHER_TYPE_SNOW, WEATHER_TYPE_STORM, and WEATHER_TYPE_THUNDERS.

Referenced by Weather::SendWeatherUpdateToPlayer(), and Weather::UpdateWeather().

◆ getWorldInstance()

std::unique_ptr< IWorld > & getWorldInstance ( )

#include <azerothcore-wotlk/src/server/game/World/World.h>

149{
150 static std::unique_ptr<IWorld> instance = std::make_unique<World>();
151 return instance;
152}

◆ GetZone()

uint32 Weather::GetZone ( ) const
inline

#include <azerothcore-wotlk/src/server/game/Weather/Weather.h>

For which zone is this weather?

77{ return m_zone; };
uint32 m_zone
Definition Weather.h:82

References Weather::m_zone.

Referenced by WeatherMgr::AddWeather().

◆ LoadWeatherData()

void WeatherMgr::LoadWeatherData ( )

#include <azerothcore-wotlk/src/server/game/Weather/WeatherMgr.cpp>

83 {
84 uint32 oldMSTime = getMSTime();
85
86 uint32 count = 0;
87
88 QueryResult result = WorldDatabase.Query("SELECT "
89 "zone, spring_rain_chance, spring_snow_chance, spring_storm_chance,"
90 "summer_rain_chance, summer_snow_chance, summer_storm_chance,"
91 "fall_rain_chance, fall_snow_chance, fall_storm_chance,"
92 "winter_rain_chance, winter_snow_chance, winter_storm_chance,"
93 "ScriptName FROM game_weather");
94
95 if (!result)
96 {
97 LOG_WARN("server.loading", ">> Loaded 0 weather definitions. DB table `game_weather` is empty.");
98 LOG_INFO("server.loading", " ");
99 return;
100 }
101
102 do
103 {
104 Field* fields = result->Fetch();
105
106 uint32 zone_id = fields[0].Get<uint32>();
107
108 WeatherData& wzc = mWeatherZoneMap[zone_id];
109
110 for (uint8 season = 0; season < WEATHER_SEASONS; ++season)
111 {
112 wzc.data[season].rainChance = fields[season * (MAX_WEATHER_TYPE - 1) + 1].Get<uint8>();
113 wzc.data[season].snowChance = fields[season * (MAX_WEATHER_TYPE - 1) + 2].Get<uint8>();
114 wzc.data[season].stormChance = fields[season * (MAX_WEATHER_TYPE - 1) + 3].Get<uint8>();
115
116 if (wzc.data[season].rainChance > 100)
117 {
118 wzc.data[season].rainChance = 25;
119 LOG_ERROR("sql.sql", "Weather for zone {} season {} has wrong rain chance > 100%", zone_id, season);
120 }
121
122 if (wzc.data[season].snowChance > 100)
123 {
124 wzc.data[season].snowChance = 25;
125 LOG_ERROR("sql.sql", "Weather for zone {} season {} has wrong snow chance > 100%", zone_id, season);
126 }
127
128 if (wzc.data[season].stormChance > 100)
129 {
130 wzc.data[season].stormChance = 25;
131 LOG_ERROR("sql.sql", "Weather for zone {} season {} has wrong storm chance > 100%", zone_id, season);
132 }
133 }
134
135 wzc.ScriptId = sObjectMgr->GetScriptId(fields[13].Get<std::string>());
136
137 ++count;
138 } while (result->NextRow());
139
140 LOG_INFO("server.loading", ">> Loaded {} Weather Definitions in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
141 LOG_INFO("server.loading", " ");
142 }
std::shared_ptr< ResultSet > QueryResult
Definition DatabaseEnvFwd.h:27
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition DatabaseEnv.cpp:20
std::uint8_t uint8
Definition Define.h:109
std::uint32_t uint32
Definition Define.h:107
#define LOG_INFO(filterType__,...)
Definition Log.h:165
#define LOG_ERROR(filterType__,...)
Definition Log.h:157
#define LOG_WARN(filterType__,...)
Definition Log.h:161
#define sObjectMgr
Definition ObjectMgr.h:1636
#define MAX_WEATHER_TYPE
Definition SharedDefines.h:3146
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:131
uint32 getMSTime()
Definition Timer.h:103
Class used to access individual fields of database query result.
Definition Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition Field.h:112
WeatherSeasonChances data[WEATHER_SEASONS]
Definition Weather.h:40
#define WEATHER_SEASONS
Definition Weather.h:30
uint32 rainChance
Definition Weather.h:33

References WeatherData::data, Field::Get(), getMSTime(), GetMSTimeDiffToNow(), LOG_ERROR, LOG_INFO, LOG_WARN, MAX_WEATHER_TYPE, WeatherSeasonChances::rainChance, sObjectMgr, WEATHER_SEASONS, and WorldDatabase.

Referenced by World::SetInitialWorldSettings().

◆ ReGenerate()

bool Weather::ReGenerate ( )

#include <azerothcore-wotlk/src/server/game/Weather/Weather.h>

Calculate the new weather.

Weather statistics:

  • 30% - no change
  • 30% - weather gets better (if not fine) or change weather type
  • 30% - weather worsens (if not fine)
  • 10% - radical change (if not fine)

Radical change:

  • if light -> heavy
  • if medium -> change weather type
  • if heavy -> 50% light, 50% change weather type

New weather statistics (if not fine):

  • 85% light
  • 7% medium
  • 7% heavy If fine 100% sun (no fog)
68{
70 {
72 m_grade = 0.0f;
73 return false;
74 }
75
81 uint32 u = urand(0, 99);
82
83 if (u < 30)
84 return false;
85
86 // remember old values
87 WeatherType old_type = m_type;
88 float old_grade = m_grade;
89
90 //78 days between January 1st and March 20nd; 365/4=91 days by season
91 // season source http://aa.usno.navy.mil/data/docs/EarthSeasons.html
92 uint32 season = ((Acore::Time::GetDayInYear() - 78 + 365) / 91) % 4;
93
94 static char const* seasonName[WEATHER_SEASONS] = { "spring", "summer", "fall", "winter" };
95 LOG_DEBUG("weather", "Generating a change in {} weather for zone {}.", seasonName[season], m_zone);
96
97 if ((u < 60) && (m_grade < 0.33333334f)) // Get fair
98 {
100 m_grade = 0.0f;
101 }
102
103 if ((u < 60) && (m_type != WEATHER_TYPE_FINE)) // Get better
104 {
105 m_grade -= 0.33333334f;
106 return true;
107 }
108
109 if ((u < 90) && (m_type != WEATHER_TYPE_FINE)) // Get worse
110 {
111 m_grade += 0.33333334f;
112 return true;
113 }
114
116 {
121
122 if (m_grade < 0.33333334f)
123 {
124 m_grade = 0.9999f; // go nuts
125 return true;
126 }
127 else
128 {
129 if (m_grade > 0.6666667f)
130 {
131 // Severe change, but how severe?
132 uint32 rnd = urand(0, 99);
133 if (rnd < 50)
134 {
135 m_grade -= 0.6666667f;
136 return true;
137 }
138 }
139 m_type = WEATHER_TYPE_FINE; // clear up
140 m_grade = 0;
141 }
142 }
143
144 // At this point, only weather that isn't doing anything remains but that have weather data
145 uint32 chance1 = m_weatherChances->data[season].rainChance;
146 uint32 chance2 = chance1 + m_weatherChances->data[season].snowChance;
147 uint32 chance3 = chance2 + m_weatherChances->data[season].stormChance;
148
149 uint32 rnd = urand(1, 100);
150 if (rnd <= chance1)
152 else if (rnd <= chance2)
154 else if (rnd <= chance3)
156 else
158
164
166 {
167 m_grade = 0.0f;
168 }
169 else if (u < 90)
170 {
171 m_grade = (float)rand_norm() * 0.3333f;
172 }
173 else
174 {
175 // Severe change, but how severe?
176 rnd = urand(0, 99);
177 if (rnd < 50)
178 m_grade = (float)rand_norm() * 0.3333f + 0.3334f;
179 else
180 m_grade = (float)rand_norm() * 0.3333f + 0.6667f;
181 }
182
183 // return true only in case weather changes
184 return m_type != old_type || m_grade != old_grade;
185}
#define LOG_DEBUG(filterType__,...)
Definition Log.h:169
uint32 urand(uint32 min, uint32 max)
Definition Random.cpp:44
double rand_norm()
Definition Random.cpp:77
WeatherType
Definition SharedDefines.h:3137
uint32 snowChance
Definition Weather.h:34
uint32 stormChance
Definition Weather.h:35
AC_COMMON_API uint32 GetDayInYear(Seconds time=0s)
Definition Timer.cpp:414

References WeatherData::data, Acore::Time::GetDayInYear(), LOG_DEBUG, Weather::m_grade, Weather::m_type, Weather::m_weatherChances, Weather::m_zone, WeatherSeasonChances::rainChance, rand_norm(), WeatherSeasonChances::snowChance, WeatherSeasonChances::stormChance, urand(), WEATHER_SEASONS, WEATHER_TYPE_FINE, WEATHER_TYPE_RAIN, WEATHER_TYPE_SNOW, and WEATHER_TYPE_STORM.

Referenced by WeatherMgr::AddWeather(), and Weather::Update().

◆ RemoveWeather()

void WeatherMgr::RemoveWeather ( uint32  id)

#include <azerothcore-wotlk/src/server/game/Weather/WeatherMgr.cpp>

Remove a Weather object for the given zoneid.

57 {
58 // not called at the moment. Kept for completeness
59 WeatherMap::iterator itr = m_weathers.find(id);
60
61 if (itr != m_weathers.end())
62 m_weathers.erase(itr);
63 }

◆ SendFineWeatherUpdateToPlayer()

void WeatherMgr::SendFineWeatherUpdateToPlayer ( Player player)

#include <azerothcore-wotlk/src/server/game/Weather/WeatherMgr.cpp>

145 {
147 player->SendDirectMessage(weather.Write());
148 }
void SendDirectMessage(WorldPacket const *data) const
Definition Player.cpp:5733
Definition MiscPackets.h:32

References Player::SendDirectMessage(), WEATHER_STATE_FINE, and WorldPackets::Misc::Weather::Write().

Referenced by Player::UpdateZone().

◆ SendWeatherUpdateToPlayer()

void Weather::SendWeatherUpdateToPlayer ( Player player)

#include <azerothcore-wotlk/src/server/game/Weather/Weather.h>

188{
190 player->SendDirectMessage(weather.Write());
191}
WeatherState GetWeatherState() const
Get the sound number associated with the current weather.
Definition Weather.cpp:273

References Weather::GetWeatherState(), Weather::m_grade, Player::SendDirectMessage(), and WorldPackets::Misc::Weather::Write().

◆ SetWeather()

void Weather::SetWeather ( WeatherType  type,
float  grade 
)

#include <azerothcore-wotlk/src/server/game/Weather/Weather.h>

Set the weather.

263{
264 if (m_type == type && m_grade == grade)
265 return;
266
267 m_type = type;
268 m_grade = grade;
270}

References Weather::m_grade, Weather::m_type, and Weather::UpdateWeather().

Referenced by misc_commandscript::HandleChangeWeather().

◆ Update() [1/2]

bool Weather::Update ( uint32  diff)

#include <azerothcore-wotlk/src/server/game/Weather/Weather.h>

Launch a weather update.

  • If the timer has passed, ReGenerate the weather
  • Weather will be removed if not updated (no players in zone anymore)
43{
44 if (m_timer.GetCurrent() >= 0)
45 m_timer.Update(diff);
46 else
48
50 if (m_timer.Passed())
51 {
52 m_timer.Reset();
53 // update only if Regenerate has changed the weather
54 if (ReGenerate())
55 {
57 if (!UpdateWeather())
58 return false;
59 }
60 }
61
62 sScriptMgr->OnWeatherUpdate(this, diff);
63 return true;
64}
#define sScriptMgr
Definition ScriptMgr.h:727
IntervalTimer m_timer
Definition Weather.h:85
time_t GetCurrent() const
Definition Timer.h:189
bool Passed()
Definition Timer.h:161
void Update(time_t diff)
Definition Timer.h:152
void SetCurrent(time_t current)
Definition Timer.h:174
void Reset()
Definition Timer.h:166

References IntervalTimer::GetCurrent(), Weather::m_timer, IntervalTimer::Passed(), Weather::ReGenerate(), IntervalTimer::Reset(), IntervalTimer::SetCurrent(), sScriptMgr, IntervalTimer::Update(), and Weather::UpdateWeather().

◆ Update() [2/2]

void WeatherMgr::Update ( uint32  diff)

#include <azerothcore-wotlk/src/server/game/Weather/WeatherMgr.cpp>

  • Send an update signal to Weather objects
  • and remove Weather objects for zones with no player
151 {
153 WeatherMap::iterator itr, next;
154 for (itr = m_weathers.begin(); itr != m_weathers.end(); itr = next)
155 {
156 next = itr;
157 ++next;
158
160 // As interval > WorldTick
161 if (!itr->second->Update(diff))
162 m_weathers.erase(itr);
163 }
164 }

Referenced by World::Update().

◆ UpdateWeather()

bool Weather::UpdateWeather ( )

#include <azerothcore-wotlk/src/server/game/Weather/Weather.h>

Send the new weather to all players in the zone.

  • Send the weather packet to all players in this zone
  • Log the event
195{
197 if (m_grade >= 1)
198 m_grade = 0.9999f;
199 else if (m_grade < 0)
200 m_grade = 0.0001f;
201
203
204 WorldPackets::Misc::Weather weather(state, m_grade);
205
206 //- Returns false if there were no players found to update
207 if (!sWorldSessionMgr->SendZoneMessage(m_zone, weather.Write()))
208 return false;
209
211 char const* wthstr;
212 switch (state)
213 {
215 wthstr = "fog";
216 break;
218 wthstr = "light rain";
219 break;
221 wthstr = "medium rain";
222 break;
224 wthstr = "heavy rain";
225 break;
227 wthstr = "light snow";
228 break;
230 wthstr = "medium snow";
231 break;
233 wthstr = "heavy snow";
234 break;
236 wthstr = "light sandstorm";
237 break;
239 wthstr = "medium sandstorm";
240 break;
242 wthstr = "heavy sandstorm";
243 break;
245 wthstr = "thunders";
246 break;
248 wthstr = "blackrain";
249 break;
251 default:
252 wthstr = "fine";
253 break;
254 }
255
256 LOG_DEBUG("weather", "Change the weather of zone {} to {}.", m_zone, wthstr);
257 sScriptMgr->OnWeatherChange(this, state, m_grade);
258 return true;
259}
#define sWorldSessionMgr
Definition WorldSessionMgr.h:110
WeatherState
Definition Weather.h:45

References Weather::GetWeatherState(), LOG_DEBUG, Weather::m_grade, Weather::m_zone, sScriptMgr, sWorldSessionMgr, WEATHER_STATE_BLACKRAIN, WEATHER_STATE_FINE, WEATHER_STATE_FOG, WEATHER_STATE_HEAVY_RAIN, WEATHER_STATE_HEAVY_SANDSTORM, WEATHER_STATE_HEAVY_SNOW, WEATHER_STATE_LIGHT_RAIN, WEATHER_STATE_LIGHT_SANDSTORM, WEATHER_STATE_LIGHT_SNOW, WEATHER_STATE_MEDIUM_RAIN, WEATHER_STATE_MEDIUM_SANDSTORM, WEATHER_STATE_MEDIUM_SNOW, WEATHER_STATE_THUNDERS, and WorldPackets::Misc::Weather::Write().

Referenced by WeatherMgr::AddWeather(), Weather::SetWeather(), and Weather::Update().

◆ Weather()

Weather::Weather ( uint32  zone,
WeatherData const *  weatherChances 
)

#include <azerothcore-wotlk/src/server/game/Weather/Weather.h>

Create the Weather object.

32 : m_zone(zone), m_weatherChances(weatherChances)
33{
36 m_grade = 0;
37
38 LOG_DEBUG("weather", "WORLD: Starting weather system for zone {} (change every {} minutes).", m_zone, (uint32)(m_timer.GetInterval() / (MINUTE * IN_MILLISECONDS)));
39}
constexpr auto IN_MILLISECONDS
Definition Common.h:53
constexpr auto MINUTE
Definition Common.h:47
@ CONFIG_INTERVAL_CHANGEWEATHER
Definition IWorld.h:211
#define sWorld
Definition World.h:363
void SetInterval(time_t interval)
Definition Timer.h:179
time_t GetInterval() const
Definition Timer.h:184

References CONFIG_INTERVAL_CHANGEWEATHER, IntervalTimer::GetInterval(), IN_MILLISECONDS, LOG_DEBUG, Weather::m_grade, Weather::m_timer, Weather::m_type, Weather::m_zone, MINUTE, IntervalTimer::SetInterval(), sWorld, and WEATHER_TYPE_FINE.

◆ ~Weather()

Weather::~Weather ( )
default

Variable Documentation

◆ data

◆ m_grade

◆ m_timer

IntervalTimer Weather::m_timer
private

◆ m_type

◆ m_weatherChances

WeatherData const* Weather::m_weatherChances
private

◆ m_zone

◆ rainChance

uint32 WeatherSeasonChances::rainChance

◆ realm

◆ ScriptId

uint32 WeatherData::ScriptId

Referenced by Weather::GetScriptId().

◆ snowChance

uint32 WeatherSeasonChances::snowChance

Referenced by Weather::ReGenerate().

◆ stormChance

uint32 WeatherSeasonChances::stormChance

Referenced by Weather::ReGenerate().