7 /* flags */ WEP_FLAG_HIDDEN | WEP_TYPE_SPLASH,
8 /* rating */ BOT_PICKUP_RATING_MID,
11 /* xgettext:no-c-format */
12 /* fullname */ _("@!#%'n Tuba")
15 #define TUBA_SETTINGS(weapon) \
16 WEP_ADD_CVAR(weapon, MO_NONE, animtime) \
17 WEP_ADD_CVAR(weapon, MO_NONE, attenuation) \
18 WEP_ADD_CVAR(weapon, MO_NONE, damage) \
19 WEP_ADD_CVAR(weapon, MO_NONE, edgedamage) \
20 WEP_ADD_CVAR(weapon, MO_NONE, force) \
21 WEP_ADD_CVAR(weapon, MO_NONE, radius) \
22 WEP_ADD_CVAR(weapon, MO_NONE, refire) \
23 WEP_ADD_PROP(weapon, reloading_ammo, reload_ammo) \
24 WEP_ADD_PROP(weapon, reloading_time, reload_time) \
25 WEP_ADD_PROP(weapon, switchdelay_raise, switchdelay_raise) \
26 WEP_ADD_PROP(weapon, switchdelay_drop, switchdelay_drop)
31 .float tuba_smoketime;
32 .float tuba_instrument;
34 #define MAX_TUBANOTES 32
35 .float tuba_lastnotes_last;
36 .float tuba_lastnotes_cnt; // over
37 .vector tuba_lastnotes[MAX_TUBANOTES];
41 void spawnfunc_weapon_tuba (void) { weapon_defaultspawnfunc(WEP_TUBA); }
43 float W_Tuba_HasPlayed(entity pl, string melody, float instrument, float ignorepitch, float mintempo, float maxtempo)
45 float i, j, mmin, mmax, nolength;
46 float n = tokenize_console(melody);
47 if(n > pl.tuba_lastnotes_cnt)
52 if(pl.tuba_instrument != instrument)
57 for(i = 0; i < n; ++i)
59 vector v = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - i + MAX_TUBANOTES, MAX_TUBANOTES)]);
60 float ai = stof(argv(n - i - 1));
64 // n counts the last played notes BACKWARDS
68 if(ignorepitch && i == 0)
70 pitchshift = np - v_z;
74 if(v_z + pitchshift != np)
79 // now we know the right NOTES were played
85 mmin = 240 / maxtempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec
89 mmax = 240 / mintempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec
91 mmax = 240; // you won't try THAT hard... (tempo 1)
92 //print(sprintf("initial tempo rules: %f %f\n", mmin, mmax));
94 for(i = 0; i < n; ++i)
96 vector vi = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - i + MAX_TUBANOTES, MAX_TUBANOTES)]);
97 float ai = stof(argv(n - i - 1));
98 ti -= 1 / (ai - floor(ai));
100 for(j = i+1; j < n; ++j)
102 vector vj = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - j + MAX_TUBANOTES, MAX_TUBANOTES)]);
103 float aj = stof(argv(n - j - 1));
104 tj -= (aj - floor(aj));
106 // note i should be at m*ti+b
107 // note j should be at m*tj+b
109 // we have a LINE l, so that
110 // vi_x <= l(ti) <= vi_y
111 // vj_x <= l(tj) <= vj_y
114 // vi_x <= vi_y <= vj_x <= vj_y
116 //print(sprintf("first note: %f to %f, should be %f\n", vi_x, vi_y, ti));
117 //print(sprintf("second note: %f to %f, should be %f\n", vj_x, vj_y, tj));
118 //print(sprintf("m1 = %f\n", (vi_x - vj_y) / (ti - tj)));
119 //print(sprintf("m2 = %f\n", (vi_y - vj_x) / (ti - tj)));
120 mmin = max(mmin, (vi_x - vj_y) / (ti - tj)); // lower bound
121 mmax = min(mmax, (vi_y - vj_x) / (ti - tj)); // upper bound
125 if(mmin > mmax) // rhythm fail
129 pl.tuba_lastnotes_cnt = 0;
134 void W_Tuba_NoteOff()
137 // on: self.spawnshieldtime
140 if(self.owner.tuba_note == self)
142 self.owner.tuba_lastnotes_last = mod(self.owner.tuba_lastnotes_last + 1, MAX_TUBANOTES);
143 self.owner.(tuba_lastnotes[self.owner.tuba_lastnotes_last]) = eX * self.spawnshieldtime + eY * time + eZ * self.cnt;
144 self.owner.tuba_note = world;
145 self.owner.tuba_lastnotes_cnt = bound(0, self.owner.tuba_lastnotes_cnt + 1, MAX_TUBANOTES);
148 s = trigger_magicear_processmessage_forallears(self.owner, 0, world, string_null);
151 // simulate a server message
152 switch(self.tuba_instrument)
156 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Tuba: ^7", s, "\n"));
159 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Accordeon: ^7", s, "\n"));
162 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Klein Bottle: ^7", s, "\n"));
170 float Tuba_GetNote(entity pl, float hittype)
175 if(pl.movement_x < 0) movestate -= 3;
176 if(pl.movement_x > 0) movestate += 3;
177 if(pl.movement_y < 0) movestate -= 1;
178 if(pl.movement_y > 0) movestate += 1;
184 // layout: originally I wanted
188 // but then you only use forward and right key. So to make things more
189 // interesting, I swapped B with e#. Har har har...
193 case 1: note = -6; break; // Gb
194 case 2: note = -5; break; // G
195 case 3: note = -4; break; // G#
196 case 4: note = +5; break; // e#
198 case 5: note = 0; break; // c
199 case 6: note = +2; break; // d
200 case 7: note = +3; break; // eb
201 case 8: note = +4; break; // e
202 case 9: note = -1; break; // B
208 if(hittype & HITTYPE_SECONDARY)
211 // we support two kinds of tubas, those tuned in Eb and those tuned in C
212 // kind of tuba currently is player slot number, or team number if in
214 // that way, holes in the range of notes are "plugged"
217 if(pl.team == NUM_TEAM_2 || pl.team == NUM_TEAM_4)
222 if(pl.clientcolors & 1)
226 // total range of notes:
232 // *** ********************* ****
233 // -18.........................+12
234 // *** ********************* ****
235 // -18............................+15
236 // with jump: ... +24
241 float W_Tuba_NoteSendEntity(entity to, float sf)
246 if(!sound_allowed(MSG_ONE, self.realowner))
249 WriteByte(MSG_ENTITY, ENT_CLIENT_TUBANOTE);
250 WriteByte(MSG_ENTITY, sf);
253 WriteChar(MSG_ENTITY, self.cnt);
255 if(self.realowner != to)
257 f |= 2 * self.tuba_instrument;
258 WriteByte(MSG_ENTITY, f);
262 WriteCoord(MSG_ENTITY, self.origin_x);
263 WriteCoord(MSG_ENTITY, self.origin_y);
264 WriteCoord(MSG_ENTITY, self.origin_z);
269 void W_Tuba_NoteThink()
276 if(time > self.teleport_time)
281 self.nextthink = time;
282 dist_mult = WEP_CVAR(tuba, attenuation) / autocvar_snd_soundradius;
283 FOR_EACH_REALCLIENT(e)
284 if(e != self.realowner)
286 v = self.origin - (e.origin + e.view_ofs);
287 vol0 = max(0, 1 - vlen(v) * dist_mult);
289 v = self.realowner.origin - (e.origin + e.view_ofs);
290 vol1 = max(0, 1 - vlen(v) * dist_mult);
292 if(fabs(vol0 - vol1) > 0.005) // 0.5 percent change in volume
294 setorigin(self, self.realowner.origin);
298 if(dir0 * dir1 < 0.9994) // 2 degrees change in angle
300 setorigin(self, self.realowner.origin);
307 void W_Tuba_NoteOn(float hittype)
312 W_SetupShot(self, FALSE, 2, "", 0, WEP_CVAR(tuba, damage));
314 n = Tuba_GetNote(self, hittype);
317 if(self.tuba_instrument & 1)
318 hittype |= HITTYPE_SECONDARY;
319 if(self.tuba_instrument & 2)
320 hittype |= HITTYPE_BOUNCE;
324 if(self.tuba_note.cnt != n || self.tuba_note.tuba_instrument != self.tuba_instrument)
326 entity oldself = self;
327 self = self.tuba_note;
335 self.tuba_note = spawn();
336 self.tuba_note.owner = self.tuba_note.realowner = self;
337 self.tuba_note.cnt = n;
338 self.tuba_note.tuba_instrument = self.tuba_instrument;
339 self.tuba_note.think = W_Tuba_NoteThink;
340 self.tuba_note.nextthink = time;
341 self.tuba_note.spawnshieldtime = time;
342 Net_LinkEntity(self.tuba_note, FALSE, 0, W_Tuba_NoteSendEntity);
345 self.tuba_note.teleport_time = time + WEP_CVAR(tuba, refire) * 2 * W_WeaponRateFactor(); // so it can get prolonged safely
347 //sound(self, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), autocvar_g_balance_tuba_attenuation);
348 RadiusDamage(self, self, WEP_CVAR(tuba, damage), WEP_CVAR(tuba, edgedamage), WEP_CVAR(tuba, radius), world, world, WEP_CVAR(tuba, force), hittype | WEP_TUBA, world);
350 o = gettaginfo(self.exteriorweaponentity, 0);
351 if(time > self.tuba_smoketime)
353 pointparticles(particleeffectnum("smoke_ring"), o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1);
354 self.tuba_smoketime = time + 0.25;
358 float w_tuba(float req)
364 // bots cannot play the Tuba well yet
365 // I think they should start with the recorder first
366 if(vlen(self.origin - self.enemy.origin) < WEP_CVAR(tuba, radius))
369 self.BUTTON_ATCK = 1;
371 self.BUTTON_ATCK2 = 1;
378 if (self.BUTTON_ATCK)
379 if (weapon_prepareattack(0, WEP_CVAR(tuba, refire)))
382 //weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_tuba_animtime, w_ready);
383 weapon_thinkf(WFRAME_IDLE, WEP_CVAR(tuba, animtime), w_ready);
385 if (self.BUTTON_ATCK2)
386 if (weapon_prepareattack(1, WEP_CVAR(tuba, refire)))
388 W_Tuba_NoteOn(HITTYPE_SECONDARY);
389 //weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_tuba_animtime, w_ready);
390 weapon_thinkf(WFRAME_IDLE, WEP_CVAR(tuba, animtime), w_ready);
394 if(!self.BUTTON_ATCK && !self.BUTTON_ATCK2)
396 entity oldself = self;
397 self = self.tuba_note;
407 precache_model ("models/weapons/g_tuba.md3");
408 precache_model ("models/weapons/v_tuba.md3");
409 precache_model ("models/weapons/h_tuba.iqm");
410 precache_model ("models/weapons/v_akordeon.md3");
411 precache_model ("models/weapons/h_akordeon.iqm");
412 precache_model ("models/weapons/v_kleinbottle.md3");
413 precache_model ("models/weapons/h_kleinbottle.iqm");
414 WEP_SET_PROPS(TUBA_SETTINGS(tuba), WEP_TUBA)
419 self.current_ammo = ammo_none;
420 self.tuba_instrument = 0;
425 // switch to alternate instruments :)
426 if(self.weaponentity.state == WS_READY)
428 switch(self.tuba_instrument)
431 self.tuba_instrument = 1;
432 self.weaponname = "akordeon";
435 self.tuba_instrument = 2;
436 self.weaponname = "kleinbottle";
439 self.tuba_instrument = 0;
440 self.weaponname = "tuba";
443 W_SetupShot(self, FALSE, 0, "", 0, 0);
444 pointparticles(particleeffectnum("teleport"), w_shotorg, '0 0 0', 1);
445 self.weaponentity.state = WS_INUSE;
446 weapon_thinkf(WFRAME_RELOAD, 0.5, w_ready);
454 return TRUE; // tuba has infinite ammo
458 WEP_CONFIG_SETTINGS(TUBA_SETTINGS(tuba))
461 case WR_SUICIDEMESSAGE:
463 if(w_deathtype & HITTYPE_BOUNCE)
464 return WEAPON_KLEINBOTTLE_SUICIDE;
465 else if(w_deathtype & HITTYPE_SECONDARY)
466 return WEAPON_ACCORDEON_SUICIDE;
468 return WEAPON_TUBA_SUICIDE;
472 if(w_deathtype & HITTYPE_BOUNCE)
473 return WEAPON_KLEINBOTTLE_MURDER;
474 else if(w_deathtype & HITTYPE_SECONDARY)
475 return WEAPON_ACCORDEON_MURDER;
477 return WEAPON_TUBA_MURDER;
484 float w_tuba(float req)
486 // nothing to do here; particles of tuba are handled differently