mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-17 13:41:07 +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;
|
bonus->sid = art->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CBonusSystemNode::treeHasChanged();
|
||||||
|
|
||||||
for (CArtifact * art : artifacts)
|
for (CArtifact * art : artifacts)
|
||||||
{
|
{
|
||||||
|
@ -140,6 +140,7 @@ void CCreature::setId(CreatureID ID)
|
|||||||
if(bonus->source == Bonus::CREATURE_ABILITY)
|
if(bonus->source == Bonus::CREATURE_ABILITY)
|
||||||
bonus->sid = ID;
|
bonus->sid = ID;
|
||||||
}
|
}
|
||||||
|
CBonusSystemNode::treeHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AddAbility(CCreature *cre, const JsonVector &ability_vec)
|
static void AddAbility(CCreature *cre, const JsonVector &ability_vec)
|
||||||
@ -452,8 +453,14 @@ void CCreatureHandler::loadCrExpBon()
|
|||||||
}
|
}
|
||||||
do //parse everything that's left
|
do //parse everything that's left
|
||||||
{
|
{
|
||||||
b.sid = parser.readNumber(); //id = this particular creature ID
|
auto sid = parser.readNumber(); //id = this particular creature ID
|
||||||
loadStackExp(b, creatures[b.sid]->getBonusList(), parser); //add directly to CCreature Node
|
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());
|
while (parser.endLine());
|
||||||
|
|
||||||
|
@ -995,11 +995,6 @@ CBonusSystemNode::ENodeTypes CBonusSystemNode::getNodeType() const
|
|||||||
return nodeType;
|
return nodeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
BonusList& CBonusSystemNode::getBonusList()
|
|
||||||
{
|
|
||||||
return bonuses;
|
|
||||||
}
|
|
||||||
|
|
||||||
const BonusList& CBonusSystemNode::getBonusList() const
|
const BonusList& CBonusSystemNode::getBonusList() const
|
||||||
{
|
{
|
||||||
return bonuses;
|
return bonuses;
|
||||||
|
@ -694,7 +694,6 @@ public:
|
|||||||
void exportBonus(Bonus * b);
|
void exportBonus(Bonus * b);
|
||||||
void exportBonuses();
|
void exportBonuses();
|
||||||
|
|
||||||
BonusList &getBonusList();
|
|
||||||
const BonusList &getBonusList() const;
|
const BonusList &getBonusList() const;
|
||||||
BonusList &getExportedBonusList();
|
BonusList &getExportedBonusList();
|
||||||
CBonusSystemNode::ENodeTypes getNodeType() const;
|
CBonusSystemNode::ENodeTypes getNodeType() const;
|
||||||
|
@ -46,7 +46,7 @@ void CArmedInstance::updateMoraleBonusFromArmy()
|
|||||||
if(!validTypes(false)) //object not randomized, don't bother
|
if(!validTypes(false)) //object not randomized, don't bother
|
||||||
return;
|
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)
|
if(!b)
|
||||||
{
|
{
|
||||||
b = new Bonus(Bonus::PERMANENT, Bonus::MORALE, Bonus::ARMY, 0, -1);
|
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
|
b->description = b->description.substr(0, b->description.size()-2);//trim value
|
||||||
}
|
}
|
||||||
boost::algorithm::trim(b->description);
|
boost::algorithm::trim(b->description);
|
||||||
|
CBonusSystemNode::treeHasChanged();
|
||||||
|
|
||||||
//-1 modifier for any Undead unit in army
|
//-1 modifier for any Undead unit in army
|
||||||
const ui8 UNDEAD_MODIFIER_ID = -2;
|
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(hasUndead)
|
||||||
{
|
{
|
||||||
if(!undeadModifier)
|
if(!undeadModifier)
|
||||||
|
@ -818,7 +818,7 @@ void CGHeroInstance::updateSkill(SecondarySkill which, int val)
|
|||||||
|
|
||||||
|
|
||||||
Bonus::ValueType skillValType = skillVal ? Bonus::BASE_NUMBER : Bonus::INDEPENDENT_MIN;
|
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
|
.And(Selector::sourceType(Bonus::SECONDARY_SKILL)))) //only local hero bonus
|
||||||
{
|
{
|
||||||
b->val = skillVal;
|
b->val = skillVal;
|
||||||
@ -831,6 +831,7 @@ void CGHeroInstance::updateSkill(SecondarySkill which, int val)
|
|||||||
addNewBonus(bonus);
|
addNewBonus(bonus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CBonusSystemNode::treeHasChanged();
|
||||||
}
|
}
|
||||||
void CGHeroInstance::setPropertyDer( ui8 what, ui32 val )
|
void CGHeroInstance::setPropertyDer( ui8 what, ui32 val )
|
||||||
{
|
{
|
||||||
@ -1365,6 +1366,7 @@ void CGHeroInstance::setPrimarySkill(PrimarySkill::PrimarySkill primarySkill, si
|
|||||||
{
|
{
|
||||||
skill->val += value;
|
skill->val += value;
|
||||||
}
|
}
|
||||||
|
CBonusSystemNode::treeHasChanged();
|
||||||
}
|
}
|
||||||
else if(primarySkill == PrimarySkill::EXPERIENCE)
|
else if(primarySkill == PrimarySkill::EXPERIENCE)
|
||||||
{
|
{
|
||||||
|
@ -856,7 +856,7 @@ void CGTownInstance::deserializationFix()
|
|||||||
|
|
||||||
void CGTownInstance::updateMoraleBonusFromArmy()
|
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)
|
if(!b)
|
||||||
{
|
{
|
||||||
b = new Bonus(Bonus::PERMANENT, Bonus::MORALE, Bonus::ARMY, 0, -1);
|
b = new Bonus(Bonus::PERMANENT, Bonus::MORALE, Bonus::ARMY, 0, -1);
|
||||||
@ -864,7 +864,10 @@ void CGTownInstance::updateMoraleBonusFromArmy()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (garrisonHero)
|
if (garrisonHero)
|
||||||
|
{
|
||||||
b->val = 0;
|
b->val = 0;
|
||||||
|
CBonusSystemNode::treeHasChanged();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
CArmedInstance::updateMoraleBonusFromArmy();
|
CArmedInstance::updateMoraleBonusFromArmy();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user