avoitishin / xray-16

XRAY 16 Engine Modifications
Other
10 stars 6 forks source link

Shotgun spread #29

Open denanden opened 9 years ago

denanden commented 9 years ago

Right now the spread depends on stance, aiming, crouching etc. which is total nonsense for a shotgun loaded with shot. These factors should only affect the gun when using slugs. Suggested change:

float CActor::GetWeaponAccuracy() const
{
    CEntity::SEntityState state;

    if (g_State(state))
    {
        CWeapon* W = smart_cast<CWeapon*>(inventory().ActiveItem());
        int buckShot = 0;

        if (W != NULL)
        {
            if (!W->m_magazine.empty())
            {
                buckShot = W->m_magazine.back().param_s.buckShot;
            }
            else
            {
                CWeaponAmmo *pAmmo = (W->m_pCurrentAmmo != NULL) ? W->m_pCurrentAmmo : smart_cast<CWeaponAmmo*>(W->m_pInventory->GetAny(W->m_ammoTypes[W->m_ammoType].c_str()));
                buckShot = (pAmmo != NULL) ? pAmmo->cartridge_param.buckShot : 0;
            }
        }

        if (buckShot > 1)
        return 0.0;

        float dispersion = m_fDispBase * GetWeaponParam(W, Get_PDM_Base(), 1.0f);

        if ( IsZoomAimingMode() && W && !GetWeaponParam(W, IsRotatingToZoom(), false) )
        {
            return m_fDispAim;
        }

        //fAVelocity = angle velocity
        dispersion *= ( 1.0f + (state.fAVelocity/VEL_A_MAX) * m_fDispVelFactor * GetWeaponParam(W, Get_PDM_Vel_F(), 1.0f) );
        //fVelocity = linear velocity
        dispersion *= ( 1.0f + (state.fVelocity/VEL_MAX) * m_fDispVelFactor * GetWeaponParam(W, Get_PDM_Vel_F(), 1.0f) );

        bool bAccelerated = isActorAccelerated( mstate_real, IsZoomAimingMode() );
        if ( bAccelerated || !state.bCrouch )
        {
            dispersion *= ( 1.0f + m_fDispAccelFactor * GetWeaponParam(W, Get_PDM_Accel_F(), 1.0f) );
        }

        if ( state.bCrouch )
        {    
            dispersion *= ( 1.0f + m_fDispCrouchFactor * GetWeaponParam(W, Get_PDM_Crouch(), 1.0f) );
            if ( !bAccelerated )
            {
                dispersion *= ( 1.0f + m_fDispCrouchNoAccelFactor * GetWeaponParam(W, Get_PDM_Crouch_NA(), 1.0f) );
            }
        }
        return dispersion;
    }
}
Shotgunsurgeon commented 9 years ago

Its not nonsense, as these still factor in. Supporting an 8 pound longarm, managing recoil with muscular tension, skeletal positioning and dealing with the constant motions of the human body introduce undesirable motion when aiming. Improving support and stability will reduce this. Just because pellets separate does not mean that the shooter does not introduce their own variability. Granted, the spread is ludicrous in game, thus shooter sway is somewhat moot. This issue is mostly resolvable by editing the .ltx files.

denanden commented 9 years ago

It is not resolvable by editing the .ltx files without affecting the accuracy of slug rounds.

ghost commented 9 years ago

@Shotgunsurgeon : I'm sorry but you're a bit wrong and denanden is correct. When you move around, the spread of a shotgun does NOT increase, ever. You are correct though that there are all sorts of factor that introduce instability to firing, and we do need some sort of code I think that makes it so shotguns are inaccurate when moving, but done in a different way.

A more realistic approach, would be to have it so that when moving the shotgun has a chance to deviate and fire away from the center of the screen or something. There's some code for deviation_yaw and deviation_pitch on xp-dev.com that could come in handy for a feature like this.

Shotgunsurgeon commented 9 years ago

@Swartz27 are you sure? Weapons.ltx specifies k_disp for ammo types, which allows for different ammo types to have varying levels of accuracy. In the repo, you can see that buckshot has a dispersion value of 15, while a slug (zhekan) has only 1. This reflects the ingame accuracy of each. If one wants more accurate buckshot, then reduce its k_disp value (line 724 in the repo's version). This way, pellet spread can be modified independent of slug accuracy.

ghost commented 9 years ago

I don't think you understand what I meant, maybe I wasn't clear: in real-life, a shotgun's spread should never increase due to posture or instability. Shotguns simply do not work like that. I know we can modify k_disp.

Shotgunsurgeon commented 9 years ago

So you're saying that rather than have the shot fill the entirety of the crosshair, have it fill a smaller circle that moves around within the crosshair? If so, then that would make sense.

ghost commented 9 years ago

I hadn't thought of it that way, but yeah that would work. I was thinking more along the lines of this code though: https://xp-dev.com/sc/change/204486/164 I've tested it and trying a value of say 0.1 for both will throw your shot up and to the left of the crosshair. Probably not the best system though as we do want to use the crosshair for something, so your idea is better.