mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Fixed initialization of heroes in taverns
This commit is contained in:
@@ -1390,18 +1390,7 @@ void HeroRecruited::applyGs(CGameState * gs) const
|
||||
|
||||
h->setOwner(player);
|
||||
h->pos = tile;
|
||||
bool fresh = !h->isInitialized();
|
||||
if(fresh)
|
||||
{ // this is a fresh hero who hasn't appeared yet
|
||||
if (boatId >= 0) //Hero spawns on water
|
||||
{
|
||||
h->setMovementPoints(h->movementPointsLimit(false));
|
||||
}
|
||||
else
|
||||
{
|
||||
h->setMovementPoints(h->movementPointsLimit(true));
|
||||
}
|
||||
}
|
||||
h->initObj(gs->getRandomGenerator());
|
||||
|
||||
if(h->id == ObjectInstanceID())
|
||||
{
|
||||
@@ -1414,16 +1403,10 @@ void HeroRecruited::applyGs(CGameState * gs) const
|
||||
gs->map->heroesOnMap.emplace_back(h);
|
||||
p->heroes.emplace_back(h);
|
||||
h->attachTo(*p);
|
||||
if(fresh)
|
||||
{
|
||||
h->initObj(gs->getRandomGenerator());
|
||||
}
|
||||
gs->map->addBlockVisTiles(h);
|
||||
|
||||
if(t)
|
||||
{
|
||||
t->setVisitingHero(h);
|
||||
}
|
||||
}
|
||||
|
||||
void GiveHero::applyGs(CGameState * gs) const
|
||||
@@ -2205,31 +2188,31 @@ void BattleResultAccepted::applyGs(CGameState * gs) const
|
||||
for(auto & res : heroResult)
|
||||
{
|
||||
if(res.hero)
|
||||
res.hero->removeBonusesRecursive(Bonus::OneBattle);
|
||||
}
|
||||
|
||||
if(winnerSide != 2)
|
||||
{
|
||||
// Grow up growing artifacts
|
||||
const auto hero = heroResult[winnerSide].hero;
|
||||
|
||||
if (hero)
|
||||
{
|
||||
if(hero->commander && hero->commander->alive)
|
||||
{
|
||||
for(auto & art : hero->commander->artifactsWorn)
|
||||
art.second.artifact->growingUp();
|
||||
}
|
||||
for(auto & art : hero->artifactsWorn)
|
||||
{
|
||||
art.second.artifact->growingUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(VLC->settings()->getBoolean(EGameSettings::MODULE_STACK_EXPERIENCE))
|
||||
{
|
||||
if(heroResult[0].army)
|
||||
res.hero->removeBonusesRecursive(Bonus::OneBattle);
|
||||
}
|
||||
|
||||
if(winnerSide != 2)
|
||||
{
|
||||
// Grow up growing artifacts
|
||||
const auto hero = heroResult[winnerSide].hero;
|
||||
|
||||
if (hero)
|
||||
{
|
||||
if(hero->commander && hero->commander->alive)
|
||||
{
|
||||
for(auto & art : hero->commander->artifactsWorn)
|
||||
art.second.artifact->growingUp();
|
||||
}
|
||||
for(auto & art : hero->artifactsWorn)
|
||||
{
|
||||
art.second.artifact->growingUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(VLC->settings()->getBoolean(EGameSettings::MODULE_STACK_EXPERIENCE))
|
||||
{
|
||||
if(heroResult[0].army)
|
||||
heroResult[0].army->giveStackExp(heroResult[0].exp);
|
||||
if(heroResult[1].army)
|
||||
heroResult[1].army->giveStackExp(heroResult[1].exp);
|
||||
|
@@ -255,6 +255,7 @@ CGHeroInstance::CGHeroInstance():
|
||||
setNodeType(HERO);
|
||||
ID = Obj::HERO;
|
||||
secSkills.emplace_back(SecondarySkill::DEFAULT, -1);
|
||||
blockVisit = true;
|
||||
}
|
||||
|
||||
PlayerColor CGHeroInstance::getOwner() const
|
||||
@@ -364,8 +365,19 @@ void CGHeroInstance::initHero(CRandomGenerator & rand)
|
||||
commander->giveStackExp (exp); //after our exp is set
|
||||
}
|
||||
|
||||
if (mana < 0)
|
||||
mana = manaLimit();
|
||||
skillsInfo.rand.setSeed(rand.nextInt());
|
||||
skillsInfo.resetMagicSchoolCounter();
|
||||
skillsInfo.resetWisdomCounter();
|
||||
|
||||
//copy active (probably growing) bonuses from hero prototype to hero object
|
||||
for(const std::shared_ptr<Bonus> & b : type->specialty)
|
||||
addNewBonus(b);
|
||||
|
||||
//initialize bonuses
|
||||
recreateSecondarySkillsBonuses();
|
||||
|
||||
movement = movementPointsLimit(true);
|
||||
mana = manaLimit(); //after all bonuses are taken into account, make sure this line is the last one
|
||||
}
|
||||
|
||||
void CGHeroInstance::initArmy(CRandomGenerator & rand, IArmyDescriptor * dst)
|
||||
@@ -533,15 +545,9 @@ void CGHeroInstance::SecondarySkillsInfo::resetWisdomCounter()
|
||||
|
||||
void CGHeroInstance::initObj(CRandomGenerator & rand)
|
||||
{
|
||||
blockVisit = true;
|
||||
|
||||
if(!type)
|
||||
initHero(rand); //TODO: set up everything for prison before specialties are configured
|
||||
|
||||
skillsInfo.rand.setSeed(rand.nextInt());
|
||||
skillsInfo.resetMagicSchoolCounter();
|
||||
skillsInfo.resetWisdomCounter();
|
||||
|
||||
if (ID != Obj::PRISON)
|
||||
{
|
||||
auto terrain = cb->gameState()->getTile(visitablePos())->terType->getId();
|
||||
@@ -549,15 +555,6 @@ void CGHeroInstance::initObj(CRandomGenerator & rand)
|
||||
if (customApp)
|
||||
appearance = customApp;
|
||||
}
|
||||
|
||||
//copy active (probably growing) bonuses from hero prototype to hero object
|
||||
for(const std::shared_ptr<Bonus> & b : type->specialty)
|
||||
addNewBonus(b);
|
||||
|
||||
//initialize bonuses
|
||||
recreateSecondarySkillsBonuses();
|
||||
|
||||
mana = manaLimit(); //after all bonuses are taken into account, make sure this line is the last one
|
||||
}
|
||||
|
||||
void CGHeroInstance::recreateSecondarySkillsBonuses()
|
||||
|
Reference in New Issue
Block a user