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