]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/trigger/multivibrator.qc
Ensure headers are always #included
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / trigger / multivibrator.qc
index 02a258e87f13a92a942f70f5c2427129f4457928..d946efe5f17cc533c2b104b52fb1dc2c2e37ba82 100644 (file)
@@ -1,47 +1,52 @@
+#include "multivibrator.qh"
 #ifdef SVQC
-void multivibrator_send()
+void multivibrator_send(entity this)
 {
        float newstate;
        float cyclestart;
 
-       cyclestart = floor((time + self.phase) / (self.wait + self.respawntime)) * (self.wait + self.respawntime) - self.phase;
+       cyclestart = floor((time + this.phase) / (this.wait + this.respawntime)) * (this.wait + this.respawntime) - this.phase;
 
-       newstate = (time < cyclestart + self.wait);
+       newstate = (time < cyclestart + this.wait);
 
-       activator = self;
-       if(self.state != newstate)
-               SUB_UseTargets();
-       self.state = newstate;
+       if(this.state != newstate)
+               SUB_UseTargets(this, this, NULL);
+       this.state = newstate;
 
-       if(self.state)
-               self.nextthink = cyclestart + self.wait + 0.01;
+       if(this.state)
+               this.nextthink = cyclestart + this.wait + 0.01;
        else
-               self.nextthink = cyclestart + self.wait + self.respawntime + 0.01;
+               this.nextthink = cyclestart + this.wait + this.respawntime + 0.01;
 }
 
-void multivibrator_toggle()
+void multivibrator_send_think(entity this)
 {
-       if(self.nextthink == 0)
+       multivibrator_send(this);
+}
+
+void multivibrator_toggle(entity this, entity actor, entity trigger)
+{
+       if(this.nextthink == 0)
        {
-               multivibrator_send();
+               multivibrator_send(this);
        }
        else
        {
-               if(self.state)
+               if(this.state)
                {
-                       SUB_UseTargets();
-                       self.state = 0;
+                       SUB_UseTargets(this, actor, trigger);
+                       this.state = 0;
                }
-               self.nextthink = 0;
+               this.nextthink = 0;
        }
 }
 
-void multivibrator_reset()
+void multivibrator_reset(entity this)
 {
-       if(!(self.spawnflags & 1))
-               self.nextthink = 0; // wait for a trigger event
+       if(!(this.spawnflags & 1))
+               this.nextthink = 0; // wait for a trigger event
        else
-               self.nextthink = max(1, time);
+               this.nextthink = max(1, time);
 }
 
 /*QUAKED trigger_multivibrator (.5 .5 .5) (-8 -8 -8) (8 8 8) START_ON
@@ -55,19 +60,19 @@ respawntime: "off" cycle time (default: same as wait)
 -------- SPAWNFLAGS --------
 START_ON: assume it is already turned on (when targeted)
 */
-void spawnfunc_trigger_multivibrator()
+spawnfunc(trigger_multivibrator)
 {
-       if(!self.wait)
-               self.wait = 1;
-       if(!self.respawntime)
-               self.respawntime = self.wait;
+       if(!this.wait)
+               this.wait = 1;
+       if(!this.respawntime)
+               this.respawntime = this.wait;
 
-       self.state = 0;
-       self.use = multivibrator_toggle;
-       self.think = multivibrator_send;
-       self.nextthink = max(1, time);
+       this.state = 0;
+       this.use = multivibrator_toggle;
+       setthink(this, multivibrator_send_think);
+       this.nextthink = max(1, time);
 
        IFTARGETED
-               multivibrator_reset();
+               multivibrator_reset(this);
 }
 #endif