+float music_disabled;
entity music_default;
entity music_target;
entity music_trigger;
.float state;
+.float lastvol;
-void Net_AdvanceMusic()
+void TargetMusic_Advance()
{
// run AFTER all the thinks!
entity best, e;
- float s0;
+ float vol, vol0;
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)); )
+ for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); ) if(e.noise)
{
- s0 = e.state;
+ vol0 = e.lastvol;
+ if(getsoundtime(e, CHAN_VOICE) < 0)
+ {
+ vol0 = -1;
+ }
if(e == best)
{
// increase volume
if(e.fade_time > 0)
- e.state = min(1, e.state + frametime / e.fade_time);
+ e.state = bound(0, e.state + frametime / e.fade_time, 1);
else
e.state = 1;
}
{
// decrease volume
if(e.fade_rate > 0)
- e.state = max(1, e.state - frametime / e.fade_rate);
+ e.state = bound(0, e.state - frametime / e.fade_rate, 1);
else
e.state = 0;
}
- if(e.state != s0)
- sound(e, CHAN_PROJECTILE, "", e.volume * e.state, ATTN_NONE);
+ vol = e.state * e.volume * cvar("bgmvolume");
+ if(vol != vol0)
+ {
+ if(vol0 < 0)
+ sound(e, CHAN_VOICE, e.noise, vol, ATTN_NONE); // restart
+ else
+ sound(e, CHAN_VOICE, "", vol, ATTN_NONE);
+ e.lastvol = vol;
+ }
}
music_trigger = world;
+
+ if(best)
+ bgmtime = getsoundtime(best, CHAN_VOICE);
+ else
+ bgmtime = gettime(GETTIME_CDTRACK);
}
void Net_TargetMusic()
{
e = spawn();
e.enttype = ENT_CLIENT_TRIGGER_MUSIC;
+ e.count = id;
+ }
+ if(e.noise != noi)
+ {
if(e.noise)
strunzone(e.noise);
e.noise = strzone(noi);
- sound(e, CHAN_PROJECTILE, self.noise, 0, ATTN_NONE);
+ precache_sound(e.noise);
+ sound(e, CHAN_VOICE, e.noise, 0, ATTN_NONE);
+ if(getsoundtime(e, CHAN_VOICE) < 0)
+ {
+ print("Cannot initialize sound ", e.noise, "\n");
+ strunzone(e.noise);
+ e.noise = string_null;
+ }
}
e.volume = vol;
e.fade_time = fai;
if(tim == 0)
{
music_default = e;
+ if(!music_disabled)
+ {
+ e.state = 2;
+ localcmd("cd stop\n"); // just in case
+ music_disabled = 1;
+ }
}
else
{
void Ent_TriggerMusic_Think()
{
- if(WarpZoneLib_BoxTouchesBrush(pmove_org + pmove_mins, pmove_org + pmove_maxs, self, world))
+ if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, self, world))
+ {
music_trigger = self;
+ }
self.nextthink = time;
}
void Ent_ReadTriggerMusic()
{
float f;
+ string s;
f = ReadByte();
if(f & 4)
{
self.volume = ReadByte() / 255.0;
self.fade_time = ReadByte() / 16.0;
self.fade_rate = ReadByte() / 16.0;
+ s = self.noise;
if(self.noise)
strunzone(self.noise);
self.noise = strzone(ReadString());
+ if(self.noise != s)
+ {
+ precache_sound(self.noise);
+ sound(self, CHAN_VOICE, self.noise, 0, ATTN_NONE);
+ if(getsoundtime(self, CHAN_VOICE) < 0)
+ {
+ print("Cannot initialize sound ", self.noise, "\n");
+ strunzone(self.noise);
+ self.noise = string_null;
+ }
+ }
}
+ setorigin(self, self.origin);
+ setsize(self, self.mins, self.maxs);
self.cnt = 1;
self.think = Ent_TriggerMusic_Think;
self.nextthink = time;