Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
tuba.qc File Reference
#include "tuba.qh"
Include dependency graph for tuba.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MAX_TUBANOTES   32
#define TUBA_STARTNOTE(i, n)

Functions

void Ent_TubaNote_StopSound (entity this)
void Ent_TubaNote_Think (entity this)
void Ent_TubaNote_UpdateSound (entity this)
 NET_HANDLE (ENT_CLIENT_TUBANOTE, bool isNew)
 PRECACHE (Tuba)
void tubasound (entity e, bool restart)
int W_Tuba_GetNote (entity pl, int hittype)
bool W_Tuba_HasPlayed (entity pl,.entity weaponentity, string melody, int instrument, bool ignorepitch, float mintempo, float maxtempo)
void W_Tuba_NoteOff (entity this)
void W_Tuba_NoteOn (entity actor,.entity weaponentity, float hittype)
bool W_Tuba_NoteSendEntity (entity this, entity to, int sf)
void W_Tuba_NoteThink (entity this)

Variables

const int TUBA_INSTRUMENTS = 3
vector tuba_lastnotes [MAX_TUBANOTES]
float tuba_lastnotes_cnt
float tuba_lastnotes_last
const int TUBA_MAX = 27
const int TUBA_MIN = -18
entity tuba_note
int Tuba_PitchStep
float tuba_smoketime

Macro Definition Documentation

◆ MAX_TUBANOTES

#define MAX_TUBANOTES   32

Definition at line 8 of file tuba.qc.

Referenced by W_Tuba_HasPlayed(), and W_Tuba_NoteOff().

◆ TUBA_STARTNOTE

#define TUBA_STARTNOTE ( i,
n )
Value:
_Sound_fixpath(W_Sound(strcat("tuba", (i ? ftos(i) : ""), "_loopnote", ftos(n))))
string ftos(float f)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
string _Sound_fixpath(string base)
Definition sound.qh:94
string W_Sound(string w_snd)
Definition all.qc:225

Definition at line 433 of file tuba.qc.

Referenced by PRECACHE(), and tubasound().

Function Documentation

◆ Ent_TubaNote_StopSound()

void Ent_TubaNote_StopSound ( entity this)

Definition at line 521 of file tuba.qc.

522{
523 this.enemy.nextthink = time;
524 this.enemy = NULL;
525}
float time
#define NULL
Definition post.qh:14
entity enemy
Definition sv_ctf.qh:153

References enemy, entity(), NULL, and time.

Referenced by NET_HANDLE().

◆ Ent_TubaNote_Think()

void Ent_TubaNote_Think ( entity this)

Definition at line 491 of file tuba.qc.

492{
494 if (f > 0) {
495 this.tuba_volume -= frametime * this.tuba_volume_initial / f;
496 } else {
497 this.tuba_volume = 0;
498 }
499 this.nextthink = time;
500 if (this.tuba_volume <= 0) {
501 sound(this, CH_TUBA_SINGLE, SND_Null, 0, 0);
502 if (this.enemy) {
503 sound(this.enemy, CH_TUBA_SINGLE, SND_Null, 0, 0);
504 delete(this.enemy);
505 }
506 delete(this);
507 } else {
508 tubasound(this, 0);
509 }
510}
float frametime
float nextthink
const int CH_TUBA_SINGLE
Definition sound.qh:17
#define sound(e, c, s, v, a)
Definition sound.qh:52
void tubasound(entity e, bool restart)
Definition tuba.qc:441
float autocvar_cl_tuba_fadetime
Definition tuba.qh:15

References autocvar_cl_tuba_fadetime, CH_TUBA_SINGLE, enemy, entity(), frametime, nextthink, sound, time, and tubasound().

Referenced by NET_HANDLE().

◆ Ent_TubaNote_UpdateSound()

void Ent_TubaNote_UpdateSound ( entity this)

Definition at line 512 of file tuba.qc.

