]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/func/rotating.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / rotating.qc
1 #include "rotating.qh"
2 #ifdef SVQC
3 const int FUNC_ROTATING_STARTOFF = BIT(4);
4
5 void func_rotating_setactive(entity this, int astate)
6 {
7         if (astate == ACTIVE_TOGGLE) {
8                 if (this.active == ACTIVE_ACTIVE) {
9                         this.active = ACTIVE_NOT;
10                 } else {
11                         this.active = ACTIVE_ACTIVE;
12                 }
13         } else {
14                 this.active = astate;
15         }
16
17         if (this.active  == ACTIVE_NOT) {
18                 this.avelocity = '0 0 0';
19         } else {
20                 this.avelocity = this.pos1;
21         }
22 }
23
24 void func_rotating_reset(entity this)
25 {
26         // TODO: reset angles as well?
27
28         if (this.spawnflags & FUNC_ROTATING_STARTOFF) {
29                 this.avelocity = '0 0 0';
30                 this.active = ACTIVE_NOT;
31         } else {
32                 this.avelocity = this.pos1;
33                 this.active = ACTIVE_ACTIVE;
34         }
35 }
36
37 /*QUAKED spawnfunc_func_rotating (0 .5 .8) ? - - X_AXIS Y_AXIS
38 Brush model that spins in place on one axis (default Z).
39 speed   : speed to rotate (in degrees per second)
40 noise   : path/name of looping .wav file to play.
41 dmg     : Do this mutch dmg every .dmgtime intervall when blocked
42 dmgtime : See above.
43 */
44
45 spawnfunc(func_rotating)
46 {
47         if (this.noise != "") {
48                 precache_sound(this.noise);
49                 ambientsound(this.origin, this.noise, VOL_BASE, ATTEN_IDLE);
50         }
51
52         this.setactive = func_rotating_setactive;
53
54         if (!this.speed) {
55                 this.speed = 100;
56         }
57         // FIXME: test if this turns the right way, then remove this comment (negate as needed)
58         if (this.spawnflags & BIT(2)) { // X (untested)
59                 this.avelocity = '0 0 1' * this.speed;
60         }
61         // FIXME: test if this turns the right way, then remove this comment (negate as needed)
62         else if (this.spawnflags & BIT(3)) { // Y (untested)
63                 this.avelocity = '1 0 0' * this.speed;
64         }
65         // FIXME: test if this turns the right way, then remove this comment (negate as needed)
66         else { // Z
67                 this.avelocity = '0 1 0' * this.speed;
68         }
69
70         this.pos1 = this.avelocity;
71
72         // do this after setting pos1, so we can safely reactivate the func_rotating
73         if (this.spawnflags & FUNC_ROTATING_STARTOFF) {
74                 this.avelocity = '0 0 0';
75                 this.active = ACTIVE_NOT;
76         } else {
77                 this.active = ACTIVE_ACTIVE;
78         }
79
80         if (this.dmg && (this.message == "")) {
81                 this.message = " was squished";
82         }
83         if (this.dmg && (this.message2 == "")) {
84                 this.message2 = "was squished by";
85         }
86
87
88         if (this.dmg && (!this.dmgtime)) {
89                 this.dmgtime = 0.25;
90         }
91
92         this.dmgtime2 = time;
93
94         if (!InitMovingBrushTrigger(this)) {
95                 return;
96         }
97         // no EF_LOWPRECISION here, as rounding angles is bad
98
99         setblocked(this, generic_plat_blocked);
100
101         // wait for targets to spawn
102         this.nextthink = this.ltime + 999999999;
103         setthink(this, SUB_NullThink); // for PushMove
104
105         this.reset = func_rotating_reset;
106 }
107 #endif