]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/target/music.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / target / music.qc
index 0fde9e043904d00f4093fe74bcc45a9ce0a74b52..7742357a0d48d8fbc1402cc6e9e6f82a312a72c0 100644 (file)
@@ -2,9 +2,10 @@
 #if defined(CSQC)
 #elif defined(MENUQC)
 #elif defined(SVQC)
-    #include <common/constants.qh>
-    #include <server/constants.qh>
-    #include <server/defs.qh>
+#include <common/constants.qh>
+#include <common/net_linked.qh>
+#include <server/constants.qh>
+#include <server/defs.qh>
 #endif
 
 REGISTER_NET_TEMP(TE_CSQC_TARGET_MUSIC)
@@ -13,7 +14,10 @@ REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_MUSIC)
 #ifdef SVQC
 
 IntrusiveList g_targetmusic_list;
-STATIC_INIT(g_targetmusic_list) { g_targetmusic_list = IL_NEW(); }
+STATIC_INIT(g_targetmusic_list)
+{
+       g_targetmusic_list = IL_NEW();
+}
 
 // values:
 //   volume
@@ -36,25 +40,26 @@ void target_music_sendto(entity this, int to, bool is)
 }
 void target_music_reset(entity this)
 {
-       if (this.targetname == "") target_music_sendto(this, MSG_ALL, 1);
+       if (this.targetname == "") { target_music_sendto(this, MSG_ALL, 1); }
 }
 void target_music_kill()
 {
        IL_EACH(g_targetmusic_list, true,
        {
                it.volume = 0;
-        if (it.targetname == "")
-            target_music_sendto(it, MSG_ALL, 1);
-        else
-            target_music_sendto(it, MSG_ALL, 0);
+               if (it.targetname == "") {
+                       target_music_sendto(it, MSG_ALL, 1);
+               } else {
+                       target_music_sendto(it, MSG_ALL, 0);
+               }
        });
 }
 void target_music_use(entity this, entity actor, entity trigger)
 {
-       if(!actor)
+       if (!actor) {
                return;
-       if(IS_REAL_CLIENT(actor))
-       {
+       }
+       if (IS_REAL_CLIENT(actor)) {
                msg_entity = actor;
                target_music_sendto(this, MSG_ONE, 1);
        }
@@ -67,22 +72,25 @@ spawnfunc(target_music)
 {
        this.use = target_music_use;
        this.reset = target_music_reset;
-       if(!this.volume)
+       if (!this.volume) {
                this.volume = 1;
+       }
        IL_PUSH(g_targetmusic_list, this);
-       if(this.targetname == "")
+       if (this.targetname == "") {
                target_music_sendto(this, MSG_INIT, 1);
-       else
+       } else {
                target_music_sendto(this, MSG_INIT, 0);
+       }
 }
 void TargetMusic_RestoreGame()
 {
        IL_EACH(g_targetmusic_list, true,
        {
-               if(it.targetname == "")
+               if (it.targetname == "") {
                        target_music_sendto(it, MSG_INIT, 1);
-               else
+               } else {
                        target_music_sendto(it, MSG_INIT, 0);
+               }
        });
 }
 // values:
@@ -97,19 +105,17 @@ bool trigger_music_SendEntity(entity this, entity to, float sf)
 {
        WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_MUSIC);
        sf &= ~0x80;
-       if(this.cnt)
+       if (this.cnt) {
                sf |= 0x80;
+       }
        WriteByte(MSG_ENTITY, sf);
-       if(sf & 4)
-       {
+       if (sf & 4) {
                WriteCoord(MSG_ENTITY, this.origin.x);
                WriteCoord(MSG_ENTITY, this.origin.y);
                WriteCoord(MSG_ENTITY, this.origin.z);
        }
-       if(sf & 1)
-       {
-               if(this.model != "null")
-               {
+       if (sf & 1) {
+               if (this.model != "null") {
                        WriteShort(MSG_ENTITY, this.modelindex);
                        WriteCoord(MSG_ENTITY, this.mins.x);
                        WriteCoord(MSG_ENTITY, this.mins.y);
@@ -117,9 +123,7 @@ bool trigger_music_SendEntity(entity this, entity to, float sf)
                        WriteCoord(MSG_ENTITY, this.maxs.x);
                        WriteCoord(MSG_ENTITY, this.maxs.y);
                        WriteCoord(MSG_ENTITY, this.maxs.z);
-               }
-               else
-               {
+               } else {
                        WriteShort(MSG_ENTITY, 0);
                        WriteCoord(MSG_ENTITY, this.maxs.x);
                        WriteCoord(MSG_ENTITY, this.maxs.y);
@@ -144,10 +148,9 @@ void trigger_music_use(entity this, entity actor, entity trigger)
 }
 spawnfunc(trigger_music)
 {
-       if(this.model != "") _setmodel(this, this.model);
-       if(!this.volume) this.volume = 1;
-       if(!this.modelindex)
-       {
+       if (this.model != "") { _setmodel(this, this.model); }
+       if (!this.volume) { this.volume = 1; }
+       if (!this.modelindex) {
                setorigin(this, this.origin + this.mins);
                setsize(this, '0 0 0', this.maxs - this.mins);
        }
@@ -170,27 +173,24 @@ void TargetMusic_Advance()
 {
        // run AFTER all the thinks!
        entity best = music_default;
-       if (music_target && time < music_target.lifetime) best = music_target;
-       if (music_trigger) best = music_trigger;
+       if (music_target && time < music_target.lifetime) { best = music_target; }
+       if (music_trigger) { best = music_trigger; }
        LL_EACH(TargetMusic_list, it.noise, {
                const float vol0 = (getsoundtime(it, CH_BGM_SINGLE) >= 0) ? it.lastvol : -1;
-               if (it == best)
-               {
-                       // increase volume
+               if (it == best) {
+                   // increase volume
                        it.state = (it.fade_time > 0) ? bound(0, it.state + frametime / it.fade_time, 1) : 1;
-               }
-               else
-               {
-                       // decrease volume
+               } else {
+                   // decrease volume
                        it.state = (it.fade_rate > 0) ? bound(0, it.state - frametime / it.fade_rate, 1) : 0;
                }
                const float vol = it.state * it.volume * autocvar_bgmvolume;
-               if (vol != vol0)
-               {
-                       if(vol0 < 0)
+               if (vol != vol0) {
+                       if (vol0 < 0) {
                                _sound(it, CH_BGM_SINGLE, it.noise, vol, ATTEN_NONE); // restart
-                       else
+                       } else {
                                _sound(it, CH_BGM_SINGLE, "", vol, ATTEN_NONE);
+                       }
                        it.lastvol = vol;
                }
        });
@@ -214,21 +214,21 @@ void Net_TargetMusic()
        const string noi = ReadString();
 
        entity e = NULL;
-       LL_EACH(TargetMusic_list, it.count == id, { e = it; break; });
-       if (!e)
-       {
+       LL_EACH(TargetMusic_list, it.count == id, { e = it;
+                                                                                               break;
+               });
+       if (!e) {
                LL_PUSH(TargetMusic_list, e = new_pure(TargetMusic));
                e.count = id;
        }
-       if(e.noise != noi)
-       {
-               if(e.noise)
+       if (e.noise != noi) {
+               if (e.noise) {
                        strunzone(e.noise);
+               }
                e.noise = strzone(noi);
                precache_sound(e.noise);
                _sound(e, CH_BGM_SINGLE, e.noise, 0, ATTEN_NONE);
-               if(getsoundtime(e, CH_BGM_SINGLE) < 0)
-               {
+               if (getsoundtime(e, CH_BGM_SINGLE) < 0) {
                        LOG_TRACEF("Cannot initialize sound %s", e.noise);
                        strunzone(e.noise);
                        e.noise = string_null;
@@ -237,21 +237,16 @@ void Net_TargetMusic()
        e.volume = vol;
        e.fade_time = fai;
        e.fade_rate = fao;
-       if(vol > 0)
-       {
-               if(tim == 0)
-               {
+       if (vol > 0) {
+               if (tim == 0) {
                        music_default = e;
-                       if(!music_disabled)
-                       {
+                       if (!music_disabled) {
                                e.state = 2;
                                cvar_settemp("music_playlist_index", "-1"); // don't use playlists
-                               localcmd("cd stop\n"); // just in case
+                               localcmd("cd stop\n");                      // just in case
                                music_disabled = 1;
                        }
-               }
-               else
-               {
+               } else {
                        music_target = e;
                        e.lifetime = time + tim;
                }
@@ -260,8 +255,7 @@ void Net_TargetMusic()
 
 void Ent_TriggerMusic_Think(entity this)
 {
-       if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, this, NULL))
-       {
+       if (WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, this, NULL)) {
                music_trigger = this;
        }
        this.nextthink = time;
@@ -269,34 +263,30 @@ void Ent_TriggerMusic_Think(entity this)
 
 void Ent_TriggerMusic_Remove(entity this)
 {
-       if(this.noise)
+       if (this.noise) {
                strunzone(this.noise);
+       }
        this.noise = string_null;
 }
 
 NET_HANDLE(ENT_CLIENT_TRIGGER_MUSIC, bool isnew)
 {
        int f = ReadByte();
-       if(f & 4)
-       {
+       if (f & 4) {
                this.origin_x = ReadCoord();
                this.origin_y = ReadCoord();
                this.origin_z = ReadCoord();
        }
-       if(f & 1)
-       {
+       if (f & 1) {
                this.modelindex = ReadShort();
-               if(this.modelindex)
-               {
+               if (this.modelindex) {
                        this.mins_x = ReadCoord();
                        this.mins_y = ReadCoord();
                        this.mins_z = ReadCoord();
                        this.maxs_x = ReadCoord();
                        this.maxs_y = ReadCoord();
                        this.maxs_z = ReadCoord();
-               }
-               else
-               {
+               } else {
                        this.mins    = '0 0 0';
                        this.maxs_x = ReadCoord();
                        this.maxs_y = ReadCoord();
@@ -307,15 +297,14 @@ NET_HANDLE(ENT_CLIENT_TRIGGER_MUSIC, bool isnew)
                this.fade_time = ReadByte() / 16.0;
                this.fade_rate = ReadByte() / 16.0;
                string s = this.noise;
-               if(this.noise)
+               if (this.noise) {
                        strunzone(this.noise);
+               }
                this.noise = strzone(ReadString());
-               if(this.noise != s)
-               {
+               if (this.noise != s) {
                        precache_sound(this.noise);
                        _sound(this, CH_BGM_SINGLE, this.noise, 0, ATTEN_NONE);
-                       if(getsoundtime(this, CH_BGM_SINGLE) < 0)
-                       {
+                       if (getsoundtime(this, CH_BGM_SINGLE) < 0) {
                                LOG_TRACEF("Cannot initialize sound %s", this.noise);
                                strunzone(this.noise);
                                this.noise = string_null;