1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Implement "emergency" projectile init attempt

This commit is contained in:
dydzio 2017-02-02 20:27:51 +01:00
parent c91bc25e70
commit 141e5ad032
3 changed files with 21 additions and 11 deletions

View File

@ -798,6 +798,9 @@ bool CShootingAnimation::init()
auto & angles = shooterInfo->animation.missleFrameAngles;
double pi = boost::math::constants::pi<double>();
if (owner->idToProjectile.count(spi.creID) == 0) //in some cases (known one: hero grants shooter bonus to unit) the shooter stack's projectile may not be properly initialized
owner->initStackProjectile(shooter);
// only frames below maxFrame are usable: anything higher is either no present or we don't know when it should be used
size_t maxFrame = std::min<size_t>(angles.size(), owner->idToProjectile.at(spi.creID)->ourImages.size());

View File

@ -985,20 +985,25 @@ void CBattleInterface::newStack(const CStack *stack)
//loading projectiles for units
if (stack->getCreature()->isShooting())
{
CDefHandler *&projectile = idToProjectile[stack->getCreature()->idNumber];
initStackProjectile(stack);
}
}
const CCreature *creature;//creature whose shots should be loaded
if (stack->getCreature()->idNumber == CreatureID::ARROW_TOWERS)
creature = CGI->creh->creatures[siegeH->town->town->clientInfo.siegeShooter];
else
creature = stack->getCreature();
void CBattleInterface::initStackProjectile(const CStack * stack)
{
CDefHandler *&projectile = idToProjectile[stack->getCreature()->idNumber];
projectile = CDefHandler::giveDef(creature->animation.projectileImageName);
const CCreature *creature;//creature whose shots should be loaded
if (stack->getCreature()->idNumber == CreatureID::ARROW_TOWERS)
creature = CGI->creh->creatures[siegeH->town->town->clientInfo.siegeShooter];
else
creature = stack->getCreature();
for (auto & elem : projectile->ourImages) //alpha transforming
{
CSDL_Ext::alphaTransform(elem.bitmap);
}
projectile = CDefHandler::giveDef(creature->animation.projectileImageName);
for (auto & elem : projectile->ourImages) //alpha transforming
{
CSDL_Ext::alphaTransform(elem.bitmap);
}
}

View File

@ -363,6 +363,8 @@ public:
void gateStateChanged(const EGateState state);
void initStackProjectile(const CStack *stack);
const CGHeroInstance *currentHero() const;
InfoAboutHero enemyHero() const;