mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	* experimental support for bonus limiter/propagator loading from json (not turned on yet)
This commit is contained in:
		| @@ -910,21 +910,21 @@ void CArtHandler::addBonuses() | ||||
| 		ART_PRIM_SKILL (154, 0, +6); //Hardened Shield | ||||
| 	} | ||||
|  | ||||
| // 	JsonNode cfg; | ||||
| // 	BOOST_FOREACH(auto art, artifacts) | ||||
| // 	{ | ||||
| // 		art->id; | ||||
| // 		JsonNode jn; | ||||
| // 		jn["id"].Float() = art->id; | ||||
| // 		BOOST_FOREACH (auto b, art->getBonusList()) | ||||
| // 		{ | ||||
| // 			JsonNode bn; | ||||
| // 			UnparseBonus(bn, b); | ||||
| // 			jn["bonuses"].Vector().push_back(bn); | ||||
| // 		} | ||||
| // 		cfg.Vector().push_back(jn); | ||||
| // 	} | ||||
| // 	JsonWriter(std::ofstream("config/artifacts.json"), cfg); | ||||
| 	JsonNode cfg; | ||||
| 	BOOST_FOREACH(auto art, artifacts) | ||||
| 	{ | ||||
| 		art->id; | ||||
| 		JsonNode jn; | ||||
| 		jn["id"].Float() = art->id; | ||||
| 		BOOST_FOREACH (auto b, art->getBonusList()) | ||||
| 		{ | ||||
| 			JsonNode bn; | ||||
| 			UnparseBonus(bn, b); | ||||
| 			jn["bonuses"].Vector().push_back(bn); | ||||
| 		} | ||||
| 		cfg.Vector().push_back(jn); | ||||
| 	} | ||||
|  	JsonWriter(std::ofstream("config/artifacts.json"), cfg); | ||||
| } | ||||
|  | ||||
| void CArtHandler::clear() | ||||
|   | ||||
| @@ -48,6 +48,15 @@ const std::map<std::string, int> bonusLimitEffect = boost::assign::map_list_of | ||||
| 	BONUS_ITEM(ONLY_MELEE_FIGHT) | ||||
| 	BONUS_ITEM(ONLY_ENEMY_ARMY); | ||||
|  | ||||
| const std::map<std::string, TLimiterPtr> bonusLimiterMap = boost::assign::map_list_of | ||||
| 	("SHOOTER_ONLY", make_shared<HasAnotherBonusLimiter>(Bonus::SHOOTER)) | ||||
| 	("DRAGON_NATURE", make_shared<HasAnotherBonusLimiter>(Bonus::DRAGON_NATURE)); | ||||
|  | ||||
| const std::map<std::string, TPropagatorPtr> bonusPropagatorMap = boost::assign::map_list_of | ||||
| 	("BATTLE_WIDE", make_shared<CPropagatorNodeType>(CBonusSystemNode::BATTLE)) | ||||
| 	("VISITED_TOWN_AND_VISITOR", make_shared<CPropagatorNodeType>(CBonusSystemNode::TOWN_AND_VISITOR)); | ||||
|  | ||||
|  | ||||
| #define BONUS_LOG_LINE(x) tlog5 << x << std::endl | ||||
|  | ||||
| int CBonusSystemNode::treeChanged = 1; | ||||
|   | ||||
| @@ -879,6 +879,8 @@ namespace Selector | ||||
| } | ||||
|  | ||||
| extern DLL_LINKAGE const std::map<std::string, int> bonusNameMap, bonusValueMap, bonusSourceMap, bonusDurationMap, bonusLimitEffect; | ||||
| extern DLL_LINKAGE const std::map<std::string, TLimiterPtr> bonusLimiterMap; | ||||
| extern DLL_LINKAGE const std::map<std::string, TPropagatorPtr> bonusPropagatorMap; | ||||
|  | ||||
| // BonusList template that requires full interface of CBonusSystemNode | ||||
| template <class InputIterator> | ||||
|   | ||||
| @@ -925,8 +925,24 @@ Bonus * ParseBonus (const JsonVector &ability_vec) //TODO: merge with AddAbility | ||||
| 	b->turnsRemain = 0; | ||||
| 	return b; | ||||
| } | ||||
|  | ||||
|  | ||||
| template <typename T> | ||||
| const T & parseByMap(const std::map<std::string, T> & map, const JsonNode * val, std::string err) | ||||
| { | ||||
| 	if (!val->isNull()) | ||||
| 	{ | ||||
| 		std::string type = val->String(); | ||||
| 		auto it = map.find(type); | ||||
| 		if (it == map.end()) | ||||
| 		{ | ||||
| 			tlog1 << "Error: invalid " << err << type << std::endl; | ||||
| 			return T(); | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			return it->second; | ||||
| 		} | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| Bonus * ParseBonus (const JsonNode &ability) | ||||
| { | ||||
| @@ -934,24 +950,6 @@ Bonus * ParseBonus (const JsonNode &ability) | ||||
| 	Bonus * b = new Bonus(); | ||||
| 	const JsonNode *value; | ||||
|  | ||||
| 	auto parseByMap = [&](const std::map<std::string, int> & map, const JsonNode * val, std::string err) -> int | ||||
| 	{ | ||||
| 		if (!val->isNull()) | ||||
| 		{ | ||||
| 			std::string type = val->String(); | ||||
| 			auto it = map.find(type); | ||||
| 			if (it == map.end()) | ||||
| 			{ | ||||
| 				tlog1 << "Error: invalid " << err << type << std::endl; | ||||
| 				return -1; | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				return it->second; | ||||
| 			} | ||||
| 		} | ||||
| 	}; | ||||
|  | ||||
| 	std::string type = ability["type"].String(); | ||||
| 	auto it = bonusNameMap.find(type); | ||||
| 	if (it == bonusNameMap.end()) | ||||
| @@ -969,8 +967,6 @@ Bonus * ParseBonus (const JsonNode &ability) | ||||
| 	if (!value->isNull()) | ||||
| 		b->val = value->Float(); | ||||
|  | ||||
| 	value = &ability["valueType"]; | ||||
|  | ||||
| 	b->valType = parseByMap(bonusValueMap, &ability["valueType"], "value type "); | ||||
|  | ||||
| 	value = &ability["additionalInfo"]; | ||||
| @@ -995,15 +991,15 @@ Bonus * ParseBonus (const JsonNode &ability) | ||||
|  | ||||
| 	b->source = parseByMap(bonusSourceMap, &ability["source"], "source type "); | ||||
|  | ||||
| 	//TODO: | ||||
| // 	value = &ability["limiter"]; | ||||
| // 	if (!value->isNull()) | ||||
| // 		b->limiter = parseByMap(bonusLimiterMap, value, "limiter type "); | ||||
| //  | ||||
| //  | ||||
| // 	value = &ability["propagator"]; | ||||
| // 	if (!value->isNull()) | ||||
| // 		b->propagator = parseByMap(bonusLimiterMap, value, "propagator type "); | ||||
|  | ||||
| 	//value = &ability["limiter"]; | ||||
| 	//if (!value->isNull()) | ||||
| 	//	b->limiter = value->Float(); | ||||
|  | ||||
| 	//value = &ability["propagator"]; | ||||
| 	//if (!value->isNull()) | ||||
| 	//	b->propagator = value->Float(); | ||||
| 	return b; | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user