Warband Script Enhancer 2 (v1.1.2.0)

Users who are viewing this thread

@K700 , What is the foggy weather like in Warband? Is it simply random? Does it have anything to do with geography? Will it affect the distance AI decides to shoot, AI shooting accuracy, damage, etc?
 
hi, wse2 not showing me certain trees, rgl log says it's not able to load tree_o.dds - most likely because this file is neither in my game or mod (Persistent Kingdoms) textures
 
@K700 , What is the foggy weather like in Warband? Is it simply random? Does it have anything to do with geography? Will it affect the distance AI decides to shoot, AI shooting accuracy, damage, etc?
Code:
void mbWeather::update(mbParty *party, float *regionProximityData, int regionType)
{
    if (m_dayTime < 0.0f)
        m_dayTime = fmod(mbGetGameTime(), 24.0f);

    bool validPrecipitation = m_precipitationType != -1;
    bool validFogDistance = m_fogFar < -0.5f;
    rglVector4 weatherData = g_game->getWeatherData(party->getPosition().vec2());

    float regionHumidity =
        regionProximityData[rt_snow_forest] * 0.01f +
        regionProximityData[rt_snow] * 0.005f +
        regionProximityData[rt_ocean] * 0.1f +
        regionProximityData[rt_river] * 0.01f +
        regionProximityData[rt_plain] * 0.001f +
        regionProximityData[rt_forest] * 0.002f +
        regionProximityData[rt_mountain] * 0.003f +
        regionProximityData[rt_mountain_forest] * 0.005f +
        regionProximityData[rt_steppe] * 0.0005f +
        regionProximityData[rt_steppe_forest] * 0.0015f;

    regionHumidity = rglClamp(regionHumidity, 0.0f, 1.0f);

    rglVector4 noise = rglPerlinOctave(96.0f, 0.7f, 4, false, rglVector4(g_game->m_seed * 0.1f, mbGetGameTime(), 0.0f));
    float fogNoise = noise.sumComponents() * 5.0f;

    noise = rglPerlinOctave(72.0f, 0.7f, 4, false, rglVector4(g_game->m_seed * 0.1f, mbGetGameTime(), 700.0f));

    float cloudNoise = noise.sumComponents() * 5.0f;

    m_height = party->getPosition().z;
    m_precipitationDirection.x = weatherData.z;
    m_precipitationDirection.y = weatherData.w;
    m_temperature = weatherData.x;
    m_humidity = rglClamp((fogNoise + fogNoise + 0.5f) * regionHumidity + rglRandf() * 0.05f, 0.0f, 1.0f);
    m_cloudType = rglRound((regionHumidity + 1.5f) * 1.5f * g_game->m_cloudAmount);
    m_fogDensity = (g_game->m_cloudAmount + 0.3f) * (regionHumidity + 0.5f) * 0.008f * g_game->m_hazeAmount * g_game->m_hazeAmount + 0.0001f;

    if (!validPrecipitation)
    {
        m_precipitationType = wpr_none;
        m_precipitationStrength = 0.0f;
    }

    if (g_game->m_hazeAmount > 0.9f)
    {
        m_fogDensity = (m_fogDensity + 0.02f) * 1.3f;
        
        if (g_game->m_hazeAmount > 0.94f)
        {
            m_fogDensity = (m_fogDensity + 0.02f) * 1.2f;

            if (g_game->m_hazeAmount > 0.98f)
                m_fogDensity += 0.01f;
        }
    }

    if (!validFogDistance)
    {
        m_fogFar = (rglRandf() * 0.5f + 0.5f) * (1.2f - m_humidity) * 2000.0f;

        if (m_dayTime > 3.0f && m_dayTime < 10.0f)
            m_fogFar *= rglRandf() * 0.7f + 0.3f;
    }

    if (g_game->m_cloudAmount > 0.6f)
    {
        if (g_game->m_cloudAmount * 0.2f + cloudNoise + m_humidity * 0.1f + rglRandf() * 0.05f > 0.4f)
        {
            if (!validPrecipitation)
            {
                if (regionType == rt_snow || regionType == rt_snow_forest)
                    m_precipitationType = wpr_snow;
                else
                    m_precipitationType = wpr_rain;

                m_precipitationStrength = rglRandf() * 0.5f + 0.5f;
            }

            if (m_cloudType < 2)
                m_cloudType = 2;

            if (m_precipitationStrength > 0.3f)
                m_cloudType = 3;

            float fogRand = rglSquare(rglRandf());

            if (!validFogDistance)
                m_fogFar /= fogRand * 3.0f * m_precipitationStrength + 1.0f;

            m_fogDensity += fogRand * 0.0015f * m_precipitationStrength;

            if (m_precipitationType == wpr_snow)
            {
                float snowFogRand = rglSquare(rglRandf());

                if (!validFogDistance)
                    m_fogFar *= 1.0f - 0.5f * snowFogRand;

                m_fogDensity = (m_precipitationStrength * 0.0025f * snowFogRand + m_fogDensity) * (snowFogRand * 0.5f + 1.0f);
            }
        }
    }

    if (!validFogDistance && m_fogFar < 60.0f)
        m_fogFar = 60.0f;

    if (m_fogDensity > 0.15f)
        m_fogDensity = 0.15f;

    if (party->m_quad)
        m_manifoldFaceNo = party->m_quad->m_manifoldFaceNo;
    else
        m_manifoldFaceNo = 0;

    m_regionType = regionType;
    m_skyboxNo = 0;
    
#if !defined DEDICATED_SERVER
    if (g_graphicsContext.highDynamicRangeEnabled() && rglBetween(g_game->m_sceneHdrSkyboxNo, 0, g_numSkyboxes))
    {
        m_skyboxNo = g_game->m_sceneHdrSkyboxNo;
    }
    else if (rglBetween(g_game->m_sceneSkyboxNo, 0, g_numSkyboxes))
    {
        m_skyboxNo = g_game->m_sceneSkyboxNo;
    }
    else
    {
        for (int i = 0; i < g_numSkyboxes; ++i)
        {
            mbSkybox *skybox = &g_skyboxes[i];

            skybox->m_suitability = rglRandf() * 0.01f;

            bool correctHour;
            
            if (m_dayTime <= 4.0f || m_dayTime >= 20.0f)
                correctHour = (skybox->m_flags & sf_time_mask) == sf_night;
            else if (m_dayTime <= 7.0f || m_dayTime >= 17.0f)
                correctHour = (skybox->m_flags & sf_time_mask) == sf_dawn;
            else
                correctHour = (skybox->m_flags & sf_time_mask) == sf_day;

            if (correctHour)
                skybox->m_suitability += 1.0f;

            skybox->m_suitability -= rglAbs((int)(m_cloudType - ((skybox->m_flags & sf_clouds_mask) >> sf_clouds_shift))) * 0.1f;

            bool isHdr = (skybox->m_flags & sf_hdr) != 0;

            if (isHdr != g_graphicsContext.highDynamicRangeEnabled())
                skybox->m_suitability = 0.0f;
        }

        for (int i = 0; i < g_numSkyboxes; ++i)
        {
            if (g_skyboxes[m_skyboxNo].m_suitability < g_skyboxes[i].m_suitability)
                m_skyboxNo = i;
        }
    }
#endif
}

