g_chase.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 = NULL;
  28. return;
  29. }
  30. targ = ent->client->chase_target;
  31. VectorCopy(targ->s.origin, ownerv);
  32. VectorCopy(ent->s.origin, oldgoal);
  33. ownerv[2] += targ->viewheight;
  34. VectorCopy(targ->client->v_angle, angles);
  35. if (angles[PITCH] > 56)
  36. angles[PITCH] = 56;
  37. AngleVectors (angles, forward, right, NULL);
  38. VectorNormalize(forward);
  39. VectorMA(ownerv, -30, forward, o);
  40. if (o[2] < targ->s.origin[2] + 20)
  41. o[2] = targ->s.origin[2] + 20;
  42. // jump animation lifts
  43. if (!targ->groundentity)
  44. o[2] += 16;
  45. trace = gi.trace(ownerv, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
  46. VectorCopy(trace.endpos, goal);
  47. VectorMA(goal, 2, forward, goal);
  48. // pad for floors and ceilings
  49. VectorCopy(goal, o);
  50. o[2] += 6;
  51. trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
  52. if (trace.fraction < 1) {
  53. VectorCopy(trace.endpos, goal);
  54. goal[2] -= 6;
  55. }
  56. VectorCopy(goal, o);
  57. o[2] -= 6;
  58. trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
  59. if (trace.fraction < 1) {
  60. VectorCopy(trace.endpos, goal);
  61. goal[2] += 6;
  62. }
  63. ent->client->ps.pmove.pm_type = PM_FREEZE;
  64. VectorCopy(goal, ent->s.origin);
  65. for (i=0 ; i<3 ; i++)
  66. ent->client->ps.pmove.delta_angles[i] = ANGLE2SHORT(targ->client->v_angle[i] - ent->client->resp.cmd_angles[i]);
  67. VectorCopy(targ->client->v_angle, ent->client->ps.viewangles);
  68. VectorCopy(targ->client->v_angle, ent->client->v_angle);
  69. ent->viewheight = 0;
  70. ent->client->ps.pmove.pm_flags |= PMF_NO_PREDICTION;
  71. gi.linkentity(ent);
  72. if ((!ent->client->showscores && !ent->client->menu &&
  73. !ent->client->showinventory && !ent->client->showhelp &&
  74. !(level.framenum & 31)) || ent->client->update_chase) {
  75. char s[1024];
  76. ent->client->update_chase = false;
  77. sprintf(s, "xv 0 yb -68 string2 \"Chasing %s\"",
  78. targ->client->pers.netname);
  79. gi.WriteByte (svc_layout);
  80. gi.WriteString (s);
  81. gi.unicast(ent, false);
  82. }
  83. }
  84. void ChaseNext(edict_t *ent)
  85. {
  86. int i;
  87. edict_t *e;
  88. if (!ent->client->chase_target)
  89. return;
  90. i = ent->client->chase_target - g_edicts;
  91. do {
  92. i++;
  93. if (i > maxclients->value)
  94. i = 1;
  95. e = g_edicts + i;
  96. if (!e->inuse)
  97. continue;
  98. if (e->solid != SOLID_NOT)
  99. break;
  100. } while (e != ent->client->chase_target);
  101. ent->client->chase_target = e;
  102. ent->client->update_chase = true;
  103. }
  104. void ChasePrev(edict_t *ent)
  105. {
  106. int i;
  107. edict_t *e;
  108. if (!ent->client->chase_target)
  109. return;
  110. i = ent->client->chase_target - g_edicts;
  111. do {
  112. i--;
  113. if (i < 1)
  114. i = maxclients->value;
  115. e = g_edicts + i;
  116. if (!e->inuse)
  117. continue;
  118. if (e->solid != SOLID_NOT)
  119. break;
  120. } while (e != ent->client->chase_target);
  121. ent->client->chase_target = e;
  122. ent->client->update_chase = true;
  123. }