mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-06 23:26:26 +02:00
Implement loading of bonus source type
This commit is contained in:
parent
3b010d9596
commit
e54ba7b977
100
lib/JsonNode.cpp
100
lib/JsonNode.cpp
@ -427,10 +427,9 @@ static void loadBonusSubtype(TBonusSubtype & subtype, BonusType type, const Json
|
|||||||
|
|
||||||
if (node.isNumber()) // Compatibility code for 1.3 or older
|
if (node.isNumber()) // Compatibility code for 1.3 or older
|
||||||
{
|
{
|
||||||
VLC->identifiers()->requestIdentifier( "bonusSubtype", node, [&subtype](int32_t identifier)
|
logMod->warn("Bonus subtype must be string!");
|
||||||
{
|
subtype = BonusSubtypeID(node.Integer());
|
||||||
subtype = BonusSubtypeID(identifier);
|
return;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!node.isString())
|
if (!node.isString())
|
||||||
@ -547,7 +546,100 @@ static void loadBonusSubtype(TBonusSubtype & subtype, BonusType type, const Json
|
|||||||
|
|
||||||
static void loadBonusSourceInstance(TBonusSourceID & sourceInstance, BonusSource sourceType, const JsonNode & node)
|
static void loadBonusSourceInstance(TBonusSourceID & sourceInstance, BonusSource sourceType, const JsonNode & node)
|
||||||
{
|
{
|
||||||
|
if (node.isNull())
|
||||||
|
{
|
||||||
|
sourceInstance = TBonusSourceID();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.isNumber()) // Compatibility code for 1.3 or older
|
||||||
|
{
|
||||||
|
logMod->warn("Bonus source must be string!");
|
||||||
|
sourceInstance = TBonusSourceID(node.Integer());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!node.isString())
|
||||||
|
{
|
||||||
|
logMod->warn("Bonus source must be string!");
|
||||||
|
sourceInstance = TBonusSourceID();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (sourceType)
|
||||||
|
{
|
||||||
|
case BonusSource::ARTIFACT:
|
||||||
|
case BonusSource::ARTIFACT_INSTANCE:
|
||||||
|
{
|
||||||
|
VLC->identifiers()->requestIdentifier( "artifact", node, [&sourceInstance](int32_t identifier)
|
||||||
|
{
|
||||||
|
sourceInstance = ArtifactID(identifier);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BonusSource::OBJECT:
|
||||||
|
case BonusSource::HERO_BASE_SKILL:
|
||||||
assert(0); // TODO
|
assert(0); // TODO
|
||||||
|
sourceInstance = ObjectInstanceID();
|
||||||
|
break;
|
||||||
|
case BonusSource::CREATURE_ABILITY:
|
||||||
|
{
|
||||||
|
VLC->identifiers()->requestIdentifier( "creature", node, [&sourceInstance](int32_t identifier)
|
||||||
|
{
|
||||||
|
sourceInstance = CreatureID(identifier);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BonusSource::TERRAIN_OVERLAY:
|
||||||
|
{
|
||||||
|
VLC->identifiers()->requestIdentifier( "spell", node, [&sourceInstance](int32_t identifier)
|
||||||
|
{
|
||||||
|
sourceInstance = BattleField(identifier);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BonusSource::SPELL_EFFECT:
|
||||||
|
{
|
||||||
|
VLC->identifiers()->requestIdentifier( "spell", node, [&sourceInstance](int32_t identifier)
|
||||||
|
{
|
||||||
|
sourceInstance = SpellID(identifier);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BonusSource::TOWN_STRUCTURE:
|
||||||
|
assert(0); // TODO
|
||||||
|
sourceInstance = BuildingTypeUniqueID();
|
||||||
|
break;
|
||||||
|
case BonusSource::SECONDARY_SKILL:
|
||||||
|
{
|
||||||
|
VLC->identifiers()->requestIdentifier( "secondarySkill", node, [&sourceInstance](int32_t identifier)
|
||||||
|
{
|
||||||
|
sourceInstance = SecondarySkill(identifier);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BonusSource::HERO_SPECIAL:
|
||||||
|
{
|
||||||
|
VLC->identifiers()->requestIdentifier( "hero", node, [&sourceInstance](int32_t identifier)
|
||||||
|
{
|
||||||
|
sourceInstance = HeroTypeID(identifier);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BonusSource::CAMPAIGN_BONUS:
|
||||||
|
assert(0); // TODO
|
||||||
|
sourceInstance = CampaignScenarioID();
|
||||||
|
break;
|
||||||
|
case BonusSource::ARMY:
|
||||||
|
case BonusSource::STACK_EXPERIENCE:
|
||||||
|
case BonusSource::COMMANDER:
|
||||||
|
case BonusSource::GLOBAL:
|
||||||
|
case BonusSource::TERRAIN_NATIVE:
|
||||||
|
case BonusSource::OTHER:
|
||||||
|
default:
|
||||||
|
sourceInstance = TBonusSourceID();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Bonus> JsonUtils::parseBonus(const JsonVector & ability_vec)
|
std::shared_ptr<Bonus> JsonUtils::parseBonus(const JsonVector & ability_vec)
|
||||||
|
@ -186,7 +186,6 @@ class JsonNode;
|
|||||||
BONUS_SOURCE(HERO_SPECIAL)\
|
BONUS_SOURCE(HERO_SPECIAL)\
|
||||||
BONUS_SOURCE(ARMY)\
|
BONUS_SOURCE(ARMY)\
|
||||||
BONUS_SOURCE(CAMPAIGN_BONUS)\
|
BONUS_SOURCE(CAMPAIGN_BONUS)\
|
||||||
BONUS_SOURCE(SPECIAL_WEEK)\
|
|
||||||
BONUS_SOURCE(STACK_EXPERIENCE)\
|
BONUS_SOURCE(STACK_EXPERIENCE)\
|
||||||
BONUS_SOURCE(COMMANDER) /*TODO: consider using simply STACK_INSTANCE */\
|
BONUS_SOURCE(COMMANDER) /*TODO: consider using simply STACK_INSTANCE */\
|
||||||
BONUS_SOURCE(GLOBAL) /*used for base bonuses which all heroes or all stacks should have*/\
|
BONUS_SOURCE(GLOBAL) /*used for base bonuses which all heroes or all stacks should have*/\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user