]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/tuba.qc
Remove SELFPARAM() from .think and .touch
[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         remove(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 > self.teleport_time)
284         {
285                 W_Tuba_NoteOff(this);
286                 return;
287         }
288         self.nextthink = time;
289         dist_mult = WEP_CVAR(tuba, attenuation) / autocvar_snd_soundradius;
290         FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != self.realowner, {
291                 v = self.origin - (it.origin + it.view_ofs);
292                 vol0 = max(0, 1 - vlen(v) * dist_mult);
293                 dir0 = normalize(v);
294                 v = self.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(self, self.realowner.origin);
300                         self.SendFlags |= 2;
301                         break;
302                 }
303                 if(dir0 * dir1 < 0.9994) // 2 degrees change in angle
304                 {
305                         setorigin(self, self.realowner.origin);
306                         self.SendFlags |= 2;
307                         break;
308                 }
309         });
310 }
311
312 void W_Tuba_NoteOn(float hittype)
313 {SELFPARAM();
314         vector o;
315         float n;
316
317         W_SetupShot(self, false, 2, SND_Null, 0, WEP_CVAR(tuba, damage));
318
319         n = W_Tuba_GetNote(self, hittype);
320
321         hittype = 0;
322         if(self.tuba_instrument & 1)
323                 hittype |= HITTYPE_SECONDARY;
324         if(self.tuba_instrument & 2)
325                 hittype |= HITTYPE_BOUNCE;
326
327         if(self.tuba_note)
328         {
329                 if(self.tuba_note.cnt != n || self.tuba_note.tuba_instrument != self.tuba_instrument)
330                 {
331                         W_Tuba_NoteOff(self.tuba_note);
332                 }
333         }
334
335         if(!self.tuba_note)
336         {
337                 self.tuba_note = new(tuba_note);
338                 self.tuba_note.owner = self.tuba_note.realowner = self;
339                 self.tuba_note.cnt = n;
340                 self.tuba_note.tuba_instrument = self.tuba_instrument;
341                 setthink(self.tuba_note, W_Tuba_NoteThink);
342                 self.tuba_note.nextthink = time;
343                 self.tuba_note.spawnshieldtime = time;
344                 Net_LinkEntity(self.tuba_note, false, 0, W_Tuba_NoteSendEntity);
345         }
346
347         self.tuba_note.teleport_time = time + WEP_CVAR(tuba, refire) * 2 * W_WeaponRateFactor(); // so it can get prolonged safely
348
349         //sound(self, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), autocvar_g_balance_tuba_attenuation);
350         RadiusDamage(self, self, 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(self.exteriorweaponentity, 0);
353         if(time > self.tuba_smoketime)
354         {
355                 Send_Effect(EFFECT_SMOKE_RING, o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1);
356                 self.tuba_smoketime = time + 0.25;
357         }
358 }
359 #endif
360
361 #ifdef SVQC
362 METHOD(Tuba, wr_aim, void(Tuba this))
363 {
364         entity actor = self;
365         // bots cannot play the Tuba well yet
366         // I think they should start with the recorder first
367         if (vdist((actor.origin - actor.enemy.origin), <, WEP_CVAR(tuba, radius)))
368         {
369                 if (random() > 0.5)
370                         PHYS_INPUT_BUTTON_ATCK(actor) = true;
371                 else
372                         PHYS_INPUT_BUTTON_ATCK2(actor) = true;
373         }
374 }
375
376 METHOD(Tuba, wr_think, void(Tuba this, entity actor, .entity weaponentity, int fire))
377 {
378         if (fire & 1)
379         if (weapon_prepareattack(this, actor, weaponentity, false, WEP_CVAR(tuba, refire)))
380         {
381                 W_Tuba_NoteOn(0);
382                 weapon_thinkf(actor, weaponentity, WFRAME_IDLE, WEP_CVAR(tuba, animtime), w_ready);
383         }
384         if (fire & 2)
385         if (weapon_prepareattack(this, actor, weaponentity, true, WEP_CVAR(tuba, refire)))
386         {
387                 W_Tuba_NoteOn(HITTYPE_SECONDARY);
388                 weapon_thinkf(actor, weaponentity, WFRAME_IDLE, WEP_CVAR(tuba, animtime), w_ready);
389         }
390         if (actor.tuba_note)
391         {
392                 if (!(fire & 1) && !(fire & 2))
393                 {
394                         W_Tuba_NoteOff(actor.tuba_note);
395                 }
396         }
397 }
398
399 METHOD(Tuba, wr_setup, void(Tuba this))
400 {
401         entity actor = self;
402         actor.ammo_field = ammo_none;
403         actor.tuba_instrument = 0;
404 }
405 #endif
406
407 REGISTER_NET_S2C(tuba_instrument)
408 #ifdef CSQC
409 NET_HANDLE(tuba_instrument, bool)
410 {
411         int i = ReadByte();
412         return = true;
413         string s = (i == 0) ? "tuba" :
414                    (i == 1) ? "akordeon" :
415                               "kleinbottle" ;
416         CL_WeaponEntity_SetModel(viewmodel, s, true);
417 }
418 #endif
419 #ifdef SVQC
420 void tuba_instrument_send(entity this, int instr)
421 {
422         msg_entity = this;
423         int chan = MSG_ONE;
424         WriteHeader(chan, tuba_instrument);
425         WriteByte(chan, instr);
426 }
427 SPECTATE_COPY()
428 {
429         if (this.tuba_instrument != spectatee.tuba_instrument)
430                 tuba_instrument_send(this, this.tuba_instrument = spectatee.tuba_instrument);
431 }
432 METHOD(Tuba, wr_reload, void(Tuba this, entity actor, .entity weaponentity))
433 {
434         // switch to alternate instruments :)
435         if (actor.(weaponentity).state == WS_READY)
436         {
437                 switch (actor.tuba_instrument)
438                 {
439                         case 0:
440                                 actor.tuba_instrument = 1;
441                                 actor.weaponname = "akordeon";
442                                 break;
443                         case 1:
444                                 actor.tuba_instrument = 2;
445                                 actor.weaponname = "kleinbottle";
446                                 break;
447                         case 2:
448                                 actor.tuba_instrument = 0;
449                                 actor.weaponname = "tuba";
450                                 break;
451                 }
452                 tuba_instrument_send(actor, actor.tuba_instrument);
453                 W_SetupShot(actor, false, 0, SND_Null, 0, 0);
454                 Send_Effect(EFFECT_TELEPORT, w_shotorg, '0 0 0', 1);
455                 actor.(weaponentity).state = WS_INUSE;
456                 weapon_thinkf(actor, weaponentity, WFRAME_RELOAD, 0.5, w_ready);
457         }
458 }
459 #endif
460
461 #ifdef SVQC
462
463 // infinite ammo
464 METHOD(Tuba, wr_checkammo1, bool(Tuba this, entity actor)) { return true; }
465 METHOD(Tuba, wr_checkammo2, bool(Tuba this, entity actor)) { return true; }
466
467 METHOD(Tuba, wr_suicidemessage, Notification(Tuba this))
468 {
469         if (w_deathtype & HITTYPE_BOUNCE)
470                 return WEAPON_KLEINBOTTLE_SUICIDE;
471         else if (w_deathtype & HITTYPE_SECONDARY)
472                 return WEAPON_ACCORDEON_SUICIDE;
473         else
474                 return WEAPON_TUBA_SUICIDE;
475 }
476 METHOD(Tuba, wr_killmessage, Notification(Tuba this))
477 {
478         if (w_deathtype & HITTYPE_BOUNCE)
479                 return WEAPON_KLEINBOTTLE_MURDER;
480         else if (w_deathtype & HITTYPE_SECONDARY)
481                 return WEAPON_ACCORDEON_MURDER;
482         else
483                 return WEAPON_TUBA_MURDER;
484 }
485
486 #endif
487
488 #ifdef CSQC
489
490 #define TUBA_STARTNOTE(i, n) _Sound_fixpath(W_Sound(strcat("tuba", (i ? ftos(i) : ""), "_loopnote", ftos(n))))
491
492 const int TUBA_MIN = -18;
493 const int TUBA_MAX = 27;
494 const int TUBA_INSTRUMENTS = 3;
495
496 entityclass(Tuba);
497 class(Tuba) .int note;
498 class(Tuba) .bool tuba_attenuate;
499 class(Tuba) .float tuba_volume;
500 class(Tuba) .float tuba_volume_initial;
501 class(Tuba) .int tuba_instrument;
502
503 int Tuba_PitchStep;
504
505 void tubasound(entity e, bool restart)
506 {
507         string snd1 = string_null;
508         if (Tuba_PitchStep) {
509                 float vol1 = 1;
510                 float speed1 = 1;
511                 string snd2 = string_null;
512                 float vol2 = 0;
513                 float speed2 = 1;
514
515                 int m = pymod(e.note, Tuba_PitchStep);
516                 if (m) {
517                         if (e.note - m < TUBA_MIN) {
518                                 if (restart) {
519                                         snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
520                                 }
521                                 speed1 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
522                         } else if (e.note - m + Tuba_PitchStep > TUBA_MAX) {
523                                 if (restart) {
524                                         snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
525                                 }
526                                 speed1 = pow(2.0, m / 12.0);
527                         } else {
528                                 if (restart) {
529                                         snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
530                                 }
531                                 vol1 = cos(M_PI_2 * m / Tuba_PitchStep);
532                                 speed1 = pow(2.0, m / 12.0);
533                                 if (restart) {
534                                         snd2 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
535                                 }
536                                 vol2 = sin(M_PI_2 * m / Tuba_PitchStep);
537                                 speed2 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
538                         }
539                 } else if (restart) {
540                         snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
541                 }
542
543                 sound7(e, CH_TUBA_SINGLE, snd1, e.tuba_volume * vol1, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation, 100 * speed1, 0);
544                 if (vol2) {
545                         sound7(e.enemy, CH_TUBA_SINGLE, snd2, e.tuba_volume * vol2, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation, 100 * speed2, 0);
546                 }
547         } else {
548                 if (restart) {
549                         snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
550                 }
551                 _sound(e, CH_TUBA_SINGLE, snd1, e.tuba_volume, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation);
552         }
553 }
554
555 void Ent_TubaNote_Think(entity this)
556 {
557         float f = autocvar_g_balance_tuba_fadetime;
558         if (f > 0) {
559                 this.tuba_volume -= frametime * this.tuba_volume_initial / f;
560         } else {
561                 this.tuba_volume = 0;
562         }
563         this.nextthink = time;
564         if (this.tuba_volume <= 0) {
565                 sound(this, CH_TUBA_SINGLE, SND_Null, 0, 0);
566                 if (this.enemy) {
567                         sound(this.enemy, CH_TUBA_SINGLE, SND_Null, 0, 0);
568                         remove(this.enemy);
569                 }
570                 remove(this);
571         } else {
572                 tubasound(this, 0);
573         }
574 }
575
576 void Ent_TubaNote_UpdateSound(entity this)
577 {
578         this.enemy.tuba_volume = bound(0, VOL_BASE * autocvar_g_balance_tuba_volume, 1);
579         this.enemy.tuba_volume_initial = this.enemy.tuba_volume;
580         this.enemy.note = this.note;
581         this.enemy.tuba_instrument = this.tuba_instrument;
582         tubasound(this.enemy, 1);
583 }
584
585 void Ent_TubaNote_StopSound(entity this)
586 {
587         this.enemy.nextthink = time;
588         this.enemy = NULL;
589 }
590
591 NET_HANDLE(ENT_CLIENT_TUBANOTE, bool isNew)
592 {
593         bool upd = false;
594         int f = ReadByte();
595         if (f & 1) {
596                 int n = ReadChar();
597                 int i = ReadByte();
598                 bool att = (i & 1);
599                 i >>= 1;
600
601                 if (this.enemy) {
602                         if (n != this.note || i != this.tuba_instrument || isNew) {
603                                 Ent_TubaNote_StopSound(this);
604                         }
605                 } else {
606                         this.enemy = new(tuba_note);
607                         if (Tuba_PitchStep) {
608                                 this.enemy.enemy = new(tuba_note_2);
609                         }
610                         isNew = true;
611                 }
612
613                 this.enemy.tuba_attenuate = att;
614
615                 if (isNew) {
616                         this.note = n;
617                         this.tuba_instrument = i;
618                         upd = true;
619                 }
620         }
621
622         if (f & 2) {
623                 this.enemy.origin_x = ReadCoord();
624                 this.enemy.origin_y = ReadCoord();
625                 this.enemy.origin_z = ReadCoord();
626                 setorigin(this.enemy, this.enemy.origin);
627                 if (this.enemy.enemy) {
628                         setorigin(this.enemy.enemy, this.enemy.origin);
629                 }
630         }
631
632         setthink(this, Ent_TubaNote_StopSound);
633         this.entremove = Ent_TubaNote_StopSound;
634         setthink(this.enemy, Ent_TubaNote_Think);
635         this.enemy.nextthink = time + 10;
636
637         if (upd) {
638                 Ent_TubaNote_UpdateSound(this);
639         }
640         return true;
641 }
642
643 PRECACHE(Tuba)
644 {
645         Tuba_PitchStep = autocvar_g_balance_tuba_pitchstep;
646         if (Tuba_PitchStep) {
647                 if (!checkextension("DP_SND_SOUND7_WIP2") && !checkextension("DP_SND_SOUND7")) {
648                         LOG_WARNING("requested pitch shifting, but not supported by this engine build");
649                         Tuba_PitchStep = 0;
650                 }
651         }
652         for (int n = TUBA_MIN; n <= TUBA_MAX; ++n) {
653                 if (!Tuba_PitchStep || pymod(n, Tuba_PitchStep) == 0) {
654                         for (int i = 0; i < TUBA_INSTRUMENTS; ++i) {
655                                 precache_sound(TUBA_STARTNOTE(i, n));
656                         }
657                 }
658         }
659 }
660
661 #endif
662 #endif