Mini Release Random Weather

Newbie Spellweaver
Joined
Jan 4, 2024
Messages
29
Reaction score
44
i release the mini source change for random weather.
fall snow slow, fall snow fast and rain.
This code make random a weather all 2-5 min you can change this
have fun.

#define __RANDOM_WEATHER // Added Random Weather Rain/Snow/None


SkyBox.cpp
Code:
void CSkyBox::Process()
{
    if (!g_Option.m_nWeatherEffect) return;

    if (m_pWorld)
    {
#ifdef __RANDOM_WEATHER
        static DWORD dwNextWeatherChange =
            timeGetTime() + (120000 + rand() % 180000); // 2–5 Minuten

        DWORD dwNow = timeGetTime();

        if (dwNow >= dwNextWeatherChange)
        {
            dwNextWeatherChange =
                dwNow + (120000 + rand() % 180000); // 2–5 Minuten

            int rnd = rand() % 100;
            int nNextWeather;

            if (rnd < 35)
                nNextWeather = WEATHER_NONE;
            else if (rnd < 70)
                nNextWeather = WEATHER_RAIN;
            else
                nNextWeather = WEATHER_SNOW;

            if (m_nWeather != nNextWeather)
            {
                if (nNextWeather == WEATHER_NONE)
                {
                    SetWeather(m_nWeather, FALSE);
                    m_nWeather = WEATHER_NONE;
                }
                else
                {
                    SetWeather(nNextWeather, TRUE);
                }

                InitFall();
            }
        }
#endif

#ifdef __JEFF_11
#ifdef __CLIENT
        if (m_pWorld->GetID() == WI_WORLD_KEBARAS)
        {
            if (CWorld::m_skyBox.GetWeather() != WEATHER_SNOW)
                CWorld::m_skyBox.SetWeather(WEATHER_SNOW, TRUE);
        }
#endif    // __CLIENT
#endif    // __JEFF_11
        BOOL bFall = FALSE;

        if (m_nWeather == WEATHER_RAIN)
        {
            for (int i = 0; i < (int)(m_nFall); i++)
            {
                FLOAT fheight = m_pWorld->GetLandHeight_Fast(m_vFall[i].x, m_vFall[i].z) - 1.0f;
                if (fheight == 0) fheight = 100000.0f;
                if (1) //m_timerWeather.IsTimeOut() == FALSE )
                {
                    if (fheight > m_vFall[i].y)
                    {
                        if (xRandom(10) >= 7)
                        {
                            D3DXVECTOR3 v3Pos;
                            D3DXVECTOR3 vec3Tri[3];
                            m_pWorld->GetLandTri(m_vFall[i].x, m_vFall[i].z, vec3Tri);
                            FLOAT ffHeight = m_pWorld->GetLandHeight(m_vFall[i].x, m_vFall[i].z);

                            D3DXVECTOR3 vVector1 = vec3Tri[2] - vec3Tri[0];
                            D3DXVECTOR3 vVector2 = vec3Tri[1] - vec3Tri[0];
                            D3DXVECTOR3 vNormal;
                            D3DXVec3Cross(&vNormal, &vVector1, &vVector2);
                            D3DXVec3Normalize(&vNormal, &vNormal);

                            D3DXVECTOR3 v3Up = D3DXVECTOR3(0.0f, -1.0f, 0.0f);
                            D3DXVECTOR3 v3Cross;
                            FLOAT fDot;
                            FLOAT fTheta;
                            D3DXVec3Cross(&v3Cross, &v3Up, &vNormal);
                            fDot = D3DXVec3Dot(&v3Up, &vNormal);
                            fTheta = acos(fDot);

                            D3DXQUATERNION qDirMap;
                            D3DXQuaternionRotationAxis(&qDirMap, &v3Cross, fTheta);

                            v3Pos = m_vFall[i];
                            v3Pos.y = ffHeight + 0.1f;

                            D3DXVECTOR3 vYPW;
                            QuaternionRotationToYPW(qDirMap, vYPW);


                            LPWATERHEIGHT pWaterHeight = m_pWorld->GetWaterHeight(m_vFall[i]);

                            if (pWaterHeight &&
                                (pWaterHeight->byWaterTexture & (byte)(~MASK_WATERFRAME)) == WTYPE_WATER)
                            {
                                FLOAT fHeight = (FLOAT)pWaterHeight->byWaterHeight;
                                v3Pos.y = fHeight;
                                CSfx* pObj = CreateSfx(g_Neuz.m_pd3dDevice, XI_GEN_RAINCIRCLE01, v3Pos);
                                FLOAT fscal = (FLOAT)(xRandom(2) + 1);

                                fscal *= 0.1f;

                                pObj->SetScale(D3DXVECTOR3(fscal, fscal, fscal));
                            }
                            else
                            {
                                FLOAT fscal = xRandom(2) + 0.05f;
                                CSfx* pObj = CreateSfx(g_Neuz.m_pd3dDevice, XI_GEN_RAINCIRCLE01, v3Pos);
                                fscal *= 0.1f;
                                pObj->SetScale(D3DXVECTOR3(fscal, fscal, fscal));

                                pObj->m_pSfxObj->m_vRotate.x = D3DXToDegree(vYPW.x);
                                pObj->m_pSfxObj->m_vRotate.y = D3DXToDegree(vYPW.y);
                                pObj->m_pSfxObj->m_vRotate.z = D3DXToDegree(vYPW.z);

                            }
                        }
                        m_vFall[i].x = g_pPlayer->GetPos().x + (float(rand() - RAND_MAX / 2) / RAND_MAX * 70);
                        m_vFall[i].z = g_pPlayer->GetPos().z + (float(rand() - RAND_MAX / 2) / RAND_MAX * 70);
                        m_vFall[i].y = g_pPlayer->GetPos().y + 10 + (float(rand()) / RAND_MAX * 10);
                    }
                    else
                    {
                        m_vFall[i] += m_vVelocity[i] * 1.5;
                    }
                    bFall = TRUE;
                }
                else

                    if (fheight < m_vFall[i].y)
                    {
                        bFall = TRUE;
                        m_vFall[i] += m_vVelocity[i] * 1.5;
                    }
            }
        }
        else if (m_nWeather == WEATHER_SNOW )
        {
            for (int i = 0; i < (int)(m_nFall); i++)
            {
                FLOAT fheight = m_pWorld->GetLandHeight_Fast(m_vFall[i].x, m_vFall[i].z) - 1.0f;
                if (fheight == 0)
                    fheight = 100000.0f;
                if (1) //m_timerWeather.IsTimeOut() == FALSE )
                {
                    if (fheight > m_vFall[i].y)
                    {
                        m_vFall[i].x = g_pPlayer->GetPos().x + (float(rand() - RAND_MAX / 2) / RAND_MAX * 70);
                        m_vFall[i].z = g_pPlayer->GetPos().z + (float(rand() - RAND_MAX / 2) / RAND_MAX * 70);
                        m_vFall[i].y = g_pPlayer->GetPos().y + 10 + (float(rand()) / RAND_MAX * 20);
                    }
                    else
                        m_vFall[i] += m_vVelocity[i];
                    bFall = TRUE;
                }
                else

                    if (fheight < m_vFall[i].y)
                    {
                        bFall = TRUE;
                        m_vFall[i] += m_vVelocity[i];
                    }
            }
        }
        //    if( bFall == FALSE )
        //        m_nWeather = WEATHER_NONE;
    }
}


