User:Ivan/Mod format WIP

From VCMI Project Wiki
< User:Ivan
Revision as of 13:50, 14 December 2012 by Ivan (talk | contribs)
Jump to: navigation, search

Sandbox, testing syntax highlight

 
{
	"artifacts":
	[
		{
			"id": 146, /* axe of smashing */
			"bonusesPerLevel":
			[
				{
					"level": 6,
					"bonus": ["PRIMARY_SKILL", 1, 0, 0]
				}
			]
		},
		{
			"id": 147, //mithril mail
			"bonusesPerLevel":
			[
				{
					"level": 1,
					"bonus": ["STACK_HEALTH", 1, 0, 0]
				}
			]
		},
		{
			"id": 148, //sword of sharpness
			"bonusesPerLevel":
			[
				{
					"level": 1,
					"bonus": ["CREATURE_DAMAGE", 1, 0, 0]
				}
			]
		}
	]
}
 
int CHeroClass::chooseSecSkill(const std::set<int> & possibles) const //picks secondary skill out from given possibilities
{
	if(possibles.size()==1) /* picks secondary skill out from given  */
		return *possibles.begin();
	int totalProb = 0;
	for(std::set<int>::const_iterator i=possibles.begin(); i!=possibles.end(); i++)
	{
		totalProb += proSec[*i];
	}
	int ran = rand()%totalProb;
	for(std::set<int>::const_iterator i=possibles.begin(); i!=possibles.end(); i++)
	{
		ran -= proSec[*i];
		if(ran<0)
			return *i;
	}
	throw std::runtime_error("Cannot pick secondary skill!");
}