]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/target_music.qc
Merge branch 'master' into terencehill/music_player
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / target_music.qc
index 34a8ffb537f2b6930d6fb61024410a54f8631e30..cd1b374e6b247fab04cf6d8d85cfea5f67c7da6f 100644 (file)
@@ -1,37 +1,61 @@
+.float lifetime;
 // values:
 //   volume
 //   noise
 //   targetname
-//   timeout
+//   lifetime
 //   fade_time
-// when triggered, the music is overridden for activator until timeout (or forever, if timeout is 0)
+//   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)
+void target_music_sendto(float to, float is)
 {
+       WriteByte(to, SVC_TEMPENTITY);
        WriteByte(to, TE_CSQC_TARGET_MUSIC);
-       WriteByte(to, self.volume * 255.0);
+       WriteShort(to, num_for_edict(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);
 }
 void target_music_reset()
 {
-       target_music_sendto(MSG_ALL);
+       if(self.targetname == "")
+               target_music_sendto(MSG_ALL, 1);
 }
 void target_music_use()
 {
        if(!activator)
                return;
-       msg_entity = activator;
-       target_music_sendto(MSG_ONE);
+       if(IS_REAL_CLIENT(activator))
+       {
+               msg_entity = activator;
+               target_music_sendto(MSG_ONE, 1);
+       }
+       entity head;
+       FOR_EACH_SPEC(head) if(head.enemy == activator) { msg_entity = head; target_music_sendto(MSG_ONE, 1); }
 }
 void spawnfunc_target_music()
 {
        self.use = target_music_use;
        self.reset = target_music_reset;
-       precache_sound(self.noise);
        if(!self.volume)
                self.volume = 1;
-       target_music_sendto(MSG_INIT);
+       if(self.targetname == "")
+               target_music_sendto(MSG_INIT, 1);
+       else
+               target_music_sendto(MSG_INIT, 0);
+}
+void TargetMusic_RestoreGame()
+{
+       for(self = world; (self = find(self, classname, "target_music")); )
+       {
+               if(self.targetname == "")
+                       target_music_sendto(MSG_INIT, 1);
+               else
+                       target_music_sendto(MSG_INIT, 0);
+       }
 }
 // values:
 //   volume
@@ -43,8 +67,8 @@ void spawnfunc_target_music()
 // when triggered, it is disabled/enabled for everyone
 float trigger_music_SendEntity(entity to, float sf)
 {
-       WriteByte(MSG_ENTITY, TE_CSQC_TARGET_MUSIC);
-       sf &~= 0x80;
+       WriteByte(MSG_ENTITY, ENT_CLIENT_TRIGGER_MUSIC);
+       sf &= ~0x80;
        if(self.cnt)
                sf |= 0x80;
        WriteByte(MSG_ENTITY, sf);
@@ -75,6 +99,7 @@ float trigger_music_SendEntity(entity to, float sf)
                }
                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);
        }
        return 1;
@@ -93,7 +118,6 @@ void spawnfunc_trigger_music()
 {
        if(self.model != "")
                setmodel(self, self.model);
-       precache_sound (self.noise);
        if(!self.volume)
                self.volume = 1;
        if(!self.modelindex)