buttons.qc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. buttons.qc
  3. button and multiple button
  4. Copyright (C) 1996-1997 Id Software, Inc.
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. See the GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to:
  15. Free Software Foundation, Inc.
  16. 59 Temple Place - Suite 330
  17. Boston, MA 02111-1307, USA
  18. */
  19. void() button_wait;
  20. void() button_return;
  21. void() button_wait =
  22. {
  23. self.state = STATE_TOP;
  24. self.nextthink = self.ltime + self.wait;
  25. self.think = button_return;
  26. activator = self.enemy;
  27. SUB_UseTargets();
  28. self.frame = 1; // use alternate textures
  29. };
  30. void() button_done =
  31. {
  32. self.state = STATE_BOTTOM;
  33. };
  34. void() button_return =
  35. {
  36. self.state = STATE_DOWN;
  37. SUB_CalcMove (self.pos1, self.speed, button_done);
  38. self.frame = 0; // use normal textures
  39. if (self.health)
  40. self.takedamage = DAMAGE_YES; // can be shot again
  41. };
  42. void() button_blocked =
  43. { // do nothing, just don't ome all the way back out
  44. };
  45. void() button_fire =
  46. {
  47. if (self.state == STATE_UP || self.state == STATE_TOP)
  48. return;
  49. sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  50. self.state = STATE_UP;
  51. SUB_CalcMove (self.pos2, self.speed, button_wait);
  52. };
  53. void() button_use =
  54. {
  55. self.enemy = activator;
  56. button_fire ();
  57. };
  58. void() button_touch =
  59. {
  60. if (other.classname != "player")
  61. return;
  62. self.enemy = other;
  63. button_fire ();
  64. };
  65. void() button_killed =
  66. {
  67. self.enemy = damage_attacker;
  68. self.health = self.max_health;
  69. self.takedamage = DAMAGE_NO; // wil be reset upon return
  70. button_fire ();
  71. };
  72. /*QUAKED func_button (0 .5 .8) ?
  73. 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.
  74. "angle" determines the opening direction
  75. "target" all entities with a matching targetname will be used
  76. "speed" override the default 40 speed
  77. "wait" override the default 1 second wait (-1 = never return)
  78. "lip" override the default 4 pixel lip remaining at end of move
  79. "health" if set, the button must be killed instead of touched
  80. "sounds"
  81. 0) steam metal
  82. 1) wooden clunk
  83. 2) metallic click
  84. 3) in-out
  85. */
  86. void() func_button =
  87. {
  88. local float gtemp, ftemp;
  89. if (self.sounds == 0)
  90. {
  91. precache_sound ("buttons/airbut1.wav");
  92. self.noise = "buttons/airbut1.wav";
  93. }
  94. if (self.sounds == 1)
  95. {
  96. precache_sound ("buttons/switch21.wav");
  97. self.noise = "buttons/switch21.wav";
  98. }
  99. if (self.sounds == 2)
  100. {
  101. precache_sound ("buttons/switch02.wav");
  102. self.noise = "buttons/switch02.wav";
  103. }
  104. if (self.sounds == 3)
  105. {
  106. precache_sound ("buttons/switch04.wav");
  107. self.noise = "buttons/switch04.wav";
  108. }
  109. SetMovedir ();
  110. self.movetype = MOVETYPE_PUSH;
  111. self.solid = SOLID_BSP;
  112. setmodel (self, self.model);
  113. self.blocked = button_blocked;
  114. self.use = button_use;
  115. if (self.health)
  116. {
  117. self.max_health = self.health;
  118. self.th_die = button_killed;
  119. self.takedamage = DAMAGE_YES;
  120. }
  121. else
  122. self.touch = button_touch;
  123. if (!self.speed)
  124. self.speed = 40;
  125. if (!self.wait)
  126. self.wait = 1;
  127. if (!self.lip)
  128. self.lip = 4;
  129. self.state = STATE_BOTTOM;
  130. self.pos1 = self.origin;
  131. self.pos2 = self.pos1 + self.movedir*(fabs(self.movedir*self.size) - self.lip);
  132. };