513{
514 this.enemy.tuba_volume = bound(0, VOL_BASE * autocvar_cl_tuba_volume, 1);
515 this.enemy.tuba_volume_initial = this.enemy.tuba_volume;
516 this.enemy.note = this.note;
517 this.enemy.tuba_instrument = this.tuba_instrument;
518 tubasound(this.enemy, 1);
519}
float bound(float min, float value, float max)
const float VOL_BASE
Definition sound.qh:36
float autocvar_cl_tuba_volume
Definition tuba.qh:17
int tuba_instrument
Definition wepent.qh:10

References autocvar_cl_tuba_volume, bound(), enemy, entity(), tuba_instrument, tubasound(), and VOL_BASE.

Referenced by NET_HANDLE().

◆ NET_HANDLE()

NET_HANDLE ( ENT_CLIENT_TUBANOTE ,
bool isNew )

Definition at line 527 of file tuba.qc.

528{
529 bool upd = false;
530 int f = ReadByte();
531 if (f & 1) {
532 int n = ReadChar();
533 int i = ReadByte();
534 bool att = (i & 1);
535 i >>= 1;
536
537 if (this.enemy) {
538 if (n != this.note || i != this.tuba_instrument || isNew) {
540 }
541 } else {
542 this.enemy = new(tuba_note);
543 if (Tuba_PitchStep) {
544 this.enemy.enemy = new(tuba_note_2);
545 }
546 isNew = true;
547 }
548
549 this.enemy.tuba_attenuate = att;
550
551 if (isNew) {
552 this.note = n;
553 this.tuba_instrument = i;
554 upd = true;
555 }
556 }
557
558 if (f & 2) {
559 this.enemy.origin = ReadVector();
560 setorigin(this.enemy, this.enemy.origin);
561 if (this.enemy.enemy) {
562 setorigin(this.enemy.enemy, this.enemy.origin);
563 }
564 }
565
567 this.entremove = Ent_TubaNote_StopSound;
569 this.enemy.nextthink = time + 10;
570
571 if (upd) {
573 }
574 return true;
575}
#define ReadVector()
Definition net.qh:367
int ReadByte()
#define setthink(e, f)
void Ent_TubaNote_UpdateSound(entity this)
Definition tuba.qc:512
void Ent_TubaNote_StopSound(entity this)
Definition tuba.qc:521
void Ent_TubaNote_Think(entity this)
Definition tuba.qc:491
entity tuba_note
Definition tuba.qc:5
int Tuba_PitchStep
Definition tuba.qc:439

References enemy, Ent_TubaNote_StopSound(), Ent_TubaNote_Think(), Ent_TubaNote_UpdateSound(), ReadByte(), ReadVector, setthink, time, tuba_instrument, tuba_note, and Tuba_PitchStep.

◆ PRECACHE()

PRECACHE ( Tuba )

Definition at line 577 of file tuba.qc.

578{
580 if (Tuba_PitchStep) {
581 if (!checkextension("DP_SND_SOUND7_WIP2") && !checkextension("DP_SND_SOUND7")) {
582 LOG_WARN("requested pitch shifting, but not supported by this engine build");
583 Tuba_PitchStep = 0;
584 }
585 }
586 for (int n = TUBA_MIN; n <= TUBA_MAX; ++n) {
587 if (!Tuba_PitchStep || pymod(n, Tuba_PitchStep) == 0) {
588 for (int i = 0; i < TUBA_INSTRUMENTS; ++i) {
590 }
591 }
592 }
593}
#define LOG_WARN(...)
Definition log.qh:61
float pymod(float e, float f)
Pythonic mod: TODO: %% operator?
Definition mathlib.qc:194
string precache_sound(string sample)
float checkextension(string ext)
const int TUBA_MIN
Definition tuba.qc:435
const int TUBA_MAX
Definition tuba.qc:436
const int TUBA_INSTRUMENTS
Definition tuba.qc:437
#define TUBA_STARTNOTE(i, n)
Definition tuba.qc:433
float autocvar_cl_tuba_pitchstep
Definition tuba.qh:16

