Subversion Repositories eduke32

Rev

Rev 8541 | Rev 8552 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8541 Rev 8551
Line 2877... Line 2877...
2877
#define PREAMBLETURN 5
2877
#define PREAMBLETURN  5
2878
#define NORMALKEYMOVE 40
2878
#define NORMALKEYMOVE 40
2879
#define MAXVEL       ((NORMALKEYMOVE*2)+10)
2879
#define MAXVEL        ((NORMALKEYMOVE*2)+10)
2880
#define MAXSVEL      ((NORMALKEYMOVE*2)+10)
2880
#define MAXSVEL       ((NORMALKEYMOVE*2)+10)
2881
#define MAXANGVEL    1024
2881
#define MAXANGVEL     1024
2882
#define MAXHORIZ     256
2882
#define MAXHORIZVEL   256
2883
2883
2884
int32_t g_myAimMode = 0, g_myAimStat = 0, g_oldAimStat = 0;
2884
int32_t g_myAimMode = 0, g_myAimStat = 0, g_oldAimStat = 0;
2885
int32_t mouseyaxismode = -1;
2885
int32_t mouseyaxismode = -1;
2886
2886
2887
static int P_CheckLockedMovement(int const playerNum)
2887
static int P_CheckLockedMovement(int const playerNum)
2888
{
2888
{
2889
    auto const pPlayer = g_player[playerNum].ps;
2889
    auto const pPlayer = g_player[playerNum].ps;
2890
    return (pPlayer->fist_incs || pPlayer->transporter_hold > 2 || pPlayer->hard_landing || pPlayer->access_incs > 0 || pPlayer->knee_incs > 0
2890
    return (pPlayer->dead_flag || pPlayer->fist_incs || pPlayer->transporter_hold > 2 || pPlayer->hard_landing || pPlayer->access_incs > 0 || pPlayer->knee_incs > 0
2891
            || (PWEAPON(playerNum, pPlayer->curr_weapon, WorksLike) == TRIPBOMB_WEAPON && pPlayer->kickback_pic > 1
2891
            || (PWEAPON(playerNum, pPlayer->curr_weapon, WorksLike) == TRIPBOMB_WEAPON && pPlayer->kickback_pic > 1
2892
                && pPlayer->kickback_pic < PWEAPON(playerNum, pPlayer->curr_weapon, FireDelay)));
2892
                && pPlayer->kickback_pic < PWEAPON(playerNum, pPlayer->curr_weapon, FireDelay)));
2893
}
2893
}
2894
2894
-
 
2895
static bool g_horizRecenter;
-
 
2896
static float g_horizAngleAdjust;
-
 
2897
static fix16_t g_horizSkew;
-
 
2898
2895
void P_GetInput(int const playerNum)
2899
void P_GetInput(int const playerNum)
2896
{
2900
{
2897
    auto const pPlayer = g_player[playerNum].ps;
2901
    auto const pPlayer = g_player[playerNum].ps;
2898
    ControlInfo info;
2902
    ControlInfo info;
2899
2903
2900
    if (g_cheatBufLen > 1 || (pPlayer->gm & (MODE_MENU|MODE_TYPE)) || (ud.pause_on && !KB_KeyPressed(sc_Pause)))
2904
    if (g_cheatBufLen > 1 || (pPlayer->gm & (MODE_MENU|MODE_TYPE)) || (ud.pause_on && !KB_KeyPressed(sc_Pause)))
2901
    {
2905
    {
2902
        if (!(pPlayer->gm&MODE_MENU))
2906
        if (!(pPlayer->gm&MODE_MENU))
2903
            CONTROL_GetInput(&info);
2907
            CONTROL_GetInput(&info);
2904
2908
2905
        Bmemset(&localInput, 0, sizeof(input_t));
2909
        localInput = {};
2906
-
 
2907
        localInput.bits    = (((int32_t)g_gameQuit) << SK_GAMEQUIT);
2910
        localInput.bits    = (((int32_t)g_gameQuit) << SK_GAMEQUIT);
2908
        localInput.extbits |= (1<<7);
2911
        localInput.extbits |= (1<<7);
2909
2912
2910
        return;
2913
        return;
2911
    }
2914
    }
Line 2950... Line 2953...
2950
    }
2953
    }
2951
2954
2952
    // JBF: Run key behaviour is selectable
2955
    // JBF: Run key behaviour is selectable
2953
    int const playerRunning = (ud.runkey_mode) ? (BUTTON(gamefunc_Run) | ud.auto_run) : (ud.auto_run ^ BUTTON(gamefunc_Run));
2956
    int const     playerRunning    = (ud.runkey_mode) ? (BUTTON(gamefunc_Run) | ud.auto_run) : (ud.auto_run ^ BUTTON(gamefunc_Run));
2954
    int const turnAmount = playerRunning ? (NORMALTURN << 1) : NORMALTURN;
2957
    int const     turnAmount       = playerRunning ? (NORMALTURN << 1) : NORMALTURN;
2955
    constexpr int const analogTurnAmount = (NORMALTURN << 1);
