Advertisement
Guest User

Rotation QuakeC 1

a guest
Oct 26th, 2011
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.68 KB | None | 0 0
  1. /*
  2. * HL rotating things
  3. *
  4. * from QuakeLife by avirox
  5. *
  6. * Pros: Simpler and use less models
  7. * Cons: Engine and map compiler must support (origin brushes)
  8. * Possible solution: Set the origin some other way
  9. * It's messy though - Quake wasn't made for this
  10. *
  11. */
  12.  
  13. // for now only doors, gb
  14.  
  15. void() rot_crush =
  16. {
  17. //dprint ("plat_crush\n");
  18.  
  19. T_Damage (other, self, self, 1000, DTH_WORLD_SQUISH, FALSE, 1);
  20. };
  21.  
  22. // DOOR_START_OPEN 1
  23. float DOOR_REVERSE = 2;
  24. // DOOR_DONT_LINK 4
  25. // DOOR_GOLD_KEY 8
  26. // DOOR_SILVER_KEY 16
  27. // TOGGLE 32
  28. float DOOR_X_AXIS = 64;
  29. float DOOR_Y_AXIS = 128;
  30.  
  31. /*QUAKED rotate_door (0 .5 .8) ? START_OPEN DOOR_REVERSE DOOR_DONT_LINK GOLD_KEY SILVER_KEY TOGGLE DOOR_X_AXIS DOOR_Y_AXIS
  32. if two doors touch, they are assumed to be connected and operate as a unit.
  33.  
  34. TOGGLE causes the door to wait in both the start and end states for a trigger event.
  35.  
  36. START_OPEN causes the door to move to its destination when spawned, and operate in reverse. It is used to temporarily or permanently close off an area when triggered (not usefull for touch or takedamage doors).
  37.  
  38. Key doors are allways wait -1.
  39.  
  40. "target" must target an info_null or info_rotate with matching targetname, which marks the center of rotation
  41. "linkname" rotating doors must be linked manually; give linked doors the same linkname (string)
  42. "message" is printed when the door is touched if it is a trigger door and it hasn't been fired yet
  43. "distance" amount in degrees to rotate
  44. "targetname" if set, no touch field will be spawned and a remote button or trigger field activates the door.
  45. "health" if set, door must be shot open
  46. "speed" movement speed (100 default)
  47. "wait" wait before returning (3 default, -1 = never return)
  48. "lip" lip remaining at end of move (8 default)
  49. "dmg" damage to inflict when blocked (2 default)
  50. "noise1" overrides the stopping sound if sounds 0
  51. "noise2" overrides the moving sound if sounds 0
  52. "sounds"
  53. 0) no sound
  54. 1) stone
  55. 2) base
  56. 3) stone chain
  57. 4) screechy metal
  58. */
  59.  
  60. // avirox, Urre, LordHavoc, Baker, gb
  61.  
  62. void() rotate_door =
  63. {
  64. /* local entity ent;
  65.  
  66. ent = find( world, targetname, self.target);
  67. */
  68. if (!self.target) // gb
  69. objerror ("rotate_door without target\n");
  70.  
  71. if (world.worldtype == 0)
  72. {
  73. precache_sound ("doors/medtry.wav");
  74. precache_sound ("doors/meduse.wav");
  75. self.noise3 = "doors/medtry.wav";
  76. self.noise4 = "doors/meduse.wav";
  77. }
  78. else if (world.worldtype == 1)
  79. {
  80. precache_sound ("doors/runetry.wav");
  81. precache_sound ("doors/runeuse.wav");
  82. self.noise3 = "doors/runetry.wav";
  83. self.noise4 = "doors/runeuse.wav";
  84. }
  85. else if (world.worldtype == 2)
  86. {
  87. precache_sound ("doors/basetry.wav");
  88. precache_sound ("doors/baseuse.wav");
  89. self.noise3 = "doors/basetry.wav";
  90. self.noise4 = "doors/baseuse.wav";
  91. }
  92. else
  93. {
  94. dprint ("no worldtype set!\n");
  95. }
  96. if (self.sounds == 0)
  97. {
  98. if (!self.noise1) // gb, stopping sound
  99. self.noise1 = "misc/null.wav";
  100.  
  101. if (!self.noise2) // gb, moving sound
  102. self.noise2 = "misc/null.wav";
  103.  
  104. precache_sound (self.noise1);
  105. precache_sound (self.noise2);
  106. }
  107. if (self.sounds == 1)
  108. {
  109. precache_sound ("doors/drclos4.wav");
  110. precache_sound ("doors/doormv1.wav");
  111. self.noise1 = "doors/drclos4.wav";
  112. self.noise2 = "doors/doormv1.wav";
  113. }
  114. if (self.sounds == 2)
  115. {
  116. precache_sound ("doors/hydro1.wav");
  117. precache_sound ("doors/hydro2.wav");
  118. self.noise2 = "doors/hydro1.wav";
  119. self.noise1 = "doors/hydro2.wav";
  120. }
  121. if (self.sounds == 3)
  122. {
  123. precache_sound ("doors/stndr1.wav");
  124. precache_sound ("doors/stndr2.wav");
  125. self.noise2 = "doors/stndr1.wav";
  126. self.noise1 = "doors/stndr2.wav";
  127. }
  128. if (self.sounds == 4)
  129. {
  130. precache_sound ("doors/ddoor1.wav");
  131. precache_sound ("doors/ddoor2.wav");
  132. self.noise1 = "doors/ddoor2.wav";
  133. self.noise2 = "doors/ddoor1.wav";
  134. }
  135.  
  136.  
  137. if (self.spawnflags & DOOR_X_AXIS)
  138. self.movedir_z = 1.0;
  139. else if (self.spawnflags & DOOR_Y_AXIS)
  140. self.movedir_x = 1.0;
  141. else // Z_AXIS
  142. self.movedir_y = 1.0;
  143.  
  144. // check for reverse rotation
  145. if (self.spawnflags & DOOR_REVERSE)
  146. self.movedir = '0 0 0' - self.movedir;
  147.  
  148. // if (world.model == "maps/e1m2rq.bsp")
  149. // self.effects = 8192;
  150.  
  151.  
  152. self.max_health = self.health;
  153. self.solid = SOLID_BSP;
  154. self.movetype = MOVETYPE_PUSH; // gb
  155.  
  156. setorigin (self, self.origin); // self.origin
  157.  
  158. setmodel (self, self.model);
  159.  
  160. self.classname = "door_rotating";
  161.  
  162. if (!self.linkname)
  163. self.linkname = string_null;
  164.  
  165. self.blocked = door_blocked;
  166. self.use = door_use;
  167.  
  168. if (self.spawnflags & DOOR_SILVER_KEY)
  169. self.items = IT_KEY1;
  170. if (self.spawnflags & DOOR_GOLD_KEY)
  171. self.items = IT_KEY2;
  172.  
  173. if (!self.speed)
  174. self.speed = 100;
  175. if (!self.wait)
  176. self.wait = 3;
  177. if (!self.lip)
  178. self.lip = 8;
  179. if (!self.dmg)
  180. self.dmg = 2;
  181.  
  182. // self.pos1 = self.origin;
  183. // self.pos2 = self.pos1 + self.movedir*(fabs(self.movedir*self.size) - self.lip);
  184.  
  185. self.pos1 = self.angles;
  186. self.pos2 = self.angles + self.movedir * self.distance;
  187.  
  188. // DOOR_START_OPEN is to allow an entity to be lighted in the closed position
  189. // but spawn in the open position
  190. if (self.spawnflags & DOOR_START_OPEN) // fixed this, gb
  191. {
  192.  
  193. self.pos2 = self.angles;
  194. self.pos1 = self.angles - self.movedir * self.distance;
  195. self.angles = self.angles + self.movedir * self.distance;
  196. // setorigin (self, self.pos1);
  197. }
  198.  
  199. self.state = STATE_BOTTOM;
  200.  
  201. if (self.health)
  202. {
  203. self.takedamage = DAMAGE_YES;
  204. self.nobleed = TRUE;
  205. self.th_die = door_killed;
  206. }
  207.  
  208. if (self.items)
  209. self.wait = -1;
  210.  
  211. //if (!(self.spawnflags & 256)) // use only - but use is touch in quake anyways lol
  212. self.touch = door_touch;
  213.  
  214. if (self.targetname) { // Door is locked if it must be triggered
  215. self.touch = SUB_Null;
  216. self.th_die = SUB_Null;
  217. }
  218.  
  219. // LinkDoors can't be done until all of the doors have been spawned, so
  220. // the sizes can be detected properly.
  221. if (!(self.spawnflags & 4))
  222. self.spawnflags = self.spawnflags | 4; // so we DONT link doors
  223.  
  224. self.think = LinkDoors;
  225. self.nextthink = self.ltime + 0.1;
  226. };
  227.  
  228. /*
  229. * gb - another rotating bmodel using origin brushes / origin vector - for testing purposes
  230. * this is from the quakesrc.org avelocity engine / qc tutorial
  231. * and should work in conjunction with avirox' engine avelocity tutorial
  232. * or any engine that supports avelocity (angle velocity)
  233. *
  234. */
  235.  
  236. float STATE_WAITING = 0;
  237. float STATE_SPINNING = 1;
  238.  
  239. // gb
  240. void() accelerator_think =
  241. {
  242. local float accel_factor;
  243.  
  244. if (self.is_female) // backwards
  245. {
  246. if (self.cnt >= self.is_female) // reached top speed?
  247. {
  248. self.think = SUB_Remove;
  249. self.nextthink = time + 0.1;
  250. dprint("removing accelerator\n");
  251. return;
  252. }
  253.  
  254. accel_factor = self.is_female / self.delay / 10;
  255. }
  256. else
  257. {
  258. if (self.cnt >= self.speed) // reached top speed?
  259. {
  260. self.think = SUB_Remove;
  261. self.nextthink = time + 0.1;
  262. dprint("removing accelerator\n");
  263. return;
  264. }
  265.  
  266. accel_factor = self.speed / self.delay / 10; // 10 FPS; delay 10 = 100 frames
  267. }
  268.  
  269. self.cnt = self.cnt + accel_factor; // keep count
  270.  
  271. if (self.wait == 4) // lol
  272. {
  273. if (self.is_female) // backwards?
  274. self.owner.avelocity_z = self.owner.avelocity_z - accel_factor;
  275. else
  276. self.owner.avelocity_z = self.owner.avelocity_z + accel_factor;
  277. }
  278. else if (self.wait == 8) // yup, save globals
  279. {
  280. if (self.is_female) // backwards?
  281. self.owner.avelocity_x = self.owner.avelocity_x - accel_factor;
  282. else
  283. self.owner.avelocity_x = self.owner.avelocity_x + accel_factor;
  284. }
  285. else
  286. {
  287. if (self.is_female) // backwards?
  288. self.owner.avelocity_y = self.owner.avelocity_y - accel_factor;
  289. else
  290. self.owner.avelocity_y = self.owner.avelocity_y + accel_factor;
  291. }
  292.  
  293. self.nextthink = time + 0.1; // accelerate every frame
  294. };
  295.  
  296. // gb
  297. void() decelerator_think =
  298. {
  299. local float accel_factor;
  300.  
  301. if (self.owner.avelocity == '0 0 0') // make very sure it stopped completely
  302. {
  303. self.think = SUB_Remove;
  304. self.nextthink = time + 0.1;
  305. dprint("removing decelerator\n");
  306. return;
  307. }
  308.  
  309. if (self.is_female) // backwards
  310. accel_factor = self.is_female / self.delay / 10;
  311. else
  312. accel_factor = self.speed / self.delay / 10; // 10 FPS; delay 10 = 100 frames
  313.  
  314. if (self.wait == 4) // lol
  315. {
  316. if (self.owner.avelocity_z < 10 && self.owner.avelocity_z > -10) // have to account for both - might be reverse
  317. self.owner.avelocity_z = 0; // make sure it doesn't go the other direction
  318. else if (self.is_female) // backwards
  319. self.owner.avelocity_z = self.owner.avelocity_z + accel_factor;
  320. else
  321. self.owner.avelocity_z = self.owner.avelocity_z - accel_factor;
  322. }
  323. else if (self.wait == 8) // yup, save globals
  324. {
  325. if (self.owner.avelocity_x < 10 && self.owner.avelocity_x > -10)
  326. self.owner.avelocity_x = 0;
  327. else if (self.is_female) // backwards
  328. self.owner.avelocity_x = self.owner.avelocity_x + accel_factor;
  329. else
  330. self.owner.avelocity_x = self.owner.avelocity_x - accel_factor;
  331. }
  332. else
  333. {
  334. if (self.owner.avelocity_y < 10 && self.owner.avelocity_y > -10)
  335. self.owner.avelocity_y = 0;
  336. else if (self.is_female) // backwards
  337. self.owner.avelocity_y = self.owner.avelocity_y + accel_factor;
  338. else
  339. self.owner.avelocity_y = self.owner.avelocity_y - accel_factor;
  340. }
  341.  
  342. self.nextthink = time + 0.1; // accelerate every frame
  343. };
  344.  
  345. // gb
  346. void() rotate_continuous_use =
  347. {
  348. local entity e; // we're dumb, so use a helper
  349.  
  350. if (self.state == STATE_SPINNING) // gb, already spinning, got toggled off - stop moving
  351. {
  352. if (self.spawnflags & 4)
  353. {
  354. if (self.delay > 0) // shall I decelerate?
  355. {
  356. e = spawn();
  357. e.owner = self;
  358. e.delay = self.delay;
  359. e.speed = self.speed;
  360. e.is_female = self.is_female; // backwards?
  361. e.wait = 4; // lol
  362. e.think = decelerator_think;
  363. e.nextthink = time + 0.1;
  364. dprint ("decelerator spawned\n");
  365. //return;
  366. }
  367. else // nope, just go for it
  368. {
  369. self.avelocity_z = 0;
  370. }
  371. }
  372. else if (self.spawnflags & 8)
  373. {
  374. if (self.delay > 0) // shall I decelerate?
  375. {
  376. e = spawn();
  377. e.owner = self;
  378. e.delay = self.delay;
  379. e.speed = self.speed;
  380. e.is_female = self.is_female; // backwards?
  381. e.wait = 8; // lol
  382. e.think = decelerator_think;
  383. e.nextthink = time + 0.1;
  384. dprint("decelerator spawned\n");
  385. //return;
  386. }
  387. else // nope, just go for it
  388. {
  389. self.avelocity_x = 0;
  390. }
  391. }
  392. else
  393. {
  394. if (self.delay > 0) // shall I decelerate?
  395. {
  396. e = spawn();
  397. e.owner = self;
  398. e.delay = self.delay;
  399. e.speed = self.speed;
  400. e.is_female = self.is_female; // backwards?
  401. // no wait
  402. e.think = decelerator_think;
  403. e.nextthink = time + 0.1;
  404. dprint("decelerator spawned\n");
  405. //return;
  406. }
  407. else // nope, just go for it
  408. {
  409. self.avelocity_y = 0;
  410. }
  411. }
  412.  
  413. self.state = STATE_WAITING; // possibly let the helper set this once stopped
  414. }
  415. else // STATE_WAITING // gb, got toggled on - start spinning
  416. {
  417. if (self.spawnflags & 4)
  418. {
  419. self.avelocity_x = 0;
  420. self.avelocity_y = 0;
  421. self.avelocity_z = 0; // null it out
  422.  
  423. if (self.delay > 0) // shall I accelerate?
  424. {
  425. e = spawn();
  426. e.owner = self;
  427. e.delay = self.delay;
  428. e.speed = self.speed;
  429. e.is_female = self.is_female; // backwards?
  430. e.wait = 4; // lol
  431. e.think = accelerator_think;
  432. e.nextthink = time + 0.1;
  433. dprint ("accelerator spawned\n");
  434. //return;
  435. }
  436. else // nope, just go for it
  437. {
  438. self.avelocity_z = self.speed;
  439. }
  440. }
  441. else if (self.spawnflags & 8)
  442. {
  443. self.avelocity_z = 0;
  444. self.avelocity_y = 0;
  445. self.avelocity_x = 0; // null it out
  446.  
  447. if (self.delay > 0) // shall I accelerate?
  448. {
  449. e = spawn();
  450. e.owner = self;
  451. e.delay = self.delay;
  452. e.speed = self.speed;
  453. e.is_female = self.is_female; // backwards?
  454. e.wait = 8; // lol
  455. e.think = accelerator_think;
  456. e.nextthink = time + 0.1;
  457. dprint("accelerator spawned\n");
  458. //return;
  459. }
  460. else // nope, just go for it
  461. {
  462. self.avelocity_x = self.speed;
  463. }
  464. }
  465. else
  466. {
  467. self.avelocity_z = 0;
  468. self.avelocity_x = 0;
  469. self.avelocity_y = 0; // null it out
  470.  
  471. if (self.delay > 0) // shall I accelerate?
  472. {
  473. e = spawn();
  474. e.owner = self;
  475. e.delay = self.delay;
  476. e.speed = self.speed;
  477. e.is_female = self.is_female; // backwards?
  478. // no wait
  479. e.think = accelerator_think;
  480. e.nextthink = time + 0.1;
  481. dprint("accelerator spawned\n");
  482. //return;
  483. }
  484. else // nope, just go for it
  485. {
  486. self.avelocity_y = self.speed;
  487. }
  488. }
  489.  
  490. self.state = STATE_SPINNING; // possibly let the helper set this once fully spun up
  491.  
  492. self.think = SUB_Null;
  493. self.nextthink = self.ltime + 9999999;
  494. }
  495. };
  496.  
  497. /*QUAKED rotate_continuous (0 .5 .8) ? x REVERSE Z_AXIS X_AXIS x x NONSOLID
  498. RMQ Origin-rotating bmodel - experimental
  499.  
  500. "targetname" if set, waits for trigger and can be toggled on/off
  501. "speed" nominal rotating speed (100 default)
  502. "delay" if set, duration of acceleration / deceleration
  503. "target" must target an info_null, which marks the center of rotation
  504. */
  505.  
  506. // gb
  507. void() rotate_continuous =
  508. {
  509. if (!self.target)
  510. objerror ("rotate_continuous without target\n");
  511.  
  512. self.solid = SOLID_BSP;
  513. self.movetype = MOVETYPE_PUSH;
  514. //self.think = SUB_Null;
  515. setorigin (self, self.origin);
  516. setmodel (self, self.model);
  517. self.classname = "rotate_continuous";
  518. setsize (self, self.mins, self.maxs);
  519.  
  520. if (!self.speed)
  521. self.speed = 100;
  522.  
  523. if (self.spawnflags & 2) // reverse direction
  524. {
  525. self.is_female = self.speed; // yeah
  526. self.speed = 0 - self.speed;
  527. }
  528.  
  529. if (self.spawnflags & 64) // not solid
  530. self.solid = SOLID_NOT;
  531.  
  532. if (!self.targetname)
  533. {
  534. self.state = STATE_WAITING;
  535. rotate_continuous_use();
  536. }
  537. else
  538. {
  539. self.state = STATE_WAITING;
  540. self.use = rotate_continuous_use;
  541. }
  542.  
  543. self.blocked = rot_crush;
  544. };
  545.  
  546. void() rotate_continuous_model = //ijed, gb A model instead of being a brush entity
  547. {
  548. if ((self.mdl) || (self.model))
  549. {
  550. if (self.mdl)
  551. {
  552. precache_model (self.mdl);
  553. self.model = self.mdl;
  554. }
  555. precache_model (self.model);
  556. setmodel (self, self.model);
  557. }
  558. else
  559. {
  560. dprint ("null rotate_continuous_model at: ");
  561. dprint (vtos (self.origin));
  562. dprint ("\n");
  563. }
  564.  
  565. rotate_continuous();
  566. };
  567.  
  568.  
  569. // still more rotating crap, this time by urre
  570. // must target something to get its origin
  571. /*
  572. void () rotate_obejct =
  573. {
  574. setorigin (self, self.origin);
  575. setmodel (self, self.model);
  576. setsize (self, self.mins, self.maxs);
  577.  
  578. self.classname = self.netname;
  579.  
  580. if (self.classname == "func_rotating_door")
  581. func_rotating_door();
  582.  
  583. else if (self.classname == "func_rotating_banana")
  584. func-rotating_banana();
  585. };
  586. */
  587.  
  588.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement