plats.qc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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. 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. self = self.enemy;
  94. if (self.state == STATE_TOP)
  95. plat_go_down ();
  96. };
  97. void() plat_trigger_use =
  98. {
  99. if (self.think)
  100. return; // allready activated
  101. plat_go_down();
  102. };
  103. void() plat_crush =
  104. {
  105. T_Damage (other, self, self, 1);
  106. if (self.state == STATE_UP)
  107. plat_go_down ();
  108. else if (self.state == STATE_DOWN)
  109. plat_go_up ();
  110. else
  111. objerror ("plat_crush: bad self.state\n");
  112. };
  113. void() plat_use =
  114. {
  115. self.use = SUB_Null;
  116. if (self.state != STATE_UP)
  117. objerror ("plat_use: not in up state");
  118. plat_go_down();
  119. };
  120. /*QUAKED func_plat (0 .5 .8) ? PLAT_LOW_TRIGGER
  121. speed default 150
  122. Plats are always drawn in the extended position, so they will light correctly.
  123. 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.
  124. If the "height" key is set, that will determine the amount the plat moves, instead of being implicitly determined by the model's height.
  125. Set "sounds" to one of the following:
  126. 1) base fast
  127. 2) chain slow
  128. */
  129. void() func_plat =
  130. {
  131. if (!self.t_length)
  132. self.t_length = 80;
  133. if (!self.t_width)
  134. self.t_width = 10;
  135. if (self.sounds == 0)
  136. self.sounds = 2;
  137. // FIX THIS TO LOAD A GENERIC PLAT SOUND
  138. if (self.sounds == 1)
  139. {
  140. precache_sound ("plats/plat1.wav");
  141. precache_sound ("plats/plat2.wav");
  142. self.noise = "plats/plat1.wav";
  143. self.noise1 = "plats/plat2.wav";
  144. }
  145. if (self.sounds == 2)
  146. {
  147. precache_sound ("plats/medplat1.wav");
  148. precache_sound ("plats/medplat2.wav");
  149. self.noise = "plats/medplat1.wav";
  150. self.noise1 = "plats/medplat2.wav";
  151. }
  152. self.mangle = self.angles;
  153. self.angles = '0 0 0';
  154. self.classname = "func_plat";
  155. self.solid = SOLID_BSP;
  156. self.movetype = MOVETYPE_PUSH;
  157. setorigin (self, self.origin);
  158. setmodel (self, self.model);
  159. setsize (self, self.mins , self.maxs);
  160. self.blocked = plat_crush;
  161. if (!self.speed)
  162. self.speed = 150;
  163. // pos1 is the top position, pos2 is the bottom
  164. self.pos1 = self.origin;
  165. self.pos2 = self.origin;
  166. if (self.height)
  167. self.pos2_z = self.origin_z - self.height;
  168. else
  169. self.pos2_z = self.origin_z - self.size_z + 8;
  170. self.use = plat_trigger_use;
  171. plat_spawn_inside_trigger (); // the "start moving" trigger
  172. if (self.targetname != string_null)
  173. {
  174. self.state = STATE_UP;
  175. self.use = plat_use;
  176. }
  177. else
  178. {
  179. setorigin (self, self.pos2);
  180. self.state = STATE_BOTTOM;
  181. }
  182. };
  183. //============================================================================
  184. void() train_next;
  185. void() func_train_find;
  186. void() train_blocked =
  187. {
  188. if (time < self.attack_finished)
  189. return;
  190. self.attack_finished = time + 0.5;
  191. T_Damage (other, self, self, self.dmg);
  192. };
  193. void() train_use =
  194. {
  195. if (self.think != func_train_find)
  196. return; // already activated
  197. train_next();
  198. };
  199. void() train_wait =
  200. {
  201. if (self.wait)
  202. {
  203. self.nextthink = self.ltime + self.wait;
  204. sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  205. }
  206. else
  207. self.nextthink = self.ltime + 0.1;
  208. self.think = train_next;
  209. };
  210. void() train_next =
  211. {
  212. local entity targ;
  213. targ = find (world, targetname, self.target);
  214. self.target = targ.target;
  215. if (!self.target)
  216. objerror ("train_next: no next target");
  217. if (targ.wait)
  218. self.wait = targ.wait;
  219. else
  220. self.wait = 0;
  221. sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
  222. SUB_CalcMove (targ.origin - self.mins, self.speed, train_wait);
  223. };
  224. void() func_train_find =
  225. {
  226. local entity targ;
  227. targ = find (world, targetname, self.target);
  228. self.target = targ.target;
  229. setorigin (self, targ.origin - self.mins);
  230. if (!self.targetname)
  231. { // not triggered, so start immediately
  232. self.nextthink = self.ltime + 0.1;
  233. self.think = train_next;
  234. }
  235. };
  236. /*QUAKED func_train (0 .5 .8) ?
  237. Trains are moving platforms that players can ride.
  238. The targets origin specifies the min point of the train at each corner.
  239. The train spawns at the first target it is pointing at.
  240. If the train is the target of a button or trigger, it will not begin moving until activated.
  241. speed default 100
  242. dmg default 2
  243. sounds
  244. 1) ratchet metal
  245. */
  246. void() func_train =
  247. {
  248. if (!self.speed)
  249. self.speed = 100;
  250. if (!self.target)
  251. objerror ("func_train without a target");
  252. if (!self.dmg)
  253. self.dmg = 2;
  254. if (self.sounds == 0)
  255. {
  256. self.noise = ("misc/null.wav");
  257. precache_sound ("misc/null.wav");
  258. self.noise1 = ("misc/null.wav");
  259. precache_sound ("misc/null.wav");
  260. }
  261. if (self.sounds == 1)
  262. {
  263. self.noise = ("plats/train2.wav");//stop sound
  264. precache_sound ("plats/train2.wav");
  265. self.noise1 = ("plats/train1.wav");//move sound
  266. precache_sound ("plats/train1.wav");
  267. }
  268. self.cnt = 1;
  269. self.solid = SOLID_BSP;
  270. self.movetype = MOVETYPE_PUSH;
  271. self.blocked = train_blocked;
  272. self.use = train_use;
  273. self.classname = "train";
  274. setmodel (self, self.model);
  275. setsize (self, self.mins , self.maxs);
  276. setorigin (self, self.origin);
  277. // start trains on the second frame, to make sure their targets have had
  278. // a chance to spawn
  279. self.nextthink = self.ltime + 0.1;
  280. self.think = func_train_find;
  281. };
  282. /*QUAKED misc_teleporttrain (0 .5 .8) (-8 -8 -8) (8 8 8)
  283. This is used for the final bos
  284. */
  285. void() misc_teleporttrain =
  286. {
  287. if (!self.speed)
  288. self.speed = 100;
  289. if (!self.target)
  290. objerror ("func_train without a target");
  291. self.cnt = 1;
  292. self.solid = SOLID_NOT;
  293. self.movetype = MOVETYPE_PUSH;
  294. self.blocked = train_blocked;
  295. self.use = train_use;
  296. self.avelocity = '100 200 300';
  297. self.noise = ("misc/null.wav");
  298. precache_sound ("misc/null.wav");
  299. self.noise1 = ("misc/null.wav");
  300. precache_sound ("misc/null.wav");
  301. precache_model2 ("progs/teleport.mdl");
  302. setmodel (self, "progs/teleport.mdl");
  303. setsize (self, self.mins , self.maxs);
  304. setorigin (self, self.origin);
  305. // start trains on the second frame, to make sure their targets have had
  306. // a chance to spawn
  307. self.nextthink = self.ltime + 0.1;
  308. self.think = func_train_find;
  309. };