in doom_py/src/vizdoom/src/p_user.cpp [2194:2646]
void P_PlayerThink (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 %td: (%d, %d, %d, %u) b:%02x p:%d y:%d f:%d s:%d u:%d\n",
gametic, player-players, player->mo->X(), player->mo->Y(), player->mo->Z(),
player->mo->angle>>ANGLETOFINESHIFT, 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.
if (player->playerstate != PST_DEAD && // No adjustment while dead.
player->ReadyWeapon != NULL && // No adjustment if no weapon.
player->ReadyWeapon->FOVScale != 0) // No adjustment if the adjustment is zero.
{
// A negative scale is used to prevent G_AddViewAngle/G_AddViewPitch
// from scaling with the FOV scale.
desired *= fabs(player->ReadyWeapon->FOVScale);
}
if (player->FOV != desired)
{
if (fabsf (player->FOV - desired) < 7.f)
{
player->FOV = desired;
}
else
{
float zoom = MAX(7.f, fabsf(player->FOV - desired) * 0.025f);
if (player->FOV > desired)
{
player->FOV = player->FOV - zoom;
}
else
{
player->FOV = player->FOV + zoom;
}
}
}
if (player->inventorytics)
{
player->inventorytics--;
}
// Don't interpolate the view for more than one tic
player->cheats &= ~CF_INTERPVIEW;
// No-clip cheat
if ((player->cheats & (CF_NOCLIP | CF_NOCLIP2)) == CF_NOCLIP2)
{ // No noclip2 without noclip
player->cheats &= ~CF_NOCLIP2;
}
if (player->cheats & (CF_NOCLIP | CF_NOCLIP2) || (player->mo->GetDefault()->flags & MF_NOCLIP))
{
player->mo->flags |= MF_NOCLIP;
}
else
{
player->mo->flags &= ~MF_NOCLIP;
}
if (player->cheats & CF_NOCLIP2)
{
player->mo->flags |= MF_NOGRAVITY;
}
else if (!(player->mo->flags2 & MF2_FLY) && !(player->mo->GetDefault()->flags & MF_NOGRAVITY))
{
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;
}
bool totallyfrozen = P_IsPlayerTotallyFrozen(player);
// [RH] Being totally frozen zeros out most input parameters.
if (totallyfrozen)
{
if (gamestate == GS_TITLELEVEL)
{
cmd->ucmd.buttons = 0;
}
else
{
cmd->ucmd.buttons &= BT_USE;
}
cmd->ucmd.pitch = 0;
cmd->ucmd.yaw = 0;
cmd->ucmd.roll = 0;
cmd->ucmd.forwardmove = 0;
cmd->ucmd.sidemove = 0;
cmd->ucmd.upmove = 0;
player->turnticks = 0;
}
else if (player->cheats & CF_FROZEN)
{
cmd->ucmd.forwardmove = 0;
cmd->ucmd.sidemove = 0;
cmd->ucmd.upmove = 0;
}
// Handle crouching
if (player->cmd.ucmd.buttons & BT_JUMP)
{
player->cmd.ucmd.buttons &= ~BT_CROUCH;
}
if (player->CanCrouch() && player->health > 0 && level.IsCrouchingAllowed())
{
if (!totallyfrozen)
{
int crouchdir = player->crouching;
if (crouchdir == 0)
{
crouchdir = (player->cmd.ucmd.buttons & BT_CROUCH) ? -1 : 1;
}
else if (player->cmd.ucmd.buttons & BT_CROUCH)
{
player->crouching = 0;
}
if (crouchdir == 1 && player->crouchfactor < FRACUNIT &&
player->mo->Top() < player->mo->ceilingz)
{
P_CrouchMove(player, 1);
}
else if (crouchdir == -1 && player->crouchfactor > FRACUNIT/2)
{
P_CrouchMove(player, -1);
}
}
}
else
{
player->Uncrouch();
}
player->crouchoffset = -FixedMul(player->mo->ViewHeight, (FRACUNIT - player->crouchfactor));
// MUSINFO stuff
if (player->MUSINFOtics >= 0 && player->MUSINFOactor != NULL)
{
if (--player->MUSINFOtics < 0)
{
if (player - players == consoleplayer)
{
if (player->MUSINFOactor->args[0] != 0)
{
FName *music = level.info->MusicMap.CheckKey(player->MUSINFOactor->args[0]);
if (music != NULL)
{
S_ChangeMusic(music->GetChars(), player->MUSINFOactor->args[1]);
}
}
else
{
S_ChangeMusic("*");
}
}
DPrintf("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 ();
}
// [RH] Look up/down stuff
if (!level.IsFreelookAllowed())
{
player->mo->pitch = 0;
}
else
{
int look = cmd->ucmd.pitch << 16;
// The player's view pitch is clamped between -32 and +56 degrees,
// 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.
if (look)
{
if (look == -32768 << 16)
{ // center view
player->centering = true;
}
else if (!player->centering)
{
fixed_t oldpitch = player->mo->pitch;
player->mo->pitch -= look;
if (look > 0)
{ // look up
player->mo->pitch = MAX(player->mo->pitch, player->MinPitch);
if (player->mo->pitch > oldpitch)
{
player->mo->pitch = player->MinPitch;
}
}
else
{ // look down
player->mo->pitch = MIN(player->mo->pitch, player->MaxPitch);
if (player->mo->pitch < oldpitch)
{
player->mo->pitch = player->MaxPitch;
}
}
}
}
}
if (player->centering)
{
if (abs(player->mo->pitch) > 2*ANGLE_1)
{
player->mo->pitch = FixedMul(player->mo->pitch, FRACUNIT*2/3);
}
else
{
player->mo->pitch = 0;
player->centering = false;
if (player - players == consoleplayer)
{
LocalViewPitch = 0;
}
}
}
// [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);
// [RH] check for jump
if (cmd->ucmd.buttons & BT_JUMP)
{
if (player->crouchoffset != 0)
{
// Jumping while crouching will force an un-crouch but not jump
player->crouching = 1;
}
else if (player->mo->waterlevel >= 2)
{
player->mo->velz = FixedMul(4*FRACUNIT, player->mo->Speed);
}
else if (player->mo->flags & MF_NOGRAVITY)
{
player->mo->velz = 3*FRACUNIT;
}
else if (level.IsJumpingAllowed() && player->onground && player->jumpTics == 0)
{
fixed_t jumpvelz = player->mo->JumpZ * 35 / TICRATE;
// [BC] If the player has the high jump power, double his jump velocity.
if ( player->cheats & CF_HIGHJUMP ) jumpvelz *= 2;
player->mo->velz += jumpvelz;
player->mo->flags2 &= ~MF2_ONMOBJ;
player->jumpTics = -1;
if (!(player->cheats & CF_PREDICTING))
S_Sound(player->mo, CHAN_BODY, "*jump", 1, ATTN_NORM);
}
}
if (cmd->ucmd.upmove == -32768)
{ // Only land if in the air
if ((player->mo->flags & MF_NOGRAVITY) && player->mo->waterlevel < 2)
{
//player->mo->flags2 &= ~MF2_FLY;
player->mo->flags &= ~MF_NOGRAVITY;
}
}
else if (cmd->ucmd.upmove != 0)
{
// Clamp the speed to some reasonable maximum.
int magnitude = abs (cmd->ucmd.upmove);
if (magnitude > 0x300)
{
cmd->ucmd.upmove = ksgn (cmd->ucmd.upmove) * 0x300;
}
if (player->mo->waterlevel >= 2 || (player->mo->flags2 & MF2_FLY) || (player->cheats & CF_NOCLIP2))
{
player->mo->velz = FixedMul(player->mo->Speed, cmd->ucmd.upmove << 9);
if (player->mo->waterlevel < 2 && !(player->mo->flags & MF_NOGRAVITY))
{
player->mo->flags2 |= MF2_FLY;
player->mo->flags |= MF_NOGRAVITY;
if ((player->mo->velz <= -39 * FRACUNIT) && !(player->cheats & CF_PREDICTING))
{ // Stop falling scream
S_StopSound (player->mo, CHAN_VOICE);
}
}
}
else if (cmd->ucmd.upmove > 0 && !(player->cheats & CF_PREDICTING))
{
AInventory *fly = player->mo->FindInventory (NAME_ArtiFly);
if (fly != NULL)
{
player->mo->UseInventory (fly);
}
}
}
}
P_CalcHeight (player);
if (!(player->cheats & CF_PREDICTING))
{
P_PlayerOnSpecial3DFloor (player);
P_PlayerInSpecialSector (player);
if (player->mo->Z() <= player->mo->Sector->floorplane.ZatPoint(player->mo) ||
player->mo->waterlevel)
{
// Player must be touching the floor
P_PlayerOnSpecialFlat(player, P_GetThingFloorType(player->mo));
}
if (player->mo->velz <= -player->mo->FallingScreamMinSpeed &&
player->mo->velz >= -player->mo->FallingScreamMaxSpeed && !player->morphTics &&
player->mo->waterlevel == 0)
{
int id = S_FindSkinnedSound (player->mo, "*falling");
if (id != 0 && !S_IsActorPlayingSomething (player->mo, CHAN_VOICE, id))
{
S_Sound (player->mo, CHAN_VOICE, id, 1, ATTN_NORM);
}
}
// check for use
if (cmd->ucmd.buttons & BT_USE)
{
if (!player->usedown)
{
player->usedown = true;
if (!P_TalkFacing(player->mo))
{
P_UseLines(player);
}
}
}
else
{
player->usedown = false;
}
// Morph counter
if (player->morphTics)
{
if (player->chickenPeck)
{ // Chicken attack counter
player->chickenPeck -= 3;
}
if (!--player->morphTics)
{ // Attempt to undo the chicken/pig
P_UndoPlayerMorph (player, player, MORPH_UNDOBYTIMEOUT);
}
}
// Cycle psprites
P_MovePsprites (player);
// Other Counters
if (player->damagecount)
player->damagecount--;
if (player->bonuscount)
player->bonuscount--;
if (player->hazardcount)
{
player->hazardcount--;
if (!(level.time % player->hazardinterval) && player->hazardcount > 16*TICRATE)
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)
{
if ((level.time % TICRATE) == 0 && player->health > deh.MaxHealth)
{
if (player->health - 5 < deh.MaxHealth)
player->health = deh.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);
}
}
}
}