]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/trigger/multi.qc
Properly support team field on trigger_multiple
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / trigger / multi.qc
index 5edf1dfa542966323582053311fe839568d7b7f1..2f32e50fa50b92d8396a72293df0022c07413420 100644 (file)
@@ -1,9 +1,10 @@
+#include "multi.qh"
 // NOTE: also contains trigger_once at bottom
 
 #ifdef SVQC
 // the wait time has passed, so set back up for another activation
-void multi_wait()
-{SELFPARAM();
+void multi_wait(entity this)
+{
        if (this.max_health)
        {
                this.health = this.max_health;
@@ -45,16 +46,16 @@ void multi_trigger(entity this)
 
        if (this.wait > 0)
        {
-               this.think = multi_wait;
+               setthink(this, multi_wait);
                this.nextthink = time + this.wait;
        }
        else if (this.wait == 0)
        {
-               WITHSELF(this, multi_wait()); // waiting finished
+               multi_wait(this); // waiting finished
        }
        else
-       {       // we can't just remove (this) here, because this is a touch function
-               // called wheil C code is looping through area links...
+       {       // we can't just delete(this) here, because this is a touch function
+               // called while C code is looping through area links...
                settouch(this, func_null);
        }
 }
@@ -66,35 +67,34 @@ void multi_use(entity this, entity actor, entity trigger)
        multi_trigger(this);
 }
 
-void multi_touch()
-{SELFPARAM();
-       if(!(self.spawnflags & 2))
-       if(!other.iscreature)
+void multi_touch(entity this, entity toucher)
+{
+       if(!(this.spawnflags & 2))
+       if(!toucher.iscreature)
                        return;
 
-       if(self.team)
-               if(((self.spawnflags & 4) == 0) == (self.team != other.team))
+       if(this.team)
+               if(((this.spawnflags & 4) == 0) == (this.team != toucher.team))
                        return;
 
 // if the trigger has an angles field, check player's facing direction
-       if (self.movedir != '0 0 0')
+       if (this.movedir != '0 0 0')
        {
-               makevectors (other.angles);
-               if (v_forward * self.movedir < 0)
+               makevectors (toucher.angles);
+               if (v_forward * this.movedir < 0)
                        return;         // not facing the right way
        }
 
        // if the trigger has pressed keys, check that the player is pressing those keys
-       if(self.pressedkeys)
-       if(IS_PLAYER(other)) // only for players
-       if(!(other.pressedkeys & self.pressedkeys))
+       if(this.pressedkeys && IS_PLAYER(toucher)) // only for players
+       if(!(CS(toucher).pressedkeys & this.pressedkeys))
                return;
 
-       EXACTTRIGGER_TOUCH;
+       EXACTTRIGGER_TOUCH(this, toucher);
 
-       self.enemy = other;
-       self.goalentity = other;
-       multi_trigger(self);
+       this.enemy = toucher;
+       this.goalentity = toucher;
+       multi_trigger(this);
 }
 
 void multi_eventdamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
@@ -104,6 +104,9 @@ void multi_eventdamage(entity this, entity inflictor, entity attacker, float dam
        if(this.spawnflags & DOOR_NOSPLASH)
                if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
                        return;
+       if(this.team)
+               if(((this.spawnflags & 4) == 0) == (this.team != attacker.team))
+                       return;
        this.health = this.health - damage;
        if (this.health <= 0)
        {
@@ -123,7 +126,7 @@ void multi_reset(entity this)
                this.takedamage = DAMAGE_YES;
                this.solid = SOLID_BBOX;
        }
-       this.think = func_null;
+       setthink(this, func_null);
        this.nextthink = 0;
        this.team = this.team_saved;
 }
@@ -163,23 +166,25 @@ spawnfunc(trigger_multiple)
        EXACTTRIGGER_INIT;
 
        this.team_saved = this.team;
+       IL_PUSH(g_saved_team, this);
 
        if (this.health)
        {
                if (this.spawnflags & SPAWNFLAG_NOTOUCH)
-                       objerror ("health and notouch don't make sense\n");
+                       objerror (this, "health and notouch don't make sense\n");
+               this.canteamdamage = true;
                this.max_health = this.health;
                this.event_damage = multi_eventdamage;
                this.takedamage = DAMAGE_YES;
                this.solid = SOLID_BBOX;
-               setorigin (this, this.origin);  // make sure it links into the world
+               setorigin(this, this.origin);   // make sure it links into the world
        }
        else
        {
                if ( !(this.spawnflags & SPAWNFLAG_NOTOUCH) )
                {
                        settouch(this, multi_touch);
-                       setorigin (this, this.origin);  // make sure it links into the world
+                       setorigin(this, this.origin);   // make sure it links into the world
                }
        }
 }