new_ai.qc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* Copyright (C) 1996-2022 id Software LLC
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  13. See file, 'COPYING', for details.
  14. */
  15. // new ai functions
  16. //
  17. // pmack
  18. // ================================================================
  19. // ai_orbit - used to have an object orbit an entity.
  20. //
  21. // destEnt: the entity to orbit
  22. // radius: how large a radius to orbit at (0 will just track)
  23. // offset: center of the orbit. this is added to dest.origin.
  24. //
  25. // Uses self.orbitPosition to determine current destination.
  26. // ================================================================
  27. void(entity destEnt, float radius, vector offset) ai_orbit =
  28. {
  29. local vector dir;
  30. local float dist;
  31. if (self.orbitPosition > 3)
  32. self.orbitPosition = 0;
  33. else if (self.orbitPosition < 0)
  34. self.orbitPosition = 0;
  35. traceline ( self.origin, destEnt.origin + offset, TRUE, world);
  36. if ( trace_fraction < 1 )
  37. {
  38. setorigin (self, destEnt.origin + offset);
  39. self.orbitPosition = self.orbitPosition + 1;
  40. return;
  41. }
  42. if ( self.orbitPosition == 0)
  43. {
  44. dir = (destEnt.origin + offset) - self.origin;
  45. dir_x = dir_x + radius;
  46. }
  47. else if ( self.orbitPosition == 1)
  48. {
  49. dir = (destEnt.origin + offset) - self.origin;
  50. dir_y = dir_y + radius;
  51. }
  52. else if ( self.orbitPosition == 2)
  53. {
  54. dir = (destEnt.origin + offset) - self.origin;
  55. dir_x = dir_x - radius;
  56. }
  57. else
  58. {
  59. dir = (destEnt.origin + offset) - self.origin;
  60. dir_y = dir_y - radius;
  61. }
  62. dist = vlen(dir);
  63. if( dist < 8 )
  64. {
  65. self.orbitPosition = self.orbitPosition + 1;
  66. }
  67. else if( dist < 50 )
  68. {
  69. self.velocity = normalize(dir);
  70. self.velocity = self.velocity * 150;
  71. }
  72. else
  73. {
  74. self.velocity = normalize(dir);
  75. self.velocity = self.velocity * 500;
  76. }
  77. };
  78. // ================================================================
  79. // ai_track - used to have an object chase/track an enemy. the object
  80. // flies directly at the destEnt's view_ofs point.
  81. //
  82. // destEnt: the entity to orbit
  83. // trackSpeed: the velocity multiplier (speed) of the object
  84. // ================================================================
  85. void(entity destEnt, float trackSpeed) ai_track =
  86. {
  87. local vector dir;
  88. dir = destEnt.origin + destEnt.view_ofs;
  89. dir = normalize(dir - self.origin);
  90. self.velocity = dir * trackSpeed;
  91. };
  92. // ================================================================
  93. // ViolentDeath
  94. // ================================================================
  95. void(string gibname, float dm) AccelerateGib =
  96. {
  97. local entity new;
  98. local float offset1;
  99. new = spawn();
  100. new.origin = self.origin;
  101. setmodel (new, gibname);
  102. setsize (new, '-8 -8 -8', '8 8 8');
  103. new.velocity = -1.25 * self.velocity;
  104. makevectors ( new.velocity );
  105. offset1 = random() * 300 - 150;
  106. new.velocity = new.velocity + v_right * offset1;
  107. offset1 = random() * 300 - 150;
  108. new.velocity = new.velocity + v_up * offset1;
  109. new.movetype = MOVETYPE_BOUNCE;
  110. new.solid = SOLID_NOT;
  111. new.avelocity_x = random()*600;
  112. new.avelocity_y = random()*600;
  113. new.avelocity_z = random()*600;
  114. new.think = SUB_Remove;
  115. new.ltime = time;
  116. new.nextthink = time + 10 + random()*10;
  117. new.frame = 0;
  118. new.flags = 0;
  119. };
  120. void(float gibCount) ViolentDeath =
  121. {
  122. while(gibCount > 0)
  123. {
  124. AccelerateGib ("progs/gib1.mdl", (-4 * gibCount));
  125. AccelerateGib ("progs/gib2.mdl", (-6 * gibCount));
  126. AccelerateGib ("progs/gib3.mdl", (-8 * gibCount));
  127. gibCount = gibCount - 3;
  128. }
  129. };
  130. entity(string gibname) StartGib =
  131. {
  132. local entity new;
  133. new = spawn();
  134. new.origin = self.origin;
  135. setmodel (new, gibname);
  136. setsize (new, '0 0 0', '0 0 0');
  137. new.movetype = MOVETYPE_BOUNCE;
  138. new.solid = SOLID_NOT;
  139. new.think = SUB_Remove;
  140. new.ltime = time;
  141. new.nextthink = time + 10 + random()*10;
  142. new.frame = 0;
  143. new.flags = 0;
  144. return new;
  145. };