From abd4a96bf163fbf1c776e6be974a30b25ae54654 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Tue, 18 Sep 2012 07:36:07 +0000 Subject: [PATCH] Very simple loading and adding new creatures. Needs testing. --- client/CMusicHandler.h | 26 ---------------- lib/CModHandler.cpp | 49 ++++++++++++++++++++++++++++-- lib/Filesystem/CResourceLoader.cpp | 2 +- lib/VCMI_Lib.cpp | 3 ++ 4 files changed, 50 insertions(+), 30 deletions(-) diff --git a/client/CMusicHandler.h b/client/CMusicHandler.h index 531ab7a1a..b208e1db2 100644 --- a/client/CMusicHandler.h +++ b/client/CMusicHandler.h @@ -19,32 +19,6 @@ struct _Mix_Music; typedef struct _Mix_Music Mix_Music; struct Mix_Chunk; - -//// Sound infos for creatures in combat -//struct CreaturesBattleSounds { -// soundBase::soundID attack; -// soundBase::soundID defend; -// soundBase::soundID killed; // was killed or died -// soundBase::soundID move; -// soundBase::soundID shoot; // range attack -// soundBase::soundID wince; // attacked but did not die -// soundBase::soundID ext1; // creature specific extension -// soundBase::soundID ext2; // creature specific extension -// soundBase::soundID startMoving; // usually same as ext1 -// soundBase::soundID endMoving; // usually same as ext2 -// -// CreaturesBattleSounds(): attack(soundBase::invalid), -// defend(soundBase::invalid), -// killed(soundBase::invalid), -// move(soundBase::invalid), -// shoot(soundBase::invalid), -// wince(soundBase::invalid), -// ext1(soundBase::invalid), -// ext2(soundBase::invalid), -// startMoving(soundBase::invalid), -// endMoving(soundBase::invalid) {}; -//}; - class CAudioBase { protected: bool initialized; diff --git a/lib/CModHandler.cpp b/lib/CModHandler.cpp index 21f360301..4ee603b1c 100644 --- a/lib/CModHandler.cpp +++ b/lib/CModHandler.cpp @@ -62,6 +62,43 @@ void CModHandler::loadConfigFromFile (std::string name) modules.STACK_ARTIFACT = gameModules["STACK_ARTIFACTS"].Bool(); modules.COMMANDERS = gameModules["COMMANDERS"].Bool(); modules.MITHRIL = gameModules["MITHRIL"].Bool(); + + //auto mods = config["activeMods"]; //TODO: load only mods from the list + + CResourceLoader * modLoader = new CResourceLoader; + + auto iterator = modLoader->getIterator([](const ResourceID & ident) -> bool + { + std::string name = ident.getName(); + + return ident.getType() == EResType::TEXT + && std::count(name.begin(), name.end(), '/') == 3 + && boost::algorithm::starts_with(name, "ALL/MODS/") + && boost::algorithm::ends_with(name, "MOD"); //all mods have "mod.json" name - does it make sense? + }); + + std::set foundMods; + while (iterator.hasNext()) + { + foundMods.insert(iterator->getName()); + ++iterator; + } + + BOOST_FOREACH (auto mod, foundMods) + { + tlog3 << "\t\tFound mod file: " << mod << "\n"; + + const JsonNode config (ResourceID("mod")); + const JsonNode *value = &config["creatures"]; + if (!value->isNull()) + { + BOOST_FOREACH (auto creature, value->Vector()) + { + auto cre = loadCreature (creature); + addNewCreature (cre); + } + } + } } void CModHandler::saveConfigToFile (std::string name) { @@ -187,10 +224,15 @@ void CModHandler::recreateHandlers() { //TODO: consider some template magic to unify all handlers? - VLC->arth->artifacts.clear(); - VLC->creh->creatures.clear(); //TODO: what about items from original game? + //VLC->arth->artifacts.clear(); + //VLC->creh->creatures.clear(); //TODO: what about items from original game? - BOOST_FOREACH (auto mod, activeMods) + BOOST_FOREACH (auto creature, creatures) + { + VLC->creh->creatures.push_back (creature); + } + + BOOST_FOREACH (auto mod, activeMods) //inactive part { BOOST_FOREACH (auto art, allMods[mod].artifacts) { @@ -201,6 +243,7 @@ void CModHandler::recreateHandlers() BOOST_FOREACH (auto creature, allMods[mod].creatures) { VLC->creh->creatures.push_back (creatures[creature]); + //TODO VLC->creh->notUsedMonster.push_back (creatures[creature]); //TODO: recreate upgrades and other properties based on string id } diff --git a/lib/Filesystem/CResourceLoader.cpp b/lib/Filesystem/CResourceLoader.cpp index ccc45f3cb..6d418aa8e 100644 --- a/lib/Filesystem/CResourceLoader.cpp +++ b/lib/Filesystem/CResourceLoader.cpp @@ -419,7 +419,7 @@ void CResourceHandler::loadModsFilesystems() BOOST_FOREACH(const std::string & entry, foundMods) { - tlog1 << "\t\tFound mod filesystem: " << entry << "\n"; + tlog3 << "\t\tFound mod filesystem: " << entry << "\n"; loadFileSystem(entry); } } diff --git a/lib/VCMI_Lib.cpp b/lib/VCMI_Lib.cpp index 92e272021..a889ef499 100644 --- a/lib/VCMI_Lib.cpp +++ b/lib/VCMI_Lib.cpp @@ -102,6 +102,9 @@ void LibClasses::init() spellh->loadSpells(); tlog0<<"\tSpell handler: "<recreateHandlers(); //load all new creatures parsed in the meantime. + //TODO: This should be done every time mod config changes + IS_AI_ENABLED = false; }