g_chase.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. Copyright (C) 1997-2001 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include "g_local.h"
  16. void UpdateChaseCam(edict_t *ent)
  17. {
  18. vec3_t o, ownerv, goal;
  19. edict_t *targ;
  20. vec3_t forward, right;
  21. trace_t trace;
  22. int i;
  23. vec3_t oldgoal;
  24. vec3_t angles;
  25. // is our chase target gone?
  26. if (!ent->client->chase_target->inuse
  27. || ent->client->chase_target->client->resp.spectator) {
  28. edict_t *old = ent->client->chase_target;
  29. ChaseNext(ent);
  30. if (ent->client->chase_target == old) {
  31. ent->client->chase_target = NULL;
  32. ent->client->ps.pmove.pm_flags &= ~PMF_NO_PREDICTION;
  33. return;
  34. }
  35. }
  36. targ = ent->client->chase_target;
  37. VectorCopy(targ->s.origin, ownerv);
  38. VectorCopy(ent->s.origin, oldgoal);
  39. ownerv[2] += targ->viewheight;
  40. VectorCopy(targ->client->v_angle, angles);
  41. if (angles[PITCH] > 56)
  42. angles[PITCH] = 56;
  43. AngleVectors (angles, forward, right, NULL);
  44. VectorNormalize(forward);
  45. VectorMA(ownerv, -30, forward, o);
  46. if (o[2] < targ->s.origin[2] + 20)
  47. o[2] = targ->s.origin[2] + 20;
  48. // jump animation lifts
  49. if (!targ->groundentity)
  50. o[2] += 16;
  51. trace = gi.trace(ownerv, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
  52. VectorCopy(trace.endpos, goal);
  53. VectorMA(goal, 2, forward, goal);
  54. // pad for floors and ceilings
  55. VectorCopy(goal, o);
  56. o[2] += 6;
  57. trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
  58. if (trace.fraction < 1) {
  59. VectorCopy(trace.endpos, goal);
  60. goal[2] -= 6;
  61. }
  62. VectorCopy(goal, o);
  63. o[2] -= 6;
  64. trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
  65. if (trace.fraction < 1) {
  66. VectorCopy(trace.endpos, goal);
  67. goal[2] += 6;
  68. }
  69. if (targ->deadflag)
  70. ent->client->ps.pmove.pm_type = PM_DEAD;
  71. else
  72. ent->client->ps.pmove.pm_type = PM_FREEZE;
  73. VectorCopy(goal, ent->s.origin);
  74. for (i=0 ; i<3 ; i++)
  75. ent->client->ps.pmove.delta_angles[i] = ANGLE2SHORT(targ->client->v_angle[i] - ent->client->resp.cmd_angles[i]);
  76. if (targ->deadflag) {
  77. ent->client->ps.viewangles[ROLL] = 40;
  78. ent->client->ps.viewangles[PITCH] = -15;
  79. ent->client->ps.viewangles[YAW] = targ->client->killer_yaw;
  80. } else {
  81. VectorCopy(targ->client->v_angle, ent->client->ps.viewangles);
  82. VectorCopy(targ->client->v_angle, ent->client->v_angle);
  83. }
  84. ent->viewheight = 0;
  85. ent->client->ps.pmove.pm_flags |= PMF_NO_PREDICTION;
  86. gi.linkentity(ent);
  87. }
  88. void ChaseNext(edict_t *ent)
  89. {
  90. int i;
  91. edict_t *e;
  92. if (!ent->client->chase_target)
  93. return;
  94. i = ent->client->chase_target - g_edicts;
  95. do {
  96. i++;
  97. if (i > maxclients->value)
  98. i = 1;
  99. e = g_edicts + i;
  100. if (!e->inuse)
  101. continue;
  102. if (!e->client->resp.spectator)
  103. break;
  104. } while (e != ent->client->chase_target);
  105. ent->client->chase_target = e;
  106. ent->client->update_chase = true;
  107. }
  108. void ChasePrev(edict_t *ent)
  109. {
  110. int i;
  111. edict_t *e;
  112. if (!ent->client->chase_target)
  113. return;
  114. i = ent->client->chase_target - g_edicts;
  115. do {
  116. i--;
  117. if (i < 1)
  118. i = maxclients->value;
  119. e = g_edicts + i;
  120. if (!e->inuse)
  121. continue;
  122. if (!e->client->resp.spectator)
  123. break;
  124. } while (e != ent->client->chase_target);
  125. ent->client->chase_target = e;
  126. ent->client->update_chase = true;
  127. }
  128. void GetChaseTarget(edict_t *ent)
  129. {
  130. int i;
  131. edict_t *other;
  132. for (i = 1; i <= maxclients->value; i++) {
  133. other = g_edicts + i;
  134. if (other->inuse && !other->client->resp.spectator) {
  135. ent->client->chase_target = other;
  136. ent->client->update_chase = true;
  137. UpdateChaseCam(ent);
  138. return;
  139. }
  140. }
  141. gi.centerprintf(ent, "No other players to chase.");
  142. }