浏览代码

Fixed unitialized ptrs in CArtifacts.

Parsing for adventure map def for artifacts.
DjWarmonger 13 年之前
父节点
当前提交
99e7177d57
共有 3 个文件被更改,包括 23 次插入3 次删除
  1. 3 2
      lib/CArtHandler.cpp
  2. 2 1
      lib/CArtHandler.h
  3. 18 0
      lib/CModHandler.cpp

+ 3 - 2
lib/CArtHandler.cpp

@@ -171,6 +171,8 @@ CArtifact::CArtifact()
 	possibleSlots[ArtBearer::HERO]; //we want to generate map entry even if it will be empty
 	possibleSlots[ArtBearer::CREATURE]; //we want to generate map entry even if it will be empty
 	possibleSlots[ArtBearer::COMMANDER];
+	constituents = NULL; //default pointer to zero
+	constituentOf = NULL;
 }
 
 CArtifact::~CArtifact()
@@ -333,7 +335,6 @@ void CArtHandler::loadArtifacts(bool onlyTxt)
 			continue;
 
 		// Fill in information about combined artifacts. Should perhaps be moved to a config file?
-		nart.constituentOf = NULL;
 		switch (nart.id)
 		{
 			case 129: // Angelic Alliance
@@ -399,7 +400,6 @@ void CArtHandler::loadArtifacts(bool onlyTxt)
 			// TODO: WoG combinationals
 
 			default:
-				nart.constituents = NULL;
 				break;
 		}
 
@@ -476,6 +476,7 @@ CArtifact * CArtHandler::loadArtifact(const JsonNode & node)
 	value = &graphics["large"];
 	if (!value->isNull())
 		art->large = value->String();
+	art->advMapDef = graphics["map"].String();
 
 	art->price = node["value"].Float();
 

+ 2 - 1
lib/CArtHandler.h

@@ -77,6 +77,7 @@ public:
 
 	std::string image;
 	std::string large; // big image for cutom artifacts, used in drag & drop
+	std::string advMapDef; //used for adventure map object
 	si32 iconIndex; //TODO: handle automatically
 
 	const std::string &Name() const; //getter
@@ -103,7 +104,7 @@ public:
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
 		h & static_cast<CBonusSystemNode&>(*this);
-		h & name & description & eventText & image & large & iconIndex &
+		h & name & description & eventText & image & large & advMapDef & iconIndex &
 			price & possibleSlots & constituents & constituentOf & aClass & id;
 	}
 

+ 18 - 0
lib/CModHandler.cpp

@@ -165,6 +165,7 @@ void CModHandler::loadActiveMods()
 void CModHandler::reload()
 {
 	{
+		//recreate adventure map defs
 		assert(!VLC->dobjinfo->gobjs[Obj::MONSTER].empty()); //make sure that at least some def info was found
 
 		const CGDefInfo * baseInfo = VLC->dobjinfo->gobjs[Obj::MONSTER].begin()->second;
@@ -181,6 +182,23 @@ void CModHandler::reload()
 			}
 		}
 	}
+	{
+		assert(!VLC->dobjinfo->gobjs[Obj::ARTIFACT].empty());
+
+		const CGDefInfo * baseInfo = VLC->dobjinfo->gobjs[Obj::ARTIFACT].begin()->second;
+
+		BOOST_FOREACH(auto & art, VLC->arth->artifacts)
+		{
+			if (!vstd::contains(VLC->dobjinfo->gobjs[Obj::ARTIFACT], art->id)) // no obj info for this type
+			{
+				CGDefInfo * info = new CGDefInfo(*baseInfo);
+				info->subid = art->id;
+				info->name = art->advMapDef;
+
+				VLC->dobjinfo->gobjs[Obj::ARTIFACT][art->id] = info;
+			}
+		}
+	}
 
 	{
 		assert(!VLC->dobjinfo->gobjs[Obj::TOWN].empty()); //make sure that at least some def info was found