Advertisement
Guest User

Untitled

a guest
Dec 11th, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.24 KB | None | 0 0
  1. // Emacs style mode select -*- C++ -*-
  2. //-----------------------------------------------------------------------------
  3. //
  4. // Copyright (C) 2013 James Haley et al.
  5. //
  6. // This program is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program. If not, see http://www.gnu.org/licenses/
  18. //
  19. //--------------------------------------------------------------------------
  20. //
  21. // DESCRIPTION:
  22. // Player related stuff.
  23. // Bobbing POV/weapon, movement.
  24. // Pending weapon.
  25. //
  26. //-----------------------------------------------------------------------------
  27.  
  28. #include "z_zone.h"
  29.  
  30. #include "a_small.h"
  31. #include "c_net.h"
  32. #include "c_runcmd.h"
  33. #include "doomstat.h"
  34. #include "d_event.h"
  35. #include "d_gi.h"
  36. #include "e_player.h"
  37. #include "e_states.h"
  38. #include "g_game.h"
  39. #include "hu_stuff.h"
  40. #include "m_random.h"
  41. #include "p_chase.h"
  42. #include "p_map.h"
  43. #include "p_map3d.h"
  44. #include "p_maputl.h"
  45. #include "p_skin.h"
  46. #include "p_spec.h"
  47. #include "p_user.h"
  48. #include "r_defs.h"
  49. #include "r_main.h"
  50. #include "s_sound.h"
  51. #include "sounds.h"
  52. #include "st_stuff.h"
  53.  
  54. //
  55. // Movement.
  56. //
  57.  
  58. // less than original 16 pixels of bob
  59.  
  60. #define MAXBOB 0x020000
  61.  
  62. bool onground; // whether player is on ground or in air
  63.  
  64. bool pitchedflight = true;
  65. bool default_pitchedflight = true;
  66.  
  67. int jumpStage = 0;
  68. int jetpackfuel = 60; // Exactly 1 second
  69. int soundlooptimer = 0;
  70. bool jumpRestrict = false;
  71. bool havejetpack = true;
  72. bool jetpackrecharging = false;
  73.  
  74. //
  75. // P_SetDisplayPlayer
  76. //
  77. // Sets the current display player.
  78. //
  79. void P_SetDisplayPlayer(int new_displayplayer)
  80. {
  81. displayplayer = new_displayplayer;
  82.  
  83. ST_Start();
  84. HU_Start();
  85. S_UpdateSounds(players[displayplayer].mo);
  86. P_ResetChasecam();
  87. }
  88.  
  89. //
  90. // P_Thrust
  91. // Moves the given origin along a given angle.
  92. //
  93. // davidph 06/06/12: Added pitch.
  94. //
  95. void P_Thrust(player_t *player, angle_t angle, angle_t pitch, fixed_t move)
  96. {
  97. if(pitch)
  98. {
  99. pitch >>= ANGLETOFINESHIFT;
  100. player->mo->momz -= FixedMul(move, finesine[pitch]);
  101. move = FixedMul(move, finecosine[pitch]);
  102. }
  103.  
  104. player->mo->momx += FixedMul(move, finecosine[angle >>= ANGLETOFINESHIFT]);
  105. player->mo->momy += FixedMul(move, finesine[angle]);
  106. }
  107.  
  108. //
  109. // P_Bob
  110. // Same as P_Thrust, but only affects bobbing.
  111. //
  112. // killough 10/98: We apply thrust separately between the real physical player
  113. // and the part which affects bobbing. This way, bobbing only comes from player
  114. // motion, nothing external, avoiding many problems, e.g. bobbing should not
  115. // occur on conveyors, unless the player walks on one, and bobbing should be
  116. // reduced at a regular rate, even on ice (where the player coasts).
  117. //
  118. // davidph 06/06/12: Added pitch. (Though only used to determine the true move.)
  119. //
  120. void P_Bob(player_t *player, angle_t angle, angle_t pitch, fixed_t move)
  121. {
  122. // e6y
  123. if(demo_version < 203)
  124. return;
  125.  
  126. if(pitch)
  127. {
  128. pitch >>= ANGLETOFINESHIFT;
  129. //player->momz -= FixedMul(move, finesine[pitch]);
  130. move = FixedMul(move, finecosine[pitch]);
  131. }
  132.  
  133. player->momx += FixedMul(move,finecosine[angle >>= ANGLETOFINESHIFT]);
  134. player->momy += FixedMul(move,finesine[angle]);
  135. }
  136.  
  137. //
  138. // P_CalcHeight
  139. //
  140. // Calculate the walking / running height adjustment
  141. //
  142. void P_CalcHeight(player_t *player)
  143. {
  144. int angle;
  145. fixed_t bob;
  146.  
  147. // Regular movement bobbing
  148. // (needs to be calculated for gun swing
  149. // even if not on ground)
  150. // OPTIMIZE: tablify angle
  151. // Note: a LUT allows for effects
  152. // like a ramp with low health.
  153.  
  154. // killough 10/98: Make bobbing depend only on player-applied motion.
  155. //
  156. // Note: don't reduce bobbing here if on ice: if you reduce bobbing here,
  157. // it causes bobbing jerkiness when the player moves from ice to non-ice,
  158. // and vice-versa.
  159. //
  160. // haleyjd: cph found out this can affect demo sync due to
  161. // differences it introduces in firing height etc. so it needs to be
  162. // optioned.
  163. // 04/11/10: refactored
  164.  
  165. player->bob = 0;
  166. // if(demo_version >= 203)
  167. if(onground == 1) // tweaked bobbing a bit - soda
  168. {
  169. if(player_bobbing)
  170. {
  171. player->bob = (FixedMul(player->momx, player->momx) +
  172. FixedMul(player->momy, player->momy)) >> 3;
  173. }
  174. }
  175.  
  176. // haleyjd 06/05/12: flying players
  177. if(player->mo->flags4 & MF4_FLY && !onground)
  178. player->bob = FRACUNIT / 2;
  179.  
  180. if(!onground || player->cheats & CF_NOMOMENTUM)
  181. {
  182. player->viewz = player->mo->z + VIEWHEIGHT;
  183.  
  184. if(player->viewz > player->mo->ceilingz - 4 * FRACUNIT)
  185. player->viewz = player->mo->ceilingz - 4 * FRACUNIT;
  186.  
  187. // phares 2/25/98:
  188. // The following line was in the Id source and appears
  189. // to be a bug. player->viewz is checked in a similar
  190. // manner at a different exit below.
  191.  
  192. // player->viewz = player->mo->z + player->viewheight;
  193.  
  194. return;
  195. }
  196.  
  197. angle = (FINEANGLES / 4 * leveltime / 4) & FINEMASK; // tweaked this -soda
  198. bob = FixedMul(player->bob / 3, finesine[angle]);
  199.  
  200. // move viewheight
  201.  
  202. if(player->playerstate == PST_LIVE)
  203. {
  204. player->viewheight += player->deltaviewheight;
  205.  
  206. if(player->viewheight > VIEWHEIGHT)
  207. {
  208. player->viewheight = VIEWHEIGHT;
  209. player->deltaviewheight = 0;
  210. }
  211.  
  212. if(player->viewheight < VIEWHEIGHT / 2)
  213. {
  214. player->viewheight = VIEWHEIGHT / 2;
  215. if(player->deltaviewheight <= 0)
  216. player->deltaviewheight = 1;
  217. }
  218.  
  219. if(player->deltaviewheight)
  220. {
  221. player->deltaviewheight += FRACUNIT / 4;
  222. if(!player->deltaviewheight)
  223. player->deltaviewheight = 1;
  224. }
  225. }
  226.  
  227. player->viewz = player->mo->z + player->viewheight + bob;
  228.  
  229. // haleyjd 08/07/04: new floorclip system
  230. if(player->mo->floorclip && player->playerstate != PST_DEAD &&
  231. player->mo->z <= player->mo->floorz)
  232. {
  233. player->viewz -= player->mo->floorclip;
  234. }
  235.  
  236. if(player->viewz > player->mo->ceilingz - 2 * FRACUNIT) // Adjusted for half scale - Soda
  237. player->viewz = player->mo->ceilingz - 2 * FRACUNIT;
  238. }
  239.  
  240. //
  241. // P_PlayerFlight
  242. //
  243. // haleyjd 06/05/12: flying logic for players
  244. //
  245. static void P_PlayerFlight(player_t *player, ticcmd_t *cmd)
  246. {
  247. int fly = cmd->fly;
  248.  
  249. if(fly && player->powers[pw_flight])
  250. {
  251. if(fly != FLIGHT_CENTER)
  252. {
  253. player->flyheight = fly * 2;
  254.  
  255. if(!(player->mo->flags4 & MF4_FLY))
  256. P_PlayerStartFlight(player, false);
  257. }
  258. else
  259. P_PlayerStopFlight(player);
  260. }
  261. // TODO:
  262. // else
  263. // * If have a flight-granting powerup, activate it now
  264.  
  265. if(player->mo->flags4 & MF4_FLY)
  266. {
  267. if(player->mo->intflags & MIF_CLEARMOMZ)
  268. {
  269. player->mo->momz = 0;
  270. player->mo->intflags &= ~MIF_CLEARMOMZ;
  271. }
  272.  
  273. if(player->flyheight)
  274. {
  275. player->mo->momz = player->flyheight * FRACUNIT;
  276. player->flyheight /= 2;
  277. }
  278. }
  279. }
  280.  
  281. //
  282. // P_MovePlayer
  283. //
  284. // Adds momentum
  285. //
  286. // killough 10/98: simplified
  287. //
  288. void P_MovePlayer(player_t* player)
  289. {
  290. ticcmd_t *cmd = &player->cmd;
  291. Mobj *mo = player->mo;
  292.  
  293. mo->angle += cmd->angleturn << 16;
  294.  
  295. // haleyjd: OVER_UNDER
  296. // 06/05/12: flying players
  297. onground =
  298. mo->z <= mo->floorz ||
  299. (P_Use3DClipping() && mo->intflags & MIF_ONMOBJ) ||
  300. (mo->flags4 & MF4_FLY);
  301.  
  302. // killough 10/98:
  303. //
  304. // We must apply thrust to the player and bobbing separately, to avoid
  305. // anomalies. The thrust applied to bobbing is always the same strength on
  306. // ice, because the player still "works just as hard" to move, while the
  307. // thrust applied to the movement varies with 'movefactor'.
  308.  
  309. if(//(!demo_compatibility && demo_version < 203) ||
  310. cmd->forwardmove | cmd->sidemove) // killough 10/98
  311. { // Tweaked with help from Linguica. -Soda
  312. if (onground || mo->flags & MF_BOUNCES)
  313. {
  314. int friction, movefactor = P_GetMoveFactor(mo, &friction);
  315.  
  316. // killough 11/98:
  317. // On sludge, make bobbing depend on efficiency.
  318. // On ice, make it depend on effort.
  319.  
  320. int bobfactor =
  321. friction < ORIG_FRICTION ? movefactor : ORIG_FRICTION_FACTOR;
  322.  
  323. // davidph 06/06/12: pitch-to-fly
  324. fixed_t pitch = player->pitch;
  325.  
  326. if(!(mo->flags4 & MF4_FLY) || !pitchedflight)
  327. pitch = 0;
  328.  
  329.  
  330. //mo->angle = angle of the player;
  331. //cmd->forwardmove*movefactor
  332. /*
  333. if (cmd->forwardmove)
  334. {
  335. movangle = 0
  336. */
  337.  
  338. /*
  339. float maxfloat = 1.0;
  340. float movintens = 0.0;
  341. int movangle = 4096;
  342. */
  343. /*
  344. if (movintense > 0)
  345. {
  346. P_Bob(player, mo->angle, pitch, cmd->forwardmove*bobfactor);
  347. P_Thrust(player, mo->angle(times whatever movangle is), pitch, cmd->forwardmove*movefactor);
  348. }*/
  349.  
  350. float fwdThrust = cmd->forwardmove; //0.0 - 1.0
  351. float sideThrust = cmd->sidemove; // 0.0 - 1.0
  352. float totalThrust = sqrt(pow(fwdThrust, 2) + pow(sideThrust, 2)); //0.0 - 1.41
  353. if(totalThrust > 14) // cap speed - Soda
  354. totalThrust = 14;
  355. if(totalThrust < -14)
  356. totalThrust = -14;
  357.  
  358. float offsetAngle = atan(sideThrust/fwdThrust) * 2*ANG90 / PI;
  359. totalThrust = totalThrust*movefactor;
  360. if(fwdThrust < 0)
  361. totalThrust = -totalThrust;
  362.  
  363. P_Thrust(player, mo->angle-offsetAngle, 0, totalThrust);
  364.  
  365. //thing->player->armorpoints = offsetAngle;
  366.  
  367.  
  368.  
  369.  
  370. if (cmd->forwardmove)
  371. {
  372. P_Bob(player, mo->angle, pitch, cmd->forwardmove*bobfactor);
  373. // P_Thrust(player, mo->angle, 0, cmd->forwardmove*movefactor);
  374. }
  375.  
  376. if (cmd->sidemove)
  377. {
  378. P_Bob(player, mo->angle-ANG90, 0, cmd->sidemove*bobfactor);
  379. // P_Thrust(player, mo->angle-ANG90, 0, cmd->sidemove*movefactor);
  380. }
  381.  
  382. }
  383. else
  384. {
  385. int friction, movefactor = P_GetMoveFactor(mo, &friction); // LAME HACK
  386.  
  387. // killough 11/98:
  388. // On sludge, make bobbing depend on efficiency.
  389. // On ice, make it depend on effort.
  390.  
  391. /* int bobfactor =
  392. friction < ORIG_FRICTION ? movefactor : ORIG_FRICTION_FACTOR;
  393. */
  394. // davidph 06/06/12: pitch-to-fly
  395. fixed_t pitch = player->pitch;
  396.  
  397. if(!(mo->flags4 & MF4_FLY) || !pitchedflight)
  398. pitch = 0;
  399.  
  400.  
  401. float fwdThrust = cmd->forwardmove; //0.0 - 1.0
  402. float sideThrust = cmd->sidemove; // 0.0 - 1.0
  403. float totalThrust = sqrt(pow(fwdThrust, 2) + pow(sideThrust, 2)); //0.0 - 1.41
  404. if(totalThrust > 14) // cap speed - Soda
  405. totalThrust = 14;
  406. if(totalThrust < -14)
  407. totalThrust = -14;
  408.  
  409. float offsetAngle = atan(sideThrust/fwdThrust) * 2*ANG90 / PI;
  410. totalThrust = totalThrust*movefactor;
  411. if(fwdThrust < 0)
  412. totalThrust = -totalThrust;
  413.  
  414. P_Thrust(player, mo->angle-offsetAngle, 0, totalThrust);
  415. /*
  416. if (cmd->forwardmove)
  417. {
  418. // P_Bob(player, mo->angle, pitch, cmd->forwardmove*bobfactor);
  419. P_Thrust(player, mo->angle, pitch, cmd->forwardmove*movefactor/2.0);
  420. }
  421.  
  422. if (cmd->sidemove)
  423. {
  424. // P_Bob(player, mo->angle-ANG90, 0, cmd->sidemove*bobfactor);
  425. P_Thrust(player, mo->angle-ANG90, 0, cmd->sidemove*movefactor/2.0);
  426. }*/
  427. }
  428.  
  429. if(mo->state == states[mo->info->spawnstate])
  430. P_SetMobjState(mo, mo->info->seestate);
  431. }
  432.  
  433. // haleyjd 06/05/12: flight
  434. P_PlayerFlight(player, cmd);
  435. }
  436.  
  437. #define ANG5 (ANG90/18)
  438.  
  439. //
  440. // P_DeathThink
  441. //
  442. // Fall on your face when dying.
  443. // Decrease POV height to floor height.
  444. //
  445. void P_DeathThink(player_t *player)
  446. {
  447. angle_t angle;
  448. angle_t delta;
  449.  
  450. P_MovePsprites(player);
  451.  
  452. // fall to the ground
  453.  
  454. if(player->viewheight > 3 * FRACUNIT) // adjusted for half scale - soda
  455. player->viewheight -= FRACUNIT;
  456.  
  457. if(player->viewheight < 3 * FRACUNIT) // adjusted for half scale - soda
  458. player->viewheight = 3 * FRACUNIT; // adjusted for half scale - soda
  459.  
  460. player->deltaviewheight = 0;
  461.  
  462. // haleyjd: never bob player view when dead, and always treat player like
  463. // he is on the ground
  464. if(demo_version >= 333)
  465. {
  466. onground = true;
  467. player->momx = player->momy = 0;
  468. }
  469. else
  470. {
  471. onground = player->mo->z <= player->mo->floorz ||
  472. (P_Use3DClipping() &&
  473. player->mo->intflags & MIF_ONMOBJ);
  474.  
  475. }
  476.  
  477. P_CalcHeight(player);
  478.  
  479. if(player->attacker && player->attacker != player->mo)
  480. {
  481. angle = P_PointToAngle(player->mo->x,
  482. player->mo->y,
  483. player->attacker->x,
  484. player->attacker->y);
  485.  
  486. delta = angle - player->mo->angle;
  487.  
  488. if(delta < ANG5 || delta > (unsigned int)-ANG5)
  489. {
  490. // Looking at killer,
  491. // so fade damage flash down.
  492.  
  493. player->mo->angle = angle;
  494.  
  495. if(player->damagecount)
  496. player->damagecount--;
  497. }
  498. else
  499. if(delta < ANG180)
  500. player->mo->angle += ANG5;
  501. else
  502. player->mo->angle -= ANG5;
  503. }
  504. else if(player->damagecount)
  505. player->damagecount--;
  506.  
  507. // haleyjd 10/05/08:
  508. // handle looking slightly up when the player is attached to a non-player
  509. // object and is dead. This was done for the decapitation deaths in Heretic
  510. // and Hexen.
  511. if(!E_IsPlayerClassThingType(player->mo->type))
  512. {
  513. if(player->mo->z <= player->mo->floorz && player->pitch > -ANGLE_1 * 15)
  514. player->pitch -= 2*ANGLE_1/3;
  515. }
  516.  
  517. if(player->cmd.buttons & BT_USE)
  518. player->playerstate = PST_REBORN;
  519. }
  520.  
  521. //
  522. // P_HereticCurrent
  523. //
  524. // Applies Heretic current effects to the player.
  525. //
  526. // haleyjd 09/09/07: Rewritten to use msecnodes and eliminate the redundant
  527. // Mobj::floorsec field.
  528. //
  529. static void P_HereticCurrent(player_t *player)
  530. {
  531. msecnode_t *m;
  532. Mobj *thing = player->mo;
  533.  
  534. // don't affect the player if noclipping is on (pushes you through walls)
  535. if(thing->flags & MF_NOCLIP)
  536. return;
  537.  
  538. // determine what touched sector the player is standing on
  539. for(m = thing->touching_sectorlist; m; m = m->m_tnext)
  540. {
  541. if(thing->z == m->m_sector->floorheight)
  542. break;
  543. }
  544.  
  545. if(m)
  546. {
  547. sector_t *sec = m->m_sector;
  548.  
  549. if(sec->hticPushType == SECTOR_HTIC_CURRENT)
  550. P_Thrust(player, sec->hticPushAngle, 0, sec->hticPushForce);
  551. }
  552. }
  553.  
  554. //
  555. // P_doTorchFlicker
  556. //
  557. // haleyjd 08/31/13: apply flickering effect when player has a torch
  558. //
  559. static void P_doTorchFlicker(player_t *player)
  560. {
  561. // if infinite duration, or just starting, set fixedcolormap
  562. // if it's out of range of the torch effect
  563. if(player->powers[pw_torch] < 0 ||
  564. player->powers[pw_torch] >= INFRATICS - 1)
  565. {
  566. if(!player->fixedcolormap || player->fixedcolormap > 7)
  567. player->fixedcolormap = 1;
  568. }
  569.  
  570. if(leveltime & 16)
  571. return;
  572.  
  573. if(player->newtorch)
  574. {
  575. if(player->fixedcolormap + player->torchdelta > 7 ||
  576. player->fixedcolormap + player->torchdelta < 1 ||
  577. player->newtorch == player->fixedcolormap)
  578. {
  579. player->newtorch = 0;
  580. }
  581. else
  582. player->fixedcolormap += player->torchdelta;
  583. }
  584. else
  585. {
  586. player->newtorch = (M_Random() & 7) + 1;
  587. if(player->newtorch == player->fixedcolormap)
  588. player->torchdelta = 0;
  589. else if(player->newtorch > player->fixedcolormap)
  590. player->torchdelta = 1;
  591. else
  592. player->torchdelta = -1;
  593. }
  594. }
  595.  
  596. enum
  597. {
  598. PLS_NONE,
  599. PLS_LIGHTAMP,
  600. PLS_TORCH
  601. };
  602.  
  603. //
  604. // P_PlayerLightSourceType
  605. //
  606. // Return the type of light source the player is using.
  607. //
  608. static int P_PlayerLightSourceType(player_t *player)
  609. {
  610. // infrared is higher priority than torch
  611. if(player->powers[pw_infrared])
  612. return PLS_LIGHTAMP;
  613. else if(player->powers[pw_torch])
  614. return PLS_TORCH;
  615. else
  616. return PLS_NONE;
  617. }
  618.  
  619. //
  620. // P_PlayerLightTics
  621. //
  622. // haleyjd 08/31/13: get the player's light power tics
  623. //
  624. static int P_PlayerLightTics(player_t *player)
  625. {
  626. switch(P_PlayerLightSourceType(player))
  627. {
  628. case PLS_LIGHTAMP:
  629. return player->powers[pw_infrared];
  630. case PLS_TORCH:
  631. return player->powers[pw_torch];
  632. default:
  633. return 0;
  634. }
  635. }
  636.  
  637. //
  638. // P_SectorIsSpecial
  639. //
  640. // haleyjd 12/28/08: Determines whether or not a sector is special.
  641. //
  642. inline static bool P_SectorIsSpecial(sector_t *sector)
  643. {
  644. return (sector->special || sector->flags || sector->damage);
  645. }
  646.  
  647. //
  648. // P_PlayerThink
  649. //
  650. void P_PlayerThink(player_t *player)
  651. {
  652. ticcmd_t* cmd;
  653.  
  654. // haleyjd 01/04/14: backup viewz and mobj location for interpolation
  655. player->prevviewz = player->viewz;
  656. player->mo->backupPosition();
  657.  
  658. // killough 2/8/98, 3/21/98:
  659. // (this code is necessary despite questions raised elsewhere in a comment)
  660.  
  661. if(player->cheats & CF_NOCLIP)
  662. player->mo->flags |= MF_NOCLIP;
  663. else
  664. player->mo->flags &= ~MF_NOCLIP;
  665.  
  666. // chain saw run forward
  667.  
  668. cmd = &player->cmd;
  669. if(player->mo->flags & MF_JUSTATTACKED)
  670. {
  671. cmd->angleturn = 0;
  672. cmd->forwardmove = 0xc800/512;
  673. cmd->sidemove = 0;
  674. player->mo->flags &= ~MF_JUSTATTACKED;
  675. }
  676.  
  677. if(player->playerstate == PST_DEAD)
  678. {
  679. P_DeathThink(player);
  680. return;
  681. }
  682.  
  683. // haleyjd 04/03/05: new yshear code
  684. if(!allowmlook)
  685. player->pitch = 0;
  686. else
  687. {
  688. int look = cmd->look;
  689.  
  690. if(look)
  691. {
  692. // test for special centerview value
  693. if(look == -32768)
  694. player->pitch = 0;
  695. else
  696. {
  697. player->pitch -= look << 16;
  698. if(player->pitch < -ANGLE_1*32)
  699. player->pitch = -ANGLE_1*32;
  700. else if(player->pitch > ANGLE_1*32)
  701. player->pitch = ANGLE_1*32;
  702. }
  703. }
  704. }
  705.  
  706. // haleyjd: count down jump timer
  707. if(player->jumptime)
  708. player->jumptime--;
  709.  
  710. // Move around.
  711. // Reactiontime is used to prevent movement
  712. // for a bit after a teleport.
  713.  
  714. if(player->mo->reactiontime)
  715. player->mo->reactiontime--;
  716. else
  717. {
  718. P_MovePlayer(player);
  719.  
  720. // Handle actions -- joek 12/22/07
  721.  
  722. // Jump and jetpack systems designed by Samuel Oliver,
  723. // Initially partially implemented by Steve Moses
  724.  
  725. if(soundlooptimer > 0) // Decrement delay for jetpack sounds
  726. soundlooptimer --;
  727.  
  728. if(onground == 1)
  729. {
  730. jumpStage = 0;
  731. jetpackrecharging = true;
  732. player->mo->momz = 0;
  733. if(jumpRestrict == true && cmd->actions != AC_JUMP)
  734. {
  735. jumpRestrict = false; // Let loose, the player's released the key
  736. }
  737. }
  738.  
  739. if(jumpStage == 0)
  740. {
  741. if(onground == 0) //player is above the floor in jumpStage 0
  742. {
  743. jumpStage = 2;
  744. }
  745. else if(cmd->actions & AC_JUMP && jumpRestrict == false) // Jump key is down at all and player isn't prohibited from jumping
  746. { // if player is on ground or an object, and player is not in jumptime, jump
  747. if((onground == 1 ||
  748. (player->mo->intflags & MIF_ONMOBJ)) && !player->jumptime)
  749. {
  750. jumpRestrict = true; // Restrict jumping to prevent bunnyhopping when holding key - Soda
  751. // Lower viewheight to suggest bending knees and then launching, still TODO - Soda
  752. S_StartSound (player->mo, GameModeInfo->playerSounds[sk_noway]); // Audibly grunt
  753. player->mo->momz += 4.15*FRACUNIT; // PCLASS_FIXME: make jump height pclass property
  754. player->mo->intflags &= ~MIF_ONMOBJ;
  755. player->mo->flags2 |= MF2_LOGRAV;
  756. player->jumptime = 1;
  757. jumpStage = 1;
  758. }
  759. }
  760. }
  761. else if(jumpStage == 1)
  762. {
  763. if(cmd->actions & AC_JUMP) // Jump key is down
  764. {
  765. if(player->mo->momz <= 0*FRACUNIT) // Player has neutral or negative momentum
  766. jumpStage = 2;
  767. }
  768. else
  769. jumpStage = 2;
  770. }
  771. else if(jumpStage == 2) // on the way down; ran out of upward momentum but didn't release jump yet
  772. {
  773. player->mo->flags2 &= ~MF2_LOGRAV;
  774. if(player->mo->momz > 1.85*FRACUNIT) // Cap upward momentum to accentuate height control
  775. {
  776. player->mo->momz = 1.85*FRACUNIT;
  777. }
  778. if(player->mo->momz < -12*FRACUNIT) // Cap downward momentum
  779. {
  780. player->mo->momz = -12*FRACUNIT;
  781. }
  782. if(cmd->actions != AC_JUMP) // Jump key isn't down
  783. {
  784. jumpStage = 3; // player has released jump key from falling, prep jetpack for firing
  785. }
  786. }
  787. else if(jumpStage == 3) // released jump button; jet pack ready to fire
  788. {
  789. jumpRestrict = false; // Allow holding to immediately boost again as long as you released the key once before, like in Quake. Makes it easier for some of the tighter platforming bits. - Soda
  790. player->mo->flags2 &= ~MF2_LOGRAV;
  791. if(player->mo->momz < -12*FRACUNIT) // Cap downward momentum
  792. {
  793. player->mo->momz = -12*FRACUNIT;
  794. }
  795. if(cmd->actions & AC_JUMP && player->mo->z >= (player->mo->floorz + 16*FRACUNIT) && havejetpack == true) // Jump key is down at all and player isn't too close to the ground, only if they have the jetpack
  796. {
  797. jumpStage = 4; // activate jetpack
  798. }
  799. }
  800. else if(jumpStage == 4) // jetpack activated and thrusting
  801. {
  802. player->mo->flags2 |= MF2_LOGRAV;
  803. jumpRestrict = true; // Annoying to accidentally jump when jetpacking straight to a ledge, so this is in place.
  804. jetpackrecharging = false;
  805. if(player->mo->z < (player->mo->floorz + 16*FRACUNIT)) // Too little distance to keep using the jetpack? Force a landing.
  806. {
  807. jumpStage = 3;
  808. }
  809. if(soundlooptimer == 0)
  810. {
  811. S_StartSound (player->mo, GameModeInfo->playerSounds[sk_radio]); // Play sound
  812. soundlooptimer = 12;
  813. }
  814. if(player->mo->momz > 2.75*FRACUNIT) // Cap upward momentum
  815. {
  816. player->mo->momz = 2.75*FRACUNIT;
  817. }
  818. if(player->mo->momz < -12*FRACUNIT) // Cap downward momentum
  819. {
  820. player->mo->momz = -12*FRACUNIT;
  821. }
  822. if(cmd->actions & AC_JUMP && jetpackfuel > 0) // Jump key is down and player still has some boost remaining
  823. {
  824. player->mo->momz += 0.35*FRACUNIT; // Thrust rather weakly every frame
  825. jetpackfuel--;
  826. }
  827. else //jump key released
  828. {
  829. jumpStage = 5; // stop jetpack thrust (continue idling, though)
  830. //soundlooptimer = 0;
  831. }
  832. }
  833. else if(jumpStage == 5) // jetpack activated and idling
  834. {
  835. player->mo->flags2 |= MF2_LOGRAV;
  836. jumpRestrict = false; // Let go, the player isn't actively trying to move up anyway
  837. if(player->mo->momz > 0 && jetpackfuel > 0) // Still heading up? Take fuel despite not actively thrusting. This ensures you can't exploit the intended max upward range by tapping instead of holding. Also reduce momentum a tad.
  838. {
  839. jetpackfuel--;
  840. }
  841. if(soundlooptimer == 0)
  842. {
  843. S_StartSound (player->mo, GameModeInfo->playerSounds[sk_plfall]); // Play sound
  844. soundlooptimer = 10;
  845. }
  846. if(player->mo->z < (player->mo->floorz + 12*FRACUNIT)) // Too little distance to keep using the jetpack? Force a landing.
  847. {
  848. jumpStage = 3;
  849. }
  850. if(player->mo->momz > 2.75*FRACUNIT) // Cap upward momentum
  851. {
  852. player->mo->momz = 2.75*FRACUNIT;
  853. }
  854. if(player->mo->momz < -12*FRACUNIT) // Cap downward momentum
  855. {
  856. player->mo->momz = -12*FRACUNIT;
  857. }
  858. if(player->mo->momz < -5.8*FRACUNIT) // Slow excess downward movement with gradually added resistance (+0.1 offset from intended 5.7 because of 0.2 large wraparound, will fix later with a cap that latches properly)
  859. {
  860. player->mo->momz += 0.2*FRACUNIT;
  861. }
  862. if(cmd->actions & AC_JUMP) // Jump key is down at all
  863. {
  864. if(jetpackfuel > 0)
  865. jumpStage = 4; // activate jump pack
  866. }
  867. }
  868. if((jetpackrecharging)&&(jetpackfuel < 60))
  869. jetpackfuel++;
  870. }
  871.  
  872. P_CalcHeight(player); // Determines view height and bobbing
  873.  
  874. // haleyjd: are we falling? might need to scream :->
  875. if(!comp[comp_fallingdmg] && demo_version >= 329)
  876. {
  877. if(player->mo->momz >= 0)
  878. player->mo->intflags &= ~MIF_SCREAMED;
  879.  
  880. if(player->mo->momz <= -17.5*FRACUNIT && // adjusted for half scale - soda
  881. player->mo->momz >= -20*FRACUNIT && // adjusted for half scale - soda
  882. !(player->mo->intflags & MIF_SCREAMED))
  883. {
  884. player->mo->intflags |= MIF_SCREAMED;
  885. S_StartSound(player->mo, GameModeInfo->playerSounds[sk_plfall]);
  886. }
  887. }
  888.  
  889. // Determine if there's anything about the sector you're in that's
  890. // going to affect you, like painful floors.
  891.  
  892. if(P_SectorIsSpecial(player->mo->subsector->sector))
  893. P_PlayerInSpecialSector(player);
  894.  
  895. // haleyjd 08/23/05: terrain-based effects
  896. P_PlayerOnSpecialFlat(player);
  897.  
  898. // haleyjd: Heretic current specials
  899. P_HereticCurrent(player);
  900.  
  901. // Check for weapon change.
  902.  
  903. // A special event has no other buttons.
  904.  
  905. if(cmd->buttons & BT_SPECIAL)
  906. cmd->buttons = 0;
  907.  
  908. if(cmd->buttons & BT_CHANGE)
  909. {
  910. // The actual changing of the weapon is done
  911. // when the weapon psprite can do it
  912. // (read: not in the middle of an attack).
  913.  
  914. weapontype_t newweapon = (cmd->buttons & BT_WEAPONMASK) >> BT_WEAPONSHIFT;
  915.  
  916. // killough 3/22/98: For demo compatibility we must perform the fist
  917. // and SSG weapons switches here, rather than in G_BuildTiccmd(). For
  918. // other games which rely on user preferences, we must use the latter.
  919.  
  920. // WEAPON_FIXME: bunch of crap (compat weapon changing)
  921.  
  922. if(demo_compatibility)
  923. {
  924. // compatibility mode -- required for old demos -- killough
  925. if(newweapon == wp_fist && player->weaponowned[wp_chainsaw] &&
  926. (player->readyweapon != wp_chainsaw ||
  927. !player->powers[pw_strength]))
  928. newweapon = wp_chainsaw;
  929. if(enable_ssg &&
  930. newweapon == wp_shotgun &&
  931. player->weaponowned[wp_supershotgun] &&
  932. player->readyweapon != wp_supershotgun)
  933. newweapon = wp_supershotgun;
  934. }
  935.  
  936. // killough 2/8/98, 3/22/98 -- end of weapon selection changes
  937.  
  938. // WEAPON_FIXME: setting pendingweapon
  939.  
  940. if(player->weaponowned[newweapon] && newweapon != player->readyweapon)
  941. {
  942. // Do not go to plasma or BFG in shareware, even if cheated.
  943. // haleyjd 06/28/13: generalized for EDF weapon system
  944. weaponinfo_t *pendingweapon = P_GetPlayerWeapon(player, newweapon);
  945.  
  946. if(pendingweapon &&
  947. !(GameModeInfo->flags & GIF_SHAREWARE &&
  948. pendingweapon->flags & WPF_NOTSHAREWARE))
  949. {
  950. player->pendingweapon = newweapon;
  951. }
  952. }
  953. }
  954.  
  955. // check for use
  956.  
  957. if(cmd->buttons & BT_USE)
  958. {
  959. if(!player->usedown)
  960. {
  961. P_UseLines(player);
  962. player->usedown = true;
  963. }
  964. }
  965. else
  966. player->usedown = false;
  967.  
  968. // cycle psprites
  969.  
  970. P_MovePsprites (player);
  971.  
  972. // Counters, time dependent power ups.
  973.  
  974. // Strength counts up to diminish fade.
  975.  
  976. if(player->powers[pw_strength])
  977. player->powers[pw_strength]++;
  978.  
  979. // killough 1/98: Make idbeholdx toggle:
  980.  
  981. if(player->powers[pw_invulnerability] > 0) // killough
  982. player->powers[pw_invulnerability]--;
  983.  
  984. if(player->powers[pw_invisibility] > 0)
  985. {
  986. if(!--player->powers[pw_invisibility] )
  987. player->mo->flags &= ~MF_SHADOW;
  988. }
  989.  
  990. if(player->powers[pw_infrared] > 0) // killough
  991. player->powers[pw_infrared]--;
  992.  
  993. // haleyjd: torch
  994. if(player->powers[pw_torch] > 0)
  995. player->powers[pw_torch]--;
  996.  
  997. if(player->powers[pw_ironfeet] > 0) // killough
  998. player->powers[pw_ironfeet]--;
  999.  
  1000. if(player->powers[pw_ghost] > 0) // haleyjd
  1001. {
  1002. if(!--player->powers[pw_ghost])
  1003. player->mo->flags3 &= ~MF3_GHOST;
  1004. }
  1005.  
  1006. if(player->powers[pw_totalinvis] > 0) // haleyjd
  1007. {
  1008. if(!--player->powers[pw_totalinvis])
  1009. {
  1010. player->mo->flags2 &= ~MF2_DONTDRAW;
  1011. player->mo->flags4 &= ~MF4_TOTALINVISIBLE;
  1012. }
  1013. }
  1014.  
  1015. if(player->powers[pw_flight] > 0) // haleyjd 06/05/12
  1016. {
  1017. if(!--player->powers[pw_flight])
  1018. P_PlayerStopFlight(player);
  1019. }
  1020.  
  1021. if(player->damagecount)
  1022. player->damagecount--;
  1023.  
  1024. if(player->bonuscount)
  1025. player->bonuscount--;
  1026.  
  1027. // get length of time left on any active lighting powerup
  1028. int lighttics = P_PlayerLightTics(player);
  1029. int lightsource = P_PlayerLightSourceType(player);
  1030.  
  1031. // Handling colormaps.
  1032. if(player->powers[pw_invulnerability])
  1033. {
  1034. if(player->powers[pw_invulnerability] > 4*32 ||
  1035. player->powers[pw_invulnerability] & 8)
  1036. player->fixedcolormap = INVERSECOLORMAP;
  1037. else
  1038. player->fixedcolormap = 0;
  1039. }
  1040. else if(lightsource != PLS_NONE)
  1041. {
  1042. if(lighttics > 0 && lighttics <= 4*32) // fading out?
  1043. player->fixedcolormap = ((lighttics & 8) != 0);
  1044. else
  1045. {
  1046. // haleyjd: if player has a torch, do flickering
  1047. if(lightsource == PLS_TORCH)
  1048. P_doTorchFlicker(player);
  1049. else
  1050. player->fixedcolormap = 1; // almost full bright
  1051. }
  1052. }
  1053. else
  1054. player->fixedcolormap = 0;
  1055.  
  1056. // haleyjd 01/21/07: clear earthquake flag before running quake thinkers later
  1057. player->quake = 0;
  1058. }
  1059.  
  1060. //
  1061. // P_SetPlayerAttacker
  1062. //
  1063. // haleyjd 09/30/2011: Needed function to fix a BOOM problem wherein
  1064. // player_t::attacker is not properly reference-counted against the
  1065. // Mobj to which it points.
  1066. //
  1067. // Usually the worst consequence of this problem was having your view
  1068. // spin around to a pseudo-random angle when watching a Lost Soul that
  1069. // had killed you be removed from the game world.
  1070. //
  1071. void P_SetPlayerAttacker(player_t *player, Mobj *attacker)
  1072. {
  1073. if(full_demo_version >= make_full_version(340, 17))
  1074. P_SetTarget<Mobj>(&player->attacker, attacker);
  1075. else
  1076. player->attacker = attacker;
  1077. }
  1078.  
  1079. //
  1080. // P_PlayerStartFlight
  1081. //
  1082. // Call this to start the player flying.
  1083. //
  1084. void P_PlayerStartFlight(player_t *player, bool thrustup)
  1085. {
  1086. if(full_demo_version < make_full_version(340, 23))
  1087. return;
  1088.  
  1089. player->mo->flags4 |= MF4_FLY;
  1090. player->mo->flags |= MF_NOGRAVITY;
  1091.  
  1092. if(thrustup && player->mo->z <= player->mo->floorz)
  1093. player->flyheight = 2 * FLIGHT_IMPULSE_AMT;
  1094.  
  1095. // TODO: stop screaming if falling
  1096. }
  1097.  
  1098. //
  1099. // P_PlayerStopFlight
  1100. //
  1101. // Call this to make the player stop flying.
  1102. //
  1103. void P_PlayerStopFlight(player_t *player)
  1104. {
  1105. if(full_demo_version < make_full_version(340, 23))
  1106. return;
  1107.  
  1108. player->mo->flags4 &= ~MF4_FLY;
  1109. player->mo->flags &= ~MF_NOGRAVITY;
  1110. }
  1111.  
  1112. #if 0
  1113. // Small native functions for player stuff
  1114.  
  1115. static cell AMX_NATIVE_CALL sm_getplayername(AMX *amx, cell *params)
  1116. {
  1117. int err, pnum, packed;
  1118. cell *cstr;
  1119.  
  1120. pnum = (int)params[1] - 1;
  1121. packed = (int)params[3];
  1122.  
  1123. if((err = amx_GetAddr(amx, params[2], &cstr)) != AMX_ERR_NONE)
  1124. {
  1125. amx_RaiseError(amx, err);
  1126. return 0;
  1127. }
  1128.  
  1129. if(pnum < 0 || pnum >= MAXPLAYERS)
  1130. {
  1131. amx_RaiseError(amx, AMX_ERR_BOUNDS);
  1132. return 0;
  1133. }
  1134.  
  1135. if(!playeringame[pnum])
  1136. amx_SetString(cstr, "null", packed, 0);
  1137. else
  1138. amx_SetString(cstr, players[pnum].name, packed, 0);
  1139.  
  1140. return 0;
  1141. }
  1142.  
  1143. AMX_NATIVE_INFO user_Natives[] =
  1144. {
  1145. { "_GetPlayerName", sm_getplayername },
  1146. { NULL, NULL }
  1147. };
  1148. #endif
  1149.  
  1150. //----------------------------------------------------------------------------
  1151. //
  1152. // $Log: p_user.c,v $
  1153. // Revision 1.14 1998/05/12 12:47:25 phares
  1154. // Removed OVER UNDER code
  1155. //
  1156. // Revision 1.13 1998/05/10 23:38:04 killough
  1157. // Add #include p_user.h to ensure consistent prototypes
  1158. //
  1159. // Revision 1.12 1998/05/05 15:35:20 phares
  1160. // Documentation and Reformatting changes
  1161. //
  1162. // Revision 1.11 1998/05/03 23:21:04 killough
  1163. // Fix #includes and remove unnecessary decls at the top, nothing else
  1164. //
  1165. // Revision 1.10 1998/03/23 15:24:50 phares
  1166. // Changed pushers to linedef control
  1167. //
  1168. // Revision 1.9 1998/03/23 03:35:24 killough
  1169. // Move weapons changes to G_BuildTiccmd, fix idclip
  1170. //
  1171. // Revision 1.8 1998/03/12 14:28:50 phares
  1172. // friction and IDCLIP changes
  1173. //
  1174. // Revision 1.7 1998/03/09 18:26:55 phares
  1175. // Fixed bug in neighboring variable friction sectors
  1176. //
  1177. // Revision 1.6 1998/02/27 08:10:08 phares
  1178. // Added optional player bobbing
  1179. //
  1180. // Revision 1.5 1998/02/24 08:46:42 phares
  1181. // Pushers, recoil, new friction, and over/under work
  1182. //
  1183. // Revision 1.4 1998/02/15 02:47:57 phares
  1184. // User-defined keys
  1185. //
  1186. // Revision 1.3 1998/02/09 03:13:20 killough
  1187. // Improve weapon control and add preferences
  1188. //
  1189. // Revision 1.2 1998/01/26 19:24:34 phares
  1190. // First rev with no ^Ms
  1191. //
  1192. // Revision 1.1.1.1 1998/01/19 14:03:01 rand
  1193. // Lee's Jan 19 sources
  1194. //
  1195. //----------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement