1 #include "target_music.qh"
3 #include "autocvars.qh"
6 #include "../common/constants.qh"
7 #include "../common/util.qh"
8 #include "../warpzonelib/common.qh"
18 void TargetMusic_Advance()
20 // run AFTER all the thinks!
24 if(music_target && time < music_target.lifetime)
28 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); ) if(e.noise)
31 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
39 e.state = bound(0, e.state + frametime / e.fade_time, 1);
47 e.state = bound(0, e.state - frametime / e.fade_rate, 1);
51 vol = e.state * e.volume * autocvar_bgmvolume;
55 sound(e, CH_BGM_SINGLE, e.noise, vol, ATTEN_NONE); // restart
57 sound(e, CH_BGM_SINGLE, "", vol, ATTEN_NONE);
61 music_trigger = world;
64 bgmtime = getsoundtime(best, CH_BGM_SINGLE);
66 bgmtime = gettime(GETTIME_CDTRACK);
69 void Net_TargetMusic()
72 float vol = ReadByte() / 255.0;
73 float fai = ReadByte() / 16.0;
74 float fao = ReadByte() / 16.0;
75 float tim = ReadByte();
76 string noi = ReadString();
79 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); )
87 e.enttype = ENT_CLIENT_TRIGGER_MUSIC;
94 e.noise = strzone(noi);
95 precache_sound(e.noise);
96 sound(e, CH_BGM_SINGLE, e.noise, 0, ATTEN_NONE);
97 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
99 dprintf("Cannot initialize sound %s\n", e.noise);
101 e.noise = string_null;
115 cvar_settemp("music_playlist_index", "-1"); // don't use playlists
116 localcmd("cd stop\n"); // just in case
123 e.lifetime = time + tim;
128 void Ent_TriggerMusic_Think()
130 if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, self, world))
132 music_trigger = self;
134 self.nextthink = time;
137 void Ent_TriggerMusic_Remove()
140 strunzone(self.noise);
141 self.noise = string_null;
144 void Ent_ReadTriggerMusic()
149 self.origin_x = ReadCoord();
150 self.origin_y = ReadCoord();
151 self.origin_z = ReadCoord();
155 self.modelindex = ReadShort();
158 self.mins_x = ReadCoord();
159 self.mins_y = ReadCoord();
160 self.mins_z = ReadCoord();
161 self.maxs_x = ReadCoord();
162 self.maxs_y = ReadCoord();
163 self.maxs_z = ReadCoord();
168 self.maxs_x = ReadCoord();
169 self.maxs_y = ReadCoord();
170 self.maxs_z = ReadCoord();
173 self.volume = ReadByte() / 255.0;
174 self.fade_time = ReadByte() / 16.0;
175 self.fade_rate = ReadByte() / 16.0;
176 string s = self.noise;
178 strunzone(self.noise);
179 self.noise = strzone(ReadString());
182 precache_sound(self.noise);
183 sound(self, CH_BGM_SINGLE, self.noise, 0, ATTEN_NONE);
184 if(getsoundtime(self, CH_BGM_SINGLE) < 0)
186 dprintf("Cannot initialize sound %s\n", self.noise);
187 strunzone(self.noise);
188 self.noise = string_null;
193 setorigin(self, self.origin);
194 setsize(self, self.mins, self.maxs);
196 self.think = Ent_TriggerMusic_Think;
197 self.nextthink = time;