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",
13 /* wepimg */ "weapontuba",
15 /* xgettext:no-c-format */
16 /* wepname */ _("@!#%'n Tuba")
19 #define TUBA_SETTINGS(w_cvar,w_prop) TUBA_SETTINGS_LIST(w_cvar, w_prop, TUBA, tuba)
20 #define TUBA_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
21 w_cvar(id, sn, NONE, animtime) \
22 w_cvar(id, sn, NONE, attenuation) \
23 w_cvar(id, sn, NONE, damage) \
24 w_cvar(id, sn, NONE, edgedamage) \
25 w_cvar(id, sn, NONE, fadetime) \
26 w_cvar(id, sn, NONE, force) \
27 w_cvar(id, sn, NONE, pitchstep) \
28 w_cvar(id, sn, NONE, radius) \
29 w_cvar(id, sn, NONE, refire) \
30 w_cvar(id, sn, NONE, volume) \
31 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
32 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
33 w_prop(id, sn, string, weaponreplace, weaponreplace) \
34 w_prop(id, sn, float, weaponstart, weaponstart) \
35 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
36 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
39 TUBA_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
40 float W_Tuba_MarkClientOnlyFieldsAsUsed() {
41 // These variables are only used by client/tuba.qc. TODO: move client/tuba.qc code here.
42 return WEP_CVAR(tuba, fadetime) + WEP_CVAR(tuba, pitchstep) + WEP_CVAR(tuba, volume);
46 .float tuba_smoketime;
47 .float tuba_instrument;
49 #define MAX_TUBANOTES 32
50 .float tuba_lastnotes_last;
51 .float tuba_lastnotes_cnt; // over
52 .vector tuba_lastnotes[MAX_TUBANOTES];
56 void spawnfunc_weapon_tuba(void) { weapon_defaultspawnfunc(WEP_TUBA); }
58 float W_Tuba_HasPlayed(entity pl, string melody, float instrument, float ignorepitch, float mintempo, float maxtempo)
60 float i, j, mmin, mmax, nolength;
61 float n = tokenize_console(melody);
62 if(n > pl.tuba_lastnotes_cnt)
67 if(pl.tuba_instrument != instrument)
72 for(i = 0; i < n; ++i)
74 vector v = pl.(tuba_lastnotes[(pl.tuba_lastnotes_last - i + MAX_TUBANOTES) % MAX_TUBANOTES]);
75 float ai = stof(argv(n - i - 1));
79 // n counts the last played notes BACKWARDS
83 if(ignorepitch && i == 0)
85 pitchshift = np - v.z;
89 if(v.z + pitchshift != np)
94 // now we know the right NOTES were played
100 mmin = 240 / maxtempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec
104 mmax = 240 / mintempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec
106 mmax = 240; // you won't try THAT hard... (tempo 1)
107 //printf("initial tempo rules: %f %f\n", mmin, mmax);
109 for(i = 0; i < n; ++i)
111 vector vi = pl.(tuba_lastnotes[(pl.tuba_lastnotes_last - i + MAX_TUBANOTES) % MAX_TUBANOTES]);
112 float ai = stof(argv(n - i - 1));
113 ti -= 1 / (ai - floor(ai));
115 for(j = i+1; j < n; ++j)
117 vector vj = pl.(tuba_lastnotes[(pl.tuba_lastnotes_last - j + MAX_TUBANOTES) % MAX_TUBANOTES]);
118 float aj = stof(argv(n - j - 1));
119 tj -= (aj - floor(aj));
121 // note i should be at m*ti+b
122 // note j should be at m*tj+b
124 // we have a LINE l, so that
125 // vi_x <= l(ti) <= vi_y
126 // vj_x <= l(tj) <= vj_y
129 // vi_x <= vi_y <= vj_x <= vj_y
131 //printf("first note: %f to %f, should be %f\n", vi_x, vi_y, ti);
132 //printf("second note: %f to %f, should be %f\n", vj_x, vj_y, tj);
133 //printf("m1 = %f\n", (vi_x - vj_y) / (ti - tj));
134 //printf("m2 = %f\n", (vi_y - vj_x) / (ti - tj));
135 mmin = max(mmin, (vi.x - vj.y) / (ti - tj)); // lower bound
136 mmax = min(mmax, (vi.y - vj.x) / (ti - tj)); // upper bound
140 if(mmin > mmax) // rhythm fail
144 pl.tuba_lastnotes_cnt = 0;
149 void W_Tuba_NoteOff(void)
152 // on: self.spawnshieldtime
155 if(self.owner.tuba_note == self)
157 self.owner.tuba_lastnotes_last = (self.owner.tuba_lastnotes_last + 1) % MAX_TUBANOTES;
158 self.owner.(tuba_lastnotes[self.owner.tuba_lastnotes_last]) = eX * self.spawnshieldtime + eY * time + eZ * self.cnt;
159 self.owner.tuba_note = world;
160 self.owner.tuba_lastnotes_cnt = bound(0, self.owner.tuba_lastnotes_cnt + 1, MAX_TUBANOTES);
163 s = trigger_magicear_processmessage_forallears(self.owner, 0, world, string_null);
166 // simulate a server message
167 switch(self.tuba_instrument)
171 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Tuba: ^7", s, "\n"));
174 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Accordeon: ^7", s, "\n"));
177 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Klein Bottle: ^7", s, "\n"));
185 float W_Tuba_GetNote(entity pl, float hittype)
188 if (pl.movement.x < 0) movestate -= 3;
189 else if (pl.movement.x > 0) movestate += 3;
190 if (pl.movement.y < 0) movestate -= 1;
191 else if (pl.movement.y > 0) movestate += 1;
196 // layout: originally I wanted
200 // but then you only use forward and right key. So to make things more
201 // interesting, I swapped B with e#. Har har har...
205 case 1: note = -6; break; // Gb
206 case 2: note = -5; break; // G
207 case 3: note = -4; break; // G#
208 case 4: note = +5; break; // e#
210 case 5: note = 0; break; // c
211 case 6: note = +2; break; // d
212 case 7: note = +3; break; // eb
213 case 8: note = +4; break; // e
214 case 9: note = -1; break; // B
220 if(hittype & HITTYPE_SECONDARY)
223 // we support two kinds of tubas, those tuned in Eb and those tuned in C
224 // kind of tuba currently is player slot number, or team number if in
226 // that way, holes in the range of notes are "plugged"
229 if(pl.team == NUM_TEAM_2 || pl.team == NUM_TEAM_4)
234 if(pl.clientcolors & 1)
238 // total range of notes:
244 // *** ********************* ****
245 // -18.........................+12
246 // *** ********************* ****
247 // -18............................+15
248 // with jump: ... +24
253 float W_Tuba_NoteSendEntity(entity to, float sf)
258 if(!sound_allowed(MSG_ONE, self.realowner))
261 WriteByte(MSG_ENTITY, ENT_CLIENT_TUBANOTE);
262 WriteByte(MSG_ENTITY, sf);
265 WriteChar(MSG_ENTITY, self.cnt);
267 if(self.realowner != to)
269 f |= 2 * self.tuba_instrument;
270 WriteByte(MSG_ENTITY, f);
274 WriteCoord(MSG_ENTITY, self.origin.x);
275 WriteCoord(MSG_ENTITY, self.origin.y);
276 WriteCoord(MSG_ENTITY, self.origin.z);
281 void W_Tuba_NoteThink(void)
288 if(time > self.teleport_time)
293 self.nextthink = time;
294 dist_mult = WEP_CVAR(tuba, attenuation) / autocvar_snd_soundradius;
295 FOR_EACH_REALCLIENT(e)
296 if(e != self.realowner)
298 v = self.origin - (e.origin + e.view_ofs);
299 vol0 = max(0, 1 - vlen(v) * dist_mult);
301 v = self.realowner.origin - (e.origin + e.view_ofs);
302 vol1 = max(0, 1 - vlen(v) * dist_mult);
304 if(fabs(vol0 - vol1) > 0.005) // 0.5 percent change in volume
306 setorigin(self, self.realowner.origin);
310 if(dir0 * dir1 < 0.9994) // 2 degrees change in angle
312 setorigin(self, self.realowner.origin);
319 void W_Tuba_NoteOn(float hittype)
324 W_SetupShot(self, false, 2, "", 0, WEP_CVAR(tuba, damage));
326 n = W_Tuba_GetNote(self, hittype);
329 if(self.tuba_instrument & 1)
330 hittype |= HITTYPE_SECONDARY;
331 if(self.tuba_instrument & 2)
332 hittype |= HITTYPE_BOUNCE;
336 if(self.tuba_note.cnt != n || self.tuba_note.tuba_instrument != self.tuba_instrument)
338 entity oldself = self;
339 self = self.tuba_note;
347 self.tuba_note = spawn();
348 self.tuba_note.owner = self.tuba_note.realowner = self;
349 self.tuba_note.cnt = n;
350 self.tuba_note.tuba_instrument = self.tuba_instrument;
351 self.tuba_note.think = W_Tuba_NoteThink;
352 self.tuba_note.nextthink = time;
353 self.tuba_note.spawnshieldtime = time;
354 Net_LinkEntity(self.tuba_note, false, 0, W_Tuba_NoteSendEntity);
357 self.tuba_note.teleport_time = time + WEP_CVAR(tuba, refire) * 2 * W_WeaponRateFactor(); // so it can get prolonged safely
359 //sound(self, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), autocvar_g_balance_tuba_attenuation);
360 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);
362 o = gettaginfo(self.exteriorweaponentity, 0);
363 if(time > self.tuba_smoketime)
365 pointparticles(particleeffectnum("smoke_ring"), o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1);
366 self.tuba_smoketime = time + 0.25;
370 float W_Tuba(float req)
376 // bots cannot play the Tuba well yet
377 // I think they should start with the recorder first
378 if(vlen(self.origin - self.enemy.origin) < WEP_CVAR(tuba, radius))
381 self.BUTTON_ATCK = 1;
383 self.BUTTON_ATCK2 = 1;
391 if(weapon_prepareattack(0, WEP_CVAR(tuba, refire)))
394 //weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_tuba_animtime, w_ready);
395 weapon_thinkf(WFRAME_IDLE, WEP_CVAR(tuba, animtime), w_ready);
397 if(self.BUTTON_ATCK2)
398 if(weapon_prepareattack(1, WEP_CVAR(tuba, refire)))
400 W_Tuba_NoteOn(HITTYPE_SECONDARY);
401 //weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_tuba_animtime, w_ready);
402 weapon_thinkf(WFRAME_IDLE, WEP_CVAR(tuba, animtime), w_ready);
406 if(!self.BUTTON_ATCK && !self.BUTTON_ATCK2)
408 entity oldself = self;
409 self = self.tuba_note;
419 precache_model("models/weapons/g_tuba.md3");
420 precache_model("models/weapons/v_tuba.md3");
421 precache_model("models/weapons/h_tuba.iqm");
422 precache_model("models/weapons/v_akordeon.md3");
423 precache_model("models/weapons/h_akordeon.iqm");
424 precache_model("models/weapons/v_kleinbottle.md3");
425 precache_model("models/weapons/h_kleinbottle.iqm");
426 TUBA_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
431 self.ammo_field = ammo_none;
432 self.tuba_instrument = 0;
437 // switch to alternate instruments :)
438 if(self.weaponentity.state == WS_READY)
440 switch(self.tuba_instrument)
443 self.tuba_instrument = 1;
444 self.weaponname = "akordeon";
447 self.tuba_instrument = 2;
448 self.weaponname = "kleinbottle";
451 self.tuba_instrument = 0;
452 self.weaponname = "tuba";
455 W_SetupShot(self, false, 0, "", 0, 0);
456 pointparticles(particleeffectnum("teleport"), w_shotorg, '0 0 0', 1);
457 self.weaponentity.state = WS_INUSE;
458 weapon_thinkf(WFRAME_RELOAD, 0.5, w_ready);
466 return true; // tuba has infinite ammo
470 TUBA_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
473 case WR_SUICIDEMESSAGE:
475 if(w_deathtype & HITTYPE_BOUNCE)
476 return WEAPON_KLEINBOTTLE_SUICIDE;
477 else if(w_deathtype & HITTYPE_SECONDARY)
478 return WEAPON_ACCORDEON_SUICIDE;
480 return WEAPON_TUBA_SUICIDE;
484 if(w_deathtype & HITTYPE_BOUNCE)
485 return WEAPON_KLEINBOTTLE_MURDER;
486 else if(w_deathtype & HITTYPE_SECONDARY)
487 return WEAPON_ACCORDEON_MURDER;
489 return WEAPON_TUBA_MURDER;
496 float W_Tuba(float req)
498 // nothing to do here; particles of tuba are handled differently
505 // no weapon specific image for this weapon