]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/trigger/keylock.qc
Merge branch 'master' into terencehill/hud_updates
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / trigger / keylock.qc
index 365c6f5a908d01a7ea8a3f7f76a51ce2545e0b70..bf20d1e9732e4dfe133ed4fc5473ae50b5021bd9 100644 (file)
@@ -1,24 +1,12 @@
+#include "keylock.qh"
 /**
  * trigger given targets
  */
-void trigger_keylock_trigger(string s)
-{SELFPARAM();
-       entity otemp = other;
-       entity atemp = activator;
-
-       entity t;
-       for(t = world; (t = find(t, targetname, s)); )
+void trigger_keylock_trigger(entity this, entity actor, string s)
+{
+       for(entity t = NULL; (t = find(t, targetname, s)); )
                if(t.use)
-               {
-                       setself(t);
-                       other = this;
-                       activator = atemp;
-                       self.use();
-               }
-
-       setself(this);
-       other = otemp;
-       activator = atemp;
+                       t.use(t, actor, this);
 }
 
 /**
@@ -27,90 +15,90 @@ void trigger_keylock_trigger(string s)
 void trigger_keylock_kill(string s)
 {
        entity t;
-       for(t = world; (t = find(t, targetname, s)); )
-               remove(t);
+       for(t = NULL; (t = find(t, targetname, s)); )
+               delete(t);
 }
 
-void trigger_keylock_touch()
-{SELFPARAM();
+void trigger_keylock_touch(entity this, entity toucher)
+{
        bool key_used = false;
        bool started_delay = false;
 
        // only player may trigger the lock
-       if(!IS_PLAYER(other))
+       if(!IS_PLAYER(toucher))
                return;
 
        // check silver key
-       if(self.itemkeys)
-               key_used = item_keys_usekey(self, other);
+       if(this.itemkeys)
+               key_used = item_keys_usekey(this, toucher);
 
-       activator = other;
-
-       if(self.itemkeys)
+       if(this.itemkeys)
        {
 #ifdef SVQC
                // at least one of the keys is missing
                if(key_used)
                {
                        // one or more keys were given, but others are still missing!
-                       play2(other, self.noise1);
-                       Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_ALSONEED, item_keys_keylist(self.itemkeys));
-                       other.key_door_messagetime = time + 2;
+                       play2(toucher, this.noise1);
+                       Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_DOOR_LOCKED_ALSONEED, item_keys_keylist(this.itemkeys));
+                       toucher.key_door_messagetime = time + 2;
                }
-               else if(other.key_door_messagetime <= time)
+               else if(toucher.key_door_messagetime <= time)
                {
                        // no keys were given
-                       play2(other, self.noise2);
-                       Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_NEED, item_keys_keylist(self.itemkeys));
-                       other.key_door_messagetime = time + 2;
+                       play2(toucher, this.noise2);
+                       Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_DOOR_LOCKED_NEED, item_keys_keylist(this.itemkeys));
+                       toucher.key_door_messagetime = time + 2;
                }
 #endif
 
                // trigger target2
-               if(self.delay <= time || started_delay == true)
-               if(self.target2)
+               if(this.delay <= time || started_delay == true)
+               if(this.target2)
                {
-                       trigger_keylock_trigger(self.target2);
+                       trigger_keylock_trigger(this, toucher, this.target2);
                        started_delay = true;
-                       self.delay = time + self.wait;
+                       this.delay = time + this.wait;
                }
        }
        else
        {
 #ifdef SVQC
                // all keys were given!
-               play2(other, self.noise);
-               centerprint(other, self.message);
+               play2(toucher, this.noise);
+               centerprint(toucher, this.message);
 #endif
 
-               if(self.target)
-                       trigger_keylock_trigger(self.target);
+               if(this.target)
+                       trigger_keylock_trigger(this, toucher, this.target);
 
-               if(self.killtarget)
-                       trigger_keylock_kill(self.killtarget);
+               if(this.killtarget)
+                       trigger_keylock_kill(this.killtarget);
 
-               remove(self);
+               delete(this);
        }
 
 }
 
+REGISTER_NET_LINKED(ENT_CLIENT_KEYLOCK)
+
 #ifdef SVQC
-bool trigger_keylock_send(entity to, int sf)
-{SELFPARAM();
-       WriteByte(MSG_ENTITY, ENT_CLIENT_KEYLOCK);
+bool trigger_keylock_send(entity this, entity to, int sf)
+{
+       WriteHeader(MSG_ENTITY, ENT_CLIENT_KEYLOCK);
 
-       WriteInt24_t(MSG_ENTITY, self.itemkeys);
-       WriteByte(MSG_ENTITY, self.height);
+       WriteInt24_t(MSG_ENTITY, this.itemkeys);
+       WriteByte(MSG_ENTITY, this.height);
 
-       trigger_common_write(true);
+       trigger_common_write(this, true);
 
        return true;
 }
 
-void trigger_keylock_link()
+void trigger_keylock_link(entity this)
 {
        // uncomment to network keylocks
-       //Net_LinkEntity(self, false, 0, trigger_keylock_send);
+       //Net_LinkEntity(this, false, 0, trigger_keylock_send);
 }
 
 /*QUAKED trigger_keylock (.0 .5 .8) ?
@@ -134,78 +122,77 @@ message2 and noise2 will be resent to the player every 2 seconds while he is in
 */
 spawnfunc(trigger_keylock)
 {
-       if(!self.itemkeys) { remove(self); return; }
+       if(!this.itemkeys) { delete(this); return; }
 
        // set unlocked message
-       if(self.message == "")
-               self.message = "Unlocked!";
+       if(this.message == "")
+               this.message = "Unlocked!";
 
        // set default unlock noise
-       if(self.noise == "")
+       if(this.noise == "")
        {
-               if(self.sounds == 1)
-                       self.noise = "misc/secret.wav";
-               else if(self.sounds == 2)
-                       self.noise = SND(TALK);
-               else //if (self.sounds == 3) {
-                       self.noise = "misc/trigger1.wav";
+               if(this.sounds == 1)
+                       this.noise = "misc/secret.wav";
+               else if(this.sounds == 2)
+                       this.noise = strzone(SND(TALK));
+               else //if (this.sounds == 3) {
+                       this.noise = "misc/trigger1.wav";
        }
 
        // set default use key sound
-       if(self.noise1 == "")
-               self.noise1 = "misc/decreasevalue.wav";
+       if(this.noise1 == "")
+               this.noise1 = "misc/decreasevalue.wav";
 
        // set closed sourd
-       if(self.noise2 == "")
-               self.noise2 = SND(TALK);
+       if(this.noise2 == "")
+               this.noise2 = SND(TALK);
 
        // delay between triggering message2 and trigger2
-       if(!self.wait) { self.wait = 5; }
+       if(!this.wait) { this.wait = 5; }
 
        // precache sounds
-       precache_sound(self.noise);
-       precache_sound(self.noise1);
-       precache_sound(self.noise2);
+       precache_sound(this.noise);
+       precache_sound(this.noise1);
+       precache_sound(this.noise2);
 
        EXACTTRIGGER_INIT;
 
-       self.touch = trigger_keylock_touch;
+       settouch(this, trigger_keylock_touch);
 
-       trigger_keylock_link();
+       trigger_keylock_link(this);
 }
 #elif defined(CSQC)
-void keylock_remove()
-{SELFPARAM();
-       if(self.target) { strunzone(self.target); }
-       self.target = string_null;
+void keylock_remove(entity this)
+{
+       if(this.target) { strunzone(this.target); }
+       this.target = string_null;
 
-       if(self.target2) { strunzone(self.target2); }
-       self.target2 = string_null;
+       if(this.target2) { strunzone(this.target2); }
+       this.target2 = string_null;
 
-       if(self.target3) { strunzone(self.target3); }
-       self.target3 = string_null;
+       if(this.target3) { strunzone(this.target3); }
+       this.target3 = string_null;
 
-       if(self.target4) { strunzone(self.target4); }
-       self.target4 = string_null;
+       if(this.target4) { strunzone(this.target4); }
+       this.target4 = string_null;
 
-       if(self.killtarget) { strunzone(self.killtarget); }
-       self.killtarget = string_null;
+       if(this.killtarget) { strunzone(this.killtarget); }
+       this.killtarget = string_null;
 
-       if(self.targetname) { strunzone(self.targetname); }
-       self.targetname = string_null;
+       if(this.targetname) { strunzone(this.targetname); }
+       this.targetname = string_null;
 }
 
-void ent_keylock()
-{SELFPARAM();
-       self.itemkeys = ReadInt24_t();
-       self.height = ReadByte();
+NET_HANDLE(ENT_CLIENT_KEYLOCK, bool isnew)
+{
+       this.itemkeys = ReadInt24_t();
+       this.height = ReadByte();
+
+       trigger_common_read(this, true);
 
-       trigger_common_read(true);
+       return = true;
 
-       self.classname = "trigger_keylock";
-       self.drawmask = MASK_NORMAL;
-       self.draw = trigger_draw_generic;
-       self.trigger_touch = trigger_keylock_touch;
-       self.entremove = keylock_remove;
+       this.classname = "trigger_keylock";
+       this.entremove = keylock_remove;
 }
 #endif