Index: binaries/data/mods/public/audio/interface/alarm/alarm_ally_defeated.xml =================================================================== --- /dev/null +++ binaries/data/mods/public/audio/interface/alarm/alarm_ally_defeated.xml @@ -0,0 +1,15 @@ + + + 1 + owner + 1 + 100 + 1 + 0 + 1 + 1 + 1 + 1 + audio/interface/alarm/ + alarmalert2.ogg + Index: binaries/data/mods/public/audio/interface/alarm/alarm_defeat.xml =================================================================== --- binaries/data/mods/public/audio/interface/alarm/alarm_defeat.xml +++ binaries/data/mods/public/audio/interface/alarm/alarm_defeat.xml @@ -1,13 +0,0 @@ - - - 1 - 100 - 1 - 0 - 1 - 1 - 1 - 1 - audio/interface/alarm/ - alarmdefeat_1.ogg - Index: binaries/data/mods/public/audio/interface/alarm/alarm_defeated.xml =================================================================== --- binaries/data/mods/public/audio/interface/alarm/alarm_defeated.xml +++ binaries/data/mods/public/audio/interface/alarm/alarm_defeated.xml @@ -1,13 +1,15 @@ - - - 1 - 100 - 1 - 0 - 1 - 1 - 1 - 1 - audio/interface/alarm/ - alarmdefeat_1.ogg - + + + 1 + owner + 1 + 100 + 1 + 0 + 1 + 1 + 1 + 1 + audio/interface/alarm/ + alarmalert0.ogg + Index: binaries/data/mods/public/audio/interface/alarm/alarm_enemy_defeated.xml =================================================================== --- /dev/null +++ binaries/data/mods/public/audio/interface/alarm/alarm_enemy_defeated.xml @@ -0,0 +1,15 @@ + + + 1 + owner + 1 + 100 + 1 + 0 + 1 + 1 + 1 + 1 + audio/interface/alarm/ + alarmalert1.ogg + Index: binaries/data/mods/public/simulation/components/Player.js =================================================================== --- binaries/data/mods/public/simulation/components/Player.js +++ binaries/data/mods/public/simulation/components/Player.js @@ -920,4 +920,16 @@ this.startingTechnologies = techs; }; +Player.prototype.OnGlobalPlayerDefeated = function(msg) +{ + let cmpSound = Engine.QueryInterface(this.entity, IID_Sound); + if (!cmpSound) + return; + + let cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager); + let soundGroup = cmpSound.GetSoundGroup(this.playerID === msg.playerId ? "defeated" : this.IsAlly(msg.playerId) ? "ally_defeated" : this.state === "won" ? "won" : "enemy_defeated"); + if (soundGroup) + cmpSoundManager.PlaySoundGroupForPlayer(soundGroup, this.playerID); +}; + Engine.RegisterComponentType(IID_Player, "Player", Player); Index: binaries/data/mods/public/simulation/templates/special/player/player.xml =================================================================== --- binaries/data/mods/public/simulation/templates/special/player/player.xml +++ binaries/data/mods/public/simulation/templates/special/player/player.xml @@ -88,6 +88,13 @@ 1000 + + + interface/alarm/alarm_defeated.xml + interface/alarm/alarm_ally_defeated.xml + interface/alarm/alarm_enemy_defeated.xml + + Index: source/simulation2/components/CCmpSoundManager.cpp =================================================================== --- source/simulation2/components/CCmpSoundManager.cpp +++ source/simulation2/components/CCmpSoundManager.cpp @@ -91,6 +91,14 @@ g_SoundManager->PlayAsGroup(name, CVector3D(sourcePos), INVALID_ENTITY, false); } + virtual void PlaySoundGroupForPlayer(const VfsPath& groupPath, const player_id_t playerId) const + { + if (!g_SoundManager || GetSimContext().GetCurrentDisplayedPlayer() != playerId) + return; + + g_SoundManager->PlayAsGroup(groupPath, CVector3D(0.f, 0.f, 0.f), INVALID_ENTITY, true); + } + virtual void StopMusic() { if (!g_SoundManager) Index: source/simulation2/components/ICmpSoundManager.h =================================================================== --- source/simulation2/components/ICmpSoundManager.h +++ 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 @@ -42,6 +42,13 @@ */ 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) Index: source/simulation2/components/ICmpSoundManager.cpp =================================================================== --- source/simulation2/components/ICmpSoundManager.cpp +++ 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)