2
0
Эх сурвалжийг харах

Parsing for new artifact format: http://wiki.vcmi.eu/index.php?title=Artifact_Format
Not finished, not tested.

DjWarmonger 13 жил өмнө
parent
commit
730cbd930a

+ 1 - 1
client/GUIClasses.cpp

@@ -4136,7 +4136,7 @@ void CArtPlace::showAll(SDL_Surface * to)
 {
 	if (ourArt && !picked && ourArt == ourOwner->curHero->getArt(slotID, false)) //last condition is needed for disassembling -> artifact may be gone, but we don't know yet TODO: real, nice solution
 	{
-		int graphic = locked ? 145 : ourArt->artType->id;
+		int graphic = locked ? GameConstants::ID_LOCK : ourArt->artType->id;
 		blitAt(graphics->artDefs->ourImages[graphic].bitmap, pos.x, pos.y, to);
 	}
 

+ 1 - 1
client/Graphics.h

@@ -44,7 +44,7 @@ public:
 	SDL_Color * playerColorPalette; //palette to make interface colors good - array of size [256]
 	SDL_Color * neutralColorPalette; 
 
-	CDefEssential * artDefs; //artifacts
+	CDefEssential * artDefs; //artifacts //TODO: move to CArtifact class
 	std::vector<SDL_Surface *> portraitSmall; //48x32 px portraits of heroes
 	std::vector<SDL_Surface *> portraitLarge; //58x64 px portraits of heroes
 	std::vector<CDefEssential *> flags1, flags2, flags3, flags4; //flags blitted on heroes when ,

+ 110 - 1
lib/CArtHandler.cpp

@@ -9,7 +9,6 @@
 #include "CSpellHandler.h"
 #include "CObjectHandler.h"
 #include "NetPacks.h"
-#include "JsonNode.h"
 
 using namespace boost::assign;
 
@@ -25,6 +24,40 @@ using namespace boost::assign;
 
 extern boost::rand48 ran;
 
+const std::map<std::string, int> artRarityMap = boost::assign::map_list_of 
+	("TREASURE", CArtifact::ART_TREASURE)
+	("MINOR", CArtifact::ART_MINOR)
+	("MAJOR", CArtifact::ART_MAJOR)
+	("RELIC", CArtifact::ART_RELIC)
+	("SPECIAL", CArtifact::ART_SPECIAL);
+
+#define ART_BEARER(x) ( #x, ArtBearer::x )
+	const std::map<std::string, int> artifactBearerMap = boost::assign::map_list_of ART_BEARER_LIST;
+#undef ART_BEARER
+
+#define ART_POS(x) ( #x, ArtifactPosition::x )
+
+const std::map<std::string, int> artifactPositionMap = boost::assign::map_list_of 
+	ART_POS(HEAD)
+	ART_POS(SHOULDERS)
+	ART_POS(NECK)
+	ART_POS(RIGHT_HAND)
+	ART_POS(LEFT_HAND)
+	ART_POS(TORSO)
+	ART_POS(RIGHT_RING)
+	ART_POS(LEFT_RING)
+	ART_POS(FEET)
+	ART_POS(MISC1)
+	ART_POS(MISC2)
+	ART_POS(MISC3)
+	ART_POS(MISC4)
+	ART_POS(MISC5)
+	ART_POS(MACH1)
+	ART_POS(MACH2)
+	ART_POS(MACH3)
+	ART_POS(MACH4)
+	ART_POS(SPELLBOOK); //no need to specify commander / stack position?
+
 const std::string & CArtifact::Name() const
 {
 	return name;
@@ -402,6 +435,82 @@ void CArtHandler::loadArtifacts(bool onlyTxt)
 	}
 }
 