2958
    constexpr int analogTurnAmount = (NORMALTURN << 1);
2956
    int const keyMove    = playerRunning ? (NORMALKEYMOVE << 1) : NORMALKEYMOVE;
2959
    int const     keyMove          = playerRunning ? (NORMALKEYMOVE << 1) : NORMALKEYMOVE;
2957
    constexpr int const analogExtent = 32767; // KEEPINSYNC sdlayer.cpp
2960
    constexpr int analogExtent     = 32767;  // KEEPINSYNC sdlayer.cpp
2958
2961
2959
    input_t input {};
2962
    input_t input {};
2960
2963
2961
    if (BUTTON(gamefunc_Strafe))
2964
    if (BUTTON(gamefunc_Strafe))
2962
    {
2965
    {
Line 2967... Line 2970...
2967
2970
2968
        input.svel -= info.dyaw * keyMove / analogExtent;
2971
        input.svel -= info.dyaw * keyMove / analogExtent;
2969
    }
2972
    }
2970
    else
2973
    else
2971
    {
2974
    {
2972
        input.q16avel = fix16_div(fix16_from_int(info.mousex), F16(32));
2975
        input.q16avel += fix16_div(fix16_from_int(info.mousex), F16(32));
2973
        input.q16avel += fix16_from_int(info.dyaw) / analogExtent * (analogTurnAmount << 1);
2976
        input.q16avel += fix16_from_int(info.dyaw) / analogExtent * (analogTurnAmount << 1);
2974
    }
2977
    }
2975
2978
2976
    if (g_myAimMode)
2979
    if (g_myAimMode)
2977
        input.q16horz = fix16_div(fix16_from_int(info.mousey), F16(64));
2980
        input.q16horz += fix16_div(fix16_from_int(info.mousey), F16(64));
2978
    else
2981
    else
2979
        input.fvel = -(info.mousey >> 3);
2982
        input.fvel = -(info.mousey >> 3);
2980
2983
2981
    if (ud.mouseflip) input.q16horz = -input.q16horz;
2984
    if (ud.mouseflip) input.q16horz = -input.q16horz;
2982
2985
2983
    input.q16horz -= fix16_from_int(info.dpitch) / analogExtent * analogTurnAmount;
2986
    input.q16horz -= fix16_from_int(info.dpitch) / analogExtent * analogTurnAmount;
2984
    input.svel -= info.dx * keyMove / analogExtent;
2987
    input.svel -= info.dx * keyMove / analogExtent;
2985
    input.fvel -= info.dz * keyMove / analogExtent;
2988
    input.fvel -= info.dz * keyMove / analogExtent;
2986
2989
-
 
2990
    static double lastInputTicks;
-
 
2991
    auto const    currentHiTicks    = timerGetHiTicks();
-
 
2992
    double const  elapsedInputTicks = currentHiTicks - lastInputTicks;
-
 
2993
-
 
2994
    lastInputTicks = currentHiTicks;
-
 
2995
-
 
2996
    auto scaleAdjustmentToInterval = [=](double x) { return x * REALGAMETICSPERSEC / (1000.0 / elapsedInputTicks); };
-
 
2997
2987
    if (BUTTON(gamefunc_Strafe))
2998
    if (BUTTON(gamefunc_Strafe))
2988
    {
2999
    {
-
 
3000
        if (!localInput.svel)
-
 
3001
        {
2989
        if (BUTTON(gamefunc_Turn_Left) && !(pPlayer->movement_lock&4))
3002
            if (BUTTON(gamefunc_Turn_Left) && !(pPlayer->movement_lock & 4) && !localInput.svel)
2990
            input.svel -= -keyMove;
3003
                input.svel = -keyMove;
2991
3004
2992
        if (BUTTON(gamefunc_Turn_Right) && !(pPlayer->movement_lock&8))
3005
            if (BUTTON(gamefunc_Turn_Right) && !(pPlayer->movement_lock & 8) && !localInput.svel)
2993
            input.svel -= keyMove;
3006
                input.svel = keyMove;
-
 
3007
        }
2994
    }
3008
    }
2995
    else
3009
    else
2996
    {
3010
    {
2997
        static int32_t turnHeldTime   = 0;
3011
        static int32_t turnHeldTime;
2998
        static int32_t lastInputClock = 0;  // MED
3012
        static int32_t lastInputClock;  // MED
2999
        int32_t const  elapsedTics    = (int32_t) totalclock - lastInputClock;
3013
        int32_t const  elapsedTics = (int32_t)totalclock - lastInputClock;
3000
3014
3001
        lastInputClock = (int32_t) totalclock;
3015
        lastInputClock = (int32_t) totalclock;
3002
3016
3003
        if (BUTTON(gamefunc_Turn_Left))
3017
        if (BUTTON(gamefunc_Turn_Left))
3004
        {
3018
        {
3005
            turnHeldTime += elapsedTics;
3019
            turnHeldTime += elapsedTics;
3006
            input.q16avel -= fix16_from_int((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1));
3020
            input.q16avel -= fix16_from_float(scaleAdjustmentToInterval((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1)));
3007
        }
3021
        }
3008
        else if (BUTTON(gamefunc_Turn_Right))
3022
        else if (BUTTON(gamefunc_Turn_Right))
3009
        {
3023
        {
3010
            turnHeldTime += elapsedTics;
3024
            turnHeldTime += elapsedTics;
3011
            input.q16avel += fix16_from_int((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1));
3025
            input.q16avel += fix16_from_float(scaleAdjustmentToInterval((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1)));
3012
        }
3026
        }
3013
        else
3027
        else
3014
            turnHeldTime=0;
3028
            turnHeldTime = 0;
3015
    }
3029
    }
