]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/tuba.qc
Merge branch 'terencehill/respawn_timer_fix' into 'master'
[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(entity actor, float hittype)
313 {entity this = actor;
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, 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, 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, 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         CL_WeaponEntity_SetModel(viewmodel, s, true);
415 }
416 #endif
417 #ifdef SVQC
418 void tuba_instrument_send(entity this, int instr)
419 {
420         msg_entity = this;
421         int chan = MSG_ONE;
422         WriteHeader(chan, tuba_instrument);
423         WriteByte(chan, instr);
424 }
425 SPECTATE_COPY()
426 {
427         if (this.tuba_instrument != spectatee.tuba_instrument)
428                 tuba_instrument_send(this, this.tuba_instrument = spectatee.tuba_instrument);
429 }
430 METHOD(Tuba, wr_reload, void(Tuba this, entity actor, .entity weaponentity))
431 {
432         // switch to alternate instruments :)
433         if (actor.(weaponentity).state == WS_READY)
434         {
435                 switch (actor.tuba_instrument)
436                 {
437                         case 0:
438                                 actor.tuba_instrument = 1;
439                                 actor.weaponname = "akordeon";
440                                 break;
441                         case 1:
442                                 actor.tuba_instrument = 2;
443                                 actor.weaponname = "kleinbottle";
444                                 break;
445                         case 2:
446                                 actor.tuba_instrument = 0;
447                                 actor.weaponname = "tuba";
448                                 break;
449                 }
450                 tuba_instrument_send(actor, actor.tuba_instrument);
451                 W_SetupShot(actor, false, 0, SND_Null, 0, 0);
452                 Send_Effect(EFFECT_TELEPORT, w_shotorg, '0 0 0', 1);
453                 actor.(weaponentity).state = WS_INUSE;
454                 weapon_thinkf(actor, weaponentity, WFRAME_RELOAD, 0.5, w_ready);
455         }
456 }
457 #endif
458
459 #ifdef SVQC
460
461 // infinite ammo
462 METHOD(Tuba, wr_checkammo1, bool(Tuba this, entity actor)) { return true; }
463 METHOD(Tuba, wr_checkammo2, bool(Tuba this, entity actor)) { return true; }
464
465 METHOD(Tuba, wr_suicidemessage, Notification(Tuba this))
466 {
467         if (w_deathtype & HITTYPE_BOUNCE)
468                 return WEAPON_KLEINBOTTLE_SUICIDE;
469         else if (w_deathtype & HITTYPE_SECONDARY)
470                 return WEAPON_ACCORDEON_SUICIDE;
471         else
472                 return WEAPON_TUBA_SUICIDE;
473 }
474 METHOD(Tuba, wr_killmessage, Notification(Tuba this))
475 {
476         if (w_deathtype & HITTYPE_BOUNCE)
477                 return WEAPON_KLEINBOTTLE_MURDER;
478         else if (w_deathtype & HITTYPE_SECONDARY)
479                 return WEAPON_ACCORDEON_MURDER;
480         else
481                 return WEAPON_TUBA_MURDER;
482 }
483
484 #endif
485
486 #ifdef CSQC
487
488 #define TUBA_STARTNOTE(i, n) _Sound_fixpath(W_Sound(strcat("tuba", (i ? ftos(i) : ""), "_loopnote", ftos(n))))
489
490 const int TUBA_MIN = -18;
491 const int TUBA_MAX = 27;
492 const int TUBA_INSTRUMENTS = 3;
493
494 entityclass(Tuba);
495 class(Tuba) .int note;
496 class(Tuba) .bool tuba_attenuate;
497 class(Tuba) .float tuba_volume;
498 class(Tuba) .float tuba_volume_initial;
499 class(Tuba) .int tuba_instrument;
500
501 int Tuba_PitchStep;
502
503 void tubasound(entity e, bool restart)
504 {
505         string snd1 = string_null;
506         if (Tuba_PitchStep) {
507                 float vol1 = 1;
508                 float speed1 = 1;
509                 string snd2 = string_null;
510                 float vol2 = 0;
511                 float speed2 = 1;
512
513                 int m = pymod(e.note, Tuba_PitchStep);
514                 if (m) {
515                         if (e.note - m < TUBA_MIN) {
516                                 if (restart) {
517                                         snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
518                                 }
519                                 speed1 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
520                         } else if (e.note - m + Tuba_PitchStep > TUBA_MAX) {
521                                 if (restart) {
522                                         snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
523                                 }
524                                 speed1 = pow(2.0, m / 12.0);
525                         } else {
526                                 if (restart) {
527                                         snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
528                                 }
529                                 vol1 = cos(M_PI_2 * m / Tuba_PitchStep);
530                                 speed1 = pow(2.0, m / 12.0);
531                                 if (restart) {
532                                         snd2 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
533                                 }
534                                 vol2 = sin(M_PI_2 * m / Tuba_PitchStep);
535                                 speed2 = pow(2.0, (m - Tuba_PitchStep) / 12.0);
536                         }
537                 } else if (restart) {
538                         snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
539                 }
540
541                 sound7(e, CH_TUBA_SINGLE, snd1, e.tuba_volume * vol1, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation, 100 * speed1, 0);
542                 if (vol2) {
543                         sound7(e.enemy, CH_TUBA_SINGLE, snd2, e.tuba_volume * vol2, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation, 100 * speed2, 0);
544                 }
545         } else {
546                 if (restart) {
547                         snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
548                 }
549                 _sound(e, CH_TUBA_SINGLE, snd1, e.tuba_volume, e.tuba_attenuate * autocvar_g_balance_tuba_attenuation);
550         }
551 }
552
553 void Ent_TubaNote_Think(entity this)
554 {
555         float f = autocvar_g_balance_tuba_fadetime;
556         if (f > 0) {
557                 this.tuba_volume -= frametime * this.tuba_volume_initial / f;
558         } else {
559                 this.tuba_volume = 0;
560         }
561         this.nextthink = time;
562         if (this.tuba_volume <= 0) {
563                 sound(this, CH_TUBA_SINGLE, SND_Null, 0, 0);
564                 if (this.enemy) {
565                         sound(this.enemy, CH_TUBA_SINGLE, SND_Null, 0, 0);
566                         remove(this.enemy);
567                 }
568                 remove(this);
569         } else {
570                 tubasound(this, 0);
571         }
572 }
573
574 void Ent_TubaNote_UpdateSound(entity this)
575 {
576         this.enemy.tuba_volume = bound(0, VOL_BASE * autocvar_g_balance_tuba_volume, 1);
577         this.enemy.tuba_volume_initial = this.enemy.tuba_volume;
578         this.enemy.note = this.note;
579         this.enemy.tuba_instrument = this.tuba_instrument;
580         tubasound(this.enemy, 1);
581 }
582
583 void Ent_TubaNote_StopSound(entity this)
584 {
585         this.enemy.nextthink = time;
586         this.enemy = NULL;
587 }
588
589 NET_HANDLE(ENT_CLIENT_TUBANOTE, bool isNew)
590 {
591         bool upd = false;
592         int f = ReadByte();
593         if (f & 1) {
594                 int n = ReadChar();
595                 int i = ReadByte();
596                 bool att = (i & 1);
597                 i >>= 1;
598
599                 if (this.enemy) {
600                         if (n != this.note || i != this.tuba_instrument || isNew) {
601                                 Ent_TubaNote_StopSound(this);
602                         }
603                 } else {
604                         this.enemy = new(tuba_note);
605                         if (Tuba_PitchStep) {
606                                 this.enemy.enemy = new(tuba_note_2);
607                         }
608                         isNew = true;
609                 }
610
611                 this.enemy.tuba_attenuate = att;
612
613                 if (isNew) {
614                         this.note = n;
615                         this.tuba_instrument = i;
616                         upd = true;
617                 }
618         }
619
620         if (f & 2) {
621                 this.enemy.origin_x = ReadCoord();
622                 this.enemy.origin_y = ReadCoord();
623                 this.enemy.origin_z = ReadCoord();
624                 setorigin(this.enemy, this.enemy.origin);
625                 if (this.enemy.enemy) {
626                         setorigin(this.enemy.enemy, this.enemy.origin);
627                 }
628         }
629
630         setthink(this, Ent_TubaNote_StopSound);
631         this.entremove = Ent_TubaNote_StopSound;
632         setthink(this.enemy, Ent_TubaNote_Think);
633         this.enemy.nextthink = time + 10;
634
635         if (upd) {
636                 Ent_TubaNote_UpdateSound(this);
637         }
638         return true;
639 }
640
641 PRECACHE(Tuba)
642 {
643         Tuba_PitchStep = autocvar_g_balance_tuba_pitchstep;
644         if (Tuba_PitchStep) {
645                 if (!checkextension("DP_SND_SOUND7_WIP2") && !checkextension("DP_SND_SOUND7")) {
646                         LOG_WARNING("requested pitch shifting, but not supported by this engine build");
647                         Tuba_PitchStep = 0;
648                 }
649         }
650         for (int n = TUBA_MIN; n <= TUBA_MAX; ++n) {
651                 if (!Tuba_PitchStep || pymod(n, Tuba_PitchStep) == 0) {
652                         for (int i = 0; i < TUBA_INSTRUMENTS; ++i) {
653                                 precache_sound(TUBA_STARTNOTE(i, n));
654                         }
655                 }
656         }
657 }
658
659 #endif
660 #endif