1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

- Fix for hero specialties (creature type limiters)

- Improved handling of new heroes / arts, check forum for fresh mod packages :)
This commit is contained in:
DjWarmonger 2013-01-20 16:31:18 +00:00
parent 1cab54b87a
commit fff7909958
5 changed files with 22 additions and 16 deletions

View File

@ -752,7 +752,7 @@ std::vector<ui32> BattleInfo::calculateResistedStacks(const CSpell * sp, const C
if( (*it)->hasBonusOfType(Bonus::SPELL_IMMUNITY, sp->id) //100% sure spell immunity if( (*it)->hasBonusOfType(Bonus::SPELL_IMMUNITY, sp->id) //100% sure spell immunity
|| ( (*it)->count - 1 ) * (*it)->MaxHealth() + (*it)->firstHPleft || ( (*it)->count - 1 ) * (*it)->MaxHealth() + (*it)->firstHPleft
> >
usedSpellPower * 25 + sp->powers[spellLevel] usedSpellPower * 25 + sp->powers[spellLevel] //TODO: allow 'damage' bonus for hypnotize
) )
{ {
ret.push_back((*it)->ID); ret.push_back((*it)->ID);

View File

@ -383,12 +383,11 @@ void CArtHandler::load(const JsonNode & node)
if (!entry.second.isNull()) // may happens if mod removed creature by setting json entry to null if (!entry.second.isNull()) // may happens if mod removed creature by setting json entry to null
{ {
CArtifact * art = loadArtifact(entry.second); CArtifact * art = loadArtifact(entry.second);
art->setName (entry.first);
art->id = artifacts.size(); art->id = artifacts.size();
artifacts.push_back(art); artifacts.push_back(art);
tlog5 << "Added artifact: " << entry.first << "\n"; tlog5 << "Added artifact: " << entry.first << "\n";
VLC->modh->identifiers.registerObject (std::string("artifact.") + art->Name(), art->id); VLC->modh->identifiers.registerObject (std::string("artifact.") + entry.first, art->id);
} }
} }
} }

View File

