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