int mbAgent::spawnMissile()
{
    if (isBot())
        m_attackOverrideType = -1;

    mbItem weaponItem = getWieldedItem(ah_primary);
    rglTransform transform = m_entity->m_skeleton->getBoneTransform(hb_head);

    transform.o += transform.f * 0.15f;

    rglVector4 shootPosition = m_rotatedTransform.transformPointToParent(transform.o);
    rglVector4 missileDirection = getMissileDirection();

    if (isBot() && m_ai.m_lookTargetAgentNo >= 0)
    {
        mbAgent *lookTargetAgent = g_mission->getAgent(m_ai.m_lookTargetAgentNo);
        int proficiency = (int)getTroop()->getProficiency(weaponItem.getItemKind()->getProficiency(getWieldedItem(ah_secondary).isValid()));
        rglVector4 velDiff = lookTargetAgent->m_smoothVelocity - m_smoothVelocity;
        rglVector4 posDiff = lookTargetAgent->m_position - m_position;
        rglVector4 dir = posDiff;
        float distance = dir.normalize();
        float difficultyFactor = rglConfig::BattleAi::iReduceBattleAi * 0.5f;
        float proficiencyFactor = proficiency + 20.0f;
        float errorFactor = rglMin(((velDiff.length() * dir.cross((posDiff + velDiff).normalized()).length() * 10.0f / (distance + 10.0f)) * 0.3f / proficiencyFactor * (difficultyFactor + 0.5f)) + (0.65f / proficiencyFactor * (difficultyFactor + 1.0f)), 0.2f);

        if (g_mission->m_weather.m_fogFar > 0.0f && g_mission->m_weather.m_fogFar < 200.0f)
            errorFactor += distance * 0.05f / g_mission->m_weather.m_fogFar;

        if (!g_game->isDay())
            errorFactor += distance * 0.001f;

        missileDirection.x += (0.5f - rglRandf()) * errorFactor;
        missileDirection.y += (0.5f - rglRandf()) * errorFactor;
        missileDirection.z += (0.5f - rglRandf()) * errorFactor;
    }

    return g_mission->spawnMissile(g_basicGame.isClient(), shootPosition, applyInaccuracy(missileDirection, m_inaccuracy), weaponItem, getAmmoItem(), m_no);
}
 
