]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/subs.qc
Properly support team field on trigger_multiple
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / subs.qc
index 6389a03cda7f450bef288cba18feba5e48aa4991..5b6182e0ab8574877e11f8432a316bcf41e94aa3 100644 (file)
@@ -1,3 +1,4 @@
+#include "subs.qh"
 void SUB_NullThink(entity this) { }
 
 void SUB_CalcMoveDone(entity this);
@@ -13,9 +14,9 @@ Applies some friction to this
 .float friction;
 void SUB_Friction (entity this)
 {
-       this.SUB_NEXTTHINK = time;
-       if(this.SUB_FLAGS & FL_ONGROUND)
-               this.SUB_VELOCITY = this.SUB_VELOCITY * (1 - frametime * this.friction);
+       this.nextthink = time;
+       if(IS_ONGROUND(this))
+               this.velocity = this.velocity * (1 - frametime * this.friction);
 }
 
 /*
@@ -40,7 +41,7 @@ void SUB_VanishOrRemove (entity ent)
        else
        {
                // remove
-               remove (ent);
+               delete(ent);
        }
 }
 
@@ -48,13 +49,13 @@ void SUB_SetFade_Think (entity this)
 {
        if(this.alpha == 0)
                this.alpha = 1;
-       SUB_THINK(this, SUB_SetFade_Think);
-       this.SUB_NEXTTHINK = time;
+       setthink(this, SUB_SetFade_Think);
+       this.nextthink = time;
        this.alpha -= frametime * this.fade_rate;
        if (this.alpha < 0.01)
                SUB_VanishOrRemove(this);
        else
-               this.SUB_NEXTTHINK = time;
+               this.nextthink = time;
 }
 
 /*
@@ -67,26 +68,26 @@ Fade 'ent' out when time >= 'when'
 void SUB_SetFade (entity ent, float when, float fading_time)
 {
        ent.fade_rate = 1/fading_time;
-       SUB_THINK(ent, SUB_SetFade_Think);
-       ent.SUB_NEXTTHINK = when;
+       setthink(ent, SUB_SetFade_Think);
+       ent.nextthink = when;
 }
 
 /*
 =============
 SUB_CalcMove
 
-calculate this.SUB_VELOCITY and this.SUB_NEXTTHINK to reach dest from
-this.SUB_ORIGIN traveling at speed
+calculate this.velocity and this.nextthink to reach dest from
+this.origin traveling at speed
 ===============
 */
 void SUB_CalcMoveDone(entity this)
 {
        // After moving, set origin to exact final destination
 
-       SUB_SETORIGIN (this, this.finaldest);
-       this.SUB_VELOCITY = '0 0 0';
-       this.SUB_NEXTTHINK = -1;
-       if (this.think1)
+       setorigin (this, this.finaldest);
+       this.velocity = '0 0 0';
+       this.nextthink = -1;
+       if (this.think1 && this.think1 != SUB_CalcMoveDone)
                this.think1 (this);
 }
 
@@ -121,31 +122,31 @@ void SUB_CalcMove_controller_think (entity this)
                        destangle_x = -destangle_x; // flip up / down orientation
 
                        // take the shortest distance for the angles
-                       vector v = SUB_ANGLES(this.owner);
+                       vector v = this.owner.angles;
                        v.x -= 360 * floor((v.x - destangle_x) / 360 + 0.5);
                        v.y -= 360 * floor((v.y - destangle_y) / 360 + 0.5);
                        v.z -= 360 * floor((v.z - destangle_z) / 360 + 0.5);
-                       SUB_ANGLES(this.owner) = v;
-                       angloc = destangle - SUB_ANGLES(this.owner);
+                       this.owner.angles = v;
+                       angloc = destangle - this.owner.angles;
                        angloc = angloc * (1 / PHYS_INPUT_FRAMETIME); // so it arrives for the next frame
-                       this.owner.SUB_AVELOCITY = angloc;
+                       this.owner.avelocity = angloc;
                }
                if(nexttick < this.animstate_endtime)
-                       veloc = nextpos - this.owner.SUB_ORIGIN;
+                       veloc = nextpos - this.owner.origin;
                else
-                       veloc = this.finaldest - this.owner.SUB_ORIGIN;
+                       veloc = this.finaldest - this.owner.origin;
                veloc = veloc * (1 / PHYS_INPUT_FRAMETIME); // so it arrives for the next frame
 
