1 #include "target_music.qh"
3 #include "autocvars.qh"
7 #include "../common/constants.qh"
8 #include "../common/util.qh"
10 #include "../warpzonelib/common.qh"
20 void TargetMusic_Advance()
22 // run AFTER all the thinks!
26 if(music_target && time < music_target.lifetime)
30 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); ) if(e.noise)
33 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
41 e.state = bound(0, e.state + frametime / e.fade_time, 1);
49 e.state = bound(0, e.state - frametime / e.fade_rate, 1);
53 vol = e.state * e.volume * autocvar_bgmvolume;
57 sound(e, CH_BGM_SINGLE, e.noise, vol, ATTEN_NONE); // restart
59 sound(e, CH_BGM_SINGLE, "", vol, ATTEN_NONE);
63 music_trigger = world;
66 bgmtime = getsoundtime(best, CH_BGM_SINGLE);
68 bgmtime = gettime(GETTIME_CDTRACK);
71 void Net_TargetMusic()
74 float vol = ReadByte() / 255.0;
75 float fai = ReadByte() / 16.0;
76 float fao = ReadByte() / 16.0;
77 float tim = ReadByte();
78 string noi = ReadString();
81 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); )
89 e.enttype = ENT_CLIENT_TRIGGER_MUSIC;
96 e.noise = strzone(noi);
97 precache_sound(e.noise);
98 sound(e, CH_BGM_SINGLE, e.noise, 0, ATTEN_NONE);
99 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
101 dprintf("Cannot initialize sound %s\n", e.noise);
103 e.noise = string_null;
117 cvar_settemp("music_playlist_index", "-1"); // don't use playlists
118 localcmd("cd stop\n"); // just in case
125 e.lifetime = time + tim;
130 void Ent_TriggerMusic_Think()
132 if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, self, world))
134 music_trigger = self;
136 self.nextthink = time;
139 void Ent_TriggerMusic_Remove()
142 strunzone(self.noise);
143 self.noise = string_null;
146 void Ent_ReadTriggerMusic()
151 self.origin_x = ReadCoord();
152 self.origin_y = ReadCoord();
153 self.origin_z = ReadCoord();
157 self.modelindex = ReadShort();
160 self.mins_x = ReadCoord();
161 self.mins_y = ReadCoord();
162 self.mins_z = ReadCoord();
163 self.maxs_x = ReadCoord();
164 self.maxs_y = ReadCoord();
165 self.maxs_z = ReadCoord();
170 self.maxs_x = ReadCoord();
171 self.maxs_y = ReadCoord();
172 self.maxs_z = ReadCoord();
175 self.volume = ReadByte() / 255.0;
176 self.fade_time = ReadByte() / 16.0;
177 self.fade_rate = ReadByte() / 16.0;
178 string s = self.noise;
180 strunzone(self.noise);
181 self.noise = strzone(ReadString());
184 precache_sound(self.noise);
185 sound(self, CH_BGM_SINGLE, self.noise, 0, ATTEN_NONE);
186 if(getsoundtime(self, CH_BGM_SINGLE) < 0)
188 dprintf("Cannot initialize sound %s\n", self.noise);
189 strunzone(self.noise);
190 self.noise = string_null;
195 setorigin(self, self.origin);
196 setsize(self, self.mins, self.maxs);
198 self.think = Ent_TriggerMusic_Think;
199 self.nextthink = time;