mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
formatting
This commit is contained in:
parent
7bf8c9bd69
commit
00bd1bd100
109
lib/CStack.cpp
109
lib/CStack.cpp
@ -125,9 +125,9 @@ CHealth::CHealth(const CHealth & other):
|
|||||||
|
|
||||||
void CHealth::init(const int32_t baseAmount)
|
void CHealth::init(const int32_t baseAmount)
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
fullUnits = baseAmount > 1 ? baseAmount - 1 : 0;
|
fullUnits = baseAmount > 1 ? baseAmount - 1 : 0;
|
||||||
firstHPleft = baseAmount > 0 ? owner->MaxHealth() : 0;
|
firstHPleft = baseAmount > 0 ? owner->MaxHealth() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHealth::addResurrected(int32_t amount)
|
void CHealth::addResurrected(int32_t amount)
|
||||||
@ -194,7 +194,7 @@ void CHealth::heal(int32_t & amount, EHealLevel level, EHealPower power)
|
|||||||
switch(level)
|
switch(level)
|
||||||
{
|
{
|
||||||
case EHealLevel::HEAL:
|
case EHealLevel::HEAL:
|
||||||
maxHeal = std::max(0, unitHealth-firstHPleft);
|
maxHeal = std::max(0, unitHealth - firstHPleft);
|
||||||
break;
|
break;
|
||||||
case EHealLevel::RESURRECT:
|
case EHealLevel::RESURRECT:
|
||||||
maxHeal = total() - available();
|
maxHeal = total() - available();
|
||||||
@ -282,8 +282,8 @@ void CHealth::takeResurrected()
|
|||||||
}
|
}
|
||||||
|
|
||||||
///CStack
|
///CStack
|
||||||
CStack::CStack(const CStackInstance * Base, PlayerColor O, int I, ui8 Side, SlotID S)
|
CStack::CStack(const CStackInstance * Base, PlayerColor O, int I, ui8 Side, SlotID S):
|
||||||
: base(Base), ID(I), owner(O), slot(S), side(Side),
|
base(Base), ID(I), owner(O), slot(S), side(Side),
|
||||||
counterAttacks(this), shots(this), casts(this), health(this), cloneID(-1),
|
counterAttacks(this), shots(this), casts(this), health(this), cloneID(-1),
|
||||||
position()
|
position()
|
||||||
{
|
{
|
||||||
@ -301,8 +301,8 @@ CStack::CStack():
|
|||||||
setNodeType(STACK_BATTLE);
|
setNodeType(STACK_BATTLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
CStack::CStack(const CStackBasicDescriptor * stack, PlayerColor O, int I, ui8 Side, SlotID S)
|
CStack::CStack(const CStackBasicDescriptor * stack, PlayerColor O, int I, ui8 Side, SlotID S):
|
||||||
: base(nullptr), ID(I), owner(O), slot(S), side(Side),
|
base(nullptr), ID(I), owner(O), slot(S), side(Side),
|
||||||
counterAttacks(this), shots(this), casts(this), health(this), cloneID(-1),
|
counterAttacks(this), shots(this), casts(this), health(this), cloneID(-1),
|
||||||
position()
|
position()
|
||||||
{
|
{
|
||||||
@ -373,7 +373,7 @@ void CStack::localInit(BattleInfo * battleInfo)
|
|||||||
|
|
||||||
ui32 CStack::level() const
|
ui32 CStack::level() const
|
||||||
{
|
{
|
||||||
if (base)
|
if(base)
|
||||||
return base->getLevel(); //creatture or commander
|
return base->getLevel(); //creatture or commander
|
||||||
else
|
else
|
||||||
return std::max(1, (int)getCreature()->level); //war machine, clone etc
|
return std::max(1, (int)getCreature()->level); //war machine, clone etc
|
||||||
@ -382,19 +382,19 @@ ui32 CStack::level() const
|
|||||||
si32 CStack::magicResistance() const
|
si32 CStack::magicResistance() const
|
||||||
{
|
{
|
||||||
si32 magicResistance;
|
si32 magicResistance;
|
||||||
if (base) //TODO: make war machines receive aura of magic resistance
|
if(base) //TODO: make war machines receive aura of magic resistance
|
||||||
{
|
{
|
||||||
magicResistance = base->magicResistance();
|
magicResistance = base->magicResistance();
|
||||||
int auraBonus = 0;
|
int auraBonus = 0;
|
||||||
for (const CStack * stack : base->armyObj->battle-> batteAdjacentCreatures(this))
|
for(const CStack * stack : base->armyObj->battle-> batteAdjacentCreatures(this))
|
||||||
{
|
|
||||||
if (stack->owner == owner)
|
|
||||||
{
|
{
|
||||||
vstd::amax(auraBonus, stack->valOfBonuses(Bonus::SPELL_RESISTANCE_AURA)); //max value
|
if(stack->owner == owner)
|
||||||
|
{
|
||||||
|
vstd::amax(auraBonus, stack->valOfBonuses(Bonus::SPELL_RESISTANCE_AURA)); //max value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
magicResistance += auraBonus;
|
magicResistance += auraBonus;
|
||||||
vstd::amin (magicResistance, 100);
|
vstd::amin(magicResistance, 100);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
magicResistance = type->magicResistance();
|
magicResistance = type->magicResistance();
|
||||||
@ -403,15 +403,15 @@ si32 CStack::magicResistance() const
|
|||||||
|
|
||||||
bool CStack::willMove(int turn /*= 0*/) const
|
bool CStack::willMove(int turn /*= 0*/) const
|
||||||
{
|
{
|
||||||
return ( turn ? true : !vstd::contains(state, EBattleStackState::DEFENDING) )
|
return (turn ? true : !vstd::contains(state, EBattleStackState::DEFENDING))
|
||||||
&& !moved(turn)
|
&& !moved(turn)
|
||||||
&& canMove(turn);
|
&& canMove(turn);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CStack::canMove( int turn /*= 0*/ ) const
|
bool CStack::canMove(int turn /*= 0*/) const
|
||||||
{
|
{
|
||||||
return alive()
|
return alive()
|
||||||
&& !hasBonus(Selector::type(Bonus::NOT_ACTIVE).And(Selector::turns(turn))); //eg. Ammo Cart or blinded creature
|
&& !hasBonus(Selector::type(Bonus::NOT_ACTIVE).And(Selector::turns(turn))); //eg. Ammo Cart or blinded creature
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CStack::canCast() const
|
bool CStack::canCast() const
|
||||||
@ -434,7 +434,7 @@ bool CStack::isShooter() const
|
|||||||
return shots.total() > 0 && hasBonusOfType(Bonus::SHOOTER);
|
return shots.total() > 0 && hasBonusOfType(Bonus::SHOOTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CStack::moved( int turn /*= 0*/ ) const
|
bool CStack::moved(int turn /*= 0*/) const
|
||||||
{
|
{
|
||||||
if(!turn)
|
if(!turn)
|
||||||
return vstd::contains(state, EBattleStackState::MOVED);
|
return vstd::contains(state, EBattleStackState::MOVED);
|
||||||
@ -514,26 +514,27 @@ std::vector<BattleHex> CStack::getSurroundingHexes(BattleHex attackerPos) const
|
|||||||
{
|
{
|
||||||
const int WN = GameConstants::BFIELD_WIDTH;
|
const int WN = GameConstants::BFIELD_WIDTH;
|
||||||
if(side == BattleSide::ATTACKER)
|
if(side == BattleSide::ATTACKER)
|
||||||
{ //position is equal to front hex
|
{
|
||||||
BattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN+2 : WN+1 ), hexes);
|
//position is equal to front hex
|
||||||
BattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes);
|
BattleHex::checkAndPush(hex - ((hex / WN) % 2 ? WN + 2 : WN + 1), hexes);
|
||||||
BattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes);
|
BattleHex::checkAndPush(hex - ((hex / WN) % 2 ? WN + 1 : WN), hexes);
|
||||||
|
BattleHex::checkAndPush(hex - ((hex / WN) % 2 ? WN : WN - 1), hexes);
|
||||||
BattleHex::checkAndPush(hex - 2, hexes);
|
BattleHex::checkAndPush(hex - 2, hexes);
|
||||||
BattleHex::checkAndPush(hex + 1, hexes);
|
BattleHex::checkAndPush(hex + 1, hexes);
|
||||||
BattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN-2 : WN-1 ), hexes);
|
BattleHex::checkAndPush(hex + ((hex / WN) % 2 ? WN - 2 : WN - 1), hexes);
|
||||||
BattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes);
|
BattleHex::checkAndPush(hex + ((hex / WN) % 2 ? WN - 1 : WN), hexes);
|
||||||
BattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes);
|
BattleHex::checkAndPush(hex + ((hex / WN) % 2 ? WN : WN + 1), hexes);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes);
|
BattleHex::checkAndPush(hex - ((hex / WN) % 2 ? WN + 1 : WN), hexes);
|
||||||
BattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes);
|
BattleHex::checkAndPush(hex - ((hex / WN) % 2 ? WN : WN - 1), hexes);
|
||||||
BattleHex::checkAndPush(hex - ( (hex/WN)%2 ? WN-1 : WN-2 ), hexes);
|
BattleHex::checkAndPush(hex - ((hex / WN) % 2 ? WN - 1 : WN - 2), hexes);
|
||||||
BattleHex::checkAndPush(hex + 2, hexes);
|
BattleHex::checkAndPush(hex + 2, hexes);
|
||||||
BattleHex::checkAndPush(hex - 1, hexes);
|
BattleHex::checkAndPush(hex - 1, hexes);
|
||||||
BattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes);
|
BattleHex::checkAndPush(hex + ((hex / WN) % 2 ? WN - 1 : WN), hexes);
|
||||||
BattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes);
|
BattleHex::checkAndPush(hex + ((hex / WN) % 2 ? WN : WN + 1), hexes);
|
||||||
BattleHex::checkAndPush(hex + ( (hex/WN)%2 ? WN+1 : WN+2 ), hexes);
|
BattleHex::checkAndPush(hex + ((hex / WN) % 2 ? WN + 1 : WN + 2), hexes);
|
||||||
}
|
}
|
||||||
return hexes;
|
return hexes;
|
||||||
}
|
}
|
||||||
@ -565,15 +566,15 @@ std::vector<si32> CStack::activeSpells() const
|
|||||||
std::stringstream cachingStr;
|
std::stringstream cachingStr;
|
||||||
cachingStr << "!type_" << Bonus::NONE << "source_" << Bonus::SPELL_EFFECT;
|
cachingStr << "!type_" << Bonus::NONE << "source_" << Bonus::SPELL_EFFECT;
|
||||||
CSelector selector = Selector::sourceType(Bonus::SPELL_EFFECT)
|
CSelector selector = Selector::sourceType(Bonus::SPELL_EFFECT)
|
||||||
.And(CSelector([](const Bonus *b)->bool
|
.And(CSelector([](const Bonus * b)->bool
|
||||||
{
|
{
|
||||||
return b->type != Bonus::NONE;
|
return b->type != Bonus::NONE;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
TBonusListPtr spellEffects = getBonuses(selector, Selector::all, cachingStr.str());
|
TBonusListPtr spellEffects = getBonuses(selector, Selector::all, cachingStr.str());
|
||||||
for(const std::shared_ptr<Bonus> it : *spellEffects)
|
for(const std::shared_ptr<Bonus> it : *spellEffects)
|
||||||
{
|
{
|
||||||
if (!vstd::contains(ret, it->sid)) //do not duplicate spells with multiple effects
|
if(!vstd::contains(ret, it->sid)) //do not duplicate spells with multiple effects
|
||||||
ret.push_back(it->sid);
|
ret.push_back(it->sid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -590,7 +591,7 @@ const CGHeroInstance * CStack::getMyHero() const
|
|||||||
if(base)
|
if(base)
|
||||||
return dynamic_cast<const CGHeroInstance *>(base->armyObj);
|
return dynamic_cast<const CGHeroInstance *>(base->armyObj);
|
||||||
else //we are attached directly?
|
else //we are attached directly?
|
||||||
for(const CBonusSystemNode *n : getParentNodes())
|
for(const CBonusSystemNode * n : getParentNodes())
|
||||||
if(n->getNodeType() == HERO)
|
if(n->getNodeType() == HERO)
|
||||||
return dynamic_cast<const CGHeroInstance *>(n);
|
return dynamic_cast<const CGHeroInstance *>(n);
|
||||||
|
|
||||||
@ -701,23 +702,23 @@ bool CStack::isMeleeAttackPossible(const CStack * attacker, const CStack * defen
|
|||||||
defenderPos = defender->position;
|
defenderPos = defender->position;
|
||||||
|
|
||||||
return
|
return
|
||||||
(BattleHex::mutualPosition(attackerPos, defenderPos) >= 0) //front <=> front
|
(BattleHex::mutualPosition(attackerPos, defenderPos) >= 0)//front <=> front
|
||||||
|| (attacker->doubleWide() //back <=> front
|
|| (attacker->doubleWide()//back <=> front
|
||||||
&& BattleHex::mutualPosition(attackerPos + (attacker->side == BattleSide::ATTACKER ? -1 : 1), defenderPos) >= 0)
|
&& BattleHex::mutualPosition(attackerPos + (attacker->side == BattleSide::ATTACKER ? -1 : 1), defenderPos) >= 0)
|
||||||
|| (defender->doubleWide() //front <=> back
|
|| (defender->doubleWide()//front <=> back
|
||||||
&& BattleHex::mutualPosition(attackerPos, defenderPos + (defender->side == BattleSide::ATTACKER ? -1 : 1)) >= 0)
|
&& BattleHex::mutualPosition(attackerPos, defenderPos + (defender->side == BattleSide::ATTACKER ? -1 : 1)) >= 0)
|
||||||
|| (defender->doubleWide() && attacker->doubleWide()//back <=> back
|
|| (defender->doubleWide() && attacker->doubleWide()//back <=> back
|
||||||
&& BattleHex::mutualPosition(attackerPos + (attacker->side == BattleSide::ATTACKER ? -1 : 1), defenderPos + (defender->side == BattleSide::ATTACKER ? -1 : 1)) >= 0);
|
&& BattleHex::mutualPosition(attackerPos + (attacker->side == BattleSide::ATTACKER ? -1 : 1), defenderPos + (defender->side == BattleSide::ATTACKER ? -1 : 1)) >= 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CStack::ableToRetaliate() const
|
bool CStack::ableToRetaliate() const
|
||||||
{
|
{
|
||||||
return alive()
|
return alive()
|
||||||
&& (counterAttacks.canUse() || hasBonusOfType(Bonus::UNLIMITED_RETALIATIONS))
|
&& (counterAttacks.canUse() || hasBonusOfType(Bonus::UNLIMITED_RETALIATIONS))
|
||||||
&& !hasBonusOfType(Bonus::SIEGE_WEAPON)
|
&& !hasBonusOfType(Bonus::SIEGE_WEAPON)
|
||||||
&& !hasBonusOfType(Bonus::HYPNOTIZED)
|
&& !hasBonusOfType(Bonus::HYPNOTIZED)
|
||||||
&& !hasBonusOfType(Bonus::NO_RETALIATION);
|
&& !hasBonusOfType(Bonus::NO_RETALIATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CStack::getName() const
|
std::string CStack::getName() const
|
||||||
@ -753,8 +754,8 @@ bool CStack::isTurret() const
|
|||||||
bool CStack::canBeHealed() const
|
bool CStack::canBeHealed() const
|
||||||
{
|
{
|
||||||
return getFirstHPleft() < MaxHealth()
|
return getFirstHPleft() < MaxHealth()
|
||||||
&& isValidTarget()
|
&& isValidTarget()
|
||||||
&& !hasBonusOfType(Bonus::SIEGE_WEAPON);
|
&& !hasBonusOfType(Bonus::SIEGE_WEAPON);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CStack::makeGhost()
|
void CStack::makeGhost()
|
||||||
@ -815,7 +816,7 @@ void CStack::getCasterName(MetaString & text) const
|
|||||||
addNameReplacement(text, true);
|
addNameReplacement(text, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CStack::getCastDescription(const CSpell * spell, const std::vector<const CStack*> & attacked, MetaString & text) const
|
void CStack::getCastDescription(const CSpell * spell, const std::vector<const CStack *> & attacked, MetaString & text) const
|
||||||
{
|
{
|
||||||
text.addTxt(MetaString::GENERAL_TXT, 565);//The %s casts %s
|
text.addTxt(MetaString::GENERAL_TXT, 565);//The %s casts %s
|
||||||
//todo: use text 566 for single creature
|
//todo: use text 566 for single creature
|
||||||
|
10
lib/CStack.h
10
lib/CStack.h
@ -237,12 +237,12 @@ public:
|
|||||||
template <typename Handler> void serialize(Handler & h, const int version)
|
template <typename Handler> void serialize(Handler & h, const int version)
|
||||||
{
|
{
|
||||||
assert(isIndependentNode());
|
assert(isIndependentNode());
|
||||||
h & static_cast<CBonusSystemNode&>(*this);
|
h & static_cast<CBonusSystemNode &>(*this);
|
||||||
h & type;
|
h & type;
|
||||||
h & ID & baseAmount & owner & slot & side & position & state
|
h & ID & baseAmount & owner & slot & side & position & state;
|
||||||
& shots & casts & counterAttacks & health;
|
h & shots & casts & counterAttacks & health;
|
||||||
|
|
||||||
const CArmedInstance *army = (base ? base->armyObj : nullptr);
|
const CArmedInstance * army = (base ? base->armyObj : nullptr);
|
||||||
SlotID extSlot = (base ? base->armyObj->findStack(base) : SlotID());
|
SlotID extSlot = (base ? base->armyObj->findStack(base) : SlotID());
|
||||||
|
|
||||||
if(h.saving)
|
if(h.saving)
|
||||||
@ -255,7 +255,7 @@ public:
|
|||||||
if(extSlot == SlotID::COMMANDER_SLOT_PLACEHOLDER)
|
if(extSlot == SlotID::COMMANDER_SLOT_PLACEHOLDER)
|
||||||
{
|
{
|
||||||
auto hero = dynamic_cast<const CGHeroInstance *>(army);
|
auto hero = dynamic_cast<const CGHeroInstance *>(army);
|
||||||
assert (hero);
|
assert(hero);
|
||||||
base = hero->commander;
|
base = hero->commander;
|
||||||
}
|
}
|
||||||
else if(slot == SlotID::SUMMONED_SLOT_PLACEHOLDER || slot == SlotID::ARROW_TOWERS_SLOT || slot == SlotID::WAR_MACHINES_SLOT)
|
else if(slot == SlotID::SUMMONED_SLOT_PLACEHOLDER || slot == SlotID::ARROW_TOWERS_SLOT || slot == SlotID::WAR_MACHINES_SLOT)
|
||||||
|
Loading…
Reference in New Issue
Block a user