]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/target/music.qc
Merge branch 'terencehill/g_lms_extra_lives' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / target / music.qc
index b3a5a24330763d13152eb088cecb0dfd9ff445df..3f38914f472b9405c3ed8bae978a655531614581 100644 (file)
@@ -1,12 +1,14 @@
 #if defined(CSQC)
 #elif defined(MENUQC)
 #elif defined(SVQC)
-    #include "../../../server/_all.qh"
     #include "../../constants.qh"
     #include "../../../server/constants.qh"
     #include "../../../server/defs.qh"
 #endif
 
+REGISTER_NET_TEMP(TE_CSQC_TARGET_MUSIC)
+REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_MUSIC)
+
 #ifdef SVQC
 
 // values:
@@ -19,9 +21,8 @@
 // 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)
-{
-       WriteByte(to, SVC_TEMPENTITY);
-       WriteByte(to, TE_CSQC_TARGET_MUSIC);
+{SELFPARAM();
+       WriteHeader(to, TE_CSQC_TARGET_MUSIC);
        WriteShort(to, num_for_edict(self));
        WriteByte(to, self.volume * 255.0 * is);
        WriteByte(to, self.fade_time * 16.0);
@@ -29,10 +30,20 @@ void target_music_sendto(float to, float is)
        WriteByte(to, self.lifetime);
        WriteString(to, self.noise);
 }
-void target_music_reset()
+void target_music_reset(entity this)
 {
-       if(self.targetname == "")
-               target_music_sendto(MSG_ALL, 1);
+       if (this.targetname == "") target_music_sendto(MSG_ALL, 1);
+}
+void target_music_kill()
+{
+       for(self = world; (self = find(self, classname, "target_music")); )
+       {
+               self.volume = 0;
+               if(self.targetname == "")
+                       target_music_sendto(MSG_ALL, 1);
+               else
+                       target_music_sendto(MSG_ALL, 0);
+       }
 }
 void target_music_use()
 {
@@ -46,7 +57,7 @@ void target_music_use()
        entity head;
        FOR_EACH_SPEC(head) if(head.enemy == activator) { msg_entity = head; target_music_sendto(MSG_ONE, 1); }
 }
-void spawnfunc_target_music()
+spawnfunc(target_music)
 {
        self.use = target_music_use;
        self.reset = target_music_reset;
@@ -58,9 +69,10 @@ void spawnfunc_target_music()
                target_music_sendto(MSG_INIT, 0);
 }
 void TargetMusic_RestoreGame()
-{
-       for(self = world; (self = find(self, classname, "target_music")); )
+{SELFPARAM();
+       for(entity e = world; (e = find(e, classname, "target_music")); )
        {
+               setself(e);
                if(self.targetname == "")
                        target_music_sendto(MSG_INIT, 1);
                else
@@ -75,9 +87,9 @@ void TargetMusic_RestoreGame()
 // spawnflags:
 //   1 = START_OFF
 // when triggered, it is disabled/enabled for everyone
-float trigger_music_SendEntity(entity to, float sf)
+bool trigger_music_SendEntity(entity this, entity to, float sf)
 {
-       WriteByte(MSG_ENTITY, ENT_CLIENT_TRIGGER_MUSIC);
+       WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_MUSIC);
        sf &= ~0x80;
        if(self.cnt)
                sf |= 0x80;
@@ -114,33 +126,31 @@ float trigger_music_SendEntity(entity to, float sf)
        }
        return 1;
 }
-void trigger_music_reset()
+void trigger_music_reset(entity this)
 {
-       self.cnt = !(self.spawnflags & 1);
-       self.SendFlags |= 0x80;
+       this.cnt = !(this.spawnflags & 1);
+       this.SendFlags |= 0x80;
 }
 void trigger_music_use()
-{
+{SELFPARAM();
        self.cnt = !self.cnt;
        self.SendFlags |= 0x80;
 }
-void spawnfunc_trigger_music()
+spawnfunc(trigger_music)
 {
-       if(self.model != "")
-               setmodel(self, self.model);
-       if(!self.volume)
-               self.volume = 1;
-       if(!self.modelindex)
+       if(this.model != "") _setmodel(this, this.model);
+       if(!this.volume) this.volume = 1;
+       if(!this.modelindex)
        {
-               setorigin(self, self.origin + self.mins);
-               setsize(self, '0 0 0', self.maxs - self.mins);
+               setorigin(this, this.origin + this.mins);
+               setsize(this, '0 0 0', this.maxs - this.mins);
        }
-       trigger_music_reset();
+       trigger_music_reset(this);
 
-       self.use = trigger_music_use;
-       self.reset = trigger_music_reset;
+       this.use = trigger_music_use;
+       this.reset = trigger_music_reset;
 
-       Net_LinkEntity(self, false, 0, trigger_music_SendEntity);
+       Net_LinkEntity(this, false, 0, trigger_music_SendEntity);
 }
 #elif defined(CSQC)
 
@@ -154,7 +164,7 @@ void TargetMusic_Advance()
                best = music_target;
        if(music_trigger)
                best = music_trigger;
-       for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); ) if(e.noise)
+       for(e = world; (e = findfloat(e, enttype, NET_ENT_CLIENT_TRIGGER_MUSIC.m_id)); ) if(e.noise)
        {
                vol0 = e.lastvol;
                if(getsoundtime(e, CH_BGM_SINGLE) < 0)
@@ -181,9 +191,9 @@ void TargetMusic_Advance()
                if(vol != vol0)
                {
                        if(vol0 < 0)
-                               sound(e, CH_BGM_SINGLE, e.noise, vol, ATTEN_NONE); // restart
+                               _sound(e, CH_BGM_SINGLE, e.noise, vol, ATTEN_NONE); // restart
                        else
-                               sound(e, CH_BGM_SINGLE, "", vol, ATTEN_NONE);
+                               _sound(e, CH_BGM_SINGLE, "", vol, ATTEN_NONE);
                        e.lastvol = vol;
                }
        }
@@ -195,6 +205,12 @@ void TargetMusic_Advance()
                bgmtime = gettime(GETTIME_CDTRACK);
 }
 
