diff options
-rw-r--r-- | src/server/game/Chat/Commands/Level3.cpp | 5 | ||||
-rw-r--r-- | src/server/game/Entities/Player/Player.cpp | 5 | ||||
-rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 63 | ||||
-rw-r--r-- | src/server/game/Globals/ObjectMgr.h | 15 | ||||
-rw-r--r-- | src/server/game/Weather/WeatherMgr.cpp | 160 | ||||
-rw-r--r-- | src/server/game/Weather/WeatherMgr.h | 69 | ||||
-rw-r--r-- | src/server/game/World/World.cpp | 67 | ||||
-rw-r--r-- | src/server/game/World/World.h | 6 |
8 files changed, 238 insertions, 152 deletions
diff --git a/src/server/game/Chat/Commands/Level3.cpp b/src/server/game/Chat/Commands/Level3.cpp index 93c9ad2ea76..57813285632 100644 --- a/src/server/game/Chat/Commands/Level3.cpp +++ b/src/server/game/Chat/Commands/Level3.cpp @@ -57,6 +57,7 @@ #include "ConditionMgr.h" #include "DisableMgr.h" #include "Transport.h" +#include "WeatherMgr.h" //reload commands bool ChatHandler::HandleReloadAllCommand(const char*) @@ -4656,10 +4657,10 @@ bool ChatHandler::HandleChangeWeather(const char *args) Player *player = m_session->GetPlayer(); uint32 zoneid = player->GetZoneId(); - Weather* wth = sWorld.FindWeather(zoneid); + Weather* wth = sWeatherMgr.FindWeather(zoneid); if (!wth) - wth = sWorld.AddWeather(zoneid); + wth = sWeatherMgr.AddWeather(zoneid); if (!wth) { SendSysMessage(LANG_NO_WEATHER); diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 836c467593f..ccb7f4c37b0 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -68,6 +68,7 @@ #include "SpellAuraEffects.h" #include "ConditionMgr.h" #include "DisableMgr.h" +#include "WeatherMgr.h" #include <cmath> #define ZONE_UPDATE_INTERVAL (1*IN_MILLISECONDS) @@ -6965,12 +6966,12 @@ void Player::UpdateZone(uint32 newZone, uint32 newArea) if (sWorld.getConfig(CONFIG_WEATHER)) { - Weather *wth = sWorld.FindWeather(zone->ID); + Weather *wth = sWeatherMgr.FindWeather(zone->ID); if (wth) wth->SendWeatherUpdateToPlayer(this); else { - if (!sWorld.AddWeather(zone->ID)) + if (!sWeatherMgr.AddWeather(zone->ID)) { // send fine weather packet to remove old zone's weather Weather::SendFineWeatherUpdateToPlayer(this); diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 530a1d5201e..7ed5a5a4103 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -7227,69 +7227,6 @@ void ObjectMgr::LoadNPCSpellClickSpells() sLog.outString(">> Loaded %u spellclick definitions", count); } -void ObjectMgr::LoadWeatherData() -{ - uint32 count = 0; - - // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 - QueryResult_AutoPtr result = WorldDatabase.Query("SELECT zone, spring_rain_chance, spring_snow_chance, spring_storm_chance, summer_rain_chance, summer_snow_chance, summer_storm_chance, fall_rain_chance, fall_snow_chance, fall_storm_chance, winter_rain_chance, winter_snow_chance, winter_storm_chance, ScriptName FROM game_weather"); - - if (!result) - { - barGoLink bar(1); - - bar.step(); - - sLog.outString(); - sLog.outErrorDb(">> Loaded 0 weather definitions. DB table `game_weather` is empty."); - return; - } - - barGoLink bar(result->GetRowCount()); - - do - { - Field *fields = result->Fetch(); - bar.step(); - - uint32 zone_id = fields[0].GetUInt32(); - - WeatherData& wzc = mWeatherZoneMap[zone_id]; - - for (uint8 season = 0; season < WEATHER_SEASONS; ++season) - { - wzc.data[season].rainChance = fields[season * (MAX_WEATHER_TYPE-1) + 1].GetUInt32(); - wzc.data[season].snowChance = fields[season * (MAX_WEATHER_TYPE-1) + 2].GetUInt32(); - wzc.data[season].stormChance = fields[season * (MAX_WEATHER_TYPE-1) + 3].GetUInt32(); - - if (wzc.data[season].rainChance > 100) - { - wzc.data[season].rainChance = 25; - sLog.outErrorDb("Weather for zone %u season %u has wrong rain chance > 100%%",zone_id,season); - } - - if (wzc.data[season].snowChance > 100) - { - wzc.data[season].snowChance = 25; - sLog.outErrorDb("Weather for zone %u season %u has wrong snow chance > 100%%",zone_id,season); - } - - if (wzc.data[season].stormChance > 100) - { - wzc.data[season].stormChance = 25; - sLog.outErrorDb("Weather for zone %u season %u has wrong storm chance > 100%%",zone_id,season); - } - } - - wzc.ScriptId = objmgr.GetScriptId(fields[13].GetString()); - - ++count; - } while (result->NextRow()); - - sLog.outString(); - sLog.outString(">> Loaded %u weather definitions", count); -} - void ObjectMgr::SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t) { mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)] = t; diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index 05c4ba43223..0715375c615 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -40,7 +40,6 @@ #include "ace/Singleton.h" #include "SQLStorage.h" #include "Vehicle.h" -#include "Weather.h" #include "ObjectMgr.h" #include <string> #include <map> @@ -385,8 +384,6 @@ class ObjectMgr typedef UNORDERED_MAP<uint32, PointOfInterest> PointOfInterestMap; - typedef UNORDERED_MAP<uint32, WeatherData> WeatherZoneMap; - typedef std::vector<std::string> ScriptNameMap; Player* GetPlayer(const char* name) const { return sObjectAccessor.FindPlayerByName(name);} @@ -675,7 +672,6 @@ class ObjectMgr void LoadNPCSpellClickSpells(); - void LoadWeatherData(); void LoadGameTele(); void LoadNpcTextId(); @@ -728,15 +724,6 @@ class ObjectMgr return NULL; } - WeatherData const* GetWeatherChances(uint32 zone_id) const - { - WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id); - if (itr != mWeatherZoneMap.end()) - return &itr->second; - else - return NULL; - } - CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id) { return mMapObjectGuids[MAKE_PAIR32(mapid,spawnMode)][cell_id]; @@ -1022,8 +1009,6 @@ class ObjectMgr QuestPOIMap mQuestPOIMap; - WeatherZoneMap mWeatherZoneMap; - //character reserved names typedef std::set<std::wstring> ReservedNamesMap; ReservedNamesMap m_ReservedNames; diff --git a/src/server/game/Weather/WeatherMgr.cpp b/src/server/game/Weather/WeatherMgr.cpp new file mode 100644 index 00000000000..9aa193bdcbc --- /dev/null +++ b/src/server/game/Weather/WeatherMgr.cpp @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> + * + * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/** \file + \ingroup world +*/ + +#include "WeatherMgr.h" +#include "Log.h" +#include "ProgressBar.h" +#include "ObjectMgr.h" + +WeatherMgr::~WeatherMgr() +{ + ///- Empty the WeatherMap + for (WeatherMap::const_iterator itr = m_weathers.begin(); itr != m_weathers.end(); ++itr) + delete itr->second; + + m_weathers.clear(); +} + +/// Find a Weather object by the given zoneid +Weather* WeatherMgr::FindWeather(uint32 id) const +{ + WeatherMap::const_iterator itr = m_weathers.find(id); + + if (itr != m_weathers.end()) + return itr->second; + else + return 0; +} + +/// Remove a Weather object for the given zoneid +void WeatherMgr::RemoveWeather(uint32 id) +{ + // not called at the moment. Kept for completeness + WeatherMap::iterator itr = m_weathers.find(id); + + if (itr != m_weathers.end()) + { + delete itr->second; + m_weathers.erase(itr); + } +} + +/// Add a Weather object to the list +Weather* WeatherMgr::AddWeather(uint32 zone_id) +{ + WeatherData const* weatherChances = GetWeatherChances(zone_id); + + // zone not have weather, ignore + if (!weatherChances) + return NULL; + + Weather* w = new Weather(zone_id,weatherChances); + m_weathers[w->GetZone()] = w; + w->ReGenerate(); + w->UpdateWeather(); + return w; +} + +void WeatherMgr::LoadWeatherData() +{ + uint32 count = 0; + + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 + QueryResult_AutoPtr result = WorldDatabase.Query("SELECT zone, spring_rain_chance, spring_snow_chance, spring_storm_chance, summer_rain_chance, summer_snow_chance, summer_storm_chance, fall_rain_chance, fall_snow_chance, fall_storm_chance, winter_rain_chance, winter_snow_chance, winter_storm_chance, ScriptName FROM game_weather"); + + if (!result) + { + barGoLink bar(1); + + bar.step(); + + sLog.outString(); + sLog.outErrorDb(">> Loaded 0 weather definitions. DB table `game_weather` is empty."); + return; + } + + barGoLink bar(result->GetRowCount()); + + do + { + Field *fields = result->Fetch(); + bar.step(); + + uint32 zone_id = fields[0].GetUInt32(); + + WeatherData& wzc = mWeatherZoneMap[zone_id]; + + for (uint8 season = 0; season < WEATHER_SEASONS; ++season) + { + wzc.data[season].rainChance = fields[season * (MAX_WEATHER_TYPE-1) + 1].GetUInt32(); + wzc.data[season].snowChance = fields[season * (MAX_WEATHER_TYPE-1) + 2].GetUInt32(); + wzc.data[season].stormChance = fields[season * (MAX_WEATHER_TYPE-1) + 3].GetUInt32(); + + if (wzc.data[season].rainChance > 100) + { + wzc.data[season].rainChance = 25; + sLog.outErrorDb("Weather for zone %u season %u has wrong rain chance > 100%%",zone_id,season); + } + + if (wzc.data[season].snowChance > 100) + { + wzc.data[season].snowChance = 25; + sLog.outErrorDb("Weather for zone %u season %u has wrong snow chance > 100%%",zone_id,season); + } + + if (wzc.data[season].stormChance > 100) + { + wzc.data[season].stormChance = 25; + sLog.outErrorDb("Weather for zone %u season %u has wrong storm chance > 100%%",zone_id,season); + } + } + + wzc.ScriptId = objmgr.GetScriptId(fields[13].GetString()); + + ++count; + } + while (result->NextRow()); + + sLog.outString(); + sLog.outString(">> Loaded %u weather definitions", count); +} + +void WeatherMgr::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)) + { + delete itr->second; + m_weathers.erase(itr); + } + } +} diff --git a/src/server/game/Weather/WeatherMgr.h b/src/server/game/Weather/WeatherMgr.h new file mode 100644 index 00000000000..5751e68a563 --- /dev/null +++ b/src/server/game/Weather/WeatherMgr.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> + * + * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/// \addtogroup world +/// @{ +/// \file + +#ifndef __WEATHERMGR_H +#define __WEATHERMGR_H + +#include "Common.h" +#include "SharedDefines.h" +#include "Timer.h" +#include "Weather.h" + +class WeatherMgr +{ + friend class ACE_Singleton<WeatherMgr, ACE_Null_Mutex>; + WeatherMgr() {} + ~WeatherMgr(); + + public: + + void LoadWeatherData(); + + Weather* FindWeather(uint32 id) const; + Weather* AddWeather(uint32 zone_id); + void RemoveWeather(uint32 zone_id); + + WeatherData const* GetWeatherChances(uint32 zone_id) const + { + WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id); + if (itr != mWeatherZoneMap.end()) + return &itr->second; + else + return NULL; + } + + void Update(uint32 diff); + + typedef UNORDERED_MAP<uint32, Weather*> WeatherMap; + typedef UNORDERED_MAP<uint32, WeatherData> WeatherZoneMap; + + private: + + WeatherMap m_weathers; + WeatherZoneMap mWeatherZoneMap; +}; + +#define sWeatherMgr (*ACE_Singleton<WeatherMgr, ACE_Null_Mutex>::instance()) + +#endif diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index b4c0413b98e..f9bc9eb74b8 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -30,7 +30,6 @@ #include "Opcodes.h" #include "WorldSession.h" #include "WorldPacket.h" -#include "Weather.h" #include "Player.h" #include "Vehicle.h" #include "SkillExtraItems.h" @@ -71,6 +70,7 @@ #include "DisableMgr.h" #include "CharacterDatabaseCleaner.h" #include "ScriptMgr.h" +#include "WeatherMgr.h" volatile bool World::m_stopEvent = false; uint8 World::m_ExitCode = SHUTDOWN_EXIT_CODE; @@ -128,12 +128,6 @@ World::~World() m_sessions.erase(m_sessions.begin()); } - ///- Empty the WeatherMap - for (WeatherMap::const_iterator itr = m_weathers.begin(); itr != m_weathers.end(); ++itr) - delete itr->second; - - m_weathers.clear(); - CliCommandHolder* command; while (cliCmdQueue.next(command)) delete command; @@ -416,46 +410,6 @@ bool World::RemoveQueuedPlayer(WorldSession* sess) return found; } -/// Find a Weather object by the given zoneid -Weather* World::FindWeather(uint32 id) const -{ - WeatherMap::const_iterator itr = m_weathers.find(id); - - if (itr != m_weathers.end()) - return itr->second; - else - return 0; -} - -/// Remove a Weather object for the given zoneid -void World::RemoveWeather(uint32 id) -{ - // not called at the moment. Kept for completeness - WeatherMap::iterator itr = m_weathers.find(id); - - if (itr != m_weathers.end()) - { - delete itr->second; - m_weathers.erase(itr); - } -} - -/// Add a Weather object to the list -Weather* World::AddWeather(uint32 zone_id) -{ - WeatherData const* weatherChances = objmgr.GetWeatherChances(zone_id); - - // zone not have weather, ignore - if (!weatherChances) - return NULL; - - Weather* w = new Weather(zone_id,weatherChances); - m_weathers[w->GetZone()] = w; - w->ReGenerate(); - w->UpdateWeather(); - return w; -} - /// Initialize config values void World::LoadConfigSettings(bool reload) { @@ -1456,7 +1410,7 @@ void World::SetInitialWorldSettings() gameeventmgr.LoadFromDB(); sLog.outString("Loading Weather Data..."); - objmgr.LoadWeatherData(); + sWeatherMgr.LoadWeatherData(); sLog.outString("Loading Quests..."); objmgr.LoadQuests(); // must be loaded after DBCs, creature_template, item_template, gameobject tables @@ -1939,22 +1893,7 @@ void World::Update(uint32 diff) if (m_timers[WUPDATE_WEATHERS].Passed()) { m_timers[WUPDATE_WEATHERS].Reset(); - - ///- 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(m_timers[WUPDATE_WEATHERS].GetInterval())) - { - delete itr->second; - m_weathers.erase(itr); - } - } + sWeatherMgr.Update(m_timers[WUPDATE_WEATHERS].GetInterval()); } /// <li> Update uptime table diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h index 5742741db07..4255d0407f9 100644 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -40,7 +40,6 @@ class Object; class WorldPacket; class WorldSession; class Player; -class Weather; struct ScriptAction; struct ScriptInfo; class SqlResultQueue; @@ -520,9 +519,6 @@ class World inline void DecreasePlayerCount() { m_PlayerCount--; } Player* FindPlayerInZone(uint32 zone); - Weather* FindWeather(uint32 id) const; - Weather* AddWeather(uint32 zone_id); - void RemoveWeather(uint32 zone_id); /// Deny clients? bool IsClosed() const; @@ -724,8 +720,6 @@ class World uint32 m_updateTimeCount; uint32 m_currentTime; - typedef UNORDERED_MAP<uint32, Weather*> WeatherMap; - WeatherMap m_weathers; typedef UNORDERED_MAP<uint32, WorldSession*> SessionMap; SessionMap m_sessions; typedef UNORDERED_MAP<uint32, time_t> DisconnectMap; |