5 /* ammotype */ ammo_none,
7 /* flags */ WEP_FLAG_HIDDEN | WEP_TYPE_SPLASH,
8 /* rating */ BOT_PICKUP_RATING_MID,
10 /* modelname */ "tuba",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairtuba",
14 /* xgettext:no-c-format */
15 /* wepname */ _("@!#%'n Tuba")
18 #define TUBA_SETTINGS(w_cvar,w_prop) TUBA_SETTINGS_LIST(w_cvar, w_prop, TUBA, tuba)
19 #define TUBA_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20 w_cvar(id, sn, NONE, animtime) \
21 w_cvar(id, sn, NONE, attenuation) \
22 w_cvar(id, sn, NONE, damage) \
23 w_cvar(id, sn, NONE, edgedamage) \
24 w_cvar(id, sn, NONE, force) \
25 w_cvar(id, sn, NONE, radius) \
26 w_cvar(id, sn, NONE, refire) \
27 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
28 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
29 w_prop(id, sn, string, weaponreplace, weaponreplace) \
30 w_prop(id, sn, float, weaponstart, weaponstart) \
31 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride)
34 TUBA_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
36 .float tuba_smoketime;
37 .float tuba_instrument;
39 #define MAX_TUBANOTES 32
40 .float tuba_lastnotes_last;
41 .float tuba_lastnotes_cnt; // over
42 .vector tuba_lastnotes[MAX_TUBANOTES];
46 void spawnfunc_weapon_tuba (void) { weapon_defaultspawnfunc(WEP_TUBA); }
48 float W_Tuba_HasPlayed(entity pl, string melody, float instrument, float ignorepitch, float mintempo, float maxtempo)
50 float i, j, mmin, mmax, nolength;
51 float n = tokenize_console(melody);
52 if(n > pl.tuba_lastnotes_cnt)
57 if(pl.tuba_instrument != instrument)
62 for(i = 0; i < n; ++i)
64 vector v = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - i + MAX_TUBANOTES, MAX_TUBANOTES)]);
65 float ai = stof(argv(n - i - 1));
69 // n counts the last played notes BACKWARDS
73 if(ignorepitch && i == 0)
75 pitchshift = np - v_z;
79 if(v_z + pitchshift != np)
84 // now we know the right NOTES were played
90 mmin = 240 / maxtempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec
94 mmax = 240 / mintempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec
96 mmax = 240; // you won't try THAT hard... (tempo 1)
97 //printf("initial tempo rules: %f %f\n", mmin, mmax);
99 for(i = 0; i < n; ++i)
101 vector vi = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - i + MAX_TUBANOTES, MAX_TUBANOTES)]);
102 float ai = stof(argv(n - i - 1));
103 ti -= 1 / (ai - floor(ai));
105 for(j = i+1; j < n; ++j)
107 vector vj = pl.(tuba_lastnotes[mod(pl.tuba_lastnotes_last - j + MAX_TUBANOTES, MAX_TUBANOTES)]);
108 float aj = stof(argv(n - j - 1));
109 tj -= (aj - floor(aj));
111 // note i should be at m*ti+b
112 // note j should be at m*tj+b
114 // we have a LINE l, so that
115 // vi_x <= l(ti) <= vi_y
116 // vj_x <= l(tj) <= vj_y
119 // vi_x <= vi_y <= vj_x <= vj_y
121 //printf("first note: %f to %f, should be %f\n", vi_x, vi_y, ti);
122 //printf("second note: %f to %f, should be %f\n", vj_x, vj_y, tj);
123 //printf("m1 = %f\n", (vi_x - vj_y) / (ti - tj));
124 //printf("m2 = %f\n", (vi_y - vj_x) / (ti - tj));
125 mmin = max(mmin, (vi_x - vj_y) / (ti - tj)); // lower bound
126 mmax = min(mmax, (vi_y - vj_x) / (ti - tj)); // upper bound
130 if(mmin > mmax) // rhythm fail
134 pl.tuba_lastnotes_cnt = 0;
139 void W_Tuba_NoteOff()
142 // on: self.spawnshieldtime
145 if(self.owner.tuba_note == self)
147 self.owner.tuba_lastnotes_last = mod(self.owner.tuba_lastnotes_last + 1, MAX_TUBANOTES);
148 self.owner.(tuba_lastnotes[self.owner.tuba_lastnotes_last]) = eX * self.spawnshieldtime + eY * time + eZ * self.cnt;
149 self.owner.tuba_note = world;
150 self.owner.tuba_lastnotes_cnt = bound(0, self.owner.tuba_lastnotes_cnt + 1, MAX_TUBANOTES);
153 s = trigger_magicear_processmessage_forallears(self.owner, 0, world, string_null);
156 // simulate a server message
157 switch(self.tuba_instrument)
161 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Tuba: ^7", s, "\n"));
164 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Accordeon: ^7", s, "\n"));
167 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Klein Bottle: ^7", s, "\n"));
175 float W_Tuba_GetNote(entity pl, float hittype)
180 if(pl.movement_x < 0) movestate -= 3;
181 if(pl.movement_x > 0) movestate += 3;
182 if(pl.movement_y < 0) movestate -= 1;
183 if(pl.movement_y > 0) movestate += 1;
189 // layout: originally I wanted
193 // but then you only use forward and right key. So to make things more
194 // interesting, I swapped B with e#. Har har har...
198 case 1: note = -6; break; // Gb
199 case 2: note = -5; break; // G
200 case 3: note = -4; break; // G#
201 case 4: note = +5; break; // e#
203 case 5: note = 0; break; // c
204 case 6: note = +2; break; // d
205 case 7: note = +3; break; // eb
206 case 8: note = +4; break; // e
207 case 9: note = -1; break; // B
213 if(hittype & HITTYPE_SECONDARY)
216 // we support two kinds of tubas, those tuned in Eb and those tuned in C
217 // kind of tuba currently is player slot number, or team number if in
219 // that way, holes in the range of notes are "plugged"
222 if(pl.team == NUM_TEAM_2 || pl.team == NUM_TEAM_4)
227 if(pl.clientcolors & 1)
231 // total range of notes:
237 // *** ********************* ****
238 // -18.........................+12
239 // *** ********************* ****
240 // -18............................+15
241 // with jump: ... +24
246 float W_Tuba_NoteSendEntity(entity to, float sf)
251 if(!sound_allowed(MSG_ONE, self.realowner))
254 WriteByte(MSG_ENTITY, ENT_CLIENT_TUBANOTE);
255 WriteByte(MSG_ENTITY, sf);
258 WriteChar(MSG_ENTITY, self.cnt);
260 if(self.realowner != to)
262 f |= 2 * self.tuba_instrument;
263 WriteByte(MSG_ENTITY, f);
267 WriteCoord(MSG_ENTITY, self.origin_x);
268 WriteCoord(MSG_ENTITY, self.origin_y);
269 WriteCoord(MSG_ENTITY, self.origin_z);
274 void W_Tuba_NoteThink()
281 if(time > self.teleport_time)
286 self.nextthink = time;
287 dist_mult = WEP_CVAR(tuba, attenuation) / autocvar_snd_soundradius;
288 FOR_EACH_REALCLIENT(e)
289 if(e != self.realowner)
291 v = self.origin - (e.origin + e.view_ofs);
292 vol0 = max(0, 1 - vlen(v) * dist_mult);
294 v = self.realowner.origin - (e.origin + e.view_ofs);
295 vol1 = max(0, 1 - vlen(v) * dist_mult);
297 if(fabs(vol0 - vol1) > 0.005) // 0.5 percent change in volume
299 setorigin(self, self.realowner.origin);
303 if(dir0 * dir1 < 0.9994) // 2 degrees change in angle
305 setorigin(self, self.realowner.origin);
312 void W_Tuba_NoteOn(float hittype)
317 W_SetupShot(self, FALSE, 2, "", 0, WEP_CVAR(tuba, damage));
319 n = W_Tuba_GetNote(self, hittype);
322 if(self.tuba_instrument & 1)
323 hittype |= HITTYPE_SECONDARY;
324 if(self.tuba_instrument & 2)
325 hittype |= HITTYPE_BOUNCE;
329 if(self.tuba_note.cnt != n || self.tuba_note.tuba_instrument != self.tuba_instrument)
331 entity oldself = self;
332 self = self.tuba_note;
340 self.tuba_note = spawn();
341 self.tuba_note.owner = self.tuba_note.realowner = self;
342 self.tuba_note.cnt = n;
343 self.tuba_note.tuba_instrument = self.tuba_instrument;
344 self.tuba_note.think = W_Tuba_NoteThink;
345 self.tuba_note.nextthink = time;
346 self.tuba_note.spawnshieldtime = time;
347 Net_LinkEntity(self.tuba_note, FALSE, 0, W_Tuba_NoteSendEntity);
350 self.tuba_note.teleport_time = time + WEP_CVAR(tuba, refire) * 2 * W_WeaponRateFactor(); // so it can get prolonged safely
352 //sound(self, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), autocvar_g_balance_tuba_attenuation);
353 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);
355 o = gettaginfo(self.exteriorweaponentity, 0);
356 if(time > self.tuba_smoketime)
358 pointparticles(particleeffectnum("smoke_ring"), o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1);
359 self.tuba_smoketime = time + 0.25;
363 float W_Tuba(float req)
369 // bots cannot play the Tuba well yet
370 // I think they should start with the recorder first
371 if(vlen(self.origin - self.enemy.origin) < WEP_CVAR(tuba, radius))
374 self.BUTTON_ATCK = 1;
376 self.BUTTON_ATCK2 = 1;
383 if (self.BUTTON_ATCK)
384 if (weapon_prepareattack(0, WEP_CVAR(tuba, refire)))
387 //weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_tuba_animtime, w_ready);
388 weapon_thinkf(WFRAME_IDLE, WEP_CVAR(tuba, animtime), w_ready);
390 if (self.BUTTON_ATCK2)
391 if (weapon_prepareattack(1, WEP_CVAR(tuba, refire)))
393 W_Tuba_NoteOn(HITTYPE_SECONDARY);
394 //weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_tuba_animtime, w_ready);
395 weapon_thinkf(WFRAME_IDLE, WEP_CVAR(tuba, animtime), w_ready);
399 if(!self.BUTTON_ATCK && !self.BUTTON_ATCK2)
401 entity oldself = self;
402 self = self.tuba_note;
412 precache_model ("models/weapons/g_tuba.md3");
413 precache_model ("models/weapons/v_tuba.md3");
414 precache_model ("models/weapons/h_tuba.iqm");
415 precache_model ("models/weapons/v_akordeon.md3");
416 precache_model ("models/weapons/h_akordeon.iqm");
417 precache_model ("models/weapons/v_kleinbottle.md3");
418 precache_model ("models/weapons/h_kleinbottle.iqm");
419 TUBA_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
424 self.ammo_field = ammo_none;
425 self.tuba_instrument = 0;
430 // switch to alternate instruments :)
431 if(self.weaponentity.state == WS_READY)
433 switch(self.tuba_instrument)
436 self.tuba_instrument = 1;
437 self.weaponname = "akordeon";
440 self.tuba_instrument = 2;
441 self.weaponname = "kleinbottle";
444 self.tuba_instrument = 0;
445 self.weaponname = "tuba";
448 W_SetupShot(self, FALSE, 0, "", 0, 0);
449 pointparticles(particleeffectnum("teleport"), w_shotorg, '0 0 0', 1);
450 self.weaponentity.state = WS_INUSE;
451 weapon_thinkf(WFRAME_RELOAD, 0.5, w_ready);
459 return TRUE; // tuba has infinite ammo
463 TUBA_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
466 case WR_SUICIDEMESSAGE:
468 if(w_deathtype & HITTYPE_BOUNCE)
469 return WEAPON_KLEINBOTTLE_SUICIDE;
470 else if(w_deathtype & HITTYPE_SECONDARY)
471 return WEAPON_ACCORDEON_SUICIDE;
473 return WEAPON_TUBA_SUICIDE;
477 if(w_deathtype & HITTYPE_BOUNCE)
478 return WEAPON_KLEINBOTTLE_MURDER;
479 else if(w_deathtype & HITTYPE_SECONDARY)
480 return WEAPON_ACCORDEON_MURDER;
482 return WEAPON_TUBA_MURDER;
489 float W_Tuba(float req)
491 // nothing to do here; particles of tuba are handled differently
498 // no weapon specific image for this weapon