3016
3030
-
 
3031
    if (localInput.svel < keyMove && localInput.svel > -keyMove)
-
 
3032
    {
3017
    if (BUTTON(gamefunc_Strafe_Left) && !(pPlayer->movement_lock & 4))
3033
        if (BUTTON(gamefunc_Strafe_Left) && !(pPlayer->movement_lock & 4))
3018
        input.svel += keyMove;
3034
            input.svel += keyMove;
3019
3035
3020
    if (BUTTON(gamefunc_Strafe_Right) && !(pPlayer->movement_lock & 8))
3036
        if (BUTTON(gamefunc_Strafe_Right) && !(pPlayer->movement_lock & 8))
3021
        input.svel += -keyMove;
3037
            input.svel += -keyMove;
-
 
3038
    }
3022
3039
-
 
3040
    if (localInput.fvel < keyMove && localInput.fvel > -keyMove)
-
 
3041
    {
3023
    if (BUTTON(gamefunc_Move_Forward) && !(pPlayer->movement_lock & 1))
3042
        if (BUTTON(gamefunc_Move_Forward) && !(pPlayer->movement_lock & 1))
3024
        input.fvel += keyMove;
3043
            input.fvel += keyMove;
3025
3044
3026
    if (BUTTON(gamefunc_Move_Backward) && !(pPlayer->movement_lock & 2))
3045
        if (BUTTON(gamefunc_Move_Backward) && !(pPlayer->movement_lock & 2))
3027
        input.fvel += -keyMove;
3046
            input.fvel += -keyMove;
3028
-
 
3029
    input.fvel = clamp(input.fvel, -MAXVEL, MAXVEL);
-
 
3030
    input.svel = clamp(input.svel, -MAXSVEL, MAXSVEL);
-
 
3031
3047
    }
3032
    input.q16avel = fix16_clamp(input.q16avel, F16(-MAXANGVEL), F16(MAXANGVEL));
-
 
3033
    input.q16horz = fix16_clamp(input.q16horz, F16(-MAXHORIZ), F16(MAXHORIZ));
-
 
3034
3048
3035
    int weaponSelection;
3049
    int weaponSelection;
3036
3050
3037
    for (weaponSelection = gamefunc_Weapon_10; weaponSelection >= gamefunc_Weapon_1; --weaponSelection)
3051
    for (weaponSelection = gamefunc_Weapon_10; weaponSelection >= gamefunc_Weapon_1; --weaponSelection)
