pendulum.qc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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. // pendulum.qc
  16. $frame frame1 frame2 frame3 frame4 frame5 frame6 frame7
  17. $frame frame8 frame9 frame10 frame11 frame12 frame13
  18. float impactVelocity;
  19. //float pend_frame;
  20. float PEND_X = 1;
  21. float PEND_Y = 2;
  22. float PEND_Z = 4;
  23. float PEND_TRG = 8;
  24. /*
  25. void() pend_stand =[ $frame4, pend_stand ] {};
  26. */
  27. void() pend_swing1 =[ $frame1, pend_swing2 ]
  28. {
  29. //// pend_frame = 1;
  30. // 0 -148 88 (center) W 56, H 80 (28,40)
  31. if( self.spawnflags & PEND_Y)
  32. setsize ( self, '-8 -176 48', '8 -120 128' );
  33. else if ( self.spawnflags & PEND_X )
  34. setsize ( self, '-176 -8 48', '-120 8 128' );
  35. self.nextthink = time + 0.17;
  36. impactVelocity = 1;
  37. };
  38. void() pend_swing2 =[ $frame2, pend_swing3 ]
  39. {
  40. //// pend_frame = pend_frame + 1;
  41. // 0 -142 50 (center) W 60, H 76 (30, 38)
  42. if( self.spawnflags & PEND_Y)
  43. setsize ( self, '-8 -172 12', '8 -112 88' );
  44. else if ( self.spawnflags & PEND_X )
  45. setsize ( self, '-172 -8 12', '-112 8 88' );
  46. self.nextthink = time + 0.15;
  47. };
  48. void() pend_swing3 =[ $frame3, pend_swing4 ]
  49. {
  50. //// pend_frame = pend_frame + 1;
  51. // 0 -128 14 (center) W 64, H 72 (32, 36)
  52. if( self.spawnflags & PEND_Y)
  53. setsize ( self, '-8 -160 -22', '8 -96 50' );
  54. else if ( self.spawnflags & PEND_X )
  55. setsize ( self, '-160 -8 -22', '-96 8 50' );
  56. self.nextthink = time + 0.13;
  57. };
  58. void() pend_swing4 =[ $frame4, pend_swing5 ]
  59. {
  60. sound ( self, CHAN_AUTO, "pendulum/swing.wav", 0.5, ATTN_NORM);
  61. //// pend_frame = pend_frame + 1;
  62. // 0 -104 -17 (center) W 68, H 68 (34, 34)
  63. if( self.spawnflags & PEND_Y)
  64. setsize ( self, '-8 -138 -51', '8 -70 17' );
  65. else if ( self.spawnflags & PEND_X )
  66. setsize ( self, '-138 -8 -51', '-70 8 17' );
  67. self.nextthink = time + 0.11;
  68. };
  69. void() pend_swing5 =[ $frame5, pend_swing6 ]
  70. {
  71. // pend_frame = pend_frame + 1;
  72. // 0 -74 40 (center) W 72, H 64 (36, 32)
  73. if( self.spawnflags & PEND_Y)
  74. setsize ( self, '-8 -110 -72', '8 -38 -8' );
  75. else if ( self.spawnflags & PEND_X )
  76. setsize ( self, '-110 -8 -72', '-38 8 -8' );
  77. self.nextthink = time + 0.09;
  78. };
  79. void() pend_swing6 =[ $frame6, pend_swing7 ]
  80. {
  81. // pend_frame = pend_frame + 1;
  82. // 0 -38 53 (center) W 76, H 60 (38, 30)
  83. if( self.spawnflags & PEND_Y)
  84. setsize ( self, '-8 -76 -83', '8 0 -23' );
  85. else if ( self.spawnflags & PEND_X )
  86. setsize ( self, '-76 -8 -83', '0 8 -23' );
  87. self.nextthink = time + 0.07;
  88. };
  89. void() pend_swing7 =[ $frame7, pend_swing8 ]
  90. {
  91. // pend_frame = pend_frame + 1;
  92. // 0 0 60 (center) W 80, H 56 (40, 28)
  93. if( self.spawnflags & PEND_Y)
  94. setsize ( self, '-8 -40 -88', '8 40 -32' );
  95. else if ( self.spawnflags & PEND_X )
  96. setsize ( self, '-40 -8 -88', '40 8 -32' );
  97. self.nextthink = time + 0.05;
  98. };
  99. void() pend_swing8 =[ $frame8, pend_swing9 ]
  100. {
  101. // pend_frame = pend_frame + 1;
  102. // 0 38 53 (center) W 76, H 60 (38, 30)
  103. if( self.spawnflags & PEND_Y)
  104. setsize ( self, '-8 0 -83', '8 76 -23' );
  105. else if ( self.spawnflags & PEND_X )
  106. setsize ( self, '0 -8 -83', '76 8 -23' );
  107. self.nextthink = time + 0.07;
  108. };
  109. void() pend_swing9 =[ $frame9, pend_swing10 ]
  110. {
  111. // pend_frame = pend_frame + 1;
  112. // 0 74 40 (center) W 72, H 64 (36, 32)
  113. if( self.spawnflags & PEND_Y)
  114. setsize ( self, '-8 38 -72', '8 100 -8' );
  115. else if ( self.spawnflags & PEND_X )
  116. setsize ( self, '38 -8 -72', '100 8 -8' );
  117. self.nextthink = time + 0.09;
  118. };
  119. void() pend_swing10 =[ $frame10, pend_swing11 ]
  120. {
  121. // pend_frame = pend_frame + 1;
  122. // 0 104 17 (center) W 68, H 68 (34, 34)
  123. if( self.spawnflags & PEND_Y)
  124. setsize ( self, '-8 70 -51', '8 138 17' );
  125. else if ( self.spawnflags & PEND_X )
  126. setsize ( self, '70 -8 -51', '138 8 17' );
  127. self.nextthink = time + 0.11;
  128. };
  129. void() pend_swing11 =[ $frame11, pend_swing12 ]
  130. {
  131. // pend_frame = pend_frame + 1;
  132. // 0 128 -14 (center) W 64, H 72 (32, 36)
  133. if( self.spawnflags & PEND_Y)
  134. setsize ( self, '-8 96 -22', '8 160 50' );
  135. else if ( self.spawnflags & PEND_X )
  136. setsize ( self, '96 -8 -22', '160 8 50' );
  137. self.nextthink = time + 0.13;
  138. };
  139. void() pend_swing12 =[ $frame12, pend_swing13 ]
  140. {
  141. // pend_frame = pend_frame + 1;
  142. // 0 142 -50 (center) W 60, H 76 (30, 38)
  143. if( self.spawnflags & PEND_Y)
  144. setsize ( self, '-8 112 12', '8 172 88' );
  145. else if ( self.spawnflags & PEND_X )
  146. setsize ( self, '112 -8 12', '172 8 88' );
  147. self.nextthink = time + 0.15;
  148. };
  149. void() pend_swing13 =[ $frame13, pend_swing14 ]
  150. {
  151. // pend_frame = pend_frame + 1;
  152. // 0 148 -88 (center) W 56, H 80 (28, 40)
  153. if( self.spawnflags & PEND_Y)
  154. setsize ( self, '-8 120 48', '8 176 128' );
  155. else if ( self.spawnflags & PEND_X )
  156. setsize ( self, '120 -8 48', '176 8 128' );
  157. self.nextthink = time + 0.17;
  158. };
  159. void() pend_swing14 =[ $frame13, pend_swing15 ]
  160. {
  161. // pend_frame = pend_frame + 1;
  162. // same frame, same location. no change to bbox.
  163. self.nextthink = time + 0.17;
  164. };
  165. void() pend_swing15 =[ $frame12, pend_swing16 ]
  166. {
  167. // pend_frame = pend_frame + 1;
  168. // 0 142 -50 (center) W 60, H 76 (30, 38)
  169. if( self.spawnflags & PEND_Y)
  170. setsize ( self, '-8 112 12', '8 172 88' );
  171. else if ( self.spawnflags & PEND_X )
  172. setsize ( self, '112 -8 12', '172 8 88' );
  173. self.nextthink = time + 0.15;
  174. impactVelocity = -1;
  175. };
  176. void() pend_swing16 =[ $frame11, pend_swing17 ]
  177. {
  178. // pend_frame = pend_frame + 1;
  179. // 0 128 -14 (center) W 64, H 72 (32, 36)
  180. if( self.spawnflags & PEND_Y)
  181. setsize ( self, '-8 96 -22', '8 160 50' );
  182. else if ( self.spawnflags & PEND_X )
  183. setsize ( self, '96 -8 -22', '160 8 50' );
  184. self.nextthink = time + 0.13;
  185. };
  186. void() pend_swing17 =[ $frame10, pend_swing18 ]
  187. {
  188. sound ( self, CHAN_AUTO, "pendulum/swing.wav", 0.5, ATTN_NORM);
  189. // pend_frame = pend_frame + 1;
  190. // 0 104 17 (center) W 68, H 68 (34, 34)
  191. if( self.spawnflags & PEND_Y)
  192. setsize ( self, '-8 70 -51', '8 138 17' );
  193. else if ( self.spawnflags & PEND_X )
  194. setsize ( self, '70 -8 -51', '138 8 17' );
  195. self.nextthink = time + 0.11;
  196. };
  197. void() pend_swing18 =[ $frame9, pend_swing19 ]
  198. {
  199. // pend_frame = pend_frame + 1;
  200. // 0 74 40 (center) W 72, H 64 (36, 32)
  201. if( self.spawnflags & PEND_Y)
  202. setsize ( self, '-8 38 -72', '8 100 -8' );
  203. else if ( self.spawnflags & PEND_X )
  204. setsize ( self, '38 -8 -72', '100 8 -8' );
  205. self.nextthink = time + 0.09;
  206. };
  207. void() pend_swing19 =[ $frame8, pend_swing20 ]
  208. {
  209. // pend_frame = pend_frame + 1;
  210. // 0 38 53 (center) W 76, H 60 (38, 30)
  211. if( self.spawnflags & PEND_Y)
  212. setsize ( self, '-8 0 -83', '8 76 -23' );
  213. else if ( self.spawnflags & PEND_X )
  214. setsize ( self, '0 -8 -83', '76 8 -23' );
  215. self.nextthink = time + 0.07;
  216. };
  217. void() pend_swing20 =[ $frame7, pend_swing21 ]
  218. {
  219. // pend_frame = pend_frame + 1;
  220. // 0 0 60 (center) W 80, H 56 (40, 28)
  221. if( self.spawnflags & PEND_Y)
  222. setsize ( self, '-8 -40 -88', '8 40 -32' );
  223. else if ( self.spawnflags & PEND_X )
  224. setsize ( self, '-40 -8 -88', '40 8 -32' );
  225. self.nextthink = time + 0.05;
  226. };
  227. void() pend_swing21 =[ $frame6, pend_swing22 ]
  228. {
  229. // pend_frame = pend_frame + 1;
  230. // 0 -38 53 (center) W 76, H 60 (38, 30)
  231. if( self.spawnflags & PEND_Y)
  232. setsize ( self, '-8 -76 -83', '8 0 -23' );
  233. else if ( self.spawnflags & PEND_X )
  234. setsize ( self, '-76 -8 -83', '0 8 -23' );
  235. self.nextthink = time + 0.07;
  236. };
  237. void() pend_swing22 =[ $frame5, pend_swing23 ]
  238. {
  239. // pend_frame = pend_frame + 1;
  240. // 0 -74 40 (center) W 72, H 64 (36, 32)
  241. if( self.spawnflags & PEND_Y)
  242. setsize ( self, '-8 -110 -72', '8 -28 -8' );
  243. else if ( self.spawnflags & PEND_X )
  244. setsize ( self, '-110 -8 -72', '-28 8 -8' );
  245. self.nextthink = time + 0.09;
  246. };
  247. void() pend_swing23 =[ $frame4, pend_swing24 ]
  248. {
  249. // pend_frame = pend_frame + 1;
  250. // 0 -104 17 (center) W 68, H 68 (34, 34)
  251. if( self.spawnflags & PEND_Y)
  252. setsize ( self, '-8 -172 -51', '8 -70 17' );
  253. else if ( self.spawnflags & PEND_X )
  254. setsize ( self, '-172 -8 -51', '-70 8 17' );
  255. self.nextthink = time + 0.11;
  256. };
  257. void() pend_swing24 =[ $frame3, pend_swing25 ]
  258. {
  259. // pend_frame = pend_frame + 1;
  260. // 0 -128 -14 (center) W 64, H 72 (32, 36)
  261. if( self.spawnflags & PEND_Y)
  262. setsize ( self, '-8 -160 -22', '8 -96 50' );
  263. else if ( self.spawnflags & PEND_X )
  264. setsize ( self, '-160 -8 -22', '-96 8 50' );
  265. self.nextthink = time + 0.13;
  266. };
  267. void() pend_swing25 =[ $frame2, pend_swing26 ]
  268. {
  269. // pend_frame = pend_frame + 1;
  270. // 0 -142 -50 (center) W 60, H 76 (30, 38)
  271. if( self.spawnflags & PEND_Y)
  272. setsize ( self, '-8 -172 12', '8 -112 88' );
  273. else if ( self.spawnflags & PEND_X )
  274. setsize ( self, '-172 -8 12', '-112 8 88' );
  275. self.nextthink = time + 0.15;
  276. };
  277. void() pend_swing26 =[ $frame1, pend_swing1 ]
  278. {
  279. // pend_frame = pend_frame + 1;
  280. // 0 -148 -88 (center) W 56, H 80 (28,40)
  281. if( self.spawnflags & PEND_Y)
  282. setsize ( self, '-8 -176 48', '8 -120 128' );
  283. else if ( self.spawnflags & PEND_X )
  284. setsize ( self, '-176 -8 48', '-120 8 128' );
  285. self.nextthink = time + 0.17;
  286. };
  287. void() pend_touch =
  288. {
  289. if (other.health < 1 || other.takedamage == DAMAGE_NO)
  290. return;
  291. if (self.attack_finished < time)
  292. {
  293. sound ( self, CHAN_VOICE, "pendulum/hit.wav", 1, ATTN_NORM);
  294. self.attack_finished = time + 1;
  295. }
  296. T_Damage (other, self, self, self.currentammo);
  297. // Fling the impactee in the direction the blade was swinging.
  298. if (self.spawnflags & PEND_Y)
  299. {
  300. // other.velocity_y = other.velocity_y - impactVelocity * 250;
  301. other.velocity_y = impactVelocity * -250;
  302. }
  303. else if(self.spawnflags & PEND_X)
  304. {
  305. // other.velocity_x = other.velocity_x + impactVelocity * 250;
  306. other.velocity_x = impactVelocity * 250;
  307. }
  308. // Fling the impactee up a little bit.
  309. // other.velocity_z = other.velocity_z + 200;
  310. other.velocity_z = 200;
  311. SpawnMeatSpray ( other.origin, other.velocity);
  312. };
  313. void() pend_use =
  314. {
  315. self.nextthink = time + self.delay;
  316. self.think = pend_swing1;
  317. };
  318. /*QUAKED pendulum (0 .5 .8) (-8 -24 -100) (8 24 100) PEND_X PEND_Y PEND_TRG
  319. The Pendulum
  320. Values:
  321. delay - amount of time (in seconds) before starting swinging. default 1.
  322. currentammo - amount of damage for each contact. default 5.
  323. Directional Flags: Pendulum swings perpendicular to it's angle. (eg. A pendulum facing east will swing north/south).
  324. Default: PEND_Y
  325. The pendulum angle is set automatically depending on the PEND_ choice.
  326. PEND_X - a pendulum hanging from the ceiling swinging parallel to the X axis.
  327. PEND_Y - a pendulum hanging from the ceiling swinging parallel to the Y axis.
  328. PEND_TRG - the pendulum must be triggered to start swinging. The delay value still affects the pendulum.
  329. */
  330. void() pendulum =
  331. {
  332. local vector center;
  333. precache_model ("progs/pendulum.mdl");
  334. precache_sound ("pendulum/swing.wav");
  335. precache_sound ("pendulum/hit.wav");
  336. setmodel (self, "progs/pendulum.mdl");
  337. if (!self.spawnflags)
  338. self.spawnflags = self.spawnflags + PEND_Y;
  339. if (self.spawnflags & PEND_Y)
  340. {
  341. setsize (self, '-8 -24 -100', '8 24 100');
  342. self.angles = '0 0 0';
  343. self.v_angle = '0 0 0';
  344. // if (self.angles_y != 0 )
  345. // self.angles_y = 0;
  346. }
  347. else if ( self.spawnflags & PEND_X )
  348. {
  349. setsize (self, '-24 -8 -100', '24 8 100');
  350. self.angles = '0 270 0';
  351. self.v_angle = '0 270 0';
  352. // if (self.angles_y != 270 )
  353. // self.angles_y = 270;
  354. }
  355. else
  356. error ( "ERROR: Unimplemented Pendulum Type (pendulum.qc)" );
  357. if (!self.currentammo)
  358. self.currentammo = 5;
  359. if (!self.delay)
  360. self.delay = 1;
  361. impactVelocity = 0;
  362. self.solid = SOLID_TRIGGER;
  363. self.takedamage = DAMAGE_NO;
  364. self.touch = pend_touch;
  365. if (self.spawnflags & PEND_TRG)
  366. {
  367. self.use = pend_use;
  368. }
  369. else
  370. {
  371. self.nextthink = time + self.delay;
  372. self.think = pend_swing1;
  373. }
  374. };