4 #include "../../constants.qh"
5 #include "../../../server/constants.qh"
6 #include "../../../server/defs.qh"
18 // when triggered, the music is overridden for activator until lifetime (or forever, if lifetime is 0)
19 // when targetname is not set, THIS ONE is default
20 void target_music_sendto(float to, float is)
22 WriteByte(to, SVC_TEMPENTITY);
23 WriteByte(to, TE_CSQC_TARGET_MUSIC);
24 WriteShort(to, num_for_edict(self));
25 WriteByte(to, self.volume * 255.0 * is);
26 WriteByte(to, self.fade_time * 16.0);
27 WriteByte(to, self.fade_rate * 16.0);
28 WriteByte(to, self.lifetime);
29 WriteString(to, self.noise);
31 void target_music_reset()
33 if(self.targetname == "")
34 target_music_sendto(MSG_ALL, 1);
36 void target_music_kill()
38 for(self = world; (self = find(self, classname, "target_music")); )
41 if(self.targetname == "")
42 target_music_sendto(MSG_ALL, 1);
44 target_music_sendto(MSG_ALL, 0);
47 void target_music_use()
51 if(IS_REAL_CLIENT(activator))
53 msg_entity = activator;
54 target_music_sendto(MSG_ONE, 1);
57 FOR_EACH_SPEC(head) if(head.enemy == activator) { msg_entity = head; target_music_sendto(MSG_ONE, 1); }
59 spawnfunc(target_music)
61 self.use = target_music_use;
62 self.reset = target_music_reset;
65 if(self.targetname == "")
66 target_music_sendto(MSG_INIT, 1);
68 target_music_sendto(MSG_INIT, 0);
70 void TargetMusic_RestoreGame()
72 for(entity e = world; (e = find(e, classname, "target_music")); )
75 if(self.targetname == "")
76 target_music_sendto(MSG_INIT, 1);
78 target_music_sendto(MSG_INIT, 0);
88 // when triggered, it is disabled/enabled for everyone
89 bool trigger_music_SendEntity(entity this, entity to, float sf)
91 WriteByte(MSG_ENTITY, ENT_CLIENT_TRIGGER_MUSIC);
95 WriteByte(MSG_ENTITY, sf);
98 WriteCoord(MSG_ENTITY, self.origin.x);
99 WriteCoord(MSG_ENTITY, self.origin.y);
100 WriteCoord(MSG_ENTITY, self.origin.z);
104 if(self.model != "null")
106 WriteShort(MSG_ENTITY, self.modelindex);
107 WriteCoord(MSG_ENTITY, self.mins.x);
108 WriteCoord(MSG_ENTITY, self.mins.y);
109 WriteCoord(MSG_ENTITY, self.mins.z);
110 WriteCoord(MSG_ENTITY, self.maxs.x);
111 WriteCoord(MSG_ENTITY, self.maxs.y);
112 WriteCoord(MSG_ENTITY, self.maxs.z);
116 WriteShort(MSG_ENTITY, 0);
117 WriteCoord(MSG_ENTITY, self.maxs.x);
118 WriteCoord(MSG_ENTITY, self.maxs.y);
119 WriteCoord(MSG_ENTITY, self.maxs.z);
121 WriteByte(MSG_ENTITY, self.volume * 255.0);
122 WriteByte(MSG_ENTITY, self.fade_time * 16.0);
123 WriteByte(MSG_ENTITY, self.fade_rate * 16.0);
124 WriteString(MSG_ENTITY, self.noise);
128 void trigger_music_reset()
130 self.cnt = !(self.spawnflags & 1);
131 self.SendFlags |= 0x80;
133 void trigger_music_use()
135 self.cnt = !self.cnt;
136 self.SendFlags |= 0x80;
138 spawnfunc(trigger_music)
141 _setmodel(self, self.model);
146 setorigin(self, self.origin + self.mins);
147 setsize(self, '0 0 0', self.maxs - self.mins);
149 trigger_music_reset();
151 self.use = trigger_music_use;
152 self.reset = trigger_music_reset;
154 Net_LinkEntity(self, false, 0, trigger_music_SendEntity);
158 void TargetMusic_Advance()
160 // run AFTER all the thinks!
163 best = music_default;
164 if(music_target && time < music_target.lifetime)
167 best = music_trigger;
168 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); ) if(e.noise)
171 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
179 e.state = bound(0, e.state + frametime / e.fade_time, 1);
187 e.state = bound(0, e.state - frametime / e.fade_rate, 1);
191 vol = e.state * e.volume * autocvar_bgmvolume;
195 _sound(e, CH_BGM_SINGLE, e.noise, vol, ATTEN_NONE); // restart
197 _sound(e, CH_BGM_SINGLE, "", vol, ATTEN_NONE);
201 music_trigger = world;
204 bgmtime = getsoundtime(best, CH_BGM_SINGLE);
206 bgmtime = gettime(GETTIME_CDTRACK);
209 void Net_TargetMusic()
211 int id = ReadShort();
212 float vol = ReadByte() / 255.0;
213 float fai = ReadByte() / 16.0;
214 float fao = ReadByte() / 16.0;
215 float tim = ReadByte();
216 string noi = ReadString();
219 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); )
227 e.enttype = ENT_CLIENT_TRIGGER_MUSIC;
234 e.noise = strzone(noi);
235 precache_sound(e.noise);
236 _sound(e, CH_BGM_SINGLE, e.noise, 0, ATTEN_NONE);
237 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
239 LOG_TRACEF("Cannot initialize sound %s\n", e.noise);
241 e.noise = string_null;
255 cvar_settemp("music_playlist_index", "-1"); // don't use playlists
256 localcmd("cd stop\n"); // just in case
263 e.lifetime = time + tim;
268 void Ent_TriggerMusic_Think()
270 if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, self, world))
272 music_trigger = self;
274 self.nextthink = time;
277 void Ent_TriggerMusic_Remove()
280 strunzone(self.noise);
281 self.noise = string_null;
284 void Ent_ReadTriggerMusic()
289 self.origin_x = ReadCoord();
290 self.origin_y = ReadCoord();
291 self.origin_z = ReadCoord();
295 self.modelindex = ReadShort();
298 self.mins_x = ReadCoord();
299 self.mins_y = ReadCoord();
300 self.mins_z = ReadCoord();
301 self.maxs_x = ReadCoord();
302 self.maxs_y = ReadCoord();
303 self.maxs_z = ReadCoord();
308 self.maxs_x = ReadCoord();
309 self.maxs_y = ReadCoord();
310 self.maxs_z = ReadCoord();
313 self.volume = ReadByte() / 255.0;
314 self.fade_time = ReadByte() / 16.0;
315 self.fade_rate = ReadByte() / 16.0;
316 string s = self.noise;
318 strunzone(self.noise);
319 self.noise = strzone(ReadString());
322 precache_sound(self.noise);
323 _sound(self, CH_BGM_SINGLE, self.noise, 0, ATTEN_NONE);
324 if(getsoundtime(self, CH_BGM_SINGLE) < 0)
326 LOG_TRACEF("Cannot initialize sound %s\n", self.noise);
327 strunzone(self.noise);
328 self.noise = string_null;
333 setorigin(self, self.origin);
334 setsize(self, self.mins, self.maxs);
336 self.think = Ent_TriggerMusic_Think;
337 self.nextthink = time;