@ -925,6 +925,8 @@ void CGHeroInstance::initObj() //TODO: use bonus system
{ {
blockVisit = true; blockVisit = true;
HeroSpecial * hs = new HeroSpecial(); HeroSpecial * hs = new HeroSpecial();
hs->setNodeType(CBonusSystemNode::specialty);
attachTo(hs); //do we ever need to detach it?
if(!type) if(!type)
return; //TODO: support prison return; //TODO: support prison
@ -956,7 +958,7 @@ void CGHeroInstance::initObj() //TODO: use bonus system
} }
} }
bonus->additionalInfo = spec.additionalinfo; //creature id //bonus->additionalInfo = spec.additionalinfo; //creature id, should not be used again - this works only with limiter
bonus->limiter.reset(new CCreatureTypeLimiter (specCreature, true)); //with upgrades bonus->limiter.reset(new CCreatureTypeLimiter (specCreature, true)); //with upgrades
bonus->type = Bonus::PRIMARY_SKILL; bonus->type = Bonus::PRIMARY_SKILL;
bonus->valType = Bonus::ADDITIVE_VALUE; bonus->valType = Bonus::ADDITIVE_VALUE;
@ -1102,13 +1104,13 @@ void CGHeroInstance::initObj() //TODO: use bonus system
tlog2 << "Unexpected hero specialty " << type <<'\n'; tlog2 << "Unexpected hero specialty " << type <<'\n';
} }
} }
hs->setNodeType(CBonusSystemNode::specialty);
attachTo(hs); //do we ever need to detach it?
specialty.push_back(hs); //will it work? specialty.push_back(hs); //will it work?
BOOST_FOREACH (auto hs2, type->specialty) //copy active (probably growing) bonuses from hero prootype to hero object BOOST_FOREACH (auto hs2, type->specialty) //copy active (probably growing) bonuses from hero prootype to hero object
{ {
HeroSpecial * hs = new HeroSpecial(); HeroSpecial * hs = new HeroSpecial();
attachTo(hs); //do we ever need to detach it?
hs->setNodeType(CBonusSystemNode::specialty); hs->setNodeType(CBonusSystemNode::specialty);
BOOST_FOREACH (auto bonus, hs2.bonuses) BOOST_FOREACH (auto bonus, hs2.bonuses)
{ {
@ -1116,7 +1118,6 @@ void CGHeroInstance::initObj() //TODO: use bonus system
} }
hs->growsWithLevel = hs2.growsWithLevel; hs->growsWithLevel = hs2.growsWithLevel;
attachTo(hs); //do we ever need to detach it?
specialty.push_back(hs); //will it work? specialty.push_back(hs); //will it work?
} }
@ -1145,16 +1146,18 @@ void CGHeroInstance::Updatespecialty() //TODO: calculate special value of bonuse
break; //use only hero skills as bonuses to avoid feedback loop break; //use only hero skills as bonuses to avoid feedback loop
case Bonus::PRIMARY_SKILL: //for creatures, that is case Bonus::PRIMARY_SKILL: //for creatures, that is
{ {
const CCreature * cre = NULL;
int creLevel = 0; int creLevel = 0;
if (auto creatureLimiter = std::dynamic_pointer_cast<CCreatureTypeLimiter>(b->limiter)) //TODO: more general eveluation of bonuses? if (auto creatureLimiter = std::dynamic_pointer_cast<CCreatureTypeLimiter>(b->limiter)) //TODO: more general eveluation of bonuses?
{ {
creLevel = creatureLimiter->creature->level; cre = creatureLimiter->creature;
if(!creLevel) creLevel = cre->level;
if (!creLevel)
{ {
creLevel = 5; //treat ballista as tier 5 creLevel = 5; //treat ballista as tier 5
} }
} }
else else //no creature found, can't calculate value
{ {
tlog2 << "Primary skill specialty growth supported only with creature type limiters\n"; tlog2 << "Primary skill specialty growth supported only with creature type limiters\n";
break; break;
@ -1165,13 +1168,13 @@ void CGHeroInstance::Updatespecialty() //TODO: calculate special value of bonuse
switch (b->subtype) switch (b->subtype)
{ {
case PrimarySkill::ATTACK: case PrimarySkill::ATTACK:
param = creatures[b->additionalInfo]->Attack(); param = cre->Attack();
break; break;
case PrimarySkill::DEFENSE: case PrimarySkill::DEFENSE:
param = creatures[b->additionalInfo]->Defense(); param = cre->Defense();
break; break;
default: default:
param = 0; continue;
} }
b->val = ceil(param * (1 + primSkillModifier)) - param; //yep, overcomplicated but matches original b->val = ceil(param * (1 + primSkillModifier)) - param; //yep, overcomplicated but matches original
break; break;
@ -1514,6 +1517,11 @@ bool CGHeroInstance::hasSpellbook() const
void CGHeroInstance::deserializationFix() void CGHeroInstance::deserializationFix()
{ {
artDeserializationFix(this); artDeserializationFix(this);
//BOOST_FOREACH (auto hs, specialty)
//{
// attachTo (hs);
//}
} }
CBonusSystemNode * CGHeroInstance::whereShouldBeAttached(CGameState *gs) CBonusSystemNode * CGHeroInstance::whereShouldBeAttached(CGameState *gs)

View File

@ -292,6 +292,7 @@ struct DLL_LINKAGE Bonus
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & duration & type & subtype & source & val & sid & description & additionalInfo & turnsRemain & valType & effectRange & limiter & propagator; h & duration & type & subtype & source & val & sid & description & additionalInfo & turnsRemain & valType & effectRange & limiter & propagator;
h & calculator;
} }
static bool compareByAdditionalInfo(const Bonus *a, const Bonus *b) static bool compareByAdditionalInfo(const Bonus *a, const Bonus *b)

View File

@ -991,9 +991,7 @@ Bonus * JsonUtils::parseBonus (const JsonNode &ability)
if (!value->isNull()) if (!value->isNull())
b->valType = parseByMap(bonusValueMap, value, "value type "); b->valType = parseByMap(bonusValueMap, value, "value type ");
value = &ability["additionalInfo"]; resolveIdentifier (b->additionalInfo, ability, "addInfo");
if (!value->isNull())
b->additionalInfo = value->Float();
value = &ability["turns"]; value = &ability["turns"];
if (!value->isNull()) if (!value->isNull())