g_chase.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // Copyright (c) ZeniMax Media Inc.
  2. // Licensed under the GNU General Public License 2.0.
  3. #include "g_local.h"
  4. void UpdateChaseCam(edict_t *ent)
  5. {
  6. vec3_t o, ownerv, goal;
  7. edict_t *targ;
  8. vec3_t forward, right;
  9. trace_t trace;
  10. int i;
  11. vec3_t oldgoal;
  12. vec3_t angles;
  13. // is our chase target gone?
  14. if (!ent->client->chase_target->inuse
  15. || ent->client->chase_target->client->resp.spectator) {
  16. edict_t *old = ent->client->chase_target;
  17. ChaseNext(ent);
  18. if (ent->client->chase_target == old) {
  19. ent->client->chase_target = NULL;
  20. ent->client->ps.pmove.pm_flags &= ~PMF_NO_PREDICTION;
  21. return;
  22. }
  23. }
  24. targ = ent->client->chase_target;
  25. VectorCopy(targ->s.origin, ownerv);
  26. VectorCopy(ent->s.origin, oldgoal);
  27. ownerv[2] += targ->viewheight;
  28. VectorCopy(targ->client->v_angle, angles);
  29. if (angles[PITCH] > 56)
  30. angles[PITCH] = 56;
  31. AngleVectors (angles, forward, right, NULL);
  32. VectorNormalize(forward);
  33. VectorMA(ownerv, -30, forward, o);
  34. if (o[2] < targ->s.origin[2] + 20)
  35. o[2] = targ->s.origin[2] + 20;
  36. // jump animation lifts
  37. if (!targ->groundentity)
  38. o[2] += 16;
  39. trace = gi.trace(ownerv, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
  40. VectorCopy(trace.endpos, goal);
  41. VectorMA(goal, 2, forward, goal);
  42. // pad for floors and ceilings
  43. VectorCopy(goal, o);
  44. o[2] += 6;
  45. trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
  46. if (trace.fraction < 1) {
  47. VectorCopy(trace.endpos, goal);
  48. goal[2] -= 6;
  49. }
  50. VectorCopy(goal, o);
  51. o[2] -= 6;
  52. trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
  53. if (trace.fraction < 1) {
  54. VectorCopy(trace.endpos, goal);
  55. goal[2] += 6;
  56. }
  57. if (targ->deadflag)
  58. ent->client->ps.pmove.pm_type = PM_DEAD;
  59. else
  60. ent->client->ps.pmove.pm_type = PM_FREEZE;
  61. VectorCopy(goal, ent->s.origin);
  62. for (i=0 ; i<3 ; i++)
  63. ent->client->ps.pmove.delta_angles[i] = ANGLE2SHORT(targ->client->v_angle[i] - ent->client->resp.cmd_angles[i]);
  64. if (targ->deadflag) {
  65. ent->client->ps.viewangles[ROLL] = 40;
  66. ent->client->ps.viewangles[PITCH] = -15;
  67. ent->client->ps.viewangles[YAW] = targ->client->killer_yaw;
  68. } else {
  69. VectorCopy(targ->client->v_angle, ent->client->ps.viewangles);
  70. VectorCopy(targ->client->v_angle, ent->client->v_angle);
  71. }
  72. ent->viewheight = 0;
  73. ent->client->ps.pmove.pm_flags |= PMF_NO_PREDICTION;
  74. gi.linkentity(ent);
  75. }
  76. void ChaseNext(edict_t *ent)
  77. {
  78. int i;
  79. edict_t *e;
  80. if (!ent->client->chase_target)
  81. return;
  82. i = ent->client->chase_target - g_edicts;
  83. do {
  84. i++;
  85. if (i > maxclients->value)
  86. i = 1;
  87. e = g_edicts + i;
  88. if (!e->inuse)
  89. continue;
  90. if (!e->client->resp.spectator)
  91. break;
  92. } while (e != ent->client->chase_target);
  93. ent->client->chase_target = e;
  94. ent->client->update_chase = true;
  95. }
  96. void ChasePrev(edict_t *ent)
  97. {
  98. int i;
  99. edict_t *e;
  100. if (!ent->client->chase_target)
  101. return;
  102. i = ent->client->chase_target - g_edicts;
  103. do {
  104. i--;
  105. if (i < 1)
  106. i = maxclients->value;
  107. e = g_edicts + i;
  108. if (!e->inuse)
  109. continue;
  110. if (!e->client->resp.spectator)
  111. break;
  112. } while (e != ent->client->chase_target);
  113. ent->client->chase_target = e;
  114. ent->client->update_chase = true;
  115. }
  116. void GetChaseTarget(edict_t *ent)
  117. {
  118. int i;
  119. edict_t *other;
  120. for (i = 1; i <= maxclients->value; i++) {
  121. other = g_edicts + i;
  122. if (other->inuse && !other->client->resp.spectator) {
  123. ent->client->chase_target = other;
  124. ent->client->update_chase = true;
  125. UpdateChaseCam(ent);
  126. return;
  127. }
  128. }
  129. gi.centerprintf(ent, "No other players to chase.");
  130. }