]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
tuba: move to common
authorTimePath <andrew.hardaker1995@gmail.com>
Thu, 24 Dec 2015 09:20:35 +0000 (20:20 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Thu, 24 Dec 2015 09:20:51 +0000 (20:20 +1100)
qcsrc/client/main.qc
qcsrc/client/progs.inc
qcsrc/client/tuba.qc [deleted file]
qcsrc/client/tuba.qh [deleted file]
qcsrc/common/weapons/weapon/tuba.qc

index e436052f982d152e1638db58af17578c78e1d0b6..fad35276cda39659ed8e34c0361f4cf1f32704e4 100644 (file)
@@ -8,7 +8,6 @@
 #include "quickmenu.qh"
 #include "scoreboard.qh"
 #include "shownames.qh"
-#include "tuba.qh"
 #include "../common/t_items.qh"
 #include "wall.qh"
 #include "weapons/projectile.qh"
index fa6728d3bcc8bf65441741765d13c54e65da85c3..0f95ad580395c9d17dc16c46375cf4fcc73fbefb 100644 (file)
@@ -15,7 +15,6 @@
 #include "scoreboard.qc"
 #include "shownames.qc"
 #include "teamradar.qc"
-#include "tuba.qc"
 #include "view.qc"
 #include "wall.qc"
 
diff --git a/qcsrc/client/tuba.qc b/qcsrc/client/tuba.qc
deleted file mode 100644 (file)
index 8f8fc4d..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-#include "tuba.qh"
-
-#include "../common/constants.qh"
-
-
-#define TUBA_STARTNOTE(i, n) _Sound_fixpath(W_Sound(strcat("tuba", (i ? ftos(i) : ""), "_loopnote", ftos(n))))
-
-const int TUBA_MIN = -18;
-const int TUBA_MAX = 27;
-const int TUBA_INSTRUMENTS = 3;
-
-class(Tuba) .int note;
-class(Tuba) .bool tuba_attenuate;
-class(Tuba) .float tuba_volume;
-class(Tuba) .float tuba_volume_initial;
-class(Tuba) .int tuba_instrument;
-
-int Tuba_PitchStep;
-
-void tubasound(entity e, bool restart)
-{
-       string snd1 = string_null;
-       if (Tuba_PitchStep) {
-               float vol1 = 1;
-               float speed1 = 1;
-               string snd2 = string_null;
-               float vol2 = 0;
-               float speed2 = 1;
-
-               int m = pymod(e.note, Tuba_PitchStep);
-               if (m) {
-                       if (e.note - m < TUBA_MIN) {
-                               if (restart) {
-                                       snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
-                               }
-                               speed1 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
-                       } else if (e.note - m + Tuba_PitchStep > TUBA_MAX) {
-                               if (restart) {
-                                       snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
-                               }
-                               speed1 = pow(2.0, m / 12.0);
-                       } else {
-                               if (restart) {
-                                       snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
-                               }
-                               vol1 = cos(M_PI_2 * m / Tuba_PitchStep);
-                               speed1 = pow(2.0, m / 12.0);
-                               if (restart) {
-                                       snd2 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
-                               }
-                               vol2 = sin(M_PI_2 * m / Tuba_PitchStep);
-                               speed2 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
-                       }
-               } else if (restart) {
-                       snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
-               }
-
-               sound7(e, CH_TUBA_SINGLE, snd1, e.tuba_volume * vol1, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation, 100 * speed1, 0);
-               if (vol2) {
-                       sound7(e.enemy, CH_TUBA_SINGLE, snd2, e.tuba_volume * vol2, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation, 100 * speed2, 0);
-               }
-       } else {
-               if (restart) {
-                       snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
-               }
-               _sound(e, CH_TUBA_SINGLE, snd1, e.tuba_volume, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation);
-       }
-}
-
-void Ent_TubaNote_Think()
-{SELFPARAM();
-       float f = autocvar_g_balance_tuba_fadetime;
-       if (f > 0) {
-               self.tuba_volume -= frametime * self.tuba_volume_initial / f;
-       } else {
-               self.tuba_volume = 0;
-       }
-       self.nextthink = time;
-       if (self.tuba_volume <= 0) {
-               sound(self, CH_TUBA_SINGLE, SND_Null, 0, 0);
-               if (self.enemy) {
-                       sound(self.enemy, CH_TUBA_SINGLE, SND_Null, 0, 0);
-                       remove(self.enemy);
-               }
-               remove(self);
-       } else {
-               tubasound(self, 0);
-       }
-}
-
-void Ent_TubaNote_UpdateSound()
-{SELFPARAM();
-       self.enemy.tuba_volume = bound(0, VOL_BASE * autocvar_g_balance_tuba_volume, 1);
-       self.enemy.tuba_volume_initial = self.enemy.tuba_volume;
-       self.enemy.note = self.note;
-       self.enemy.tuba_instrument = self.tuba_instrument;
-       tubasound(self.enemy, 1);
-}
-
-void Ent_TubaNote_StopSound()
-{SELFPARAM();
-       self.enemy.nextthink = time;
-       self.enemy = world;
-}
-
-NET_HANDLE(ENT_CLIENT_TUBANOTE, bool isNew)
-{
-       bool upd = false;
-       int f = ReadByte();
-       if (f & 1) {
-               int n = ReadChar();
-               int i = ReadByte();
-               bool att = (i & 1);
-               i >>= 1;
-
-               if (self.enemy) {
-                       if (n != self.note || i != self.tuba_instrument || isNew) {
-                               Ent_TubaNote_StopSound();
-                       }
-               } else {
-                       self.enemy = new(tuba_note);
-                       if (Tuba_PitchStep) {
-                               self.enemy.enemy = new(tuba_note_2);
-                       }
-                       isNew = true;
-               }
-
-               self.enemy.tuba_attenuate = att;
-
-               if (isNew) {
-                       self.note = n;
-                       self.tuba_instrument = i;
-                       upd = true;
-               }
-       }
-
-       if (f & 2) {
-               self.enemy.origin_x = ReadCoord();
-               self.enemy.origin_y = ReadCoord();
-               self.enemy.origin_z = ReadCoord();
-               setorigin(self.enemy, self.enemy.origin);
-               if (self.enemy.enemy) {
-                       setorigin(self.enemy.enemy, self.enemy.origin);
-               }
-       }
-
-       self.think = Ent_TubaNote_StopSound;
-       self.entremove = Ent_TubaNote_StopSound;
-       self.enemy.think = Ent_TubaNote_Think;
-       self.enemy.nextthink = time + 10;
-
-       if (upd) {
-               Ent_TubaNote_UpdateSound();
-       }
-       return true;
-}
-
-PRECACHE(Tuba)
-{
-       Tuba_PitchStep = autocvar_g_balance_tuba_pitchstep;
-       if (Tuba_PitchStep) {
-               if (!checkextension("DP_SND_SOUND7_WIP2") && !checkextension("DP_SND_SOUND7")) {
-                       LOG_INFO("^1NOTE:^7 requested pitch shifting, but not supported by this engine build\n");
-                       Tuba_PitchStep = 0;
-               }
-       }
-       for (int n = TUBA_MIN; n <= TUBA_MAX; ++n) {
-               if (!Tuba_PitchStep || pymod(n, Tuba_PitchStep) == 0) {
-                       for (int i = 0; i < TUBA_INSTRUMENTS; ++i) {
-                               precache_sound(TUBA_STARTNOTE(i, n));
-                       }
-               }
-       }
-}
diff --git a/qcsrc/client/tuba.qh b/qcsrc/client/tuba.qh
deleted file mode 100644 (file)
index 0a310c3..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef CLIENT_TUBA_H
-#define CLIENT_TUBA_H
-
-entityclass(Tuba);
-
-#endif
index 084c5cff466e8fd029e55521f35deff74a8a80c1..bb750d72114bf07c6a1daa7e6492566196c85eb5 100644 (file)
@@ -54,6 +54,7 @@ REGISTER_WEAPON(TUBA, tuba, NEW(Tuba));
 .vector tuba_lastnotes[MAX_TUBANOTES];
 #endif
 #endif
+
 #ifdef IMPLEMENTATION
 #ifdef SVQC
 spawnfunc(weapon_tuba) { weapon_defaultspawnfunc(this, WEP_TUBA); }
@@ -459,5 +460,180 @@ void W_Tuba_NoteOn(float hittype)
                                return WEAPON_TUBA_MURDER;
                }
 
