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