Browse Source

Very simple loading and adding new creatures. Needs testing.

DjWarmonger 13 years ago
parent
commit
abd4a96bf1
4 changed files with 50 additions and 30 deletions
  1. 0 26
      client/CMusicHandler.h
  2. 46 3
      lib/CModHandler.cpp
  3. 1 1
      lib/Filesystem/CResourceLoader.cpp
  4. 3 0
      lib/VCMI_Lib.cpp

+ 0 - 26
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;

+ 46 - 3
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<std::string> 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 creature, creatures)
+	{
+		VLC->creh->creatures.push_back (creature);
+	}
 
-	BOOST_FOREACH (auto mod, activeMods)
+	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
 		}

+ 1 - 1
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);
 	}
 }

+ 3 - 0
lib/VCMI_Lib.cpp

@@ -102,6 +102,9 @@ void LibClasses::init()
 	spellh->loadSpells();
 	tlog0<<"\tSpell handler: "<<pomtime.getDiff()<<std::endl;
 
+	modh->recreateHandlers(); //load all new creatures parsed in the meantime.
+	//TODO: This should be done every time mod config changes
+
 	IS_AI_ENABLED = false;
 }