trigger_gravity overlap fixes
authorRudolf Polzer <divverent@alientrap.org>
Sat, 8 May 2010 18:35:52 +0000 (20:35 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Sat, 8 May 2010 18:35:52 +0000 (20:35 +0200)
qcsrc/server/g_triggers.qc

index 9c10e38..c31352e 100644 (file)
@@ -534,21 +534,34 @@ void spawnfunc_trigger_heal()
 //////////////////////////////////////////////////////////////
 
 .entity trigger_gravity_check;
+void trigger_gravity_remove(entity own)
+{
+       if(own.trigger_gravity_check.owner == own)
+       {
+               UpdateCSQCProjectile(own);
+               own.gravity = own.trigger_gravity_check.gravity;
+               remove(own.trigger_gravity_check);
+       }
+       else
+               backtrace("Removing a trigger_gravity_check with no valid owner");
+       own.trigger_gravity_check = world;
+}
 void trigger_gravity_check_think()
 {
        // This spawns when a player enters the gravity zone and checks if he left.
-       // Each frame, self.cnt is set to 2 by trigger_gravity_touch() and decreased by 1 here.
+       // Each frame, self.count is set to 2 by trigger_gravity_touch() and decreased by 1 here.
        // It the player has left the gravity trigger, this will be allowed to reach 0 and indicate that.
-       if(self.cnt <= 0)
+       if(self.count <= 0)
        {
-               UpdateCSQCProjectile(self.owner);
-               self.owner.gravity = self.gravity;
-               self.owner.trigger_gravity_check = world;
-               remove(self);
+               if(self.owner.trigger_gravity_check == self)
+                       trigger_gravity_remove(self.owner);
+               else
+                       remove(self);
+               return;
        }
        else
        {
-               self.cnt -= 1;
+               self.count -= 1;
                self.nextthink = time;
        }
 };
@@ -573,15 +586,26 @@ void trigger_gravity_touch()
        {
                if(other.trigger_gravity_check)
                {
-                       other.trigger_gravity_check.cnt = 2; // gravity one more frames...
-                       return;
+                       if(self == other.trigger_gravity_check.enemy)
+                       {
+                               // same?
+                               other.trigger_gravity_check.count = 2; // gravity one more frame...
+                               return;
+                       }
+
+                       // compare prio
+                       if(self.cnt > other.trigger_gravity_check.enemy.cnt)
+                               trigger_gravity_remove(other);
+                       else
+                               return;
                }
                other.trigger_gravity_check = spawn();
+               other.trigger_gravity_check.enemy = self;
                other.trigger_gravity_check.owner = other;
                other.trigger_gravity_check.gravity = other.gravity;
                other.trigger_gravity_check.think = trigger_gravity_check_think;
                other.trigger_gravity_check.nextthink = time;
-               other.trigger_gravity_check.cnt = 2;
+               other.trigger_gravity_check.count = 2;
                if(other.gravity)
                        g *= other.gravity;
        }