2 #include "../dpdefs/csprogsdefs.qc"
3 #include "../common/constants.qh"
4 #include "../warpzonelib/mathlib.qh"
5 #include "../common/util.qh"
6 #include "autocvars.qh"
8 #include "../csqcmodellib/cl_model.qh"
13 const float TUBA_MIN = -18;
14 const float TUBA_MAX = 27;
15 const float TUBA_INSTRUMENTS = 3;
17 #define TUBA_STARTNOTE(i,n) strcat("weapons/tuba", (i ? ftos(i) : ""), "_loopnote", ftos(n), ".wav")
19 .float attenuate; // if set, attenuate it
20 .float cnt; // current volume
21 .float count; // initial volume
22 .float tuba_instrument;
26 void tubasound(entity e, float restart)
45 m = e.note % Tuba_PitchStep;
48 if(e.note - m < TUBA_MIN)
51 snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
52 p1 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
54 else if(e.note - m + Tuba_PitchStep > TUBA_MAX)
57 snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
58 p1 = pow(2.0, m / 12.0);
63 snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
64 f1 = cos(M_PI_2 * m / Tuba_PitchStep);
65 p1 = pow(2.0, m / 12.0);
67 snd2 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
68 f2 = sin(M_PI_2 * m / Tuba_PitchStep);
69 p2 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
75 snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
78 sound7(e, CH_TUBA_SINGLE, snd1, e.cnt * f1, e.attenuate * autocvar_g_balance_tuba_attenuation, 100 * p1, 0);
80 sound7(e.enemy, CH_TUBA_SINGLE, snd2, e.cnt * f2, e.attenuate * autocvar_g_balance_tuba_attenuation, 100 * p2, 0);
85 snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
86 sound(e, CH_TUBA_SINGLE, snd1, e.cnt, e.attenuate * autocvar_g_balance_tuba_attenuation);
90 void Ent_TubaNote_Think()
93 f = autocvar_g_balance_tuba_fadetime;
95 self.cnt -= frametime * self.count / f;
98 self.nextthink = time;
101 sound(self, CH_TUBA_SINGLE, "misc/null.wav", 0, 0);
104 sound(self.enemy, CH_TUBA_SINGLE, "misc/null.wav", 0, 0);
115 void Ent_TubaNote_UpdateSound()
117 self.enemy.cnt = bound(0, VOL_BASE * autocvar_g_balance_tuba_volume, 1);
118 self.enemy.count = self.enemy.cnt;
119 self.enemy.note = self.note;
120 self.enemy.tuba_instrument = self.tuba_instrument;
121 tubasound(self.enemy, 1);
124 void Ent_TubaNote_StopSound()
126 self.enemy.nextthink = time;
130 void Ent_TubaNote(float bIsNew)
145 if(n != self.note || i != self.tuba_instrument || bIsNew)
148 Ent_TubaNote_StopSound();
153 self.enemy = spawn();
154 self.enemy.classname = "tuba_note";
157 self.enemy.enemy = spawn();
158 self.enemy.enemy.classname = "tuba_note_2";
163 self.enemy.attenuate = att;
168 self.tuba_instrument = i;
175 self.enemy.origin_x = ReadCoord();
176 self.enemy.origin_y = ReadCoord();
177 self.enemy.origin_z = ReadCoord();
178 setorigin(self.enemy, self.enemy.origin);
180 setorigin(self.enemy.enemy, self.enemy.origin);
183 self.think = Ent_TubaNote_StopSound;
184 self.entremove = Ent_TubaNote_StopSound;
185 self.enemy.think = Ent_TubaNote_Think;
186 self.enemy.nextthink = time + 10;
189 Ent_TubaNote_UpdateSound();
196 Tuba_PitchStep = autocvar_g_balance_tuba_pitchstep;
199 if(!checkextension("DP_SND_SOUND7_WIP2") && !checkextension("DP_SND_SOUND7"))
201 print("^1NOTE:^7 requested pitch shifting, but not supported by this engine build\n");
205 for(n = TUBA_MIN; n <= TUBA_MAX; ++n)
207 if(!Tuba_PitchStep || ((n % Tuba_PitchStep) == 0))
209 for(i = 0; i < TUBA_INSTRUMENTS; ++i)
210 precache_sound(TUBA_STARTNOTE(i, n));