refactor(Core/Game): restyle game lib with astyle (#3466)

This commit is contained in:
Kargatum
2020-10-12 15:08:15 +07:00
committed by GitHub
parent e99b526e17
commit a2b26272d2
338 changed files with 52196 additions and 50944 deletions

View File

@@ -27,7 +27,7 @@ Weather::Weather(uint32 zone, WeatherData const* weatherChances)
m_grade = 0;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDetail("WORLD: Starting weather system for zone %u (change every %u minutes).", m_zone, (uint32)(m_timer.GetInterval() / (MINUTE*IN_MILLISECONDS)));
sLog->outDetail("WORLD: Starting weather system for zone %u (change every %u minutes).", m_zone, (uint32)(m_timer.GetInterval() / (MINUTE * IN_MILLISECONDS)));
#endif
}
@@ -85,7 +85,7 @@ bool Weather::ReGenerate()
time_t gtime = sWorld->GetGameTime();
struct tm ltime;
localtime_r(&gtime, &ltime);
uint32 season = ((ltime.tm_yday - 78 + 365)/91)%4;
uint32 season = ((ltime.tm_yday - 78 + 365) / 91) % 4;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
static char const* seasonName[WEATHER_SEASONS] = { "spring", "summer", "fall", "winter" };
@@ -126,7 +126,7 @@ bool Weather::ReGenerate()
{
if (m_grade > 0.6666667f)
{
// Severe change, but how severe?
// Severe change, but how severe?
uint32 rnd = urand(0, 99);
if (rnd < 50)
{
@@ -141,8 +141,8 @@ bool Weather::ReGenerate()
// At this point, only weather that isn't doing anything remains but that have weather data
uint32 chance1 = m_weatherChances->data[season].rainChance;
uint32 chance2 = chance1+ m_weatherChances->data[season].snowChance;
uint32 chance3 = chance2+ m_weatherChances->data[season].stormChance;
uint32 chance2 = chance1 + m_weatherChances->data[season].snowChance;
uint32 chance3 = chance2 + m_weatherChances->data[season].stormChance;
uint32 rnd = urand(0, 99);
if (rnd <= chance1)
@@ -277,29 +277,29 @@ void Weather::SetWeather(WeatherType type, float grade)
/// Get the sound number associated with the current weather
WeatherState Weather::GetWeatherState() const
{
if (m_grade<0.27f)
if (m_grade < 0.27f)
return WEATHER_STATE_FINE;
switch (m_type)
{
case WEATHER_TYPE_RAIN:
if (m_grade<0.40f)
if (m_grade < 0.40f)
return WEATHER_STATE_LIGHT_RAIN;
else if (m_grade<0.70f)
else if (m_grade < 0.70f)
return WEATHER_STATE_MEDIUM_RAIN;
else
return WEATHER_STATE_HEAVY_RAIN;
case WEATHER_TYPE_SNOW:
if (m_grade<0.40f)
if (m_grade < 0.40f)
return WEATHER_STATE_LIGHT_SNOW;
else if (m_grade<0.70f)
else if (m_grade < 0.70f)
return WEATHER_STATE_MEDIUM_SNOW;
else
return WEATHER_STATE_HEAVY_SNOW;
case WEATHER_TYPE_STORM:
if (m_grade<0.40f)
if (m_grade < 0.40f)
return WEATHER_STATE_LIGHT_SANDSTORM;
else if (m_grade<0.70f)
else if (m_grade < 0.70f)
return WEATHER_STATE_MEDIUM_SANDSTORM;
else
return WEATHER_STATE_HEAVY_SANDSTORM;

View File

@@ -52,29 +52,29 @@ enum WeatherState
/// Weather for one zone
class Weather
{
public:
public:
Weather(uint32 zone, WeatherData const* weatherChances);
~Weather() { };
Weather(uint32 zone, WeatherData const* weatherChances);
~Weather() { };
bool Update(uint32 diff);
bool ReGenerate();
bool UpdateWeather();
bool Update(uint32 diff);
bool ReGenerate();
bool UpdateWeather();
void SendWeatherUpdateToPlayer(Player* player);
void SetWeather(WeatherType type, float grade);
void SendWeatherUpdateToPlayer(Player* player);
void SetWeather(WeatherType type, float grade);
/// For which zone is this weather?
uint32 GetZone() const { return m_zone; };
uint32 GetScriptId() const { return m_weatherChances->ScriptId; }
/// For which zone is this weather?
uint32 GetZone() const { return m_zone; };
uint32 GetScriptId() const { return m_weatherChances->ScriptId; }
private:
private:
WeatherState GetWeatherState() const;
uint32 m_zone;
WeatherType m_type;
float m_grade;
IntervalTimer m_timer;
WeatherData const* m_weatherChances;
WeatherState GetWeatherState() const;
uint32 m_zone;
WeatherType m_type;
float m_grade;
IntervalTimer m_timer;
WeatherData const* m_weatherChances;
};
#endif

View File

@@ -20,141 +20,140 @@
namespace WeatherMgr
{
namespace
{
typedef std::unordered_map<uint32, acore::AutoPtr<Weather, ACE_Null_Mutex> > WeatherMap;
typedef std::unordered_map<uint32, WeatherData> WeatherZoneMap;
WeatherMap m_weathers;
WeatherZoneMap mWeatherZoneMap;
WeatherData const* GetWeatherData(uint32 zone_id)
namespace
{
WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id);
return (itr != mWeatherZoneMap.end()) ? &itr->second : nullptr;
}
}
typedef std::unordered_map<uint32, acore::AutoPtr<Weather, ACE_Null_Mutex> > WeatherMap;
typedef std::unordered_map<uint32, WeatherData> WeatherZoneMap;
/// 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;
}
WeatherMap m_weathers;
WeatherZoneMap mWeatherZoneMap;
/// 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 nullptr;
Weather* w = new Weather(zone_id, weatherChances);
m_weathers[w->GetZone()].reset(w);
w->ReGenerate();
w->UpdateWeather();
return w;
}
void LoadWeatherData()
{
uint32 oldMSTime = getMSTime();
uint32 count = 0;
QueryResult 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)
{
sLog->outErrorDb(">> Loaded 0 weather definitions. DB table `game_weather` is empty.");
sLog->outString();
return;
}
do
{
Field* fields = result->Fetch();
uint32 zone_id = fields[0].GetUInt32();
WeatherData& wzc = mWeatherZoneMap[zone_id];
for (uint8 season = 0; season < WEATHER_SEASONS; ++season)
WeatherData const* GetWeatherData(uint32 zone_id)
{
wzc.data[season].rainChance = fields[season * (MAX_WEATHER_TYPE-1) + 1].GetUInt8();
wzc.data[season].snowChance = fields[season * (MAX_WEATHER_TYPE-1) + 2].GetUInt8();
wzc.data[season].stormChance = fields[season * (MAX_WEATHER_TYPE-1) + 3].GetUInt8();
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);
}
WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id);
return (itr != mWeatherZoneMap.end()) ? &itr->second : nullptr;
}
wzc.ScriptId = sObjectMgr->GetScriptId(fields[13].GetCString());
++count;
}
while (result->NextRow());
sLog->outString(">> Loaded %u weather definitions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
sLog->outString();
}
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)
/// Find a Weather object by the given zoneid
Weather* FindWeather(uint32 id)
{
next = itr;
++next;
WeatherMap::const_iterator itr = m_weathers.find(id);
return (itr != m_weathers.end()) ? itr->second.get() : 0;
}
///- and remove Weather objects for zones with no player
// As interval > WorldTick
if (!itr->second->Update(diff))
/// 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 nullptr;
Weather* w = new Weather(zone_id, weatherChances);
m_weathers[w->GetZone()].reset(w);
w->ReGenerate();
w->UpdateWeather();
return w;
}
void LoadWeatherData()
{
uint32 oldMSTime = getMSTime();
uint32 count = 0;
QueryResult 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)
{
sLog->outErrorDb(">> Loaded 0 weather definitions. DB table `game_weather` is empty.");
sLog->outString();
return;
}
do
{
Field* fields = result->Fetch();
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].GetUInt8();
wzc.data[season].snowChance = fields[season * (MAX_WEATHER_TYPE - 1) + 2].GetUInt8();
wzc.data[season].stormChance = fields[season * (MAX_WEATHER_TYPE - 1) + 3].GetUInt8();
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 = sObjectMgr->GetScriptId(fields[13].GetCString());
++count;
} while (result->NextRow());
sLog->outString(">> Loaded %u weather definitions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
sLog->outString();
}
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