diff --git a/client/CAdvmapInterface.cpp b/client/CAdvmapInterface.cpp index acb6373ea..057d1b3e7 100644 --- a/client/CAdvmapInterface.cpp +++ b/client/CAdvmapInterface.cpp @@ -1450,7 +1450,8 @@ void CAdvMapInt::select(const CArmedInstance *sel, bool centerView /*= true*/) assert(sel); LOCPLINT->cb->setSelection(sel); selection = sel; - CCS->musich->playMusic(CCS->musich->terrainMusics[LOCPLINT->cb->getTile(sel->visitablePos())->tertype]); + if (LOCPLINT->battleInt == NULL) + CCS->musich->playMusic(CCS->musich->terrainMusics[LOCPLINT->cb->getTile(sel->visitablePos())->tertype]); if(centerView) centerOn(sel); diff --git a/client/CBattleInterface.cpp b/client/CBattleInterface.cpp index c978b3730..73d861108 100644 --- a/client/CBattleInterface.cpp +++ b/client/CBattleInterface.cpp @@ -27,6 +27,7 @@ #include "CCreatureWindow.h" #include "CVideoHandler.h" #include "../lib/CTownHandler.h" +#include "../lib/map.h" #include #include #include @@ -1431,6 +1432,12 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe bTacticNextStack(); active = 0; } + + CCS->musich->stopMusic(); + + int channel = CCS->soundh->playSoundFromSet(CCS->soundh->battleIntroSounds); + CCS->soundh->setCallback(channel, boost::bind(&CMusicHandler::playMusicFromSet, CCS->musich, CCS->musich->battleMusics, -1)); + } CBattleInterface::~CBattleInterface() @@ -1478,7 +1485,15 @@ CBattleInterface::~CBattleInterface() delete siegeH; curInt->battleInt = NULL; - //TODO:restart music (can be AI or terrain). May be easier to backup and restore it instead of re-selecting + //TODO: play AI tracks if battle was during AI turn + //if (!curInt->makingTurn) + //CCS->musich->playMusicFromSet(CCS->musich->aiMusics, -1); + + if(adventureInt && adventureInt->selection) + { + int terrain = LOCPLINT->cb->getTile(adventureInt->selection->visitablePos())->tertype; + CCS->musich->playMusic(CCS->musich->terrainMusics[terrain], -1); + } } void CBattleInterface::setPrintCellBorders(bool set) diff --git a/client/CMusicHandler.cpp b/client/CMusicHandler.cpp index 3140ee849..a5ff73f67 100644 --- a/client/CMusicHandler.cpp +++ b/client/CMusicHandler.cpp @@ -331,6 +331,8 @@ CMusicHandler::CMusicHandler() #undef VCMI_MUSIC_FILE // Vectors for helper + aiMusics += musicBase::AITheme0, musicBase::AITheme1, musicBase::AITheme2; + battleMusics += musicBase::combat1, musicBase::combat2, musicBase::combat3, musicBase::combat4; diff --git a/client/CMusicHandler.h b/client/CMusicHandler.h index 4582f2b57..4579d0465 100644 --- a/client/CMusicHandler.h +++ b/client/CMusicHandler.h @@ -157,6 +157,7 @@ public: // Musics std::map musics; + std::vector aiMusics; std::vector battleMusics; std::vector townMusics; std::vector terrainMusics; diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index a3ef2fcd7..d7f4c3a4f 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -571,10 +571,6 @@ void CPlayerInterface::battleStart(const CCreatureSet *army1, const CCreatureSet SDL_Delay(20); boost::unique_lock un(*pim); - CCS->musich->stopMusic(); - - int channel = CCS->soundh->playSoundFromSet(CCS->soundh->battleIntroSounds); - CCS->soundh->setCallback(channel, boost::bind(&CMusicHandler::playMusicFromSet, CCS->musich, CCS->musich->battleMusics, -1)); GH.pushInt(battleInt); } diff --git a/config/startres.json b/config/startres.json index 0b7bd3624..0a5f3df8c 100644 --- a/config/startres.json +++ b/config/startres.json @@ -2,28 +2,28 @@ { "difficulty": [ - { + { "human": { "wood" : 30, "mercury": 15, "ore": 30, "sulfur": 15, "crystal": 15, "gems": 15, "gold": 30000, "mithril": 0 }, "ai": { "wood" : 5, "mercury": 2, "ore": 5, "sulfur": 2, "crystal": 2, "gems": 2, "gold": 5000, "mithril": 0 } }, - { + { "human": { "wood" : 20, "mercury": 10, "ore": 20, "sulfur": 10, "crystal": 10, "gems": 10, "gold": 20000, "mithril": 0 }, "ai": { "wood" : 10, "mercury": 4, "ore": 10, "sulfur": 4, "crystal": 4, "gems": 4, "gold": 7500, "mithril": 0 } }, - { + { "human": { "wood" : 15, "mercury": 7, "ore": 15, "sulfur": 7, "crystal": 7, "gems": 7, "gold": 15000, "mithril": 0 }, "ai": { "wood" : 15, "mercury": 7, "ore": 15, "sulfur": 7, "crystal": 7, "gems": 7, "gold": 10000, "mithril": 0 } }, - { + { "human": { "wood" : 10, "mercury": 4, "ore": 10, "sulfur": 4, "crystal": 4, "gems": 4, "gold": 10000, "mithril": 0 }, "ai": { "wood" : 15, "mercury": 7, "ore": 15, "sulfur": 7, "crystal": 7, "gems": 7, "gold": 10000, "mithril": 0 } - } + }, { - "human": { "wood" : 0, "mercury": 0, "ore": 0 , "sulfur": 0, "crystal": 0, "gems": 0, "gold": 0, "mithril": 0 }, + "human": { "wood" : 0, "mercury": 0, "ore": 0 , "sulfur": 0, "crystal": 0, "gems": 0, "gold": 0, "mithril": 0 }, "ai": { "wood" : 15, "mercury": 7, "ore": 15, "sulfur": 7, "crystal": 7, "gems": 7, "gold": 10000, "mithril": 0 } } ] diff --git a/lib/JsonNode.cpp b/lib/JsonNode.cpp index caddba207..f1fc79d9c 100644 --- a/lib/JsonNode.cpp +++ b/lib/JsonNode.cpp @@ -20,7 +20,8 @@ JsonNode::JsonNode(std::string input): JsonParser parser(input, *this); } -JsonNode::JsonNode(const char *filename) +JsonNode::JsonNode(const char *filename): + type(DATA_NULL) { std::ifstream file(filename); std::string str((std::istreambuf_iterator(file)), @@ -246,12 +247,13 @@ JsonParser::JsonParser(const std::string inputString, JsonNode &root): pos(0) { extractValue(root); + extractWhitespace(false); //Warn if there are any non-whitespace symbols left - if (input.find_first_not_of(" \r\t\n", pos) != std::string::npos) + if (pos < input.size()) error("Not all file was parsed!", true); - //TODO: better way to show errors + //TODO: better way to show errors (like printing file name as well) tlog2<= input.size()) + if (pos >= input.size() && verbose) return error("Unexpected end of file!"); return true; } diff --git a/lib/JsonNode.h b/lib/JsonNode.h index b5203418e..f6c066ace 100644 --- a/lib/JsonNode.h +++ b/lib/JsonNode.h @@ -43,7 +43,7 @@ public: //Create tree from Json-formatted input explicit JsonNode(std::string input); //Create tree from JSON file - JsonNode(const char *filename); + explicit JsonNode(const char *filename); //Copy c-tor JsonNode(const JsonNode ©); @@ -101,7 +101,7 @@ class JsonParser bool extractEscaping(std::string &str); bool extractLiteral(const std::string &literal); bool extractString(std::string &string); - bool extractWhitespace(); + bool extractWhitespace(bool verbose = true); bool extractSeparator(); //Methods for extracting JSON data