Exemple #1
0
void Weather::SendWeatherUpdateToPlayer(Player* player)
{
    NormalizeGrade();

    WorldPacket data(SMSG_WEATHER, 4 + 4 + 1);
    data << uint32(GetWeatherState());
    data << float(m_grade);
    data << uint8(0);       // 1 = instant change, 0 = smooth change

    player->GetSession()->SendPacket(&data);
}
Exemple #2
0
// Send the new weather to all players in the zone
bool Weather::SendWeatherForPlayersInZone(Map const* _map)
{
    NormalizeGrade();

    WorldPacket data(SMSG_WEATHER, 4 + 4 + 4 + 1);
    data << uint32(m_type);
    data << float(m_grade);
    data << uint32(GetSound()); // 1.12 soundid
    data << uint8(0);       // 1 = instant change, 0 = smooth change

    ///- Send the weather packet to all players in this zone
    if (!_map->SendToPlayersInZone(data, m_zone))
        return false;

    ///- Log the event
    LogWeatherState(GetWeatherState());
    return true;
}
Exemple #3
0
// Send the new weather to all players in the zone
bool Weather::SendWeatherForPlayersInZone(Map const* _map)
{
    NormalizeGrade();

    WeatherState state = GetWeatherState();

    WorldPacket data(SMSG_WEATHER, 4 + 4 + 1);
    data << uint32(state);
    data << float(m_grade);
    data << uint8(0);       // 1 = instant change, 0 = smooth change

    ///- Send the weather packet to all players in this zone
    if (!_map->SendToPlayersInZone(&data, m_zone))
        return false;

    ///- Log the event
    LogWeatherState(state);

    sEluna->OnChange(this, m_zone, state, m_grade);
    return true;
}
Exemple #4
0
/// Calculate the new weather, returns true if and only if the weather changed
bool Weather::ReGenerate()
{
    if (m_isPermanentWeather)
        return false;

    // remember old values
    WeatherType old_type = m_type;
    float old_grade = m_grade;

    if (!m_weatherChances)
    {
        m_type = WEATHER_TYPE_FINE;
        m_grade = 0.0f;
        // No chanced calculation for this zone
        return old_type != m_type || old_grade != m_grade;
    }

    /// Weather statistics:
    ///- 30% - no change
    ///- 30% - weather gets better (if not fine) or change weather type
    ///- 30% - weather worsens (if not fine)
    ///- 10% - radical change (if not fine)
    uint32 u = urand(0, 99);

    if (u < 30)
        return false;

    // 78 days between January 1st and March 20nd; 365/4=91 days by season
    // season source http://aa.usno.navy.mil/data/docs/EarthSeasons.html
    time_t gtime = sWorld.GetGameTime();
    struct tm* ltime = localtime(&gtime);
    uint32 season = ((ltime->tm_yday - 78 + 365) / 91) % 4;

    static char const* seasonName[WEATHER_SEASONS] = { "spring", "summer", "fall", "winter" };

    DEBUG_FILTER_LOG(LOG_FILTER_WEATHER, "Generating a change in %s weather for zone %u.", seasonName[season], m_zone);

    if ((u < 60) && (m_grade < 0.33333334f))                // Get fair
    {
        m_type = WEATHER_TYPE_FINE;
        m_grade = 0.0f;
    }

    if ((u < 60) && (m_type != WEATHER_TYPE_FINE))          // Get better
    {
        m_grade -= 0.33333334f;
        return true;
    }

    if ((u < 90) && (m_type != WEATHER_TYPE_FINE))          // Get worse
    {
        m_grade += 0.33333334f;
        return true;
    }

    if (m_type != WEATHER_TYPE_FINE)
    {
        /// Radical change:
        ///- if light -> heavy
        ///- if medium -> change weather type
        ///- if heavy -> 50% light, 50% change weather type

        if (m_grade < 0.33333334f)
        {
            m_grade = 0.9999f;                              // go nuts
            return true;
        }
        else
        {
            if (m_grade > 0.6666667f)
            {
                // Severe change, but how severe?
                uint32 rnd = urand(0, 99);
                if (rnd < 50)
                {
                    m_grade -= 0.6666667f;
                    return true;
                }
            }
            m_type = WEATHER_TYPE_FINE;                     // clear up
            m_grade = 0;
        }
    }

    // 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 rnd = urand(1, 100);
    if (rnd <= chance1)
        m_type = WEATHER_TYPE_RAIN;
    else if (rnd <= chance2)
        m_type = WEATHER_TYPE_SNOW;
    else if (rnd <= chance3)
        m_type = WEATHER_TYPE_STORM;
    else
        m_type = WEATHER_TYPE_FINE;

    /// New weather statistics (if not fine):
    ///- 85% light
    ///- 7% medium
    ///- 7% heavy
    /// If fine 100% sun (no fog)

    if (m_type == WEATHER_TYPE_FINE)
    {
        m_grade = 0.0f;
    }
    else if (u < 90)
    {
        m_grade = rand_norm_f() * 0.3333f;
    }
    else
    {
        // Severe change, but how severe?
        rnd = urand(0, 99);
        if (rnd < 50)
            m_grade = rand_norm_f() * 0.3333f + 0.3334f;
        else
            m_grade = rand_norm_f() * 0.3333f + 0.6667f;
    }

    NormalizeGrade();

    // return true only in case weather changes
    return m_type != old_type || m_grade != old_grade;
}