Do not let nonspin characters enter sectors they could not enter if standing at full height

This commit is contained in:
lachablock 2021-03-23 14:49:22 +11:00
parent b882aea2e4
commit 0405b3922c
4 changed files with 53 additions and 6 deletions

View file

@ -1671,6 +1671,26 @@ static int lib_pSwitchShield(lua_State *L)
return 0;
}
static int lib_pPlayerCanEnterSpinGaps(lua_State *L)
{
player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
INLEVEL
if (!player)
return LUA_ErrInvalid(L, "player_t");
lua_pushboolean(L, P_PlayerCanEnterSpinGaps(player));
return 1;
}
static int lib_pPlayerShouldUseSpinHeight(lua_State *L)
{
player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
INLEVEL
if (!player)
return LUA_ErrInvalid(L, "player_t");
lua_pushboolean(L, P_PlayerShouldUseSpinHeight(player));
return 1;
}
// P_MAP
///////////
@ -3872,6 +3892,8 @@ static luaL_Reg lib[] = {
{"P_SpawnSpinMobj",lib_pSpawnSpinMobj},
{"P_Telekinesis",lib_pTelekinesis},
{"P_SwitchShield",lib_pSwitchShield},
{"P_PlayerCanEnterSpinGaps",lib_pPlayerCanEnterSpinGaps},
{"P_PlayerShouldUseSpinHeight",lib_pPlayerShouldUseSpinHeight},
// p_map
{"P_CheckPosition",lib_pCheckPosition},

View file

@ -143,6 +143,8 @@ angle_t P_GetLocalAngle(player_t *player);
void P_SetLocalAngle(player_t *player, angle_t angle);
void P_ForceLocalAngle(player_t *player, angle_t angle);
boolean P_PlayerFullbright(player_t *player);
boolean P_PlayerCanEnterSpinGaps(player_t *player);
boolean P_PlayerShouldUseSpinHeight(player_t *player);
boolean P_IsObjectInGoop(mobj_t *mo);
boolean P_IsObjectOnGround(mobj_t *mo);

View file

@ -1955,6 +1955,12 @@ static boolean PIT_CheckLine(line_t *ld)
// set openrange, opentop, openbottom
P_LineOpening(ld, tmthing);
// players should not always cross into sectors that they could not at full height
if (tmthing->player
&& openrange < P_GetPlayerHeight(tmthing->player)
&& !P_PlayerCanEnterSpinGaps(tmthing->player))
return false;
// adjust floor / ceiling heights
if (opentop < tmceilingz)
{
@ -3331,6 +3337,11 @@ static boolean PTR_LineIsBlocking(line_t *li)
if (openbottom - slidemo->z > FixedMul(MAXSTEPMOVE, slidemo->scale))
return true; // too big a step up
if (slidemo->player
&& openrange < P_GetPlayerHeight(slidemo->player)
&& !P_PlayerCanEnterSpinGaps(slidemo->player))
return true; // nonspin character should not take this path
return false;
}

View file

@ -8653,12 +8653,7 @@ void P_MovePlayer(player_t *player)
fixed_t oldheight = player->mo->height;
// Less height while spinning. Good for spinning under things...?
if ((player->mo->state == &states[player->mo->info->painstate])
|| ((player->pflags & PF_JUMPED) && !(player->pflags & PF_NOJUMPDAMAGE))
|| (player->pflags & PF_SPINNING)
|| player->powers[pw_tailsfly] || player->pflags & PF_GLIDING
|| (player->charability == CA_GLIDEANDCLIMB && player->mo->state-states == S_PLAY_GLIDE_LANDING)
|| (player->charability == CA_FLY && player->mo->state-states == S_PLAY_FLY_TIRED))
if (P_PlayerShouldUseSpinHeight(player))
{
player->mo->height = P_GetPlayerSpinHeight(player);
atspinheight = true;
@ -12953,3 +12948,20 @@ boolean P_PlayerFullbright(player_t *player)
|| !(player->mo->state >= &states[S_PLAY_NIGHTS_TRANS1]
&& player->mo->state < &states[S_PLAY_NIGHTS_TRANS6])))); // Note the < instead of <=
}
// returns true if the player can enter a sector that they could not if standing at their skin's full height
boolean P_PlayerCanEnterSpinGaps(player_t *player)
{
return ((player->pflags & (PF_SPINNING|PF_GLIDING))
|| (player->charability == CA_GLIDEANDCLIMB && player->mo->state-states == S_PLAY_GLIDE_LANDING));
}
// returns true if the player should use their skin's spinheight instead of their skin's height
boolean P_PlayerShouldUseSpinHeight(player_t *player)
{
return (P_PlayerCanEnterSpinGaps(player)
|| (player->mo->state == &states[player->mo->info->painstate])
|| ((player->pflags & PF_JUMPED) && !(player->pflags & PF_NOJUMPDAMAGE))
|| player->powers[pw_tailsfly]
|| (player->charability == CA_FLY && player->mo->state-states == S_PLAY_FLY_TIRED));
}