]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/effects/qc/globalsound.qh
Merge branch 'master' into terencehill/infomessages_panel_update
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / qc / globalsound.qh
1 #ifndef GLOBALSOUND_H
2 #define GLOBALSOUND_H
3
4 #ifdef SVQC
5         /** Use new sound handling. TODO: use when sounds play correctly on clients */
6         bool autocvar_g_debug_globalsounds = false;
7 #endif
8
9 // player sounds, voice messages
10
11 .string m_playersoundstr;
12 ..string m_playersoundfld;
13
14 REGISTRY(PlayerSounds, BITS(8) - 1)
15 #define PlayerSounds_from(i) _PlayerSounds_from(i, NULL)
16 #define REGISTER_PLAYERSOUND(id) \
17         .string _playersound_##id; \
18         REGISTER(PlayerSounds, playersound, id, m_id, new_pure(PlayerSound)) \
19         { \
20                 this.m_playersoundstr = #id; \
21                 this.m_playersoundfld = _playersound_##id; \
22         }
23 REGISTER_REGISTRY(PlayerSounds)
24 REGISTRY_SORT(PlayerSounds)
25 STATIC_INIT(PlayerSounds_renumber)
26 {
27         FOREACH(PlayerSounds, true, it.m_id = i);
28 }
29 REGISTRY_CHECK(PlayerSounds)
30
31 REGISTER_PLAYERSOUND(death)
32 REGISTER_PLAYERSOUND(drown)
33 REGISTER_PLAYERSOUND(fall)
34 REGISTER_PLAYERSOUND(falling)
35 REGISTER_PLAYERSOUND(gasp)
36 REGISTER_PLAYERSOUND(jump)
37 REGISTER_PLAYERSOUND(pain100)
38 REGISTER_PLAYERSOUND(pain25)
39 REGISTER_PLAYERSOUND(pain50)
40 REGISTER_PLAYERSOUND(pain75)
41
42 .bool instanceOfVoiceMessage;
43 .int m_playersoundvt;
44 #define REGISTER_VOICEMSG(id, vt) \
45         .string _playersound_##id; \
46         REGISTER(PlayerSounds, playersound, id, m_id, new_pure(VoiceMessage)) \
47         { \
48                 this.instanceOfVoiceMessage = true; \
49                 this.m_playersoundstr = #id; \
50                 this.m_playersoundfld = _playersound_##id; \
51                 this.m_playersoundvt = vt; \
52         }
53
54 const int VOICETYPE_PLAYERSOUND = 10;
55 const int VOICETYPE_TEAMRADIO = 11;
56 const int VOICETYPE_LASTATTACKER = 12;
57 const int VOICETYPE_LASTATTACKER_ONLY = 13;
58 const int VOICETYPE_AUTOTAUNT = 14;
59 const int VOICETYPE_TAUNT = 15;
60
61 REGISTER_VOICEMSG(attack, VOICETYPE_TEAMRADIO)
62 REGISTER_VOICEMSG(attackinfive, VOICETYPE_TEAMRADIO)
63 REGISTER_VOICEMSG(coverme, VOICETYPE_TEAMRADIO)
64 REGISTER_VOICEMSG(defend, VOICETYPE_TEAMRADIO)
65 REGISTER_VOICEMSG(freelance, VOICETYPE_TEAMRADIO)
66 REGISTER_VOICEMSG(incoming, VOICETYPE_TEAMRADIO)
67 REGISTER_VOICEMSG(meet, VOICETYPE_TEAMRADIO)
68 REGISTER_VOICEMSG(needhelp, VOICETYPE_TEAMRADIO)
69 REGISTER_VOICEMSG(seenflag, VOICETYPE_TEAMRADIO)
70 REGISTER_VOICEMSG(taunt, VOICETYPE_TAUNT)
71 REGISTER_VOICEMSG(teamshoot, VOICETYPE_LASTATTACKER)
72
73 // reserved sound names for the future (some models lack sounds for them):
74 // _VOICEMSG(flagcarriertakingdamage)
75 // _VOICEMSG(getflag)
76 // reserved sound names for the future (ALL models lack sounds for them):
77 // _VOICEMSG(affirmative)
78 // _VOICEMSG(attacking)
79 // _VOICEMSG(defending)
80 // _VOICEMSG(roaming)
81 // _VOICEMSG(onmyway)
82 // _VOICEMSG(droppedflag)
83 // _VOICEMSG(negative)
84 // _VOICEMSG(seenenemy)
85
86 .string m_globalsoundstr;
87 REGISTRY(GlobalSounds, BITS(8) - 1)
88 #define GlobalSounds_from(i) _GlobalSounds_from(i, NULL)
89 #define REGISTER_GLOBALSOUND(id, str) \
90         REGISTER(GlobalSounds, GS, id, m_id, new_pure(GlobalSound)) \
91         { \
92                 this.m_globalsoundstr = str; \
93         }
94 REGISTER_REGISTRY(GlobalSounds)
95 REGISTRY_SORT(GlobalSounds)
96 STATIC_INIT(GlobalSounds_renumber)
97 {
98         FOREACH(GlobalSounds, true, it.m_id = i);
99 }
100 REGISTRY_CHECK(GlobalSounds)
101 void PrecacheGlobalSound(string samplestring);
102 PRECACHE(GlobalSounds)
103 {
104         FOREACH(GlobalSounds, true, PrecacheGlobalSound(it.m_globalsoundstr));
105 }
106
107 REGISTER_GLOBALSOUND(STEP, "misc/footstep0 6")
108 REGISTER_GLOBALSOUND(STEP_METAL, "misc/metalfootstep0 6")
109 REGISTER_GLOBALSOUND(FALL, "misc/hitground 4")
110 REGISTER_GLOBALSOUND(FALL_METAL, "misc/metalhitground 4")
111
112 bool GetPlayerSoundSampleField_notFound;
113 void PrecachePlayerSounds(string f);
114 //#ifdef CSQC
115         .string GetVoiceMessageSampleField(string type);
116         .string GetPlayerSoundSampleField(string type);
117         void ClearPlayerSounds(entity this);
118         float LoadPlayerSounds(entity this, string f, bool strict);
119         void UpdatePlayerSounds(entity this);
120 //#endif
121 entity GetVoiceMessage(string type);
122
123 #ifdef SVQC
124
125         void _GlobalSound(entity this, entity gs, entity ps, string sample, float chan, float vol, float voicetype, bool fake);
126         #define GlobalSound(this, def, chan, vol, voicetype) _GlobalSound(this, def, NULL, string_null, chan, vol, voicetype, false)
127         #define GlobalSound_string(this, def, chan, vol, voicetype) _GlobalSound(this, NULL, NULL, def, chan, vol, voicetype, false)
128         #define PlayerSound(this, def, chan, vol, voicetype) _GlobalSound(this, NULL, def, string_null, chan, vol, voicetype, false)
129         #define VoiceMessage(this, def, msg) \
130                 MACRO_BEGIN \
131                 { \
132                         entity VM = def; \
133                         int voicetype = VM.m_playersoundvt; \
134                         bool ownteam = (voicetype == VOICETYPE_TEAMRADIO); \
135                         int flood = Say(this, ownteam, NULL, msg, true); \
136                         bool fake; \
137                         if (IS_SPEC(this) || IS_OBSERVER(this) || flood < 0) fake = true; \
138                         else if (flood > 0) fake = false; \
139                         else break; \
140                         _GlobalSound(this, NULL, VM, string_null, CH_VOICE, VOL_BASEVOICE, voicetype, fake); \
141                 } MACRO_END
142
143 #endif
144
145 string allvoicesamples;
146 STATIC_INIT(allvoicesamples)
147 {
148     FOREACH(PlayerSounds, it.instanceOfVoiceMessage, allvoicesamples = strcat(allvoicesamples, " ", it.m_playersoundstr));
149     allvoicesamples = strzone(substring(allvoicesamples, 1, -1));
150 }
151
152 #endif