diff --git a/client/battle/BattleInterface.cpp b/client/battle/BattleInterface.cpp index f9411a9fb..8309add13 100644 --- a/client/battle/BattleInterface.cpp +++ b/client/battle/BattleInterface.cpp @@ -35,6 +35,7 @@ #include "../adventureMap/AdventureMapInterface.h" #include "../../CCallback.h" +#include "../../lib/BattleFieldHandler.h" #include "../../lib/CStack.h" #include "../../lib/CConfigHandler.h" #include "../../lib/CGeneralTextHandler.h" @@ -113,6 +114,9 @@ void BattleInterface::playIntroSoundAndUnlockInterface() onIntroSoundPlayed(); }; + auto bfieldType = getBattle()->battleGetBattlefieldType(); + const auto & battlefieldSound = bfieldType.getInfo()->musicFilename; + std::vector battleIntroSounds = { soundBase::battle00, soundBase::battle01, @@ -120,7 +124,13 @@ void BattleInterface::playIntroSoundAndUnlockInterface() soundBase::battle05, soundBase::battle06, soundBase::battle07 }; - int battleIntroSoundChannel = CCS->soundh->playSoundFromSet(battleIntroSounds); + int battleIntroSoundChannel = -1; + + if (!battlefieldSound.empty()) + battleIntroSoundChannel = CCS->soundh->playSound(battlefieldSound); + else + battleIntroSoundChannel = CCS->soundh->playSoundFromSet(battleIntroSounds); + if (battleIntroSoundChannel != -1) { CCS->soundh->setCallback(battleIntroSoundChannel, onIntroPlayed); @@ -144,7 +154,13 @@ void BattleInterface::onIntroSoundPlayed() if (openingPlaying()) openingEnd(); - CCS->musich->playMusicFromSet("battle", true, true); + auto bfieldType = getBattle()->battleGetBattlefieldType(); + const auto & battlefieldMusic = bfieldType.getInfo()->musicFilename; + + if (!battlefieldMusic.empty()) + CCS->musich->playMusic(battlefieldMusic, true, true); + else + CCS->musich->playMusicFromSet("battle", true, true); } void BattleInterface::openingEnd() diff --git a/config/schemas/battlefield.json b/config/schemas/battlefield.json index 3135c2fb4..0a19116ae 100644 --- a/config/schemas/battlefield.json +++ b/config/schemas/battlefield.json @@ -24,6 +24,18 @@ "format" : "imageFile", "description" : "Background image for this battlefield" }, + "music" : + { + "description" : "Optional, filename for custom music to play during combat on this terrain", + "type" : "string", + "format" : "musicFile" + }, + "openingSound" : + { + "description" : "Optional, filename for custom sound to play during combat opening on this terrain", + "type" : "string", + "format" : "musicFile" + }, "impassableHexes" : { "type" : "array", "description" : "List of battle hexes that will be always blocked on this battlefield (e.g. ship to ship battles)", diff --git a/docs/modders/Entities_Format/Battlefield_Format.md b/docs/modders/Entities_Format/Battlefield_Format.md index 2d8164228..e6f7a5eb0 100644 --- a/docs/modders/Entities_Format/Battlefield_Format.md +++ b/docs/modders/Entities_Format/Battlefield_Format.md @@ -1,17 +1,23 @@ ```jsonc // Human-readable name of the battlefield - "name" : "" + "name" : "", // If set to true, obstacles will be taken from "specialBattlefields" property of an obstacle // If set to false, obstacles will be taken from "allowedTerrains" instead - "isSpecial" : false + "isSpecial" : false, // List of bonuses that will affect all battles on this battlefield - "bonuses" : { BONUS_FORMAT } + "bonuses" : { BONUS_FORMAT }, // Background image for this battlefield - "graphics" : "" + "graphics" : "", + + // Optional, filename for custom music to play during combat on this terrain + "music" : "", + + // Optional, filename for custom sound to play during combat opening on this terrain + "openingSound" : "", // List of battle hexes that will be always blocked on this battlefield (e.g. ship to ship battles) - "impassableHexes" : [ 10, 20, 50 ] + "impassableHexes" : [ 10, 20, 50 ], ``` \ No newline at end of file diff --git a/lib/BattleFieldHandler.cpp b/lib/BattleFieldHandler.cpp index 7482eff5a..98a6a9a58 100644 --- a/lib/BattleFieldHandler.cpp +++ b/lib/BattleFieldHandler.cpp @@ -40,6 +40,9 @@ std::shared_ptr BattleFieldHandler::loadFromJson(const std::str for(auto node : json["impassableHexes"].Vector()) info->impassableHexes.emplace_back(node.Integer()); + info->openingSoundFilename = AudioPath::fromJson(json["openingSound"]); + info->musicFilename = AudioPath::fromJson(json["music"]); + return info; } diff --git a/lib/BattleFieldHandler.h b/lib/BattleFieldHandler.h index ca2ddc8ce..f8b814f50 100644 --- a/lib/BattleFieldHandler.h +++ b/lib/BattleFieldHandler.h @@ -32,6 +32,8 @@ public: std::string icon; si32 iconIndex; std::vector impassableHexes; + AudioPath openingSoundFilename; + AudioPath musicFilename; BattleFieldInfo() : BattleFieldInfo(BattleField::NONE, "")