3038
    {
3052
    {
Line 3052... Line 3066...
3052
    else if (BUTTON(gamefunc_Previous_Weapon) || (BUTTON(gamefunc_Dpad_Select) && input.fvel < 0))
3066
    else if (BUTTON(gamefunc_Previous_Weapon) || (BUTTON(gamefunc_Dpad_Select) && input.fvel < 0))
3053
        weaponSelection = 11;
3067
        weaponSelection = 11;
3054
    else if (weaponSelection == gamefunc_Weapon_1-1)
3068
    else if (weaponSelection == gamefunc_Weapon_1-1)
3055
        weaponSelection = 0;
3069
        weaponSelection = 0;
3056
3070
-
 
3071
    if ((localInput.bits & 0xf00) == 0)
-
 
3072
        localInput.bits |= (weaponSelection << SK_WEAPON_BITS);
-
 
3073
3057
    localInput.bits = (weaponSelection << SK_WEAPON_BITS) | (BUTTON(gamefunc_Fire) << SK_FIRE);
3074
    localInput.bits |= (BUTTON(gamefunc_Fire) << SK_FIRE);
3058
    localInput.bits |= (BUTTON(gamefunc_Open) << SK_OPEN);
3075
    localInput.bits |= (BUTTON(gamefunc_Open) << SK_OPEN);
3059
3076
3060
    int const sectorLotag = pPlayer->cursectnum != -1 ? sector[pPlayer->cursectnum].lotag : 0;
3077
    int const sectorLotag = pPlayer->cursectnum != -1 ? sector[pPlayer->cursectnum].lotag : 0;
3061
    int const crouchable = sectorLotag != 2 && (sectorLotag != 1 || pPlayer->spritebridge) && !pPlayer->jetpack_on;
3078
    int const crouchable = sectorLotag != 2 && (sectorLotag != 1 || pPlayer->spritebridge) && !pPlayer->jetpack_on;
3062
3079
Line 3114... Line 3131...
3114
        input.fvel = 0;
3131
        input.fvel = 0;
3115
3132
3116
    if (PWEAPON(playerNum, pPlayer->curr_weapon, Flags) & WEAPON_SEMIAUTO && BUTTON(gamefunc_Fire))
3133
    if (PWEAPON(playerNum, pPlayer->curr_weapon, Flags) & WEAPON_SEMIAUTO && BUTTON(gamefunc_Fire))
3117
        CONTROL_ClearButton(gamefunc_Fire);
3134
        CONTROL_ClearButton(gamefunc_Fire);
3118
3135
3119
    localInput.extbits = (BUTTON(gamefunc_Move_Forward) || (input.fvel > 0));
3136
    localInput.extbits |= (BUTTON(gamefunc_Move_Forward) || (input.fvel > 0));
3120
    localInput.extbits |= (BUTTON(gamefunc_Move_Backward) || (input.fvel < 0)) << 1;
3137
    localInput.extbits |= (BUTTON(gamefunc_Move_Backward) || (input.fvel < 0)) << 1;
3121
    localInput.extbits |= (BUTTON(gamefunc_Strafe_Left) || (input.svel > 0)) << 2;
3138
    localInput.extbits |= (BUTTON(gamefunc_Strafe_Left) || (input.svel > 0)) << 2;
3122
    localInput.extbits |= (BUTTON(gamefunc_Strafe_Right) || (input.svel < 0)) << 3;
3139
    localInput.extbits |= (BUTTON(gamefunc_Strafe_Right) || (input.svel < 0)) << 3;
3123
    localInput.extbits |= BUTTON(gamefunc_Turn_Left)<<4;
3140
    localInput.extbits |= BUTTON(gamefunc_Turn_Left)<<4;
3124
    localInput.extbits |= BUTTON(gamefunc_Turn_Right)<<5;
3141
    localInput.extbits |= BUTTON(gamefunc_Turn_Right)<<5;
3125
    localInput.extbits |= BUTTON(gamefunc_Alt_Fire)<<6;
3142
    localInput.extbits |= BUTTON(gamefunc_Alt_Fire)<<6;
3126
3143
-
 
3144
    if ((ud.scrollmode && ud.overhead_on) || P_CheckLockedMovement(playerNum))
-
 
3145
    {
3127
    if (ud.scrollmode && ud.overhead_on)
3146
        if (ud.scrollmode && ud.overhead_on)
3128
    {
3147
        {
3129
        ud.folfvel = input.fvel;
3148
            ud.folfvel = input.fvel;
3130
        ud.folavel = fix16_to_int(input.q16avel);
3149
            ud.folavel = fix16_to_int(input.q16avel);
-
 
3150
        }
3131
3151
3132
        localInput.fvel = 0;
3152
        localInput.fvel = 0;
3133
        localInput.svel = 0;
3153
        localInput.svel = 0;
3134
3154
3135
        localInput.q16avel = 0;
3155
        localInput.q16avel = 0;
3136
        localInput.q16horz = 0;
3156
        localInput.q16horz = 0;
-
 
3157
    }
-
 
3158
    else
-
 
3159
    {
-
 
3160
        localInput.q16avel = fix16_add(localInput.q16avel, input.q16avel);
-
 
3161
        localInput.q16horz = fix16_clamp(fix16_add(localInput.q16horz, input.q16horz), F16(-MAXHORIZVEL), F16(MAXHORIZVEL));
-
 
3162
        localInput.fvel    = clamp(localInput.fvel + input.fvel, -MAXVEL, MAXVEL);
-
 
3163
        localInput.svel    = clamp(localInput.svel + input.svel, -MAXSVEL, MAXSVEL);
3137
3164
-
 
3165
        pPlayer->q16ang = fix16_add(pPlayer->q16ang, input.q16avel);
-
 
3166
        pPlayer->q16ang &= 0x7FFFFFF;
-
 
3167
-
 
3168
        pPlayer->q16horiz = fix16_clamp(fix16_add(pPlayer->q16horiz, input.q16horz), F16(HORIZ_MIN), F16(HORIZ_MAX));
-
 
3169
    }
-
 
3170
-
 
3171
    // A horiz diff of 128 equal 45 degrees,
-
 
3172
    // so we convert horiz to 1024 angle units
-
 
3173
-
 
3174
    if (g_horizAngleAdjust)
-
 
3175
    {
-
 
3176
        float const horizAngle
-
 
3177
        = atan2f(pPlayer->q16horiz - F16(100), F16(128)) * (512.f / fPI) + scaleAdjustmentToInterval(g_horizAngleAdjust);
-
 
3178
        pPlayer->q16horiz = F16(100) + Blrintf(F16(128) * tanf(horizAngle * (fPI / 512.f)));
-
 
3179
    }
-
 
3180
    else if (pPlayer->return_to_center > 0 || g_horizRecenter)
-
 
3181
    {
-
 
3182
        pPlayer->q16horiz += fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(F16(33) - fix16_div(pPlayer->q16horiz, F16(3)))));
-
 
3183
-
 
3184
        if (pPlayer->q16horiz >= F16(99.9) && pPlayer->q16horiz <= F16(100.1))
-
 
3185
        {
-
 
3186
            pPlayer->q16horiz = F16(100);
-
 
3187
            g_horizRecenter   = 0;
3138
        return;
3188
        }
-
 
3189
-
 
3190
        if (pPlayer->q16horizoff >= F16(-0.1) && pPlayer->q16horizoff <= F16(0.1))
-
 
3191
            pPlayer->q16horizoff = 0;
3139
    }
3192
    }