+NET_HANDLE(TE_CSQC_TARGET_MUSIC, bool isNew)
+{
+       Net_TargetMusic();
+       return true;
+}
+
 void Net_TargetMusic()
 {
        int id = ReadShort();
@@ -205,7 +221,7 @@ void Net_TargetMusic()
        string noi = ReadString();
 
        entity e;
-       for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); )
+       for(e = world; (e = findfloat(e, enttype, NET_ENT_CLIENT_TRIGGER_MUSIC.m_id)); )
        {
                if(e.count == id)
                        break;
@@ -213,7 +229,7 @@ void Net_TargetMusic()
        if(!e)
        {
                e = spawn();
-               e.enttype = ENT_CLIENT_TRIGGER_MUSIC;
+               e.enttype = NET_ENT_CLIENT_TRIGGER_MUSIC.m_id;
                e.count = id;
        }
        if(e.noise != noi)
@@ -222,7 +238,7 @@ void Net_TargetMusic()
                        strunzone(e.noise);
                e.noise = strzone(noi);
                precache_sound(e.noise);
-               sound(e, CH_BGM_SINGLE, e.noise, 0, ATTEN_NONE);
+               _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);
@@ -255,7 +271,7 @@ void Net_TargetMusic()
 }
 
 void Ent_TriggerMusic_Think()
-{
+{SELFPARAM();
        if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, self, world))
        {
                music_trigger = self;
@@ -264,13 +280,13 @@ void Ent_TriggerMusic_Think()
 }
 
 void Ent_TriggerMusic_Remove()
-{
+{SELFPARAM();
        if(self.noise)
                strunzone(self.noise);
        self.noise = string_null;
 }
 
-void Ent_ReadTriggerMusic()
+NET_HANDLE(ENT_CLIENT_TRIGGER_MUSIC, bool isnew)
 {
        int f = ReadByte();
        if(f & 4)
@@ -309,7 +325,7 @@ void Ent_ReadTriggerMusic()
                if(self.noise != s)
                {
                        precache_sound(self.noise);
-                       sound(self, CH_BGM_SINGLE, self.noise, 0, ATTEN_NONE);
+                       _sound(self, CH_BGM_SINGLE, self.noise, 0, ATTEN_NONE);
                        if(getsoundtime(self, CH_BGM_SINGLE) < 0)
                        {
                                LOG_TRACEF("Cannot initialize sound %s\n", self.noise);
@@ -324,6 +340,7 @@ void Ent_ReadTriggerMusic()
        self.cnt = 1;
        self.think = Ent_TriggerMusic_Think;
        self.nextthink = time;
+       return true;
 }
 
 #endif