mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	* start map in campaign button is properly disabled/enabled (I hope)
* exported json for artifact bonuses; no limiters/propagators yet, so it's not used * minor changes
This commit is contained in:
		| @@ -2810,7 +2810,7 @@ void CBonusSelection::init() | ||||
| 	} | ||||
|  | ||||
| 	//unlock if no bonuses -- it's acceptable | ||||
| 	startB->setState( ourCampaign->getCurrentScenario().travelOptions.bonusesToChoose.size() ? CButtonBase::BLOCKED : CButtonBase::NORMAL); | ||||
| 	 | ||||
|  | ||||
| // 	//init campaign state if necessary | ||||
| // 	if (ourCampaign->campaignName.size() == 0) | ||||
| @@ -3022,6 +3022,8 @@ void CBonusSelection::updateBonusSelection() | ||||
| 	const CCampaignScenario &scenario = ourCampaign->camp->scenarios[sInfo.campState->currentMap]; | ||||
| 	const std::vector<CScenarioTravel::STravelBonus> & bonDescs = scenario.travelOptions.bonusesToChoose; | ||||
|  | ||||
| 	updateStartButtonState(-1); | ||||
|  | ||||
| 	for (size_t i=0; i<bonuses->buttons.size(); i++) | ||||
| 	{ | ||||
| 		if (bonuses->buttons[i]->active) | ||||
| @@ -3215,8 +3217,7 @@ void CBonusSelection::selectBonus( int id ) | ||||
| 		sInfo.campState->chosenCampaignBonuses[sInfo.campState->currentMap] = id; | ||||
| 		GH.totalRedraw(); | ||||
|  | ||||
| 		if (startB->getState() == CButtonBase::BLOCKED) | ||||
| 			startB->setState(CButtonBase::NORMAL); | ||||
| 		updateStartButtonState(id); | ||||
| 	} | ||||
|  | ||||
|  | ||||
| @@ -3248,6 +3249,14 @@ void CBonusSelection::changeDiff( bool increase ) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CBonusSelection::updateStartButtonState( int selected /*= -1*/ ) | ||||
| { | ||||
| 	if(selected == -1) | ||||
| 		startB->setState( ourCampaign->getCurrentScenario().travelOptions.bonusesToChoose.size() ? CButtonBase::BLOCKED : CButtonBase::NORMAL); | ||||
| 	else if(startB->getState() == CButtonBase::BLOCKED) | ||||
| 		startB->setState(CButtonBase::NORMAL); | ||||
| } | ||||
|  | ||||
| CBonusSelection::CRegion::CRegion( CBonusSelection * _owner, bool _accessible, bool _selectable, int _myNumber ) | ||||
| : owner(_owner), accessible(_accessible), selectable(_selectable), myNumber(_myNumber) | ||||
| { | ||||
| @@ -3654,3 +3663,4 @@ void CCampaignScreen::showAll(SDL_Surface *to) | ||||
| 	if (pos.h != to->h || pos.w != to->w) | ||||
| 		CMessage::drawBorder(1, to, pos.w+28, pos.h+30, pos.x-14, pos.y-15); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -422,6 +422,8 @@ class CBonusSelection : public CIntObject | ||||
| 	CAdventureMapButton * diffLb, * diffRb; //buttons for changing difficulty | ||||
| 	void changeDiff(bool increase); //if false, then decrease | ||||
|  | ||||
|  | ||||
| 	void updateStartButtonState(int selected = -1); //-1 -- no bonus is selected | ||||
| 	//bonus selection | ||||
| 	void updateBonusSelection(); | ||||
| 	CHighlightableButtonsGroup * bonuses; | ||||
| @@ -479,6 +481,7 @@ private: | ||||
| 	std::vector<CPicture*> images; | ||||
|  | ||||
| 	CAdventureMapButton* createExitButton(const JsonNode& button); | ||||
|  | ||||
| public: | ||||
| 	enum CampaignSet {ROE, AB, SOD, WOG}; | ||||
|  | ||||
|   | ||||
							
								
								
									
										3554
									
								
								config/artifacts.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3554
									
								
								config/artifacts.json
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -606,6 +606,17 @@ void CArtHandler::addBonuses() | ||||
| 	auto shooterOnlyLimiter = make_shared<HasAnotherBonusLimiter>(Bonus::SHOOTER); | ||||
| 	auto dragonNatureLimiter = make_shared<HasAnotherBonusLimiter>(Bonus::DRAGON_NATURE); | ||||
|  | ||||
| // 	const JsonNode config(ResourceID("config/artifacts.json")); | ||||
| // 	BOOST_FOREACH(const JsonNode &artifact, config.Vector()) | ||||
| // 	{ | ||||
| // 		auto ga = artifacts[artifact["id"].Float()].get(); | ||||
| // 		 | ||||
| // 		BOOST_FOREACH (auto b, artifact["bonuses"].Vector()) | ||||
| // 		{ | ||||
| // 			ga->addNewBonus(ParseBonus (b["bonus"].Vector())); | ||||
| // 		} | ||||
| // 	} | ||||
|  | ||||
| 	//Attack bonus artifacts (Weapons) | ||||
| 	ART_PRIM_SKILL(7,0,+2); //Centaur Axe | ||||
| 	ART_PRIM_SKILL(8,0,+3); //Blackshard of the Dead Knight | ||||
| @@ -898,6 +909,22 @@ void CArtHandler::addBonuses() | ||||
| 		giveArtBonus(151, Bonus::STACKS_SPEED, 1); //Boots of haste | ||||
| 		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); | ||||
| } | ||||
|  | ||||
| void CArtHandler::clear() | ||||
|   | ||||
							
								
								
									
										111
									
								
								lib/JsonNode.cpp
									
									
									
									
									
								
							
							
						
						
									
										111
									
								
								lib/JsonNode.cpp
									
									
									
									
									
								
							| @@ -926,11 +926,32 @@ Bonus * ParseBonus (const JsonVector &ability_vec) //TODO: merge with AddAbility | ||||
