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