]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/func/pendulum.qc
Step 5: complete
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / pendulum.qc
1 #ifdef SVQC
2 .float freq;
3 void func_pendulum_controller_think(entity this)
4 {
5         float v;
6         this.nextthink = time + 0.1;
7
8         if (!(this.owner.active == ACTIVE_ACTIVE))
9         {
10                 this.owner.avelocity_x = 0;
11                 return;
12         }
13
14         // calculate sinewave using makevectors
15         makevectors((this.nextthink * this.owner.freq + this.owner.phase) * '0 360 0');
16         v = this.owner.speed * v_forward_y + this.cnt;
17         if(this.owner.classname == "func_pendulum") // don't brake stuff if the func_bobbing was killtarget'ed
18         {
19                 // * 10 so it will arrive in 0.1 sec
20                 this.owner.avelocity_z = (remainder(v - this.owner.angles_z, 360)) * 10;
21         }
22 }
23
24 spawnfunc(func_pendulum)
25 {
26         entity controller;
27         if (this.noise != "")
28         {
29                 precache_sound(this.noise);
30                 soundto(MSG_INIT, this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE);
31         }
32
33         this.active = ACTIVE_ACTIVE;
34
35         // keys: angle, speed, phase, noise, freq
36
37         if(!this.speed)
38                 this.speed = 30;
39         // not initializing this.dmg to 2, to allow damageless pendulum
40
41         if(this.dmg && (this.message == ""))
42                 this.message = " was squished";
43         if(this.dmg && (this.message2 == ""))
44                 this.message2 = "was squished by";
45         if(this.dmg && (!this.dmgtime))
46                 this.dmgtime = 0.25;
47         this.dmgtime2 = time;
48
49         this.blocked = generic_plat_blocked;
50
51         this.avelocity_z = 0.0000001;
52         if (!InitMovingBrushTrigger(this))
53                 return;
54
55         if(!this.freq)
56         {
57                 // find pendulum length (same formula as Q3A)
58                 this.freq = 1 / (M_PI * 2) * sqrt(autocvar_sv_gravity / (3 * max(8, fabs(this.mins_z))));
59         }
60
61         // copy initial angle
62         this.cnt = this.angles_z;
63
64         // wait for targets to spawn
65         controller = new(func_pendulum_controller);
66         controller.owner = this;
67         controller.nextthink = time + 1;
68         setthink(controller, func_pendulum_controller_think);
69         this.nextthink = this.SUB_LTIME + 999999999;
70         SUB_THINK(this, SUB_NullThink); // for PushMove
71
72         //this.effects |= EF_LOWPRECISION;
73
74         // TODO make a reset function for this one
75 }
76 #endif