Code:
void mbWeather::update(mbParty *party, float *regionProximityData, int regionType)
{
    if (m_dayTime < 0.0f)
        m_dayTime = fmod(mbGetGameTime(), 24.0f);

    bool validPrecipitation = m_precipitationType != -1;
    bool validFogDistance = m_fogFar < -0.5f;
    rglVector4 weatherData = g_game->getWeatherData(party->getPosition().vec2());

    float regionHumidity =
        regionProximityData[rt_snow_forest] * 0.01f +
        regionProximityData[rt_snow] * 0.005f +
        regionProximityData[rt_ocean] * 0.1f +
        regionProximityData[rt_river] * 0.01f +
        regionProximityData[rt_plain] * 0.001f +
        regionProximityData[rt_forest] * 0.002f +
        regionProximityData[rt_mountain] * 0.003f +
        regionProximityData[rt_mountain_forest] * 0.005f +
        regionProximityData[rt_steppe] * 0.0005f +
        regionProximityData[rt_steppe_forest] * 0.0015f;

    regionHumidity = rglClamp(regionHumidity, 0.0f, 1.0f);

    rglVector4 noise = rglPerlinOctave(96.0f, 0.7f, 4, false, rglVector4(g_game->m_seed * 0.1f, mbGetGameTime(), 0.0f));
    float fogNoise = noise.sumComponents() * 5.0f;

    noise = rglPerlinOctave(72.0f, 0.7f, 4, false, rglVector4(g_game->m_seed * 0.1f, mbGetGameTime(), 700.0f));

    float cloudNoise = noise.sumComponents() * 5.0f;

    m_height = party->getPosition().z;
    m_precipitationDirection.x = weatherData.z;
    m_precipitationDirection.y = weatherData.w;
    m_temperature = weatherData.x;
    m_humidity = rglClamp((fogNoise + fogNoise + 0.5f) * regionHumidity + rglRandf() * 0.05f, 0.0f, 1.0f);
    m_cloudType = rglRound((regionHumidity + 1.5f) * 1.5f * g_game->m_cloudAmount);
    m_fogDensity = (g_game->m_cloudAmount + 0.3f) * (regionHumidity + 0.5f) * 0.008f * g_game->m_hazeAmount * g_game->m_hazeAmount + 0.0001f;

    if (!validPrecipitation)
    {
        m_precipitationType = wpr_none;
        m_precipitationStrength = 0.0f;
    }

    if (g_game->m_hazeAmount > 0.9f)
    {
        m_fogDensity = (m_fogDensity + 0.02f) * 1.3f;
       
        if (g_game->m_hazeAmount > 0.94f)
        {
            m_fogDensity = (m_fogDensity + 0.02f) * 1.2f;

            if (g_game->m_hazeAmount > 0.98f)
                m_fogDensity += 0.01f;
        }
    }

    if (!validFogDistance)
    {
        m_fogFar = (rglRandf() * 0.5f + 0.5f) * (1.2f - m_humidity) * 2000.0f;

        if (m_dayTime > 3.0f && m_dayTime < 10.0f)
            m_fogFar *= rglRandf() * 0.7f + 0.3f;
    }

    if (g_game->m_cloudAmount > 0.6f)
    {
        if (g_game->m_cloudAmount * 0.2f + cloudNoise + m_humidity * 0.1f + rglRandf() * 0.05f > 0.4f)
        {
            if (!validPrecipitation)
            {
                if (regionType == rt_snow || regionType == rt_snow_forest)
                    m_precipitationType = wpr_snow;
                else
                    m_precipitationType = wpr_rain;

                m_precipitationStrength = rglRandf() * 0.5f + 0.5f;
            }

            if (m_cloudType < 2)
                m_cloudType = 2;

            if (m_precipitationStrength > 0.3f)
                m_cloudType = 3;

            float fogRand = rglSquare(rglRandf());

            if (!validFogDistance)
                m_fogFar /= fogRand * 3.0f * m_precipitationStrength + 1.0f;

            m_fogDensity += fogRand * 0.0015f * m_precipitationStrength;

            if (m_precipitationType == wpr_snow)
            {
                float snowFogRand = rglSquare(rglRandf());

                if (!validFogDistance)
                    m_fogFar *= 1.0f - 0.5f * snowFogRand;

                m_fogDensity = (m_precipitationStrength * 0.0025f * snowFogRand + m_fogDensity) * (snowFogRand * 0.5f + 1.0f);
            }
        }
    }

    if (!validFogDistance && m_fogFar < 60.0f)
        m_fogFar = 60.0f;

    if (m_fogDensity > 0.15f)
        m_fogDensity = 0.15f;

    if (party->m_quad)
        m_manifoldFaceNo = party->m_quad->m_manifoldFaceNo;
    else
        m_manifoldFaceNo = 0;

    m_regionType = regionType;
    m_skyboxNo = 0;
   
#if !defined DEDICATED_SERVER
    if (g_graphicsContext.highDynamicRangeEnabled() && rglBetween(g_game->m_sceneHdrSkyboxNo, 0, g_numSkyboxes))
    {
        m_skyboxNo = g_game->m_sceneHdrSkyboxNo;
    }
    else if (rglBetween(g_game->m_sceneSkyboxNo, 0, g_numSkyboxes))
    {
        m_skyboxNo = g_game->m_sceneSkyboxNo;
    }
    else
    {
        for (int i = 0; i < g_numSkyboxes; ++i)
        {
            mbSkybox *skybox = &g_skyboxes[i];

            skybox->m_suitability = rglRandf() * 0.01f;

            bool correctHour;
           
            if (m_dayTime <= 4.0f || m_dayTime >= 20.0f)
                correctHour = (skybox->m_flags & sf_time_mask) == sf_night;
            else if (m_dayTime <= 7.0f || m_dayTime >= 17.0f)
                correctHour = (skybox->m_flags & sf_time_mask) == sf_dawn;
            else
                correctHour = (skybox->m_flags & sf_time_mask) == sf_day;

            if (correctHour)
                skybox->m_suitability += 1.0f;

            skybox->m_suitability -= rglAbs((int)(m_cloudType - ((skybox->m_flags & sf_clouds_mask) >> sf_clouds_shift))) * 0.1f;

            bool isHdr = (skybox->m_flags & sf_hdr) != 0;

            if (isHdr != g_graphicsContext.highDynamicRangeEnabled())
                skybox->m_suitability = 0.0f;
        }

        for (int i = 0; i < g_numSkyboxes; ++i)
        {
            if (g_skyboxes[m_skyboxNo].m_suitability < g_skyboxes[i].m_suitability)
                m_skyboxNo = i;
        }
    }
#endif
}

