5 // FIXME also control bgmvolume here, to not require a target_music for the default track.
10 void TargetMusic_Advance()
12 // run AFTER all the thinks!
16 if(music_target && time < music_target.lifetime)
20 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); ) if(e.noise)
23 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
31 e.state = bound(0, e.state + frametime / e.fade_time, 1);
39 e.state = bound(0, e.state - frametime / e.fade_rate, 1);
43 vol = e.state * e.volume * autocvar_bgmvolume;
47 sound(e, CH_BGM_SINGLE, e.noise, vol, ATTN_NONE); // restart
49 sound(e, CH_BGM_SINGLE, "", vol, ATTN_NONE);
53 music_trigger = world;
56 bgmtime = getsoundtime(best, CH_BGM_SINGLE);
58 bgmtime = gettime(GETTIME_CDTRACK);
61 void Net_TargetMusic()
63 float vol, fai, fao, tim, id;
68 vol = ReadByte() / 255.0;
69 fai = ReadByte() / 16.0;
70 fao = ReadByte() / 16.0;
74 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); )
82 e.enttype = ENT_CLIENT_TRIGGER_MUSIC;
89 e.noise = strzone(noi);
90 precache_sound(e.noise);
91 sound(e, CH_BGM_SINGLE, e.noise, 0, ATTN_NONE);
92 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
94 print(sprintf(_("Cannot initialize sound %s\n"), e.noise));
96 e.noise = string_null;
110 cvar_settemp("music_playlist_index", "-1"); // don't use playlists
111 localcmd("cd stop\n"); // just in case
118 e.lifetime = time + tim;
123 void Ent_TriggerMusic_Think()
125 if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, self, world))
127 music_trigger = self;
129 self.nextthink = time;
132 void Ent_TriggerMusic_Remove()
135 strunzone(self.noise);
136 self.noise = string_null;
139 void Ent_ReadTriggerMusic()
146 self.origin_x = ReadCoord();
147 self.origin_y = ReadCoord();
148 self.origin_z = ReadCoord();
152 self.modelindex = ReadShort();
155 self.mins_x = ReadCoord();
156 self.mins_y = ReadCoord();
157 self.mins_z = ReadCoord();
158 self.maxs_x = ReadCoord();
159 self.maxs_y = ReadCoord();
160 self.maxs_z = ReadCoord();
165 self.maxs_x = ReadCoord();
166 self.maxs_y = ReadCoord();
167 self.maxs_z = ReadCoord();
170 self.volume = ReadByte() / 255.0;
171 self.fade_time = ReadByte() / 16.0;
172 self.fade_rate = ReadByte() / 16.0;
175 strunzone(self.noise);
176 self.noise = strzone(ReadString());
179 precache_sound(self.noise);
180 sound(self, CH_BGM_SINGLE, self.noise, 0, ATTN_NONE);
181 if(getsoundtime(self, CH_BGM_SINGLE) < 0)
183 print(sprintf(_("Cannot initialize sound %s\n"), self.noise));
184 strunzone(self.noise);
185 self.noise = string_null;
190 setorigin(self, self.origin);
191 setsize(self, self.mins, self.maxs);
193 self.think = Ent_TriggerMusic_Think;
194 self.nextthink = time;