Code:
initfall

    // -------------------------------------------------
    // KEIN STURM, KEIN WIND
    // -------------------------------------------------
    m_bStorm = false;

    // -------------------------------------------------
    // PARTIKEL-MENGE (ruhig & wenig)
    // -------------------------------------------------
    if (m_nWeather == WEATHER_RAIN)
        m_nFall = 300;          // 🌧 sehr sanfter Regen
    else if (m_nWeather == WEATHER_SNOW)
        m_nFall = 250;          // ❄ ruhiger Schnee
    else
        m_nFall = 0;
        
        
    
    // -------------------------------------------------
    // INTENSITÄT (sehr sanft)
    // -------------------------------------------------
    float rainIntensity = -0.015f; // langsamer, ruhiger Fall
    float snowIntensity = -0.005f;   
    
    
        // -------------------------------------------------
    // FALL-PARTIKEL
    // -------------------------------------------------
    for (int i = 0; i < m_nFall; i++)
    {
        m_vFall[i].x = g_pPlayer->GetPos().x +
            (float(rand() - RAND_MAX / 2) / RAND_MAX * 60.0f);
        m_vFall[i].z = g_pPlayer->GetPos().z +
            (float(rand() - RAND_MAX / 2) / RAND_MAX * 60.0f);
        m_vFall[i].y = g_pPlayer->GetPos().y +
            10.0f + (float(rand()) / RAND_MAX * 8.0f);

        // -----------------------------
        // RAIN (ruhig, gerade)
        // -----------------------------
        if (m_nWeather == WEATHER_RAIN)
        {
            int y = -6 - xRandom(6);

            m_vVelocity[i] = D3DXVECTOR3(
                0.0f,                                  // kein Wind
                float(y) / 220.0f - 0.04f + rainIntensity,
                0.0f
            );
        }

        // -----------------------------
        // SNOW (ruhig)
        // -----------------------------
        else if (m_nWeather == WEATHER_SNOW)
        {
            int y = -1 - xRandom(2);

            m_vVelocity[i] = D3DXVECTOR3(
                0.0f,
                float(y) / 320.0f - 0.01f + snowIntensity,
                0.0f
            );
        }
    }
}

