]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/tuba.qc
04114d324ab4b9c31590b9c9056bf15f9d71f790
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / tuba.qc
1 #define TUBA_STARTNOTE(n) strcat((checkextension("DP_SND_SETPARAMS") ? "weapons/tuba_loopnote" : "weapons/tuba_note"), ftos(n), ".wav")
2 .float cnt; // note
3 .float attenuate; // if set, attenuate it
4
5 void Ent_TubaNote_Think()
6 {
7         float f;
8         f = autocvar_g_balance_tuba_fadetime;
9         if(f > 0)
10                 self.cnt -= frametime * self.count / f;
11         else
12                 self.cnt = 0;
13         self.nextthink = time;
14         if(self.cnt <= 0)
15         {
16                 sound(self, CH_SHOTS_SINGLE, "misc/null.wav", 0, 0);
17                 remove(self);
18         }
19         else
20                 sound(self, CH_SHOTS_SINGLE, "", self.cnt, self.attenuate * autocvar_g_balance_tuba_attenuation);
21 }
22
23 void Ent_TubaNote_UpdateSound()
24 {
25         self.enemy.cnt = bound(0, VOL_BASE * autocvar_g_balance_tuba_volume, 1);
26         self.enemy.count = self.enemy.cnt;
27 #ifdef PITCHSHIFT
28         sound7(self.enemy, CH_SHOTS_SINGLE, TUBA_STARTNOTE(0), self.enemy.cnt, self.enemy.attenuate * autocvar_g_balance_tuba_attenuation, 100 * pow(2.0, self.cnt / 12.0), 0);
29 #else
30         sound(self.enemy, CH_SHOTS_SINGLE, TUBA_STARTNOTE(self.cnt), self.enemy.cnt, self.enemy.attenuate * autocvar_g_balance_tuba_attenuation);
31 #endif
32 }
33
34 void Ent_TubaNote_StopSound()
35 {
36         self.enemy.nextthink = time;
37         self.enemy = world;
38 }
39
40 void Ent_TubaNote(float bIsNew)
41 {
42         float f, n;
43         f = ReadByte();
44         n = floor(f / 2) - 42;
45         if(n != self.cnt || bIsNew)
46                 if(self.enemy)
47                         Ent_TubaNote_StopSound();
48         if(!self.enemy)
49         {
50                 self.enemy = spawn();
51                 self.enemy.classname = "tuba_note";
52                 bIsNew = TRUE;
53         }
54         if(f & 1)
55         {
56                 self.enemy.origin_x = ReadCoord();
57                 self.enemy.origin_y = ReadCoord();
58                 self.enemy.origin_z = ReadCoord();
59                 setorigin(self.enemy, self.enemy.origin);
60                 self.enemy.attenuate = ReadByte();
61         }
62         self.think = Ent_TubaNote_StopSound;
63         self.entremove = Ent_TubaNote_StopSound;
64         self.enemy.think = Ent_TubaNote_Think;
65         self.enemy.nextthink = time + 10;
66         if(bIsNew)
67         {
68                 self.cnt = n;
69                 Ent_TubaNote_UpdateSound();
70         }
71 }
72
73 void Tuba_Precache()
74 {
75         float i;
76 #ifdef PITCHSHIFT
77         precache_sound(TUBA_STARTNOTE(0));
78 #else
79         for(i = -18; i <= +27; ++i)
80         {
81                 precache_sound(TUBA_STARTNOTE(i));
82         }
83 #endif
84         //precache_sound(""); // we want to change volume of existing sounds
85 }