TrinityCore
Loading...
Searching...
No Matches
WeatherMgr.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
22#include "WeatherMgr.h"
23#include "Containers.h"
24#include "DatabaseEnv.h"
25#include "Log.h"
26#include "ObjectMgr.h"
27#include "Timer.h"
28#include "Weather.h"
29#include "MiscPackets.h"
30
31namespace WeatherMgr
32{
33
34namespace
35{
36 std::unordered_map<uint32, WeatherData> _weatherData;
37}
38
40{
41 return Trinity::Containers::MapGetValuePtr(_weatherData, zone_id);
42}
43
45{
46 uint32 oldMSTime = getMSTime();
47
48 uint32 count = 0;
49
50 QueryResult result = WorldDatabase.Query("SELECT "
51 "zone, spring_rain_chance, spring_snow_chance, spring_storm_chance,"
52 "summer_rain_chance, summer_snow_chance, summer_storm_chance,"
53 "fall_rain_chance, fall_snow_chance, fall_storm_chance,"
54 "winter_rain_chance, winter_snow_chance, winter_storm_chance,"
55 "ScriptName FROM game_weather");
56
57 if (!result)
58 {
59 TC_LOG_INFO("server.loading", ">> Loaded 0 weather definitions. DB table `game_weather` is empty.");
60 return;
61 }
62
63 do
64 {
65 Field* fields = result->Fetch();
66
67 uint32 zone_id = fields[0].GetUInt32();
68
69 WeatherData& wzc = _weatherData[zone_id];
70
71 for (uint8 season = 0; season < WEATHER_SEASONS; ++season)
72 {
73 wzc.data[season].rainChance = fields[season * (MAX_WEATHER_TYPE-1) + 1].GetUInt8();
74 wzc.data[season].snowChance = fields[season * (MAX_WEATHER_TYPE-1) + 2].GetUInt8();
75 wzc.data[season].stormChance = fields[season * (MAX_WEATHER_TYPE-1) + 3].GetUInt8();
76
77 if (wzc.data[season].rainChance > 100)
78 {
79 wzc.data[season].rainChance = 25;
80 TC_LOG_ERROR("sql.sql", "Weather for zone {} season {} has wrong rain chance > 100%", zone_id, season);
81 }
82
83 if (wzc.data[season].snowChance > 100)
84 {
85 wzc.data[season].snowChance = 25;
86 TC_LOG_ERROR("sql.sql", "Weather for zone {} season {} has wrong snow chance > 100%", zone_id, season);
87 }
88
89 if (wzc.data[season].stormChance > 100)
90 {
91 wzc.data[season].stormChance = 25;
92 TC_LOG_ERROR("sql.sql", "Weather for zone {} season {} has wrong storm chance > 100%", zone_id, season);
93 }
94 }
95
96 wzc.ScriptId = sObjectMgr->GetScriptId(fields[13].GetString());
97
98 ++count;
99 }
100 while (result->NextRow());
101
102 TC_LOG_INFO("server.loading", ">> Loaded {} weather definitions in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
103}
104
105} // namespace
std::shared_ptr< ResultSet > QueryResult
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
#define TC_LOG_ERROR(filterType__,...)
Definition Log.h:165
#define TC_LOG_INFO(filterType__,...)
Definition Log.h:159
#define sObjectMgr
Definition ObjectMgr.h:1721
#define MAX_WEATHER_TYPE
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:57
uint32 getMSTime()
Definition Timer.h:33
Class used to access individual fields of database query result.
Definition Field.h:92
uint32 GetUInt32() const
Definition Field.cpp:61
void LoadWeatherData()
WeatherSeasonChances data[WEATHER_SEASONS]
Definition Weather.h:42
#define WEATHER_SEASONS
Definition Weather.h:32
uint32 ScriptId
Definition Weather.h:43
WeatherData const * GetWeatherData(uint32 zone_id)
auto MapGetValuePtr(M &map, typename M::key_type const &key)
Definition MapUtils.h:29