Merge remote branch 'origin/mirceakitsune/gravity_trigger'
authorRudolf Polzer <divVerent@alientrap.org>
Sat, 8 May 2010 12:57:34 +0000 (14:57 +0200)
committerRudolf Polzer <divVerent@alientrap.org>
Sat, 8 May 2010 12:57:34 +0000 (14:57 +0200)
qcsrc/server/g_triggers.qc

index 7868844..0bd56b0 100644 (file)
@@ -533,7 +533,79 @@ void spawnfunc_trigger_heal()
 //
 //////////////////////////////////////////////////////////////
 
+.float trigger_gravity_active;
+.entity trigger_gravity_check;
+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.
+       // It the player has left the gravity trigger, this will be allowed to reach 0 and indicate that.
+       if(self.cnt <= 0)
+       {
+               self.owner.gravity = 1;
+               self.owner.trigger_gravity_active = FALSE;
+               remove(self);
+       }
+       else
+       {
+               self.cnt -= 1;
+               self.nextthink = time;
+       }
+};
+
+void trigger_gravity_use()
+{
+       self.state = !self.state;
+};
+
+void trigger_gravity_touch()
+{
+       if(self.state != TRUE)
+               return;
+
+       EXACTTRIGGER_TOUCH;
+
+       if not(self.spawnflags & 1)
+       {
+               if(!other.trigger_gravity_active)
+               {
+                       other.trigger_gravity_active = TRUE;
+                       other.trigger_gravity_check = spawn();
+                       other.trigger_gravity_check.owner = other;
+                       other.trigger_gravity_check.think = trigger_gravity_check_think;
+                       other.trigger_gravity_check.nextthink = time;
+               }
+               other.trigger_gravity_check.cnt = 2;
+       }
+
+       if (other.gravity != self.gravity)
+       {
+               other.gravity = self.gravity;
+               if(self.noise != "")
+                       sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NORM);
+       }
+};
+
+void spawnfunc_trigger_gravity()
+{
+       if(self.gravity == 1)
+               return;
 
+       EXACTTRIGGER_INIT;
+       self.touch = trigger_gravity_touch;
+       if(self.noise != "")
+               precache_sound(self.noise);
+
+       self.state = TRUE;
+       IFTARGETED
+       {
+               self.use = trigger_gravity_use;
+               if(self.spawnflags & 2)
+                       self.state = FALSE;
+       }
+};
+
+//=============================================================================
 
 // TODO add a way to do looped sounds with sound(); then complete this entity
 .float volume, atten;