1 #include "target_music.qh"
4 #include "../common/constants.qh"
5 #include "../common/util.qh"
7 #include "../warpzonelib/common.qh"
17 void TargetMusic_Advance()
19 // run AFTER all the thinks!
23 if(music_target && time < music_target.lifetime)
27 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); ) if(e.noise)
30 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
38 e.state = bound(0, e.state + frametime / e.fade_time, 1);
46 e.state = bound(0, e.state - frametime / e.fade_rate, 1);
50 vol = e.state * e.volume * autocvar_bgmvolume;
54 sound(e, CH_BGM_SINGLE, e.noise, vol, ATTEN_NONE); // restart
56 sound(e, CH_BGM_SINGLE, "", vol, ATTEN_NONE);
60 music_trigger = world;
63 bgmtime = getsoundtime(best, CH_BGM_SINGLE);
65 bgmtime = gettime(GETTIME_CDTRACK);
68 void Net_TargetMusic()
71 float vol = ReadByte() / 255.0;
72 float fai = ReadByte() / 16.0;
73 float fao = ReadByte() / 16.0;
74 float tim = ReadByte();
75 string noi = ReadString();
78 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); )
86 e.enttype = ENT_CLIENT_TRIGGER_MUSIC;
93 e.noise = strzone(noi);
94 precache_sound(e.noise);
95 sound(e, CH_BGM_SINGLE, e.noise, 0, ATTEN_NONE);
96 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
98 dprintf("Cannot initialize sound %s\n", e.noise);
100 e.noise = string_null;
114 cvar_settemp("music_playlist_index", "-1"); // don't use playlists
115 localcmd("cd stop\n"); // just in case
122 e.lifetime = time + tim;
127 void Ent_TriggerMusic_Think()
129 if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, self, world))
131 music_trigger = self;
133 self.nextthink = time;
136 void Ent_TriggerMusic_Remove()
139 strunzone(self.noise);
140 self.noise = string_null;
143 void Ent_ReadTriggerMusic()
148 self.origin_x = ReadCoord();
149 self.origin_y = ReadCoord();
150 self.origin_z = ReadCoord();
154 self.modelindex = ReadShort();
157 self.mins_x = ReadCoord();
158 self.mins_y = ReadCoord();
159 self.mins_z = ReadCoord();
160 self.maxs_x = ReadCoord();
161 self.maxs_y = ReadCoord();
162 self.maxs_z = ReadCoord();
167 self.maxs_x = ReadCoord();
168 self.maxs_y = ReadCoord();
169 self.maxs_z = ReadCoord();
172 self.volume = ReadByte() / 255.0;
173 self.fade_time = ReadByte() / 16.0;
174 self.fade_rate = ReadByte() / 16.0;
175 string s = self.noise;
177 strunzone(self.noise);
178 self.noise = strzone(ReadString());
181 precache_sound(self.noise);
182 sound(self, CH_BGM_SINGLE, self.noise, 0, ATTEN_NONE);
183 if(getsoundtime(self, CH_BGM_SINGLE) < 0)
185 dprintf("Cannot initialize sound %s\n", self.noise);
186 strunzone(self.noise);
187 self.noise = string_null;
192 setorigin(self, self.origin);
193 setsize(self, self.mins, self.maxs);
195 self.think = Ent_TriggerMusic_Think;
196 self.nextthink = time;