dicsord: BlackSoturi#6395
 
i release the mini source change for random weather.
fall snow slow, fall snow fast and rain.
This code make random a weather all 2-5 min you can change this
have fun.

#define __RANDOM_WEATHER // Added Random Weather Rain/Snow/None


SkyBox.cpp
Code:
void CSkyBox::Process()
{
    if (!g_Option.m_nWeatherEffect) return;

    if (m_pWorld)
    {
#ifdef __RANDOM_WEATHER
        static DWORD dwNextWeatherChange =
            timeGetTime() + (120000 + rand() % 180000); // 2–5 Minuten

        DWORD dwNow = timeGetTime();

        if (dwNow >= dwNextWeatherChange)
        {
            dwNextWeatherChange =
                dwNow + (120000 + rand() % 180000); // 2–5 Minuten

            int rnd = rand() % 100;
            int nNextWeather;

            if (rnd < 35)
                nNextWeather = WEATHER_NONE;
            else if (rnd < 70)
                nNextWeather = WEATHER_RAIN;
            else
                nNextWeather = WEATHER_SNOW;

            if (m_nWeather != nNextWeather)
            {
                if (nNextWeather == WEATHER_NONE)
                {
                    SetWeather(m_nWeather, FALSE);
                    m_nWeather = WEATHER_NONE;
                }
                else
                {
                    SetWeather(nNextWeather, TRUE);
                }

                InitFall();
            }
        }
#endif

#ifdef __JEFF_11
#ifdef __CLIENT
        if (m_pWorld->GetID() == WI_WORLD_KEBARAS)
        {
            if (CWorld::m_skyBox.GetWeather() != WEATHER_SNOW)
                CWorld::m_skyBox.SetWeather(WEATHER_SNOW, TRUE);
        }
#endif    // __CLIENT
#endif    // __JEFF_11
        BOOL bFall = FALSE;

        if (m_nWeather == WEATHER_RAIN)
        {
            for (int i = 0; i < (int)(m_nFall); i++)
            {
                FLOAT fheight = m_pWorld->GetLandHeight_Fast(m_vFall[i].x, m_vFall[i].z) - 1.0f;
                if (fheight == 0) fheight = 100000.0f;
                if (1) //m_timerWeather.IsTimeOut() == FALSE )
                {
                    if (fheight > m_vFall[i].y)
                    {
                        if (xRandom(10) >= 7)
                        {
                            D3DXVECTOR3 v3Pos;
                            D3DXVECTOR3 vec3Tri[3];
                            m_pWorld->GetLandTri(m_vFall[i].x, m_vFall[i].z, vec3Tri);
                            FLOAT ffHeight = m_pWorld->GetLandHeight(m_vFall[i].x, m_vFall[i].z);

                            D3DXVECTOR3 vVector1 = vec3Tri[2] - vec3Tri[0];
                            D3DXVECTOR3 vVector2 = vec3Tri[1] - vec3Tri[0];
                            D3DXVECTOR3 vNormal;
                            D3DXVec3Cross(&vNormal, &vVector1, &vVector2);
                            D3DXVec3Normalize(&vNormal, &vNormal);

                            D3DXVECTOR3 v3Up = D3DXVECTOR3(0.0f, -1.0f, 0.0f);
                            D3DXVECTOR3 v3Cross;
                            FLOAT fDot;
                            FLOAT fTheta;
                            D3DXVec3Cross(&v3Cross, &v3Up, &vNormal);
                            fDot = D3DXVec3Dot(&v3Up, &vNormal);
                            fTheta = acos(fDot);

                            D3DXQUATERNION qDirMap;
                            D3DXQuaternionRotationAxis(&qDirMap, &v3Cross, fTheta);

                            v3Pos = m_vFall[i];
                            v3Pos.y = ffHeight + 0.1f;

                            D3DXVECTOR3 vYPW;
                            QuaternionRotationToYPW(qDirMap, vYPW);


                            LPWATERHEIGHT pWaterHeight = m_pWorld->GetWaterHeight(m_vFall[i]);

                            if (pWaterHeight &&
                                (pWaterHeight->byWaterTexture & (byte)(~MASK_WATERFRAME)) == WTYPE_WATER)
                            {
                                FLOAT fHeight = (FLOAT)pWaterHeight->byWaterHeight;
                                v3Pos.y = fHeight;
                                CSfx* pObj = CreateSfx(g_Neuz.m_pd3dDevice, XI_GEN_RAINCIRCLE01, v3Pos);
                                FLOAT fscal = (FLOAT)(xRandom(2) + 1);

                                fscal *= 0.1f;

                                pObj->SetScale(D3DXVECTOR3(fscal, fscal, fscal));
                            }
                            else
                            {
                                FLOAT fscal = xRandom(2) + 0.05f;
                                CSfx* pObj = CreateSfx(g_Neuz.m_pd3dDevice, XI_GEN_RAINCIRCLE01, v3Pos);
                                fscal *= 0.1f;
                                pObj->SetScale(D3DXVECTOR3(fscal, fscal, fscal));

                                pObj->m_pSfxObj->m_vRotate.x = D3DXToDegree(vYPW.x);
                                pObj->m_pSfxObj->m_vRotate.y = D3DXToDegree(vYPW.y);
                                pObj->m_pSfxObj->m_vRotate.z = D3DXToDegree(vYPW.z);

                            }
                        }
                        m_vFall[i].x = g_pPlayer->GetPos().x + (float(rand() - RAND_MAX / 2) / RAND_MAX * 70);
                        m_vFall[i].z = g_pPlayer->GetPos().z + (float(rand() - RAND_MAX / 2) / RAND_MAX * 70);
                        m_vFall[i].y = g_pPlayer->GetPos().y + 10 + (float(rand()) / RAND_MAX * 10);
                    }
                    else
                    {
                        m_vFall[i] += m_vVelocity[i] * 1.5;
                    }
                    bFall = TRUE;
                }
                else

                    if (fheight < m_vFall[i].y)
                    {
                        bFall = TRUE;
                        m_vFall[i] += m_vVelocity[i] * 1.5;
                    }
            }
        }
        else if (m_nWeather == WEATHER_SNOW )
        {
            for (int i = 0; i < (int)(m_nFall); i++)
            {
                FLOAT fheight = m_pWorld->GetLandHeight_Fast(m_vFall[i].x, m_vFall[i].z) - 1.0f;
                if (fheight == 0)
                    fheight = 100000.0f;
                if (1) //m_timerWeather.IsTimeOut() == FALSE )
                {
                    if (fheight > m_vFall[i].y)
                    {
                        m_vFall[i].x = g_pPlayer->GetPos().x + (float(rand() - RAND_MAX / 2) / RAND_MAX * 70);
                        m_vFall[i].z = g_pPlayer->GetPos().z + (float(rand() - RAND_MAX / 2) / RAND_MAX * 70);
                        m_vFall[i].y = g_pPlayer->GetPos().y + 10 + (float(rand()) / RAND_MAX * 20);
                    }
                    else
                        m_vFall[i] += m_vVelocity[i];
                    bFall = TRUE;
                }
                else

                    if (fheight < m_vFall[i].y)
                    {
                        bFall = TRUE;
                        m_vFall[i] += m_vVelocity[i];
                    }
            }
        }
        //    if( bFall == FALSE )
        //        m_nWeather = WEATHER_NONE;
    }
}