References autocvar_cl_tuba_pitchstep, checkextension(), LOG_WARN, precache_sound(), pymod(), TUBA_INSTRUMENTS, TUBA_MAX, TUBA_MIN, Tuba_PitchStep, and TUBA_STARTNOTE.

◆ tubasound()

void tubasound ( entity e,
bool restart )

Definition at line 441 of file tuba.qc.

442{
443 string snd1 = string_null;
444 if (Tuba_PitchStep) {
445 float vol1 = 1;
446 float speed1 = 1;
447 string snd2 = string_null;
448 float vol2 = 0;
449 float speed2 = 1;
450
451 int m = pymod(e.note, Tuba_PitchStep);
452 if (m) {
453 if (e.note - m < TUBA_MIN) {
454 if (restart) {
455 snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
456 }
457 speed1 = (2.0 ** ((m - Tuba_PitchStep) / 12.0));
458 } else if (e.note - m + Tuba_PitchStep > TUBA_MAX) {
459 if (restart) {
460 snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
461 }
462 speed1 = (2.0 ** (m / 12.0));
463 } else {
464 if (restart) {
465 snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m);
466 }
467 vol1 = cos(M_PI_2 * m / Tuba_PitchStep);
468 speed1 = (2.0 ** (m / 12.0));
469 if (restart) {
470 snd2 = TUBA_STARTNOTE(e.tuba_instrument, e.note - m + Tuba_PitchStep);
471 }
472 vol2 = sin(M_PI_2 * m / Tuba_PitchStep);
473 speed2 = (2.0 ** ((m - Tuba_PitchStep) / 12.0));
474 }
475 } else if (restart) {
476 snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
477 }
478
479 sound7(e, CH_TUBA_SINGLE, snd1, e.tuba_volume * vol1, e.tuba_attenuate * autocvar_cl_tuba_attenuation, 100 * speed1, 0);
480 if (vol2) {
481 sound7(e.enemy, CH_TUBA_SINGLE, snd2, e.tuba_volume * vol2, e.tuba_attenuate * autocvar_cl_tuba_attenuation, 100 * speed2, 0);
482 }
483 } else {
484 if (restart) {
485 snd1 = TUBA_STARTNOTE(e.tuba_instrument, e.note);
486 }
487 _sound(e, CH_TUBA_SINGLE, snd1, e.tuba_volume, e.tuba_attenuate * autocvar_cl_tuba_attenuation);
488 }
489}
const float M_PI_2
Definition mathlib.qh:109
float cos(float f)
float sin(float f)
string string_null
Definition nil.qh:9
#define _sound(e, c, s, v, a)
Definition sound.qh:43
float speed2
float autocvar_cl_tuba_attenuation
Definition tuba.qh:14

References _sound, autocvar_cl_tuba_attenuation, CH_TUBA_SINGLE, cos(), entity(), M_PI_2, pymod(), sin(), speed2, string_null, TUBA_MAX, TUBA_MIN, Tuba_PitchStep, and TUBA_STARTNOTE.

Referenced by Ent_TubaNote_Think(), and Ent_TubaNote_UpdateSound().

◆ W_Tuba_GetNote()

int W_Tuba_GetNote ( entity pl,
int hittype )

Definition at line 141 of file tuba.qc.

