]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/func/door.qc
Merge branch 'master' into TimePath/debug_draw
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / door.qc
index fed8e9fa424515b9c3aa8aa5aa3f5029e07b3529..e2d12281680c236888ecda11f3fe47e5fe4decab 100644 (file)
@@ -36,14 +36,14 @@ void door_blocked()
        )
        { // KIll Kill Kill!!
 #ifdef SVQC
-               Damage (other, self, self, 10000, DEATH_HURTTRIGGER, other.origin, '0 0 0');
+               Damage (other, self, self, 10000, DEATH_HURTTRIGGER.m_id, other.origin, '0 0 0');
 #endif
        }
        else
        {
 #ifdef SVQC
                if((self.dmg) && (other.takedamage == DAMAGE_YES))    // Shall we bite?
-                       Damage (other, self, self, self.dmg, DEATH_HURTTRIGGER, other.origin, '0 0 0');
+                       Damage (other, self, self, self.dmg, DEATH_HURTTRIGGER.m_id, other.origin, '0 0 0');
 #endif
 
                 // don't change direction for dead or dying stuff
@@ -78,7 +78,7 @@ void door_blocked()
                {
                        //gib dying stuff just to make sure
                        if((self.dmg) && (other.takedamage != DAMAGE_NO))    // Shall we bite?
-                               Damage (other, self, self, 10000, DEATH_HURTTRIGGER, other.origin, '0 0 0');
+                               Damage (other, self, self, 10000, DEATH_HURTTRIGGER.m_id, other.origin, '0 0 0');
                }
 #endif
        }
@@ -154,61 +154,56 @@ ACTIVATION FUNCTIONS
 =============================================================================
 */
 
-float door_check_keys(void)
-{SELFPARAM();
-       local entity door;
-
-
-       if (self.owner)
-               door = self.owner;
-       else
-               door = self;
+bool door_check_keys(entity door, entity player)
+{
+       if(door.owner)
+               door = door.owner;
 
        // no key needed
-       if (!door.itemkeys)
+       if(!door.itemkeys)
                return true;
 
        // this door require a key
        // only a player can have a key
-       if (!IS_PLAYER(other))
+       if(!IS_PLAYER(player))
                return false;
 
-#ifdef SVQC
-       if (item_keys_usekey(door, other))
-       {
-               // some keys were used
-               if (other.key_door_messagetime <= time)
-               {
+       int valid = (door.itemkeys & player.itemkeys);
+       door.itemkeys &= ~valid; // only some of the needed keys were given
 
-                       play2(other, SND(TALK));
-                       Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_ALSONEED, item_keys_keylist(door.itemkeys));
-                       other.key_door_messagetime = time + 2;
-               }
+       if(!door.itemkeys)
+       {
+#ifdef SVQC
+               play2(player, SND(TALK));
+               Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_DOOR_UNLOCKED);
+#endif
+               return true;
        }
-       else
+
+       if(!valid)
        {
-               // no keys were used
-               if (other.key_door_messagetime <= time)
+#ifdef SVQC
+               if(player.key_door_messagetime <= time)
                {
-                       play2(other, SND(TALK));
-                       Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_NEED, item_keys_keylist(door.itemkeys));
-
-                       other.key_door_messagetime = time + 2;
+                       play2(player, door.noise3);
+                       Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_DOOR_LOCKED_NEED, item_keys_keylist(door.itemkeys));
+                       player.key_door_messagetime = time + 2;
                }
-       }
 #endif
+               return false;
+       }
 
-       if (door.itemkeys)
-       {
+       // door needs keys the player doesn't have
 #ifdef SVQC
-               // door is now unlocked
-               play2(other, SND(TALK));
-               Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_UNLOCKED);
-#endif
-               return true;
+       if(player.key_door_messagetime <= time)
+       {
+               play2(player, door.noise3);
+               Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_DOOR_LOCKED_ALSONEED, item_keys_keylist(door.itemkeys));
+               player.key_door_messagetime = time + 2;
        }
-       else
-               return false;
+#endif
+
+       return false;
 }
 
 void door_fire()
@@ -298,6 +293,7 @@ void door_damage(entity inflictor, entity attacker, float damage, int deathtype,
        }
 }
 
