elevatr.qc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. // elevator button
  16. // pmack
  17. // sept 96
  18. float ELVTR_DOWN = 1;
  19. void() elvtr_button_wait;
  20. void() elvtr_button_return;
  21. void() elvtr_button_wait =
  22. {
  23. elvButnDir = 0;
  24. if (self.spawnflags & ELVTR_DOWN)
  25. elvButnDir = -1;
  26. else
  27. elvButnDir = 1;
  28. self.state = STATE_TOP;
  29. self.nextthink = self.ltime + self.wait;
  30. self.think = elvtr_button_return;
  31. activator = self.enemy;
  32. SUB_UseTargets();
  33. self.frame = 1; // use alternate textures
  34. };
  35. void() elvtr_button_done =
  36. {
  37. self.state = STATE_BOTTOM;
  38. };
  39. void() elvtr_button_return =
  40. {
  41. self.state = STATE_DOWN;
  42. SUB_CalcMove (self.pos1, self.speed, elvtr_button_done);
  43. self.frame = 0; // use normal textures
  44. if (self.health)
  45. self.takedamage = DAMAGE_YES; // can be shot again
  46. };
  47. void() elvtr_button_blocked =
  48. { // do nothing, just don't ome all the way back out
  49. };
  50. void() elvtr_button_fire =
  51. {
  52. if (self.state == STATE_UP || self.state == STATE_TOP)
  53. return;
  54. sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  55. self.state = STATE_UP;
  56. SUB_CalcMove (self.pos2, self.speed, elvtr_button_wait);
  57. };
  58. void() elvtr_button_use =
  59. {
  60. self.enemy = activator;
  61. elvtr_button_fire ();
  62. };
  63. void() elvtr_button_touch =
  64. {
  65. if (other.classname != "player")
  66. return;
  67. self.enemy = other;
  68. elvtr_button_fire ();
  69. };
  70. void() elvtr_button_killed =
  71. {
  72. self.enemy = damage_attacker;
  73. self.health = self.max_health;
  74. self.takedamage = DAMAGE_NO; // wil be reset upon return
  75. elvtr_button_fire ();
  76. };
  77. /*QUAKED func_elvtr_button (0 .5 .8) ? ELVTR_DOWN
  78. ELEVATOR BUTTON ONLY!
  79. ELVTR_DOWN causes this to be a DOWN button.
  80. Default is UP.
  81. When a button is touched, it moves some distance in the direction of it's angle, triggers all of it's targets, waits some time, then returns to it's original position where it can be triggered again.
  82. "angle" determines the opening direction
  83. "target" all entities with a matching targetname will be used
  84. "speed" override the default 40 speed
  85. "wait" override the default 1 second wait (-1 = never return)
  86. "lip" override the default 4 pixel lip remaining at end of move
  87. "health" if set, the button must be killed instead of touched
  88. "sounds"
  89. 0) steam metal
  90. 1) wooden clunk
  91. 2) metallic click
  92. 3) in-out
  93. */
  94. void() func_elvtr_button =
  95. {
  96. local float gtemp, ftemp;
  97. if (self.sounds == 0)
  98. {
  99. precache_sound ("buttons/airbut1.wav");
  100. self.noise = "buttons/airbut1.wav";
  101. }
  102. if (self.sounds == 1)
  103. {
  104. precache_sound ("buttons/switch21.wav");
  105. self.noise = "buttons/switch21.wav";
  106. }
  107. if (self.sounds == 2)
  108. {
  109. precache_sound ("buttons/switch02.wav");
  110. self.noise = "buttons/switch02.wav";
  111. }
  112. if (self.sounds == 3)
  113. {
  114. precache_sound ("buttons/switch04.wav");
  115. self.noise = "buttons/switch04.wav";
  116. }
  117. SetMovedir ();
  118. self.movetype = MOVETYPE_PUSH;
  119. self.solid = SOLID_BSP;
  120. setmodel (self, self.model);
  121. self.blocked = elvtr_button_blocked;
  122. self.use = elvtr_button_use;
  123. if (self.health)
  124. {
  125. self.max_health = self.health;
  126. self.th_die = elvtr_button_killed;
  127. self.takedamage = DAMAGE_YES;
  128. }
  129. else
  130. self.touch = elvtr_button_touch;
  131. if (!self.speed)
  132. self.speed = 40;
  133. if (!self.wait)
  134. self.wait = 1;
  135. if (!self.lip)
  136. self.lip = 4;
  137. self.state = STATE_BOTTOM;
  138. self.pos1 = self.origin;
  139. self.pos2 = self.pos1 + self.movedir*(fabs(self.movedir*self.size) - self.lip);
  140. };