Skip to content

Commit

Permalink
add killstreak sounds cg_killSounds
Browse files Browse the repository at this point in the history
adapted from older versions
  • Loading branch information
siecvi committed Nov 22, 2024
1 parent f35ed0d commit 51ff6e0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Sources/Client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ namespace spades {
audioDevice->RegisterSound("Sounds/Weapons/Grenade/ExplodeFar.opus");
audioDevice->RegisterSound("Sounds/Weapons/Grenade/Debris.opus");

LoadKillSounds();

// load models
renderer->RegisterModel("Models/MapObjects/Intel.kv6");
renderer->RegisterModel("Models/MapObjects/CheckPoint.kv6");
Expand Down Expand Up @@ -619,6 +621,25 @@ namespace spades {
audioDevice->PlayLocal(c.GetPointerOrNull(), AudioParam());
}

void Client::LoadKillSounds() {
// list available sounds in the directory
auto files = FileManager::EnumFiles("Sounds/Feedback/Killstreak");
for (const auto& file : files) {
// check extension
if (file.size() < 5 || file.rfind(".opus") != file.size() - 5)
continue;

auto fullPath = "Sounds/Feedback/Killstreak/" + file;

// register sound
killSounds.push_back(audioDevice->RegisterSound(fullPath.c_str()));
}

int soundsNum = static_cast<int>(killSounds.size());
if (soundsNum > 0)
SPLog("Loaded %d killstreak sounds", soundsNum);
}

/** Records chat message/game events to the log file. */
void Client::NetLog(const char* format, ...) {
char buf[4096];
Expand Down
4 changes: 4 additions & 0 deletions Sources/Client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ namespace spades {
void PlayAlertSound();
void PlayScreenshotSound();

// Killsteak sounds
std::vector<Handle<IAudioChunk>> killSounds;
void LoadKillSounds();

void UpdateWorld(float dt);
void UpdateLocalSpectator(float dt);
void UpdateLocalPlayer(float dt);
Expand Down
15 changes: 15 additions & 0 deletions Sources/Client/Client_Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ DEFINE_SPADES_SETTING(cg_hitFeedbackSoundGain, "0.2");
DEFINE_SPADES_SETTING(cg_headshotFeedbackSoundGain, "0.2");
DEFINE_SPADES_SETTING(cg_deathSoundGain, "0.2");
DEFINE_SPADES_SETTING(cg_respawnSoundGain, "1");
DEFINE_SPADES_SETTING(cg_killSounds, "0");
DEFINE_SPADES_SETTING(cg_killSoundsPitch, "1");
DEFINE_SPADES_SETTING(cg_killSoundsGain, "0.2");
DEFINE_SPADES_SETTING(cg_tracers, "1");
DEFINE_SPADES_SETTING(cg_tracersFirstPerson, "1");
DEFINE_SPADES_SETTING(cg_hitAnalyze, "0");
Expand Down Expand Up @@ -892,6 +895,18 @@ namespace spades {
meleeKills++;
else if (kt == KillTypeGrenade)
grenadeKills++;

if (cg_killSounds && curStreak >= 2) {
AudioParam param;
param.pitch = (float)cg_killSoundsPitch;
param.volume = (float)cg_killSoundsGain;

int sndIndex = curStreak - 2;
if (sndIndex < static_cast<int>(killSounds.size())) {
Handle<IAudioChunk> c = killSounds[sndIndex];
audioDevice->PlayLocal(c.GetPointerOrNull(), param);
}
}
}
}

Expand Down

0 comments on commit 51ff6e0

Please sign in to comment.