- split P_PlayerThink into several smaller functions.

This is for a future script export where overriding the actions separately may be interesting.
This commit is contained in:
Christoph Oelckers 2017-04-08 15:45:11 +02:00
parent 18d6fb7f49
commit e1698c6d41

View file

@ -2385,6 +2385,7 @@ void P_DeathThink (player_t *player)
int dir;
DAngle delta;
player->Uncrouch();
player->TickPSprites();
player->onground = (player->mo->Z() <= player->mo->floorz);
@ -2524,28 +2525,12 @@ void P_CrouchMove(player_t * player, int direction)
//----------------------------------------------------------------------------
//
// PROC P_PlayerThink
// PROC P_CheckFOV
//
//----------------------------------------------------------------------------
void P_PlayerThink (player_t *player)
void P_CheckFOV(player_t *player)
{
ticcmd_t *cmd;
if (player->mo == NULL)
{
I_Error ("No player %td start\n", player - players + 1);
}
if (debugfile && !(player->cheats & CF_PREDICTING))
{
fprintf (debugfile, "tic %d for pl %d: (%f, %f, %f, %f) b:%02x p:%d y:%d f:%d s:%d u:%d\n",
gametic, (int)(player-players), player->mo->X(), player->mo->Y(), player->mo->Z(),
player->mo->Angles.Yaw.Degrees, player->cmd.ucmd.buttons,
player->cmd.ucmd.pitch, player->cmd.ucmd.yaw, player->cmd.ucmd.forwardmove,
player->cmd.ucmd.sidemove, player->cmd.ucmd.upmove);
}
// [RH] Zoom the player's FOV
float desired = player->DesiredFOV;
// Adjust FOV using on the currently held weapon.
@ -2576,13 +2561,16 @@ void P_PlayerThink (player_t *player)
}
}
}
if (player->inventorytics)
{
player->inventorytics--;
}
// Don't interpolate the view for more than one tic
player->cheats &= ~CF_INTERPVIEW;
//----------------------------------------------------------------------------
//
// PROC P_CheckCheats
//
//----------------------------------------------------------------------------
void P_CheckCheats(player_t *player)
{
// No-clip cheat
if ((player->cheats & (CF_NOCLIP | CF_NOCLIP2)) == CF_NOCLIP2)
{ // No noclip2 without noclip
@ -2604,20 +2592,18 @@ void P_PlayerThink (player_t *player)
{
player->mo->flags &= ~MF_NOGRAVITY;
}
cmd = &player->cmd;
// Make unmodified copies for ACS's GetPlayerInput.
player->original_oldbuttons = player->original_cmd.buttons;
player->original_cmd = cmd->ucmd;
if (player->mo->flags & MF_JUSTATTACKED)
{ // Chainsaw/Gauntlets attack auto forward motion
cmd->ucmd.yaw = 0;
cmd->ucmd.forwardmove = 0xc800/2;
cmd->ucmd.sidemove = 0;
player->mo->flags &= ~MF_JUSTATTACKED;
}
//----------------------------------------------------------------------------
//
// PROC P_CheckFrozen
//
//----------------------------------------------------------------------------
bool P_CheckFrozen(player_t *player)
{
auto cmd = &player->cmd;
bool totallyfrozen = P_IsPlayerTotallyFrozen(player);
// [RH] Being totally frozen zeros out most input parameters.
@ -2645,8 +2631,17 @@ void P_PlayerThink (player_t *player)
cmd->ucmd.sidemove = 0;
cmd->ucmd.upmove = 0;
}
return totallyfrozen;
}
// Handle crouching
//----------------------------------------------------------------------------
//
// PROC P_CheckCrouch
//
//----------------------------------------------------------------------------
void P_CheckCrouch(player_t *player, bool totallyfrozen)
{
if (player->cmd.ucmd.buttons & BT_JUMP)
{
player->cmd.ucmd.buttons &= ~BT_CROUCH;
@ -2682,7 +2677,16 @@ void P_PlayerThink (player_t *player)
}
player->crouchoffset = -(player->mo->ViewHeight) * (1 - player->crouchfactor);
}
//----------------------------------------------------------------------------
//
// PROC P_CheckMusicChange
//
//----------------------------------------------------------------------------
void P_CheckMusicChange(player_t *player)
{
// MUSINFO stuff
if (player->MUSINFOtics >= 0 && player->MUSINFOactor != NULL)
{
@ -2707,26 +2711,16 @@ void P_PlayerThink (player_t *player)
DPrintf(DMSG_NOTIFY, "MUSINFO change for player %d to %d\n", (int)(player - players), player->MUSINFOactor->args[0]);
}
}
if (player->playerstate == PST_DEAD)
{
player->Uncrouch();
P_DeathThink (player);
return;
}
if (player->jumpTics != 0)
{
player->jumpTics--;
if (player->onground && player->jumpTics < -18)
{
player->jumpTics = 0;
}
}
if (player->morphTics && !(player->cheats & CF_PREDICTING))
{
player->mo->MorphPlayerThink ();
}
//----------------------------------------------------------------------------
//
// PROC P_CheckPitch
//
//----------------------------------------------------------------------------
void P_CheckPitch(player_t *player)
{
// [RH] Look up/down stuff
if (!level.IsFreelookAllowed())
{
@ -2738,7 +2732,7 @@ void P_PlayerThink (player_t *player)
// which translates to about half a screen height up and (more than)
// one full screen height down from straight ahead when view panning
// is used.
int clook = cmd->ucmd.pitch;
int clook = player->cmd.ucmd.pitch;
if (clook != 0)
{
if (clook == -32768)
@ -2768,24 +2762,18 @@ void P_PlayerThink (player_t *player)
}
}
}
// [RH] Check for fast turn around
if (cmd->ucmd.buttons & BT_TURN180 && !(player->oldbuttons & BT_TURN180))
{
player->turnticks = TURN180_TICKS;
}
// Handle movement
if (player->mo->reactiontime)
{ // Player is frozen
player->mo->reactiontime--;
}
else
{
P_MovePlayer (player);
//----------------------------------------------------------------------------
//
// PROC P_CheckJump
//
//----------------------------------------------------------------------------
void P_CheckJump(player_t *player)
{
// [RH] check for jump
if (cmd->ucmd.buttons & BT_JUMP)
if (player->cmd.ucmd.buttons & BT_JUMP)
{
if (player->crouchoffset != 0)
{
@ -2824,6 +2812,17 @@ void P_PlayerThink (player_t *player)
S_Sound(player->mo, CHAN_BODY, "*jump", 1, ATTN_NORM);
}
}
}
//----------------------------------------------------------------------------
//
// PROC P_CheckMoveUpDown
//
//----------------------------------------------------------------------------
void P_CheckMoveUpDown(player_t *player)
{
auto cmd = &player->cmd;
if (cmd->ucmd.upmove == -32768)
{ // Only land if in the air
@ -2861,9 +2860,14 @@ void P_PlayerThink (player_t *player)
}
}
P_CalcHeight (player);
if (!(player->cheats & CF_PREDICTING))
//----------------------------------------------------------------------------
//
// PROC P_CheckEnviroment
//
//----------------------------------------------------------------------------
void P_CheckEnvironment(player_t *player)
{
P_PlayerOnSpecial3DFloor(player);
P_PlayerInSpecialSector(player);
@ -2884,8 +2888,18 @@ void P_PlayerThink (player_t *player)
S_Sound(player->mo, CHAN_VOICE, id, 1, ATTN_NORM);
}
}
}
//----------------------------------------------------------------------------
//
// PROC P_CheckUse
//
//----------------------------------------------------------------------------
void P_CheckUse(player_t *player)
{
// check for use
if (cmd->ucmd.buttons & BT_USE)
if (player->cmd.ucmd.buttons & BT_USE)
{
if (!player->usedown)
{
@ -2900,6 +2914,16 @@ void P_PlayerThink (player_t *player)
{
player->usedown = false;
}
}
//----------------------------------------------------------------------------
//
// PROC P_CheckUndoMorph
//
//----------------------------------------------------------------------------
void P_CheckUndoMorph(player_t *player)
{
// Morph counter
if (player->morphTics)
{
@ -2912,6 +2936,182 @@ void P_PlayerThink (player_t *player)
P_UndoPlayerMorph(player, player, MORPH_UNDOBYTIMEOUT);
}
}
}
//----------------------------------------------------------------------------
//
// PROC P_CheckPoison
//
//----------------------------------------------------------------------------
void P_CheckPoison(player_t *player)
{
if (player->poisoncount && !(level.time & 15))
{
player->poisoncount -= 5;
if (player->poisoncount < 0)
{
player->poisoncount = 0;
}
P_PoisonDamage(player, player->poisoner, 1, true);
}
}
//----------------------------------------------------------------------------
//
// PROC P_CheckDegeneration
//
//----------------------------------------------------------------------------
void P_CheckDegeneration(player_t *player)
{
// Apply degeneration.
if (dmflags2 & DF2_YES_DEGENERATION)
{
int maxhealth = player->mo->GetMaxHealth(true);
if ((level.time % TICRATE) == 0 && player->health > maxhealth)
{
if (player->health - 5 < maxhealth)
player->health = maxhealth;
else
player->health--;
player->mo->health = player->health;
}
}
}
//----------------------------------------------------------------------------
//
// PROC P_CheckAirSupply
//
//----------------------------------------------------------------------------
void P_CheckAirSupply(player_t *player)
{
// Handle air supply
//if (level.airsupply > 0)
{
if (player->mo->waterlevel < 3 ||
(player->mo->flags2 & MF2_INVULNERABLE) ||
(player->cheats & (CF_GODMODE | CF_NOCLIP2)) ||
(player->cheats & CF_GODMODE2))
{
player->mo->ResetAirSupply();
}
else if (player->air_finished <= level.time && !(level.time & 31))
{
P_DamageMobj(player->mo, NULL, NULL, 2 + ((level.time - player->air_finished) / TICRATE), NAME_Drowning);
}
}
}
//----------------------------------------------------------------------------
//
// PROC P_HandleMovement
//
//----------------------------------------------------------------------------
void P_HandleMovement(player_t *player)
{
// [RH] Check for fast turn around
if (player->cmd.ucmd.buttons & BT_TURN180 && !(player->oldbuttons & BT_TURN180))
{
player->turnticks = TURN180_TICKS;
}
// Handle movement
if (player->mo->reactiontime)
{ // Player is frozen
player->mo->reactiontime--;
}
else
{
P_MovePlayer(player);
P_CheckJump(player);
P_CheckMoveUpDown(player);
}
}
//----------------------------------------------------------------------------
//
// PROC P_PlayerThink
//
//----------------------------------------------------------------------------
void P_PlayerThink (player_t *player)
{
ticcmd_t *cmd = &player->cmd;
if (player->mo == NULL)
{
I_Error ("No player %td start\n", player - players + 1);
}
if (debugfile && !(player->cheats & CF_PREDICTING))
{
fprintf (debugfile, "tic %d for pl %d: (%f, %f, %f, %f) b:%02x p:%d y:%d f:%d s:%d u:%d\n",
gametic, (int)(player-players), player->mo->X(), player->mo->Y(), player->mo->Z(),
player->mo->Angles.Yaw.Degrees, player->cmd.ucmd.buttons,
player->cmd.ucmd.pitch, player->cmd.ucmd.yaw, player->cmd.ucmd.forwardmove,
player->cmd.ucmd.sidemove, player->cmd.ucmd.upmove);
}
// Make unmodified copies for ACS's GetPlayerInput.
player->original_oldbuttons = player->original_cmd.buttons;
player->original_cmd = cmd->ucmd;
// Don't interpolate the view for more than one tic
player->cheats &= ~CF_INTERPVIEW;
P_CheckFOV(player);
if (player->inventorytics)
{
player->inventorytics--;
}
P_CheckCheats(player);
if (player->mo->flags & MF_JUSTATTACKED)
{ // Chainsaw/Gauntlets attack auto forward motion
cmd->ucmd.yaw = 0;
cmd->ucmd.forwardmove = 0xc800/2;
cmd->ucmd.sidemove = 0;
player->mo->flags &= ~MF_JUSTATTACKED;
}
bool totallyfrozen = P_CheckFrozen(player);
// Handle crouching
P_CheckCrouch(player, totallyfrozen);
P_CheckMusicChange(player);
if (player->playerstate == PST_DEAD)
{
P_DeathThink (player);
return;
}
if (player->jumpTics != 0)
{
player->jumpTics--;
if (player->onground && player->jumpTics < -18)
{
player->jumpTics = 0;
}
}
if (player->morphTics && !(player->cheats & CF_PREDICTING))
{
player->mo->MorphPlayerThink ();
}
P_CheckPitch(player);
P_HandleMovement(player);
P_CalcHeight (player);
if (!(player->cheats & CF_PREDICTING))
{
P_CheckEnvironment(player);
P_CheckUse(player);
P_CheckUndoMorph(player);
// Cycle psprites
player->TickPSprites();
@ -2929,46 +3129,9 @@ void P_PlayerThink (player_t *player)
P_DamageMobj (player->mo, NULL, NULL, 5, player->hazardtype);
}
if (player->poisoncount && !(level.time & 15))
{
player->poisoncount -= 5;
if (player->poisoncount < 0)
{
player->poisoncount = 0;
}
P_PoisonDamage (player, player->poisoner, 1, true);
}
// Apply degeneration.
if (dmflags2 & DF2_YES_DEGENERATION)
{
int maxhealth = player->mo->GetMaxHealth(true);
if ((level.time % TICRATE) == 0 && player->health > maxhealth)
{
if (player->health - 5 < maxhealth)
player->health = maxhealth;
else
player->health--;
player->mo->health = player->health;
}
}
// Handle air supply
//if (level.airsupply > 0)
{
if (player->mo->waterlevel < 3 ||
(player->mo->flags2 & MF2_INVULNERABLE) ||
(player->cheats & (CF_GODMODE | CF_NOCLIP2)) ||
(player->cheats & CF_GODMODE2))
{
player->mo->ResetAirSupply ();
}
else if (player->air_finished <= level.time && !(level.time & 31))
{
P_DamageMobj (player->mo, NULL, NULL, 2 + ((level.time-player->air_finished)/TICRATE), NAME_Drowning);
}
}
P_CheckPoison(player);
P_CheckDegeneration(player);
P_CheckAirSupply(player);
}
}