3140
3193
-
 
3194
    // calculates automatic view angle for playing without a mouse
-
 
3195
    if (!pPlayer->aim_mode && pPlayer->on_ground && sectorLotag != ST_2_UNDERWATER && (sector[pPlayer->cursectnum].floorstat & 2))
-
 
3196
    {
-
 
3197
        // this is some kind of horse shit approximation of where the player is looking, I guess?
-
 
3198
        vec2_t const adjustedPosition = { pPlayer->pos.x + (sintable[(fix16_to_int(pPlayer->q16ang) + 512) & 2047] >> 5),
-
 
3199
                                          pPlayer->pos.y + (sintable[fix16_to_int(pPlayer->q16ang) & 2047] >> 5) };
3141
    int16_t const q16ang = fix16_to_int(pPlayer->q16ang);
3200
        int16_t currentSector = pPlayer->cursectnum;
3142
3201
3143
    localInput.fvel = mulscale9(input.fvel, sintable[(q16ang + 2560) & 2047]) +
-
 
3144
                      mulscale9(input.svel, sintable[(q16ang + 2048) & 2047]) +
-
 
3145
                      (FURY ? 0 : pPlayer->fric.x);
-
 
3146
-
 
3147
    localInput.svel = mulscale9(input.fvel, sintable[(q16ang + 2048) & 2047]) +
-
 
3148
                      mulscale9(input.svel, sintable[(q16ang + 1536) & 2047]) +
3202
        updatesector(adjustedPosition.x, adjustedPosition.y, &currentSector);
3149
                      (FURY ? 0 : pPlayer->fric.y);
-
 
3150
3203
-
 
3204
        if (currentSector >= 0)
-
 
3205
        {
-
 
3206
            int const slopeZ = getflorzofslope(pPlayer->cursectnum, adjustedPosition.x, adjustedPosition.y);
-
 
3207
            if ((pPlayer->cursectnum == currentSector) || (klabs(getflorzofslope(currentSector, adjustedPosition.x, adjustedPosition.y) - slopeZ) <= ZOFFSET6))
-
 
3208
                pPlayer->q16horizoff += fix16_from_float(scaleAdjustmentToInterval(mulscale16(pPlayer->truefz - slopeZ, 160)));
-
 
3209
        }
-
 
3210
    }
-
 
3211
-
 
3212
    if (pPlayer->q16horizoff > 0)
-
 
3213
    {
-
 
3214
        pPlayer->q16horizoff -= fix16_from_float(scaleAdjustmentToInterval(fix16_to_float((pPlayer->q16horizoff >> 3) + fix16_one)));
-
 
3215
        pPlayer->q16horizoff = fix16_max(pPlayer->q16horizoff, 0);
-
 
3216
    }
3151
    localInput.q16avel = input.q16avel;
3217
    else if (pPlayer->q16horizoff < 0)
-
 
3218
    {
-
 
3219
        pPlayer->q16horizoff += fix16_from_float(scaleAdjustmentToInterval(fix16_to_float((-pPlayer->q16horizoff >> 3) + fix16_one)));
3152
    localInput.q16horz = input.q16horz;
3220
        pPlayer->q16horizoff = fix16_min(pPlayer->q16horizoff, 0);
-
 
3221
    }
-
 
3222
-
 
3223
    if (g_horizSkew)
-
 
3224
        pPlayer->q16horiz += fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(g_horizSkew)));
-
 
3225
-
 
3226
    pPlayer->q16horiz = fix16_clamp(pPlayer->q16horiz, F16(HORIZ_MIN), F16(HORIZ_MAX));