142{
143 float movestate = 5;
144 if (CS(pl).movement.x < 0) movestate -= 3;
145 else if (CS(pl).movement.x > 0) movestate += 3;
146 if (CS(pl).movement.y < 0) movestate -= 1;
147 else if (CS(pl).movement.y > 0) movestate += 1;
148
149 int note = 0;
150 switch (movestate)
151 {
152 // layout: originally I wanted
153 // eb e e#=f
154 // B c d
155 // Gb G G#
156 // but then you only use forward and right key. So to make things more
157 // interesting, I swapped B with e#. Har har har...
158 // eb e B
159 // f=e# c d
160 // Gb G G#
161 case 1: note = -6; break; // Gb
162 case 2: note = -5; break; // G
163 case 3: note = -4; break; // G#
164 case 4: note = +5; break; // e#
165 default:
166 case 5: note = 0; break; // c
167 case 6: note = +2; break; // d
168 case 7: note = +3; break; // eb
169 case 8: note = +4; break; // e
170 case 9: note = -1; break; // B
171 }
173 note -= 12;
175 note += 12;
176 if(hittype & HITTYPE_SECONDARY)
177 note += 7;
178
179 // we support two kinds of tubas, those tuned in Eb and those tuned in C
180 // kind of tuba currently is player slot number, or team number if in
181 // teamplay
182 // that way, holes in the range of notes are "plugged"
183 if(teamplay)
184 {
185 if(pl.team == NUM_TEAM_2 || pl.team == NUM_TEAM_4)
186 note += 3;
187 }
188 else
189 {
190 if(pl.clientcolors & 1)
191 note += 3;
192 }
193
194 // total range of notes:
195 // 0
196 // *** ** ****
197 // *** ** ****
198 // *** ** ****
199 // *** ** ****
200 // *** ********************* ****
201 // -18.........................+12
202 // *** ********************* ****
203 // -18............................+15
204 // with jump: ... +24
205 // ... +27
206 return note;
207}
#define PHYS_INPUT_BUTTON_CROUCH(s)
Definition player.qh:154
vector movement
Definition player.qh:229
#define PHYS_INPUT_BUTTON_JUMP(s)
Definition player.qh:151
const int HITTYPE_SECONDARY
Definition all.qh:29
ClientState CS(Client this)
Definition state.qh:47
const int NUM_TEAM_2
Definition teams.qh:14
const int NUM_TEAM_4
Definition teams.qh:16
bool teamplay
Definition teams.qh:59

References CS(), entity(), HITTYPE_SECONDARY, movement, NUM_TEAM_2, NUM_TEAM_4, PHYS_INPUT_BUTTON_CROUCH, PHYS_INPUT_BUTTON_JUMP, and teamplay.

Referenced by W_Tuba_NoteOn().

◆ W_Tuba_HasPlayed()

bool W_Tuba_HasPlayed ( entity pl,
.entity weaponentity,
string melody,
int instrument,
bool ignorepitch,
float mintempo,
float maxtempo )

Definition at line 13 of file tuba.qc.

