From 88b08ef5253cd13badcc5ec7d5dc67aa5267f286 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 14 Oct 2015 10:01:16 +1000 Subject: [PATCH] Clean up door key handling --- qcsrc/common/triggers/func/door.qc | 77 ++++++++++++------------ qcsrc/common/triggers/trigger/keylock.qh | 17 +----- qcsrc/server/item_key.qc | 5 +- 3 files changed, 44 insertions(+), 55 deletions(-) diff --git a/qcsrc/common/triggers/func/door.qc b/qcsrc/common/triggers/func/door.qc index 02d4f8e62..218a2ac5e 100644 --- a/qcsrc/common/triggers/func/door.qc +++ b/qcsrc/common/triggers/func/door.qc @@ -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 diff --git a/qcsrc/common/triggers/trigger/keylock.qh b/qcsrc/common/triggers/trigger/keylock.qh index b21145d42..bbec0182f 100644 --- a/qcsrc/common/triggers/trigger/keylock.qh +++ b/qcsrc/common/triggers/trigger/keylock.qh @@ -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 diff --git a/qcsrc/server/item_key.qc b/qcsrc/server/item_key.qc index 4b83a6bdb..8c5a06b32 100644 --- a/qcsrc/server/item_key.qc +++ b/qcsrc/server/item_key.qc @@ -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; }; /** -- 2.39.2