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