Code:
initfall

    // -------------------------------------------------
    // KEIN STURM, KEIN WIND
    // -------------------------------------------------
    m_bStorm = false;

    // -------------------------------------------------
    // PARTIKEL-MENGE (ruhig & wenig)
    // -------------------------------------------------
    if (m_nWeather == WEATHER_RAIN)
        m_nFall = 300;          // 🌧 sehr sanfter Regen
    else if (m_nWeather == WEATHER_SNOW)
        m_nFall = 250;          // ❄ ruhiger Schnee
    else
        m_nFall = 0;
       
       
   
    // -------------------------------------------------
    // INTENSITÄT (sehr sanft)
    // -------------------------------------------------
    float rainIntensity = -0.015f; // langsamer, ruhiger Fall
    float snowIntensity = -0.005f;  
   
   
        // -------------------------------------------------
    // FALL-PARTIKEL
    // -------------------------------------------------
    for (int i = 0; i < m_nFall; i++)
    {
        m_vFall[i].x = g_pPlayer->GetPos().x +
            (float(rand() - RAND_MAX / 2) / RAND_MAX * 60.0f);
        m_vFall[i].z = g_pPlayer->GetPos().z +
            (float(rand() - RAND_MAX / 2) / RAND_MAX * 60.0f);
        m_vFall[i].y = g_pPlayer->GetPos().y +
            10.0f + (float(rand()) / RAND_MAX * 8.0f);

        // -----------------------------
        // RAIN (ruhig, gerade)
        // -----------------------------
        if (m_nWeather == WEATHER_RAIN)
        {
            int y = -6 - xRandom(6);

            m_vVelocity[i] = D3DXVECTOR3(
                0.0f,                                  // kein Wind
                float(y) / 220.0f - 0.04f + rainIntensity,
                0.0f
            );
        }

        // -----------------------------
        // SNOW (ruhig)
        // -----------------------------
        else if (m_nWeather == WEATHER_SNOW)
        {
            int y = -1 - xRandom(2);

            m_vVelocity[i] = D3DXVECTOR3(
                0.0f,
                float(y) / 320.0f - 0.01f + snowIntensity,
                0.0f
            );
        }
    }
}

