]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/trigger/multivibrator.qc
Change the internal database value name to _ranked
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / trigger / multivibrator.qc
1 #include "multivibrator.qh"
2 #ifdef SVQC
3 void multivibrator_send(entity this)
4 {
5         float newstate;
6         float cyclestart;
7
8         cyclestart = floor((time + this.phase) / (this.wait + this.respawntime)) * (this.wait + this.respawntime) - this.phase;
9
10         newstate = (time < cyclestart + this.wait);
11
12         if(this.state != newstate)
13                 SUB_UseTargets(this, this, NULL);
14         this.state = newstate;
15
16         if(this.state)
17                 this.nextthink = cyclestart + this.wait + 0.01;
18         else
19                 this.nextthink = cyclestart + this.wait + this.respawntime + 0.01;
20 }
21
22 void multivibrator_send_think(entity this)
23 {
24         multivibrator_send(this);
25 }
26
27 void multivibrator_toggle(entity this, entity actor, entity trigger)
28 {
29         if(this.nextthink == 0)
30         {
31                 multivibrator_send(this);
32         }
33         else
34         {
35                 if(this.state)
36                 {
37                         SUB_UseTargets(this, actor, trigger);
38                         this.state = 0;
39                 }
40                 this.nextthink = 0;
41         }
42 }
43
44 void multivibrator_reset(entity this)
45 {
46         if(!(this.spawnflags & 1))
47                 this.nextthink = 0; // wait for a trigger event
48         else
49                 this.nextthink = max(1, time);
50 }
51
52 /*QUAKED trigger_multivibrator (.5 .5 .5) (-8 -8 -8) (8 8 8) START_ON
53 "Multivibrator" trigger gate... repeatedly sends trigger events. When triggered, turns on or off.
54 -------- KEYS --------
55 target: trigger all entities with this targetname when it goes off
56 targetname: name that identifies this entity so it can be triggered; when off, it always uses the OFF state
57 phase: offset of the timing
58 wait: "on" cycle time (default: 1)
59 respawntime: "off" cycle time (default: same as wait)
60 -------- SPAWNFLAGS --------
61 START_ON: assume it is already turned on (when targeted)
62 */
63 spawnfunc(trigger_multivibrator)
64 {
65         if(!this.wait)
66                 this.wait = 1;
67         if(!this.respawntime)
68                 this.respawntime = this.wait;
69
70         this.state = 0;
71         this.use = multivibrator_toggle;
72         setthink(this, multivibrator_send_think);
73         this.nextthink = max(1, time);
74
75         IFTARGETED
76                 multivibrator_reset(this);
77 }
78 #endif