+#endif
+
+#ifdef CSQC
+
+#define TUBA_STARTNOTE(i, n) _Sound_fixpath(W_Sound(strcat("tuba", (i ? ftos(i) : ""), "_loopnote", ftos(n))))
+
+const int TUBA_MIN = -18;
+const int TUBA_MAX = 27;
+const int TUBA_INSTRUMENTS = 3;
+
+entityclass(Tuba);
+class(Tuba) .int note;
+class(Tuba) .bool tuba_attenuate;
+class(Tuba) .float tuba_volume;
+class(Tuba) .float tuba_volume_initial;
+class(Tuba) .int tuba_instrument;
+
+int Tuba_PitchStep;
+
+void tubasound(entity e, bool restart)
+{
+       string snd1 = string_null;
+       if (Tuba_PitchStep) {
+               float vol1 = 1;
+               float speed1 = 1;
+               string snd2 = string_null;
+               float vol2 = 0;
+               float speed2 = 1;
+
+               int m = pymod(e.note, Tuba_PitchStep);
+               if (m) {
+                       if (e.note - m < TUBA_MIN) {
+                               if (restart) {
+                                       snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
+                               }
+                               speed1 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
+                       } else if (e.note - m + Tuba_PitchStep > TUBA_MAX) {
+                               if (restart) {
+                                       snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
+                               }
+                               speed1 = pow(2.0, m / 12.0);
+                       } else {
+                               if (restart) {
+                                       snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
+                               }
+                               vol1 = cos(M_PI_2 * m / Tuba_PitchStep);
+                               speed1 = pow(2.0, m / 12.0);
+                               if (restart) {
+                                       snd2 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
+                               }
+                               vol2 = sin(M_PI_2 * m / Tuba_PitchStep);
+                               speed2 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
+                       }
+               } else if (restart) {
+                       snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
+               }
+
+               sound7(e, CH_TUBA_SINGLE, snd1, e.tuba_volume * vol1, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation, 100 * speed1, 0);
+               if (vol2) {
+                       sound7(e.enemy, CH_TUBA_SINGLE, snd2, e.tuba_volume * vol2, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation, 100 * speed2, 0);
+               }
+       } else {
+               if (restart) {
+                       snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
+               }
+               _sound(e, CH_TUBA_SINGLE, snd1, e.tuba_volume, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation);
+       }
+}
+
+void Ent_TubaNote_Think()
+{SELFPARAM();
+       float f = autocvar_g_balance_tuba_fadetime;
+       if (f > 0) {
+               self.tuba_volume -= frametime * self.tuba_volume_initial / f;
+       } else {
+               self.tuba_volume = 0;
+       }
+       self.nextthink = time;
+       if (self.tuba_volume <= 0) {
+               sound(self, CH_TUBA_SINGLE, SND_Null, 0, 0);
+               if (self.enemy) {
+                       sound(self.enemy, CH_TUBA_SINGLE, SND_Null, 0, 0);
+                       remove(self.enemy);
+               }
+               remove(self);
+       } else {
+               tubasound(self, 0);
+       }
+}
+
+void Ent_TubaNote_UpdateSound()
+{SELFPARAM();
+       self.enemy.tuba_volume = bound(0, VOL_BASE * autocvar_g_balance_tuba_volume, 1);
+       self.enemy.tuba_volume_initial = self.enemy.tuba_volume;
+       self.enemy.note = self.note;
+       self.enemy.tuba_instrument = self.tuba_instrument;
+       tubasound(self.enemy, 1);
+}
+
+void Ent_TubaNote_StopSound()
+{SELFPARAM();
+       self.enemy.nextthink = time;
+       self.enemy = world;
+}
+
+NET_HANDLE(ENT_CLIENT_TUBANOTE, bool isNew)
+{
+       bool upd = false;
+       int f = ReadByte();
+       if (f & 1) {
+               int n = ReadChar();
+               int i = ReadByte();
+               bool att = (i & 1);
+               i >>= 1;
+
+               if (self.enemy) {
+                       if (n != self.note || i != self.tuba_instrument || isNew) {
+                               Ent_TubaNote_StopSound();
+                       }
+               } else {
+                       self.enemy = new(tuba_note);
+                       if (Tuba_PitchStep) {
+                               self.enemy.enemy = new(tuba_note_2);
+                       }
+                       isNew = true;
+               }
+
+               self.enemy.tuba_attenuate = att;
+
+               if (isNew) {
+                       self.note = n;
+                       self.tuba_instrument = i;
+                       upd = true;
+               }
+       }
+
+       if (f & 2) {
+               self.enemy.origin_x = ReadCoord();
+               self.enemy.origin_y = ReadCoord();
+               self.enemy.origin_z = ReadCoord();
+               setorigin(self.enemy, self.enemy.origin);
+               if (self.enemy.enemy) {
+                       setorigin(self.enemy.enemy, self.enemy.origin);
+               }
+       }
+
+       self.think = Ent_TubaNote_StopSound;
+       self.entremove = Ent_TubaNote_StopSound;
+       self.enemy.think = Ent_TubaNote_Think;
+       self.enemy.nextthink = time + 10;
+
+       if (upd) {
+               Ent_TubaNote_UpdateSound();
+       }
+       return true;
+}
+
+PRECACHE(Tuba)
+{
+       Tuba_PitchStep = autocvar_g_balance_tuba_pitchstep;
+       if (Tuba_PitchStep) {
+               if (!checkextension("DP_SND_SOUND7_WIP2") && !checkextension("DP_SND_SOUND7")) {
+                       LOG_INFO("^1NOTE:^7 requested pitch shifting, but not supported by this engine build\n");
+                       Tuba_PitchStep = 0;
+               }
+       }
+       for (int n = TUBA_MIN; n <= TUBA_MAX; ++n) {
+               if (!Tuba_PitchStep || pymod(n, Tuba_PitchStep) == 0) {
+                       for (int i = 0; i < TUBA_INSTRUMENTS; ++i) {
+                               precache_sound(TUBA_STARTNOTE(i, n));
+                       }
+               }
+       }
+}
+
 #endif
 #endif