]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/subs.qc
Remove SELFPARAM() from .think and .touch
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / subs.qc
index a0f60bb32f03a2f3cd99da0924d6e02c4cd6db09..c2be7c72d925ecd12176b44d56ab3423354ae5c2 100644 (file)
@@ -1,8 +1,7 @@
-void SUB_NullThink() { }
+void SUB_NullThink(entity this) { }
 
-void()  SUB_CalcMoveDone;
-void() SUB_CalcAngleMoveDone;
-//void() SUB_UseTargets;
+void SUB_CalcMoveDone(entity this);
+void SUB_CalcAngleMoveDone(entity this);
 
 /*
 ==================
@@ -45,17 +44,17 @@ void SUB_VanishOrRemove (entity ent)
        }
 }
 
-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);
+void SUB_SetFade_Think (entity this)
+{
+       if(this.alpha == 0)
+               this.alpha = 1;
+       SUB_THINK(this, 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;
 }
 
 /*
@@ -68,7 +67,7 @@ Fade 'ent' out when time >= 'when'
 void SUB_SetFade (entity ent, float when, float fading_time)
 {
        ent.fade_rate = 1/fading_time;
-       ent.SUB_THINK = SUB_SetFade_Think;
+       SUB_THINK(ent, SUB_SetFade_Think);
        ent.SUB_NEXTTHINK = when;
 }
 
@@ -80,21 +79,20 @@ calculate self.SUB_VELOCITY and self.SUB_NEXTTHINK to reach dest from
 self.SUB_ORIGIN traveling at speed
 ===============
 */
-void SUB_CalcMoveDone ()
-{SELFPARAM();
+void SUB_CalcMoveDone(entity this)
+{
        // After moving, set origin to exact final destination
 
        SUB_SETORIGIN (self, self.finaldest);
        self.SUB_VELOCITY = '0 0 0';
        self.SUB_NEXTTHINK = -1;
        if (self.think1)
-               self.think1 ();
+               self.think1 (self);
 }
 
 .float platmovetype_turn;
-void SUB_CalcMove_controller_think ()
-{SELFPARAM();
-       entity oldself;
+void SUB_CalcMove_controller_think (entity this)
+{
        float traveltime;
        float phasepos;
        float nexttick;
@@ -144,11 +142,10 @@ void SUB_CalcMove_controller_think ()
        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;
+               SUB_THINK(own, self.think1);
+               remove(self);
+               WITHSELF(own, SUB_THUNK(own)(own));
        }
 }
 
@@ -186,7 +183,7 @@ float TSPEED_START = 1;
 float TSPEED_END = 2;
 // TODO average too?
 
-void SUB_CalcMove_Bezier (vector tcontrol, vector tdest, float tspeedtype, float tspeed, void() func)
+void SUB_CalcMove_Bezier (vector tcontrol, vector tdest, float tspeedtype, float tspeed, void(entity this) func)
 {SELFPARAM();
        float   traveltime;
        entity controller;
@@ -196,7 +193,7 @@ void SUB_CalcMove_Bezier (vector tcontrol, vector tdest, float tspeedtype, float
 
        self.think1 = func;
        self.finaldest = tdest;
-       self.SUB_THINK = SUB_CalcMoveDone;
+       SUB_THINK(self, SUB_CalcMoveDone);
 
        switch(tspeedtype)
        {
@@ -231,20 +228,18 @@ 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;
-       controller.think1 = self.SUB_THINK;
+       setthink(controller, SUB_CalcMove_controller_think);
+       controller.think1 = SUB_THUNK(self);
 
        // the thinking is now done by the controller
-       self.SUB_THINK = SUB_NullThink; // for PushMove
+       SUB_THINK(self, SUB_NullThink); // for PushMove
        self.SUB_NEXTTHINK = self.SUB_LTIME + traveltime;
 
        // invoke controller
-       setself(controller);
-       self.think();
-       setself(self.owner);
+       WITHSELF(controller, getthink(controller)(controller));
 }
 
-void SUB_CalcMove (vector tdest, float tspeedtype, float tspeed, void() func)
+void SUB_CalcMove (vector tdest, float tspeedtype, float tspeed, void(entity this) func)
 {SELFPARAM();
        vector  delta;
        float   traveltime;
@@ -254,7 +249,7 @@ void SUB_CalcMove (vector tdest, float tspeedtype, float tspeed, void() func)
 
        self.think1 = func;
        self.finaldest = tdest;
-       self.SUB_THINK = SUB_CalcMoveDone;
+       SUB_THINK(self, SUB_CalcMoveDone);
 
        if (tdest == self.SUB_ORIGIN)
        {
@@ -293,9 +288,9 @@ void SUB_CalcMove (vector tdest, float tspeedtype, float tspeed, void() func)
        SUB_CalcMove_Bezier((self.SUB_ORIGIN + tdest) * 0.5, tdest, tspeedtype, tspeed, 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));
+void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeedtype, float tspeed, void(entity this) func)
+{
+       WITHSELF(ent, SUB_CalcMove(tdest, tspeedtype, tspeed, func));
 }
 
 /*
@@ -308,18 +303,18 @@ self.angles rotating
 The calling function should make sure self.SUB_THINK is valid
 ===============
 */
-void SUB_CalcAngleMoveDone ()
-{SELFPARAM();
+void SUB_CalcAngleMoveDone(entity this)
+{
        // After rotating, set angle to exact final angle
        self.angles = self.finalangle;
        self.SUB_AVELOCITY = '0 0 0';
        self.SUB_NEXTTHINK = -1;
        if (self.think1)
-               self.think1 ();
+               self.think1 (self);
 }
 
 // FIXME: I fixed this function only for rotation around the main axes
-void SUB_CalcAngleMove (vector destangle, float tspeedtype, float tspeed, void() func)
+void SUB_CalcAngleMove (vector destangle, float tspeedtype, float tspeed, void(entity this) func)
 {SELFPARAM();
        vector  delta;
        float   traveltime;
@@ -348,7 +343,7 @@ void SUB_CalcAngleMove (vector destangle, float tspeedtype, float tspeed, void()
 
        self.think1 = func;
        self.finalangle = destangle;
-       self.SUB_THINK = SUB_CalcAngleMoveDone;
+       SUB_THINK(self, SUB_CalcAngleMoveDone);
 
        if (traveltime < 0.1)
        {
@@ -361,7 +356,7 @@ void SUB_CalcAngleMove (vector destangle, float tspeedtype, float tspeed, void()
        self.SUB_NEXTTHINK = self.SUB_LTIME + traveltime;
 }
 
-void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeedtype, float tspeed, void() func)
-{SELFPARAM();
-       WITH(entity, self, ent, SUB_CalcAngleMove (destangle, tspeedtype, tspeed, func));
+void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeedtype, float tspeed, void(entity this) func)
+{
+       WITHSELF(ent, SUB_CalcAngleMove (destangle, tspeedtype, tspeed, func));
 }