lightnin.qc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. // lightning trail
  16. // pmack
  17. // sept 96
  18. // float ltrailLastUsed; -- now an entity field.
  19. float LT_TOGGLE = 1;
  20. float LT_ACTIVE = 2;
  21. void() ltrail_chain =
  22. {
  23. SUB_UseTargets();
  24. self.think = SUB_Null;
  25. };
  26. void() ltrail_fire =
  27. {
  28. local entity myTarget;
  29. if (self.classname != "ltrail_end")
  30. {
  31. sound (self, CHAN_VOICE, "weapons/lhit.wav", 1, ATTN_NORM);
  32. myTarget = find(world, targetname, self.target);
  33. WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  34. WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  35. WriteEntity (MSG_BROADCAST, self);
  36. WriteCoord (MSG_BROADCAST, self.origin_x);
  37. WriteCoord (MSG_BROADCAST, self.origin_y);
  38. WriteCoord (MSG_BROADCAST, self.origin_z);
  39. WriteCoord (MSG_BROADCAST, myTarget.origin_x);
  40. WriteCoord (MSG_BROADCAST, myTarget.origin_y);
  41. WriteCoord (MSG_BROADCAST, myTarget.origin_z);
  42. LightningDamage (self.origin, myTarget.origin, self, self.currentammo);
  43. }
  44. if ( self.items < time)
  45. {
  46. self.think = ltrail_chain;
  47. self.nextthink = time + self.frags;
  48. }
  49. else
  50. {
  51. self.think = ltrail_fire;
  52. self.nextthink = time + 0.05;
  53. }
  54. };
  55. void() ltrail_start_fire =
  56. {
  57. // if it's a toggle ltrail, we ignore triggers from ltrail_end's
  58. // when toggled off.
  59. if (self.spawnflags & LT_TOGGLE)
  60. {
  61. // user is not a lightning trail - change activity state.
  62. if ( other.classname != "ltrail_end" )
  63. {
  64. if (self.spawnflags & LT_ACTIVE)
  65. // currently active
  66. {
  67. self.spawnflags = self.spawnflags - LT_ACTIVE;
  68. return;
  69. }
  70. else
  71. // not active
  72. {
  73. self.spawnflags = self.spawnflags + LT_ACTIVE;
  74. }
  75. }
  76. // user is lightning trail, but trail has been turned off.
  77. // ignore the message.
  78. else if (!(self.spawnflags & LT_ACTIVE))
  79. return;
  80. }
  81. if (self.classname == "ltrail_start")
  82. {
  83. self.items = time + self.weapon;
  84. ltrail_fire();
  85. self.ltrailLastUsed = time;
  86. }
  87. else if (self.classname == "ltrail_relay")
  88. {
  89. self.items = time + self.weapon;
  90. ltrail_fire();
  91. }
  92. else
  93. {
  94. self.think = ltrail_chain;
  95. self.nextthink = time + self.frags;
  96. }
  97. };
  98. /*QUAKED ltrail_start (0 1 0) (-8 -8 -8) (8 8 8) LT_TOGGLE
  99. Starting point of a lightning trail.
  100. Set currentammo to amount of damage you want the lightning to do.
  101. Default is 25.
  102. Set frags to amount of time before next item is triggered.
  103. Default is 0.3 seconds.
  104. Set weapon to amount of time to be firing the lightning.
  105. Default is 0.3 seconds.
  106. Set the LT_TOGGLE checkbox if you want the lightning shooter to continuously fire until triggered again.
  107. */
  108. void() ltrail_start =
  109. {
  110. self.ltrailLastUsed = time;
  111. precache_sound ("weapons/lhit.wav");
  112. self.movetype = MOVETYPE_NONE;
  113. self.solid = SOLID_BBOX;
  114. self.use = ltrail_start_fire;
  115. if (self.currentammo == 0)
  116. self.currentammo = 25;
  117. if (self.weapon == 0)
  118. self.weapon = 0.3;
  119. if (self.frags == 0)
  120. self.frags = 0.3;
  121. if (self.spawnflags & LT_ACTIVE)
  122. {
  123. self.items = time + 99999999;
  124. self.think = ltrail_fire;
  125. self.nextthink = time + 0.1;
  126. }
  127. };
  128. /*QUAKED ltrail_relay (0 1 0) (-8 -8 -8) (8 8 8)
  129. Relay point of a lightning trail.
  130. Set currentammo to amount of damage you want the lightning to do.
  131. Default is 25.
  132. Set frags to amount of time before next item is triggered.
  133. Default is 0.3 seconds.
  134. Set weapon to amount of time to be firing the lightning.
  135. Default is 0.3 seconds.
  136. */
  137. void() ltrail_relay =
  138. {
  139. precache_sound ("weapons/lhit.wav");
  140. self.movetype = MOVETYPE_NONE;
  141. self.solid = SOLID_BBOX;
  142. self.use = ltrail_start_fire;
  143. if (self.currentammo == 0)
  144. self.currentammo = 25;
  145. if (self.weapon == 0)
  146. self.weapon = 0.3;
  147. if (self.frags == 0)
  148. self.frags = 0.3;
  149. };
  150. /*QUAKED ltrail_end (0 1 0) (-8 -8 -8) (8 8 8)
  151. Ending point of a lightning trail.
  152. Does not fire any lightning.
  153. Set frags to amount of time before next item is triggered.
  154. Default is 0.3 seconds.
  155. */
  156. void() ltrail_end =
  157. {
  158. precache_sound ("weapons/lhit.wav");
  159. self.movetype = MOVETYPE_NONE;
  160. self.solid = SOLID_BBOX;
  161. self.use = ltrail_start_fire;
  162. if (self.currentammo == 0)
  163. self.currentammo = 25;
  164. if (self.weapon == 0)
  165. self.weapon = 0.3;
  166. if (self.frags == 0)
  167. self.frags = 0.3;
  168. };