]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/t_plats.qc
Merge commit '6f440770dbdb' into atheros/item_keys
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / t_plats.qc
index 9ac9df289243bd36ba3028cec515d4f5394117cb..f116e74a1cebf880cf86c1bfd72eae9c09b2ea1b 100644 (file)
@@ -885,6 +885,7 @@ void door_go_up()
 }
 
 
+
 /*
 =============================================================================
 
@@ -893,6 +894,58 @@ ACTIVATION FUNCTIONS
 =============================================================================
 */
 
+float door_check_keys(void) {
+       local entity door;
+       
+       
+       if (self.owner)
+               door = self.owner;
+       else
+               door = self;
+       
+       if (door.spawnflags & (SPAWNFLAGS_GOLD_KEY | SPAWNFLAGS_SILVER_KEY)) {
+               // this door require a key
+               // only a player can have a key
+               if (other.classname != "player")
+                       return FALSE;
+               
+               // check gold key
+               if (self.owner.spawnflags & SPAWNFLAGS_GOLD_KEY) {
+                       if (!(other.itemkeys & KEYS_GOLD_KEY)) {
+                               if (other.key_door_messagetime <= time) {
+                                       play2(other, "misc/talk.wav");
+                                       centerprint(other, "You don't have the gold key!");
+                                       other.key_door_messagetime = time + 2;
+                               }
+                               return FALSE;
+                       } else {
+                               self.owner.spawnflags &~= SPAWNFLAGS_GOLD_KEY;
+                       }
+               }
+                       
+               // check silver key
+               if (self.owner.spawnflags & SPAWNFLAGS_SILVER_KEY) {
+                       if (!(other.itemkeys & KEYS_SILVER_KEY)) {
+                               if (other.key_door_messagetime <= time) {
+                                       play2(other, "misc/talk.wav");
+                                       centerprint(other, "You don't have the silver key!");
+                                       other.key_door_messagetime = time + 2;
+                               }
+                               return FALSE;
+                       } else {
+                               self.owner.spawnflags &~= SPAWNFLAGS_SILVER_KEY;
+                       }
+               }
+               
+               // door is now unlocked
+               play2(other, "misc/talk.wav");
+               centerprint(other, "Door unlocked!");
+       }
+       
+       return TRUE;
+}
+
+
 void door_fire()
 {
        entity  oself;
@@ -958,6 +1011,7 @@ void door_use()
        entity oself;
 
        //dprint("door_use (model: ");dprint(self.model);dprint(")\n");
+       
        if (self.owner)
        {
                oself = self;
@@ -971,11 +1025,16 @@ void door_use()
 void door_trigger_touch()
 {
        if (other.health < 1)
-       if not(other.iscreature && other.deadflag == DEAD_NO)
-               return;
+               if not(other.iscreature && other.deadflag == DEAD_NO)
+                       return;
 
        if (time < self.attack_finished_single)
                return;
+       
+       // check if door is locked
+       if (!door_check_keys())
+               return;
+       
        self.attack_finished_single = time + 1;
 
        activator = other;
@@ -992,6 +1051,12 @@ void door_damage(entity inflictor, entity attacker, float damage, float deathtyp
                if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
                        return;
        self.health = self.health - damage;
+       
+       if (self.spawnflags & SPAWNFLAGS_GOLD_KEY || self.spawnflags & SPAWNFLAGS_SILVER_KEY) {
+               // don't allow opening doors through damage if keys are required
+               return;
+       }
+       
        if (self.health <= 0)
        {
                oself = self;
@@ -1271,13 +1336,17 @@ void LinkDoors()
 }
 
 
-/*QUAKED spawnfunc_func_door (0 .5 .8) ? START_OPEN x DOOR_DONT_LINK x x TOGGLE
+/*QUAKED spawnfunc_func_door (0 .5 .8) ? START_OPEN x DOOR_DONT_LINK GOLD_KEY SILVER_KEY TOGGLE
 if two doors touch, they are assumed to be connected and operate as a unit.
 
 TOGGLE causes the door to wait in both the start and end states for a trigger event.
 
 START_OPEN causes the door to move to its destination when spawned, and operate in reverse.  It is used to temporarily or permanently close off an area when triggered (not useful for touch or takedamage doors).
 
+GOLD_KEY causes the door to open only if the activator holds a gold key.
+
+SILVER_KEY causes the door to open only if the activator holds a silver key.
+
 "message"      is printed when the door is touched if it is a trigger door and it hasn't been fired yet
 "angle"                determines the opening direction
 "targetname" if set, no touch field will be spawned and a remote button or trigger field activates the door.
@@ -1313,6 +1382,10 @@ void door_reset()
 
 void spawnfunc_func_door()
 {
+       //dprint("spawnfunc_func_door() spawnflags=", ftos(self.spawnflags));
+       //dprint(", gold_key=", ftos(self.spawnflags & SPAWNFLAGS_GOLD_KEY));
+       //dprint(", silver_key=", ftos(self.spawnflags & SPAWNFLAGS_SILVER_KEY), "\n");
+
        //if (!self.deathtype) // map makers can override this
        //      self.deathtype = " got in the way";
        SetMovedir ();
@@ -1326,8 +1399,9 @@ void spawnfunc_func_door()
        self.blocked = door_blocked;
        self.use = door_use;
 
-    if(self.spawnflags & 8)
-        self.dmg = 10000;
+       // FIXME: undocumented flag 8, originally (Q1) GOLD_KEY
+       // if(self.spawnflags & 8)
+       //      self.dmg = 10000;
 
     if(self.dmg && (!self.message))
                self.message = "was squished";