]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_tuba.qc
Reverted the changes in tracewalk calls introduced in r6891 as it breaks the CTF...
[divverent/nexuiz.git] / data / qcsrc / server / w_tuba.qc
1 #define TUBA_NOTE(n) strcat("weapons/tuba_note", ftos(n), ".wav")
2 .float tuba_notecount;
3
4 float Tuba_GetNote(entity pl, float hittype)
5 {
6         float note;
7         float movestate;
8         movestate = 5;
9         if(pl.movement_x < 0) movestate -= 3;
10         if(pl.movement_x > 0) movestate += 3;
11         if(pl.movement_y < 0) movestate -= 1;
12         if(pl.movement_y > 0) movestate += 1;
13         switch(movestate)
14         {
15         // layout: originally I wanted
16         //   eb e  e#=f
17         //   B  c  d
18         //   Gb G  G#
19         // but then you only use forward and right key. So to make things more
20         // interesting, I swapped B with e#. Har har har...
21         //   eb e  B
22         // f=e# c  d
23         //   Gb G  G#
24                 case 1: note = -6; break; // Gb
25                 case 2: note = -5; break; // G
26                 case 3: note = -4; break; // G#
27                 case 4: note = +5; break; // e#
28                 case 5: note =  0; break; // c
29                 case 6: note = +2; break; // d
30                 case 7: note = +3; break; // eb
31                 case 8: note = +4; break; // e
32                 case 9: note = -1; break; // B
33         }
34         if(pl.BUTTON_CROUCH)
35                 note -= 12;
36         if(pl.BUTTON_JUMP)
37                 note += 12;
38         if(hittype & HITTYPE_SECONDARY)
39                 note += 7;
40         
41         // we support two kinds of tubas, those tuned in Eb and those tuned in C
42         // kind of tuba currently is player slot number, or team number if in
43         // teamplay
44         // that way, holes in the range of notes are "plugged"
45         if(teams_matter)
46         {
47                 if(pl.team == COLOR_TEAM2 || pl.team == COLOR_TEAM4)
48                         note += 3;
49         }
50         else
51         {
52                 if(pl.clientcolors & 1)
53                         note += 3;
54         }
55         
56         // total range of notes:
57         //                       0
58         //                 ***  ** ****
59         //                        ***  ** ****
60         //     ***  ** ****
61         //            ***  ** ****
62         //     ***  ********************* ****
63         //     -18.........................+12
64         //        ***  ********************* ****
65         //     -18............................+15
66         //     with jump: ... +24
67         //     ... +27
68         return note;
69 }
70
71 void W_Tuba_Attack(float hittype)
72 {
73         vector o;
74         W_SetupShot(self, FALSE, 2, "", cvar("g_balance_tuba_damage"));
75         self.tuba_notecount = !self.tuba_notecount;
76         if(self.tuba_notecount)
77                 sound(self, CHAN_WEAPON, TUBA_NOTE(Tuba_GetNote(self, hittype)), VOL_BASE, cvar("g_balance_tuba_attenuation"));
78         else
79                 sound(self, CHAN_WEAPON2, TUBA_NOTE(Tuba_GetNote(self, hittype)), VOL_BASE, cvar("g_balance_tuba_attenuation"));
80         RadiusDamage(self, self, cvar("g_balance_tuba_damage"), cvar("g_balance_tuba_edgedamage"), cvar("g_balance_tuba_radius"), world, cvar("g_balance_tuba_force"), hittype | WEP_TUBA, world);
81
82         o = gettaginfo(self.exteriorweaponentity, 0);
83         pointparticles(particleeffectnum("smoke_ring"), o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1);
84 }
85
86 void spawnfunc_weapon_tuba (void)
87 {
88         if(!sv_cheats && !cvar("developer"))
89         {
90                 print("The @!#%'n Tuba awaits you... not.\n");
91                 remove(self);
92                 return;
93         }
94         weapon_defaultspawnfunc(WEP_TUBA);
95 }
96
97 float w_tuba(float req)
98 {
99         if (req == WR_AIM)
100         {
101                 // bots cannot play the Tuba well yet
102                 // I think they should start with the recorder first
103                 if(vlen(self.origin - self.enemy.origin) < cvar("g_balance_tuba_radius"))
104                 {
105                         if(random() > 0.5)
106                                 self.BUTTON_ATCK = 1;
107                         else
108                                 self.BUTTON_ATCK2 = 1;
109                 }
110         }
111         else if (req == WR_THINK)
112         {
113                 if (self.BUTTON_ATCK)
114                 if (weapon_prepareattack(0, cvar("g_balance_tuba_refire")))
115                 {
116                         W_Tuba_Attack(0);
117                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_tuba_animtime"), w_ready);
118                 }
119                 if (self.BUTTON_ATCK2)
120                 if (weapon_prepareattack(1, cvar("g_balance_tuba_refire")))
121                 {
122                         W_Tuba_Attack(HITTYPE_SECONDARY);
123                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_tuba_animtime"), w_ready);
124                 }
125         }
126         else if (req == WR_PRECACHE)
127         {
128                 precache_model ("models/weapons/g_tuba.md3");
129                 precache_model ("models/weapons/v_tuba.md3");
130                 precache_model ("models/weapons/h_tuba.dpm");
131
132                 float i;
133                 for(i = -18; i <= +27; ++i)
134                         precache_sound(TUBA_NOTE(i));
135         }
136         else if (req == WR_SETUP)
137                 weapon_setup(WEP_TUBA);
138         else if (req == WR_CHECKAMMO1)
139                 return TRUE; // TODO use fuel?
140         else if (req == WR_CHECKAMMO2)
141                 return TRUE; // TODO use fuel?
142         else if (req == WR_SUICIDEMESSAGE)
143         {
144                 w_deathtypestring = "hurt his own ears with the @!#%'n Tuba";
145         }
146         else if (req == WR_KILLMESSAGE)
147         {
148                 w_deathtypestring = "died of #'s great playing on the @!#%'n Tuba";
149         }
150         return TRUE;
151 };