5 /* ammotype */ ammo_none,
7 /* flags */ WEP_FLAG_HIDDEN | WEP_TYPE_SPLASH,
8 /* rating */ BOT_PICKUP_RATING_MID,
10 /* modelname */ "tuba",
11 /* model */ MDL_TUBA_ITEM,
12 /* simplemdl */ "foobar",
13 /* crosshair */ "gfx/crosshairtuba",
14 /* wepimg */ "weapontuba",
16 /* xgettext:no-c-format */
17 /* wepname */ _("@!#%'n Tuba")
20 #define TUBA_SETTINGS(w_cvar,w_prop) TUBA_SETTINGS_LIST(w_cvar, w_prop, TUBA, tuba)
21 #define TUBA_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
22 w_cvar(id, sn, NONE, animtime) \
23 w_cvar(id, sn, NONE, attenuation) \
24 w_cvar(id, sn, NONE, damage) \
25 w_cvar(id, sn, NONE, edgedamage) \
26 w_cvar(id, sn, NONE, fadetime) \
27 w_cvar(id, sn, NONE, force) \
28 w_cvar(id, sn, NONE, pitchstep) \
29 w_cvar(id, sn, NONE, radius) \
30 w_cvar(id, sn, NONE, refire) \
31 w_cvar(id, sn, NONE, volume) \
32 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
33 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
34 w_prop(id, sn, string, weaponreplace, weaponreplace) \
35 w_prop(id, sn, float, weaponstart, weaponstart) \
36 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
37 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
40 TUBA_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
41 float W_Tuba_MarkClientOnlyFieldsAsUsed() {
42 // These variables are only used by client/tuba.qc. TODO: move client/tuba.qc code here.
43 return WEP_CVAR(tuba, fadetime) + WEP_CVAR(tuba, pitchstep) + WEP_CVAR(tuba, volume);
47 .float tuba_smoketime;
48 .float tuba_instrument;
50 #define MAX_TUBANOTES 32
51 .float tuba_lastnotes_last;
52 .float tuba_lastnotes_cnt; // over
53 .vector tuba_lastnotes[MAX_TUBANOTES];
58 void spawnfunc_weapon_tuba(void) { weapon_defaultspawnfunc(WEP_TUBA.m_id); }
60 bool W_Tuba_HasPlayed(entity pl, string melody, int instrument, bool ignorepitch, float mintempo, float maxtempo)
62 float i, j, mmin, mmax, nolength;
63 float n = tokenize_console(melody);
64 if(n > pl.tuba_lastnotes_cnt)
69 if(pl.tuba_instrument != instrument)
74 for(i = 0; i < n; ++i)
76 vector v = pl.(tuba_lastnotes[(pl.tuba_lastnotes_last - i + MAX_TUBANOTES) % MAX_TUBANOTES]);
77 float ai = stof(argv(n - i - 1));
81 // n counts the last played notes BACKWARDS
85 if(ignorepitch && i == 0)
87 pitchshift = np - v.z;
91 if(v.z + pitchshift != np)
96 // now we know the right NOTES were played
102 mmin = 240 / maxtempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec
106 mmax = 240 / mintempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec
108 mmax = 240; // you won't try THAT hard... (tempo 1)
109 //printf("initial tempo rules: %f %f\n", mmin, mmax);
111 for(i = 0; i < n; ++i)
113 vector vi = pl.(tuba_lastnotes[(pl.tuba_lastnotes_last - i + MAX_TUBANOTES) % MAX_TUBANOTES]);
114 float ai = stof(argv(n - i - 1));
115 ti -= 1 / (ai - floor(ai));
117 for(j = i+1; j < n; ++j)
119 vector vj = pl.(tuba_lastnotes[(pl.tuba_lastnotes_last - j + MAX_TUBANOTES) % MAX_TUBANOTES]);
120 float aj = stof(argv(n - j - 1));
121 tj -= (aj - floor(aj));
123 // note i should be at m*ti+b
124 // note j should be at m*tj+b
126 // we have a LINE l, so that
127 // vi_x <= l(ti) <= vi_y
128 // vj_x <= l(tj) <= vj_y
131 // vi_x <= vi_y <= vj_x <= vj_y
133 //printf("first note: %f to %f, should be %f\n", vi_x, vi_y, ti);
134 //printf("second note: %f to %f, should be %f\n", vj_x, vj_y, tj);
135 //printf("m1 = %f\n", (vi_x - vj_y) / (ti - tj));
136 //printf("m2 = %f\n", (vi_y - vj_x) / (ti - tj));
137 mmin = max(mmin, (vi.x - vj.y) / (ti - tj)); // lower bound
138 mmax = min(mmax, (vi.y - vj.x) / (ti - tj)); // upper bound
142 if(mmin > mmax) // rhythm fail
146 pl.tuba_lastnotes_cnt = 0;
151 void W_Tuba_NoteOff(void)
154 // on: self.spawnshieldtime
157 if(self.owner.tuba_note == self)
159 self.owner.tuba_lastnotes_last = (self.owner.tuba_lastnotes_last + 1) % MAX_TUBANOTES;
160 self.owner.(tuba_lastnotes[self.owner.tuba_lastnotes_last]) = eX * self.spawnshieldtime + eY * time + eZ * self.cnt;
161 self.owner.tuba_note = world;
162 self.owner.tuba_lastnotes_cnt = bound(0, self.owner.tuba_lastnotes_cnt + 1, MAX_TUBANOTES);
165 s = trigger_magicear_processmessage_forallears(self.owner, 0, world, string_null);
168 // simulate a server message
169 switch(self.tuba_instrument)
173 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Tuba: ^7", s, "\n"));
176 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Accordeon: ^7", s, "\n"));
179 bprint(strcat("\{1}\{13}* ^3", self.owner.netname, "^3 played on the @!#%'n Klein Bottle: ^7", s, "\n"));
187 int W_Tuba_GetNote(entity pl, int hittype)
190 if (pl.movement.x < 0) movestate -= 3;
191 else if (pl.movement.x > 0) movestate += 3;
192 if (pl.movement.y < 0) movestate -= 1;
193 else if (pl.movement.y > 0) movestate += 1;
198 // layout: originally I wanted
202 // but then you only use forward and right key. So to make things more
203 // interesting, I swapped B with e#. Har har har...
207 case 1: note = -6; break; // Gb
208 case 2: note = -5; break; // G
209 case 3: note = -4; break; // G#
210 case 4: note = +5; break; // e#
212 case 5: note = 0; break; // c
213 case 6: note = +2; break; // d
214 case 7: note = +3; break; // eb
215 case 8: note = +4; break; // e
216 case 9: note = -1; break; // B
222 if(hittype & HITTYPE_SECONDARY)
225 // we support two kinds of tubas, those tuned in Eb and those tuned in C
226 // kind of tuba currently is player slot number, or team number if in
228 // that way, holes in the range of notes are "plugged"
231 if(pl.team == NUM_TEAM_2 || pl.team == NUM_TEAM_4)
236 if(pl.clientcolors & 1)
240 // total range of notes:
246 // *** ********************* ****
247 // -18.........................+12
248 // *** ********************* ****
249 // -18............................+15
250 // with jump: ... +24
255 bool W_Tuba_NoteSendEntity(entity to, int sf)
260 if(!sound_allowed(MSG_ONE, self.realowner))
263 WriteByte(MSG_ENTITY, ENT_CLIENT_TUBANOTE);
264 WriteByte(MSG_ENTITY, sf);
267 WriteChar(MSG_ENTITY, self.cnt);
269 if(self.realowner != to)
271 f |= 2 * self.tuba_instrument;
272 WriteByte(MSG_ENTITY, f);
276 WriteCoord(MSG_ENTITY, self.origin.x);
277 WriteCoord(MSG_ENTITY, self.origin.y);
278 WriteCoord(MSG_ENTITY, self.origin.z);
283 void W_Tuba_NoteThink(void)
290 if(time > self.teleport_time)
295 self.nextthink = time;
296 dist_mult = WEP_CVAR(tuba, attenuation) / autocvar_snd_soundradius;
297 FOR_EACH_REALCLIENT(e)
298 if(e != self.realowner)
300 v = self.origin - (e.origin + e.view_ofs);
301 vol0 = max(0, 1 - vlen(v) * dist_mult);
303 v = self.realowner.origin - (e.origin + e.view_ofs);
304 vol1 = max(0, 1 - vlen(v) * dist_mult);
306 if(fabs(vol0 - vol1) > 0.005) // 0.5 percent change in volume
308 setorigin(self, self.realowner.origin);
312 if(dir0 * dir1 < 0.9994) // 2 degrees change in angle
314 setorigin(self, self.realowner.origin);
321 void W_Tuba_NoteOn(float hittype)
326 W_SetupShot(self, false, 2, "", 0, WEP_CVAR(tuba, damage));
328 n = W_Tuba_GetNote(self, hittype);
331 if(self.tuba_instrument & 1)
332 hittype |= HITTYPE_SECONDARY;
333 if(self.tuba_instrument & 2)
334 hittype |= HITTYPE_BOUNCE;
338 if(self.tuba_note.cnt != n || self.tuba_note.tuba_instrument != self.tuba_instrument)
340 WITH(entity, self, self.tuba_note, W_Tuba_NoteOff());
346 self.tuba_note = spawn();
347 self.tuba_note.owner = self.tuba_note.realowner = self;
348 self.tuba_note.cnt = n;
349 self.tuba_note.tuba_instrument = self.tuba_instrument;
350 self.tuba_note.think = W_Tuba_NoteThink;
351 self.tuba_note.nextthink = time;
352 self.tuba_note.spawnshieldtime = time;
353 Net_LinkEntity(self.tuba_note, false, 0, W_Tuba_NoteSendEntity);
356 self.tuba_note.teleport_time = time + WEP_CVAR(tuba, refire) * 2 * W_WeaponRateFactor(); // so it can get prolonged safely
358 //sound(self, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), autocvar_g_balance_tuba_attenuation);
359 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);
361 o = gettaginfo(self.exteriorweaponentity, 0);
362 if(time > self.tuba_smoketime)
364 Send_Effect(EFFECT_SMOKE_RING, o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1);
365 self.tuba_smoketime = time + 0.25;
369 bool W_Tuba(entity thiswep, int req)
375 // bots cannot play the Tuba well yet
376 // I think they should start with the recorder first
377 if(vlen(self.origin - self.enemy.origin) < WEP_CVAR(tuba, radius))
380 self.BUTTON_ATCK = 1;
382 self.BUTTON_ATCK2 = 1;
390 if(weapon_prepareattack(0, WEP_CVAR(tuba, refire)))
393 //weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_tuba_animtime, w_ready);
394 weapon_thinkf(WFRAME_IDLE, WEP_CVAR(tuba, animtime), w_ready);
396 if(self.BUTTON_ATCK2)
397 if(weapon_prepareattack(1, WEP_CVAR(tuba, refire)))
399 W_Tuba_NoteOn(HITTYPE_SECONDARY);
400 //weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_tuba_animtime, w_ready);
401 weapon_thinkf(WFRAME_IDLE, WEP_CVAR(tuba, animtime), w_ready);
405 if(!self.BUTTON_ATCK && !self.BUTTON_ATCK2)
407 WITH(entity, self, self.tuba_note, W_Tuba_NoteOff());
415 TUBA_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
420 self.ammo_field = ammo_none;
421 self.tuba_instrument = 0;
426 // switch to alternate instruments :)
427 if(self.weaponentity.state == WS_READY)
429 switch(self.tuba_instrument)
432 self.tuba_instrument = 1;
433 self.weaponname = "akordeon";
436 self.tuba_instrument = 2;
437 self.weaponname = "kleinbottle";
440 self.tuba_instrument = 0;
441 self.weaponname = "tuba";
444 W_SetupShot(self, false, 0, "", 0, 0);
445 Send_Effect(EFFECT_TELEPORT, w_shotorg, '0 0 0', 1);
446 self.weaponentity.state = WS_INUSE;
447 weapon_thinkf(WFRAME_RELOAD, 0.5, w_ready);
455 return true; // tuba has infinite ammo
459 TUBA_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
462 case WR_SUICIDEMESSAGE:
464 if(w_deathtype & HITTYPE_BOUNCE)
465 return WEAPON_KLEINBOTTLE_SUICIDE;
466 else if(w_deathtype & HITTYPE_SECONDARY)
467 return WEAPON_ACCORDEON_SUICIDE;
469 return WEAPON_TUBA_SUICIDE;
473 if(w_deathtype & HITTYPE_BOUNCE)
474 return WEAPON_KLEINBOTTLE_MURDER;
475 else if(w_deathtype & HITTYPE_SECONDARY)
476 return WEAPON_ACCORDEON_MURDER;
478 return WEAPON_TUBA_MURDER;
485 bool W_Tuba(entity thiswep, int req)
487 // nothing to do here; particles of tuba are handled differently
494 // no weapon specific image for this weapon