earthq.qc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. // earthquake
  16. // ============================================================
  17. // Level-Wide Earthquakes
  18. // ============================================================
  19. float EQ_RANDOM = 1;
  20. void() stop_earthquake;
  21. void() earthquake_rumble =
  22. {
  23. if (self.attack_finished < time)
  24. stop_earthquake();
  25. else
  26. {
  27. sound( self, CHAN_VOICE, "equake/rumble.wav", 1, ATTN_NONE );
  28. self.think = earthquake_rumble;
  29. self.nextthink = time + 1;
  30. }
  31. };
  32. void() start_earthquake =
  33. {
  34. earthquake_active = 1;
  35. if ( self.spawnflags & EQ_RANDOM )
  36. self.attack_finished = time + random() * self.delay;
  37. else
  38. self.attack_finished = time + self.delay;
  39. earthquake_rumble();
  40. };
  41. void() stop_earthquake =
  42. {
  43. earthquake_active = 0;
  44. self.think = start_earthquake;
  45. if ( self.spawnflags & EQ_RANDOM )
  46. self.nextthink = time + random() * self.wait;
  47. else
  48. self.nextthink = time + self.wait;
  49. };
  50. /*QUAKED earthquake (0 1 0) (-8 -8 -8) (8 8 8) Random
  51. The Earthquake generator.
  52. delay - duration of the tremor (default 20)
  53. wait - time between tremors (default 60)
  54. weapon - richter scale of movement (default 40)
  55. RANDOM affects the times only. It will change the randomly between
  56. 0-n where n is the duration or time between.
  57. weapon - if you give a weapon value of 40, the X and Y displacement
  58. can vary between -20 and +20, a range of 40.
  59. */
  60. void() earthquake =
  61. {
  62. if (!self.delay)
  63. self.delay = 20;
  64. if (!self.wait)
  65. self.wait = 60;
  66. if (!self.weapon)
  67. self.weapon = 40;
  68. precache_sound ("equake/rumble.wav");
  69. earthquake_active = 0;
  70. earthquake_intensity = self.weapon * 0.5;
  71. setsize (self, '0 0 0', '0 0 0');
  72. self.think = stop_earthquake;
  73. self.nextthink = time + 1;
  74. };
  75. // ============================================================
  76. // Earthquake trigger
  77. // ============================================================
  78. void() earthquake_touch =
  79. {
  80. if (self.delay)
  81. {
  82. if ( self.attack_finished < time )
  83. {
  84. sound ( self, CHAN_VOICE, "equake/rumble.wav", 1, ATTN_NORM );
  85. self.attack_finished = time + 1;
  86. }
  87. if ( other.classname == "player" )
  88. {
  89. if ( other.flags & FL_ONGROUND )
  90. {
  91. other.velocity_x = other.velocity_x +
  92. (random() * self.weapon * 2) -
  93. self.weapon;
  94. other.velocity_y = other.velocity_y +
  95. (random() * self.weapon * 2) -
  96. self.weapon;
  97. other.velocity_z = other.velocity_z +
  98. (random() * self.weapon * 2) -
  99. self.weapon;
  100. }
  101. }
  102. }
  103. };
  104. void() earthquake_use =
  105. {
  106. self.delay = !self.delay;
  107. };
  108. /*QUAKED trigger_earthquake (.5 .5 .5) ?
  109. The Earthquake generator.
  110. Anytime a person is in an active field, they shake. If the trigger is a target, it will be OFF until triggered. It will then toggle between ON and OFF.
  111. weapon - richter scale of movement (default 40)
  112. weapon - if you give a weapon value of 40, the X and Y displacement
  113. can vary between -20 and +20, a range of 40.
  114. */
  115. void() trigger_earthquake =
  116. {
  117. precache_sound ("equake/rumble.wav");
  118. if (!self.weapon)
  119. self.weapon = 40;
  120. self.weapon = self.weapon * 0.5;
  121. self.delay = 1;
  122. self.touch = earthquake_touch;
  123. if (self.targetname)
  124. {
  125. self.use = earthquake_use;
  126. self.delay = 0;
  127. }
  128. InitTrigger();
  129. };
  130. void() kill_earthquake =
  131. {
  132. local entity eq;
  133. if ( other.classname != "player" )
  134. return;
  135. eq = find (world, classname, "earthquake");
  136. if (eq != world)
  137. {
  138. earthquake_active = 0;
  139. remove (eq);
  140. }
  141. };
  142. /*QUAKED trigger_earthquake_kill (.5 .5 .5) ?
  143. Trigger to kill the level-wide earthquake.
  144. */
  145. void() trigger_earthquake_kill =
  146. {
  147. self.touch = kill_earthquake;
  148. InitTrigger();
  149. };