g_rogue_phys.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Copyright (c) ZeniMax Media Inc.
  2. // Licensed under the GNU General Public License 2.0.
  3. #include "../g_local.h"
  4. //============
  5. // ROGUE
  6. /*
  7. =============
  8. SV_Physics_NewToss
  9. Toss, bounce, and fly movement. When on ground and no velocity, do nothing. With velocity,
  10. slide.
  11. =============
  12. */
  13. void SV_Physics_NewToss(edict_t *ent)
  14. {
  15. trace_t trace;
  16. vec3_t move;
  17. // float backoff;
  18. edict_t *slave;
  19. bool wasinwater;
  20. bool isinwater;
  21. float speed, newspeed;
  22. vec3_t old_origin;
  23. // float firstmove;
  24. // int mask;
  25. // regular thinking
  26. SV_RunThink(ent);
  27. // if not a team captain, so movement will be handled elsewhere
  28. if (ent->flags & FL_TEAMSLAVE)
  29. return;
  30. wasinwater = ent->waterlevel;
  31. // find out what we're sitting on.
  32. move = ent->s.origin;
  33. move[2] -= 0.25f;
  34. trace = gi.trace(ent->s.origin, ent->mins, ent->maxs, move, ent, ent->clipmask);
  35. if (ent->groundentity && ent->groundentity->inuse)
  36. ent->groundentity = trace.ent;
  37. else
  38. ent->groundentity = nullptr;
  39. // if we're sitting on something flat and have no velocity of our own, return.
  40. if (ent->groundentity && (trace.plane.normal[2] == 1.0f) &&
  41. !ent->velocity[0] && !ent->velocity[1] && !ent->velocity[2])
  42. {
  43. return;
  44. }
  45. // store the old origin
  46. old_origin = ent->s.origin;
  47. SV_CheckVelocity(ent);
  48. // add gravity
  49. SV_AddGravity(ent);
  50. if (ent->avelocity[0] || ent->avelocity[1] || ent->avelocity[2])
  51. SV_AddRotationalFriction(ent);
  52. // add friction
  53. speed = ent->velocity.length();
  54. if (ent->waterlevel) // friction for water movement
  55. {
  56. newspeed = speed - (sv_waterfriction * 6 * (float) ent->waterlevel);
  57. if (newspeed < 0)
  58. newspeed = 0;
  59. newspeed /= speed;
  60. ent->velocity *= newspeed;
  61. }
  62. else if (!ent->groundentity) // friction for air movement
  63. {
  64. newspeed = speed - ((sv_friction));
  65. if (newspeed < 0)
  66. newspeed = 0;
  67. newspeed /= speed;
  68. ent->velocity *= newspeed;
  69. }
  70. else // use ground friction
  71. {
  72. newspeed = speed - (sv_friction * 6);
  73. if (newspeed < 0)
  74. newspeed = 0;
  75. newspeed /= speed;
  76. ent->velocity *= newspeed;
  77. }
  78. SV_FlyMove(ent, gi.frame_time_s, ent->clipmask);
  79. gi.linkentity(ent);
  80. G_TouchTriggers(ent);
  81. // check for water transition
  82. wasinwater = (ent->watertype & MASK_WATER);
  83. ent->watertype = gi.pointcontents(ent->s.origin);
  84. isinwater = ent->watertype & MASK_WATER;
  85. if (isinwater)
  86. ent->waterlevel = WATER_FEET;
  87. else
  88. ent->waterlevel = WATER_NONE;
  89. if (!wasinwater && isinwater)
  90. gi.positioned_sound(old_origin, g_edicts, CHAN_AUTO, gi.soundindex("misc/h2ohit1.wav"), 1, 1, 0);
  91. else if (wasinwater && !isinwater)
  92. gi.positioned_sound(ent->s.origin, g_edicts, CHAN_AUTO, gi.soundindex("misc/h2ohit1.wav"), 1, 1, 0);
  93. // move teamslaves
  94. for (slave = ent->teamchain; slave; slave = slave->teamchain)
  95. {
  96. slave->s.origin = ent->s.origin;
  97. gi.linkentity(slave);
  98. }
  99. }
  100. // ROGUE
  101. //============