plats.qc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /* Copyright (C) 1996-1997 Id Software, Inc.
  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. void() plat_center_touch;
  16. void() plat_outside_touch;
  17. void() plat_trigger_use;
  18. void() plat_go_up;
  19. void() plat_go_down;
  20. void() plat_crush;
  21. float PLAT_LOW_TRIGGER = 1;
  22. void() plat_spawn_inside_trigger =
  23. {
  24. local entity trigger;
  25. local vector tmin, tmax;
  26. //
  27. // middle trigger
  28. //
  29. trigger = spawn();
  30. trigger.touch = plat_center_touch;
  31. trigger.movetype = MOVETYPE_NONE;
  32. trigger.solid = SOLID_TRIGGER;
  33. trigger.enemy = self;
  34. tmin = self.mins + '25 25 0';
  35. tmax = self.maxs - '25 25 -8';
  36. tmin_z = tmax_z - (self.pos1_z - self.pos2_z + 8);
  37. if (self.spawnflags & PLAT_LOW_TRIGGER)
  38. tmax_z = tmin_z + 8;
  39. if (self.size_x <= 50)
  40. {
  41. tmin_x = (self.mins_x + self.maxs_x) / 2;
  42. tmax_x = tmin_x + 1;
  43. }
  44. if (self.size_y <= 50)
  45. {
  46. tmin_y = (self.mins_y + self.maxs_y) / 2;
  47. tmax_y = tmin_y + 1;
  48. }
  49. setsize (trigger, tmin, tmax);
  50. };
  51. void() plat_hit_top =
  52. {
  53. sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
  54. self.state = STATE_TOP;
  55. self.think = plat_go_down;
  56. self.nextthink = self.ltime + 3;
  57. };
  58. void() plat_hit_bottom =
  59. {
  60. sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
  61. self.state = STATE_BOTTOM;
  62. };
  63. void() plat_go_down =
  64. {
  65. sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  66. self.state = STATE_DOWN;
  67. SUB_CalcMove (self.pos2, self.speed, plat_hit_bottom);
  68. };
  69. void() plat_go_up =
  70. {
  71. sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  72. self.state = STATE_UP;
  73. SUB_CalcMove (self.pos1, self.speed, plat_hit_top);
  74. };
  75. void() plat_center_touch =
  76. {
  77. if (other.classname != "player")
  78. return;
  79. if (other.health <= 0)
  80. return;
  81. self = self.enemy;
  82. if (self.state == STATE_BOTTOM)
  83. plat_go_up ();
  84. else if (self.state == STATE_TOP)
  85. self.nextthink = self.ltime + 1; // delay going down
  86. };
  87. void() plat_outside_touch =
  88. {
  89. if (other.classname != "player")
  90. return;
  91. if (other.health <= 0)
  92. return;
  93. //dprint ("plat_outside_touch\n");
  94. self = self.enemy;
  95. if (self.state == STATE_TOP)
  96. plat_go_down ();
  97. };
  98. void() plat_trigger_use =
  99. {
  100. if (self.think)
  101. return; // allready activated
  102. plat_go_down();
  103. };
  104. void() plat_crush =
  105. {
  106. //dprint ("plat_crush\n");
  107. T_Damage (other, self, self, 1);
  108. if (self.state == STATE_UP)
  109. plat_go_down ();
  110. else if (self.state == STATE_DOWN)
  111. plat_go_up ();
  112. else
  113. objerror ("plat_crush: bad self.state\n");
  114. };
  115. void() plat_use =
  116. {
  117. self.use = SUB_Null;
  118. if (self.state != STATE_UP)
  119. objerror ("plat_use: not in up state");
  120. plat_go_down();
  121. };
  122. /*QUAKED func_plat (0 .5 .8) ? PLAT_LOW_TRIGGER
  123. speed default 150
  124. Plats are always drawn in the extended position, so they will light correctly.
  125. If the plat is the target of another trigger or button, it will start out disabled in the extended position until it is trigger, when it will lower and become a normal plat.
  126. If the "height" key is set, that will determine the amount the plat moves, instead of being implicitly determined by the model's height.
  127. Set "sounds" to one of the following:
  128. 1) base fast
  129. 2) chain slow
  130. */
  131. void() func_plat =
  132. {
  133. local entity t;
  134. if (!self.t_length)
  135. self.t_length = 80;
  136. if (!self.t_width)
  137. self.t_width = 10;
  138. if (self.sounds == 0)
  139. self.sounds = 2;
  140. // FIX THIS TO LOAD A GENERIC PLAT SOUND
  141. if (self.sounds == 1)
  142. {
  143. precache_sound ("plats/plat1.wav");
  144. precache_sound ("plats/plat2.wav");
  145. self.noise = "plats/plat1.wav";
  146. self.noise1 = "plats/plat2.wav";
  147. }
  148. if (self.sounds == 2)
  149. {
  150. precache_sound ("plats/medplat1.wav");
  151. precache_sound ("plats/medplat2.wav");
  152. self.noise = "plats/medplat1.wav";
  153. self.noise1 = "plats/medplat2.wav";
  154. }
  155. self.mangle = self.angles;
  156. self.angles = '0 0 0';
  157. self.classname = "plat";
  158. self.solid = SOLID_BSP;
  159. self.movetype = MOVETYPE_PUSH;
  160. setorigin (self, self.origin);
  161. setmodel (self, self.model);
  162. setsize (self, self.mins , self.maxs);
  163. self.blocked = plat_crush;
  164. if (!self.speed)
  165. self.speed = 150;
  166. // pos1 is the top position, pos2 is the bottom
  167. self.pos1 = self.origin;
  168. self.pos2 = self.origin;
  169. if (self.height)
  170. self.pos2_z = self.origin_z - self.height;
  171. else
  172. self.pos2_z = self.origin_z - self.size_z + 8;
  173. self.use = plat_trigger_use;
  174. plat_spawn_inside_trigger (); // the "start moving" trigger
  175. if (self.targetname)
  176. {
  177. self.state = STATE_UP;
  178. self.use = plat_use;
  179. }
  180. else
  181. {
  182. setorigin (self, self.pos2);
  183. self.state = STATE_BOTTOM;
  184. }
  185. };
  186. //============================================================================
  187. void() train_next;
  188. void() func_train_find;
  189. void() train_blocked =
  190. {
  191. if (time < self.attack_finished)
  192. return;
  193. self.attack_finished = time + 0.5;
  194. T_Damage (other, self, self, self.dmg);
  195. };
  196. void() train_use =
  197. {
  198. if (self.think != func_train_find)
  199. return; // already activated
  200. train_next();
  201. };
  202. void() train_wait =
  203. {
  204. if (self.wait)
  205. {
  206. self.nextthink = self.ltime + self.wait;
  207. sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  208. }
  209. else
  210. self.nextthink = self.ltime + 0.1;
  211. self.think = train_next;
  212. };
  213. void() train_next =
  214. {
  215. local entity targ;
  216. targ = find (world, targetname, self.target);
  217. self.target = targ.target;
  218. if (!self.target)
  219. objerror ("train_next: no next target");
  220. if (targ.wait)
  221. self.wait = targ.wait;
  222. else
  223. self.wait = 0;
  224. sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
  225. SUB_CalcMove (targ.origin - self.mins, self.speed, train_wait);
  226. };
  227. void() func_train_find =
  228. {
  229. local entity targ;
  230. targ = find (world, targetname, self.target);
  231. self.target = targ.target;
  232. setorigin (self, targ.origin - self.mins);
  233. if (!self.targetname)
  234. { // not triggered, so start immediately
  235. self.nextthink = self.ltime + 0.1;
  236. self.think = train_next;
  237. }
  238. };
  239. /*QUAKED func_train (0 .5 .8) ?
  240. Trains are moving platforms that players can ride.
  241. The targets origin specifies the min point of the train at each corner.
  242. The train spawns at the first target it is pointing at.
  243. If the train is the target of a button or trigger, it will not begin moving until activated.
  244. speed default 100
  245. dmg default 2
  246. sounds
  247. 1) ratchet metal
  248. */
  249. void() func_train =
  250. {
  251. if (!self.speed)
  252. self.speed = 100;
  253. if (!self.target)
  254. objerror ("func_train without a target");
  255. if (!self.dmg)
  256. self.dmg = 2;
  257. if (self.sounds == 0)
  258. {
  259. self.noise = ("misc/null.wav");
  260. precache_sound ("misc/null.wav");
  261. self.noise1 = ("misc/null.wav");
  262. precache_sound ("misc/null.wav");
  263. }
  264. if (self.sounds == 1)
  265. {
  266. self.noise = ("plats/train2.wav");
  267. precache_sound ("plats/train2.wav");
  268. self.noise1 = ("plats/train1.wav");
  269. precache_sound ("plats/train1.wav");
  270. }
  271. self.cnt = 1;
  272. self.solid = SOLID_BSP;
  273. self.movetype = MOVETYPE_PUSH;
  274. self.blocked = train_blocked;
  275. self.use = train_use;
  276. self.classname = "train";
  277. setmodel (self, self.model);
  278. setsize (self, self.mins , self.maxs);
  279. setorigin (self, self.origin);
  280. // start trains on the second frame, to make sure their targets have had
  281. // a chance to spawn
  282. self.nextthink = self.ltime + 0.1;
  283. self.think = func_train_find;
  284. };
  285. /*QUAKED misc_teleporttrain (0 .5 .8) (-8 -8 -8) (8 8 8)
  286. This is used for the final bos
  287. */
  288. void() misc_teleporttrain =
  289. {
  290. if (!self.speed)
  291. self.speed = 100;
  292. if (!self.target)
  293. objerror ("func_train without a target");
  294. self.cnt = 1;
  295. self.solid = SOLID_NOT;
  296. self.movetype = MOVETYPE_PUSH;
  297. self.blocked = train_blocked;
  298. self.use = train_use;
  299. self.avelocity = '100 200 300';
  300. self.noise = ("misc/null.wav");
  301. precache_sound ("misc/null.wav");
  302. self.noise1 = ("misc/null.wav");
  303. precache_sound ("misc/null.wav");
  304. precache_model2 ("progs/teleport.mdl");
  305. setmodel (self, "progs/teleport.mdl");
  306. setsize (self, self.mins , self.maxs);
  307. setorigin (self, self.origin);
  308. // start trains on the second frame, to make sure their targets have had
  309. // a chance to spawn
  310. self.nextthink = self.ltime + 0.1;
  311. self.think = func_train_find;
  312. };