int mbAgent::spawnMissile()
{
    if (isBot())
        m_attackOverrideType = -1;

    mbItem weaponItem = getWieldedItem(ah_primary);
    rglTransform transform = m_entity->m_skeleton->getBoneTransform(hb_head);

    transform.o += transform.f * 0.15f;

    rglVector4 shootPosition = m_rotatedTransform.transformPointToParent(transform.o);
    rglVector4 missileDirection = getMissileDirection();

    if (isBot() && m_ai.m_lookTargetAgentNo >= 0)
    {
        mbAgent *lookTargetAgent = g_mission->getAgent(m_ai.m_lookTargetAgentNo);
        int proficiency = (int)getTroop()->getProficiency(weaponItem.getItemKind()->getProficiency(getWieldedItem(ah_secondary).isValid()));
        rglVector4 velDiff = lookTargetAgent->m_smoothVelocity - m_smoothVelocity;
        rglVector4 posDiff = lookTargetAgent->m_position - m_position;
        rglVector4 dir = posDiff;
        float distance = dir.normalize();
        float difficultyFactor = rglConfig::BattleAi::iReduceBattleAi * 0.5f;
        float proficiencyFactor = proficiency + 20.0f;
        float errorFactor = rglMin(((velDiff.length() * dir.cross((posDiff + velDiff).normalized()).length() * 10.0f / (distance + 10.0f)) * 0.3f / proficiencyFactor * (difficultyFactor + 0.5f)) + (0.65f / proficiencyFactor * (difficultyFactor + 1.0f)), 0.2f);

        if (g_mission->m_weather.m_fogFar > 0.0f && g_mission->m_weather.m_fogFar < 200.0f)
            errorFactor += distance * 0.05f / g_mission->m_weather.m_fogFar;

        if (!g_game->isDay())
            errorFactor += distance * 0.001f;

        missileDirection.x += (0.5f - rglRandf()) * errorFactor;
        missileDirection.y += (0.5f - rglRandf()) * errorFactor;
        missileDirection.z += (0.5f - rglRandf()) * errorFactor;
    }

    return g_mission->spawnMissile(g_basicGame.isClient(), shootPosition, applyInaccuracy(missileDirection, m_inaccuracy), weaponItem, getAmmoItem(), m_no);
}
Thank you so much for the codes, I'll have to spend some time understanding them.
 