3153
}
3227
}
3154
3228
3155
static int32_t P_DoCounters(int playerNum)
3229
static int32_t P_DoCounters(int playerNum)
3156
{
3230
{
3157
    auto const pPlayer = g_player[playerNum].ps;
3231
    auto const pPlayer = g_player[playerNum].ps;
Line 4651... Line 4725...
4651
4725
4652
#define GETZRANGECLIPDISTOFFSET 8
4726
#define GETZRANGECLIPDISTOFFSET 8
4653
4727
4654
void P_ProcessInput(int playerNum)
4728
void P_ProcessInput(int playerNum)
4655
{
4729
{
-
 
4730
    g_horizAngleAdjust = 0;
-
 
4731
    g_horizSkew = 0;
-
 
4732
4656
    if (g_player[playerNum].playerquitflag == 0)
4733
    if (g_player[playerNum].playerquitflag == 0)
4657
        return;
4734
        return;
4658
4735
4659
    auto const pPlayer = g_player[playerNum].ps;
4736
    auto const pPlayer = g_player[playerNum].ps;
4660
    auto const pSprite = &sprite[pPlayer->i];
4737
    auto const pSprite = &sprite[pPlayer->i];
Line 4721... Line 4798...
4721
    actor[pPlayer->i].ceilingz = ceilZ;
4798
    actor[pPlayer->i].ceilingz = ceilZ;
4722
4799
4723
    pPlayer->oq16horiz    = pPlayer->q16horiz;
4800
    pPlayer->oq16horiz    = pPlayer->q16horiz;
4724
    pPlayer->oq16horizoff = pPlayer->q16horizoff;
4801
    pPlayer->oq16horizoff = pPlayer->q16horizoff;
4725
4802
4726
    // calculates automatic view angle for playing without a mouse
-
 
4727
    if (pPlayer->aim_mode == 0 && pPlayer->on_ground && sectorLotag != ST_2_UNDERWATER
-
 
4728
        && (sector[pPlayer->cursectnum].floorstat & 2))
-
 
4729
    {
-
 
4730
        vec2_t const adjustedPlayer = { pPlayer->pos.x + (sintable[(fix16_to_int(pPlayer->q16ang) + 512) & 2047] >> 5),
-
 
4731
                                        pPlayer->pos.y + (sintable[fix16_to_int(pPlayer->q16ang) & 2047] >> 5) };
-
 
4732
        int16_t curSectNum = pPlayer->cursectnum;
-
 
4733
-
 
4734
        updatesector(adjustedPlayer.x, adjustedPlayer.y, &curSectNum);
-
 
4735
-
 
4736
        if (curSectNum >= 0)
-
 
4737
        {
-
 
4738
            int const slopeZ = getflorzofslope(pPlayer->cursectnum, adjustedPlayer.x, adjustedPlayer.y);
-
 
4739
            if ((pPlayer->cursectnum == curSectNum) ||
-
 
4740
                (klabs(getflorzofslope(curSectNum, adjustedPlayer.x, adjustedPlayer.y) - slopeZ) <= ZOFFSET6))
-
 
4741
                pPlayer->q16horizoff += fix16_from_int(mulscale16(trueFloorZ - slopeZ, 160));
-
 
4742
        }
-
 
4743
    }
-
 
4744
-
 
4745
    if (pPlayer->q16horizoff > 0)
-
 
4746
    {
-
 
4747
        pPlayer->q16horizoff -= ((pPlayer->q16horizoff >> 3) + fix16_one);
-
 
4748
        pPlayer->q16horizoff = max(pPlayer->q16horizoff, 0);
-
 
4749
    }
-
 
4750
    else if (pPlayer->q16horizoff < 0)
-
 
4751
    {
-
 
4752
        pPlayer->q16horizoff += (((-pPlayer->q16horizoff) >> 3) + fix16_one);
-
 
4753
        pPlayer->q16horizoff = min(pPlayer->q16horizoff, 0);
-
 
4754
    }
-
 
4755
-
 
4756
    if ((highZhit & 49152) == 49152)
4803
    if ((highZhit & 49152) == 49152)
4757
    {
4804
    {
4758
        int const spriteNum = highZhit & (MAXSPRITES-1);
4805
        int const spriteNum = highZhit & (MAXSPRITES-1);
4759
4806
4760
        if (sprite[spriteNum].statnum == STAT_ACTOR && sprite[spriteNum].extra >= 0)
4807
        if (sprite[spriteNum].statnum == STAT_ACTOR && sprite[spriteNum].extra >= 0)
Line 5069... Line 5116...
5069
#ifndef EDUKE32_STANDALONE
5116
#ifndef EDUKE32_STANDALONE
5070
                        else if (!FURY && pPlayer->vel.z > 2048)
5117
                        else if (!FURY && pPlayer->vel.z > 2048)
5071
                            A_PlaySound(DUKE_LAND, pPlayer->i);
5118
                            A_PlaySound(DUKE_LAND, pPlayer->i);
5072
#endif
5119
#endif
5073
                    }
5120
                    }
5074
                    pPlayer->on_ground = 1;
-
 
5075
                }
5121
                }
5076
                else
5122
                else
5077
                    pPlayer->on_ground = 0;
5123
                    pPlayer->on_ground = 0;
5078
            }
5124
            }
5079
        }
5125
        }
Line 5088... Line 5134...
5088
                pPlayer->scream_voice = -1;
5134
                pPlayer->scream_voice = -1;
5089
            }
5135
            }
5090
5136
5091
            if ((sectorLotag != ST_1_ABOVE_WATER && sectorLotag != ST_2_UNDERWATER) &&
5137
            if ((sectorLotag != ST_1_ABOVE_WATER && sectorLotag != ST_2_UNDERWATER) &&
5092
                (pPlayer->on_ground == 0 && pPlayer->vel.z > (6144 >> 1)))
5138
                (pPlayer->on_ground == 0 && pPlayer->vel.z > (6144 >> 1)))
-
 
