mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Merge pull request #147 from vcmi/fix/bonusSystemCrashes
Attempt to fix crashes on save loading that occur within bonus system
This commit is contained in:
commit
8ebdbd048b
@ -694,6 +694,7 @@ void CArtHandler::afterLoadFinalization()
|
||||
bonus->sid = art->id;
|
||||
}
|
||||
}
|
||||
CBonusSystemNode::treeHasChanged();
|
||||
|
||||
for (CArtifact * art : artifacts)
|
||||
{
|
||||
|
@ -140,6 +140,7 @@ void CCreature::setId(CreatureID ID)
|
||||
if(bonus->source == Bonus::CREATURE_ABILITY)
|
||||
bonus->sid = ID;
|
||||
}
|
||||
CBonusSystemNode::treeHasChanged();
|
||||
}
|
||||
|
||||
static void AddAbility(CCreature *cre, const JsonVector &ability_vec)
|
||||
@ -452,8 +453,14 @@ void CCreatureHandler::loadCrExpBon()
|
||||
}
|
||||
do //parse everything that's left
|
||||
{
|
||||
b.sid = parser.readNumber(); //id = this particular creature ID
|
||||
loadStackExp(b, creatures[b.sid]->getBonusList(), parser); //add directly to CCreature Node
|
||||
auto sid = parser.readNumber(); //id = this particular creature ID
|
||||
b.sid = sid;
|
||||
bl.clear();
|
||||
loadStackExp(b, bl, parser);
|
||||
for(Bonus * b : bl)
|
||||
{
|
||||
creatures[sid]->addNewBonus(b); //add directly to CCreature Node
|
||||
}
|
||||
}
|
||||
while (parser.endLine());
|
||||
|
||||
|
@ -995,11 +995,6 @@ CBonusSystemNode::ENodeTypes CBonusSystemNode::getNodeType() const
|
||||
return nodeType;
|
||||
}
|
||||
|
||||
BonusList& CBonusSystemNode::getBonusList()
|
||||
{
|
||||
return bonuses;
|
||||
}
|
||||
|
||||
const BonusList& CBonusSystemNode::getBonusList() const
|
||||
{
|
||||
return bonuses;
|
||||
|
@ -694,7 +694,6 @@ public:
|
||||
void exportBonus(Bonus * b);
|
||||
void exportBonuses();
|
||||
|
||||
BonusList &getBonusList();
|
||||
const BonusList &getBonusList() const;
|
||||
BonusList &getExportedBonusList();
|
||||
CBonusSystemNode::ENodeTypes getNodeType() const;
|
||||
|
@ -46,7 +46,7 @@ void CArmedInstance::updateMoraleBonusFromArmy()
|
||||
if(!validTypes(false)) //object not randomized, don't bother
|
||||
return;
|
||||
|
||||
Bonus *b = getBonusList().getFirst(Selector::sourceType(Bonus::ARMY).And(Selector::type(Bonus::MORALE)));
|
||||
Bonus *b = getExportedBonusList().getFirst(Selector::sourceType(Bonus::ARMY).And(Selector::type(Bonus::MORALE)));
|
||||
if(!b)
|
||||
{
|
||||
b = new Bonus(Bonus::PERMANENT, Bonus::MORALE, Bonus::ARMY, 0, -1);
|
||||
@ -96,10 +96,11 @@ void CArmedInstance::updateMoraleBonusFromArmy()
|
||||
b->description = b->description.substr(0, b->description.size()-2);//trim value
|
||||
}
|
||||
boost::algorithm::trim(b->description);
|
||||
CBonusSystemNode::treeHasChanged();
|
||||
|
||||
//-1 modifier for any Undead unit in army
|
||||
const ui8 UNDEAD_MODIFIER_ID = -2;
|
||||
Bonus *undeadModifier = getBonusList().getFirst(Selector::source(Bonus::ARMY, UNDEAD_MODIFIER_ID));
|
||||
Bonus *undeadModifier = getExportedBonusList().getFirst(Selector::source(Bonus::ARMY, UNDEAD_MODIFIER_ID));
|
||||
if(hasUndead)
|
||||
{
|
||||
if(!undeadModifier)
|
||||
|
@ -818,7 +818,7 @@ void CGHeroInstance::updateSkill(SecondarySkill which, int val)
|
||||
|
||||
|
||||
Bonus::ValueType skillValType = skillVal ? Bonus::BASE_NUMBER : Bonus::INDEPENDENT_MIN;
|
||||
if(Bonus * b = getBonusList().getFirst(Selector::typeSubtype(Bonus::SECONDARY_SKILL_PREMY, which)
|
||||
if(Bonus * b = getExportedBonusList().getFirst(Selector::typeSubtype(Bonus::SECONDARY_SKILL_PREMY, which)
|
||||
.And(Selector::sourceType(Bonus::SECONDARY_SKILL)))) //only local hero bonus
|
||||
{
|
||||
b->val = skillVal;
|
||||
@ -831,6 +831,7 @@ void CGHeroInstance::updateSkill(SecondarySkill which, int val)
|
||||
addNewBonus(bonus);
|
||||
}
|
||||
|
||||
CBonusSystemNode::treeHasChanged();
|
||||
}
|
||||
void CGHeroInstance::setPropertyDer( ui8 what, ui32 val )
|
||||
{
|
||||
@ -1365,6 +1366,7 @@ void CGHeroInstance::setPrimarySkill(PrimarySkill::PrimarySkill primarySkill, si
|
||||
{
|
||||
skill->val += value;
|
||||
}
|
||||
CBonusSystemNode::treeHasChanged();
|
||||
}
|
||||
else if(primarySkill == PrimarySkill::EXPERIENCE)
|
||||
{
|
||||
|
@ -856,7 +856,7 @@ void CGTownInstance::deserializationFix()
|
||||
|
||||
void CGTownInstance::updateMoraleBonusFromArmy()
|
||||
{
|
||||
Bonus *b = getBonusList().getFirst(Selector::sourceType(Bonus::ARMY).And(Selector::type(Bonus::MORALE)));
|
||||
Bonus *b = getExportedBonusList().getFirst(Selector::sourceType(Bonus::ARMY).And(Selector::type(Bonus::MORALE)));
|
||||
if(!b)
|
||||
{
|
||||
b = new Bonus(Bonus::PERMANENT, Bonus::MORALE, Bonus::ARMY, 0, -1);
|
||||
@ -864,7 +864,10 @@ void CGTownInstance::updateMoraleBonusFromArmy()
|
||||
}
|
||||
|
||||
if (garrisonHero)
|
||||
{
|
||||
b->val = 0;
|
||||
CBonusSystemNode::treeHasChanged();
|
||||
}
|
||||
else
|
||||
CArmedInstance::updateMoraleBonusFromArmy();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user