buttons.qc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. // button and multiple button
  16. void() button_wait;
  17. void() button_return;
  18. void() button_wait =
  19. {
  20. self.state = STATE_TOP;
  21. self.nextthink = self.ltime + self.wait;
  22. self.think = button_return;
  23. activator = self.enemy;
  24. SUB_UseTargets();
  25. self.frame = 1; // use alternate textures
  26. };
  27. void() button_done =
  28. {
  29. self.state = STATE_BOTTOM;
  30. };
  31. void() button_return =
  32. {
  33. self.state = STATE_DOWN;
  34. SUB_CalcMove (self.pos1, self.speed, button_done);
  35. self.frame = 0; // use normal textures
  36. if (self.health)
  37. self.takedamage = DAMAGE_YES; // can be shot again
  38. };
  39. void() button_blocked =
  40. { // do nothing, just don't ome all the way back out
  41. };
  42. void() button_fire =
  43. {
  44. if (self.state == STATE_UP || self.state == STATE_TOP)
  45. return;
  46. sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  47. self.state = STATE_UP;
  48. SUB_CalcMove (self.pos2, self.speed, button_wait);
  49. };
  50. void() button_use =
  51. {
  52. self.enemy = activator;
  53. button_fire ();
  54. };
  55. void() button_touch =
  56. {
  57. if (other.classname != "player" || other.observer)
  58. return;
  59. self.enemy = other;
  60. button_fire ();
  61. };
  62. void() button_killed =
  63. {
  64. self.enemy = damage_attacker;
  65. self.health = self.max_health;
  66. self.takedamage = DAMAGE_NO; // wil be reset upon return
  67. button_fire ();
  68. };
  69. /*QUAKED func_button (0 .5 .8) ?
  70. 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.
  71. "angle" determines the opening direction
  72. "target" all entities with a matching targetname will be used
  73. "speed" override the default 40 speed
  74. "wait" override the default 1 second wait (-1 = never return)
  75. "lip" override the default 4 pixel lip remaining at end of move
  76. "health" if set, the button must be killed instead of touched
  77. "sounds"
  78. 0) steam metal
  79. 1) wooden clunk
  80. 2) metallic click
  81. 3) in-out
  82. */
  83. void() func_button =
  84. {
  85. local float gtemp, ftemp;
  86. if (self.sounds == 0)
  87. {
  88. precache_sound ("buttons/airbut1.wav");
  89. self.noise = "buttons/airbut1.wav";
  90. }
  91. if (self.sounds == 1)
  92. {
  93. precache_sound ("buttons/switch21.wav");
  94. self.noise = "buttons/switch21.wav";
  95. }
  96. if (self.sounds == 2)
  97. {
  98. precache_sound ("buttons/switch02.wav");
  99. self.noise = "buttons/switch02.wav";
  100. }
  101. if (self.sounds == 3)
  102. {
  103. precache_sound ("buttons/switch04.wav");
  104. self.noise = "buttons/switch04.wav";
  105. }
  106. SetMovedir ();
  107. self.movetype = MOVETYPE_PUSH;
  108. self.solid = SOLID_BSP;
  109. setmodel (self, self.model);
  110. self.blocked = button_blocked;
  111. self.use = button_use;
  112. if (self.health)
  113. {
  114. self.max_health = self.health;
  115. self.th_die = button_killed;
  116. self.takedamage = DAMAGE_YES;
  117. }
  118. else
  119. self.touch = button_touch;
  120. if (!self.speed)
  121. self.speed = 40;
  122. if (!self.wait)
  123. self.wait = 1;
  124. if (!self.lip)
  125. self.lip = 4;
  126. self.state = STATE_BOTTOM;
  127. self.pos1 = self.origin;
  128. self.pos2 = self.pos1 + self.movedir*(fabs(self.movedir*self.size) - self.lip);
  129. };