p_trail.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. /*
  17. ==============================================================================
  18. PLAYER TRAIL
  19. ==============================================================================
  20. This is a circular list containing the a list of points of where
  21. the player has been recently. It is used by monsters for pursuit.
  22. .origin the spot
  23. .owner forward link
  24. .aiment backward link
  25. */
  26. #define TRAIL_LENGTH 8
  27. edict_t *trail[TRAIL_LENGTH];
  28. int trail_head;
  29. qboolean trail_active = false;
  30. #define NEXT(n) (((n) + 1) & (TRAIL_LENGTH - 1))
  31. #define PREV(n) (((n) - 1) & (TRAIL_LENGTH - 1))
  32. void PlayerTrail_Init (void)
  33. {
  34. int n;
  35. if (deathmatch->value /* FIXME || coop */)
  36. return;
  37. for (n = 0; n < TRAIL_LENGTH; n++)
  38. {
  39. trail[n] = G_Spawn();
  40. trail[n]->classname = "player_trail";
  41. }
  42. trail_head = 0;
  43. trail_active = true;
  44. }
  45. void PlayerTrail_Add (vec3_t spot)
  46. {
  47. vec3_t temp;
  48. if (!trail_active)
  49. return;
  50. VectorCopy (spot, trail[trail_head]->s.origin);
  51. trail[trail_head]->timestamp = level.time;
  52. VectorSubtract (spot, trail[PREV(trail_head)]->s.origin, temp);
  53. trail[trail_head]->s.angles[1] = vectoyaw (temp);
  54. trail_head = NEXT(trail_head);
  55. }
  56. void PlayerTrail_New (vec3_t spot)
  57. {
  58. if (!trail_active)
  59. return;
  60. PlayerTrail_Init ();
  61. PlayerTrail_Add (spot);
  62. }
  63. edict_t *PlayerTrail_PickFirst (edict_t *self)
  64. {
  65. int marker;
  66. int n;
  67. if (!trail_active)
  68. return NULL;
  69. for (marker = trail_head, n = TRAIL_LENGTH; n; n--)
  70. {
  71. if(trail[marker]->timestamp <= self->monsterinfo.trail_time)
  72. marker = NEXT(marker);
  73. else
  74. break;
  75. }
  76. if (visible(self, trail[marker]))
  77. {
  78. return trail[marker];
  79. }
  80. if (visible(self, trail[PREV(marker)]))
  81. {
  82. return trail[PREV(marker)];
  83. }
  84. return trail[marker];
  85. }
  86. edict_t *PlayerTrail_PickNext (edict_t *self)
  87. {
  88. int marker;
  89. int n;
  90. if (!trail_active)
  91. return NULL;
  92. for (marker = trail_head, n = TRAIL_LENGTH; n; n--)
  93. {
  94. if(trail[marker]->timestamp <= self->monsterinfo.trail_time)
  95. marker = NEXT(marker);
  96. else
  97. break;
  98. }
  99. return trail[marker];
  100. }
  101. edict_t *PlayerTrail_LastSpot (void)
  102. {
  103. return trail[PREV(trail_head)];
  104. }