User:Ivan/Mod format WIP
From VCMI Project Wiki
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("\tCannot pick secondary skill!\r\n");
}