hiprot.qc 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  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. /* Rotate QuickC program
  16. By Jim Dose' 10/17/96
  17. */
  18. float STATE_ACTIVE = 0;
  19. float STATE_INACTIVE = 1;
  20. float STATE_SPEEDINGUP = 2;
  21. float STATE_SLOWINGDOWN = 3;
  22. float STATE_CLOSED = 4;
  23. float STATE_OPEN = 5;
  24. float STATE_OPENING = 6;
  25. float STATE_CLOSING = 7;
  26. float STATE_WAIT = 0;
  27. float STATE_MOVE = 1;
  28. float STATE_STOP = 2;
  29. float STATE_FIND = 3;
  30. float STATE_NEXT = 4;
  31. float OBJECT_ROTATE = 0;
  32. float OBJECT_MOVEWALL = 1;
  33. float OBJECT_SETORIGIN = 2;
  34. float TOGGLE = 1;
  35. float START_ON = 2;
  36. float ROTATION = 1;
  37. float ANGLES = 2;
  38. float STOP = 4;
  39. float NO_ROTATE = 8;
  40. float DAMAGE = 16;
  41. float MOVETIME = 32;
  42. float SET_DAMAGE = 64;
  43. float VISIBLE = 1;
  44. float TOUCH = 2;
  45. float NONBLOCKING = 4;
  46. float STAYOPEN = 1;
  47. /*QUAKED info_rotate (0 0.5 0) (-4 -4 -4) (4 4 4)
  48. Used as the point of rotation for rotatable objects.
  49. */
  50. void() info_rotate =
  51. {
  52. // remove self after a little while, to make sure that entities that
  53. // have targeted it have had a chance to spawn
  54. self.nextthink = time + 2;
  55. self.think = SUB_Remove;
  56. };
  57. void() RotateTargets =
  58. {
  59. local entity ent;
  60. local vector vx;
  61. local vector vy;
  62. local vector vz;
  63. local vector org;
  64. makevectors (self.angles);
  65. ent = find( world, targetname, self.target);
  66. while( ent )
  67. {
  68. if ( ent.rotate_type == OBJECT_SETORIGIN )
  69. {
  70. org = ent.oldorigin;
  71. vx = ( v_forward * org_x );
  72. vy = ( v_right * org_y );
  73. vy = vy * -1;
  74. vz = ( v_up * org_z );
  75. ent.neworigin = vx + vy + vz;
  76. setorigin( ent, ent.neworigin + self.origin );
  77. }
  78. else if ( ent.rotate_type == OBJECT_ROTATE )
  79. {
  80. ent.angles = self.angles;
  81. org = ent.oldorigin;
  82. vx = ( v_forward * org_x );
  83. vy = ( v_right * org_y );
  84. vy = vy * -1;
  85. vz = ( v_up * org_z );
  86. ent.neworigin = vx + vy + vz;
  87. setorigin( ent, ent.neworigin + self.origin );
  88. }
  89. else
  90. {
  91. org = ent.oldorigin;
  92. vx = ( v_forward * org_x );
  93. vy = ( v_right * org_y );
  94. vy = vy * -1;
  95. vz = ( v_up * org_z );
  96. ent.neworigin = vx + vy + vz;
  97. ent.neworigin = self.origin - self.oldorigin + (ent.neworigin - ent.oldorigin);
  98. ent.velocity = (ent.neworigin-ent.origin)*25;
  99. }
  100. ent = find( ent, targetname, self.target);
  101. }
  102. };
  103. void() RotateTargetsFinal =
  104. {
  105. local entity ent;
  106. ent = find( world, targetname, self.target);
  107. while( ent )
  108. {
  109. ent.velocity = '0 0 0';
  110. if ( ent.rotate_type == OBJECT_ROTATE )
  111. {
  112. ent.angles = self.angles;
  113. }
  114. ent = find( ent, targetname, self.target);
  115. }
  116. };
  117. void() SetTargetOrigin =
  118. {
  119. local entity ent;
  120. ent = find( world, targetname, self.target);
  121. while( ent )
  122. {
  123. if ( ent.rotate_type == OBJECT_MOVEWALL )
  124. {
  125. setorigin( ent, self.origin - self.oldorigin +
  126. (ent.neworigin - ent.oldorigin) );
  127. }
  128. else
  129. {
  130. setorigin( ent, ent.neworigin + self.origin );
  131. }
  132. ent = find( ent, targetname, self.target);
  133. }
  134. };
  135. void() LinkRotateTargets =
  136. {
  137. local entity ent;
  138. local vector tempvec;
  139. self.oldorigin = self.origin;
  140. ent = find( world, targetname, self.target);
  141. while( ent )
  142. {
  143. if ( ent.classname == "rotate_object" )
  144. {
  145. ent.rotate_type = OBJECT_ROTATE;
  146. ent.oldorigin = ent.origin - self.oldorigin;
  147. ent.neworigin = ent.origin - self.oldorigin;
  148. ent.owner = self;
  149. }
  150. else if ( ent.classname == "func_movewall" )
  151. {
  152. ent.rotate_type = OBJECT_MOVEWALL;
  153. tempvec = ( ent.absmin + ent.absmax ) * 0.5;
  154. ent.oldorigin = tempvec - self.oldorigin;
  155. ent.neworigin = ent.oldorigin;
  156. ent.owner = self;
  157. }
  158. else
  159. {
  160. ent.rotate_type = OBJECT_SETORIGIN;
  161. ent.oldorigin = ent.origin - self.oldorigin;
  162. ent.neworigin = ent.origin - self.oldorigin;
  163. }
  164. ent = find (ent, targetname, self.target);
  165. }
  166. };
  167. void( float amount ) SetDamageOnTargets =
  168. {
  169. local entity ent;
  170. ent = find( world, targetname, self.target);
  171. while( ent )
  172. {
  173. if ( ent.classname == "trigger_hurt" )
  174. {
  175. hurt_setdamage( ent, amount );
  176. }
  177. else if ( ent.classname == "func_movewall" )
  178. {
  179. ent.dmg = amount;
  180. }
  181. ent = find( ent, targetname, self.target);
  182. }
  183. };
  184. //************************************************
  185. //
  186. // Simple continual rotatation
  187. //
  188. //************************************************
  189. void() rotate_entity_think =
  190. {
  191. local float t;
  192. t = time - self.ltime;
  193. self.ltime = time;
  194. if ( self.state == STATE_SPEEDINGUP )
  195. {
  196. self.count = self.count + self.cnt * t;
  197. if ( self.count > 1 )
  198. {
  199. self.count = 1;
  200. }
  201. // get rate of rotation
  202. t = t * self.count;
  203. }
  204. else if ( self.state == STATE_SLOWINGDOWN )
  205. {
  206. self.count = self.count - self.cnt * t;
  207. if ( self.count < 0 )
  208. {
  209. RotateTargetsFinal();
  210. self.state = STATE_INACTIVE;
  211. self.think = SUB_Null;
  212. return;
  213. }
  214. // get rate of rotation
  215. t = t * self.count;
  216. }
  217. self.angles = self.angles + ( self.rotate * t );
  218. self.angles = SUB_NormalizeAngles( self.angles );
  219. RotateTargets();
  220. self.nextthink = time + 0.02;
  221. };
  222. void() rotate_entity_use =
  223. {
  224. // change to alternate textures
  225. self.frame = 1 - self.frame;
  226. if ( self.state == STATE_ACTIVE )
  227. {
  228. if ( self.spawnflags & TOGGLE )
  229. {
  230. if ( self.speed )
  231. {
  232. self.count = 1;
  233. self.state = STATE_SLOWINGDOWN;
  234. }
  235. else
  236. {
  237. self.state = STATE_INACTIVE;
  238. self.think = SUB_Null;
  239. }
  240. }
  241. }
  242. else if ( self.state == STATE_INACTIVE )
  243. {
  244. self.think = rotate_entity_think;
  245. self.nextthink = time + 0.02;
  246. self.ltime = time;
  247. if ( self.speed )
  248. {
  249. self.count = 0;
  250. self.state = STATE_SPEEDINGUP;
  251. }
  252. else
  253. {
  254. self.state = STATE_ACTIVE;
  255. }
  256. }
  257. else if ( self.state == STATE_SPEEDINGUP )
  258. {
  259. if ( self.spawnflags & TOGGLE )
  260. {
  261. self.state = STATE_SLOWINGDOWN;
  262. }
  263. }
  264. else
  265. {
  266. self.state = STATE_SPEEDINGUP;
  267. }
  268. };
  269. void() rotate_entity_firstthink =
  270. {
  271. LinkRotateTargets();
  272. if ( self.spawnflags & START_ON )
  273. {
  274. self.state = STATE_ACTIVE;
  275. self.think = rotate_entity_think;
  276. self.nextthink = time + 0.02;
  277. self.ltime = time;
  278. }
  279. else
  280. {
  281. self.state = STATE_INACTIVE;
  282. self.think = SUB_Null;
  283. }
  284. self.use = rotate_entity_use;
  285. };
  286. /*QUAKED func_rotate_entity (0 .5 .8) (-8 -8 -8) (8 8 8) TOGGLE START_ON
  287. Creates an entity that continually rotates. Can be toggled on and
  288. off if targeted.
  289. TOGGLE = allows the rotation to be toggled on/off
  290. START_ON = wether the entity is spinning when spawned. If TOGGLE is 0, entity can be turned on, but not off.
  291. If "deathtype" is set with a string, this is the message that will appear when a player is killed by the train.
  292. "rotate" is the rate to rotate.
  293. "target" is the center of rotation.
  294. "speed" is how long the entity takes to go from standing still to full speed and vice-versa.
  295. */
  296. void() func_rotate_entity =
  297. {
  298. self.solid = SOLID_NOT;
  299. self.movetype = MOVETYPE_NONE;
  300. setmodel (self, self.model);
  301. setsize( self, self.mins, self.maxs );
  302. if ( self.speed != 0 )
  303. {
  304. self.cnt = 1 / self.speed;
  305. }
  306. self.think = rotate_entity_firstthink;
  307. self.nextthink = time + 0.1;
  308. self.ltime = time;
  309. };
  310. //************************************************
  311. //
  312. // Train with rotation functionality
  313. //
  314. //************************************************
  315. /*QUAKED path_rotate (0.5 0.3 0) (-8 -8 -8) (8 8 8) ROTATION ANGLES STOP NO_ROTATE DAMAGE MOVETIME SET_DAMAGE
  316. Path for rotate_train.
  317. ROTATION tells train to rotate at rate specified by "rotate". Use '0 0 0' to stop rotation.
  318. ANGLES tells train to rotate to the angles specified by "angles" while traveling to this path_rotate. Use values < 0 or > 360 to guarantee that it turns in a certain direction. Having this flag set automatically clears any rotation.
  319. STOP tells the train to stop and wait to be retriggered.
  320. NO_ROTATE tells the train to stop rotating when waiting to be triggered.
  321. DAMAGE tells the train to cause damage based on "dmg".
  322. MOVETIME tells the train to interpret "speed" as the length of time to take moving from one corner to another.
  323. SET_DAMAGE tells the train to set all targets damage to "dmg"
  324. "noise" contains the name of the sound to play when train stops.
  325. "noise1" contains the name of the sound to play when train moves.
  326. "event" is a target to trigger when train arrives at path_rotate.
  327. */
  328. void() path_rotate =
  329. {
  330. if ( self.noise )
  331. {
  332. precache_sound( self.noise );
  333. }
  334. if ( self.noise1 )
  335. {
  336. precache_sound( self.noise1 );
  337. }
  338. };
  339. void() rotate_train;
  340. void() rotate_train_next;
  341. void() rotate_train_find;
  342. void() rotate_train_think =
  343. {
  344. local float t;
  345. local float timeelapsed;
  346. t = time - self.ltime;
  347. self.ltime = time;
  348. if ( ( self.endtime ) && ( time >= self.endtime ) )
  349. {
  350. self.endtime = 0;
  351. if ( self.state == STATE_MOVE )
  352. {
  353. setorigin(self, self.finaldest);
  354. self.velocity = '0 0 0';
  355. }
  356. if (self.think1)
  357. self.think1();
  358. }
  359. else
  360. {
  361. timeelapsed = (time - self.cnt) * self.duration;
  362. if ( timeelapsed > 1 )
  363. timeelapsed = 1;
  364. setorigin( self, self.dest1 + ( self.dest2 * timeelapsed ) );
  365. }
  366. self.angles = self.angles + ( self.rotate * t );
  367. self.angles = SUB_NormalizeAngles( self.angles );
  368. RotateTargets();
  369. self.nextthink = time + 0.02;
  370. };
  371. void() rotate_train_use =
  372. {
  373. if (self.think1 != rotate_train_find)
  374. {
  375. if ( self.velocity != '0 0 0' )
  376. return; // already activated
  377. if ( self.think1 )
  378. {
  379. self.think1();
  380. }
  381. }
  382. };
  383. void() rotate_train_wait =
  384. {
  385. self.state = STATE_WAIT;
  386. if ( self.goalentity.noise )
  387. {
  388. sound (self, CHAN_VOICE, self.goalentity.noise, 1, ATTN_NORM);
  389. }
  390. else
  391. {
  392. sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  393. }
  394. if ( self.goalentity.spawnflags & ANGLES )
  395. {
  396. self.rotate = '0 0 0';
  397. self.angles = self.finalangle;
  398. }
  399. if ( self.goalentity.spawnflags & NO_ROTATE )
  400. {
  401. self.rotate = '0 0 0';
  402. }
  403. self.endtime = self.ltime + self.goalentity.wait;
  404. self.think1 = rotate_train_next;
  405. };
  406. void() rotate_train_stop =
  407. {
  408. self.state = STATE_STOP;
  409. if ( self.goalentity.noise )
  410. {
  411. sound (self, CHAN_VOICE, self.goalentity.noise, 1, ATTN_NORM);
  412. }
  413. else
  414. {
  415. sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  416. }
  417. if ( self.goalentity.spawnflags & ANGLES )
  418. {
  419. self.rotate = '0 0 0';
  420. self.angles = self.finalangle;
  421. }
  422. if ( self.goalentity.spawnflags & NO_ROTATE )
  423. {
  424. self.rotate = '0 0 0';
  425. }
  426. self.dmg = 0;
  427. self.think1 = rotate_train_next;
  428. };
  429. void() rotate_train_next =
  430. {
  431. local entity targ;
  432. local entity current;
  433. local vector vdestdelta;
  434. local float len, traveltime, div;
  435. local string temp;
  436. self.state = STATE_NEXT;
  437. current = self.goalentity;
  438. targ = find (world, targetname, self.path );
  439. if ( targ.classname != "path_rotate" )
  440. objerror( "Next target is not path_rotate" );
  441. if ( self.goalentity.noise1 )
  442. {
  443. self.noise1 = self.goalentity.noise1;
  444. }
  445. sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
  446. self.goalentity = targ;
  447. self.path = targ.target;
  448. if (!self.path )
  449. objerror ("rotate_train_next: no next target");
  450. if ( targ.spawnflags & STOP )
  451. {
  452. self.think1 = rotate_train_stop;
  453. }
  454. else if (targ.wait)
  455. {
  456. self.think1 = rotate_train_wait;
  457. }
  458. else
  459. {
  460. self.think1 = rotate_train_next;
  461. }
  462. if ( current.event )
  463. {
  464. // Trigger any events that should happen at the corner.
  465. temp = self.target;
  466. self.target = current.event;
  467. self.message = current.message;
  468. SUB_UseTargets();
  469. self.target = temp;
  470. self.message = string_null;
  471. }
  472. if ( current.spawnflags & ANGLES )
  473. {
  474. self.rotate = '0 0 0';
  475. self.angles = self.finalangle;
  476. }
  477. if ( current.spawnflags & ROTATION )
  478. {
  479. self.rotate = current.rotate;
  480. }
  481. if ( current.spawnflags & DAMAGE )
  482. {
  483. self.dmg = current.dmg;
  484. }
  485. if ( current.spawnflags & SET_DAMAGE )
  486. {
  487. SetDamageOnTargets( current.dmg );
  488. }
  489. if ( current.speed == -1 )
  490. {
  491. // Warp to the next path_corner
  492. setorigin( self, targ.origin );
  493. self.endtime = self.ltime + 0.01;
  494. SetTargetOrigin();
  495. if ( targ.spawnflags & ANGLES )
  496. {
  497. self.angles = targ.angles;
  498. }
  499. self.duration = 1; // 1 / duration
  500. self.cnt = time; // start time
  501. self.dest2 = '0 0 0'; // delta
  502. self.dest1 = self.origin; // original position
  503. self.finaldest = self.origin;
  504. }
  505. else
  506. {
  507. self.state = STATE_MOVE;
  508. self.finaldest = targ.origin;
  509. if (self.finaldest == self.origin)
  510. {
  511. self.velocity = '0 0 0';
  512. self.endtime = self.ltime + 0.1;
  513. self.duration = 1; // 1 / duration
  514. self.cnt = time; // start time
  515. self.dest2 = '0 0 0'; // delta
  516. self.dest1 = self.origin; // original position
  517. self.finaldest = self.origin;
  518. return;
  519. }
  520. // set destdelta to the vector needed to move
  521. vdestdelta = self.finaldest - self.origin;
  522. // calculate length of vector
  523. len = vlen (vdestdelta);
  524. if ( current.spawnflags & MOVETIME )
  525. {
  526. traveltime = current.speed;
  527. }
  528. else
  529. {
  530. // check if there's a speed change
  531. if (current.speed>0)
  532. self.speed = current.speed;
  533. if (!self.speed)
  534. objerror("No speed is defined!");
  535. // divide by speed to get time to reach dest
  536. traveltime = len / self.speed;
  537. }
  538. if (traveltime < 0.1)
  539. {
  540. self.velocity = '0 0 0';
  541. self.endtime = self.ltime + 0.1;
  542. if ( targ.spawnflags & ANGLES )
  543. {
  544. self.angles = targ.angles;
  545. }
  546. return;
  547. }
  548. // qcc won't take vec/float
  549. div = 1 / traveltime;
  550. if ( targ.spawnflags & ANGLES )
  551. {
  552. self.finalangle = SUB_NormalizeAngles( targ.angles );
  553. self.rotate = ( targ.angles - self.angles ) * div;
  554. }
  555. // set endtime to trigger a think when dest is reached
  556. self.endtime = self.ltime + traveltime;
  557. // scale the destdelta vector by the time spent traveling to get velocity
  558. self.velocity = vdestdelta * div;
  559. self.duration = div; // 1 / duration
  560. self.cnt = time; // start time
  561. self.dest2 = vdestdelta; // delta
  562. self.dest1 = self.origin; // original position
  563. }
  564. };
  565. void() rotate_train_find =
  566. {
  567. local entity targ;
  568. self.state = STATE_FIND;
  569. LinkRotateTargets();
  570. // the first target is the point of rotation.
  571. // the second target is the path.
  572. targ = find ( world, targetname, self.path);
  573. if ( targ.classname != "path_rotate" )
  574. objerror( "Next target is not path_rotate" );
  575. // Save the current entity
  576. self.goalentity = targ;
  577. if ( targ.spawnflags & ANGLES )
  578. {
  579. self.angles = targ.angles;
  580. self.finalangle = SUB_NormalizeAngles( targ.angles );
  581. }
  582. self.path = targ.target;
  583. setorigin (self, targ.origin );
  584. SetTargetOrigin();
  585. RotateTargetsFinal();
  586. self.think1 = rotate_train_next;
  587. if (!self.targetname)
  588. {
  589. // not triggered, so start immediately
  590. self.endtime = self.ltime + 0.1;
  591. }
  592. else
  593. {
  594. self.endtime = 0;
  595. }
  596. self.duration = 1; // 1 / duration
  597. self.cnt = time; // start time
  598. self.dest2 = '0 0 0'; // delta
  599. self.dest1 = self.origin; // original position
  600. };
  601. /*QUAKED func_rotate_train (0 .5 .8) (-8 -8 -8) (8 8 8)
  602. In path_rotate, set speed to be the new speed of the train after it reaches
  603. the path change. If speed is -1, the train will warp directly to the next
  604. path change after the specified wait time. If MOVETIME is set on the
  605. path_rotate, the train to interprets "speed" as the length of time to
  606. take moving from one corner to another.
  607. "noise" contains the name of the sound to play when train stops.
  608. "noise1" contains the name of the sound to play when train moves.
  609. Both "noise" and "noise1" defaults depend upon "sounds" variable and
  610. can be overridden by the "noise" and "noise1" variable in path_rotate.
  611. Also in path_rotate, if STOP is set, the train will wait until it is
  612. retriggered before moving on to the next goal.
  613. Trains are moving platforms that players can ride.
  614. "path" specifies the first path_rotate and is the starting position.
  615. If the train is the target of a button or trigger, it will not begin moving until activated.
  616. The func_rotate_train entity is the center of rotation of all objects targeted by it.
  617. If "deathtype" is set with a string, this is the message that will appear when a player is killed by the train.
  618. speed default 100
  619. dmg default 0
  620. sounds
  621. 1) ratchet metal
  622. */
  623. void() rotate_train =
  624. {
  625. objerror ("rotate_train entities should be changed to rotate_object with\nfunc_rotate_train controllers\n");
  626. };
  627. void() func_rotate_train =
  628. {
  629. if (!self.speed)
  630. self.speed = 100;
  631. if (!self.target)
  632. objerror ("rotate_train without a target");
  633. if ( !self.noise )
  634. {
  635. if (self.sounds == 0)
  636. {
  637. self.noise = ("misc/null.wav");
  638. }
  639. if (self.sounds == 1)
  640. {
  641. self.noise = ("plats/train2.wav");
  642. }
  643. }
  644. if ( !self.noise1 )
  645. {
  646. if (self.sounds == 0)
  647. {
  648. self.noise1 = ("misc/null.wav");
  649. }
  650. if (self.sounds == 1)
  651. {
  652. self.noise1 = ("plats/train1.wav");
  653. }
  654. }
  655. precache_sound( self.noise );
  656. precache_sound( self.noise1 );
  657. self.cnt = 1;
  658. self.solid = SOLID_NOT;
  659. self.movetype = MOVETYPE_STEP;
  660. self.use = rotate_train_use;
  661. setmodel (self, self.model);
  662. setsize (self, self.mins, self.maxs);
  663. setorigin (self, self.origin);
  664. // start trains on the second frame, to make sure their targets have had
  665. // a chance to spawn
  666. self.ltime = time;
  667. self.nextthink = self.ltime + 0.1;
  668. self.endtime = self.ltime + 0.1;
  669. self.think = rotate_train_think;
  670. self.think1 = rotate_train_find;
  671. self.state = STATE_FIND;
  672. self.duration = 1; // 1 / duration
  673. self.cnt = 0.1; // start time
  674. self.dest2 = '0 0 0'; // delta
  675. self.dest1 = self.origin; // original position
  676. self.flags = self.flags | FL_ONGROUND;
  677. };
  678. //************************************************
  679. //
  680. // Moving clip walls
  681. //
  682. //************************************************
  683. void() rotate_door_reversedirection;
  684. void() rotate_door_group_reversedirection;
  685. void() movewall_touch =
  686. {
  687. if (time < self.owner.attack_finished)
  688. return;
  689. if ( self.dmg )
  690. {
  691. T_Damage (other, self, self.owner, self.dmg);
  692. self.owner.attack_finished = time + 0.5;
  693. }
  694. else if ( self.owner.dmg )
  695. {
  696. T_Damage (other, self, self.owner, self.owner.dmg);
  697. self.owner.attack_finished = time + 0.5;
  698. }
  699. };
  700. void() movewall_blocked =
  701. {
  702. local entity temp;
  703. if (time < self.owner.attack_finished)
  704. return;
  705. self.owner.attack_finished = time + 0.5;
  706. if ( self.owner.classname == "func_rotate_door" )
  707. {
  708. temp = self;
  709. self = self.owner;
  710. rotate_door_group_reversedirection();
  711. self = temp;
  712. }
  713. if ( self.dmg )
  714. {
  715. T_Damage (other, self, self.owner, self.dmg);
  716. self.owner.attack_finished = time + 0.5;
  717. }
  718. else if ( self.owner.dmg )
  719. {
  720. T_Damage (other, self, self.owner, self.owner.dmg);
  721. self.owner.attack_finished = time + 0.5;
  722. }
  723. };
  724. void() movewall_think =
  725. {
  726. self.ltime = time;
  727. self.nextthink = time + 0.02;
  728. };
  729. /*QUAKED func_movewall (0 .5 .8) ? VISIBLE TOUCH NONBLOCKING
  730. Used to emulate collision on rotating objects.
  731. VISIBLE causes brush to be displayed.
  732. TOUCH specifies whether to cause damage when touched by player.
  733. NONBLOCKING makes the brush non-solid. This is useless if VISIBLE is set.
  734. "dmg" specifies the damage to cause when touched or blocked.
  735. */
  736. void() func_movewall =
  737. {
  738. self.angles = '0 0 0';
  739. self.movetype = MOVETYPE_PUSH;
  740. if ( self.spawnflags & NONBLOCKING )
  741. {
  742. self.solid = SOLID_NOT;
  743. }
  744. else
  745. {
  746. self.solid = SOLID_BSP;
  747. self.blocked = movewall_blocked;
  748. }
  749. if ( self.spawnflags & TOUCH )
  750. {
  751. self.touch = movewall_touch;
  752. }
  753. setmodel (self,self.model);
  754. if ( !( self.spawnflags & VISIBLE ) )
  755. {
  756. self.model = string_null;
  757. }
  758. self.think = movewall_think;
  759. self.nextthink = time + 0.02;
  760. self.ltime = time;
  761. };
  762. /*QUAKED rotate_object (0 .5 .8) ?
  763. This defines an object to be rotated. Used as the target of func_rotate_door.
  764. */
  765. void() rotate_object =
  766. {
  767. self.classname = "rotate_object";
  768. self.solid = SOLID_NOT;
  769. self.movetype = MOVETYPE_NONE;
  770. setmodel (self,self.model);
  771. setsize( self, self.mins, self.maxs );
  772. self.think = SUB_Null;
  773. };
  774. //************************************************
  775. //
  776. // Rotating doors
  777. //
  778. //************************************************
  779. void() rotate_door_think2 =
  780. {
  781. local float t;
  782. t = time - self.ltime;
  783. self.ltime = time;
  784. // change to alternate textures
  785. self.frame = 1 - self.frame;
  786. self.angles = self.dest;
  787. if ( self.state == STATE_OPENING )
  788. {
  789. self.state = STATE_OPEN;
  790. }
  791. else
  792. {
  793. if ( self.spawnflags & STAYOPEN )
  794. {
  795. rotate_door_group_reversedirection();
  796. return;
  797. }
  798. self.state = STATE_CLOSED;
  799. }
  800. sound(self, CHAN_VOICE, self.noise3, 1, ATTN_NORM);
  801. self.think = SUB_Null;
  802. RotateTargetsFinal();
  803. };
  804. void() rotate_door_think =
  805. {
  806. local float t;
  807. t = time - self.ltime;
  808. self.ltime = time;
  809. if ( time < self.endtime )
  810. {
  811. self.angles = self.angles + ( self.rotate * t );
  812. RotateTargets();
  813. }
  814. else
  815. {
  816. self.angles = self.dest;
  817. RotateTargets();
  818. self.think = rotate_door_think2;
  819. }
  820. self.nextthink = time + 0.01;
  821. };
  822. void() rotate_door_reversedirection =
  823. {
  824. local vector start;
  825. // change to alternate textures
  826. self.frame = 1 - self.frame;
  827. if ( self.state == STATE_CLOSING )
  828. {
  829. start = self.dest1;
  830. self.dest = self.dest2;
  831. self.state = STATE_OPENING;
  832. }
  833. else
  834. {
  835. start = self.dest2;
  836. self.dest = self.dest1;
  837. self.state = STATE_CLOSING;
  838. }
  839. sound(self, CHAN_VOICE, self.noise2, 1, ATTN_NORM);
  840. self.rotate = ( self.dest - start ) * ( 1 / self.speed );
  841. self.think = rotate_door_think;
  842. self.nextthink = time + 0.02;
  843. self.endtime = time + self.speed - ( self.endtime - time );
  844. self.ltime = time;
  845. };
  846. void() rotate_door_group_reversedirection =
  847. {
  848. local string name;
  849. // tell all associated rotaters to reverse direction
  850. if ( self.group )
  851. {
  852. name = self.group;
  853. self = find( world, group, name);
  854. while( self )
  855. {
  856. rotate_door_reversedirection();
  857. self = find( self, group, name);
  858. }
  859. }
  860. else
  861. {
  862. rotate_door_reversedirection();
  863. }
  864. };
  865. void() rotate_door_use =
  866. {
  867. local entity t;
  868. local vector start;
  869. if ( ( self.state != STATE_OPEN ) && ( self.state != STATE_CLOSED ) )
  870. return;
  871. if ( !self.cnt )
  872. {
  873. self.cnt = 1;
  874. LinkRotateTargets();
  875. }
  876. // change to alternate textures
  877. self.frame = 1 - self.frame;
  878. if ( self.state == STATE_CLOSED )
  879. {
  880. start = self.dest1;
  881. self.dest = self.dest2;
  882. self.state = STATE_OPENING;
  883. }
  884. else
  885. {
  886. start = self.dest2;
  887. self.dest = self.dest1;
  888. self.state = STATE_CLOSING;
  889. }
  890. sound(self, CHAN_VOICE, self.noise2, 1, ATTN_NORM);
  891. self.rotate = ( self.dest - start ) * ( 1 / self.speed );
  892. self.think = rotate_door_think;
  893. self.nextthink = time + 0.01;
  894. self.endtime = time + self.speed;
  895. self.ltime = time;
  896. };
  897. /*QUAKED func_rotate_door (0 .5 .8) (-8 -8 -8) (8 8 8) STAYOPEN
  898. Creates a door that rotates between two positions around a point of
  899. rotation each time it's triggered.
  900. STAYOPEN tells the door to reopen after closing. This prevents a trigger-
  901. once door from closing again when it's blocked.
  902. "dmg" specifies the damage to cause when blocked. Defaults to 2. Negative numbers indicate no damage.
  903. "speed" specifies how the time it takes to rotate
  904. "sounds"
  905. 1) medieval (default)
  906. 2) metal
  907. 3) base
  908. */
  909. void() func_rotate_door =
  910. {
  911. if (!self.target)
  912. {
  913. objerror( "rotate_door without target." );
  914. }
  915. self.dest1 = '0 0 0';
  916. self.dest2 = self.angles;
  917. self.angles = self.dest1;
  918. // default to 2 seconds
  919. if ( !self.speed )
  920. {
  921. self.speed = 2;
  922. }
  923. self.cnt = 0;
  924. if (!self.dmg)
  925. self.dmg = 2;
  926. else if ( self.dmg < 0 )
  927. {
  928. self.dmg = 0;
  929. }
  930. if (self.sounds == 0)
  931. self.sounds = 1;
  932. if (self.sounds == 1)
  933. {
  934. precache_sound ("doors/latch2.wav");
  935. precache_sound ("doors/winch2.wav");
  936. precache_sound ("doors/drclos4.wav");
  937. self.noise1 = "doors/latch2.wav";
  938. self.noise2 = "doors/winch2.wav";
  939. self.noise3 = "doors/drclos4.wav";
  940. }
  941. if (self.sounds == 2)
  942. {
  943. precache_sound ("doors/airdoor1.wav");
  944. precache_sound ("doors/airdoor2.wav");
  945. self.noise2 = "doors/airdoor1.wav";
  946. self.noise1 = "doors/airdoor2.wav";
  947. self.noise3 = "doors/airdoor2.wav";
  948. }
  949. if (self.sounds == 3)
  950. {
  951. precache_sound ("doors/basesec1.wav");
  952. precache_sound ("doors/basesec2.wav");
  953. self.noise2 = "doors/basesec1.wav";
  954. self.noise1 = "doors/basesec2.wav";
  955. self.noise3 = "doors/basesec2.wav";
  956. }
  957. self.solid = SOLID_NOT;
  958. self.movetype = MOVETYPE_NONE;
  959. setmodel (self, self.model);
  960. setorigin( self, self.origin );
  961. setsize( self, self.mins, self.maxs );
  962. self.state = STATE_CLOSED;
  963. self.use = rotate_door_use;
  964. self.think = SUB_Null;
  965. };