]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_tuba.qc
add a cvar that can disable wearing off on powerups
[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 .entity tuba_note;
4 .float tuba_smoketime;
5
6 float Tuba_GetNote(entity pl, float hittype)
7 {
8         float note;
9         float movestate;
10         movestate = 5;
11         if(pl.movement_x < 0) movestate -= 3;
12         if(pl.movement_x > 0) movestate += 3;
13         if(pl.movement_y < 0) movestate -= 1;
14         if(pl.movement_y > 0) movestate += 1;
15         switch(movestate)
16         {
17         // layout: originally I wanted
18         //   eb e  e#=f
19         //   B  c  d
20         //   Gb G  G#
21         // but then you only use forward and right key. So to make things more
22         // interesting, I swapped B with e#. Har har har...
23         //   eb e  B
24         // f=e# c  d
25         //   Gb G  G#
26                 case 1: note = -6; break; // Gb
27                 case 2: note = -5; break; // G
28                 case 3: note = -4; break; // G#
29                 case 4: note = +5; break; // e#
30                 case 5: note =  0; break; // c
31                 case 6: note = +2; break; // d
32                 case 7: note = +3; break; // eb
33                 case 8: note = +4; break; // e
34                 case 9: note = -1; break; // B
35         }
36         if(pl.BUTTON_CROUCH)
37                 note -= 12;
38         if(pl.BUTTON_JUMP)
39                 note += 12;
40         if(hittype & HITTYPE_SECONDARY)
41                 note += 7;
42         
43         // we support two kinds of tubas, those tuned in Eb and those tuned in C
44         // kind of tuba currently is player slot number, or team number if in
45         // teamplay
46         // that way, holes in the range of notes are "plugged"
47         if(teams_matter)
48         {
49                 if(pl.team == COLOR_TEAM2 || pl.team == COLOR_TEAM4)
50                         note += 3;
51         }
52         else
53         {
54                 if(pl.clientcolors & 1)
55                         note += 3;
56         }
57         
58         // total range of notes:
59         //                       0
60         //                 ***  ** ****
61         //                        ***  ** ****
62         //     ***  ** ****
63         //            ***  ** ****
64         //     ***  ********************* ****
65         //     -18.........................+12
66         //        ***  ********************* ****
67         //     -18............................+15
68         //     with jump: ... +24
69         //     ... +27
70         return note;
71 }
72
73 float W_Tuba_NoteSendEntity(entity to, float sf)
74 {
75         WriteByte(MSG_ENTITY, ENT_CLIENT_TUBANOTE);
76         WriteByte(MSG_ENTITY, (sf & 1) | ((self.cnt + 42) * 2));
77         if(sf & 1)
78         {
79                 WriteCoord(MSG_ENTITY, self.origin_x);
80                 WriteCoord(MSG_ENTITY, self.origin_y);
81                 WriteCoord(MSG_ENTITY, self.origin_z);
82         }
83         return TRUE;
84 }
85
86 void W_Tuba_NoteThink()
87 {
88         float needchange, dist_mult;
89         float vol0, vol1;
90         vector dir0, dir1;
91         vector v;
92         entity e;
93         if(time > self.teleport_time)
94         {
95                 self.owner.tuba_note = world;
96                 remove(self);
97                 return;
98         }
99         self.nextthink = time;
100         dist_mult = cvar("g_balance_tuba_attenuation") / cvar("snd_soundradius");
101         needchange = 0;
102         FOR_EACH_REALCLIENT(e)
103         if(e != self.owner)
104         {
105                 v = self.origin - (e.origin + e.view_ofs);
106                 vol0 = max(0, 1 - vlen(v) * dist_mult);
107                 dir0 = normalize(v);
108                 v = self.owner.origin - (e.origin + e.view_ofs);
109                 vol1 = max(0, 1 - vlen(v) * dist_mult);
110                 dir1 = normalize(v);
111                 if(fabs(vol0 - vol1) > 0.005) // 0.5 percent change in volume
112                 {
113                         setorigin(self, self.owner.origin);
114                         self.SendFlags |= 1;
115                         break;
116                 }
117                 if(dir0 * dir1 < 0.9994) // 2 degrees change in angle
118                 {
119                         setorigin(self, self.owner.origin);
120                         self.SendFlags |= 1;
121                         break;
122                 }
123         }
124 }
125
126 void W_Tuba_Attack(float hittype)
127 {
128         vector o;
129         float c, n;
130         W_SetupShot(self, FALSE, 2, "", cvar("g_balance_tuba_damage"));
131         if(self.tuba_notecount)
132         {
133                 self.tuba_notecount = FALSE;
134                 c = CHAN_WEAPON;
135         }
136         else
137         {
138                 self.tuba_notecount = TRUE;
139                 c = CHAN_WEAPON2;
140         }
141
142         n = Tuba_GetNote(self, hittype);
143
144         if(self.tuba_note)
145         {
146                 if(self.tuba_note.cnt != n)
147                 {
148                         /*
149                         self.tuba_note.cnt = n;
150                         self.tuba_note.SendFlags |= 2;
151                         */
152                         remove(self.tuba_note);
153                         self.tuba_note = world;
154                 }
155         }
156
157         if not(self.tuba_note)
158         {
159                 self.tuba_note = spawn();
160                 self.tuba_note.owner = self;
161                 self.tuba_note.cnt = n;
162                 self.tuba_note.think = W_Tuba_NoteThink;
163                 self.tuba_note.nextthink = time;
164                 Net_LinkEntity(self.tuba_note, FALSE, 0, W_Tuba_NoteSendEntity);
165         }
166
167         self.tuba_note.teleport_time = time + cvar("g_balance_tuba_refire") * 2; // so it can get prolonged safely
168
169         //sound(self, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), cvar("g_balance_tuba_attenuation"));
170         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);
171
172         o = gettaginfo(self.exteriorweaponentity, 0);
173         if(time > self.tuba_smoketime)
174         {
175                 pointparticles(particleeffectnum("smoke_ring"), o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1);
176                 self.tuba_smoketime = time + 0.25;
177         }
178 }
179
180 void spawnfunc_weapon_tuba (void)
181 {
182         if(!sv_cheats && !cvar("developer"))
183         {
184                 print("The @!#%'n Tuba awaits you... not.\n");
185                 remove(self);
186                 return;
187         }
188         weapon_defaultspawnfunc(WEP_TUBA);
189 }
190
191 float w_tuba(float req)
192 {
193         if (req == WR_AIM)
194         {
195                 // bots cannot play the Tuba well yet
196                 // I think they should start with the recorder first
197                 if(vlen(self.origin - self.enemy.origin) < cvar("g_balance_tuba_radius"))
198                 {
199                         if(random() > 0.5)
200                                 self.BUTTON_ATCK = 1;
201                         else
202                                 self.BUTTON_ATCK2 = 1;
203                 }
204         }
205         else if (req == WR_THINK)
206         {
207                 if (self.BUTTON_ATCK)
208                 if (weapon_prepareattack(0, cvar("g_balance_tuba_refire")))
209                 {
210                         W_Tuba_Attack(0);
211                         //weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_tuba_animtime"), w_ready);
212                         weapon_thinkf(WFRAME_IDLE, cvar("g_balance_tuba_animtime"), w_ready);
213                 }
214                 if (self.BUTTON_ATCK2)
215                 if (weapon_prepareattack(1, cvar("g_balance_tuba_refire")))
216                 {
217                         W_Tuba_Attack(HITTYPE_SECONDARY);
218                         //weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_tuba_animtime"), w_ready);
219                         weapon_thinkf(WFRAME_IDLE, cvar("g_balance_tuba_animtime"), w_ready);
220                 }
221                 if(self.tuba_note)
222                 {
223                         if(!self.BUTTON_ATCK && !self.BUTTON_ATCK2)
224                         {
225                                 remove(self.tuba_note);
226                                 self.tuba_note = world;
227                         }
228                 }
229         }
230         else if (req == WR_PRECACHE)
231         {
232                 precache_model ("models/weapons/g_tuba.md3");
233                 precache_model ("models/weapons/v_tuba.md3");
234                 precache_model ("models/weapons/h_tuba.dpm");
235
236                 //float i;
237                 //for(i = -18; i <= +27; ++i)
238                 //      precache_sound(TUBA_NOTE(i));
239         }
240         else if (req == WR_SETUP)
241                 weapon_setup(WEP_TUBA);
242         else if (req == WR_CHECKAMMO1)
243                 return TRUE; // TODO use fuel?
244         else if (req == WR_CHECKAMMO2)
245                 return TRUE; // TODO use fuel?
246         else if (req == WR_SUICIDEMESSAGE)
247         {
248                 w_deathtypestring = "hurt his own ears with the @!#%'n Tuba";
249         }
250         else if (req == WR_KILLMESSAGE)
251         {
252                 w_deathtypestring = "died of #'s great playing on the @!#%'n Tuba";
253         }
254         return TRUE;
255 };