14{
15 float i, j, mmin, mmax, nolength;
16 float n = tokenize_console(melody);
17 if(n > pl.(weaponentity).tuba_lastnotes_cnt)
18 return false;
19 float pitchshift = 0;
20
21 if(instrument >= 0)
22 if(pl.(weaponentity).tuba_instrument != instrument)
23 return false;
24
25 // verify notes...
26 nolength = false;
27 for(i = 0; i < n; ++i)
28 {
29 vector v = pl.(weaponentity).(tuba_lastnotes[(pl.(weaponentity).tuba_lastnotes_last - i + MAX_TUBANOTES) % MAX_TUBANOTES]);
30 float ai = stof(argv(n - i - 1));
31 float np = floor(ai);
32 if(ai == np)
33 nolength = true;
34 // n counts the last played notes BACKWARDS
35 // _x is start
36 // _y is end
37 // _z is note pitch
38 if(ignorepitch && i == 0)
39 {
40 pitchshift = np - v.z;
41 }
42 else
43 {
44 if(v.z + pitchshift != np)
45 return false;
46 }
47 }
48
49 // now we know the right NOTES were played
50 if(!nolength)
51 {
52 // verify rhythm...
53 float ti = 0;
54 if(maxtempo > 0)
55 mmin = 240 / maxtempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec
56 else
57 mmin = 0;
58 if(mintempo > 0)
59 mmax = 240 / mintempo; // 60 = "0.25 means 1 sec", at 120 0.5 means 1 sec, at 240 1 means 1 sec
60 else
61 mmax = 240; // you won't try THAT hard... (tempo 1)
62 //printf("initial tempo rules: %f %f\n", mmin, mmax);
63
64 for(i = 0; i < n; ++i)
65 {
66 vector vi = pl.(weaponentity).(tuba_lastnotes[(pl.(weaponentity).tuba_lastnotes_last - i + MAX_TUBANOTES) % MAX_TUBANOTES]);
67 float ai = stof(argv(n - i - 1));
68 ti -= 1 / (ai - floor(ai));
69 float tj = ti;
70 for(j = i+1; j < n; ++j)
71 {
72 vector vj = pl.(weaponentity).(tuba_lastnotes[(pl.(weaponentity).tuba_lastnotes_last - j + MAX_TUBANOTES) % MAX_TUBANOTES]);
73 float aj = stof(argv(n - j - 1));
74 tj -= (aj - floor(aj));
75
76 // note i should be at m*ti+b
77 // note j should be at m*tj+b
78 // so:
79 // we have a LINE l, so that
80 // vi_x <= l(ti) <= vi_y
81 // vj_x <= l(tj) <= vj_y
82 // what is m?
83
84 // vi_x <= vi_y <= vj_x <= vj_y
85 // ti <= tj
86 //printf("first note: %f to %f, should be %f\n", vi_x, vi_y, ti);
87 //printf("second note: %f to %f, should be %f\n", vj_x, vj_y, tj);
88 //printf("m1 = %f\n", (vi_x - vj_y) / (ti - tj));
89 //printf("m2 = %f\n", (vi_y - vj_x) / (ti - tj));
90 mmin = max(mmin, (vi.x - vj.y) / (ti - tj)); // lower bound
91 mmax = min(mmax, (vi.y - vj.x) / (ti - tj)); // upper bound
92 }
93 }
94
95 if(mmin > mmax) // rhythm fail
96 return false;
97 }
98
99 pl.(weaponentity).tuba_lastnotes_cnt = 0;
100
101 return true;
102}
#define tokenize_console
float stof(string val,...)
float min(float f,...)
float floor(float f)
string argv(float n)
float max(float f,...)
vector
Definition self.qh:92
vector tuba_lastnotes[MAX_TUBANOTES]
Definition tuba.qc:11
float tuba_lastnotes_cnt
Definition tuba.qc:10
#define MAX_TUBANOTES
Definition tuba.qc:8

References argv(), entity(), floor(), max(), MAX_TUBANOTES, min(), stof(), tokenize_console, tuba_lastnotes, tuba_lastnotes_cnt, and vector.

Referenced by trigger_magicear_processmessage().

◆ W_Tuba_NoteOff()

void W_Tuba_NoteOff ( entity this)

Definition at line 104 of file tuba.qc.

105{
106 entity actor = this.owner;
107 // we have a note:
108 // on: this.spawnshieldtime
109 // off: time
110 // note: this.cnt
111 .entity weaponentity = this.weaponentity_fld;
112 if (actor.(weaponentity).tuba_note == this)
113 {
114 actor.(weaponentity).tuba_lastnotes_last = (actor.(weaponentity).tuba_lastnotes_last + 1) % MAX_TUBANOTES;
115 actor.(weaponentity).(tuba_lastnotes[actor.(weaponentity).tuba_lastnotes_last]) = vec3(this.spawnshieldtime, time, this.cnt);
116 actor.(weaponentity).tuba_note = NULL;
117 actor.(weaponentity).tuba_lastnotes_cnt = bound(0, actor.(weaponentity).tuba_lastnotes_cnt + 1, MAX_TUBANOTES);
118
120 if (s != "")
121 {
122 // simulate a server message
123 switch (this.tuba_instrument)
124 {
125 default:
126 case 0: // Tuba
127 bprint(strcat("\{1}\{13}* ^3", actor.netname, "^3 played on the @!#%'n Tuba: ^7", s, "\n"));
128 break;
129 case 1:
130 bprint(strcat("\{1}\{13}* ^3", actor.netname, "^3 played on the @!#%'n Accordeon: ^7", s, "\n"));
131 break;
132 case 2:
133 bprint(strcat("\{1}\{13}* ^3", actor.netname, "^3 played on the @!#%'n Klein Bottle: ^7", s, "\n"));
134 break;
135 }
136 }
137 }
138 delete(this);
139}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float cnt
Definition powerups.qc:24
entity owner
Definition main.qh:87
float spawnshieldtime
Definition damage.qh:61
string trigger_magicear_processmessage_forallears(entity source, float teamsay, entity privatesay, string msgin)
Definition magicear.qc:149
void bprint(string text,...)
float tuba_lastnotes_last
Definition tuba.qc:9
#define vec3(_x, _y, _z)
Definition vector.qh:95
entity weaponentity_fld

