4 #include "../../../server/_all.qh"
5 #include "../../constants.qh"
6 #include "../../../server/constants.qh"
7 #include "../../../server/defs.qh"
19 // when triggered, the music is overridden for activator until lifetime (or forever, if lifetime is 0)
20 // when targetname is not set, THIS ONE is default
21 void target_music_sendto(float to, float is)
23 WriteByte(to, SVC_TEMPENTITY);
24 WriteByte(to, TE_CSQC_TARGET_MUSIC);
25 WriteShort(to, num_for_edict(self));
26 WriteByte(to, self.volume * 255.0 * is);
27 WriteByte(to, self.fade_time * 16.0);
28 WriteByte(to, self.fade_rate * 16.0);
29 WriteByte(to, self.lifetime);
30 WriteString(to, self.noise);
32 void target_music_reset()
34 if(self.targetname == "")
35 target_music_sendto(MSG_ALL, 1);
37 void target_music_use()
41 if(IS_REAL_CLIENT(activator))
43 msg_entity = activator;
44 target_music_sendto(MSG_ONE, 1);
47 FOR_EACH_SPEC(head) if(head.enemy == activator) { msg_entity = head; target_music_sendto(MSG_ONE, 1); }
49 spawnfunc(target_music)
51 self.use = target_music_use;
52 self.reset = target_music_reset;
55 if(self.targetname == "")
56 target_music_sendto(MSG_INIT, 1);
58 target_music_sendto(MSG_INIT, 0);
60 void TargetMusic_RestoreGame()
62 for(entity e = world; (e = find(e, classname, "target_music")); )
65 if(self.targetname == "")
66 target_music_sendto(MSG_INIT, 1);
68 target_music_sendto(MSG_INIT, 0);
78 // when triggered, it is disabled/enabled for everyone
79 float trigger_music_SendEntity(entity to, float sf)
81 WriteByte(MSG_ENTITY, ENT_CLIENT_TRIGGER_MUSIC);
85 WriteByte(MSG_ENTITY, sf);
88 WriteCoord(MSG_ENTITY, self.origin.x);
89 WriteCoord(MSG_ENTITY, self.origin.y);
90 WriteCoord(MSG_ENTITY, self.origin.z);
94 if(self.model != "null")
96 WriteShort(MSG_ENTITY, self.modelindex);
97 WriteCoord(MSG_ENTITY, self.mins.x);
98 WriteCoord(MSG_ENTITY, self.mins.y);
99 WriteCoord(MSG_ENTITY, self.mins.z);
100 WriteCoord(MSG_ENTITY, self.maxs.x);
101 WriteCoord(MSG_ENTITY, self.maxs.y);
102 WriteCoord(MSG_ENTITY, self.maxs.z);
106 WriteShort(MSG_ENTITY, 0);
107 WriteCoord(MSG_ENTITY, self.maxs.x);
108 WriteCoord(MSG_ENTITY, self.maxs.y);
109 WriteCoord(MSG_ENTITY, self.maxs.z);
111 WriteByte(MSG_ENTITY, self.volume * 255.0);
112 WriteByte(MSG_ENTITY, self.fade_time * 16.0);
113 WriteByte(MSG_ENTITY, self.fade_rate * 16.0);
114 WriteString(MSG_ENTITY, self.noise);
118 void trigger_music_reset()
120 self.cnt = !(self.spawnflags & 1);
121 self.SendFlags |= 0x80;
123 void trigger_music_use()
125 self.cnt = !self.cnt;
126 self.SendFlags |= 0x80;
128 spawnfunc(trigger_music)
131 _setmodel(self, self.model);
136 setorigin(self, self.origin + self.mins);
137 setsize(self, '0 0 0', self.maxs - self.mins);
139 trigger_music_reset();
141 self.use = trigger_music_use;
142 self.reset = trigger_music_reset;
144 Net_LinkEntity(self, false, 0, trigger_music_SendEntity);
148 void TargetMusic_Advance()
150 // run AFTER all the thinks!
153 best = music_default;
154 if(music_target && time < music_target.lifetime)
157 best = music_trigger;
158 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); ) if(e.noise)
161 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
169 e.state = bound(0, e.state + frametime / e.fade_time, 1);
177 e.state = bound(0, e.state - frametime / e.fade_rate, 1);
181 vol = e.state * e.volume * autocvar_bgmvolume;
185 sound(e, CH_BGM_SINGLE, e.noise, vol, ATTEN_NONE); // restart
187 sound(e, CH_BGM_SINGLE, "", vol, ATTEN_NONE);
191 music_trigger = world;
194 bgmtime = getsoundtime(best, CH_BGM_SINGLE);
196 bgmtime = gettime(GETTIME_CDTRACK);
199 void Net_TargetMusic()
201 int id = ReadShort();
202 float vol = ReadByte() / 255.0;
203 float fai = ReadByte() / 16.0;
204 float fao = ReadByte() / 16.0;
205 float tim = ReadByte();
206 string noi = ReadString();
209 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); )
217 e.enttype = ENT_CLIENT_TRIGGER_MUSIC;
224 e.noise = strzone(noi);
225 precache_sound(e.noise);
226 sound(e, CH_BGM_SINGLE, e.noise, 0, ATTEN_NONE);
227 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
229 LOG_TRACEF("Cannot initialize sound %s\n", e.noise);
231 e.noise = string_null;
245 cvar_settemp("music_playlist_index", "-1"); // don't use playlists
246 localcmd("cd stop\n"); // just in case
253 e.lifetime = time + tim;
258 void Ent_TriggerMusic_Think()
260 if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, self, world))
262 music_trigger = self;
264 self.nextthink = time;
267 void Ent_TriggerMusic_Remove()
270 strunzone(self.noise);
271 self.noise = string_null;
274 void Ent_ReadTriggerMusic()
279 self.origin_x = ReadCoord();
280 self.origin_y = ReadCoord();
281 self.origin_z = ReadCoord();
285 self.modelindex = ReadShort();
288 self.mins_x = ReadCoord();
289 self.mins_y = ReadCoord();
290 self.mins_z = ReadCoord();
291 self.maxs_x = ReadCoord();
292 self.maxs_y = ReadCoord();
293 self.maxs_z = ReadCoord();
298 self.maxs_x = ReadCoord();
299 self.maxs_y = ReadCoord();
300 self.maxs_z = ReadCoord();
303 self.volume = ReadByte() / 255.0;
304 self.fade_time = ReadByte() / 16.0;
305 self.fade_rate = ReadByte() / 16.0;
306 string s = self.noise;
308 strunzone(self.noise);
309 self.noise = strzone(ReadString());
312 precache_sound(self.noise);
313 sound(self, CH_BGM_SINGLE, self.noise, 0, ATTEN_NONE);
314 if(getsoundtime(self, CH_BGM_SINGLE) < 0)
316 LOG_TRACEF("Cannot initialize sound %s\n", self.noise);
317 strunzone(self.noise);
318 self.noise = string_null;
323 setorigin(self, self.origin);
324 setsize(self, self.mins, self.maxs);
326 self.think = Ent_TriggerMusic_Think;
327 self.nextthink = time;