If you can manage to understand the code explain to us too. Especialy the part with rglVector4 functions.
rglVector4 is just a data structure representing a vector with 4 floats as their components. rgl is just TaleWorlds' standard library for their custom engine.

Inside X, Y, Z they are packing the respective rotations of the vector and W typically just stores 1.
The W has actual usefulness but I am not learned enough to really understand it, lol. Something about homogeneity and matrices.
 
Last edited:
What does wse2 have to do with it?
regular warband loads it, wse2 doesnt.
edit: honestly, might be a different issue seeing that it's part of the terrain borders. if i go into edit mode, the trees i'm talking about show up in wse2 but if i turn edit mode off, then relog, the trees disappear. like i said though, this doesnt happen in regular warband so would appreciate if you could think of a fix, will send rgl log in a pm
 
Last edited:
regular warband loads it, wse2 doesnt.
edit: honestly, might be a different issue seeing that it's part of the terrain borders. if i go into edit mode, the trees i'm talking about show up in wse2 but if i turn edit mode off, then relog, the trees disappear. like i said though, this doesnt happen in regular warband so would appreciate if you could think of a fix, will send rgl log in a pm
Sounds to me that the game is loading an incorrect resource that just happens to fit the asset.

Since there is no texture loaded, it uses the previous one rendered in memory.

I don't think it does, but WSE2 might change the load order of the textures in memory and so the texture being applied is different.

Ideally you would replace the missing texture with one that is actually in the files instead of relying on a load order issue
 
regular warband loads it, wse2 doesnt.
edit: honestly, might be a different issue seeing that it's part of the terrain borders. if i go into edit mode, the trees i'm talking about show up in wse2 but if i turn edit mode off, then relog, the trees disappear. like i said though, this doesnt happen in regular warband so would appreciate if you could think of a fix, will send rgl log in a pm
Are you talking about the vanilla Persistent Kingdoms or about your modification? I didn't notice the missing trees
 
hey K700, i have switched my computer recently and WSE2 doesn't seem to run anymore, it worked fine on my old PC but its running into these two errors now, could you take a look?
(i do apologise if someone had this before and theres a fix but there's no way i'll find that in 90 pages of discussion)
 
 
Are you talking about the vanilla Persistent Kingdoms or about your modification? I didn't notice the missing trees
this is vanilla persistent kingdoms yeah - appears to be client side, other people don't face the same issue as me but would appreciate any help you might be able to give

Sounds to me that the game is loading an incorrect resource that just happens to fit the asset.

Since there is no texture loaded, it uses the previous one rendered in memory.

I don't think it does, but WSE2 might change the load order of the textures in memory and so the texture being applied is different.

Ideally you would replace the missing texture with one that is actually in the files instead of relying on a load order issue
i have no idea what to make of this i'm afraid - anything i can do?
 
this is vanilla persistent kingdoms yeah - appears to be client side, other people don't face the same issue as me but would appreciate any help you might be able to give


i have no idea what to make of this i'm afraid - anything i can do?
try delete Documents\Mount&Blade Warband WSE2\rgl_config.ini
 
Hey I am loving WSE2 and I'm glad it is created, but I plan on swapping to linux and I saw that people got it to work via bottles but I would like to know how to perform it. And also I was curious if you lose on features compared to normally running it on windows. Thanks a bunch and if you don't want to crowd the thread please pm me.
 
Hey I am loving WSE2 and I'm glad it is created, but I plan on swapping to linux and I saw that people got it to work via bottles but I would like to know how to perform it. And also I was curious if you lose on features compared to normally running it on windows. Thanks a bunch and if you don't want to crowd the thread please pm me.
I didn't test on linux, you'd better ask the people who did.
 
how do i fix this crash? it appears when i click play online in full invasion osiris mod
F50EE2A85F562034E420845B27B9B7EE40430E15

ps: i can't send the logs here bcs it's too long.
 
Back
Top Bottom