dicsord: BlackSoturi#6395
its nice but it will crash players client so much. unless someone fixed the sfx effect rendering
 
i use the official random snow and rain much better i think hmm
 
Could you provide more information about this SFX bug?
Its been awhile since this post of mine. But as far as I remember, the problem on the weather system is the fact that the changes on weather on textures on trees, sky, rain, snow etc. Causes the crashes on the clients. And my theory it is because of the old d3direct, I think. Because I have been always make changes on wndmanger functions, maybe particles.cpp, object3d.cpp, and some other files that is connected with it. But no luck.

But in summary, in my theory it is about the old win32 d3d old school .dll plugins unless you made changes to win64
 
Its been awhile since this post of mine. But as far as I remember, the problem on the weather system is the fact that the changes on weather on textures on trees, sky, rain, snow etc. Causes the crashes on the clients. And my theory it is because of the old d3direct, I think. Because I have been always make changes on wndmanger functions, maybe particles.cpp, object3d.cpp, and some other files that is connected with it. But no luck.

But in summary, in my theory it is about the old win32 d3d old school .dll plugins unless you made changes to win64
They likely disappeared with updates to the 'florist 2026' files. I haven't checked in Titanium yet—even though it's an old file, if I'm not mistaken, it runs on Win64. I'll check as soon as I get home; thanks a lot, my friend!
 
Back