]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/func/bobbing.qc
Merge branch 'TimePath/modules'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / bobbing.qc
1 #include "bobbing.qh"
2 #ifdef SVQC
3 .float height;
4 void func_bobbing_controller_think(entity this)
5 {
6         vector v;
7         this.nextthink = time + 0.1;
8
9         if(this.owner.active != ACTIVE_ACTIVE)
10         {
11                 this.owner.velocity = '0 0 0';
12                 return;
13         }
14
15         // calculate sinewave using makevectors
16         makevectors((this.nextthink * this.owner.cnt + this.owner.phase * 360) * '0 1 0');
17         v = this.owner.destvec + this.owner.movedir * v_forward_y;
18         if(this.owner.classname == "func_bobbing") // don't brake stuff if the func_bobbing was killtarget'ed
19                 // * 10 so it will arrive in 0.1 sec
20                 this.owner.velocity = (v - this.owner.SUB_ORIGIN) * 10;
21 }
22
23 /*QUAKED spawnfunc_func_bobbing (0 .5 .8) ? X_AXIS Y_AXIS
24 Brush model that moves back and forth on one axis (default Z).
25 speed : how long one cycle takes in seconds (default 4)
26 height : how far the cycle moves (default 32)
27 phase : cycle timing adjustment (0-1 as a fraction of the cycle, default 0)
28 noise : path/name of looping .wav file to play.
29 dmg : Do this mutch dmg every .dmgtime intervall when blocked
30 dmgtime : See above.
31 */
32 spawnfunc(func_bobbing)
33 {
34         entity controller;
35         if (this.noise != "")
36         {
37                 precache_sound(this.noise);
38                 soundto(MSG_INIT, this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE);
39         }
40         if (!this.speed)
41                 this.speed = 4;
42         if (!this.height)
43                 this.height = 32;
44         // center of bobbing motion
45         this.destvec = this.origin;
46         // time scale to get degrees
47         this.cnt = 360 / this.speed;
48
49         this.active = ACTIVE_ACTIVE;
50
51         // damage when blocked
52         setblocked(this, generic_plat_blocked);
53         if(this.dmg && (this.message == ""))
54                 this.message = " was squished";
55     if(this.dmg && (this.message2 == ""))
56                 this.message2 = "was squished by";
57         if(this.dmg && (!this.dmgtime))
58                 this.dmgtime = 0.25;
59         this.dmgtime2 = time;
60
61         // how far to bob
62         if (this.spawnflags & 1) // X
63                 this.movedir = '1 0 0' * this.height;
64         else if (this.spawnflags & 2) // Y
65                 this.movedir = '0 1 0' * this.height;
66         else // Z
67                 this.movedir = '0 0 1' * this.height;
68
69         if (!InitMovingBrushTrigger(this))
70                 return;
71
72         // wait for targets to spawn
73         controller = new(func_bobbing_controller);
74         controller.owner = this;
75         controller.nextthink = time + 1;
76         setthink(controller, func_bobbing_controller_think);
77         this.SUB_NEXTTHINK = this.SUB_LTIME + 999999999;
78         SUB_THINK(this, SUB_NullThink);
79
80         // Savage: Reduce bandwith, critical on e.g. nexdm02
81         this.effects |= EF_LOWPRECISION;
82
83         // TODO make a reset function for this one
84 }
85 #endif