-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbot_sounds.cpp
More file actions
231 lines (202 loc) · 7.61 KB
/
bot_sounds.cpp
File metadata and controls
231 lines (202 loc) · 7.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// ####################################
// # #
// # Ping of Death - Bot #
// # by #
// # Markus Klinge aka Count Floyd #
// # #
// ####################################
//
// Started from the HPB-Bot Alpha Source
// by Botman so Credits for a lot of the basic
// HL Server/Client Stuff goes to him
//
// bot_sounds.cpp
//
// Hooks to let Bots 'hear' otherwise unnoticed things. Base code & idea from killaruna/ParaBot
#include "bot_globals.h"
void SoundAttachToThreat(edict_t* pEdict, const char* pszSample, float fVolume)
{
// Called by the Sound Hooking Code (in EMIT_SOUND)
// Enters the played Sound into the Array associated with the Entity
Vector vecPosition;
int iIndex;
if (FNullEnt(pEdict))
return;
// Hit/Fall Sound ?
if (strncmp("player/bhit_", pszSample, 12) == 0
|| strncmp("player/headshot", pszSample, 15) == 0)
{
iIndex = ENTINDEX(pEdict) - 1;
// crash fix courtesy of Wei Mingzhi
if (iIndex < 0 || iIndex >= gpGlobals->maxClients)
iIndex = UTIL_GetNearestPlayerIndex(VecBModelOrigin(pEdict));
clients[iIndex].fHearingDistance = 768.0f * fVolume;
clients[iIndex].fTimeSoundLasting = gpGlobals->time + 1.2f;
clients[iIndex].fMaxTimeSoundLasting = 1.2f; // KWo - 01.08.2006
clients[iIndex].vecSoundPosition = pEdict->v.origin;
}
// Weapon Pickup ?
else if (strncmp("items/gunpickup", pszSample, 15) == 0)
{
iIndex = ENTINDEX(pEdict) - 1;
// crash fix courtesy of Wei Mingzhi
if (iIndex < 0 || iIndex >= gpGlobals->maxClients)
iIndex = UTIL_GetNearestPlayerIndex(VecBModelOrigin(pEdict));
clients[iIndex].fHearingDistance = 768.0f * fVolume;
clients[iIndex].fTimeSoundLasting = gpGlobals->time + 1.2f;
clients[iIndex].fMaxTimeSoundLasting = 1.2f; // KWo - 01.08.2006
clients[iIndex].vecSoundPosition = pEdict->v.origin;
}
// Sniper zooming ?
else if (strncmp("weapons/zoom", pszSample, 12) == 0)
{
iIndex = ENTINDEX(pEdict) - 1;
// crash fix courtesy of Wei Mingzhi
if (iIndex < 0 || iIndex >= gpGlobals->maxClients)
iIndex = UTIL_GetNearestPlayerIndex(VecBModelOrigin(pEdict));
clients[iIndex].fHearingDistance = 512.0f * fVolume;
clients[iIndex].fTimeSoundLasting = gpGlobals->time + 1.2f;
clients[iIndex].fMaxTimeSoundLasting = 1.2f; // KWo - 01.08.2006
clients[iIndex].vecSoundPosition = pEdict->v.origin;
}
// Reload ?
#if 0
// this doesn't work since the reload sound is played client-side - from Whistler
else if (strncmp("weapons/reload", pszSample, 14) == 0)
{
iIndex = ENTINDEX(pEdict) - 1;
// crash fix courtesy of Wei Mingzhi
if ((iIndex < 0) || (iIndex >= gpGlobals->maxClients))
iIndex = UTIL_GetNearestPlayerIndex(VecBModelOrigin(pEdict));
clients[iIndex].fReloadingTime = gpGlobals->time + 1.5f;
// ALERT(at_logged,"[DEBUG] client %s is realoading the weapon...\n", STRING(clients[iIndex].pEdict->v.netname));
}
#endif
// The following Sounds don't have the Player Entity associated
// so we need to search the nearest Player
// Ammo Pickup ?
else if (strncmp("items/9mmclip", pszSample, 13) == 0)
{
vecPosition = pEdict->v.origin;
iIndex = UTIL_GetNearestPlayerIndex(vecPosition);
clients[iIndex].fHearingDistance = 512.0f * fVolume;
clients[iIndex].fTimeSoundLasting = gpGlobals->time + 1.2f;
clients[iIndex].fMaxTimeSoundLasting = 1.2f; // KWo - 01.08.2006
clients[iIndex].vecSoundPosition = pEdict->v.origin;
}
// CT used Hostage ?
else if (strncmp("hostage/hos", pszSample, 11) == 0)
{
vecPosition = VecBModelOrigin(pEdict);
iIndex = UTIL_GetNearestPlayerIndex(vecPosition);
clients[iIndex].fHearingDistance = 1024.0f * fVolume;
clients[iIndex].fTimeSoundLasting = gpGlobals->time + 1.2f;
clients[iIndex].fMaxTimeSoundLasting = 1.2f; // KWo - 01.08.2006
clients[iIndex].vecSoundPosition = vecPosition;
}
// Broke something ?
else if (strncmp("debris/bustmetal", pszSample, 16) == 0
|| strncmp("debris/bustglass", pszSample, 16) == 0)
{
vecPosition = VecBModelOrigin(pEdict);
iIndex = UTIL_GetNearestPlayerIndex(vecPosition);
clients[iIndex].fHearingDistance = 1024.0f * fVolume;
clients[iIndex].fTimeSoundLasting = gpGlobals->time + 1.2;
clients[iIndex].fMaxTimeSoundLasting = 1.2f; // KWo - 01.08.2006
clients[iIndex].vecSoundPosition = vecPosition;
}
// Someone opened a door
else if (strncmp("doors/doormove", pszSample, 14) == 0)
{
vecPosition = VecBModelOrigin(pEdict);
iIndex = UTIL_GetNearestPlayerIndex(vecPosition);
clients[iIndex].fHearingDistance = 1024.0f * fVolume;
clients[iIndex].fTimeSoundLasting = gpGlobals->time + 3.0f;
clients[iIndex].fMaxTimeSoundLasting = 3.0f; // KWo - 01.08.2006
clients[iIndex].vecSoundPosition = vecPosition;
}
return;
}
void SoundSimulateUpdate(int iPlayerIndex)
{
// Tries to simulate playing of Sounds to let the Bots hear
// sounds which aren't captured through Server Sound hooking
assert(iPlayerIndex >= 0); // KWo - from Whistler
assert(iPlayerIndex < gpGlobals->maxClients);
if (iPlayerIndex < 0 || iPlayerIndex >= gpGlobals->maxClients)
return; // reliability check
edict_t* pPlayer = clients[iPlayerIndex].pEdict;
float fVelocity = pPlayer->v.velocity.Length2D();
float fHearDistance = 0.0f;
float fTimeSound = 0.0f;
float fMaxTimeSound = 0.5f; // KWo - 01.08.2006
float f_last_volume; // KWo - 01.08.2006
float f_volume; // KWo - 01.08.2006
// Pressed Attack Button ?
if (pPlayer->v.oldbuttons & IN_ATTACK)
{
fHearDistance = 3072.0f; // 2048.0f; // KWo 28.10.2006
fTimeSound = gpGlobals->time + 1.2f;
fMaxTimeSound = 1.2f; // KWo - 01.08.2006
}
// Pressed Use Button ?
else if (pPlayer->v.oldbuttons & IN_USE)
{
fHearDistance = 512.0f;
fTimeSound = gpGlobals->time + 1.2f;
fMaxTimeSound = 1.2f; // KWo - 01.08.2006
}
// Uses Ladder ?
else if (pPlayer->v.movetype == MOVETYPE_FLY)
{
if (fabs(pPlayer->v.velocity.z) > 50.0f)
{
fHearDistance = 1024.0f;
fTimeSound = gpGlobals->time + 1.2f;
fMaxTimeSound = 1.2f; // KWo - 01.08.2006
}
}
// Moves fast enough ?
else
{
if (g_b_cv_FootSteps)
{ // KWo - 06.04.2006
fHearDistance = 1280.0f * (fVelocity / 240.0f); // KWo - 09.10.2006
fTimeSound = gpGlobals->time + 1.2f;
fMaxTimeSound = 1.2f; // KWo - 01.08.2006
}
}
// Did issue Sound ?
if (fHearDistance > 0.0f)
{
// Some sound already associated ?
if (clients[iPlayerIndex].fTimeSoundLasting > gpGlobals->time)
{
// New Sound louder (bigger range) than old sound ?
if (clients[iPlayerIndex].fMaxTimeSoundLasting <= 0.0f) // KWo - 01.08.2006
clients[iPlayerIndex].fMaxTimeSoundLasting = 1.2f;
// the volume is lowered down when the time of lasting sound is expiring... - KWo
// f_last_volume = clients[iPlayerIndex].fHearingDistance * (clients[iPlayerIndex].fTimeSoundLasting - gpGlobals->time)/clients[iPlayerIndex].fMaxTimeSoundLasting; // KWo - 01.08.2006
f_volume = fHearDistance; // KWo - 01.08.2006
f_last_volume = clients[iPlayerIndex].fHearingDistance; // KWo - 29.12.2009 - reverting back some function...
if (f_last_volume <= f_volume) // KWo - 01.08.2006
{
// Override it with new
clients[iPlayerIndex].fHearingDistance = fHearDistance;
clients[iPlayerIndex].fTimeSoundLasting = fTimeSound;
clients[iPlayerIndex].fMaxTimeSoundLasting = fMaxTimeSound; // KWo - 01.08.2006
clients[iPlayerIndex].vecSoundPosition = pPlayer->v.origin;
}
}
// New sound ?
else
{
// Just remember it
clients[iPlayerIndex].fHearingDistance = fHearDistance;
clients[iPlayerIndex].fTimeSoundLasting = fTimeSound;
clients[iPlayerIndex].fMaxTimeSoundLasting = fMaxTimeSound; // KWo - 01.08.2006
clients[iPlayerIndex].vecSoundPosition = pPlayer->v.origin;
}
}
return;
}