+.float door_finished;
 
 /*
 ================
@@ -311,17 +307,17 @@ void door_touch()
 {SELFPARAM();
        if (!IS_PLAYER(other))
                return;
-       if (self.owner.attack_finished_single > time)
+       if (self.owner.door_finished > time)
                return;
 
-       self.owner.attack_finished_single = time + 2;
+       self.owner.door_finished = time + 2;
 
 #ifdef SVQC
        if (!(self.owner.dmg) && (self.owner.message != ""))
        {
                if (IS_CLIENT(other))
                        centerprint(other, self.owner.message);
-               play2(other, SND(TALK));
+               play2(other, self.owner.noise);
        }
 #endif
 }
@@ -331,7 +327,7 @@ void door_generic_plat_blocked()
 
        if((self.spawnflags & 8) && (other.takedamage != DAMAGE_NO)) { // KIll Kill Kill!!
 #ifdef SVQC
-               Damage (other, self, self, 10000, DEATH_HURTTRIGGER, other.origin, '0 0 0');
+               Damage (other, self, self, 10000, DEATH_HURTTRIGGER.m_id, other.origin, '0 0 0');
 #endif
        }
        else
@@ -339,7 +335,7 @@ void door_generic_plat_blocked()
 
 #ifdef SVQC
                if((self.dmg) && (other.takedamage == DAMAGE_YES))    // Shall we bite?
-                       Damage (other, self, self, self.dmg, DEATH_HURTTRIGGER, other.origin, '0 0 0');
+                       Damage (other, self, self, self.dmg, DEATH_HURTTRIGGER.m_id, other.origin, '0 0 0');
 #endif
 
                 //Dont chamge direction for dead or dying stuff
@@ -358,7 +354,7 @@ void door_generic_plat_blocked()
                {
                        //gib dying stuff just to make sure
                        if((self.dmg) && (other.takedamage != DAMAGE_NO))    // Shall we bite?
-                               Damage (other, self, self, 10000, DEATH_HURTTRIGGER, other.origin, '0 0 0');
+                               Damage (other, self, self, 10000, DEATH_HURTTRIGGER.m_id, other.origin, '0 0 0');
                }
 #endif
        }
@@ -442,14 +438,14 @@ void door_trigger_touch()
 #endif
                        return;
 
-       if (time < self.attack_finished_single)
+       if (time < self.door_finished)
                return;
 
        // check if door is locked
-       if (!door_check_keys())
+       if (!door_check_keys(self, other))
                return;
 
-       self.attack_finished_single = time + 1;
+       self.door_finished = time + 1;
 
        activator = other;
 
@@ -457,13 +453,12 @@ void door_trigger_touch()
        door_use ();
 }
 
-void spawn_field(vector fmins, vector fmaxs)
+void door_spawnfield(vector fmins, vector fmaxs)
 {SELFPARAM();
        entity  trigger;
        vector  t1 = fmins, t2 = fmaxs;
 
-       trigger = spawn();
-       trigger.classname = "doortriggerfield";
+       trigger = new(doortriggerfield);
        trigger.movetype = MOVETYPE_NONE;
        trigger.solid = SOLID_TRIGGER;
        trigger.owner = self;
@@ -533,7 +528,7 @@ void LinkDoors()
                if (self.items)
                        return;
 
-               spawn_field(self.absmin, self.absmax);
+               door_spawnfield(self.absmin, self.absmax);
 
                return;         // don't want to link this door
        }
@@ -601,7 +596,7 @@ void LinkDoors()
        if (self.items)
                return;
 
-       spawn_field(cmins, cmaxs);
+       door_spawnfield(cmins, cmaxs);
 }
 
 #ifdef SVQC
@@ -731,7 +726,7 @@ spawnfunc(func_door)
        if (self.spawnflags & SPAWNFLAGS_SILVER_KEY)
                self.itemkeys |= ITEM_KEY_BIT(1);
 
-       SetMovedir ();
+       SetMovedir(self);
 
        self.max_health = self.health;
        if (!InitMovingBrushTrigger())
@@ -739,6 +734,13 @@ spawnfunc(func_door)
        self.effects |= EF_LOWPRECISION;
        self.classname = "door";
 
+       if(self.noise == "")
+               self.noise = "misc/talk.wav";
+       if(self.noise3 == "")
+               self.noise3 = "misc/talk.wav";
+       precache_sound(self.noise);
+       precache_sound(self.noise3);
+
        self.blocked = door_blocked;
        self.use = door_use;
 
@@ -795,11 +797,11 @@ spawnfunc(func_door)
 
 #elif defined(CSQC)
 
-void door_draw()
+void door_draw(entity this)
 {
        Movetype_Physics_NoMatchServer();
 
-       trigger_draw_generic();
+       trigger_draw_generic(this);
 }
 
 void ent_door()