2 #include "../dpdefs/csprogsdefs.qc"
4 #include "../common/constants.qh"
5 #include "../warpzonelib/common.qh"
6 #include "../common/util.qh"
7 #include "autocvars.qh"
9 #include "../csqcmodellib/cl_model.qh"
18 // FIXME also control bgmvolume here, to not require a target_music for the default track.
23 void TargetMusic_Advance()
25 // run AFTER all the thinks!
29 if(music_target && time < music_target.lifetime)
33 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); ) if(e.noise)
36 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
44 e.state = bound(0, e.state + frametime / e.fade_time, 1);
52 e.state = bound(0, e.state - frametime / e.fade_rate, 1);
56 vol = e.state * e.volume * autocvar_bgmvolume;
60 sound(e, CH_BGM_SINGLE, e.noise, vol, ATTEN_NONE); // restart
62 sound(e, CH_BGM_SINGLE, "", vol, ATTEN_NONE);
66 music_trigger = world;
69 bgmtime = getsoundtime(best, CH_BGM_SINGLE);
71 bgmtime = gettime(GETTIME_CDTRACK);
74 void Net_TargetMusic()
76 float vol, fai, fao, tim, id;
81 vol = ReadByte() / 255.0;
82 fai = ReadByte() / 16.0;
83 fao = ReadByte() / 16.0;
87 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); )
95 e.enttype = ENT_CLIENT_TRIGGER_MUSIC;
102 e.noise = strzone(noi);
103 precache_sound(e.noise);
104 sound(e, CH_BGM_SINGLE, e.noise, 0, ATTEN_NONE);
105 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
107 dprintf("Cannot initialize sound %s\n", e.noise);
109 e.noise = string_null;
123 cvar_settemp("music_playlist_index", "-1"); // don't use playlists
124 localcmd("cd stop\n"); // just in case
131 e.lifetime = time + tim;
136 void Ent_TriggerMusic_Think()
138 if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, self, world))
140 music_trigger = self;
142 self.nextthink = time;
145 void Ent_TriggerMusic_Remove()
148 strunzone(self.noise);
149 self.noise = string_null;
152 void Ent_ReadTriggerMusic()
157 self.origin_x = ReadCoord();
158 self.origin_y = ReadCoord();
159 self.origin_z = ReadCoord();
163 self.modelindex = ReadShort();
166 self.mins_x = ReadCoord();
167 self.mins_y = ReadCoord();
168 self.mins_z = ReadCoord();
169 self.maxs_x = ReadCoord();
170 self.maxs_y = ReadCoord();
171 self.maxs_z = ReadCoord();
176 self.maxs_x = ReadCoord();
177 self.maxs_y = ReadCoord();
178 self.maxs_z = ReadCoord();
181 self.volume = ReadByte() / 255.0;
182 self.fade_time = ReadByte() / 16.0;
183 self.fade_rate = ReadByte() / 16.0;
184 string s = self.noise;
186 strunzone(self.noise);
187 self.noise = strzone(ReadString());
190 precache_sound(self.noise);
191 sound(self, CH_BGM_SINGLE, self.noise, 0, ATTEN_NONE);
192 if(getsoundtime(self, CH_BGM_SINGLE) < 0)
194 dprintf("Cannot initialize sound %s\n", self.noise);
195 strunzone(self.noise);
196 self.noise = string_null;
201 setorigin(self, self.origin);
202 setsize(self, self.mins, self.maxs);
204 self.think = Ent_TriggerMusic_Think;
205 self.nextthink = time;