3 // negative = SVQC autochannels
4 // positive = one per entity
7 const int CH_WEAPON_A = -1;
8 const int CH_WEAPON_B = -1;
9 const int CH_WEAPON_SINGLE = 1;
10 const int CH_VOICE = -2;
11 // const int CH_VOICE_SINGLE = 2;
12 const int CH_TRIGGER = -3;
13 const int CH_TRIGGER_SINGLE = 3;
14 const int CH_SHOTS = -4;
15 const int CH_SHOTS_SINGLE = 4;
16 // const int CH_TUBA = -5;
17 const int CH_TUBA_SINGLE = 5;
18 const int CH_PAIN = -6;
19 const int CH_PAIN_SINGLE = 6;
20 const int CH_PLAYER = -7;
21 const int CH_PLAYER_SINGLE = 7;
22 // const int CH_BGM_SINGLE = -8;
23 const int CH_BGM_SINGLE = 8;
24 const int CH_AMBIENT = -9;
25 // const int CH_AMBIENT_SINGLE = 9;
27 const float ATTEN_NONE = 0;
28 const float ATTEN_MIN = 0.015625;
29 const float ATTEN_NORM = 0.5;
30 const float ATTEN_LARGE = 1;
31 const float ATTEN_IDLE = 2;
32 const float ATTEN_STATIC = 3;
33 const float ATTEN_MAX = 3.984375;
35 const float VOL_BASE = 0.7;
36 const float VOL_BASEVOICE = 1.0;
37 const float VOL_MUFFLED = 0.35;
39 // Play all sounds via sound7, for access to the extra channels.
40 // Otherwise, channels 8 to 15 would be blocked for a weird QW feature.
42 #define _sound(e, c, s, v, a) \
46 if (sound_allowed(MSG_BROADCAST, __e)) \
47 sound7(__e, c, s, v, a, 0, 0); \
50 #define _sound(e, c, s, v, a) sound7(e, c, s, v, a, 0, 0)
52 #define sound(e, c, s, v, a) _sound(e, c, Sound_fixpath(s), v, a)
55 * because sound7 didn't have origin
57 * @param e sound owner
58 * @param o sound origin
59 * @param chan sound channel
60 * @param samp sound filename
61 * @param vol sound volume
62 * @param atten sound attenuation
66 #define sound8(e, o, chan, samp, vol, atten, speed, sf) \
71 string __samp = samp; \
73 if (__chan > 0) __e = e; \
77 __chan = fabs(__chan); \
78 entity tmp = __e = new(csqc_autochannel); \
79 setthink(tmp, SUB_Remove); \
80 tmp.nextthink = time + soundlength(__samp); \
82 vector old_origin = __e.origin; \
83 vector old_mins = __e.mins; \
84 vector old_maxs = __e.maxs; \
86 setsize(__e, '0 0 0', '0 0 0'); \
87 sound7(__e, __chan, __samp, vol, atten, speed, sf); \
90 setorigin(__e, old_origin); \
91 setsize(__e, old_mins, old_maxs); \
96 ATTRIB(Sound, m_id, int, 0);
97 ATTRIB(Sound, sound_str, string());
98 CONSTRUCTOR(Sound, string() path)
101 this.sound_str = path;
103 #define Sound_fixpath(this) _Sound_fixpath((this).sound_str())
104 string _Sound_fixpath(string base)
106 if (base == "") return string_null;
108 return strcat(base, ".wav"); // let the client engine decide
110 #define extensions(x) \
115 #define tryext(ext) { string s = strcat(base, "." #ext); if (fexists(strcat("sound/", s))) return s; }
117 LOG_WARNF("Missing sound: \"%s\"", strcat("sound/", base));
123 METHOD(Sound, sound_precache, void(Sound this))
126 string s = Sound_fixpath(this);
128 profile(sprintf("precache_sound(\"%s\")", s));