References bound(), bprint(), cnt, entity(), MAX_TUBANOTES, NULL, owner, spawnshieldtime, strcat(), string_null, time, trigger_magicear_processmessage_forallears(), tuba_instrument, tuba_lastnotes, tuba_lastnotes_cnt, tuba_lastnotes_last, tuba_note, vec3, and weaponentity_fld.

Referenced by W_Tuba_NoteOn(), and W_Tuba_NoteThink().

◆ W_Tuba_NoteOn()

void W_Tuba_NoteOn ( entity actor,
.entity weaponentity,
float hittype )

Definition at line 266 of file tuba.qc.

267{
268 float n = W_Tuba_GetNote(actor, hittype);
269
270 hittype = HITTYPE_SOUND;
271 if(actor.(weaponentity).tuba_instrument & 1)
272 hittype |= HITTYPE_SECONDARY;
273 if(actor.(weaponentity).tuba_instrument & 2)
274 hittype |= HITTYPE_BOUNCE;
275
276 W_SetupShot(actor, weaponentity, false, 2, SND_Null, 0, WEP_CVAR(WEP_TUBA, damage), hittype | WEP_TUBA.m_id);
277
278 if(actor.(weaponentity).tuba_note)
279 {
280 if(actor.(weaponentity).tuba_note.cnt != n || actor.(weaponentity).tuba_note.tuba_instrument != actor.(weaponentity).tuba_instrument)
281 {
282 W_Tuba_NoteOff(actor.(weaponentity).tuba_note);
283 }
284 }
285
286 if(!actor.(weaponentity).tuba_note)
287 {
288 entity note = new(tuba_note);
289 note.weaponentity_fld = weaponentity;
290 actor.(weaponentity).tuba_note = note;
291 note.owner = note.realowner = actor;
292 note.cnt = n;
293 note.tuba_instrument = actor.(weaponentity).tuba_instrument;
295 note.nextthink = time;
296 note.spawnshieldtime = time;
297 Net_LinkEntity(note, false, 0, W_Tuba_NoteSendEntity);
298 }
299
300 actor.(weaponentity).tuba_note.teleport_time = time + WEP_CVAR(WEP_TUBA, refire) * 2 * W_WeaponRateFactor(actor); // so it can get prolonged safely
301
302 //sound(actor, c, TUBA_NOTE(n), bound(0, VOL_BASE * autocvar_cl_tuba_volume, 1), autocvar_cl_tuba_attenuation);
303 RadiusDamage(actor, actor, WEP_CVAR(WEP_TUBA, damage), WEP_CVAR(WEP_TUBA, edgedamage), WEP_CVAR(WEP_TUBA, radius), NULL, NULL, WEP_CVAR(WEP_TUBA, force), hittype | WEP_TUBA.m_id, weaponentity, NULL);
304
305 if(time > actor.(weaponentity).tuba_smoketime)
306 {
307 // FIXME gettaginfo(actor.(weaponentity), 0) doesn't return the real origin of the weapon
308 vector org = gettaginfo(actor.(weaponentity), 0);
309 if(actor.(weaponentity).tuba_instrument == 1)
310 Send_Effect(EFFECT_SMOKE_RING, org + v_up * 25 + v_right * 10 + v_forward * 14, v_up * 100, 1);
311 else if(actor.(weaponentity).tuba_instrument == 2)
312 Send_Effect(EFFECT_SMOKE_RING, org + v_up * 50 + v_right * 10 + v_forward * 45, v_up * 100, 1);
313 else
314 Send_Effect(EFFECT_SMOKE_RING, org + v_up * 40 + v_right * 10 + v_forward * 14, v_up * 100, 1);
315 actor.(weaponentity).tuba_smoketime = time + 0.25;
316 }
317}
float radius
Definition impulse.qh:11
float W_WeaponRateFactor(entity this)
vector v_up
vector v_right
vector v_forward
float RadiusDamage(entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity cantbe, entity mustbe, float forceintensity, int deathtype,.entity weaponentity, entity directhitentity)
Definition damage.qc:981
const int HITTYPE_BOUNCE
Definition all.qh:31
const int HITTYPE_SOUND
Definition all.qh:33
void Send_Effect(entity eff, vector eff_loc, vector eff_vel, int eff_cnt)
Definition all.qc:124
void Net_LinkEntity(entity e, bool docull, float dt, bool(entity this, entity to, int sendflags) sendfunc)
Definition net.qh:123
#define gettaginfo
Definition post.qh:32
vector org
Definition self.qh:92
#define W_SetupShot(ent, wepent, antilag, recoil, snd, chan, maxdamage, deathtype)
Definition tracing.qh:34
int W_Tuba_GetNote(entity pl, int hittype)
Definition tuba.qc:141
float tuba_smoketime
Definition tuba.qc:6
bool W_Tuba_NoteSendEntity(entity this, entity to, int sf)
Definition tuba.qc:209
void W_Tuba_NoteOff(entity this)
Definition tuba.qc:104
void W_Tuba_NoteThink(entity this)
Definition tuba.qc:231
#define WEP_CVAR(wep, name)
Definition all.qh:321

