From: Rudolf Polzer Date: Wed, 5 May 2010 18:45:45 +0000 (+0200) Subject: more target_music stuff ;) X-Git-Tag: xonotic-v0.1.0preview~640^2~22 X-Git-Url: http://git.xonotic.org/?a=commitdiff_plain;h=37b903eeaeee1fc1662556a56cdcf19881abbeeb;p=xonotic%2Fxonotic-data.pk3dir.git more target_music stuff ;) --- diff --git a/qcsrc/client/target_music.qc b/qcsrc/client/target_music.qc new file mode 100644 index 000000000..69c42ee10 --- /dev/null +++ b/qcsrc/client/target_music.qc @@ -0,0 +1,141 @@ +entity music_default; +entity music_target; +entity music_trigger; + +.float state; + +void Net_AdvanceMusic() +{ + // run AFTER all the thinks! + entity best, e; + float s0; + best = music_default; + if(music_target && time < music_target.lifetime) + best = music_target; + if(music_trigger) + best = music_trigger; + for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); ) + { + s0 = e.state; + if(e == best) + { + // increase volume + if(e.fade_time > 0) + e.state = min(1, e.state + frametime / e.fade_time); + else + e.state = 1; + } + else + { + // decrease volume + if(e.fade_rate > 0) + e.state = max(1, e.state - frametime / e.fade_rate); + else + e.state = 0; + } + if(e.state != s0) + sound(e, CHAN_PROJECTILE, "", e.volume * e.state, ATTN_NONE); + } + music_trigger = world; +} + +void Net_TargetMusic() +{ + float vol, fai, fao, tim, id; + string noi; + entity e; + + id = ReadShort(); + vol = ReadByte() / 255.0; + fai = ReadByte() / 16.0; + fao = ReadByte() / 16.0; + tim = ReadByte(); + noi = ReadString(); + + for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); ) + { + if(e.count == id) + break; + } + if(!e) + { + e = spawn(); + e.enttype = ENT_CLIENT_TRIGGER_MUSIC; + if(e.noise) + strunzone(e.noise); + e.noise = strzone(noi); + sound(e, CHAN_PROJECTILE, self.noise, 0, ATTN_NONE); + } + e.volume = vol; + e.fade_time = fai; + e.fade_rate = fao; + if(vol > 0) + { + if(tim == 0) + { + music_default = e; + } + else + { + music_target = e; + e.lifetime = time + tim; + } + } +} + +void Ent_TriggerMusic_Think() +{ + if(WarpZoneLib_BoxTouchesBrush(pmove_org + pmove_mins, pmove_org + pmove_maxs, self, world)) + music_trigger = self; + self.nextthink = time; +} + +void Ent_TriggerMusic_Remove() +{ + if(self.noise) + strunzone(self.noise); + self.noise = string_null; +} + +void Ent_ReadTriggerMusic() +{ + float f; + f = ReadByte(); + if(f & 4) + { + self.origin_x = ReadCoord(); + self.origin_y = ReadCoord(); + self.origin_z = ReadCoord(); + } + if(f & 1) + { + self.modelindex = ReadShort(); + if(self.modelindex) + { + self.mins_x = ReadCoord(); + self.mins_y = ReadCoord(); + self.mins_z = ReadCoord(); + self.maxs_x = ReadCoord(); + self.maxs_y = ReadCoord(); + self.maxs_z = ReadCoord(); + } + else + { + self.mins = '0 0 0'; + self.maxs_x = ReadCoord(); + self.maxs_y = ReadCoord(); + self.maxs_z = ReadCoord(); + } + + self.volume = ReadByte() / 255.0; + self.fade_time = ReadByte() / 16.0; + self.fade_rate = ReadByte() / 16.0; + if(self.noise) + strunzone(self.noise); + self.noise = strzone(ReadString()); + } + + self.cnt = 1; + self.think = Ent_TriggerMusic_Think; + self.nextthink = time; +} diff --git a/qcsrc/server/target_music.qc b/qcsrc/server/target_music.qc index c5b7d181e..a17cc4180 100644 --- a/qcsrc/server/target_music.qc +++ b/qcsrc/server/target_music.qc @@ -1,40 +1,45 @@ +.float lifetime; // values: // volume // noise // targetname -// timeout +// lifetime // fade_time -// when triggered, the music is overridden for activator until timeout (or forever, if timeout is 0) +// fade_rate +// when triggered, the music is overridden for activator until lifetime (or forever, if lifetime is 0) // when targetname is not set, THIS ONE is default -void target_music_sendto(float to) +void target_music_sendto(float to, float is) { WriteByte(to, TE_CSQC_TARGET_MUSIC); - WriteByte(to, self.volume * 255.0); + WriteShort(to, num_for_edict(self)); + WriteByte(to, self.volume * 255.0 * is); WriteByte(to, self.fade_time * 16.0); - WriteByte(to, self.timeout); + WriteByte(to, self.fade_rate * 16.0); + WriteByte(to, self.lifetime); WriteString(to, self.noise); } void target_music_reset() { if(self.targetname == "") - target_music_sendto(MSG_ALL); + target_music_sendto(MSG_ALL, 1); } void target_music_use() { if(!activator) return; msg_entity = activator; - target_music_sendto(MSG_ONE); + target_music_sendto(MSG_ONE, 1); } void spawnfunc_target_music() { self.use = target_music_use; self.reset = target_music_reset; - precache_sound(self.noise); if(!self.volume) self.volume = 1; if(self.targetname == "") - target_music_sendto(MSG_INIT); + target_music_sendto(MSG_INIT, 1); + else + target_music_sendto(MSG_INIT, 0); } // values: // volume @@ -78,6 +83,7 @@ float trigger_music_SendEntity(entity to, float sf) } WriteByte(MSG_ENTITY, self.volume * 255.0); WriteByte(MSG_ENTITY, self.fade_time * 16.0); + WriteByte(MSG_ENTITY, self.fade_rate * 16.0); WriteString(MSG_ENTITY, self.noise); } return 1; @@ -96,7 +102,6 @@ void spawnfunc_trigger_music() { if(self.model != "") setmodel(self, self.model); - precache_sound (self.noise); if(!self.volume) self.volume = 1; if(!self.modelindex)