Low ammo alert sounds (#362)

This commit is contained in:
Cong
2017-07-16 23:17:47 +10:00
parent 5b3fb133b1
commit 8d463e3d4b
5 changed files with 33 additions and 1 deletions

BIN
sounds/ammo_low.ogg Normal file

Binary file not shown.

3
sounds/ammo_low.txt Normal file
View File

@@ -0,0 +1,3 @@
Derived alert.wav by Corsica_S
http://freesound.org/people/Corsica_S/sounds/156453/
http://creativecommons.org/licenses/by/3.0/

BIN
sounds/ammo_none.ogg Normal file

Binary file not shown.

9
sounds/ammo_none.txt Normal file
View File

@@ -0,0 +1,9 @@
Derived from
Error.wav by Autistic Lucario
http://freesound.org/people/Autistic%20Lucario/sounds/142608/
http://creativecommons.org/licenses/by/3.0/
GunSLide.wav by RazzDaSpazz
http://freesound.org/people/RazzDaSpazz/sounds/155174/
http://creativecommons.org/publicdomain/zero/1.0/

View File

@@ -288,12 +288,32 @@ static void HandleGameEvent(
{
TActor *a = ActorGetByUID(e.u.UseAmmo.UID);
if (!a->isInUse || a->dead) break;
const int ammoBefore =
*(int *)CArrayGet(&a->ammo, e.u.UseAmmo.AmmoId);
const Ammo *ammo = AmmoGetById(&gAmmo, e.u.UseAmmo.AmmoId);
const bool wasAmmoLow = AmmoIsLow(ammo, ammoBefore);
ActorAddAmmo(a, e.u.UseAmmo.AmmoId, -(int)e.u.UseAmmo.Amount);
if (e.u.UseAmmo.PlayerUID >= 0)
const PlayerData *p = PlayerDataGetByUID(e.u.UseAmmo.PlayerUID);
if (p != NULL && p->IsLocal)
{
HUDNumPopupsAdd(
&camera->HUD.numPopups, NUMBER_POPUP_AMMO,
e.u.UseAmmo.PlayerUID, -(int)e.u.UseAmmo.Amount);
// Show low or no ammo notifications
const int ammoAfter =
*(int *)CArrayGet(&a->ammo, e.u.UseAmmo.AmmoId);
const bool isAmmoLow = AmmoIsLow(ammo, ammoAfter);
if (ammoAfter == 0)
{
// No ammo
SoundPlay(&gSoundDevice, StrSound("ammo_none"));
}
else if (!wasAmmoLow && isAmmoLow)
{
// Low ammo
SoundPlay(&gSoundDevice, StrSound("ammo_low"));
}
}
}
break;