5139
            {
5093
                pPlayer->hard_landing = pPlayer->vel.z>>10;
5140
                pPlayer->hard_landing = pPlayer->vel.z >> 10;
-
 
5141
            }
5094
5142
5095
            pPlayer->on_ground = 1;
5143
            pPlayer->on_ground = 1;
5096
5144
5097
            if (floorZOffset==40)
5145
            if (floorZOffset==40)
5098
            {
5146
            {
Line 5198... Line 5246...
5198
    {
5246
    {
5199
        velocityModifier = 0;
5247
        velocityModifier = 0;
5200
        pPlayer->vel.x   = 0;
5248
        pPlayer->vel.x   = 0;
5201
        pPlayer->vel.y   = 0;
5249
        pPlayer->vel.y   = 0;
5202
    }
5250
    }
5203
    else if (g_player[playerNum].input->q16avel)            //p->ang += syncangvel * constant
-
 
5204
    {
-
 
5205
        fix16_t const inputAng  = g_player[playerNum].input->q16avel;
5251
    else if (g_player[playerNum].input->q16avel)
5206
-
 
5207
        pPlayer->q16angvel     = (sectorLotag == ST_2_UNDERWATER) ? fix16_mul(inputAng - (inputAng >> 3), fix16_from_int(ksgn(velocityModifier)))
-
 
5208
                                                               : fix16_mul(inputAng, fix16_from_int(ksgn(velocityModifier)));
-
 
5209
        pPlayer->q16ang       += pPlayer->q16angvel;
-
 
5210
        pPlayer->q16ang       &= 0x7FFFFFF;
-
 
5211
        pPlayer->crack_time = PCRACKTIME;
5252
        pPlayer->crack_time = PCRACKTIME;
5212
    }
-
 
5213
5253
5214
    if (pPlayer->spritebridge == 0)
5254
    if (pPlayer->spritebridge == 0)
5215
    {
5255
    {
5216
        int const floorPicnum = sector[pSprite->sectnum].floorpicnum;
5256
        int const floorPicnum = sector[pSprite->sectnum].floorpicnum;
5217
5257
Line 5467... Line 5507...
5467
        }
5507
        }
5468
        else if (klabs(floorZ - ceilZ) < ZOFFSET5 && isanunderoperator(sector[pPlayer->cursectnum].lotag))
5508
        else if (klabs(floorZ - ceilZ) < ZOFFSET5 && isanunderoperator(sector[pPlayer->cursectnum].lotag))
5469
            G_ActivateBySector(pPlayer->cursectnum, pPlayer->i);
5509
            G_ActivateBySector(pPlayer->cursectnum, pPlayer->i);
5470
    }
5510
    }
5471
5511
-
 
5512
    if (pPlayer->return_to_center > 0)
-
 
5513
    {
-
 
5514
        pPlayer->return_to_center--;
5472
    int centerHoriz = 0;
5515
        g_horizRecenter = true;
-
 
5516
    }
5473
5517
5474
    if (TEST_SYNC_KEY(playerBits, SK_CENTER_VIEW) || pPlayer->hard_landing)
5518
    if (TEST_SYNC_KEY(playerBits, SK_CENTER_VIEW) || pPlayer->hard_landing)
5475
        if (VM_OnEvent(EVENT_RETURNTOCENTER,pPlayer->i,playerNum) == 0)
5519
        if (VM_OnEvent(EVENT_RETURNTOCENTER, pPlayer->i,playerNum) == 0)
5476
            pPlayer->return_to_center = 9;
5520
            pPlayer->return_to_center = 9;
5477
5521
5478
    // A horiz diff of 128 equal 45 degrees,
-
 
5479
    // so we convert horiz to 1024 angle units
-
 
5480
-
 
5481
    float horizAngle = atan2f(pPlayer->q16horiz - F16(100), F16(128)) * (512.f / fPI) + fix16_to_float(g_player[playerNum].input->q16horz);
-
 
5482
-
 
5483
    if (TEST_SYNC_KEY(playerBits, SK_LOOK_UP))
5522
    if (TEST_SYNC_KEY(playerBits, SK_LOOK_UP))
5484
    {
5523
    {
5485
        if (VM_OnEvent(EVENT_LOOKUP,pPlayer->i,playerNum) == 0)
5524
        if (VM_OnEvent(EVENT_LOOKUP,pPlayer->i,playerNum) == 0)
5486
        {
5525
        {
5487
            pPlayer->return_to_center = 9;
5526
            pPlayer->return_to_center = 9;
5488
            horizAngle += float(12<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN)));
5527
            g_horizAngleAdjust = float(12<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN)));
5489
            centerHoriz++;
-
 
5490
        }
5528
        }
5491
    }
5529
    }
5492
5530
5493
    if (TEST_SYNC_KEY(playerBits, SK_LOOK_DOWN))
5531
    if (TEST_SYNC_KEY(playerBits, SK_LOOK_DOWN))
