]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/target/music.qc
Merge branch 'master' into terencehill/min_spec_time
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / target / music.qc
index c48a0ba26b351270856be3c499e156fbdbd8c2dc..7ec3351381b6265b0d24e4e16c02caa80d32fe2d 100644 (file)
@@ -1,7 +1,9 @@
+#include "music.qh"
 #if defined(CSQC)
 #elif defined(MENUQC)
 #elif defined(SVQC)
     #include <common/constants.qh>
+    #include <common/net_linked.qh>
     #include <server/constants.qh>
     #include <server/defs.qh>
 #endif
@@ -11,6 +13,9 @@ REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_MUSIC)
 
 #ifdef SVQC
 
+IntrusiveList g_targetmusic_list;
+STATIC_INIT(g_targetmusic_list) { g_targetmusic_list = IL_NEW(); }
+
 // values:
 //   volume
 //   noise
@@ -20,28 +25,29 @@ REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_MUSIC)
 //   fade_rate
 // when triggered, the music is overridden for activator until lifetime (or forever, if lifetime is 0)
 // when targetname is not set, THIS ONE is default
-void target_music_sendto(float to, float is)
-{SELFPARAM();
+void target_music_sendto(entity this, int to, bool is)
+{
        WriteHeader(to, TE_CSQC_TARGET_MUSIC);
-       WriteShort(to, etof(self));
-       WriteByte(to, self.volume * 255.0 * is);
-       WriteByte(to, self.fade_time * 16.0);
-       WriteByte(to, self.fade_rate * 16.0);
-       WriteByte(to, self.lifetime);
-       WriteString(to, self.noise);
+       WriteShort(to, etof(this));
+       WriteByte(to, this.volume * 255.0 * is);
+       WriteByte(to, this.fade_time * 16.0);
+       WriteByte(to, this.fade_rate * 16.0);
+       WriteByte(to, this.lifetime);
+       WriteString(to, this.noise);
 }
 void target_music_reset(entity this)
 {
-       if (this.targetname == "") target_music_sendto(MSG_ALL, 1);
+       if (this.targetname == "") target_music_sendto(this, MSG_ALL, 1);
 }
 void target_music_kill()
 {
-       FOREACH_ENTITY_CLASS("target_music", true, {
+       IL_EACH(g_targetmusic_list, true,
+       {
                it.volume = 0;
         if (it.targetname == "")
-            WITHSELF(it, target_music_sendto(MSG_ALL, 1));
+            target_music_sendto(it, MSG_ALL, 1);
         else
-            WITHSELF(it, target_music_sendto(MSG_ALL, 0));
+            target_music_sendto(it, MSG_ALL, 0);
        });
 }
 void target_music_use(entity this, entity actor, entity trigger)
@@ -51,34 +57,34 @@ void target_music_use(entity this, entity actor, entity trigger)
        if(IS_REAL_CLIENT(actor))
        {
                msg_entity = actor;
-               target_music_sendto(MSG_ONE, 1);
+               target_music_sendto(this, MSG_ONE, 1);
        }
        FOREACH_CLIENT(IS_SPEC(it) && it.enemy == actor, {
                msg_entity = it;
-               target_music_sendto(MSG_ONE, 1);
+               target_music_sendto(this, MSG_ONE, 1);
        });
 }
 spawnfunc(target_music)
 {
-       self.use = target_music_use;
-       self.reset = target_music_reset;
-       if(!self.volume)
-               self.volume = 1;
-       if(self.targetname == "")
-               target_music_sendto(MSG_INIT, 1);
+       this.use = target_music_use;
+       this.reset = target_music_reset;
+       if(!this.volume)
+               this.volume = 1;
+       IL_PUSH(g_targetmusic_list, this);
+       if(this.targetname == "")
+               target_music_sendto(this, MSG_INIT, 1);
        else
-               target_music_sendto(MSG_INIT, 0);
+               target_music_sendto(this, MSG_INIT, 0);
 }
 void TargetMusic_RestoreGame()
-{SELFPARAM();
-       for(entity e = world; (e = find(e, classname, "target_music")); )
+{
+       IL_EACH(g_targetmusic_list, true,
        {
-               setself(e);
-               if(self.targetname == "")
-                       target_music_sendto(MSG_INIT, 1);
+               if(it.targetname == "")
+                       target_music_sendto(it, MSG_INIT, 1);
                else
-                       target_music_sendto(MSG_INIT, 0);
-       }
+                       target_music_sendto(it, MSG_INIT, 0);
+       });
 }
 // values:
 //   volume
@@ -92,38 +98,30 @@ bool trigger_music_SendEntity(entity this, entity to, float sf)
 {
        WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_MUSIC);
        sf &= ~0x80;
-       if(self.cnt)
+       if(this.cnt)
                sf |= 0x80;
        WriteByte(MSG_ENTITY, sf);
        if(sf & 4)
        {
-               WriteCoord(MSG_ENTITY, self.origin.x);
-               WriteCoord(MSG_ENTITY, self.origin.y);
-               WriteCoord(MSG_ENTITY, self.origin.z);
+               WriteVector(MSG_ENTITY, this.origin);
        }
        if(sf & 1)
        {
-               if(self.model != "null")
+               if(this.model != "null")
                {
-                       WriteShort(MSG_ENTITY, self.modelindex);
-                       WriteCoord(MSG_ENTITY, self.mins.x);
-                       WriteCoord(MSG_ENTITY, self.mins.y);
-                       WriteCoord(MSG_ENTITY, self.mins.z);
-                       WriteCoord(MSG_ENTITY, self.maxs.x);
-                       WriteCoord(MSG_ENTITY, self.maxs.y);
-                       WriteCoord(MSG_ENTITY, self.maxs.z);
+                       WriteShort(MSG_ENTITY, this.modelindex);
+                       WriteVector(MSG_ENTITY, this.mins);
+                       WriteVector(MSG_ENTITY, this.maxs);
                }
                else
                {
                        WriteShort(MSG_ENTITY, 0);
-                       WriteCoord(MSG_ENTITY, self.maxs.x);
-                       WriteCoord(MSG_ENTITY, self.maxs.y);
-                       WriteCoord(MSG_ENTITY, self.maxs.z);
+                       WriteVector(MSG_ENTITY, this.maxs);
                }
-               WriteByte(MSG_ENTITY, self.volume * 255.0);
-               WriteByte(MSG_ENTITY, self.fade_time * 16.0);
-               WriteByte(MSG_ENTITY, self.fade_rate * 16.0);
-               WriteString(MSG_ENTITY, self.noise);
+               WriteByte(MSG_ENTITY, this.volume * 255.0);
+               WriteByte(MSG_ENTITY, this.fade_time * 16.0);
+               WriteByte(MSG_ENTITY, this.fade_rate * 16.0);
+               WriteString(MSG_ENTITY, this.noise);
        }
        return 1;
 }
@@ -189,7 +187,7 @@ void TargetMusic_Advance()
                        it.lastvol = vol;
                }
        });
