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