--- /dev/null
+entity music_default;
+entity music_target;
+entity music_trigger;
+
+.float state;
+
+void Net_AdvanceMusic()
+{
+ // run AFTER all the thinks!
+ entity best, e;
+ float s0;
+ best = music_default;
+ if(music_target && time < music_target.lifetime)
+ best = music_target;
+ if(music_trigger)
+ best = music_trigger;
+ for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); )
+ {
+ s0 = e.state;
+ if(e == best)
+ {
+ // increase volume
+ if(e.fade_time > 0)
+ e.state = min(1, e.state + frametime / e.fade_time);
+ else
+ e.state = 1;
+ }
+ else
+ {
+ // decrease volume
+ if(e.fade_rate > 0)
+ e.state = max(1, e.state - frametime / e.fade_rate);
+ else
+ e.state = 0;
+ }
+ if(e.state != s0)
+ sound(e, CHAN_PROJECTILE, "", e.volume * e.state, ATTN_NONE);
+ }
+ music_trigger = world;
+}
+
+void Net_TargetMusic()
+{
+ float vol, fai, fao, tim, id;
+ string noi;
+ entity e;
+
+ id = ReadShort();
+ vol = ReadByte() / 255.0;
+ fai = ReadByte() / 16.0;
+ fao = ReadByte() / 16.0;
+ tim = ReadByte();
+ noi = ReadString();
+
+ for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); )
+ {
+ if(e.count == id)
+ break;
+ }
+ if(!e)
+ {
+ e = spawn();
+ e.enttype = ENT_CLIENT_TRIGGER_MUSIC;
+ if(e.noise)
+ strunzone(e.noise);
+ e.noise = strzone(noi);
+ sound(e, CHAN_PROJECTILE, self.noise, 0, ATTN_NONE);
+ }
+ e.volume = vol;
+ e.fade_time = fai;
+ e.fade_rate = fao;
+ if(vol > 0)
+ {
+ if(tim == 0)
+ {
+ music_default = e;
+ }
+ else
+ {
+ music_target = e;
+ e.lifetime = time + tim;
+ }
+ }
+}
+
+void Ent_TriggerMusic_Think()
+{
+ if(WarpZoneLib_BoxTouchesBrush(pmove_org + pmove_mins, pmove_org + pmove_maxs, self, world))
+ music_trigger = self;
+ self.nextthink = time;
+}
+
+void Ent_TriggerMusic_Remove()
+{
+ if(self.noise)
+ strunzone(self.noise);
+ self.noise = string_null;
+}
+
+void Ent_ReadTriggerMusic()
+{
+ float f;
+ f = ReadByte();
+ if(f & 4)
+ {
+ self.origin_x = ReadCoord();
+ self.origin_y = ReadCoord();
+ self.origin_z = ReadCoord();
+ }
+ if(f & 1)
+ {
+ self.modelindex = ReadShort();
+ if(self.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();
+ }
+ else
+ {
+ self.mins = '0 0 0';
+ self.maxs_x = ReadCoord();
+ self.maxs_y = ReadCoord();
+ self.maxs_z = ReadCoord();
+ }
+
+ self.volume = ReadByte() / 255.0;
+ self.fade_time = ReadByte() / 16.0;
+ self.fade_rate = ReadByte() / 16.0;
+ if(self.noise)
+ strunzone(self.noise);
+ self.noise = strzone(ReadString());
+ }
+
+ self.cnt = 1;
+ self.think = Ent_TriggerMusic_Think;
+ self.nextthink = time;
+}
+.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, 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.timeout);
+ WriteByte(to, self.fade_rate * 16.0);
+ WriteByte(to, self.lifetime);
WriteString(to, self.noise);
}
void target_music_reset()
{
if(self.targetname == "")
- target_music_sendto(MSG_ALL);
+ target_music_sendto(MSG_ALL, 1);
}
void target_music_use()
{
if(!activator)
return;
msg_entity = activator;
- target_music_sendto(MSG_ONE);
+ 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;
if(self.targetname == "")
- target_music_sendto(MSG_INIT);
+ target_music_sendto(MSG_INIT, 1);
+ else
+ target_music_sendto(MSG_INIT, 0);
}
// values:
// volume
}
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;
{
if(self.model != "")
setmodel(self, self.model);
- precache_sound (self.noise);
if(!self.volume)
self.volume = 1;
if(!self.modelindex)