From: Mario Date: Wed, 14 Oct 2015 00:01:16 +0000 (+1000) Subject: Clean up door key handling X-Git-Tag: xonotic-v0.8.2~1823 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=88b08ef5253cd13badcc5ec7d5dc67aa5267f286;p=xonotic%2Fxonotic-data.pk3dir.git Clean up door key handling --- 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; }; /**