]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/subs.qc
Use think accessors
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / subs.qc
index d9de97301b9d068d8569bf1f8503723201918083..bcc7c057c26ef233ea0aa02c87806ea7fef84ccb 100644 (file)
@@ -1,8 +1,7 @@
-void SUB_NullThink(void) { }
+void SUB_NullThink() { }
 
 void()  SUB_CalcMoveDone;
 void() SUB_CalcAngleMoveDone;
-//void() SUB_UseTargets;
 
 /*
 ==================
@@ -12,7 +11,7 @@ Applies some friction to self
 ==================
 */
 .float friction;
-void SUB_Friction (void)
+void SUB_Friction ()
 {SELFPARAM();
        self.SUB_NEXTTHINK = time;
        if(self.SUB_FLAGS & FL_ONGROUND)
@@ -45,17 +44,17 @@ void SUB_VanishOrRemove (entity ent)
        }
 }
 
-void SUB_SetFade_Think (void)
+void SUB_SetFade_Think ()
 {SELFPARAM();
-       if(self.alpha == 0)
-               self.alpha = 1;
-       self.SUB_THINK = SUB_SetFade_Think;
-       self.SUB_NEXTTHINK = time;
-       self.alpha -= frametime * self.fade_rate;
-       if (self.alpha < 0.01)
-               SUB_VanishOrRemove(self);
+       if(this.alpha == 0)
+               this.alpha = 1;
+       this.SUB_THINK = SUB_SetFade_Think;
+       this.SUB_NEXTTHINK = time;
+       this.alpha -= frametime * this.fade_rate;
+       if (this.alpha < 0.01)
+               SUB_VanishOrRemove(this);
        else
-               self.SUB_NEXTTHINK = time;
+               this.SUB_NEXTTHINK = time;
 }
 
 /*
@@ -80,7 +79,7 @@ calculate self.SUB_VELOCITY and self.SUB_NEXTTHINK to reach dest from
 self.SUB_ORIGIN traveling at speed
 ===============
 */
-void SUB_CalcMoveDone (void)
+void SUB_CalcMoveDone ()
 {SELFPARAM();
        // After moving, set origin to exact final destination
 
@@ -92,9 +91,8 @@ void SUB_CalcMoveDone (void)
 }
 
 .float platmovetype_turn;
-void SUB_CalcMove_controller_think (void)
+void SUB_CalcMove_controller_think ()
 {SELFPARAM();
-       entity oldself;
        float traveltime;
        float phasepos;
        float nexttick;
@@ -144,11 +142,10 @@ void SUB_CalcMove_controller_think (void)
        else
        {
                // derivative: delta + 2 * delta2 (e.g. for angle positioning)
-               oldself = self;
-               self.owner.SUB_THINK = self.think1;
-               setself(self.owner);
-               remove(oldself);
-               self.SUB_THINK();
+               entity own = self.owner;
+               own.SUB_THINK = self.think1;
+               remove(self);
+               WITHSELF(own, own.SUB_THINK());
        }
 }
 
@@ -222,8 +219,7 @@ void SUB_CalcMove_Bezier (vector tcontrol, vector tdest, float tspeedtype, float
                return;
        }
 
-       controller = spawn();
-       controller.classname = "SUB_CalcMove_controller";
+       controller = new(SUB_CalcMove_controller);
        controller.owner = self;
        controller.platmovetype = self.platmovetype;
        controller.platmovetype_start = self.platmovetype_start;
@@ -232,7 +228,7 @@ void SUB_CalcMove_Bezier (vector tcontrol, vector tdest, float tspeedtype, float
        controller.finaldest = (tdest + '0 0 0.125'); // where do we want to end? Offset to overshoot a bit.
        controller.animstate_starttime = time;
        controller.animstate_endtime = time + traveltime;
-       controller.think = SUB_CalcMove_controller_think;
+       setthink(controller, SUB_CalcMove_controller_think);
        controller.think1 = self.SUB_THINK;
 
        // the thinking is now done by the controller
@@ -240,9 +236,7 @@ void SUB_CalcMove_Bezier (vector tcontrol, vector tdest, float tspeedtype, float
        self.SUB_NEXTTHINK = self.SUB_LTIME + traveltime;
 
        // invoke controller
-       setself(controller);
-       self.think();
-       setself(self.owner);
+       WITHSELF(controller, getthink(controller)());
 }
 
 void SUB_CalcMove (vector tdest, float tspeedtype, float tspeed, void() func)
@@ -295,8 +289,8 @@ void SUB_CalcMove (vector tdest, float tspeedtype, float tspeed, void() func)
 }
 
 void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeedtype, float tspeed, void() func)
-{SELFPARAM();
-       WITH(entity, self, ent, SUB_CalcMove(tdest, tspeedtype, tspeed, func));
+{
+       WITHSELF(ent, SUB_CalcMove(tdest, tspeedtype, tspeed, func));
 }
 
 /*
@@ -309,7 +303,7 @@ self.angles rotating
 The calling function should make sure self.SUB_THINK is valid
 ===============
 */
-void SUB_CalcAngleMoveDone (void)
+void SUB_CalcAngleMoveDone ()
 {SELFPARAM();
        // After rotating, set angle to exact final angle
        self.angles = self.finalangle;
@@ -363,6 +357,6 @@ void SUB_CalcAngleMove (vector destangle, float tspeedtype, float tspeed, void()
 }
 
 void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeedtype, float tspeed, void() func)
-{SELFPARAM();
-       WITH(entity, self, ent, SUB_CalcAngleMove (destangle, tspeedtype, tspeed, func));
+{
+       WITHSELF(ent, SUB_CalcAngleMove (destangle, tspeedtype, tspeed, func));
 }