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