]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/tuba.qc
Set the weaponmodel every frame again, instead change the tuba's mdl when the user...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / tuba.qc
1 #ifndef IMPLEMENTATION
2 CLASS(Tuba, Weapon)
3 /* impulse   */ ATTRIB(Tuba, impulse, int, 1);
4 /* flags     */ ATTRIB(Tuba, spawnflags, int, WEP_FLAG_HIDDEN | WEP_TYPE_SPLASH);
5 /* rating    */ ATTRIB(Tuba, bot_pickupbasevalue, float, BOT_PICKUP_RATING_MID);
6 /* color     */ ATTRIB(Tuba, wpcolor, vector, '0 1 0');
7 /* modelname */ ATTRIB(Tuba, mdl, string, "tuba");
8 #ifndef MENUQC
9 /* model     */ ATTRIB(Tuba, m_model, Model, MDL_TUBA_ITEM);
10 #endif
11 /* crosshair */ ATTRIB(Tuba, w_crosshair, string, "gfx/crosshairtuba");
12 /* crosshair */ //ATTRIB(Tuba, w_crosshair_size, float, 0.65);
13 /* wepimg    */ ATTRIB(Tuba, model2, string, "weapontuba");
14 /* refname   */ ATTRIB(Tuba, netname, string, "tuba");
15 /* xgettext:no-c-format */
16 /* wepname   */ ATTRIB(Tuba, m_name, string, _("@!#%'n Tuba"));
17
18 #define X(BEGIN, P, END, class, prefix) \
19         BEGIN(class) \
20                 P(class, prefix, animtime, float, NONE) \
21                 P(class, prefix, attenuation, float, NONE) \
22                 P(class, prefix, damage, float, NONE) \
23                 P(class, prefix, edgedamage, float, NONE) \
24                 P(class, prefix, fadetime, float, NONE) \
25                 P(class, prefix, force, float, NONE) \
26                 P(class, prefix, pitchstep, float, NONE) \
27                 P(class, prefix, radius, float, NONE) \
28                 P(class, prefix, refire, float, NONE) \
29                 P(class, prefix, switchdelay_drop, float, NONE) \
30                 P(class, prefix, switchdelay_raise, float, NONE) \
31                 P(class, prefix, volume, float, NONE) \
32                 P(class, prefix, weaponreplace, string, NONE) \
33                 P(class, prefix, weaponstartoverride, float, NONE) \
34                 P(class, prefix, weaponstart, float, NONE) \
35                 P(class, prefix, weaponthrowable, float, NONE) \
36         END()
37     W_PROPS(X, Tuba, tuba)
38 #undef X
39 ENDCLASS(Tuba)
40 REGISTER_WEAPON(TUBA, tuba, NEW(Tuba));
41 #endif
42
43 #ifdef IMPLEMENTATION
44
45 #ifdef SVQC
46
47 .entity tuba_note;
48 .float tuba_smoketime;
49 .float tuba_instrument;
50
51 #define MAX_TUBANOTES 32
52 .float tuba_lastnotes_last;
53 .float tuba_lastnotes_cnt; // over
54 .vector tuba_lastnotes[MAX_TUBANOTES];
55
56 spawnfunc(weapon_tuba) { weapon_defaultspawnfunc(this, WEP_TUBA); }
57
58 bool W_Tuba_HasPlayed(entity pl, string melody, int instrument, bool ignorepitch, float mintempo, float maxtempo)
59 {
60         float i, j, mmin, mmax, nolength;
61         float n = tokenize_console(melody);
62         if(n > pl.tuba_lastnotes_cnt)
63                 return false;
64         float pitchshift = 0;
65
66         if(instrument >= 0)
67                 if(pl.tuba_instrument != instrument)
68                         return false;
69
70         // verify notes...
71         nolength = false;
72         for(i = 0; i < n; ++i)
73         {
74                 vector v = pl.(tuba_lastnotes[(pl.tuba_lastnotes_last - i + MAX_TUBANOTES) % MAX_TUBANOTES]);
75                 float ai = stof(argv(n - i - 1));
76                 float np = floor(ai);
77                 if(ai == np)
78                         nolength = true;
79                 // n counts the last played notes BACKWARDS
80                 // _x is start
81                 // _y is end
82                 // _z is note pitch
83                 if(ignorepitch && i == 0)
84                 {
85                         pitchshift = np - v.z;
86                 }
87                 else
88                 {
89                         if(v.z + pitchshift != np)
90                                 return false;
91                 }
92         }
93
94         // now we know the right NOTES were played
95         if(!nolength)
96         {
97                 // verify rhythm...
98                 float ti = 0;
99                 if(maxtempo > 0)
100                         mmin = 240 / maxtempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec
101                 else
102                         mmin = 0;
103                 if(mintempo > 0)
104                         mmax = 240 / mintempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec
105                 else
106                         mmax = 240; // you won't try THAT hard... (tempo 1)
107                 //printf("initial tempo rules: %f %f\n", mmin, mmax);
108
109                 for(i = 0; i < n; ++i)
110                 {
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));
114                         float tj = ti;
115                         for(j = i+1; j < n; ++j)
116                         {
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));
120
121                                 // note i should be at m*ti+b
122                                 // note j should be at m*tj+b
123                                 // so:
124                                 // we have a LINE l, so that
125                                 // vi_x <= l(ti) <= vi_y
126                                 // vj_x <= l(tj) <= vj_y
127                                 // what is m?
128
129                                 // vi_x <= vi_y <= vj_x <= vj_y
130                                 // ti <= tj
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
137                         }
138                 }
139
140                 if(mmin > mmax) // rhythm fail
141                         return false;
142         }
143
144         pl.tuba_lastnotes_cnt = 0;
145
146         return true;
147 }
148
149 void W_Tuba_NoteOff(entity this)
150 {
151         entity actor = this.owner;
152         // we have a note:
153         //   on: this.spawnshieldtime
154         //   off: time
155         //   note: this.cnt
156         if (actor.tuba_note == this)
157         {
158                 actor.tuba_lastnotes_last = (actor.tuba_lastnotes_last + 1) % MAX_TUBANOTES;
159                 actor.(tuba_lastnotes[actor.tuba_lastnotes_last]) = eX * this.spawnshieldtime + eY * time + eZ * this.cnt;
160                 actor.tuba_note = NULL;
161                 actor.tuba_lastnotes_cnt = bound(0, actor.tuba_lastnotes_cnt + 1, MAX_TUBANOTES);
162
163                 string s = trigger_magicear_processmessage_forallears(actor, 0, NULL, string_null);
164                 if (s != "")
165                 {
166                         // simulate a server message
167                         switch (this.tuba_instrument)
168                         {
169                                 default:
170                                 case 0: // Tuba
171                                         bprint(strcat("\{1}\{13}* ^3", actor.netname, "^3 played on the @!#%'n Tuba: ^7", s, "\n"));
172                                         break;
173                                 case 1:
174                                         bprint(strcat("\{1}\{13}* ^3", actor.netname, "^3 played on the @!#%'n Accordeon: ^7", s, "\n"));
175                                         break;
176                                 case 2:
177                                         bprint(strcat("\{1}\{13}* ^3", actor.netname, "^3 played on the @!#%'n Klein Bottle: ^7", s, "\n"));
178                                         break;
179                         }
180                 }
181         }
182         delete(this);
183 }
184
185 int W_Tuba_GetNote(entity pl, int hittype)
186 {
187         float movestate = 5;
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;
192
193         int note = 0;
194         switch (movestate)
195         {
196         // layout: originally I wanted
197         //   eb e  e#=f
198         //   B  c  d
199         //   Gb G  G#
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...
202         //   eb e  B
203         // f=e# c  d
204         //   Gb G  G#
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#
209                 default:
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
215         }
216         if(PHYS_INPUT_BUTTON_CROUCH(pl))
217                 note -= 12;
218         if(PHYS_INPUT_BUTTON_JUMP(pl))
219                 note += 12;
220         if(hittype & HITTYPE_SECONDARY)
221                 note += 7;
222
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
225         // teamplay
226         // that way, holes in the range of notes are "plugged"
227         if(teamplay)
228         {
229                 if(pl.team == NUM_TEAM_2 || pl.team == NUM_TEAM_4)
230                         note += 3;
231         }
232         else
233         {
234                 if(pl.clientcolors & 1)
235                         note += 3;
236         }
237
238         // total range of notes:
239         //                       0
240         //                 ***  ** ****
241         //                        ***  ** ****
242         //     ***  ** ****
243         //            ***  ** ****
244         //     ***  ********************* ****
245         //     -18.........................+12
246         //        ***  ********************* ****
247         //     -18............................+15
248         //     with jump: ... +24
249         //     ... +27
250         return note;
251 }
252
253 bool W_Tuba_NoteSendEntity(entity this, entity to, int sf)
254 {
255         msg_entity = to;
256         if (!sound_allowed(MSG_ONE, this.realowner)) return false;
257
258         WriteHeader(MSG_ENTITY, ENT_CLIENT_TUBANOTE);
259         WriteByte(MSG_ENTITY, sf);
260         if (sf & 1)
261         {
262                 WriteChar(MSG_ENTITY, this.cnt);
263                 int f = 0;
264                 f |= 1 * (this.realowner != to);
265                 f |= 2 * this.tuba_instrument;
266                 WriteByte(MSG_ENTITY, f);
267         }
268         if (sf & 2)
269         {
270                 WriteCoord(MSG_ENTITY, this.origin.x);
271                 WriteCoord(MSG_ENTITY, this.origin.y);
272                 WriteCoord(MSG_ENTITY, this.origin.z);
273         }
274         return true;
275 }
276
277 void W_Tuba_NoteThink(entity this)
278 {
279         float dist_mult;
280         float vol0, vol1;
281         vector dir0, dir1;
282         vector v;
283         if(time > this.teleport_time)
284         {
285                 W_Tuba_NoteOff(this);
286                 return;
287         }
288         this.nextthink = time;
289         dist_mult = WEP_CVAR(tuba, attenuation) / autocvar_snd_soundradius;
290         FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != this.realowner, {
291                 v = this.origin - (it.origin + it.view_ofs);
292                 vol0 = max(0, 1 - vlen(v) * dist_mult);
293                 dir0 = normalize(v);
294                 v = this.realowner.origin - (it.origin + it.view_ofs);
295                 vol1 = max(0, 1 - vlen(v) * dist_mult);
296                 dir1 = normalize(v);
297                 if(fabs(vol0 - vol1) > 0.005) // 0.5 percent change in volume
298                 {
299                         setorigin(this, this.realowner.origin);
300                         this.SendFlags |= 2;
301                         break;
302                 }
303                 if(dir0 * dir1 < 0.9994) // 2 degrees change in angle
304                 {
305                         setorigin(this, this.realowner.origin);
306                         this.SendFlags |= 2;
307                         break;
308                 }
309         });
310 }
311
312 void W_Tuba_NoteOn(entity actor, .entity weaponentity, float hittype)
313 {
314         vector o;
315         float n;
316
317         W_SetupShot(actor, weaponentity, false, 2, SND_Null, 0, WEP_CVAR(tuba, damage));
318
319         n = W_Tuba_GetNote(actor, hittype);
320
321         hittype = 0;
322         if(actor.tuba_instrument & 1)
323                 hittype |= HITTYPE_SECONDARY;
324         if(actor.tuba_instrument & 2)
325                 hittype |= HITTYPE_BOUNCE;
326
327         if(actor.tuba_note)
328         {
329                 if(actor.tuba_note.cnt != n || actor.tuba_note.tuba_instrument != actor.tuba_instrument)
330                 {
331                         W_Tuba_NoteOff(actor.tuba_note);
332                 }
333         }
334
335         if(!actor.tuba_note)
336         {
337                 actor.tuba_note = new(tuba_note);
338                 actor.tuba_note.owner = actor.tuba_note.realowner = actor;
339                 actor.tuba_note.cnt = n;
340                 actor.tuba_note.tuba_instrument = actor.tuba_instrument;
341                 setthink(actor.tuba_note, W_Tuba_NoteThink);
342                 actor.tuba_note.nextthink = time;
343                 actor.tuba_note.spawnshieldtime = time;
344                 Net_LinkEntity(actor.tuba_note, false, 0, W_Tuba_NoteSendEntity);
345         }
346
347         actor.tuba_note.teleport_time = time + WEP_CVAR(tuba, refire) * 2 * W_WeaponRateFactor(actor); // so it can get prolonged safely
348
349         //sound(actor, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), autocvar_g_balance_tuba_attenuation);
350         RadiusDamage(actor, actor, WEP_CVAR(tuba, damage), WEP_CVAR(tuba, edgedamage), WEP_CVAR(tuba, radius), NULL, NULL, WEP_CVAR(tuba, force), hittype | WEP_TUBA.m_id, NULL);
351
352         o = gettaginfo(actor.exteriorweaponentity, 0);
353         if(time > actor.tuba_smoketime)
354         {
355                 Send_Effect(EFFECT_SMOKE_RING, o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1);
356                 actor.tuba_smoketime = time + 0.25;
357         }
358 }
359 #endif
360
361 #ifdef SVQC
362 METHOD(Tuba, wr_aim, void(Tuba this, entity actor))
363 {
364         // bots cannot play the Tuba well yet
365         // I think they should start with the recorder first
366         if (vdist((actor.origin - actor.enemy.origin), <, WEP_CVAR(tuba, radius)))
367         {
368                 if (random() > 0.5)
369                         PHYS_INPUT_BUTTON_ATCK(actor) = true;
370                 else
371                         PHYS_INPUT_BUTTON_ATCK2(actor) = true;
372         }
373 }
374
375 METHOD(Tuba, wr_think, void(Tuba this, entity actor, .entity weaponentity, int fire))
376 {
377         if (fire & 1)
378         if (weapon_prepareattack(this, actor, weaponentity, false, WEP_CVAR(tuba, refire)))
379         {
380                 W_Tuba_NoteOn(actor, weaponentity, 0);
381                 weapon_thinkf(actor, weaponentity, WFRAME_IDLE, WEP_CVAR(tuba, animtime), w_ready);
382         }
383         if (fire & 2)
384         if (weapon_prepareattack(this, actor, weaponentity, true, WEP_CVAR(tuba, refire)))
385         {
386                 W_Tuba_NoteOn(actor, weaponentity, HITTYPE_SECONDARY);
387                 weapon_thinkf(actor, weaponentity, WFRAME_IDLE, WEP_CVAR(tuba, animtime), w_ready);
388         }
389         if (actor.tuba_note)
390         {
391                 if (!(fire & 1) && !(fire & 2))
392                 {
393                         W_Tuba_NoteOff(actor.tuba_note);
394                 }
395         }
396 }
397
398 METHOD(Tuba, wr_setup, void(Tuba this, entity actor))
399 {
400         actor.ammo_field = ammo_none;
401 //      actor.tuba_instrument = 0;
402 }
403 #endif
404
405 REGISTER_NET_S2C(tuba_instrument)
406 #ifdef CSQC
407 NET_HANDLE(tuba_instrument, bool)
408 {
409         int i = ReadByte();
410         return = true;
411         string s = (i == 0) ? "tuba" :
412                    (i == 1) ? "akordeon" :
413                               "kleinbottle" ;
414         activeweapon.mdl = s;
415         CL_WeaponEntity_SetModel(viewmodel, s, true);
416 }
417 #endif
418 #ifdef SVQC
419 void tuba_instrument_send(entity this, int instr)
420 {
421         msg_entity = this;
422         int chan = MSG_ONE;
423         WriteHeader(chan, tuba_instrument);
424         WriteByte(chan, instr);
425 }
426 SPECTATE_COPY()
427 {
428         if (this.tuba_instrument != spectatee.tuba_instrument)
429                 tuba_instrument_send(this, this.tuba_instrument = spectatee.tuba_instrument);
430 }
431 METHOD(Tuba, wr_reload, void(Tuba this, entity actor, .entity weaponentity))
432 {
433         // switch to alternate instruments :)
434         if (actor.(weaponentity).state == WS_READY)
435         {
436                 switch (actor.tuba_instrument)
437                 {
438                         case 0:
439                                 actor.tuba_instrument = 1;
440                                 actor.weaponname = "akordeon";
441                                 break;
442                         case 1:
443                                 actor.tuba_instrument = 2;
444                                 actor.weaponname = "kleinbottle";
445                                 break;
446                         case 2:
447                                 actor.tuba_instrument = 0;
448                                 actor.weaponname = "tuba";
449                                 break;
450                 }
451                 tuba_instrument_send(actor, actor.tuba_instrument);
452                 W_SetupShot(actor, weaponentity, false, 0, SND_Null, 0, 0);
453                 Send_Effect(EFFECT_TELEPORT, w_shotorg, '0 0 0', 1);
454                 actor.(weaponentity).state = WS_INUSE;
455                 // TODO: don't show the reload animation cause the weapon is already switched
456                 // switch animations need a better system
457 //              weapon_thinkf(actor, weaponentity, WFRAME_RELOAD, 0.5, w_ready);
458                 weapon_thinkf(actor, weaponentity, WFRAME_IDLE, 0.5, w_ready);
459         }
460 }
461 #endif
462
463 #ifdef SVQC
464
465 // infinite ammo
466 METHOD(Tuba, wr_checkammo1, bool(Tuba this, entity actor)) { return true; }
467 METHOD(Tuba, wr_checkammo2, bool(Tuba this, entity actor)) { return true; }
468
469 METHOD(Tuba, wr_suicidemessage, Notification(Tuba this))
470 {
471         if (w_deathtype & HITTYPE_BOUNCE)
472                 return WEAPON_KLEINBOTTLE_SUICIDE;
473         else if (w_deathtype & HITTYPE_SECONDARY)
474                 return WEAPON_ACCORDEON_SUICIDE;
475         else
476                 return WEAPON_TUBA_SUICIDE;
477 }
478 METHOD(Tuba, wr_killmessage, Notification(Tuba this))
479 {
480         if (w_deathtype & HITTYPE_BOUNCE)
481                 return WEAPON_KLEINBOTTLE_MURDER;
482         else if (w_deathtype & HITTYPE_SECONDARY)
483                 return WEAPON_ACCORDEON_MURDER;
484         else
485                 return WEAPON_TUBA_MURDER;
486 }
487
488 #endif
489
490 #ifdef CSQC
491
492 #define TUBA_STARTNOTE(i, n) _Sound_fixpath(W_Sound(strcat("tuba", (i ? ftos(i) : ""), "_loopnote", ftos(n))))
493
494 const int TUBA_MIN = -18;
495 const int TUBA_MAX = 27;
496 const int TUBA_INSTRUMENTS = 3;
497
498 entityclass(Tuba);
499 class(Tuba) .int note;
500 class(Tuba) .bool tuba_attenuate;
501 class(Tuba) .float tuba_volume;
502 class(Tuba) .float tuba_volume_initial;
503 class(Tuba) .int tuba_instrument;
504
505 int Tuba_PitchStep;
506
507 void tubasound(entity e, bool restart)
508 {
509         string snd1 = string_null;
510         if (Tuba_PitchStep) {
511                 float vol1 = 1;
512                 float speed1 = 1;
513                 string snd2 = string_null;
514                 float vol2 = 0;
515                 float speed2 = 1;
516
517                 int m = pymod(e.note, Tuba_PitchStep);
518                 if (m) {
519                         if (e.note - m < TUBA_MIN) {
520                                 if (restart) {
521                                         snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
522                                 }
523                                 speed1 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
524                         } else if (e.note - m + Tuba_PitchStep > TUBA_MAX) {
525                                 if (restart) {
526                                         snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
527                                 }
528                                 speed1 = pow(2.0, m / 12.0);
529                         } else {
530                                 if (restart) {
531                                         snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
532                                 }
533                                 vol1 = cos(M_PI_2 * m / Tuba_PitchStep);
534                                 speed1 = pow(2.0, m / 12.0);
535                                 if (restart) {
536                                         snd2 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
537                                 }
538                                 vol2 = sin(M_PI_2 * m / Tuba_PitchStep);
539                                 speed2 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
540                         }
541                 } else if (restart) {
542                         snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
543                 }
544
545                 sound7(e, CH_TUBA_SINGLE, snd1, e.tuba_volume * vol1, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation, 100 * speed1, 0);
546                 if (vol2) {
547                         sound7(e.enemy, CH_TUBA_SINGLE, snd2, e.tuba_volume * vol2, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation, 100 * speed2, 0);
548                 }
549         } else {
550                 if (restart) {
551                         snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
552                 }
553                 _sound(e, CH_TUBA_SINGLE, snd1, e.tuba_volume, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation);
554         }
555 }
556
557 void Ent_TubaNote_Think(entity this)
558 {
559         float f = autocvar_g_balance_tuba_fadetime;
560         if (f > 0) {
561                 this.tuba_volume -= frametime * this.tuba_volume_initial / f;
562         } else {
563                 this.tuba_volume = 0;
564         }
565         this.nextthink = time;
566         if (this.tuba_volume <= 0) {
567                 sound(this, CH_TUBA_SINGLE, SND_Null, 0, 0);
568                 if (this.enemy) {
569                         sound(this.enemy, CH_TUBA_SINGLE, SND_Null, 0, 0);
570                         delete(this.enemy);
571                 }
572                 delete(this);
573         } else {
574                 tubasound(this, 0);
575         }
576 }
577
578 void Ent_TubaNote_UpdateSound(entity this)
579 {
580         this.enemy.tuba_volume = bound(0, VOL_BASE * autocvar_g_balance_tuba_volume, 1);
581         this.enemy.tuba_volume_initial = this.enemy.tuba_volume;
582         this.enemy.note = this.note;
583         this.enemy.tuba_instrument = this.tuba_instrument;
584         tubasound(this.enemy, 1);
585 }
586
587 void Ent_TubaNote_StopSound(entity this)
588 {
589         this.enemy.nextthink = time;
590         this.enemy = NULL;
591 }
592
593 NET_HANDLE(ENT_CLIENT_TUBANOTE, bool isNew)
594 {
595         bool upd = false;
596         int f = ReadByte();
597         if (f & 1) {
598                 int n = ReadChar();
599                 int i = ReadByte();
600                 bool att = (i & 1);
601                 i >>= 1;
602
603                 if (this.enemy) {
604                         if (n != this.note || i != this.tuba_instrument || isNew) {
605                                 Ent_TubaNote_StopSound(this);
606                         }
607                 } else {
608                         this.enemy = new(tuba_note);
609                         if (Tuba_PitchStep) {
610                                 this.enemy.enemy = new(tuba_note_2);
611                         }
612                         isNew = true;
613                 }
614
615                 this.enemy.tuba_attenuate = att;
616
617                 if (isNew) {
618                         this.note = n;
619                         this.tuba_instrument = i;
620                         upd = true;
621                 }
622         }
623
624         if (f & 2) {
625                 this.enemy.origin_x = ReadCoord();
626                 this.enemy.origin_y = ReadCoord();
627                 this.enemy.origin_z = ReadCoord();
628                 setorigin(this.enemy, this.enemy.origin);
629                 if (this.enemy.enemy) {
630                         setorigin(this.enemy.enemy, this.enemy.origin);
631                 }
632         }
633
634         setthink(this, Ent_TubaNote_StopSound);
635         this.entremove = Ent_TubaNote_StopSound;
636         setthink(this.enemy, Ent_TubaNote_Think);
637         this.enemy.nextthink = time + 10;
638
639         if (upd) {
640                 Ent_TubaNote_UpdateSound(this);
641         }
642         return true;
643 }
644
645 PRECACHE(Tuba)
646 {
647         Tuba_PitchStep = autocvar_g_balance_tuba_pitchstep;
648         if (Tuba_PitchStep) {
649                 if (!checkextension("DP_SND_SOUND7_WIP2") && !checkextension("DP_SND_SOUND7")) {
650                         LOG_WARN("requested pitch shifting, but not supported by this engine build");
651                         Tuba_PitchStep = 0;
652                 }
653         }
654         for (int n = TUBA_MIN; n <= TUBA_MAX; ++n) {
655                 if (!Tuba_PitchStep || pymod(n, Tuba_PitchStep) == 0) {
656                         for (int i = 0; i < TUBA_INSTRUMENTS; ++i) {
657                                 precache_sound(TUBA_STARTNOTE(i, n));
658                         }
659                 }
660         }
661 }
662
663 #endif
664 #endif