5494
    {
5532
    {
5495
        if (VM_OnEvent(EVENT_LOOKDOWN,pPlayer->i,playerNum) == 0)
5533
        if (VM_OnEvent(EVENT_LOOKDOWN,pPlayer->i,playerNum) == 0)
5496
        {
5534
        {
5497
            pPlayer->return_to_center = 9;
5535
            pPlayer->return_to_center = 9;
5498
            horizAngle -= float(12<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN)));
5536
            g_horizAngleAdjust = -float(12<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN)));
5499
            centerHoriz++;
-
 
5500
        }
5537
        }
5501
    }
5538
    }
5502
5539
5503
    if (TEST_SYNC_KEY(playerBits, SK_AIM_UP))
5540
    if (TEST_SYNC_KEY(playerBits, SK_AIM_UP))
5504
    {
5541
    {
5505
        if (VM_OnEvent(EVENT_AIMUP,pPlayer->i,playerNum) == 0)
5542
        if (VM_OnEvent(EVENT_AIMUP,pPlayer->i,playerNum) == 0)
5506
        {
5543
        {
5507
            horizAngle += float(6<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN)));
5544
            g_horizAngleAdjust = float(6 << (int)(TEST_SYNC_KEY(playerBits, SK_RUN)));
5508
            centerHoriz++;
5545
            g_horizRecenter    = false;
5509
        }
5546
        }
5510
    }
5547
    }
5511
5548
5512
    if (TEST_SYNC_KEY(playerBits, SK_AIM_DOWN))
5549
    if (TEST_SYNC_KEY(playerBits, SK_AIM_DOWN))
5513
    {
5550
    {
5514
        if (VM_OnEvent(EVENT_AIMDOWN,pPlayer->i,playerNum) == 0)
5551
        if (VM_OnEvent(EVENT_AIMDOWN,pPlayer->i,playerNum) == 0)
5515
        {
5552
        {
5516
            horizAngle -= float(6<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN)));
5553
            g_horizAngleAdjust = -float(6 << (int)(TEST_SYNC_KEY(playerBits, SK_RUN)));
5517
            centerHoriz++;
5554
            g_horizRecenter    = false;
5518
        }
5555
        }
5519
    }
5556
    }
5520
5557
5521
    pPlayer->q16horiz = F16(100) + Blrintf(F16(128) * tanf(horizAngle * (fPI / 512.f)));
-
 
5522
-
 
5523
    if (pPlayer->return_to_center > 0 && !TEST_SYNC_KEY(playerBits, SK_LOOK_UP) && !TEST_SYNC_KEY(playerBits, SK_LOOK_DOWN))
-
 
5524
    {
-
 
5525
        pPlayer->return_to_center--;
-
 
5526
        pPlayer->q16horiz += F16(33)-fix16_div(pPlayer->q16horiz, F16(3));
-
 
5527
        centerHoriz++;
-
 
5528
    }
-
 
5529
-
 
5530
    if (pPlayer->hard_landing > 0)
5558
    if (pPlayer->hard_landing > 0)
5531
    {
5559
    {
-
 
5560
        g_horizSkew = fix16_from_int(-(pPlayer->hard_landing << 4));
5532
        pPlayer->hard_landing--;
5561
        pPlayer->hard_landing--;
5533
        pPlayer->q16horiz -= fix16_from_int(pPlayer->hard_landing<<4);
-
 
5534
    }
5562
    }
5535
5563
5536
    if (centerHoriz)
-
 
5537
    {
-
 
5538
        if (pPlayer->q16horiz > F16(95) && pPlayer->q16horiz < F16(105)) pPlayer->q16horiz = F16(100);
-
 
5539
        if (pPlayer->q16horizoff > F16(-5) && pPlayer->q16horizoff < F16(5)) pPlayer->q16horizoff = 0;
-
 
5540
    }
-
 
5541
-
 
5542
    pPlayer->q16horiz = fix16_clamp(pPlayer->q16horiz, F16(HORIZ_MIN), F16(HORIZ_MAX));
-
 
5543
-
 
5544
    //Shooting code/changes
5564
    //Shooting code/changes
5545
5565
5546
    if (pPlayer->show_empty_weapon > 0)
5566
    if (pPlayer->show_empty_weapon > 0)
5547
    {
5567
    {
5548
        --pPlayer->show_empty_weapon;
5568
        --pPlayer->show_empty_weapon;
Line 5564... Line 5584...
5564
    }
5584
    }
5565
5585
5566
#ifndef EDUKE32_STANDALONE
5586
#ifndef EDUKE32_STANDALONE
5567
    if (!FURY && pPlayer->knee_incs > 0)
5587
    if (!FURY && pPlayer->knee_incs > 0)
5568
    {
5588
    {
5569
        pPlayer->q16horiz -= F16(48);
5589
        g_horizSkew = F16(-48);
5570
        pPlayer->return_to_center = 9;
5590
        pPlayer->return_to_center = 9;
5571
5591
5572
        if (++pPlayer->knee_incs > 15)
5592
        if (++pPlayer->knee_incs > 15)
5573
        {
5593
        {
5574
            pPlayer->knee_incs      = 0;
5594
            pPlayer->knee_incs      = 0;