+void CArtHandler::load(const JsonNode & node)
+{
+	BOOST_FOREACH(auto & entry, node.Struct())
+	{
+		if (!entry.second.isNull()) // may happens if mod removed creature by setting json entry to null
+		{
+			CArtifact * art = loadArtifact(entry.second);
+			art->setName (entry.first);
+			art->id = artifacts.size();
+
+			artifacts.push_back(art);
+			tlog3 << "Added artifact: " << entry.first << "\n";
+			VLC->modh->identifiers.registerObject (std::string("artifact.") + art->Name(), art->id);
+		}
+	}
+}
+
+CArtifact * CArtHandler::loadArtifact(const JsonNode & node)
+{
+	CArtifact * art = new CArtifact;
+	const JsonNode *value;
+
+	const JsonNode & text = node["text"];
+	art->setName		(text["name"].String());
+	art->setDescription	(text["description"].String());
+	art->setName		(text["event"].String());
+
+	art->image = node["image"].String();
+
+	art->price = node["value"].Float();
+	
+	int bearerType = -1;
+
+	auto it = artifactBearerMap.find (value->String());
+	if (it != artifactPositionMap.end())
+	{
+		bearerType = it->second;
+		switch (bearerType)
+		{
+			case ArtBearer::HERO: //TODO: allow arts having several possible bearers
+				break;
+			case ArtBearer::COMMANDER:
+				makeItCommanderArt(art->id); //TODO: when id is deduced?
+				break;
+			case ArtBearer::CREATURE:
+				makeItCreatureArt(art->id);
+				break;
+		}
+	}
+	else
+		tlog2 << "Warning! Artifact type " << value->String() << " not recognized!";
+
+	value = &node["slot"];
+	if (!value->isNull() && bearerType == ArtBearer::HERO) //we assume non-hero slots are irrelevant?
+	{
+		auto it = artifactPositionMap.find (value->String());
+		if (it != artifactPositionMap.end())
+		{
+			auto slot = it->second;
+			art->possibleSlots[ArtBearer::HERO].push_back (slot);
+		}
+		else
+			tlog2 << "Warning! Artifact slot " << value->String() << " not recognized!";
+	}
+
+	BOOST_FOREACH (const JsonNode &bonus, node["bonuses"].Vector())
+	{
+		auto b = JsonUtils::parseBonus(bonus);
+		b->source = Bonus::ARTIFACT;
+		b->duration = Bonus::PERMANENT;
+		art->addNewBonus(b);
+	}
+
+	return art;
+}
+
 int CArtHandler::convertMachineID(int id, bool creToArt )
 {
 	int dif = 142;

+ 18 - 2
lib/CArtHandler.h

@@ -3,6 +3,7 @@
 
 #include "../lib/HeroBonus.h"
 #include "../lib/ConstTransitivePtr.h"
+#include "JsonNode.h"
 
 /*
  * CArtHandler.h, part of VCMI engine
@@ -51,11 +52,18 @@ namespace ArtifactID
 	};
 }
 
+#define ART_BEARER_LIST \
+	ART_BEARER(HERO)\
+	ART_BEARER(CREATURE)\
+	ART_BEARER(COMMANDER)
+
 namespace ArtBearer
 {
 	enum
 	{
-		HERO, CREATURE, COMMANDER
+#define ART_BEARER(x) x,
+		ART_BEARER_LIST
+#undef ART_BEARER
 	};
 }
 
@@ -66,6 +74,9 @@ protected:
 	std::string eventText; //short story displayed upon picking
 public:
 	enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes
+
+	std::string image;
+
 	const std::string &Name() const; //getter
 	const std::string &Description() const; //getter
 	const std::string &EventText() const;
@@ -89,7 +100,7 @@ public:
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
 		h & static_cast<CBonusSystemNode&>(*this);
-		h & name & description & price & possibleSlots & constituents & constituentOf & aClass & id;
+		h & name & description & eventText & image & price & possibleSlots & constituents & constituentOf & aClass & id;
 	}
 
 	CArtifact();
@@ -213,6 +224,11 @@ public:
 	std::set<ui32> growingArtifacts;
 
 	void loadArtifacts(bool onlyTxt);
+	/// load all artifacts from json structure
+	void load(const JsonNode & node);
+	/// load one artifact from json config
+	CArtifact * loadArtifact(const JsonNode & node);
+
 	void sortArts();
 	void addBonuses();
 	void clear();