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

* #152 finally fixed (I hope)

This commit is contained in:
mateuszb 2010-07-28 12:31:34 +00:00
parent 7e64441e1b
commit b15e8531b2
2 changed files with 34 additions and 5 deletions

View File

@ -785,6 +785,21 @@ bool CStack::doubleWide() const
return type->doubleWide;
}
int CStack::occupiedHex() const
{
if (doubleWide())
{
if (attackerOwned)
return position - 1;
else
return position + 1;
}
else
{
return -1;
}
}
CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, const CTown *town, std::map<ui32,CGHeroInstance *> &available, const CHeroClass *bannedClass /*= NULL*/) const
{
CGHeroInstance *ret = NULL;
@ -3617,12 +3632,25 @@ si8 BattleInfo::hasDistancePenalty( int stackID, int destHex )
{
const CStack * stack = getStack(stackID);
int xDst = std::abs(destHex % BFIELD_WIDTH - stack->position % BFIELD_WIDTH),
yDst = std::abs(destHex / BFIELD_WIDTH - stack->position / BFIELD_WIDTH);
int distance = std::max(xDst, yDst) + std::min(xDst, yDst) - (std::max(xDst, yDst) + 1)/2;
struct HLP
{
static bool lowerAnalyze(const CStack * stack, int hex)
{
int xDst = std::abs(hex % BFIELD_WIDTH - stack->position % BFIELD_WIDTH),
yDst = std::abs(hex / BFIELD_WIDTH - stack->position / BFIELD_WIDTH);
int distance = std::max(xDst, yDst) + std::min(xDst, yDst) - (yDst + 1)/2;
//I hope it's approximately correct
return distance > 10 && !stack->hasBonusOfType(Bonus::NO_DISTANCE_PENALTY);
//I hope it's approximately correct
return distance > 10 && !stack->hasBonusOfType(Bonus::NO_DISTANCE_PENALTY);
}
};
const CStack * dstStack = getStackT(destHex, false);
if (dstStack->doubleWide())
return HLP::lowerAnalyze(stack, destHex) && HLP::lowerAnalyze(stack, dstStack->occupiedHex());
else
return HLP::lowerAnalyze(stack, destHex);
}
si8 BattleInfo::sameSideOfWall(int pos1, int pos2)

View File

@ -262,6 +262,7 @@ public:
ui32 Speed(int turn = 0) const; //get speed of creature with all modificators
bool doubleWide() const;
int occupiedHex() const; //returns number of occupied hex (not the position) if stack is double wide; otherwise -1
template <typename Handler> void serialize(Handler &h, const int version)
{