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, float instrument, float ignorepitch, float mintempo, float maxtempo)
17 float i, j, mmin, mmax, nolength;
18 float n = tokenize_console(melody);
19 if(n > pl.tuba_lastnotes_cnt)
24 if(pl.tuba_instrument != instrument)
29 for(i = 0; i < n; ++i)
31 vector v = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - i + MAX_TUBANOTES, MAX_TUBANOTES)]);
32 float ai = stof(argv(n - i - 1));
36 // n counts the last played notes BACKWARDS
40 if(ignorepitch && i == 0)
42 pitchshift = np - v_z;
46 if(v_z + pitchshift != np)
51 // now we know the right NOTES were played
57 mmin = 240 / maxtempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec
61 mmax = 240 / mintempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec
63 mmax = 240; // you won't try THAT hard... (tempo 1)
64 //print(sprintf("initial tempo rules: %f %f\n", mmin, mmax));
66 for(i = 0; i < n; ++i)
68 vector vi = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - i + MAX_TUBANOTES, MAX_TUBANOTES)]);
69 float ai = stof(argv(n - i - 1));
70 ti -= 1 / (ai - floor(ai));
72 for(j = i+1; j < n; ++j)
74 vector vj = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - j + MAX_TUBANOTES, MAX_TUBANOTES)]);
75 float aj = stof(argv(n - j - 1));
76 tj -= (aj - floor(aj));
78 // note i should be at m*ti+b
79 // note j should be at m*tj+b
81 // we have a LINE l, so that
82 // vi_x <= l(ti) <= vi_y
83 // vj_x <= l(tj) <= vj_y
86 // vi_x <= vi_y <= vj_x <= vj_y
88 //print(sprintf("first note: %f to %f, should be %f\n", vi_x, vi_y, ti));
89 //print(sprintf("second note: %f to %f, should be %f\n", vj_x, vj_y, tj));
90 //print(sprintf("m1 = %f\n", (vi_x - vj_y) / (ti - tj)));
91 //print(sprintf("m2 = %f\n", (vi_y - vj_x) / (ti - tj)));
92 mmin = max(mmin, (vi_x - vj_y) / (ti - tj)); // lower bound
93 mmax = min(mmax, (vi_y - vj_x) / (ti - tj)); // upper bound
97 if(mmin > mmax) // rhythm fail
101 pl.tuba_lastnotes_cnt = 0;
106 void W_Tuba_NoteOff()
109 // on: self.spawnshieldtime
112 if(self.owner.tuba_note == self)
114 self.owner.tuba_lastnotes_last = mod(self.owner.tuba_lastnotes_last + 1, MAX_TUBANOTES);
115 self.owner.(tuba_lastnotes[self.owner.tuba_lastnotes_last]) = eX * self.spawnshieldtime + eY * time + eZ * self.cnt;
116 self.owner.tuba_note = world;
117 self.owner.tuba_lastnotes_cnt = bound(0, self.owner.tuba_lastnotes_cnt + 1, MAX_TUBANOTES);
120 s = trigger_magicear_processmessage_forallears(self.owner, 0, world, string_null);
123 // simulate a server message
124 switch(self.tuba_instrument)
128 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Tuba: ^7", s, "\n"));
131 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Accordeon: ^7", s, "\n"));
134 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Klein Bottle: ^7", s, "\n"));
142 float Tuba_GetNote(entity pl, float hittype)
147 if(pl.movement_x < 0) movestate -= 3;
148 if(pl.movement_x > 0) movestate += 3;
149 if(pl.movement_y < 0) movestate -= 1;
150 if(pl.movement_y > 0) movestate += 1;
156 // layout: originally I wanted
160 // but then you only use forward and right key. So to make things more
161 // interesting, I swapped B with e#. Har har har...
165 case 1: note = -6; break; // Gb
166 case 2: note = -5; break; // G
167 case 3: note = -4; break; // G#
168 case 4: note = +5; break; // e#
170 case 5: note = 0; break; // c
171 case 6: note = +2; break; // d
172 case 7: note = +3; break; // eb
173 case 8: note = +4; break; // e
174 case 9: note = -1; break; // B
180 if(hittype & HITTYPE_SECONDARY)
183 // we support two kinds of tubas, those tuned in Eb and those tuned in C
184 // kind of tuba currently is player slot number, or team number if in
186 // that way, holes in the range of notes are "plugged"
189 if(pl.team == FL_TEAM_2 || pl.team == FL_TEAM_4)
194 if(pl.clientcolors & 1)
198 // total range of notes:
204 // *** ********************* ****
205 // -18.........................+12
206 // *** ********************* ****
207 // -18............................+15
208 // with jump: ... +24
213 float W_Tuba_NoteSendEntity(entity to, float sf)
218 if(!sound_allowed(MSG_ONE, self.realowner))
221 WriteByte(MSG_ENTITY, ENT_CLIENT_TUBANOTE);
222 WriteByte(MSG_ENTITY, sf);
225 WriteChar(MSG_ENTITY, self.cnt);
227 if(self.realowner != to)
229 f |= 2 * self.tuba_instrument;
230 WriteByte(MSG_ENTITY, f);
234 WriteCoord(MSG_ENTITY, self.origin_x);
235 WriteCoord(MSG_ENTITY, self.origin_y);
236 WriteCoord(MSG_ENTITY, self.origin_z);
241 void W_Tuba_NoteThink()
248 if(time > self.teleport_time)
253 self.nextthink = time;
254 dist_mult = autocvar_g_balance_tuba_attenuation / autocvar_snd_soundradius;
255 FOR_EACH_REALCLIENT(e)
256 if(e != self.realowner)
258 v = self.origin - (e.origin + e.view_ofs);
259 vol0 = max(0, 1 - vlen(v) * dist_mult);
261 v = self.realowner.origin - (e.origin + e.view_ofs);
262 vol1 = max(0, 1 - vlen(v) * dist_mult);
264 if(fabs(vol0 - vol1) > 0.005) // 0.5 percent change in volume
266 setorigin(self, self.realowner.origin);
270 if(dir0 * dir1 < 0.9994) // 2 degrees change in angle
272 setorigin(self, self.realowner.origin);
279 void W_Tuba_NoteOn(float hittype)
284 W_SetupShot(self, FALSE, 2, "", 0, autocvar_g_balance_tuba_damage);
286 n = Tuba_GetNote(self, hittype);
289 if(self.tuba_instrument & 1)
290 hittype |= HITTYPE_SECONDARY;
291 if(self.tuba_instrument & 2)
292 hittype |= HITTYPE_BOUNCE;
296 if(self.tuba_note.cnt != n || self.tuba_note.tuba_instrument != self.tuba_instrument)
298 entity oldself = self;
299 self = self.tuba_note;
305 if not(self.tuba_note)
307 self.tuba_note = spawn();
308 self.tuba_note.owner = self.tuba_note.realowner = self;
309 self.tuba_note.cnt = n;
310 self.tuba_note.tuba_instrument = self.tuba_instrument;
311 self.tuba_note.think = W_Tuba_NoteThink;
312 self.tuba_note.nextthink = time;
313 self.tuba_note.spawnshieldtime = time;
314 Net_LinkEntity(self.tuba_note, FALSE, 0, W_Tuba_NoteSendEntity);
317 self.tuba_note.teleport_time = time + autocvar_g_balance_tuba_refire * 2 * W_WeaponRateFactor(); // so it can get prolonged safely
319 //sound(self, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), autocvar_g_balance_tuba_attenuation);
320 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);
322 o = gettaginfo(self.exteriorweaponentity, 0);
323 if(time > self.tuba_smoketime)
325 pointparticles(particleeffectnum("smoke_ring"), o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1);
326 self.tuba_smoketime = time + 0.25;
330 void spawnfunc_weapon_tuba (void)
332 weapon_defaultspawnfunc(WEP_TUBA);
335 float w_tuba(float req)
339 // bots cannot play the Tuba well yet
340 // I think they should start with the recorder first
341 if(vlen(self.origin - self.enemy.origin) < autocvar_g_balance_tuba_radius)
344 self.BUTTON_ATCK = 1;
346 self.BUTTON_ATCK2 = 1;
349 else if (req == WR_THINK)
351 if (self.BUTTON_ATCK)
352 if (weapon_prepareattack(0, autocvar_g_balance_tuba_refire))
355 //weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_tuba_animtime, w_ready);
356 weapon_thinkf(WFRAME_IDLE, autocvar_g_balance_tuba_animtime, w_ready);
358 if (self.BUTTON_ATCK2)
359 if (weapon_prepareattack(1, autocvar_g_balance_tuba_refire))
361 W_Tuba_NoteOn(HITTYPE_SECONDARY);
362 //weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_tuba_animtime, w_ready);
363 weapon_thinkf(WFRAME_IDLE, autocvar_g_balance_tuba_animtime, w_ready);
367 if(!self.BUTTON_ATCK && !self.BUTTON_ATCK2)
369 entity oldself = self;
370 self = self.tuba_note;
376 else if (req == WR_PRECACHE)
378 precache_model ("models/weapons/g_tuba.md3");
379 precache_model ("models/weapons/v_tuba.md3");
380 precache_model ("models/weapons/h_tuba.iqm");
381 precache_model ("models/weapons/v_akordeon.md3");
382 precache_model ("models/weapons/h_akordeon.iqm");
383 precache_model ("models/weapons/v_kleinbottle.md3");
384 precache_model ("models/weapons/h_kleinbottle.iqm");
387 //for(i = -18; i <= +27; ++i)
388 // precache_sound(TUBA_NOTE(i));
390 else if (req == WR_SETUP)
392 weapon_setup(WEP_TUBA);
393 self.current_ammo = ammo_none;
394 self.tuba_instrument = 0;
396 else if (req == WR_RELOAD)
398 // switch to alternate instruments :)
399 if(self.weaponentity.state == WS_READY)
401 switch(self.tuba_instrument)
404 self.tuba_instrument = 1;
405 self.weaponname = "akordeon";
408 self.tuba_instrument = 2;
409 self.weaponname = "kleinbottle";
412 self.tuba_instrument = 0;
413 self.weaponname = "tuba";
416 W_SetupShot(self, FALSE, 0, "", 0, 0);
417 pointparticles(particleeffectnum("teleport"), w_shotorg, '0 0 0', 1);
418 self.weaponentity.state = WS_INUSE;
419 weapon_thinkf(WFRAME_RELOAD, 0.5, w_ready);
422 else if (req == WR_CHECKAMMO1)
423 return TRUE; // TODO use fuel?
424 else if (req == WR_CHECKAMMO2)
425 return TRUE; // TODO use fuel?
426 else if (req == WR_SUICIDEMESSAGE)
428 if(w_deathtype & HITTYPE_BOUNCE)
429 return WEAPON_ACCORDEON_SUICIDE;
430 else if(w_deathtype & HITTYPE_SECONDARY)
431 return WEAPON_KLEINBOTTLE_SUICIDE;
433 return WEAPON_TUBA_SUICIDE;
435 else if (req == WR_KILLMESSAGE)
437 if(w_deathtype & HITTYPE_BOUNCE)
438 return WEAPON_ACCORDEON_MURDER;
439 else if(w_deathtype & HITTYPE_SECONDARY)
440 return WEAPON_KLEINBOTTLE_MURDER;
442 return WEAPON_TUBA_MURDER;
448 float w_tuba(float req)
450 if(req == WR_IMPACTEFFECT)
452 // nothing to do here; particles of tuba are handled differently
454 else if(req == WR_PRECACHE)
460 else if (req == WR_SUICIDEMESSAGE)
464 if(w_deathtype & HITTYPE_SECONDARY)
466 if(w_deathtype & HITTYPE_BOUNCE)
472 w_deathtypestring = _("%s hurt his own ears with the @!#%%'n Tuba");
475 w_deathtypestring = _("%s hurt his own ears with the @!#%%'n Accordeon");
477 case 2: // Klein Bottle
478 w_deathtypestring = _("%s hurt his own ears with the @!#%%'n Klein Bottle");
482 else if (req == WR_KILLMESSAGE)
486 if(w_deathtype & HITTYPE_SECONDARY)
488 if(w_deathtype & HITTYPE_BOUNCE)
494 w_deathtypestring = _("%s died of %s's great playing on the @!#%%'n Tuba");
497 w_deathtypestring = _("%s died of %s's great playing on the @!#%%'n Accordeon");
499 case 2: // Klein Bottle
500 w_deathtypestring = _("%s died of %s's great playing on the @!#%%'n Klein Bottle");
504 >>>>>>> origin/master*/