📄 p_user.c
字号:
// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------//// $Id: p_user.c,v 1.14 2001/04/04 20:24:21 judgecutor Exp $//// Copyright (C) 1993-1996 by id Software, Inc.// Portions Copyright (C) 1998-2000 by DooM Legacy Team.//// This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.////// $Log: p_user.c,v $// Revision 1.14 2001/04/04 20:24:21 judgecutor// Added support for the 3D Sound//// Revision 1.13 2001/03/03 06:17:33 bpereira// no message//// Revision 1.12 2001/01/27 11:02:36 bpereira// no message//// Revision 1.11 2001/01/25 22:15:44 bpereira// added heretic support//// Revision 1.10 2000/11/04 16:23:43 bpereira// no message//// Revision 1.9 2000/11/02 17:50:09 stroggonmeth// Big 3Dfloors & FraggleScript commit!!//// Revision 1.8 2000/10/21 08:43:31 bpereira// no message//// Revision 1.7 2000/08/31 14:30:56 bpereira// no message//// Revision 1.6 2000/08/03 17:57:42 bpereira// no message//// Revision 1.5 2000/04/23 16:19:52 bpereira// no message//// Revision 1.4 2000/04/16 18:38:07 bpereira// no message//// Revision 1.3 2000/03/29 19:39:48 bpereira// no message//// Revision 1.2 2000/02/27 00:42:10 hurdler// fix CR+LF problem//// Revision 1.1.1.1 2000/02/22 20:32:32 hurdler// Initial import into CVS (v1.29 pr3)////// DESCRIPTION:// Player related stuff.// Bobbing POV/weapon, movement.// Pending weapon.////-----------------------------------------------------------------------------#include "doomdef.h"#include "d_event.h"#include "g_game.h"#include "p_local.h"#include "r_main.h"#include "s_sound.h"#include "p_setup.h"#include "p_inter.h"#include "m_random.h"#ifdef HW3SOUND#include "hardware/hw3sound.h"#endif// Index of the special effects (INVUL inverse) map.#define INVERSECOLORMAP 32//// Movement.//// 16 pixels of bob#define MAXBOB 0x100000boolean onground;//// P_Thrust// Moves the given origin along a given angle.//void P_Thrust(player_t *player, angle_t angle, fixed_t move){ angle >>= ANGLETOFINESHIFT; if(player->mo->subsector->sector->special == 15 && !(player->powers[pw_flight] && !(player->mo->z <= player->mo->floorz))) // Friction_Low { player->mo->momx += FixedMul(move>>2, finecosine[angle]); player->mo->momy += FixedMul(move>>2, finesine[angle]); } else { player->mo->momx += FixedMul(move, finecosine[angle]); player->mo->momy += FixedMul(move, finesine[angle]); }}#ifdef CLIENTPREDICTION2//// P_ThrustSpirit// Moves the given origin along a given angle.//void P_ThrustSpirit(player_t *player, angle_t angle, fixed_t move){ angle >>= ANGLETOFINESHIFT; if(player->spirit->subsector->sector->special == 15 && !(player->powers[pw_flight] && !(player->spirit->z <= player->spirit->floorz))) // Friction_Low { player->spirit->momx += FixedMul(move>>2, finecosine[angle]); player->spirit->momy += FixedMul(move>>2, finesine[angle]); } else { player->spirit->momx += FixedMul(move, finecosine[angle]); player->spirit->momy += FixedMul(move, finesine[angle]); }}#endif//// P_CalcHeight// Calculate the walking / running height adjustment//void P_CalcHeight (player_t* player){ int angle; fixed_t bob; fixed_t viewheight; mobj_t *mo; // Regular movement bobbing // (needs to be calculated for gun swing // even if not on ground) // OPTIMIZE: tablify angle // Note: a LUT allows for effects // like a ramp with low health. mo = player->mo;#ifdef CLIENTPREDICTION2 if( player->spirit ) mo = player->spirit;#endif player->bob = ((FixedMul (mo->momx,mo->momx) +FixedMul (mo->momy,mo->momy))*NEWTICRATERATIO)>>2; if (player->bob>MAXBOB) player->bob = MAXBOB; if( player->mo->flags2&MF2_FLY && !onground ) player->bob = FRACUNIT/2; if ((player->cheats & CF_NOMOMENTUM) || mo->z > mo->floorz) { //added:15-02-98: it seems to be useless code! //player->viewz = player->mo->z + (cv_viewheight.value<<FRACBITS); //if (player->viewz > player->mo->ceilingz-4*FRACUNIT) // player->viewz = player->mo->ceilingz-4*FRACUNIT; player->viewz = mo->z + player->viewheight; return; } angle = (FINEANGLES/20*localgametic/NEWTICRATERATIO)&FINEMASK; bob = FixedMul ( player->bob/2, finesine[angle]); // move viewheight viewheight = cv_viewheight.value << FRACBITS; // default eye view height if (player->playerstate == PST_LIVE) { player->viewheight += player->deltaviewheight; if (player->viewheight > viewheight) { player->viewheight = viewheight; player->deltaviewheight = 0; } if (player->viewheight < viewheight/2) { player->viewheight = viewheight/2; if (player->deltaviewheight <= 0) player->deltaviewheight = 1; } if (player->deltaviewheight) { player->deltaviewheight += FRACUNIT/4; if (!player->deltaviewheight) player->deltaviewheight = 1; } } if(player->chickenTics) player->viewz = mo->z + player->viewheight-(20*FRACUNIT); else player->viewz = mo->z + player->viewheight + bob; if(player->mo->flags2&MF2_FEETARECLIPPED && player->playerstate != PST_DEAD && player->mo->z <= player->mo->floorz) { player->viewz -= FOOTCLIPSIZE; } if (player->viewz > mo->ceilingz-4*FRACUNIT) player->viewz = mo->ceilingz-4*FRACUNIT; if (player->viewz < mo->floorz+4*FRACUNIT) player->viewz = mo->floorz+4*FRACUNIT;}extern int ticruned,ticmiss;//// P_MovePlayer//void P_MovePlayer (player_t* player){ ticcmd_t* cmd; int movefactor = 2048; //For Boom friction cmd = &player->cmd;#ifndef ABSOLUTEANGLE player->mo->angle += (cmd->angleturn<<16);#else if(demoversion<125) player->mo->angle += (cmd->angleturn<<16); else player->mo->angle = (cmd->angleturn<<16);#endif ticruned++; if( (cmd->angleturn & TICCMD_RECEIVED) == 0) ticmiss++; // Do not let the player control movement // if not onground. onground = (player->mo->z <= player->mo->floorz) || (player->cheats & CF_FLYAROUND) || (player->mo->flags2&(MF2_ONMOBJ|MF2_FLY)); if(demoversion<128) { boolean jumpover = player->cheats & CF_JUMPOVER; if (cmd->forwardmove && (onground || jumpover)) { // dirty hack to let the player avatar walk over a small wall // while in the air if (jumpover && player->mo->momz > 0) P_Thrust (player, player->mo->angle, 5*2048); else if (!jumpover) P_Thrust (player, player->mo->angle, cmd->forwardmove*2048); } if (cmd->sidemove && onground) P_Thrust (player, player->mo->angle-ANG90, cmd->sidemove*2048); player->aiming = (signed char)cmd->aiming; } else { fixed_t movepushforward=0,movepushside=0; player->aiming = cmd->aiming<<16; if( player->chickenTics ) movefactor = 2500; if(boomsupport && variable_friction) { //SoM: This seems to be buggy! Can anyone figure out why?? movefactor = P_GetMoveFactor(player->mo); //CONS_Printf("movefactor: %i\n", movefactor); } if (cmd->forwardmove) { movepushforward = cmd->forwardmove * movefactor; if (player->mo->eflags & MF_UNDERWATER) { // half forward speed when waist under water // a little better grip if feets touch the ground if (!onground) movepushforward >>= 1; else movepushforward = movepushforward *3/4; } else { // allow very small movement while in air for gameplay if (!onground) movepushforward >>= 3; } P_Thrust (player, player->mo->angle, movepushforward); } if (cmd->sidemove) { movepushside = cmd->sidemove * movefactor; if (player->mo->eflags & MF_UNDERWATER) { if (!onground) movepushside >>= 1; else movepushside = movepushside *3/4; } else if (!onground) movepushside >>= 3; P_Thrust (player, player->mo->angle-ANG90, movepushside); } // mouselook swim when waist underwater player->mo->eflags &= ~MF_SWIMMING; if (player->mo->eflags & MF_UNDERWATER) { fixed_t a; // swim up/down full move when forward full speed a = FixedMul( movepushforward*50, finesine[ (player->aiming>>ANGLETOFINESHIFT) ] >>5 ); if ( a != 0 ) { player->mo->eflags |= MF_SWIMMING; player->mo->momz += a; } } } //added:22-02-98: jumping if (cmd->buttons & BT_JUMP) { if( player->mo->flags2&MF2_FLY ) player->flyheight = 10; else if(player->mo->eflags & MF_UNDERWATER) //TODO: goub gloub when push up in water player->mo->momz = JUMPGRAVITY/2; else // can't jump while in air, can't jump while jumping if( onground && !(player->jumpdown & 1)) { player->mo->momz = JUMPGRAVITY; if( !(player->cheats & CF_FLYAROUND) ) {#ifdef HW3SOUND S_StartScreamSound (player->mo, sfx_jump);#else S_StartSound ( player->mo, sfx_jump);#endif // keep jumping ok if FLY mode. player->jumpdown |= 1; } } } else player->jumpdown &= ~1; if (cmd->forwardmove || cmd->sidemove) { if( player->chickenTics ) { if( player->mo->state == &states[S_CHICPLAY]) P_SetMobjState(player->mo, S_CHICPLAY_RUN1); } else if(player->mo->state == &states[S_PLAY]) P_SetMobjState(player->mo, S_PLAY_RUN1); } if( gamemode == heretic && (cmd->angleturn & BT_FLYDOWN) ) { player->flyheight = -10; }/* HERETODO fly = cmd->lookfly>>4; if(fly > 7) fly -= 16; if(fly && player->powers[pw_flight]) { if(fly != TOCENTER) { player->flyheight = fly*2; if(!(player->mo->flags2&MF2_FLY)) { player->mo->flags2 |= MF2_FLY; player->mo->flags |= MF_NOGRAVITY; } } else { player->mo->flags2 &= ~MF2_FLY; player->mo->flags &= ~MF_NOGRAVITY; } } else if(fly > 0) { P_PlayerUseArtifact(player, arti_fly); }*/ if(player->mo->flags2&MF2_FLY) { player->mo->momz = player->flyheight*FRACUNIT; if(player->flyheight) player->flyheight /= 2; }}//// P_DeathThink// Fall on your face when dying.// Decrease POV height to floor height.//#define ANG5 (ANG90/18)void P_DeathThink (player_t* player){ angle_t angle; angle_t delta; mobj_t* attacker; //added:22-02-98: fixed_t dist; //added:22-02-98: int pitch; //added:22-02-98: P_MovePsprites (player); // fall to the ground if (player->viewheight > 6*FRACUNIT) player->viewheight -= FRACUNIT; if (player->viewheight < 6*FRACUNIT) player->viewheight = 6*FRACUNIT; player->deltaviewheight = 0; onground = player->mo->z <= player->mo->floorz; P_CalcHeight (player); attacker = player->attacker; // watch my killer (if there is one) if (attacker && attacker != player->mo) { angle = R_PointToAngle2 (player->mo->x, player->mo->y, player->attacker->x, player->attacker->y); delta = angle - player->mo->angle; if (delta < ANG5 || delta > (unsigned)-ANG5) { // Looking at killer, // so fade damage flash down. player->mo->angle = angle; if (player->damagecount) player->damagecount--; } else if (delta < ANG180) player->mo->angle += ANG5; else player->mo->angle -= ANG5; //added:22-02-98: // change aiming to look up or down at the attacker (DOESNT WORK) // FIXME : the aiming returned seems to be too up or down... later dist = P_AproxDistance (attacker->x - player->mo->x, attacker->y - player->mo->y); //if (dist) // pitch = FixedMul ((160<<FRACBITS), FixedDiv (attacker->z + (attacker->height>>1), dist)) >>FRACBITS; //else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -