p_user.c (5282B)
1 #include "doomdef.h" 2 #include "d_event.h" 3 #include "p_local.h" 4 #include "doomstat.h" 5 6 #define INVERSECOLORMAP 32 7 #define MAXBOB 0x100000 8 #define ANG5 (ANG90/18) 9 10 boolean onground; 11 12 void 13 P_Thrust(player_t* player, angle_t angle, fixed_t move) 14 { 15 angle >>= ANGLETOFINESHIFT; 16 player->mo->momx += FixedMul(move,finecosine[angle]); 17 player->mo->momy += FixedMul(move,finesine[angle]); 18 } 19 20 void 21 P_CalcHeight (player_t* player) 22 { 23 fixed_t bob; 24 int angle; 25 26 player->bob = FixedMul(player->mo->momx, player->mo->momx) + FixedMul(player->mo->momy,player->mo->momy); 27 player->bob >>= 2; 28 if (player->bob>MAXBOB) 29 player->bob = MAXBOB; 30 if ((player->cheats & CF_NOMOMENTUM) || !onground) { 31 player->viewz = player->mo->z + VIEWHEIGHT; 32 if (player->viewz > player->mo->ceilingz-4*FRACUNIT) 33 player->viewz = player->mo->ceilingz-4*FRACUNIT; 34 player->viewz = player->mo->z + player->viewheight; 35 return; 36 } 37 angle = (FINEANGLES/20*leveltime)&FINEMASK; 38 bob = FixedMul( player->bob/2, finesine[angle]); 39 if (player->playerstate == PST_LIVE) { 40 player->viewheight += player->deltaviewheight; 41 if (player->viewheight > VIEWHEIGHT) { 42 player->viewheight = VIEWHEIGHT; 43 player->deltaviewheight = 0; 44 } 45 if (player->viewheight < VIEWHEIGHT/2) { 46 player->viewheight = VIEWHEIGHT/2; 47 if (player->deltaviewheight <= 0) 48 player->deltaviewheight = 1; 49 } 50 if (player->deltaviewheight) { 51 player->deltaviewheight += FRACUNIT/4; 52 if (!player->deltaviewheight) 53 player->deltaviewheight = 1; 54 } 55 } 56 player->viewz = player->mo->z + player->viewheight + bob; 57 if (player->viewz > player->mo->ceilingz-4*FRACUNIT) 58 player->viewz = player->mo->ceilingz-4*FRACUNIT; 59 } 60 61 void 62 P_MovePlayer(player_t* player) 63 { 64 ticcmd_t* cmd; 65 66 cmd = &player->cmd; 67 player->mo->angle += (cmd->angleturn<<16); 68 onground = (player->mo->z <= player->mo->floorz); 69 if (cmd->forwardmove && onground) P_Thrust(player, player->mo->angle, cmd->forwardmove*2048); 70 if (cmd->sidemove && onground) P_Thrust(player, player->mo->angle-ANG90, cmd->sidemove*2048); 71 if ((cmd->forwardmove || cmd->sidemove) && player->mo->state == &states[S_PLAY]) 72 P_SetMobjState(player->mo, S_PLAY_RUN1); 73 } 74 75 void P_DeathThink(player_t* player) 76 { 77 angle_t angle, delta; 78 79 P_MovePsprites(player); 80 if (player->viewheight > 6*FRACUNIT) player->viewheight -= FRACUNIT; 81 if (player->viewheight < 6*FRACUNIT) player->viewheight = 6*FRACUNIT; 82 player->deltaviewheight = 0; 83 onground = (player->mo->z <= player->mo->floorz); 84 P_CalcHeight(player); 85 if (player->attacker && player->attacker != player->mo) { 86 angle = R_PointToAngle2(player->mo->x, player->mo->y, player->attacker->x, player->attacker->y); 87 delta = angle - player->mo->angle; 88 if (delta < ANG5 || delta > (unsigned)-ANG5) { 89 player->mo->angle = angle; 90 if (player->damagecount) 91 --player->damagecount; 92 } 93 else if (delta < ANG180) player->mo->angle += ANG5; 94 else player->mo->angle -= ANG5; 95 } 96 if (player->damagecount) 97 --player->damagecount; 98 if (player->cmd.buttons & BT_USE) 99 player->playerstate = PST_REBORN; 100 } 101 102 void 103 P_PlayerThink(player_t* player) 104 { 105 ticcmd_t* cmd; 106 weapontype_t newweapon; 107 108 if (player->cheats & CF_NOCLIP) 109 player->mo->flags |= MF_NOCLIP; 110 else 111 player->mo->flags &= ~MF_NOCLIP; 112 cmd = &player->cmd; 113 if (player->mo->flags & MF_JUSTATTACKED) { 114 cmd->angleturn = 0; 115 cmd->forwardmove = 0xc800/512; 116 cmd->sidemove = 0; 117 player->mo->flags &= ~MF_JUSTATTACKED; 118 } 119 if (player->playerstate == PST_DEAD) { 120 P_DeathThink (player); 121 return; 122 } 123 if (player->mo->reactiontime) 124 --player->mo->reactiontime; 125 else 126 P_MovePlayer(player); 127 P_CalcHeight(player); 128 if (player->mo->subsector->sector->special) 129 P_PlayerInSpecialSector(player); 130 if (cmd->buttons & BT_SPECIAL) 131 cmd->buttons = 0; 132 if (cmd->buttons & BT_CHANGE) { 133 newweapon = (cmd->buttons&BT_WEAPONMASK)>>BT_WEAPONSHIFT; 134 if (newweapon == wp_fist && player->weaponowned[wp_chainsaw] && !(player->readyweapon == wp_chainsaw && player->powers[pw_strength])) 135 newweapon = wp_chainsaw; 136 if (player->weaponowned[newweapon] && newweapon != player->readyweapon) { 137 if (newweapon != wp_plasma && newweapon != wp_bfg) 138 player->pendingweapon = newweapon; 139 } 140 } 141 if (cmd->buttons & BT_USE) { 142 if (!player->usedown) { 143 P_UseLines(player); 144 player->usedown = true; 145 } 146 } else player->usedown = false; 147 P_MovePsprites(player); 148 if (player->powers[pw_strength]) 149 player->powers[pw_strength]++; 150 if (player->powers[pw_invulnerability]) 151 --player->powers[pw_invulnerability]; 152 if (player->powers[pw_invisibility]) 153 if (!--player->powers[pw_invisibility]) 154 player->mo->flags &= ~MF_SHADOW; 155 if (player->powers[pw_infrared]) 156 --player->powers[pw_infrared]; 157 if (player->powers[pw_ironfeet]) 158 --player->powers[pw_ironfeet]; 159 if (player->damagecount) 160 --player->damagecount; 161 if (player->bonuscount) 162 --player->bonuscount; 163 if (player->powers[pw_invulnerability]) { 164 if (player->powers[pw_invulnerability] > 4*32 || (player->powers[pw_invulnerability]&8)) 165 player->fixedcolormap = INVERSECOLORMAP; 166 else 167 player->fixedcolormap = 0; 168 } 169 else if (player->powers[pw_infrared]) { 170 if (player->powers[pw_infrared] > 4*32 || (player->powers[pw_infrared]&8)) 171 player->fixedcolormap = 1; 172 else 173 player->fixedcolormap = 0; 174 } else player->fixedcolormap = 0; 175 }