]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/tuba.qc
tuba: great new code that can hold notes
[divverent/nexuiz.git] / data / 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
4 void Ent_TubaNote_Think()
5 {
6         self.cnt -= frametime * self.count * 3;
7         self.nextthink = time;
8         if(self.cnt <= 0)
9         {
10                 sound(self, CHAN_PROJECTILE, "misc/null.wav", 0, 0);
11                 remove(self);
12         }
13         else
14                 sound(self, CHAN_PROJECTILE, "", self.cnt, cvar("g_balance_tuba_attenuation"));
15 }
16
17 void Ent_TubaNote_UpdateSound()
18 {
19         self.enemy.cnt = bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1);
20         self.enemy.count = self.enemy.cnt;
21         sound(self.enemy, CHAN_PROJECTILE, TUBA_STARTNOTE(self.cnt), self.enemy.cnt, cvar("g_balance_tuba_attenuation"));
22 }
23
24 void Ent_TubaNote_StopSound()
25 {
26         self.enemy.nextthink = time;
27         self.enemy = world;
28 }
29
30 void Ent_TubaNote(float bIsNew)
31 {
32         float f, n;
33         f = ReadByte();
34         n = floor(f / 2) - 42;
35         if(n != self.cnt || bIsNew)
36                 if(self.enemy)
37                         Ent_TubaNote_StopSound();
38         if(!self.enemy)
39         {
40                 self.enemy = spawn();
41                 self.enemy.classname = "tuba_note";
42                 bIsNew = TRUE;
43         }
44         if(f & 1)
45         {
46                 self.enemy.origin_x = ReadCoord();
47                 self.enemy.origin_y = ReadCoord();
48                 self.enemy.origin_z = ReadCoord();
49                 setorigin(self.enemy, self.enemy.origin);
50         }
51         self.think = Ent_TubaNote_StopSound;
52         self.entremove = Ent_TubaNote_StopSound;
53         self.enemy.think = Ent_TubaNote_Think;
54         self.enemy.nextthink = time + 10;
55         if(bIsNew)
56         {
57                 self.cnt = n;
58                 Ent_TubaNote_UpdateSound();
59         }
60 }
61
62 void Tuba_Precache()
63 {
64         float i;
65         for(i = -18; i <= +27; ++i)
66         {
67                 precache_sound(TUBA_STARTNOTE(i));
68         }
69         //precache_sound(""); // we want to change volume of existing sounds
70 }