2 REGISTER_WEAPON(TUBA, w_tuba, 0, 1, WEP_FLAG_HIDDEN | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "tuba", "tuba", _("@!#%'n Tuba"))
5 //#define TUBA_NOTE(n) strcat("weapons/tuba_note", ftos(n), ".wav")
8 .float tuba_instrument;
10 #define MAX_TUBANOTES 32
11 .float tuba_lastnotes_last;
12 .float tuba_lastnotes_cnt; // over
13 .vector tuba_lastnotes[MAX_TUBANOTES];
15 float W_Tuba_HasPlayed(entity pl, string melody)
18 float n = tokenize_console(melody);
19 if(n > pl.tuba_lastnotes_cnt)
21 for(i = 0; i < n; ++i)
23 vector v = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - i + MAX_TUBANOTES, MAX_TUBANOTES)]);
24 float ai = stof(argv(n - i - 1));
26 float nl = ((ai == np) ? 0 : (1 / (ai - np)));
27 // n counts the last played notes BACKWARDS
33 // FIXME verify rhythm
35 pl.tuba_lastnotes_cnt = 0;
42 // on: self.spawnshieldtime
45 if(self.owner.tuba_note == self)
47 self.owner.tuba_lastnotes_last = mod(self.owner.tuba_lastnotes_last + 1, MAX_TUBANOTES);
48 self.owner.(tuba_lastnotes[self.owner.tuba_lastnotes_last]) = eX * self.spawnshieldtime + eY * time + eZ * self.cnt;
49 self.owner.tuba_note = world;
50 self.owner.tuba_lastnotes_cnt = bound(0, self.owner.tuba_lastnotes_cnt + 1, MAX_TUBANOTES);
53 if(W_Tuba_HasPlayed(self.owner, "4 0 4 2"))
54 dprint("Someone knows how to play Loom!\n");
59 float Tuba_GetNote(entity pl, float hittype)
64 if(pl.movement_x < 0) movestate -= 3;
65 if(pl.movement_x > 0) movestate += 3;
66 if(pl.movement_y < 0) movestate -= 1;
67 if(pl.movement_y > 0) movestate += 1;
70 // layout: originally I wanted
74 // but then you only use forward and right key. So to make things more
75 // interesting, I swapped B with e#. Har har har...
79 case 1: note = -6; break; // Gb
80 case 2: note = -5; break; // G
81 case 3: note = -4; break; // G#
82 case 4: note = +5; break; // e#
83 case 5: note = 0; break; // c
84 case 6: note = +2; break; // d
85 case 7: note = +3; break; // eb
86 case 8: note = +4; break; // e
87 case 9: note = -1; break; // B
93 if(hittype & HITTYPE_SECONDARY)
96 // we support two kinds of tubas, those tuned in Eb and those tuned in C
97 // kind of tuba currently is player slot number, or team number if in
99 // that way, holes in the range of notes are "plugged"
102 if(pl.team == COLOR_TEAM2 || pl.team == COLOR_TEAM4)
107 if(pl.clientcolors & 1)
111 // total range of notes:
117 // *** ********************* ****
118 // -18.........................+12
119 // *** ********************* ****
120 // -18............................+15
121 // with jump: ... +24
126 float W_Tuba_NoteSendEntity(entity to, float sf)
131 if(!sound_allowed(MSG_ONE, self.realowner))
134 WriteByte(MSG_ENTITY, ENT_CLIENT_TUBANOTE);
135 WriteByte(MSG_ENTITY, sf);
138 WriteChar(MSG_ENTITY, self.cnt);
140 if(self.realowner != to)
142 f |= 2 * self.tuba_instrument;
143 WriteByte(MSG_ENTITY, f);
147 WriteCoord(MSG_ENTITY, self.origin_x);
148 WriteCoord(MSG_ENTITY, self.origin_y);
149 WriteCoord(MSG_ENTITY, self.origin_z);
154 void W_Tuba_NoteThink()
161 if(time > self.teleport_time)
166 self.nextthink = time;
167 dist_mult = autocvar_g_balance_tuba_attenuation / autocvar_snd_soundradius;
168 FOR_EACH_REALCLIENT(e)
169 if(e != self.realowner)
171 v = self.origin - (e.origin + e.view_ofs);
172 vol0 = max(0, 1 - vlen(v) * dist_mult);
174 v = self.realowner.origin - (e.origin + e.view_ofs);
175 vol1 = max(0, 1 - vlen(v) * dist_mult);
177 if(fabs(vol0 - vol1) > 0.005) // 0.5 percent change in volume
179 setorigin(self, self.realowner.origin);
183 if(dir0 * dir1 < 0.9994) // 2 degrees change in angle
185 setorigin(self, self.realowner.origin);
192 void W_Tuba_NoteOn(float hittype)
197 W_SetupShot(self, FALSE, 2, "", 0, autocvar_g_balance_tuba_damage);
199 n = Tuba_GetNote(self, hittype);
202 if(self.tuba_instrument & 1)
203 hittype |= HITTYPE_SECONDARY;
204 if(self.tuba_instrument & 2)
205 hittype |= HITTYPE_BOUNCE;
206 if(self.tuba_instrument & 4)
207 hittype |= HITTYPE_HEADSHOT;
211 if(self.tuba_note.cnt != n || self.tuba_note.tuba_instrument != self.tuba_instrument)
213 entity oldself = self;
214 self = self.tuba_note;
220 if not(self.tuba_note)
222 self.tuba_note = spawn();
223 self.tuba_note.owner = self.tuba_note.realowner = self;
224 self.tuba_note.cnt = n;
225 self.tuba_note.tuba_instrument = self.tuba_instrument;
226 self.tuba_note.think = W_Tuba_NoteThink;
227 self.tuba_note.nextthink = time;
228 self.tuba_note.spawnshieldtime = time;
229 Net_LinkEntity(self.tuba_note, FALSE, 0, W_Tuba_NoteSendEntity);
232 self.tuba_note.teleport_time = time + autocvar_g_balance_tuba_refire * 2 * W_WeaponRateFactor(); // so it can get prolonged safely
234 //sound(self, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), autocvar_g_balance_tuba_attenuation);
235 RadiusDamage(self, self, autocvar_g_balance_tuba_damage, autocvar_g_balance_tuba_edgedamage, autocvar_g_balance_tuba_radius, world, autocvar_g_balance_tuba_force, hittype | WEP_TUBA, world);
237 o = gettaginfo(self.exteriorweaponentity, 0);
238 if(time > self.tuba_smoketime)
240 pointparticles(particleeffectnum("smoke_ring"), o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1);
241 self.tuba_smoketime = time + 0.25;
245 void spawnfunc_weapon_tuba (void)
247 weapon_defaultspawnfunc(WEP_TUBA);
250 float w_tuba(float req)
254 // bots cannot play the Tuba well yet
255 // I think they should start with the recorder first
256 if(vlen(self.origin - self.enemy.origin) < autocvar_g_balance_tuba_radius)
259 self.BUTTON_ATCK = 1;
261 self.BUTTON_ATCK2 = 1;
264 else if (req == WR_THINK)
266 if (self.BUTTON_ATCK)
267 if (weapon_prepareattack(0, autocvar_g_balance_tuba_refire))
270 //weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_tuba_animtime, w_ready);
271 weapon_thinkf(WFRAME_IDLE, autocvar_g_balance_tuba_animtime, w_ready);
273 if (self.BUTTON_ATCK2)
274 if (weapon_prepareattack(1, autocvar_g_balance_tuba_refire))
276 W_Tuba_NoteOn(HITTYPE_SECONDARY);
277 //weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_tuba_animtime, w_ready);
278 weapon_thinkf(WFRAME_IDLE, autocvar_g_balance_tuba_animtime, w_ready);
282 if(!self.BUTTON_ATCK && !self.BUTTON_ATCK2)
284 entity oldself = self;
285 self = self.tuba_note;
291 else if (req == WR_PRECACHE)
293 precache_model ("models/weapons/g_tuba.md3");
294 precache_model ("models/weapons/v_tuba.md3");
295 precache_model ("models/weapons/h_tuba.iqm");
296 precache_model ("models/weapons/g_akordeon.md3");
297 precache_model ("models/weapons/v_akordeon.md3");
298 precache_model ("models/weapons/h_akordeon.iqm");
301 //for(i = -18; i <= +27; ++i)
302 // precache_sound(TUBA_NOTE(i));
304 else if (req == WR_SETUP)
306 weapon_setup(WEP_TUBA);
307 self.current_ammo = ammo_none;
308 self.tuba_instrument = 0;
310 else if (req == WR_RELOAD)
312 // switch to alternate instruments :)
313 if(self.weaponentity.state == WS_READY)
315 switch(self.tuba_instrument)
318 self.tuba_instrument = 1;
319 self.weaponname = "akordeon";
322 self.tuba_instrument = 0;
323 self.weaponname = "tuba";
326 W_SetupShot(self, FALSE, 0, "", 0, 0);
327 pointparticles(particleeffectnum("teleport"), w_shotorg, '0 0 0', 1);
328 self.weaponentity.state = WS_INUSE;
329 weapon_thinkf(WFRAME_RELOAD, 0.5, w_ready);
332 else if (req == WR_CHECKAMMO1)
333 return TRUE; // TODO use fuel?
334 else if (req == WR_CHECKAMMO2)
335 return TRUE; // TODO use fuel?
340 float w_tuba(float req)
342 if(req == WR_IMPACTEFFECT)
344 // nothing to do here; particles of tuba are handled differently
346 else if(req == WR_PRECACHE)
350 else if (req == WR_SUICIDEMESSAGE)
354 if(w_deathtype & HITTYPE_SECONDARY)
356 if(w_deathtype & HITTYPE_BOUNCE)
358 if(w_deathtype & HITTYPE_HEADSHOT)
364 w_deathtypestring = _("%s hurt his own ears with the @!#%%'n Tuba");
367 w_deathtypestring = _("%s hurt his own ears with the @!#%%'n Accordeon");
371 else if (req == WR_KILLMESSAGE)
375 if(w_deathtype & HITTYPE_SECONDARY)
377 if(w_deathtype & HITTYPE_BOUNCE)
379 if(w_deathtype & HITTYPE_HEADSHOT)
385 w_deathtypestring = _("%s died of %s's great playing on the @!#%%'n Tuba");
388 w_deathtypestring = _("%s died of %s's great playing on the @!#%%'n Accordeon");