Core/Weather: merged commit 6eb997394722fcd4b5248646b5abfa185a7ec58f

This commit is contained in:
Ovalord committed 2018-02-14 15:49:48 +01:00
1 parent 844450d542
commit dc8f263fc8
12 files changed
+106 -141

No files matched your search

+6 -70
View File
@@ -21,63 +21,24 @@
*/
#include "WeatherMgr.h"
#include "Containers.h"
#include "Weather.h"
#include "Log.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "Timer.h"
#include "Opcodes.h"
#include "WorldSession.h"
namespace WeatherMgr
{
namespace
{
typedef std::unordered_map<uint32, std::shared_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 : NULL;
}
std::unordered_map<uint32, WeatherData> _weatherData;
}
/// Find a Weather object by the given zoneid
Weather* FindWeather(uint32 id)
WeatherData const* GetWeatherData(uint32 zone_id)
{
WeatherMap::const_iterator itr = m_weathers.find(id);
return (itr != m_weathers.end()) ? itr->second.get() : nullptr;
}
/// 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);
}
/// Add a Weather object to the list
Weather* AddWeather(uint32 zone_id)
{
WeatherData const* weatherChances = GetWeatherData(zone_id);
// zone does not have weather, ignore
if (!weatherChances)
return NULL;
Weather* w = new Weather(zone_id, weatherChances);
m_weathers[w->GetZone()].reset(w);
w->ReGenerate();
w->UpdateWeather();
return w;
return Trinity::Containers::MapGetValuePtr(_weatherData, zone_id);
}
void LoadWeatherData()
@@ -105,7 +66,7 @@ void LoadWeatherData()
uint32 zone_id = fields[0].GetUInt32();
WeatherData& wzc = mWeatherZoneMap[zone_id];
WeatherData& wzc = _weatherData[zone_id];
for (uint8 season = 0; season < WEATHER_SEASONS; ++season)
{
@@ -141,29 +102,4 @@ void LoadWeatherData()
TC_LOG_INFO("server.loading", ">> Loaded %u weather definitions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
}
void SendFineWeatherUpdateToPlayer(Player* player)
{
WorldPacket data(SMSG_WEATHER, (4 + 4 + 1));
data << (uint32)WEATHER_STATE_FINE;
data << (float)0.0f;
data << uint8(0);
player->GetSession()->SendPacket(&data);
}
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