1 #include "target_music.qh"
3 void TargetMusic_Advance()
5 // run AFTER all the thinks!
9 if(music_target && time < music_target.lifetime)
13 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); ) if(e.noise)
16 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
24 e.state = bound(0, e.state + frametime / e.fade_time, 1);
32 e.state = bound(0, e.state - frametime / e.fade_rate, 1);
36 vol = e.state * e.volume * autocvar_bgmvolume;
40 sound(e, CH_BGM_SINGLE, e.noise, vol, ATTEN_NONE); // restart
42 sound(e, CH_BGM_SINGLE, "", vol, ATTEN_NONE);
46 music_trigger = world;
49 bgmtime = getsoundtime(best, CH_BGM_SINGLE);
51 bgmtime = gettime(GETTIME_CDTRACK);
54 void Net_TargetMusic()
56 float vol, fai, fao, tim, id;
61 vol = ReadByte() / 255.0;
62 fai = ReadByte() / 16.0;
63 fao = ReadByte() / 16.0;
67 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); )
75 e.enttype = ENT_CLIENT_TRIGGER_MUSIC;
82 e.noise = strzone(noi);
83 precache_sound(e.noise);
84 sound(e, CH_BGM_SINGLE, e.noise, 0, ATTEN_NONE);
85 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
87 dprintf("Cannot initialize sound %s\n", e.noise);
89 e.noise = string_null;
103 cvar_settemp("music_playlist_index", "-1"); // don't use playlists
104 localcmd("cd stop\n"); // just in case
111 e.lifetime = time + tim;
116 void Ent_TriggerMusic_Think()
118 if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, self, world))
120 music_trigger = self;
122 self.nextthink = time;
125 void Ent_TriggerMusic_Remove()
128 strunzone(self.noise);
129 self.noise = string_null;
132 void Ent_ReadTriggerMusic()
137 self.origin_x = ReadCoord();
138 self.origin_y = ReadCoord();
139 self.origin_z = ReadCoord();
143 self.modelindex = ReadShort();
146 self.mins_x = ReadCoord();
147 self.mins_y = ReadCoord();
148 self.mins_z = ReadCoord();
149 self.maxs_x = ReadCoord();
150 self.maxs_y = ReadCoord();
151 self.maxs_z = ReadCoord();
156 self.maxs_x = ReadCoord();
157 self.maxs_y = ReadCoord();
158 self.maxs_z = ReadCoord();
161 self.volume = ReadByte() / 255.0;
162 self.fade_time = ReadByte() / 16.0;
163 self.fade_rate = ReadByte() / 16.0;
164 string s = self.noise;
166 strunzone(self.noise);
167 self.noise = strzone(ReadString());
170 precache_sound(self.noise);
171 sound(self, CH_BGM_SINGLE, self.noise, 0, ATTEN_NONE);
172 if(getsoundtime(self, CH_BGM_SINGLE) < 0)
174 dprintf("Cannot initialize sound %s\n", self.noise);
175 strunzone(self.noise);
176 self.noise = string_null;
181 setorigin(self, self.origin);
182 setsize(self, self.mins, self.maxs);
184 self.think = Ent_TriggerMusic_Think;
185 self.nextthink = time;