| 	return b; | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| 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()) | ||||
| @@ -949,19 +970,8 @@ Bonus * ParseBonus (const JsonNode &ability) | ||||
| 		b->val = value->Float(); | ||||
|  | ||||
| 	value = &ability["valueType"]; | ||||
| 	if (!value->isNull()) | ||||
| 	{ | ||||
| 		std::string type = value->String(); | ||||
| 		auto it = bonusValueMap.find(type); | ||||
| 		if (it == bonusValueMap.end()) | ||||
| 		{ | ||||
| 			tlog1 << "Error: invalid value type " << type << std::endl; | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			b->valType = it->second; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	b->valType = parseByMap(bonusValueMap, &ability["valueType"], "value type "); | ||||
|  | ||||
| 	value = &ability["additionalInfo"]; | ||||
| 	if (!value->isNull()) | ||||
| @@ -979,52 +989,11 @@ Bonus * ParseBonus (const JsonNode &ability) | ||||
| 	if (!value->isNull()) | ||||
| 		b->description = value->String(); | ||||
|  | ||||
| 	b->effectRange = parseByMap(bonusLimitEffect, &ability["effectRange"], "effect range "); | ||||
| 	 | ||||
| 	value = &ability["effectRange"]; | ||||
| 	if (!value->isNull()) | ||||
| 	{ | ||||
| 		std::string type = value->String(); | ||||
| 		auto it = bonusLimitEffect.find(type); | ||||
| 		if (it == bonusLimitEffect.end()) | ||||
| 		{ | ||||
| 			tlog1 << "Error: invalid effect range " << type << std::endl; | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			b->effectRange = it->second; | ||||
| 		} | ||||
| 	} | ||||
| 	b->duration = parseByMap(bonusDurationMap, &ability["duration"], "duration type "); | ||||
|  | ||||
| 	 | ||||
| 	value = &ability["duration"]; | ||||
| 	if (!value->isNull()) | ||||
| 	{ | ||||
| 		std::string type = value->String(); | ||||
| 		auto it = bonusDurationMap.find(type); | ||||
| 		if (it == bonusDurationMap.end()) | ||||
| 		{ | ||||
| 			tlog1 << "Error: invalid duration type " << type << std::endl; | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			b->duration = it->second; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	value = &ability["source"]; | ||||
| 	if (!value->isNull()) | ||||
| 	{ | ||||
| 		std::string type = value->String(); | ||||
| 		auto it = bonusSourceMap.find(type); | ||||
| 		if (it == bonusSourceMap.end()) | ||||
| 		{ | ||||
| 			tlog1 << "Error: invalid source type " << type << std::endl; | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			b->source = it->second; | ||||
| 		} | ||||
| 	} | ||||
| 	b->source = parseByMap(bonusSourceMap, &ability["source"], "source type "); | ||||
|  | ||||
| 	//TODO: | ||||
|  | ||||
| @@ -1036,4 +1005,30 @@ Bonus * ParseBonus (const JsonNode &ability) | ||||
| 	//if (!value->isNull()) | ||||
| 	//	b->propagator = value->Float(); | ||||
| 	return b; | ||||
| } | ||||
| } | ||||
|  | ||||
| DLL_LINKAGE void UnparseBonus( JsonNode &node, const Bonus * bonus ) | ||||
| { | ||||
| 	auto reverseMap = [](const int & val, const std::map<std::string, int> map) -> std::string | ||||
| 	{ | ||||
| 		BOOST_FOREACH(auto it, map) | ||||
| 		{ | ||||
| 			if(it.second == val) | ||||
| 			{ | ||||
| 				return it.first; | ||||
| 			} | ||||
| 		} | ||||
| 	}; | ||||
| 	 | ||||
| 	node["type"].String() = reverseMap(bonus->type, bonusNameMap); | ||||
| 	node["subtype"].Float() = bonus->subtype; | ||||
| 	node["val"].Float() = bonus->val; | ||||
| 	node["valueType"].String() = reverseMap(bonus->valType, bonusValueMap); | ||||
| 	node["additionalInfo"].Float() = bonus->additionalInfo; | ||||
| 	node["turns"].Float() = bonus->turnsRemain; | ||||
| 	node["sourceID"].Float() = bonus->source; | ||||
| 	node["description"].String() = bonus->description; | ||||
| 	node["effectRange"].String() = reverseMap(bonus->effectRange, bonusLimitEffect); | ||||
| 	node["duration"].String() = reverseMap(bonus->duration, bonusDurationMap); | ||||
| 	node["source"].String() = reverseMap(bonus->source, bonusSourceMap); | ||||
| } | ||||
|   | ||||
| @@ -210,4 +210,5 @@ public: | ||||
| }; | ||||
|  | ||||
| DLL_LINKAGE Bonus * ParseBonus (const JsonVector &ability_vec); | ||||
| DLL_LINKAGE Bonus * ParseBonus (const JsonNode &bonus); | ||||
| DLL_LINKAGE Bonus * ParseBonus (const JsonNode &bonus); | ||||
| DLL_LINKAGE void UnparseBonus (JsonNode &node, const Bonus * bonus); | ||||
		Reference in New Issue
	
	Block a user