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