From 0f2b00326f8b6a00413bf3ee18675d0a6086b31a Mon Sep 17 00:00:00 2001 From: Stan Date: Wed, 18 Nov 2020 09:14:08 +0000 Subject: [PATCH] Notify players with a sound when a player is defeated Includes alarm_defeated_ally.ogg by @Samulis Reviewed by: @bb Comments by: @Angen Freagarach Differential Revision: https://code.wildfiregames.com/D2860 This was SVN commit r24199. --- .../{alarm_defeat.xml => alarm_defeated.xml} | 2 ++ .../interface/alarm/alarm_defeated_ally.ogg | 3 +++ .../interface/alarm/alarm_defeated_ally.xml | 15 +++++++++++++++ .../interface/alarm/alarm_defeated_enemy.xml | 15 +++++++++++++++ .../mods/public/simulation/components/Player.js | 11 +++++++++++ .../templates/special/player/player.xml | 7 +++++++ .../simulation2/components/CCmpSoundManager.cpp | 7 +++++++ .../simulation2/components/ICmpSoundManager.cpp | 3 ++- .../simulation2/components/ICmpSoundManager.h | 17 ++++++++++++----- 9 files changed, 74 insertions(+), 6 deletions(-) rename binaries/data/mods/public/audio/interface/alarm/{alarm_defeat.xml => alarm_defeated.xml} (86%) create mode 100644 binaries/data/mods/public/audio/interface/alarm/alarm_defeated_ally.ogg create mode 100644 binaries/data/mods/public/audio/interface/alarm/alarm_defeated_ally.xml create mode 100644 binaries/data/mods/public/audio/interface/alarm/alarm_defeated_enemy.xml diff --git a/binaries/data/mods/public/audio/interface/alarm/alarm_defeat.xml b/binaries/data/mods/public/audio/interface/alarm/alarm_defeated.xml similarity index 86% rename from binaries/data/mods/public/audio/interface/alarm/alarm_defeat.xml rename to binaries/data/mods/public/audio/interface/alarm/alarm_defeated.xml index 59529e3a4f..d5e4a04b6c 100644 --- a/binaries/data/mods/public/audio/interface/alarm/alarm_defeat.xml +++ b/binaries/data/mods/public/audio/interface/alarm/alarm_defeated.xml @@ -1,5 +1,7 @@ + 1 + owner 1 100 1 diff --git a/binaries/data/mods/public/audio/interface/alarm/alarm_defeated_ally.ogg b/binaries/data/mods/public/audio/interface/alarm/alarm_defeated_ally.ogg new file mode 100644 index 0000000000..015f91735d --- /dev/null +++ b/binaries/data/mods/public/audio/interface/alarm/alarm_defeated_ally.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:82006c38cca93189b36e31b354e8934e06274b596af4a884d10efc4518784a85 +size 305777 diff --git a/binaries/data/mods/public/audio/interface/alarm/alarm_defeated_ally.xml b/binaries/data/mods/public/audio/interface/alarm/alarm_defeated_ally.xml new file mode 100644 index 0000000000..fd4b57329d --- /dev/null +++ b/binaries/data/mods/public/audio/interface/alarm/alarm_defeated_ally.xml @@ -0,0 +1,15 @@ + + + 1 + owner + 1 + 100 + 1 + 0 + 1 + 1 + 1 + 1 + audio/interface/alarm/ + alarm_defeated_ally.ogg + diff --git a/binaries/data/mods/public/audio/interface/alarm/alarm_defeated_enemy.xml b/binaries/data/mods/public/audio/interface/alarm/alarm_defeated_enemy.xml new file mode 100644 index 0000000000..bc09bb73fe --- /dev/null +++ b/binaries/data/mods/public/audio/interface/alarm/alarm_defeated_enemy.xml @@ -0,0 +1,15 @@ + + + 1 + owner + 1 + 100 + 1 + 0 + 1 + 1 + 1 + 1 + audio/interface/alarm/ + alarmalert1.ogg + diff --git a/binaries/data/mods/public/simulation/components/Player.js b/binaries/data/mods/public/simulation/components/Player.js index 3eed4a99ff..cb0901f4aa 100644 --- a/binaries/data/mods/public/simulation/components/Player.js +++ b/binaries/data/mods/public/simulation/components/Player.js @@ -933,4 +933,15 @@ Player.prototype.SetStartingTechnologies = function(techs) this.startingTechnologies = techs; }; +Player.prototype.OnGlobalPlayerDefeated = function(msg) +{ + let cmpSound = Engine.QueryInterface(this.entity, IID_Sound); + if (!cmpSound) + return; + + let soundGroup = cmpSound.GetSoundGroup(this.playerID === msg.playerId ? "defeated" : this.IsAlly(msg.playerId) ? "defeated_ally" : this.state === "won" ? "won" : "defeated_enemy"); + if (soundGroup) + Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager).PlaySoundGroupForPlayer(soundGroup, this.playerID); +}; + Engine.RegisterComponentType(IID_Player, "Player", Player); diff --git a/binaries/data/mods/public/simulation/templates/special/player/player.xml b/binaries/data/mods/public/simulation/templates/special/player/player.xml index b09ea9f6b2..5cd6c6b81c 100644 --- a/binaries/data/mods/public/simulation/templates/special/player/player.xml +++ b/binaries/data/mods/public/simulation/templates/special/player/player.xml @@ -88,6 +88,13 @@ 1000 + + + interface/alarm/alarm_defeated.xml + interface/alarm/alarm_defeated_ally.xml + interface/alarm/alarm_defeated_enemy.xml + + diff --git a/source/simulation2/components/CCmpSoundManager.cpp b/source/simulation2/components/CCmpSoundManager.cpp index 8cee36a816..006dc467d3 100644 --- a/source/simulation2/components/CCmpSoundManager.cpp +++ b/source/simulation2/components/CCmpSoundManager.cpp @@ -91,6 +91,13 @@ public: g_SoundManager->PlayAsGroup(name, CVector3D(sourcePos), INVALID_ENTITY, false); } + virtual void PlaySoundGroupForPlayer(const VfsPath& groupPath, const player_id_t playerId) const + { + if (!g_SoundManager) + return; + g_SoundManager->PlayAsGroup(groupPath, CVector3D(0.f, 0.f, 0.f), INVALID_ENTITY, GetSimContext().GetCurrentDisplayedPlayer() == playerId); + } + virtual void StopMusic() { if (!g_SoundManager) diff --git a/source/simulation2/components/ICmpSoundManager.cpp b/source/simulation2/components/ICmpSoundManager.cpp index 869ab9d3e5..25a0f2c6f2 100644 --- a/source/simulation2/components/ICmpSoundManager.cpp +++ b/source/simulation2/components/ICmpSoundManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -24,5 +24,6 @@ BEGIN_INTERFACE_WRAPPER(SoundManager) DEFINE_INTERFACE_METHOD_2("PlaySoundGroup", void, ICmpSoundManager, PlaySoundGroup, std::wstring, entity_id_t) DEFINE_INTERFACE_METHOD_2("PlaySoundGroupAtPosition", void, ICmpSoundManager, PlaySoundGroupAtPosition, std::wstring, CFixedVector3D) +DEFINE_INTERFACE_METHOD_CONST_2("PlaySoundGroupForPlayer", void, ICmpSoundManager, PlaySoundGroupForPlayer, VfsPath, player_id_t) DEFINE_INTERFACE_METHOD_0("StopMusic", void, ICmpSoundManager, StopMusic) END_INTERFACE_WRAPPER(SoundManager) diff --git a/source/simulation2/components/ICmpSoundManager.h b/source/simulation2/components/ICmpSoundManager.h index 4ec3d30669..44b0a842b9 100644 --- a/source/simulation2/components/ICmpSoundManager.h +++ b/source/simulation2/components/ICmpSoundManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -30,18 +30,25 @@ class ICmpSoundManager : public IComponent public: /** * Start playing audio defined by a sound group file. - * @param name VFS path of sound group .xml, relative to audio/ - * @param source entity emitting the sound (used for positioning) + * @param name VFS path of sound group .xml, relative to audio/. + * @param source entity emitting the sound (used for positioning). */ virtual void PlaySoundGroup(const std::wstring& name, entity_id_t source) = 0; /** * Start playing audio defined by a sound group file. - * @param name VFS path of sound group .xml, relative to audio/ - * @param sourcePos 3d position of the sound emitter + * @param name VFS path of sound group .xml, relative to audio/. + * @param sourcePos 3d position of the sound emitter. */ virtual void PlaySoundGroupAtPosition(const std::wstring& name, const CFixedVector3D& sourcePos) = 0; + /** + * Start playing audio defined by a sound group file for a player. + * @param name VFS path of sound group .xml, relative to audio/. + * @param player the player entity. + */ + virtual void PlaySoundGroupForPlayer(const VfsPath& groupPath, const player_id_t playerId) const = 0; + virtual void StopMusic() = 0; DECLARE_INTERFACE_TYPE(SoundManager)