3 /* ammotype */ //ATTRIB(Tuba, ammo_field, .int, ammo_none)
4 /* impulse */ ATTRIB(Tuba, impulse, int, 1)
5 /* flags */ ATTRIB(Tuba, spawnflags, int, WEP_FLAG_HIDDEN | WEP_TYPE_SPLASH);
6 /* rating */ ATTRIB(Tuba, bot_pickupbasevalue, float, BOT_PICKUP_RATING_MID);
7 /* color */ ATTRIB(Tuba, wpcolor, vector, '0 1 0');
8 /* modelname */ ATTRIB(Tuba, mdl, string, "tuba");
10 /* model */ ATTRIB(Tuba, m_model, Model, MDL_TUBA_ITEM);
12 /* crosshair */ ATTRIB(Tuba, w_crosshair, string, "gfx/crosshairtuba");
13 /* crosshair */ //ATTRIB(Tuba, w_crosshair_size, float, 0.65);
14 /* wepimg */ ATTRIB(Tuba, model2, string, "weapontuba");
15 /* refname */ ATTRIB(Tuba, netname, string, "tuba");
16 /* xgettext:no-c-format */
17 /* wepname */ ATTRIB(Tuba, message, string, _("@!#%'n Tuba"));
19 REGISTER_WEAPON(TUBA, NEW(Tuba));
21 #define TUBA_SETTINGS(w_cvar,w_prop) TUBA_SETTINGS_LIST(w_cvar, w_prop, TUBA, tuba)
22 #define TUBA_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
23 w_cvar(id, sn, NONE, animtime) \
24 w_cvar(id, sn, NONE, attenuation) \
25 w_cvar(id, sn, NONE, damage) \
26 w_cvar(id, sn, NONE, edgedamage) \
27 w_cvar(id, sn, NONE, fadetime) \
28 w_cvar(id, sn, NONE, force) \
29 w_cvar(id, sn, NONE, pitchstep) \
30 w_cvar(id, sn, NONE, radius) \
31 w_cvar(id, sn, NONE, refire) \
32 w_cvar(id, sn, NONE, volume) \
33 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
34 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
35 w_prop(id, sn, string, weaponreplace, weaponreplace) \
36 w_prop(id, sn, float, weaponstart, weaponstart) \
37 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
38 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
41 TUBA_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
42 float W_Tuba_MarkClientOnlyFieldsAsUsed() {
43 // These variables are only used by client/tuba.qc. TODO: move client/tuba.qc code here.
44 return WEP_CVAR(tuba, fadetime) + WEP_CVAR(tuba, pitchstep) + WEP_CVAR(tuba, volume);
48 .float tuba_smoketime;
49 .float tuba_instrument;
51 #define MAX_TUBANOTES 32
52 .float tuba_lastnotes_last;
53 .float tuba_lastnotes_cnt; // over
54 .vector tuba_lastnotes[MAX_TUBANOTES];
59 spawnfunc(weapon_tuba) { weapon_defaultspawnfunc(this, WEP_TUBA); }
61 bool W_Tuba_HasPlayed(entity pl, string melody, int instrument, bool ignorepitch, float mintempo, float maxtempo)
63 float i, j, mmin, mmax, nolength;
64 float n = tokenize_console(melody);
65 if(n > pl.tuba_lastnotes_cnt)
70 if(pl.tuba_instrument != instrument)
75 for(i = 0; i < n; ++i)
77 vector v = pl.(tuba_lastnotes[(pl.tuba_lastnotes_last - i + MAX_TUBANOTES) % MAX_TUBANOTES]);
78 float ai = stof(argv(n - i - 1));
82 // n counts the last played notes BACKWARDS
86 if(ignorepitch && i == 0)
88 pitchshift = np - v.z;
92 if(v.z + pitchshift != np)
97 // now we know the right NOTES were played
103 mmin = 240 / maxtempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec
107 mmax = 240 / mintempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec
109 mmax = 240; // you won't try THAT hard... (tempo 1)
110 //printf("initial tempo rules: %f %f\n", mmin, mmax);
112 for(i = 0; i < n; ++i)
114 vector vi = pl.(tuba_lastnotes[(pl.tuba_lastnotes_last - i + MAX_TUBANOTES) % MAX_TUBANOTES]);
115 float ai = stof(argv(n - i - 1));
116 ti -= 1 / (ai - floor(ai));
118 for(j = i+1; j < n; ++j)
120 vector vj = pl.(tuba_lastnotes[(pl.tuba_lastnotes_last - j + MAX_TUBANOTES) % MAX_TUBANOTES]);
121 float aj = stof(argv(n - j - 1));
122 tj -= (aj - floor(aj));
124 // note i should be at m*ti+b
125 // note j should be at m*tj+b
127 // we have a LINE l, so that
128 // vi_x <= l(ti) <= vi_y
129 // vj_x <= l(tj) <= vj_y
132 // vi_x <= vi_y <= vj_x <= vj_y
134 //printf("first note: %f to %f, should be %f\n", vi_x, vi_y, ti);
135 //printf("second note: %f to %f, should be %f\n", vj_x, vj_y, tj);
136 //printf("m1 = %f\n", (vi_x - vj_y) / (ti - tj));
137 //printf("m2 = %f\n", (vi_y - vj_x) / (ti - tj));
138 mmin = max(mmin, (vi.x - vj.y) / (ti - tj)); // lower bound
139 mmax = min(mmax, (vi.y - vj.x) / (ti - tj)); // upper bound
143 if(mmin > mmax) // rhythm fail
147 pl.tuba_lastnotes_cnt = 0;
152 void W_Tuba_NoteOff(void)
155 // on: self.spawnshieldtime
158 if(self.owner.tuba_note == self)
160 self.owner.tuba_lastnotes_last = (self.owner.tuba_lastnotes_last + 1) % MAX_TUBANOTES;
161 self.owner.(tuba_lastnotes[self.owner.tuba_lastnotes_last]) = eX * self.spawnshieldtime + eY * time + eZ * self.cnt;
162 self.owner.tuba_note = world;
163 self.owner.tuba_lastnotes_cnt = bound(0, self.owner.tuba_lastnotes_cnt + 1, MAX_TUBANOTES);
166 s = trigger_magicear_processmessage_forallears(self.owner, 0, world, string_null);
169 // simulate a server message
170 switch(self.tuba_instrument)
174 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Tuba: ^7", s, "\n"));
177 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Accordeon: ^7", s, "\n"));
180 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Klein Bottle: ^7", s, "\n"));
188 int W_Tuba_GetNote(entity pl, int hittype)
191 if (pl.movement.x < 0) movestate -= 3;
192 else if (pl.movement.x > 0) movestate += 3;
193 if (pl.movement.y < 0) movestate -= 1;
194 else if (pl.movement.y > 0) movestate += 1;
199 // layout: originally I wanted
203 // but then you only use forward and right key. So to make things more
204 // interesting, I swapped B with e#. Har har har...
208 case 1: note = -6; break; // Gb
209 case 2: note = -5; break; // G
210 case 3: note = -4; break; // G#
211 case 4: note = +5; break; // e#
213 case 5: note = 0; break; // c
214 case 6: note = +2; break; // d
215 case 7: note = +3; break; // eb
216 case 8: note = +4; break; // e
217 case 9: note = -1; break; // B
223 if(hittype & HITTYPE_SECONDARY)
226 // we support two kinds of tubas, those tuned in Eb and those tuned in C
227 // kind of tuba currently is player slot number, or team number if in
229 // that way, holes in the range of notes are "plugged"
232 if(pl.team == NUM_TEAM_2 || pl.team == NUM_TEAM_4)
237 if(pl.clientcolors & 1)
241 // total range of notes:
247 // *** ********************* ****
248 // -18.........................+12
249 // *** ********************* ****
250 // -18............................+15
251 // with jump: ... +24
256 bool W_Tuba_NoteSendEntity(entity this, entity to, int sf)
261 if(!sound_allowed(MSG_ONE, self.realowner))
264 WriteByte(MSG_ENTITY, ENT_CLIENT_TUBANOTE);
265 WriteByte(MSG_ENTITY, sf);
268 WriteChar(MSG_ENTITY, self.cnt);
270 if(self.realowner != to)
272 f |= 2 * self.tuba_instrument;
273 WriteByte(MSG_ENTITY, f);
277 WriteCoord(MSG_ENTITY, self.origin.x);
278 WriteCoord(MSG_ENTITY, self.origin.y);
279 WriteCoord(MSG_ENTITY, self.origin.z);
284 void W_Tuba_NoteThink(void)
291 if(time > self.teleport_time)
296 self.nextthink = time;
297 dist_mult = WEP_CVAR(tuba, attenuation) / autocvar_snd_soundradius;
298 FOR_EACH_REALCLIENT(e)
299 if(e != self.realowner)
301 v = self.origin - (e.origin + e.view_ofs);
302 vol0 = max(0, 1 - vlen(v) * dist_mult);
304 v = self.realowner.origin - (e.origin + e.view_ofs);
305 vol1 = max(0, 1 - vlen(v) * dist_mult);
307 if(fabs(vol0 - vol1) > 0.005) // 0.5 percent change in volume
309 setorigin(self, self.realowner.origin);
313 if(dir0 * dir1 < 0.9994) // 2 degrees change in angle
315 setorigin(self, self.realowner.origin);
322 void W_Tuba_NoteOn(float hittype)
327 W_SetupShot(self, false, 2, "", 0, WEP_CVAR(tuba, damage));
329 n = W_Tuba_GetNote(self, hittype);
332 if(self.tuba_instrument & 1)
333 hittype |= HITTYPE_SECONDARY;
334 if(self.tuba_instrument & 2)
335 hittype |= HITTYPE_BOUNCE;
339 if(self.tuba_note.cnt != n || self.tuba_note.tuba_instrument != self.tuba_instrument)
341 WITH(entity, self, self.tuba_note, W_Tuba_NoteOff());
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.m_id, world);
362 o = gettaginfo(self.exteriorweaponentity, 0);
363 if(time > self.tuba_smoketime)
365 Send_Effect(EFFECT_SMOKE_RING, o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1);
366 self.tuba_smoketime = time + 0.25;
370 METHOD(Tuba, wr_aim, void(entity thiswep))
372 // bots cannot play the Tuba well yet
373 // I think they should start with the recorder first
374 if(vlen(self.origin - self.enemy.origin) < WEP_CVAR(tuba, radius))
377 self.BUTTON_ATCK = 1;
379 self.BUTTON_ATCK2 = 1;
382 METHOD(Tuba, wr_think, void(entity thiswep, entity actor, bool fire1, bool fire2))
385 if(weapon_prepareattack(thiswep, actor, false, WEP_CVAR(tuba, refire)))
388 //weapon_thinkf(actor, WFRAME_FIRE1, autocvar_g_balance_tuba_animtime, w_ready);
389 weapon_thinkf(actor, WFRAME_IDLE, WEP_CVAR(tuba, animtime), w_ready);
392 if(weapon_prepareattack(thiswep, actor, true, WEP_CVAR(tuba, refire)))
394 W_Tuba_NoteOn(HITTYPE_SECONDARY);
395 //weapon_thinkf(actor, WFRAME_FIRE2, autocvar_g_balance_tuba_animtime, w_ready);
396 weapon_thinkf(actor, WFRAME_IDLE, WEP_CVAR(tuba, animtime), w_ready);
402 WITH(entity, self, actor.tuba_note, W_Tuba_NoteOff());
406 METHOD(Tuba, wr_init, void(entity thiswep))
408 TUBA_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
410 METHOD(Tuba, wr_setup, void(entity thiswep))
412 self.ammo_field = ammo_none;
413 self.tuba_instrument = 0;
415 METHOD(Tuba, wr_reload, void(entity thiswep))
417 // switch to alternate instruments :)
418 if(self.weaponentity.state == WS_READY)
420 switch(self.tuba_instrument)
423 self.tuba_instrument = 1;
424 self.weaponname = "akordeon";
427 self.tuba_instrument = 2;
428 self.weaponname = "kleinbottle";
431 self.tuba_instrument = 0;
432 self.weaponname = "tuba";
435 W_SetupShot(self, false, 0, "", 0, 0);
436 Send_Effect(EFFECT_TELEPORT, w_shotorg, '0 0 0', 1);
437 self.weaponentity.state = WS_INUSE;
438 weapon_thinkf(self, WFRAME_RELOAD, 0.5, w_ready);
441 METHOD(Tuba, wr_checkammo1, bool(entity thiswep))
443 return true; // infinite ammo
445 METHOD(Tuba, wr_checkammo2, bool(entity thiswep))
447 return true; // tuba has infinite ammo
449 METHOD(Tuba, wr_config, void(entity thiswep))
451 TUBA_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
453 METHOD(Tuba, wr_suicidemessage, int(entity thiswep))
455 if(w_deathtype & HITTYPE_BOUNCE)
456 return WEAPON_KLEINBOTTLE_SUICIDE;
457 else if(w_deathtype & HITTYPE_SECONDARY)
458 return WEAPON_ACCORDEON_SUICIDE;
460 return WEAPON_TUBA_SUICIDE;
462 METHOD(Tuba, wr_killmessage, int(entity thiswep))
464 if(w_deathtype & HITTYPE_BOUNCE)
465 return WEAPON_KLEINBOTTLE_MURDER;
466 else if(w_deathtype & HITTYPE_SECONDARY)
467 return WEAPON_ACCORDEON_MURDER;
469 return WEAPON_TUBA_MURDER;