p_user.c
上传用户:xuyinpeng
上传日期:2021-05-12
资源大小:455k
文件大小:9k
源码类别:

射击游戏

开发平台:

Visual C++

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. // Player related stuff.
  21. // Bobbing POV/weapon, movement.
  22. // Pending weapon.
  23. //
  24. //-----------------------------------------------------------------------------
  25. static const char
  26. rcsid[] = "$Id: p_user.c,v 1.3 1997/01/28 22:08:29 b1 Exp $";
  27. #include "doomdef.h"
  28. #include "d_event.h"
  29. #include "p_local.h"
  30. #include "doomstat.h"
  31. // Index of the special effects (INVUL inverse) map.
  32. #define INVERSECOLORMAP 32
  33. //
  34. // Movement.
  35. //
  36. // 16 pixels of bob
  37. #define MAXBOB 0x100000
  38. boolean onground;
  39. //
  40. // P_Thrust
  41. // Moves the given origin along a given angle.
  42. //
  43. void
  44. P_Thrust
  45. ( player_t* player,
  46.   angle_t angle,
  47.   fixed_t move ) 
  48. {
  49.     angle >>= ANGLETOFINESHIFT;
  50.     
  51.     player->mo->momx += FixedMul(move,finecosine[angle]); 
  52.     player->mo->momy += FixedMul(move,finesine[angle]);
  53. }
  54. //
  55. // P_CalcHeight
  56. // Calculate the walking / running height adjustment
  57. //
  58. void P_CalcHeight (player_t* player) 
  59. {
  60.     int angle;
  61.     fixed_t bob;
  62.     
  63.     // Regular movement bobbing
  64.     // (needs to be calculated for gun swing
  65.     // even if not on ground)
  66.     // OPTIMIZE: tablify angle
  67.     // Note: a LUT allows for effects
  68.     //  like a ramp with low health.
  69.     player->bob =
  70. FixedMul (player->mo->momx, player->mo->momx)
  71. + FixedMul (player->mo->momy,player->mo->momy);
  72.     
  73.     player->bob >>= 2;
  74.     if (player->bob>MAXBOB)
  75. player->bob = MAXBOB;
  76.     if ((player->cheats & CF_NOMOMENTUM) || !onground)
  77.     {
  78. player->viewz = player->mo->z + VIEWHEIGHT;
  79. if (player->viewz > player->mo->ceilingz-4*FRACUNIT)
  80.     player->viewz = player->mo->ceilingz-4*FRACUNIT;
  81. player->viewz = player->mo->z + player->viewheight;
  82. return;
  83.     }
  84.     angle = (FINEANGLES/20*leveltime)&FINEMASK;
  85.     bob = FixedMul ( player->bob/2, finesine[angle]);
  86.     
  87.     // move viewheight
  88.     if (player->playerstate == PST_LIVE)
  89.     {
  90. player->viewheight += player->deltaviewheight;
  91. if (player->viewheight > VIEWHEIGHT)
  92. {
  93.     player->viewheight = VIEWHEIGHT;
  94.     player->deltaviewheight = 0;
  95. }
  96. if (player->viewheight < VIEWHEIGHT/2)
  97. {
  98.     player->viewheight = VIEWHEIGHT/2;
  99.     if (player->deltaviewheight <= 0)
  100. player->deltaviewheight = 1;
  101. }
  102. if (player->deltaviewheight)
  103. {
  104.     player->deltaviewheight += FRACUNIT/4;
  105.     if (!player->deltaviewheight)
  106. player->deltaviewheight = 1;
  107. }
  108.     }
  109.     player->viewz = player->mo->z + player->viewheight + bob;
  110.     if (player->viewz > player->mo->ceilingz-4*FRACUNIT)
  111. player->viewz = player->mo->ceilingz-4*FRACUNIT;
  112. }
  113. //
  114. // P_MovePlayer
  115. //
  116. void P_MovePlayer (player_t* player)
  117. {
  118.     ticcmd_t* cmd;
  119.     cmd = &player->cmd;
  120.     player->mo->angle += (cmd->angleturn<<16);
  121.     // Do not let the player control movement
  122.     //  if not onground.
  123.     onground = (player->mo->z <= player->mo->floorz);
  124.     if (cmd->forwardmove && onground)
  125. P_Thrust (player, player->mo->angle, cmd->forwardmove*2048);
  126.     
  127.     if (cmd->sidemove && onground)
  128. P_Thrust (player, player->mo->angle-ANG90, cmd->sidemove*2048);
  129.     if ( (cmd->forwardmove || cmd->sidemove) 
  130.  && player->mo->state == &states[S_PLAY] )
  131.     {
  132. P_SetMobjState (player->mo, S_PLAY_RUN1);
  133.     }
  134. }
  135. //
  136. // P_DeathThink
  137. // Fall on your face when dying.
  138. // Decrease POV height to floor height.
  139. //
  140. #define ANG5    (ANG90/18)
  141. void P_DeathThink (player_t* player)
  142. {
  143.     angle_t angle;
  144.     angle_t delta;
  145.     P_MovePsprites (player);
  146.     // fall to the ground
  147.     if (player->viewheight > 6*FRACUNIT)
  148. player->viewheight -= FRACUNIT;
  149.     if (player->viewheight < 6*FRACUNIT)
  150. player->viewheight = 6*FRACUNIT;
  151.     player->deltaviewheight = 0;
  152.     onground = (player->mo->z <= player->mo->floorz);
  153.     P_CalcHeight (player);
  154.     if (player->attacker && player->attacker != player->mo)
  155.     {
  156. angle = R_PointToAngle2 (player->mo->x,
  157.  player->mo->y,
  158.  player->attacker->x,
  159.  player->attacker->y);
  160. delta = angle - player->mo->angle;
  161. if (delta < ANG5 || delta > (unsigned)-ANG5)
  162. {
  163.     // Looking at killer,
  164.     //  so fade damage flash down.
  165.     player->mo->angle = angle;
  166.     if (player->damagecount)
  167. player->damagecount--;
  168. }
  169. else if (delta < ANG180)
  170.     player->mo->angle += ANG5;
  171. else
  172.     player->mo->angle -= ANG5;
  173.     }
  174.     else if (player->damagecount)
  175. player->damagecount--;
  176.     if (player->cmd.buttons & BT_USE)
  177. player->playerstate = PST_REBORN;
  178. }
  179. //
  180. // P_PlayerThink
  181. //
  182. void P_PlayerThink (player_t* player)
  183. {
  184.     ticcmd_t* cmd;
  185.     weapontype_t newweapon;
  186.     // fixme: do this in the cheat code
  187.     if (player->cheats & CF_NOCLIP)
  188. player->mo->flags |= MF_NOCLIP;
  189.     else
  190. player->mo->flags &= ~MF_NOCLIP;
  191.     
  192.     // chain saw run forward
  193.     cmd = &player->cmd;
  194.     if (player->mo->flags & MF_JUSTATTACKED)
  195.     {
  196. cmd->angleturn = 0;
  197. cmd->forwardmove = 0xc800/512;
  198. cmd->sidemove = 0;
  199. player->mo->flags &= ~MF_JUSTATTACKED;
  200.     }
  201.     if (player->playerstate == PST_DEAD)
  202.     {
  203. P_DeathThink (player);
  204. return;
  205.     }
  206.     
  207.     // Move around.
  208.     // Reactiontime is used to prevent movement
  209.     //  for a bit after a teleport.
  210.     if (player->mo->reactiontime)
  211. player->mo->reactiontime--;
  212.     else
  213. P_MovePlayer (player);
  214.     
  215.     P_CalcHeight (player);
  216.     if (player->mo->subsector->sector->special)
  217. P_PlayerInSpecialSector (player);
  218.     
  219.     // Check for weapon change.
  220.     // A special event has no other buttons.
  221.     if (cmd->buttons & BT_SPECIAL)
  222. cmd->buttons = 0;
  223.     if (cmd->buttons & BT_CHANGE)
  224.     {
  225. // The actual changing of the weapon is done
  226. //  when the weapon psprite can do it
  227. //  (read: not in the middle of an attack).
  228. newweapon = (cmd->buttons&BT_WEAPONMASK)>>BT_WEAPONSHIFT;
  229. if (newweapon == wp_fist
  230.     && player->weaponowned[wp_chainsaw]
  231.     && !(player->readyweapon == wp_chainsaw
  232.  && player->powers[pw_strength]))
  233. {
  234.     newweapon = wp_chainsaw;
  235. }
  236. if ( (gamemode == commercial)
  237.     && newweapon == wp_shotgun 
  238.     && player->weaponowned[wp_supershotgun]
  239.     && player->readyweapon != wp_supershotgun)
  240. {
  241.     newweapon = wp_supershotgun;
  242. }
  243. if (player->weaponowned[newweapon]
  244.     && newweapon != player->readyweapon)
  245. {
  246.     // Do not go to plasma or BFG in shareware,
  247.     //  even if cheated.
  248.     if ((newweapon != wp_plasma
  249.  && newweapon != wp_bfg)
  250. || (gamemode != shareware) )
  251.     {
  252. player->pendingweapon = newweapon;
  253.     }
  254. }
  255.     }
  256.     
  257.     // check for use
  258.     if (cmd->buttons & BT_USE)
  259.     {
  260. if (!player->usedown)
  261. {
  262.     P_UseLines (player);
  263.     player->usedown = true;
  264. }
  265.     }
  266.     else
  267. player->usedown = false;
  268.     
  269.     // cycle psprites
  270.     P_MovePsprites (player);
  271.     
  272.     // Counters, time dependend power ups.
  273.     // Strength counts up to diminish fade.
  274.     if (player->powers[pw_strength])
  275. player->powers[pw_strength]++;
  276.     if (player->powers[pw_invulnerability])
  277. player->powers[pw_invulnerability]--;
  278.     if (player->powers[pw_invisibility])
  279. if (! --player->powers[pw_invisibility] )
  280.     player->mo->flags &= ~MF_SHADOW;
  281.     if (player->powers[pw_infrared])
  282. player->powers[pw_infrared]--;
  283.     if (player->powers[pw_ironfeet])
  284. player->powers[pw_ironfeet]--;
  285.     if (player->damagecount)
  286. player->damagecount--;
  287.     if (player->bonuscount)
  288. player->bonuscount--;
  289.     
  290.     // Handling colormaps.
  291.     if (player->powers[pw_invulnerability])
  292.     {
  293. if (player->powers[pw_invulnerability] > 4*32
  294.     || (player->powers[pw_invulnerability]&8) )
  295.     player->fixedcolormap = INVERSECOLORMAP;
  296. else
  297.     player->fixedcolormap = 0;
  298.     }
  299.     else if (player->powers[pw_infrared])
  300.     {
  301. if (player->powers[pw_infrared] > 4*32
  302.     || (player->powers[pw_infrared]&8) )
  303. {
  304.     // almost full bright
  305.     player->fixedcolormap = 1;
  306. }
  307. else
  308.     player->fixedcolormap = 0;
  309.     }
  310.     else
  311. player->fixedcolormap = 0;
  312. }