]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Clean up door key handling
authorMario <mario@smbclan.net>
Wed, 14 Oct 2015 00:01:16 +0000 (10:01 +1000)
committerMario <mario@smbclan.net>
Wed, 14 Oct 2015 00:01:43 +0000 (10:01 +1000)
qcsrc/common/triggers/func/door.qc
qcsrc/common/triggers/trigger/keylock.qh
qcsrc/server/item_key.qc

index 02d4f8e62a04e7f9b657d44af693761d37c2aabe..218a2ac5e0f6b3c522dd712eac46d3792448bd68 100644 (file)
@@ -154,59 +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))
+       int valid = (door.itemkeys & player.itemkeys);
+       door.itemkeys &= ~valid; // only some of the needed keys were given
+
+       if(!door.itemkeys)
        {
-               // some keys were used
-               if (other.key_door_messagetime <= time)
-               {
-                       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;
-               }
+#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, SND(TALK));
+                       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, SND(TALK));
+               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()
@@ -444,7 +441,7 @@ void door_trigger_touch()
                return;
 
        // check if door is locked
-       if (!door_check_keys())
+       if (!door_check_keys(self, other))
                return;
 
        self.attack_finished_single = time + 1;
@@ -455,7 +452,7 @@ 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;
@@ -531,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
        }
@@ -599,7 +596,7 @@ void LinkDoors()
        if (self.items)
                return;
 
-       spawn_field(cmins, cmaxs);
+       door_spawnfield(cmins, cmaxs);
 }
 
 #ifdef SVQC
index b21145d429850370ccbae8407c9bbfdbd8ced465..bbec0182f3952130d5314ddadd372ff95e0c1482 100644 (file)
@@ -2,19 +2,8 @@
 void ent_keylock();
 bool item_keys_usekey(entity l, entity p)
 {
-       float valid = l.itemkeys & p.itemkeys;
-
-       if (!valid) {
-               // other has none of the needed keys
-               return false;
-       } else if (l.itemkeys == valid) {
-               // ALL needed keys were given
-               l.itemkeys = 0;
-               return true;
-       } else {
-               // only some of the needed keys were given
-               l.itemkeys &= ~valid;
-               return true;
-       }
+       int valid = (l.itemkeys & p.itemkeys);
+       l.itemkeys &= ~valid; // only some of the needed keys were given
+       return valid != 0;
 }
 #endif
index 4b83a6bdb2545b42fea64d0882e85245ab7005ba..8c5a06b320725657b56f0f54d4d3801c43a68adf 100644 (file)
@@ -39,7 +39,7 @@ string item_keys_keylist(float keylist) {
                return "";
 
        // one key
-       if ((keylist & (keylist-1)) != 0)
+       if ((keylist & (keylist-1)) == 0)
                return strcat("the ", item_keys_names[lowestbit(keylist)]);
 
        string n = "";
@@ -82,8 +82,11 @@ void item_key_touch()
 
        centerprint(other, self.message);
 
+       string oldmsg = self.message;
+       self.message = "";
        activator = other;
        SUB_UseTargets();
+       self.message = oldmsg;
 };
 
 /**