1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00
This commit is contained in:
DjWarmonger 2011-11-08 08:54:32 +00:00
parent c448b61976
commit 9b24ec0e81
2 changed files with 10 additions and 23 deletions

View File

@ -416,23 +416,10 @@ bool BattleInfo::isStackBlocked(const CStack * stack) const
if(stack->hasBonusOfType(Bonus::SIEGE_WEAPON)) //siege weapons cannot be blocked
return false;
for(unsigned int i=0; i<stacks.size();i++)
BOOST_FOREACH(CStack * s, getAdjacentCreatures(stack))
{
if( !stacks[i]->alive()
|| stacks[i]->owner==stack->owner
)
continue; //we omit dead and allied stacks
if(stacks[i]->doubleWide())
{
if( THex::mutualPosition(stacks[i]->position, stack->position) >= 0
|| THex::mutualPosition(stacks[i]->position + (stacks[i]->attackerOwned ? -1 : 1), stack->position) >= 0)
return true;
}
else
{
if( THex::mutualPosition(stacks[i]->position, stack->position) >= 0 )
return true;
}
if (s->owner != stack->owner) //blocked by enemy stack
return true;
}
return false;
}
@ -926,14 +913,14 @@ std::set<THex> BattleInfo::getAttackedHexes(const CStack* attacker, THex destina
return attackedHexes;
}
std::set<CStack*> BattleInfo::getAdjacentCreatures (const CStack * stack)
std::set<CStack*> BattleInfo::getAdjacentCreatures (const CStack * stack) const
{
std::set<CStack*> stacks;
CStack * localStack;
BOOST_FOREACH (THex hex, stack->getSurroundingHexes())
{
localStack = getStackT(hex, true); //only alive?
localStack = const_cast<CStack*>(getStackT(hex, true)); //only alive?
if (localStack)
stacks.insert(localStack);
}
@ -2662,23 +2649,23 @@ std::vector<THex> CStack::getSurroundingHexes(THex attackerPos) const
const int WN = BFIELD_WIDTH;
if(attackerOwned)
{ //position is equal to front hex
THex::checkAndPush(hex - ( (hex/WN)%2 ? WN+2 : WN+1 ), hexes);
THex::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes);
THex::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes);
THex::checkAndPush(hex - ( (hex/WN)%2 ? WN-1 : WN-2 ), hexes);
THex::checkAndPush(hex - 2, hexes);
THex::checkAndPush(hex + 1, hexes);
THex::checkAndPush(hex - ( (hex/WN)%2 ? WN-2 : WN-1 ), hexes);
THex::checkAndPush(hex + ( (hex/WN)%2 ? WN-2 : WN-1 ), hexes);
THex::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes);
THex::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes);
}
else
{
THex::checkAndPush(hex - ( (hex/WN)%2 ? WN+2 : WN+1 ), hexes);
THex::checkAndPush(hex - ( (hex/WN)%2 ? WN+1 : WN ), hexes);
THex::checkAndPush(hex - ( (hex/WN)%2 ? WN : WN-1 ), hexes);
THex::checkAndPush(hex - ( (hex/WN)%2 ? WN-1 : WN-2 ), hexes);
THex::checkAndPush(hex + 2, hexes);
THex::checkAndPush(hex - 1, hexes);
THex::checkAndPush(hex - ( (hex/WN)%2 ? WN-1 : WN ), hexes);
THex::checkAndPush(hex + ( (hex/WN)%2 ? WN-1 : WN ), hexes);
THex::checkAndPush(hex + ( (hex/WN)%2 ? WN : WN+1 ), hexes);
THex::checkAndPush(hex + ( (hex/WN)%2 ? WN+1 : WN+2 ), hexes);
}

View File

@ -103,7 +103,7 @@ struct DLL_EXPORT BattleInfo : public CBonusSystemNode
void getPotentiallyAttackableHexes(AttackableTiles &at, const CStack* attacker, THex destinationTile, THex attackerPos); //hexes around target that could be attacked in melee
std::set<CStack*> getAttackedCreatures(const CStack* attacker, THex destinationTile, THex attackerPos = THex::INVALID); //calculates range of multi-hex attacks
std::set<THex> getAttackedHexes(const CStack* attacker, THex destinationTile, THex attackerPos = THex::INVALID); //calculates range of multi-hex attacks
std::set<CStack*> getAdjacentCreatures (const CStack * stack);
std::set<CStack*> getAdjacentCreatures (const CStack * stack) const;
static int calculateSpellDuration(const CSpell * spell, const CGHeroInstance * caster, int usedSpellPower);
CStack * generateNewStack(const CStackInstance &base, int stackID, bool attackerOwned, int slot, THex position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield
CStack * generateNewStack(const CStackBasicDescriptor &base, int stackID, bool attackerOwned, int slot, THex position) const; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield