mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-30 08:57:00 +02:00
vcmi: remove deprecated CStack::getCreature()
Function battle::Unit::unitType() does the same.
This commit is contained in:
parent
d99d1509f6
commit
bc1aad3b26
@ -158,10 +158,10 @@ ECreatureAnimType AttackAnimation::findValidGroup( const std::vector<ECreatureAn
|
||||
|
||||
const CCreature * AttackAnimation::getCreature() const
|
||||
{
|
||||
if (attackingStack->getCreature()->getId() == CreatureID::ARROW_TOWERS)
|
||||
if (attackingStack->unitType()->getId() == CreatureID::ARROW_TOWERS)
|
||||
return owner.siegeController->getTurretCreature();
|
||||
else
|
||||
return attackingStack->getCreature();
|
||||
return attackingStack->unitType();
|
||||
}
|
||||
|
||||
|
||||
@ -179,7 +179,7 @@ HittedAnimation::HittedAnimation(BattleInterface & owner, const CStack * stack)
|
||||
: StackActionAnimation(owner, stack)
|
||||
{
|
||||
setGroup(ECreatureAnimType::HITTED);
|
||||
setSound(battle_sound(stack->getCreature(), wince));
|
||||
setSound(battle_sound(stack->unitType(), wince));
|
||||
logAnim->debug("Created HittedAnimation for %s", stack->getName());
|
||||
}
|
||||
|
||||
@ -187,14 +187,14 @@ DefenceAnimation::DefenceAnimation(BattleInterface & owner, const CStack * stack
|
||||
: StackActionAnimation(owner, stack)
|
||||
{
|
||||
setGroup(ECreatureAnimType::DEFENCE);
|
||||
setSound(battle_sound(stack->getCreature(), defend));
|
||||
setSound(battle_sound(stack->unitType(), defend));
|
||||
logAnim->debug("Created DefenceAnimation for %s", stack->getName());
|
||||
}
|
||||
|
||||
DeathAnimation::DeathAnimation(BattleInterface & owner, const CStack * stack, bool ranged):
|
||||
StackActionAnimation(owner, stack)
|
||||
{
|
||||
setSound(battle_sound(stack->getCreature(), killed));
|
||||
setSound(battle_sound(stack->unitType(), killed));
|
||||
|
||||
if(ranged && myAnim->framesInGroup(ECreatureAnimType::DEATH_RANGED) > 0)
|
||||
setGroup(ECreatureAnimType::DEATH_RANGED);
|
||||
@ -356,13 +356,13 @@ bool MovementAnimation::init()
|
||||
|
||||
if (moveSoundHander == -1)
|
||||
{
|
||||
moveSoundHander = CCS->soundh->playSound(battle_sound(stack->getCreature(), move), -1);
|
||||
moveSoundHander = CCS->soundh->playSound(battle_sound(stack->unitType(), move), -1);
|
||||
}
|
||||
|
||||
Point begPosition = owner.stacksController->getStackPositionAtHex(prevHex, stack);
|
||||
Point endPosition = owner.stacksController->getStackPositionAtHex(nextHex, stack);
|
||||
|
||||
progressPerSecond = AnimationControls::getMovementDistance(stack->getCreature());
|
||||
progressPerSecond = AnimationControls::getMovementDistance(stack->unitType());
|
||||
|
||||
begX = begPosition.x;
|
||||
begY = begPosition.y;
|
||||
@ -373,7 +373,7 @@ bool MovementAnimation::init()
|
||||
if (stack->hasBonus(Selector::type()(Bonus::FLYING)))
|
||||
{
|
||||
float distance = static_cast<float>(sqrt(distanceX * distanceX + distanceY * distanceY));
|
||||
progressPerSecond = AnimationControls::getFlightDistance(stack->getCreature()) / distance;
|
||||
progressPerSecond = AnimationControls::getFlightDistance(stack->unitType()) / distance;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -453,7 +453,7 @@ bool MovementEndAnimation::init()
|
||||
logAnim->debug("CMovementEndAnimation::init: stack %s", stack->getName());
|
||||
myAnim->pos.moveTo(owner.stacksController->getStackPositionAtHex(nextHex, stack));
|
||||
|
||||
CCS->soundh->playSound(battle_sound(stack->getCreature(), endMoving));
|
||||
CCS->soundh->playSound(battle_sound(stack->unitType(), endMoving));
|
||||
|
||||
if(!myAnim->framesInGroup(ECreatureAnimType::MOVE_END))
|
||||
{
|
||||
@ -494,7 +494,7 @@ bool MovementStartAnimation::init()
|
||||
}
|
||||
|
||||
logAnim->debug("CMovementStartAnimation::init: stack %s", stack->getName());
|
||||
CCS->soundh->playSound(battle_sound(stack->getCreature(), startMoving));
|
||||
CCS->soundh->playSound(battle_sound(stack->unitType(), startMoving));
|
||||
|
||||
if(!myAnim->framesInGroup(ECreatureAnimType::MOVE_START))
|
||||
{
|
||||
|
@ -146,7 +146,7 @@ BattleProjectileController::BattleProjectileController(BattleInterface & owner):
|
||||
|
||||
const CCreature & BattleProjectileController::getShooter(const CStack * stack) const
|
||||
{
|
||||
const CCreature * creature = stack->getCreature();
|
||||
const CCreature * creature = stack->unitType();
|
||||
|
||||
if(creature->getId() == CreatureID::ARROW_TOWERS)
|
||||
creature = owner.siegeController->getTurretCreature();
|
||||
|
@ -49,7 +49,7 @@ static void onAnimationFinished(const CStack *stack, std::weak_ptr<CreatureAnima
|
||||
|
||||
if (animation->isIdle())
|
||||
{
|
||||
const CCreature *creature = stack->getCreature();
|
||||
const CCreature *creature = stack->unitType();
|
||||
|
||||
if (stack->isFrozen())
|
||||
animation->setType(ECreatureAnimType::FROZEN);
|
||||
@ -207,7 +207,7 @@ void BattleStacksController::stackAdded(const CStack * stack, bool instant)
|
||||
}
|
||||
else
|
||||
{
|
||||
stackAnimation[stack->ID] = AnimationControls::getAnimation(stack->getCreature());
|
||||
stackAnimation[stack->ID] = AnimationControls::getAnimation(stack->unitType());
|
||||
stackAnimation[stack->ID]->onAnimationReset += std::bind(&onAnimationFinished, stack, stackAnimation[stack->ID]);
|
||||
stackAnimation[stack->ID]->pos.h = stackAnimation[stack->ID]->getHeight();
|
||||
stackAnimation[stack->ID]->pos.w = stackAnimation[stack->ID]->getWidth();
|
||||
|
@ -56,11 +56,6 @@ CStack::CStack(const CStackBasicDescriptor * stack, const PlayerColor & O, int I
|
||||
health.init(); //???
|
||||
}
|
||||
|
||||
const CCreature * CStack::getCreature() const
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
void CStack::localInit(BattleInfo * battleInfo)
|
||||
{
|
||||
battle = battleInfo;
|
||||
@ -88,7 +83,7 @@ ui32 CStack::level() const
|
||||
if(base)
|
||||
return base->getLevel(); //creature or commander
|
||||
else
|
||||
return std::max(1, static_cast<int>(getCreature()->getLevel())); //war machine, clone etc
|
||||
return std::max(1, static_cast<int>(unitType()->getLevel())); //war machine, clone etc
|
||||
}
|
||||
|
||||
si32 CStack::magicResistance() const
|
||||
@ -347,7 +342,7 @@ bool CStack::unitHasAmmoCart(const battle::Unit * unit) const
|
||||
{
|
||||
for(const CStack * st : battle->stacks)
|
||||
{
|
||||
if(battle->battleMatchOwner(st, unit, true) && st->getCreature()->getId() == CreatureID::AMMO_CART)
|
||||
if(battle->battleMatchOwner(st, unit, true) && st->unitType()->getId() == CreatureID::AMMO_CART)
|
||||
{
|
||||
return st->alive();
|
||||
}
|
||||
|
@ -43,8 +43,6 @@ public:
|
||||
CStack();
|
||||
~CStack();
|
||||
|
||||
const CCreature * getCreature() const; //deprecated
|
||||
|
||||
std::string nodeName() const override;
|
||||
|
||||
void localInit(BattleInfo * battleInfo);
|
||||
|
@ -52,7 +52,7 @@ void BattleInfo::calculateCasualties(std::map<ui32,si32> * casualties) const
|
||||
const CStack * const st = elem;
|
||||
si32 killed = st->getKilled();
|
||||
if(killed > 0)
|
||||
casualties[st->side][st->getCreature()->getId()] += killed;
|
||||
casualties[st->side][st->unitType()->getId()] += killed;
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,7 +210,7 @@ BattleInfo * BattleInfo::setupBattle(const int3 & tile, TerrainId terrain, const
|
||||
if(town)
|
||||
{
|
||||
curB->town = town;
|
||||
curB->terrainType = (*VLC->townh)[town->subID]->nativeTerrain;
|
||||
curB->terrainType = town->getNativeTerrain();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -271,7 +271,7 @@ PossiblePlayerBattleAction CBattleInfoCallback::getCasterAction(const CSpell * s
|
||||
return PossiblePlayerBattleAction(spellSelMode, spell->id);
|
||||
}
|
||||
|
||||
std::set<BattleHex> CBattleInfoCallback::battleGetAttackedHexes(const CStack* attacker, BattleHex destinationTile, BattleHex attackerPos) const
|
||||
std::set<BattleHex> CBattleInfoCallback::battleGetAttackedHexes(const battle::Unit * attacker, BattleHex destinationTile, BattleHex attackerPos) const
|
||||
{
|
||||
std::set<BattleHex> attackedHexes;
|
||||
RETURN_IF_NOT_BATTLE(attackedHexes);
|
||||
@ -645,7 +645,7 @@ std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const battle
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool CBattleInfoCallback::battleCanAttack(const CStack * stack, const CStack * target, BattleHex dest) const
|
||||
bool CBattleInfoCallback::battleCanAttack(const battle::Unit * stack, const battle::Unit * target, BattleHex dest) const
|
||||
{
|
||||
RETURN_IF_NOT_BATTLE(false);
|
||||
|
||||
@ -658,7 +658,7 @@ bool CBattleInfoCallback::battleCanAttack(const CStack * stack, const CStack * t
|
||||
if(!battleMatchOwner(stack, target))
|
||||
return false;
|
||||
|
||||
auto id = stack->getCreature()->getId();
|
||||
auto id = stack->unitType()->getId();
|
||||
if (id == CreatureID::FIRST_AID_TENT || id == CreatureID::CATAPULT)
|
||||
return false;
|
||||
|
||||
|
@ -83,10 +83,10 @@ public:
|
||||
|
||||
int battleGetSurrenderCost(const PlayerColor & Player) const; //returns cost of surrendering battle, -1 if surrendering is not possible
|
||||
ReachabilityInfo::TDistances battleGetDistances(const battle::Unit * unit, BattleHex assumedPosition) const;
|
||||
std::set<BattleHex> battleGetAttackedHexes(const CStack* attacker, BattleHex destinationTile, BattleHex attackerPos = BattleHex::INVALID) const;
|
||||
std::set<BattleHex> battleGetAttackedHexes(const battle::Unit * attacker, BattleHex destinationTile, BattleHex attackerPos = BattleHex::INVALID) const;
|
||||
bool isEnemyUnitWithinSpecifiedRange(BattleHex attackerPosition, const battle::Unit * defenderUnit, unsigned int range) const;
|
||||
|
||||
bool battleCanAttack(const CStack * stack, const CStack * target, BattleHex dest) const; //determines if stack with given ID can attack target at the selected destination
|
||||
bool battleCanAttack(const battle::Unit * stack, const battle::Unit * target, BattleHex dest) const; //determines if stack with given ID can attack target at the selected destination
|
||||
bool battleCanShoot(const battle::Unit * attacker, BattleHex dest) const; //determines if stack with given ID shoot at the selected destination
|
||||
bool battleCanShoot(const battle::Unit * attacker) const; //determines if stack with given ID shoot in principle
|
||||
bool battleIsUnitBlocked(const battle::Unit * unit) const; //returns true if there is neighboring enemy stack
|
||||
|
@ -1208,11 +1208,11 @@ void CGameHandler::addGenericKilledLog(BattleLogMessage & blm, const CStack * de
|
||||
boost::format txt(formatString);
|
||||
if(killed > 1)
|
||||
{
|
||||
txt % killed % (multiple ? VLC->generaltexth->allTexts[43] : defender->getCreature()->getNamePluralTranslated()); // creatures perish
|
||||
txt % killed % (multiple ? VLC->generaltexth->allTexts[43] : defender->unitType()->getNamePluralTranslated()); // creatures perish
|
||||
}
|
||||
else //killed == 1
|
||||
{
|
||||
txt % (multiple ? VLC->generaltexth->allTexts[42] : defender->getCreature()->getNameSingularTranslated()); // creature perishes
|
||||
txt % (multiple ? VLC->generaltexth->allTexts[42] : defender->unitType()->getNameSingularTranslated()); // creature perishes
|
||||
}
|
||||
MetaString line;
|
||||
line << txt.str();
|
||||
@ -4478,10 +4478,10 @@ void CGameHandler::updateGateState()
|
||||
// - deals moat damage to attacker if bridge is closed (fortress only)
|
||||
|
||||
bool hasForceFieldOnBridge = !battleGetAllObstaclesOnPos(BattleHex(ESiegeHex::GATE_BRIDGE), true).empty();
|
||||
bool hasStackAtGateInner = gs->curB->battleGetStackByPos(BattleHex(ESiegeHex::GATE_INNER), false) != nullptr;
|
||||
bool hasStackAtGateOuter = gs->curB->battleGetStackByPos(BattleHex(ESiegeHex::GATE_OUTER), false) != nullptr;
|
||||
bool hasStackAtGateBridge = gs->curB->battleGetStackByPos(BattleHex(ESiegeHex::GATE_BRIDGE), false) != nullptr;
|
||||
bool hasWideMoat = vstd::contains_if(battleGetAllObstaclesOnPos(BattleHex(ESiegeHex::GATE_BRIDGE), false), [](const std::shared_ptr<const CObstacleInstance> & obst)
|
||||
bool hasStackAtGateInner = gs->curB->battleGetUnitByPos(BattleHex(ESiegeHex::GATE_INNER), false) != nullptr;
|
||||
bool hasStackAtGateOuter = gs->curB->battleGetUnitByPos(BattleHex(ESiegeHex::GATE_OUTER), false) != nullptr;
|
||||
bool hasStackAtGateBridge = gs->curB->battleGetUnitByPos(BattleHex(ESiegeHex::GATE_BRIDGE), false) != nullptr;
|
||||
bool hasWideMoat = vstd::contains_if(battleGetAllObstaclesOnPos(BattleHex(ESiegeHex::GATE_BRIDGE), false), [](const std::shared_ptr<const CObstacleInstance> & obst)
|
||||
{
|
||||
return obst->obstacleType == CObstacleInstance::MOAT;
|
||||
});
|
||||
@ -6031,8 +6031,8 @@ void CGameHandler::handleAfterAttackCasting(bool ranged, const CStack * attacker
|
||||
|
||||
int bonusAdditionalInfo = attacker->getBonus(Selector::type()(Bonus::TRANSMUTATION))->additionalInfo[0];
|
||||
|
||||
if(defender->getCreature()->getId() == bonusAdditionalInfo ||
|
||||
(bonusAdditionalInfo == CAddInfo::NONE && defender->getCreature()->getId() == attacker->getCreature()->getId()))
|
||||
if(defender->unitType()->getId() == bonusAdditionalInfo ||
|
||||
(bonusAdditionalInfo == CAddInfo::NONE && defender->unitType()->getId() == attacker->unitType()->getId()))
|
||||
return;
|
||||
|
||||
battle::UnitInfo resurrectInfo;
|
||||
@ -6421,7 +6421,7 @@ void CGameHandler::runBattle()
|
||||
auto accessibility = getAccesibility();
|
||||
CreatureID creatureData = CreatureID(summonInfo->subtype);
|
||||
std::vector<BattleHex> targetHexes;
|
||||
const bool targetIsBig = stack->getCreature()->isDoubleWide(); //target = creature to guard
|
||||
const bool targetIsBig = stack->unitType()->isDoubleWide(); //target = creature to guard
|
||||
const bool guardianIsBig = creatureData.toCreature()->isDoubleWide();
|
||||
|
||||
/*Chosen idea for two hex units was to cover all possible surrounding hexes of target unit with as small number of stacks as possible.
|
||||
@ -6606,7 +6606,7 @@ void CGameHandler::runBattle()
|
||||
}
|
||||
|
||||
const CGHeroInstance * curOwner = battleGetOwnerHero(next);
|
||||
const int stackCreatureId = next->getCreature()->getId();
|
||||
const int stackCreatureId = next->unitType()->getId();
|
||||
|
||||
if ((stackCreatureId == CreatureID::ARROW_TOWERS || stackCreatureId == CreatureID::BALLISTA)
|
||||
&& (!curOwner || getRandomGenerator().nextInt(99) >= curOwner->valOfBonuses(Bonus::MANUAL_CONTROL, stackCreatureId)))
|
||||
@ -6622,7 +6622,7 @@ void CGameHandler::runBattle()
|
||||
|
||||
for(auto & elem : gs->curB->stacks)
|
||||
{
|
||||
if(elem->getCreature()->getId() != CreatureID::CATAPULT
|
||||
if(elem->unitType()->getId() != CreatureID::CATAPULT
|
||||
&& elem->owner != next->owner
|
||||
&& elem->isValidTarget()
|
||||
&& gs->curB->battleCanShoot(next, elem->getPosition()))
|
||||
@ -6644,7 +6644,7 @@ void CGameHandler::runBattle()
|
||||
continue;
|
||||
}
|
||||
|
||||
if (next->getCreature()->getId() == CreatureID::CATAPULT)
|
||||
if (next->unitType()->getId() == CreatureID::CATAPULT)
|
||||
{
|
||||
const auto & attackableBattleHexes = curB.getAttackableBattleHexes();
|
||||
|
||||
@ -6666,7 +6666,7 @@ void CGameHandler::runBattle()
|
||||
}
|
||||
}
|
||||
|
||||
if (next->getCreature()->getId() == CreatureID::FIRST_AID_TENT)
|
||||
if (next->unitType()->getId() == CreatureID::FIRST_AID_TENT)
|
||||
{
|
||||
TStacks possibleStacks = battleGetStacksIf([=](const CStack * s)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user