-       music_trigger = world;
+       music_trigger = NULL;
        bgmtime = (best) ? getsoundtime(best, CH_BGM_SINGLE) : gettime(GETTIME_CDTRACK);
 }
 
@@ -224,7 +222,7 @@ void Net_TargetMusic()
                _sound(e, CH_BGM_SINGLE, e.noise, 0, ATTEN_NONE);
                if(getsoundtime(e, CH_BGM_SINGLE) < 0)
                {
-                       LOG_TRACEF("Cannot initialize sound %s\n", e.noise);
+                       LOG_TRACEF("Cannot initialize sound %s", e.noise);
                        strunzone(e.noise);
                        e.noise = string_null;
                }
@@ -253,20 +251,20 @@ void Net_TargetMusic()
        }
 }
 
-void Ent_TriggerMusic_Think()
-{SELFPARAM();
-       if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, self, world))
+void Ent_TriggerMusic_Think(entity this)
+{
+       if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, this, NULL))
        {
-               music_trigger = self;
+               music_trigger = this;
        }
-       self.nextthink = time;
+       this.nextthink = time;
 }
 
-void Ent_TriggerMusic_Remove()
-{SELFPARAM();
-       if(self.noise)
-               strunzone(self.noise);
-       self.noise = string_null;
+void Ent_TriggerMusic_Remove(entity this)
+{
+       if(this.noise)
+               strunzone(this.noise);
+       this.noise = string_null;
 }
 
 NET_HANDLE(ENT_CLIENT_TRIGGER_MUSIC, bool isnew)
@@ -274,55 +272,47 @@ NET_HANDLE(ENT_CLIENT_TRIGGER_MUSIC, bool isnew)
        int f = ReadByte();
        if(f & 4)
        {
-               self.origin_x = ReadCoord();
-               self.origin_y = ReadCoord();
-               self.origin_z = ReadCoord();
+               this.origin = ReadVector();
        }
        if(f & 1)
        {
-               self.modelindex = ReadShort();
-               if(self.modelindex)
+               this.modelindex = ReadShort();
+               if(this.modelindex)
                {
-                       self.mins_x = ReadCoord();
-                       self.mins_y = ReadCoord();
-                       self.mins_z = ReadCoord();
-                       self.maxs_x = ReadCoord();
-                       self.maxs_y = ReadCoord();
-                       self.maxs_z = ReadCoord();
+                       this.mins = ReadVector();
+                       this.maxs = ReadVector();
                }
                else
                {
-                       self.mins    = '0 0 0';
-                       self.maxs_x = ReadCoord();
-                       self.maxs_y = ReadCoord();
-                       self.maxs_z = ReadCoord();
+                       this.mins    = '0 0 0';
+                       this.maxs = ReadVector();
                }
 
-               self.volume = ReadByte() / 255.0;
-               self.fade_time = ReadByte() / 16.0;
-               self.fade_rate = ReadByte() / 16.0;
-               string s = self.noise;
-               if(self.noise)
-                       strunzone(self.noise);
-               self.noise = strzone(ReadString());
-               if(self.noise != s)
+               this.volume = ReadByte() / 255.0;
+               this.fade_time = ReadByte() / 16.0;
+               this.fade_rate = ReadByte() / 16.0;
+               string s = this.noise;
+               if(this.noise)
+                       strunzone(this.noise);
+               this.noise = strzone(ReadString());
+               if(this.noise != s)
                {
-                       precache_sound(self.noise);
-                       _sound(self, CH_BGM_SINGLE, self.noise, 0, ATTEN_NONE);
-                       if(getsoundtime(self, CH_BGM_SINGLE) < 0)
+                       precache_sound(this.noise);
+                       _sound(this, CH_BGM_SINGLE, this.noise, 0, ATTEN_NONE);
+                       if(getsoundtime(this, CH_BGM_SINGLE) < 0)
                        {
-                               LOG_TRACEF("Cannot initialize sound %s\n", self.noise);
-                               strunzone(self.noise);
-                               self.noise = string_null;
+                               LOG_TRACEF("Cannot initialize sound %s", this.noise);
+                               strunzone(this.noise);
+                               this.noise = string_null;
                        }
                }
        }
 
-       setorigin(self, self.origin);
-       setsize(self, self.mins, self.maxs);
-       self.cnt = 1;
-       self.think = Ent_TriggerMusic_Think;
-       self.nextthink = time;
+       setorigin(this, this.origin);
+       setsize(this, this.mins, this.maxs);
+       this.cnt = 1;
+       setthink(this, Ent_TriggerMusic_Think);
+       this.nextthink = time;
        return true;
 }