References entity(), gettaginfo, HITTYPE_BOUNCE, HITTYPE_SECONDARY, HITTYPE_SOUND, Net_LinkEntity(), NULL, org, radius, RadiusDamage(), Send_Effect(), setthink, time, tuba_instrument, tuba_note, tuba_smoketime, v_forward, v_right, v_up, vector, W_SetupShot, W_Tuba_GetNote(), W_Tuba_NoteOff(), W_Tuba_NoteSendEntity(), W_Tuba_NoteThink(), W_WeaponRateFactor(), and WEP_CVAR.

◆ W_Tuba_NoteSendEntity()

bool W_Tuba_NoteSendEntity ( entity this,
entity to,
int sf )

Definition at line 209 of file tuba.qc.

210{
211 msg_entity = to;
212 if (!sound_allowed(MSG_ONE, this.realowner)) return false;
213
214 WriteHeader(MSG_ENTITY, ENT_CLIENT_TUBANOTE);
216 if (sf & 1)
217 {
218 WriteChar(MSG_ENTITY, this.cnt);
219 int f = 0;
220 f |= 1 * (this.realowner != to);
221 f |= 2 * this.tuba_instrument;
223 }
224 if (sf & 2)
225 {
226 WriteVector(MSG_ENTITY, this.origin);
227 }
228 return true;
229}
vector origin
const int MSG_ENTITY
Definition net.qh:115
#define WriteHeader(to, id)
Definition net.qh:221
float MSG_ONE
Definition menudefs.qc:56
void WriteChar(float data, float dest, float desto)
void WriteByte(float data, float dest, float desto)
entity msg_entity
Definition progsdefs.qc:63
bool sound_allowed(int to, entity e)
Definition all.qc:9
entity realowner