-               this.owner.SUB_VELOCITY = veloc;
+               this.owner.velocity = veloc;
                this.nextthink = nexttick;
        }
        else
        {
                // derivative: delta + 2 * delta2 (e.g. for angle positioning)
                entity own = this.owner;
-               SUB_THINK(own, this.think1);
-               remove(this);
-               WITHSELF(own, SUB_THUNK(own)(own));
+               setthink(own, this.think1);
+               delete(this);
+               getthink(own)(own);
        }
 }
 
@@ -189,23 +190,23 @@ void SUB_CalcMove_Bezier (entity this, vector tcontrol, vector tdest, float tspe
        entity controller;
 
        if (!tspeed)
-               objerror ("No speed is defined!");
+               objerror (this, "No speed is defined!");
 
        this.think1 = func;
        this.finaldest = tdest;
-       SUB_THINK(this, SUB_CalcMoveDone);
+       setthink(this, SUB_CalcMoveDone);
 
        switch(tspeedtype)
        {
                default:
                case TSPEED_START:
-                       traveltime = 2 * vlen(tcontrol - this.SUB_ORIGIN) / tspeed;
+                       traveltime = 2 * vlen(tcontrol - this.origin) / tspeed;
                        break;
                case TSPEED_END:
                        traveltime = 2 * vlen(tcontrol - tdest)       / tspeed;
                        break;
                case TSPEED_LINEAR:
-                       traveltime = vlen(tdest - this.SUB_ORIGIN)        / tspeed;
+                       traveltime = vlen(tdest - this.origin)        / tspeed;
                        break;
                case TSPEED_TIME:
                        traveltime = tspeed;
@@ -214,8 +215,8 @@ void SUB_CalcMove_Bezier (entity this, vector tcontrol, vector tdest, float tspe
 
        if (traveltime < 0.1) // useless anim
        {
-               this.SUB_VELOCITY = '0 0 0';
-               this.SUB_NEXTTHINK = this.SUB_LTIME + 0.1;
+               this.velocity = '0 0 0';
+               this.nextthink = this.ltime + 0.1;
                return;
        }
 
@@ -224,19 +225,19 @@ void SUB_CalcMove_Bezier (entity this, vector tcontrol, vector tdest, float tspe
        controller.platmovetype = this.platmovetype;
        controller.platmovetype_start = this.platmovetype_start;
        controller.platmovetype_end = this.platmovetype_end;
-       SUB_CalcMove_controller_setbezier(controller, this.SUB_ORIGIN, tcontrol, tdest);
+       SUB_CalcMove_controller_setbezier(controller, this.origin, tcontrol, tdest);
        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;
        setthink(controller, SUB_CalcMove_controller_think);
-       controller.think1 = SUB_THUNK(this);
+       controller.think1 = getthink(this);
 
        // the thinking is now done by the controller
-       SUB_THINK(this, SUB_NullThink); // for PushMove
-       this.SUB_NEXTTHINK = this.SUB_LTIME + traveltime;
+       setthink(this, SUB_NullThink); // for PushMove
+       this.nextthink = this.ltime + traveltime;
 
        // invoke controller
-       WITHSELF(controller, getthink(controller)(controller));
+       getthink(controller)(controller);
 }
 
 void SUB_CalcMove (entity this, vector tdest, float tspeedtype, float tspeed, void(entity this) func)
@@ -245,20 +246,20 @@ void SUB_CalcMove (entity this, vector tdest, float tspeedtype, float tspeed, vo
        float   traveltime;
 
        if (!tspeed)
-               objerror ("No speed is defined!");
+               objerror (this, "No speed is defined!");
 
        this.think1 = func;
        this.finaldest = tdest;
-       SUB_THINK(this, SUB_CalcMoveDone);
+       setthink(this, SUB_CalcMoveDone);
 
-       if (tdest == this.SUB_ORIGIN)
+       if (tdest == this.origin)
        {
-               this.SUB_VELOCITY = '0 0 0';
-               this.SUB_NEXTTHINK = this.SUB_LTIME + 0.1;
+               this.velocity = '0 0 0';
+               this.nextthink = this.ltime + 0.1;
                return;
        }
 
-       delta = tdest - this.SUB_ORIGIN;
+       delta = tdest - this.origin;
 
        switch(tspeedtype)
        {
@@ -279,54 +280,52 @@ void SUB_CalcMove (entity this, vector tdest, float tspeedtype, float tspeed, vo
         // The only currently implemented alternative movement is linear (value 1)
        if (traveltime < 0.15 || (this.platmovetype_start == 1 && this.platmovetype_end == 1)) // is this correct?
        {
-               this.SUB_VELOCITY = delta * (1/traveltime);     // QuakeC doesn't allow vector/float division
-               this.SUB_NEXTTHINK = this.SUB_LTIME + traveltime;
+               this.velocity = delta * (1/traveltime); // QuakeC doesn't allow vector/float division
+               this.nextthink = this.ltime + traveltime;
                return;
        }
 
        // now just run like a bezier curve...
-       SUB_CalcMove_Bezier(this, (this.SUB_ORIGIN + tdest) * 0.5, tdest, tspeedtype, tspeed, func);
+       SUB_CalcMove_Bezier(this, (this.origin + tdest) * 0.5, tdest, tspeedtype, tspeed, func);
 }
 
 void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeedtype, float tspeed, void(entity this) func)
 {
-       WITHSELF(ent, SUB_CalcMove(ent, tdest, tspeedtype, tspeed, func));
+       SUB_CalcMove(ent, tdest, tspeedtype, tspeed, func);
 }
 
 /*
 =============
 SUB_CalcAngleMove
 
-calculate this.SUB_AVELOCITY and this.SUB_NEXTTHINK to reach destangle from
+calculate this.avelocity and this.nextthink to reach destangle from
 this.angles rotating
 
-The calling function should make sure this.SUB_THINK is valid
+The calling function should make sure this.setthink is valid
 ===============
 */
 void SUB_CalcAngleMoveDone(entity this)
 {
        // After rotating, set angle to exact final angle
        this.angles = this.finalangle;
-       this.SUB_AVELOCITY = '0 0 0';
-       this.SUB_NEXTTHINK = -1;
-       if (this.think1)
+       this.avelocity = '0 0 0';
+       this.nextthink = -1;
+       if (this.think1 && this.think1 != SUB_CalcAngleMoveDone) // avoid endless loops
                this.think1 (this);
 }
 
 // FIXME: I fixed this function only for rotation around the main axes
 void SUB_CalcAngleMove (entity this, vector destangle, float tspeedtype, float tspeed, void(entity this) func)
 {
-       vector  delta;
-       float   traveltime;
-
        if (!tspeed)
-               objerror ("No speed is defined!");
+               objerror (this, "No speed is defined!");
 
        // take the shortest distance for the angles
        this.angles_x -= 360 * floor((this.angles_x - destangle_x) / 360 + 0.5);
        this.angles_y -= 360 * floor((this.angles_y - destangle_y) / 360 + 0.5);
        this.angles_z -= 360 * floor((this.angles_z - destangle_z) / 360 + 0.5);
-       delta = destangle - this.angles;
+       vector delta = destangle - this.angles;
+       float traveltime;
 
        switch(tspeedtype)
        {
@@ -343,20 +342,20 @@ void SUB_CalcAngleMove (entity this, vector destangle, float tspeedtype, float t
 
        this.think1 = func;
        this.finalangle = destangle;
-       SUB_THINK(this, SUB_CalcAngleMoveDone);
+       setthink(this, SUB_CalcAngleMoveDone);
 
        if (traveltime < 0.1)
        {
-               this.SUB_AVELOCITY = '0 0 0';
-               this.SUB_NEXTTHINK = this.SUB_LTIME + 0.1;
+               this.avelocity = '0 0 0';
+               this.nextthink = this.ltime + 0.1;
                return;
        }
 
-       this.SUB_AVELOCITY = delta * (1 / traveltime);
-       this.SUB_NEXTTHINK = this.SUB_LTIME + traveltime;
+       this.avelocity = delta * (1 / traveltime);
+       this.nextthink = this.ltime + traveltime;
 }
 
 void SUB_CalcAngleMoveEnt (entity ent, vector destangle, float tspeedtype, float tspeed, void(entity this) func)
 {
-       WITHSELF(ent, SUB_CalcAngleMove (ent, destangle, tspeedtype, tspeed, func));
+       SUB_CalcAngleMove (ent, destangle, tspeedtype, tspeed, func);
 }