diff options
Diffstat (limited to 'src/server/game/Weather')
| -rw-r--r-- | src/server/game/Weather/Weather.cpp | 24 | ||||
| -rw-r--r-- | src/server/game/Weather/Weather.h | 15 | ||||
| -rw-r--r-- | src/server/game/Weather/WeatherMgr.cpp | 87 | ||||
| -rw-r--r-- | src/server/game/Weather/WeatherMgr.h | 21 |
4 files changed, 44 insertions, 103 deletions
diff --git a/src/server/game/Weather/Weather.cpp b/src/server/game/Weather/Weather.cpp index bc22e7db66..ee4fbb85aa 100644 --- a/src/server/game/Weather/Weather.cpp +++ b/src/server/game/Weather/Weather.cpp @@ -1,14 +1,14 @@ /* * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by the - * Free Software Foundation; either version 3 of the License, or (at your - * option) any later version. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along @@ -20,16 +20,16 @@ */ #include "Weather.h" +#include "Map.h" #include "MiscPackets.h" #include "Player.h" #include "ScriptMgr.h" #include "Util.h" #include "World.h" -#include "WorldSessionMgr.h" /// Create the Weather object -Weather::Weather(uint32 zone, WeatherData const* weatherChances) - : m_zone(zone), m_weatherChances(weatherChances) +Weather::Weather(Map* map, uint32 zone, WeatherData const* weatherChances) + : m_map(map), m_zone(zone), m_weatherChances(weatherChances) { m_timer.SetInterval(sWorld->getIntConfig(CONFIG_INTERVAL_CHANGEWEATHER)); m_type = WEATHER_TYPE_FINE; @@ -190,6 +190,12 @@ void Weather::SendWeatherUpdateToPlayer(Player* player) player->SendDirectMessage(weather.Write()); } +void Weather::SendFineWeatherUpdateToPlayer(Player* player) +{ + WorldPackets::Misc::Weather weather(WEATHER_STATE_FINE); + player->SendDirectMessage(weather.Write()); +} + /// Send the new weather to all players in the zone bool Weather::UpdateWeather() { @@ -204,7 +210,7 @@ bool Weather::UpdateWeather() WorldPackets::Misc::Weather weather(state, m_grade); //- Returns false if there were no players found to update - if (!sWorldSessionMgr->SendZoneMessage(m_zone, weather.Write())) + if (!m_map->SendZoneMessage(m_zone, weather.Write())) return false; ///- Log the event diff --git a/src/server/game/Weather/Weather.h b/src/server/game/Weather/Weather.h index 9bba945272..8f4b5c866e 100644 --- a/src/server/game/Weather/Weather.h +++ b/src/server/game/Weather/Weather.h @@ -1,14 +1,14 @@ /* * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by the - * Free Software Foundation; either version 3 of the License, or (at your - * option) any later version. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along @@ -25,6 +25,7 @@ #include "SharedDefines.h" #include "Timer.h" +class Map; class Player; #define WEATHER_SEASONS 4 @@ -63,7 +64,7 @@ enum WeatherState : uint32 class Weather { public: - Weather(uint32 zone, WeatherData const* weatherChances); + Weather(Map* map, uint32 zone, WeatherData const* weatherChances); ~Weather() = default; bool Update(uint32 diff); @@ -71,6 +72,7 @@ public: bool UpdateWeather(); void SendWeatherUpdateToPlayer(Player* player); + static void SendFineWeatherUpdateToPlayer(Player* player); void SetWeather(WeatherType type, float grade); /// For which zone is this weather? @@ -79,6 +81,7 @@ public: private: [[nodiscard]] WeatherState GetWeatherState() const; + Map* m_map; uint32 m_zone; WeatherType m_type; float m_grade; diff --git a/src/server/game/Weather/WeatherMgr.cpp b/src/server/game/Weather/WeatherMgr.cpp index f7b98911e4..bf4bd05e74 100644 --- a/src/server/game/Weather/WeatherMgr.cpp +++ b/src/server/game/Weather/WeatherMgr.cpp @@ -1,14 +1,14 @@ /* * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by the - * Free Software Foundation; either version 3 of the License, or (at your - * option) any later version. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along @@ -20,63 +20,25 @@ */ #include "WeatherMgr.h" +#include "Containers.h" +#include "DatabaseEnv.h" #include "Log.h" -#include "MiscPackets.h" #include "ObjectMgr.h" -#include "Player.h" +#include "QueryResult.h" +#include "Timer.h" #include "Weather.h" -#include "WorldSession.h" namespace WeatherMgr { namespace { - typedef std::unordered_map<uint32, std::unique_ptr<Weather>> WeatherMap; - typedef std::unordered_map<uint32, WeatherData> WeatherZoneMap; - - WeatherMap m_weathers; - WeatherZoneMap mWeatherZoneMap; - - WeatherData const* GetWeatherData(uint32 zone_id) - { - WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id); - return (itr != mWeatherZoneMap.end()) ? &itr->second : nullptr; - } - } - - /// Find a Weather object by the given zoneid - Weather* FindWeather(uint32 id) - { - WeatherMap::const_iterator itr = m_weathers.find(id); - return (itr != m_weathers.end()) ? itr->second.get() : 0; - } - - /// Remove a Weather object for the given zoneid - void RemoveWeather(uint32 id) - { - // not called at the moment. Kept for completeness - WeatherMap::iterator itr = m_weathers.find(id); - - if (itr != m_weathers.end()) - m_weathers.erase(itr); + std::unordered_map<uint32, WeatherData> _weatherData; } - /// Add a Weather object to the list - Weather* AddWeather(uint32 zone_id) + WeatherData const* GetWeatherData(uint32 zone_id) { - WeatherData const* weatherChances = GetWeatherData(zone_id); - - // zone does not have weather, ignore - if (!weatherChances) - return nullptr; - - Weather* w = new Weather(zone_id, weatherChances); - m_weathers[w->GetZone()].reset(w); - w->ReGenerate(); - w->UpdateWeather(); - - return w; + return Acore::Containers::MapGetValuePtr(_weatherData, zone_id); } void LoadWeatherData() @@ -105,7 +67,7 @@ namespace WeatherMgr uint32 zone_id = fields[0].Get<uint32>(); - WeatherData& wzc = mWeatherZoneMap[zone_id]; + WeatherData& wzc = _weatherData[zone_id]; for (uint8 season = 0; season < WEATHER_SEASONS; ++season) { @@ -140,27 +102,4 @@ namespace WeatherMgr LOG_INFO("server.loading", ">> Loaded {} Weather Definitions in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); LOG_INFO("server.loading", " "); } - - void SendFineWeatherUpdateToPlayer(Player* player) - { - WorldPackets::Misc::Weather weather(WEATHER_STATE_FINE); - player->SendDirectMessage(weather.Write()); - } - - void Update(uint32 diff) - { - ///- Send an update signal to Weather objects - WeatherMap::iterator itr, next; - for (itr = m_weathers.begin(); itr != m_weathers.end(); itr = next) - { - next = itr; - ++next; - - ///- and remove Weather objects for zones with no player - // As interval > WorldTick - if (!itr->second->Update(diff)) - m_weathers.erase(itr); - } - } - } // namespace diff --git a/src/server/game/Weather/WeatherMgr.h b/src/server/game/Weather/WeatherMgr.h index 046934d8b2..0d87a7cf4d 100644 --- a/src/server/game/Weather/WeatherMgr.h +++ b/src/server/game/Weather/WeatherMgr.h @@ -1,14 +1,14 @@ /* * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by the - * Free Software Foundation; either version 3 of the License, or (at your - * option) any later version. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along @@ -25,19 +25,12 @@ #include "Define.h" class Weather; -class Player; +struct WeatherData; namespace WeatherMgr { void LoadWeatherData(); - - Weather* FindWeather(uint32 id); - Weather* AddWeather(uint32 zone_id); - void RemoveWeather(uint32 zone_id); - - void SendFineWeatherUpdateToPlayer(Player* player); - - void Update(uint32 diff); + WeatherData const* GetWeatherData(uint32 zone_id); } #endif |
