/* * CBonusTypeHandler.cpp, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * */ #include "StdInc.h" #include "CBonusTypeHandler.h" #include "JsonNode.h" #include "Filesystem/CResourceLoader.h" #include "Filesystem/ISimpleResourceLoader.h" #include "VCMI_Lib.h" #include "CCreatureHandler.h" #include "CSpellHandler.h" ///Helpers static inline void jsonSetString(const JsonNode& source, const std::string& name, std::string& dest) { dest = source[name].String();//null->empty string } static inline void jsonSetBool(const JsonNode& source, const std::string& name, bool& dest) { const JsonNode& val = source[name]; if(!val.isNull()) //do not rely on default value { dest = val.Bool(); } } ///MacroString MacroString::MacroString(const std::string &format) { static const std::string MACRO_START = "${"; static const std::string MACRO_END = "}"; static const size_t MACRO_START_L = 2; static const size_t MACRO_END_L = 1; size_t end_pos = 0; size_t start_pos = std::string::npos; tlog5 << "Parsing format " << format << std::endl; do { start_pos = format.find(MACRO_START, end_pos); if (!(start_pos == std::string::npos)) { //chunk before macro items.push_back(Item(Item::STRING,format.substr(end_pos, start_pos-end_pos))); start_pos += MACRO_START_L; end_pos = format.find(MACRO_END, start_pos); if (end_pos == std::string::npos) { tlog2 << "Format error in: " << format <