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));
25 // n counts the last played notes BACKWARDS
31 // FIXME verify rhythm
33 pl.tuba_lastnotes_cnt = 0;
40 // on: self.spawnshieldtime
43 if(self.owner.tuba_note == self)
45 self.owner.tuba_lastnotes_last = mod(self.owner.tuba_lastnotes_last + 1, MAX_TUBANOTES);
46 self.owner.(tuba_lastnotes[self.owner.tuba_lastnotes_last]) = eX * self.spawnshieldtime + eY * time + eZ * self.cnt;
47 self.owner.tuba_note = world;
48 self.owner.tuba_lastnotes_cnt = bound(0, self.owner.tuba_lastnotes_cnt + 1, MAX_TUBANOTES);
51 if(W_Tuba_HasPlayed(self.owner, "4 0 4 2"))
52 dprint("Someone knows how to play Loom!\n");
57 float Tuba_GetNote(entity pl, float hittype)
62 if(pl.movement_x < 0) movestate -= 3;
63 if(pl.movement_x > 0) movestate += 3;
64 if(pl.movement_y < 0) movestate -= 1;
65 if(pl.movement_y > 0) movestate += 1;
68 // layout: originally I wanted
72 // but then you only use forward and right key. So to make things more
73 // interesting, I swapped B with e#. Har har har...
77 case 1: note = -6; break; // Gb
78 case 2: note = -5; break; // G
79 case 3: note = -4; break; // G#
80 case 4: note = +5; break; // e#
81 case 5: note = 0; break; // c
82 case 6: note = +2; break; // d
83 case 7: note = +3; break; // eb
84 case 8: note = +4; break; // e
85 case 9: note = -1; break; // B
91 if(hittype & HITTYPE_SECONDARY)
94 // we support two kinds of tubas, those tuned in Eb and those tuned in C
95 // kind of tuba currently is player slot number, or team number if in
97 // that way, holes in the range of notes are "plugged"
100 if(pl.team == COLOR_TEAM2 || pl.team == COLOR_TEAM4)
105 if(pl.clientcolors & 1)
109 // total range of notes:
115 // *** ********************* ****
116 // -18.........................+12
117 // *** ********************* ****
118 // -18............................+15
119 // with jump: ... +24
124 float W_Tuba_NoteSendEntity(entity to, float sf)
129 if(!sound_allowed(MSG_ONE, self.realowner))
132 WriteByte(MSG_ENTITY, ENT_CLIENT_TUBANOTE);
133 WriteByte(MSG_ENTITY, sf);
136 WriteChar(MSG_ENTITY, self.cnt);
138 if(self.realowner != to)
140 f |= 2 * self.tuba_instrument;
141 WriteByte(MSG_ENTITY, f);
145 WriteCoord(MSG_ENTITY, self.origin_x);
146 WriteCoord(MSG_ENTITY, self.origin_y);
147 WriteCoord(MSG_ENTITY, self.origin_z);
152 void W_Tuba_NoteThink()
159 if(time > self.teleport_time)
164 self.nextthink = time;
165 dist_mult = autocvar_g_balance_tuba_attenuation / autocvar_snd_soundradius;
166 FOR_EACH_REALCLIENT(e)
167 if(e != self.realowner)
169 v = self.origin - (e.origin + e.view_ofs);
170 vol0 = max(0, 1 - vlen(v) * dist_mult);
172 v = self.realowner.origin - (e.origin + e.view_ofs);
173 vol1 = max(0, 1 - vlen(v) * dist_mult);
175 if(fabs(vol0 - vol1) > 0.005) // 0.5 percent change in volume
177 setorigin(self, self.realowner.origin);
181 if(dir0 * dir1 < 0.9994) // 2 degrees change in angle
183 setorigin(self, self.realowner.origin);
190 void W_Tuba_NoteOn(float hittype)
195 W_SetupShot(self, FALSE, 2, "", 0, autocvar_g_balance_tuba_damage);
197 n = Tuba_GetNote(self, hittype);
200 if(self.tuba_instrument & 1)
201 hittype |= HITTYPE_SECONDARY;
202 if(self.tuba_instrument & 2)
203 hittype |= HITTYPE_BOUNCE;
204 if(self.tuba_instrument & 4)
205 hittype |= HITTYPE_HEADSHOT;
209 if(self.tuba_note.cnt != n || self.tuba_note.tuba_instrument != self.tuba_instrument)
211 entity oldself = self;
212 self = self.tuba_note;
218 if not(self.tuba_note)
220 self.tuba_note = spawn();
221 self.tuba_note.owner = self.tuba_note.realowner = self;
222 self.tuba_note.cnt = n;
223 self.tuba_note.tuba_instrument = self.tuba_instrument;
224 self.tuba_note.think = W_Tuba_NoteThink;
225 self.tuba_note.nextthink = time;
226 self.tuba_note.spawnshieldtime = time;
227 Net_LinkEntity(self.tuba_note, FALSE, 0, W_Tuba_NoteSendEntity);
230 self.tuba_note.teleport_time = time + autocvar_g_balance_tuba_refire * 2 * W_WeaponRateFactor(); // so it can get prolonged safely
232 //sound(self, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), autocvar_g_balance_tuba_attenuation);
233 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);
235 o = gettaginfo(self.exteriorweaponentity, 0);
236 if(time > self.tuba_smoketime)
238 pointparticles(particleeffectnum("smoke_ring"), o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1);
239 self.tuba_smoketime = time + 0.25;
243 void spawnfunc_weapon_tuba (void)
245 weapon_defaultspawnfunc(WEP_TUBA);
248 float w_tuba(float req)
252 // bots cannot play the Tuba well yet
253 // I think they should start with the recorder first
254 if(vlen(self.origin - self.enemy.origin) < autocvar_g_balance_tuba_radius)
257 self.BUTTON_ATCK = 1;
259 self.BUTTON_ATCK2 = 1;
262 else if (req == WR_THINK)
264 if (self.BUTTON_ATCK)
265 if (weapon_prepareattack(0, autocvar_g_balance_tuba_refire))
268 //weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_tuba_animtime, w_ready);
269 weapon_thinkf(WFRAME_IDLE, autocvar_g_balance_tuba_animtime, w_ready);
271 if (self.BUTTON_ATCK2)
272 if (weapon_prepareattack(1, autocvar_g_balance_tuba_refire))
274 W_Tuba_NoteOn(HITTYPE_SECONDARY);
275 //weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_tuba_animtime, w_ready);
276 weapon_thinkf(WFRAME_IDLE, autocvar_g_balance_tuba_animtime, w_ready);
280 if(!self.BUTTON_ATCK && !self.BUTTON_ATCK2)
282 entity oldself = self;
283 self = self.tuba_note;
289 else if (req == WR_PRECACHE)
291 precache_model ("models/weapons/g_tuba.md3");
292 precache_model ("models/weapons/v_tuba.md3");
293 precache_model ("models/weapons/h_tuba.iqm");
294 precache_model ("models/weapons/g_akordeon.md3");
295 precache_model ("models/weapons/v_akordeon.md3");
296 precache_model ("models/weapons/h_akordeon.iqm");
299 //for(i = -18; i <= +27; ++i)
300 // precache_sound(TUBA_NOTE(i));
302 else if (req == WR_SETUP)
304 weapon_setup(WEP_TUBA);
305 self.current_ammo = ammo_none;
306 self.tuba_instrument = 0;
308 else if (req == WR_RELOAD)
310 // switch to alternate instruments :)
311 if(self.weaponentity.state == WS_READY)
313 switch(self.tuba_instrument)
316 self.tuba_instrument = 1;
317 self.weaponname = "akordeon";
320 self.tuba_instrument = 0;
321 self.weaponname = "tuba";
324 W_SetupShot(self, FALSE, 0, "", 0, 0);
325 pointparticles(particleeffectnum("teleport"), w_shotorg, '0 0 0', 1);
326 self.weaponentity.state = WS_INUSE;
327 weapon_thinkf(WFRAME_RELOAD, 0.5, w_ready);
330 else if (req == WR_CHECKAMMO1)
331 return TRUE; // TODO use fuel?
332 else if (req == WR_CHECKAMMO2)
333 return TRUE; // TODO use fuel?
338 float w_tuba(float req)
340 if(req == WR_IMPACTEFFECT)
342 // nothing to do here; particles of tuba are handled differently
344 else if(req == WR_PRECACHE)
348 else if (req == WR_SUICIDEMESSAGE)
352 if(w_deathtype & HITTYPE_SECONDARY)
354 if(w_deathtype & HITTYPE_BOUNCE)
356 if(w_deathtype & HITTYPE_HEADSHOT)
362 w_deathtypestring = _("%s hurt his own ears with the @!#%%'n Tuba");
365 w_deathtypestring = _("%s hurt his own ears with the @!#%%'n Accordeon");
369 else if (req == WR_KILLMESSAGE)
373 if(w_deathtype & HITTYPE_SECONDARY)
375 if(w_deathtype & HITTYPE_BOUNCE)
377 if(w_deathtype & HITTYPE_HEADSHOT)
383 w_deathtypestring = _("%s died of %s's great playing on the @!#%%'n Tuba");
386 w_deathtypestring = _("%s died of %s's great playing on the @!#%%'n Accordeon");