References cnt, entity(), MSG_ENTITY, msg_entity, MSG_ONE, origin, realowner, sound_allowed(), tuba_instrument, WriteByte(), WriteChar(), and WriteHeader.

Referenced by W_Tuba_NoteOn().

◆ W_Tuba_NoteThink()

void W_Tuba_NoteThink ( entity this)

Definition at line 231 of file tuba.qc.

232{
233 float dist_mult;
234 float vol0, vol1;
235 vector dir0, dir1;
236 vector v;
237 if(time > this.teleport_time)
238 {
239 W_Tuba_NoteOff(this);
240 return;
241 }
242 this.nextthink = time;
243 dist_mult = WEP_CVAR(WEP_TUBA, attenuation) / autocvar_snd_soundradius;
244 FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != this.realowner, {
245 v = this.origin - (it.origin + it.view_ofs);
246 vol0 = max(0, 1 - vlen(v) * dist_mult);
247 dir0 = normalize(v);
248 v = this.realowner.origin - (it.origin + it.view_ofs);
249 vol1 = max(0, 1 - vlen(v) * dist_mult);
250 dir1 = normalize(v);
251 if(fabs(vol0 - vol1) > 0.005) // 0.5 percent change in volume
252 {
253 setorigin(this, this.realowner.origin);
254 this.SendFlags |= 2;
255 break;
256 }
257 if(dir0 * dir1 < 0.9994) // 2 degrees change in angle
258 {
259 setorigin(this, this.realowner.origin);
260 this.SendFlags |= 2;
261 break;
262 }
263 });
264}
float teleport_time
Definition player.qh:216
int SendFlags
Definition net.qh:118
float vlen(vector v)
vector normalize(vector v)
float fabs(float f)
float autocvar_snd_soundradius
Definition tuba.qh:71
#define IS_REAL_CLIENT(v)
Definition utils.qh:17
#define FOREACH_CLIENT(cond, body)
Definition utils.qh:50

References autocvar_snd_soundradius, entity(), fabs(), FOREACH_CLIENT, IS_REAL_CLIENT, max(), nextthink, normalize(), origin, realowner, SendFlags, teleport_time, time, vector, vlen(), W_Tuba_NoteOff(), and WEP_CVAR.

Referenced by W_Tuba_NoteOn().

Variable Documentation

◆ TUBA_INSTRUMENTS

const int TUBA_INSTRUMENTS = 3

Definition at line 437 of file tuba.qc.

Referenced by PRECACHE().

◆ tuba_lastnotes

vector tuba_lastnotes[MAX_TUBANOTES]

Definition at line 11 of file tuba.qc.

Referenced by W_Tuba_HasPlayed(), and W_Tuba_NoteOff().

◆ tuba_lastnotes_cnt

float tuba_lastnotes_cnt

Definition at line 10 of file tuba.qc.

Referenced by W_Tuba_HasPlayed(), and W_Tuba_NoteOff().

◆ tuba_lastnotes_last

float tuba_lastnotes_last

Definition at line 9 of file tuba.qc.

Referenced by W_Tuba_NoteOff().

◆ TUBA_MAX

const int TUBA_MAX = 27

Definition at line 436 of file tuba.qc.

Referenced by PRECACHE(), and tubasound().

◆ TUBA_MIN

const int TUBA_MIN = -18

Definition at line 435 of file tuba.qc.

Referenced by PRECACHE(), and tubasound().

◆ tuba_note

entity tuba_note

Definition at line 5 of file tuba.qc.

Referenced by bot_cmd_debug_assert_canfire(), NET_HANDLE(), W_Tuba_NoteOff(), and W_Tuba_NoteOn().

◆ Tuba_PitchStep

int Tuba_PitchStep

Definition at line 439 of file tuba.qc.

Referenced by NET_HANDLE(), PRECACHE(), and tubasound().

◆ tuba_smoketime

float tuba_smoketime

Definition at line 6 of file tuba.qc.

Referenced by W_Tuba_NoteOn().