mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
* fixed #53
This commit is contained in:
parent
236345e61d
commit
1dd05788c9
@ -519,7 +519,7 @@ BattleAction CBattleLogic::MakeAttack(int attackerID, int destinationID)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<THex> fields = m_cb->battleGetAvailableHexes(m_cb->battleGetStackByID(attackerID), false);
|
std::vector<THex> fields = m_cb->battleGetAvailableHexes(m_cb->battleGetStackByID(attackerID), false, false);
|
||||||
|
|
||||||
if(fields.size() == 0)
|
if(fields.size() == 0)
|
||||||
{
|
{
|
||||||
|
@ -101,7 +101,7 @@ BattleAction CStupidAI::activeStack( const CStack * stack )
|
|||||||
{
|
{
|
||||||
//boost::this_thread::sleep(boost::posix_time::seconds(2));
|
//boost::this_thread::sleep(boost::posix_time::seconds(2));
|
||||||
print("activeStack called");
|
print("activeStack called");
|
||||||
std::vector<THex> avHexes = cb->battleGetAvailableHexes(stack, false);
|
std::vector<THex> avHexes = cb->battleGetAvailableHexes(stack, false, false);
|
||||||
std::vector<int> dists = cb->battleGetDistances(stack);
|
std::vector<int> dists = cb->battleGetDistances(stack);
|
||||||
std::vector<EnemyInfo> enemiesShootable, enemiesReachable, enemiesUnreachable;
|
std::vector<EnemyInfo> enemiesShootable, enemiesReachable, enemiesUnreachable;
|
||||||
|
|
||||||
@ -248,7 +248,7 @@ BattleAction CStupidAI::goTowards(const CStack * stack, THex hex)
|
|||||||
}
|
}
|
||||||
|
|
||||||
dists = cb->battleGetDistances(stack, realDest, predecessors);
|
dists = cb->battleGetDistances(stack, realDest, predecessors);
|
||||||
std::vector<THex> avHexes = cb->battleGetAvailableHexes(stack, false);
|
std::vector<THex> avHexes = cb->battleGetAvailableHexes(stack, false, false);
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
@ -570,7 +570,7 @@ void CBattleCallback::getStackQueue( std::vector<const CStack *> &out, int howMa
|
|||||||
gs->curB->getStackQueue(out, howMany);
|
gs->curB->getStackQueue(out, howMany);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<THex> CBattleCallback::battleGetAvailableHexes(const CStack * stack, bool addOccupiable)
|
std::vector<THex> CBattleCallback::battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector<THex> * attackable)
|
||||||
{
|
{
|
||||||
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||||
if(!gs->curB)
|
if(!gs->curB)
|
||||||
@ -578,7 +578,7 @@ std::vector<THex> CBattleCallback::battleGetAvailableHexes(const CStack * stack,
|
|||||||
tlog2<<"battleGetAvailableHexes called when there is no battle!"<<std::endl;
|
tlog2<<"battleGetAvailableHexes called when there is no battle!"<<std::endl;
|
||||||
return std::vector<THex>();
|
return std::vector<THex>();
|
||||||
}
|
}
|
||||||
return gs->curB->getAccessibility(stack, addOccupiable);
|
return gs->curB->getAccessibility(stack, addOccupiable, attackable);
|
||||||
//return gs->battleGetRange(ID);
|
//return gs->battleGetRange(ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ public:
|
|||||||
virtual int battleMakeAction(BattleAction* action)=0;//for casting spells by hero - DO NOT use it for moving active stack
|
virtual int battleMakeAction(BattleAction* action)=0;//for casting spells by hero - DO NOT use it for moving active stack
|
||||||
virtual TStacks battleGetStacks(EStackOwnership whose = MINE_AND_ENEMY, bool onlyAlive = true)=0; //returns stacks on battlefield
|
virtual TStacks battleGetStacks(EStackOwnership whose = MINE_AND_ENEMY, bool onlyAlive = true)=0; //returns stacks on battlefield
|
||||||
virtual void getStackQueue( std::vector<const CStack *> &out, int howMany )=0; //returns vector of stack in order of their move sequence
|
virtual void getStackQueue( std::vector<const CStack *> &out, int howMany )=0; //returns vector of stack in order of their move sequence
|
||||||
virtual std::vector<THex> battleGetAvailableHexes(const CStack * stack, bool addOccupiable)=0; //returns numbers of hexes reachable by creature with id ID
|
virtual std::vector<THex> battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector<THex> * attackable = NULL)=0; //returns numbers of hexes reachable by creature with id ID
|
||||||
virtual std::vector<int> battleGetDistances(const CStack * stack, THex hex = THex::INVALID, THex * predecessors = NULL)=0; //returns vector of distances to [dest hex number]
|
virtual std::vector<int> battleGetDistances(const CStack * stack, THex hex = THex::INVALID, THex * predecessors = NULL)=0; //returns vector of distances to [dest hex number]
|
||||||
virtual bool battleCanShoot(const CStack * stack, THex dest)=0; //returns true if unit with id ID can shoot to dest
|
virtual bool battleCanShoot(const CStack * stack, THex dest)=0; //returns true if unit with id ID can shoot to dest
|
||||||
virtual bool battleCanCastSpell()=0; //returns true, if caller can cast a spell
|
virtual bool battleCanCastSpell()=0; //returns true, if caller can cast a spell
|
||||||
@ -231,7 +231,7 @@ public:
|
|||||||
int battleMakeAction(BattleAction* action) OVERRIDE;//for casting spells by hero - DO NOT use it for moving active stack
|
int battleMakeAction(BattleAction* action) OVERRIDE;//for casting spells by hero - DO NOT use it for moving active stack
|
||||||
TStacks battleGetStacks(EStackOwnership whose = MINE_AND_ENEMY, bool onlyAlive = true) OVERRIDE; //returns stacks on battlefield
|
TStacks battleGetStacks(EStackOwnership whose = MINE_AND_ENEMY, bool onlyAlive = true) OVERRIDE; //returns stacks on battlefield
|
||||||
void getStackQueue( std::vector<const CStack *> &out, int howMany ) OVERRIDE; //returns vector of stack in order of their move sequence
|
void getStackQueue( std::vector<const CStack *> &out, int howMany ) OVERRIDE; //returns vector of stack in order of their move sequence
|
||||||
std::vector<THex> battleGetAvailableHexes(const CStack * stack, bool addOccupiable) OVERRIDE; //reutrns numbers of hexes reachable by creature with id ID
|
std::vector<THex> battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector<THex> * attackable = NULL) OVERRIDE; //returns numbers of hexes reachable by creature with id ID
|
||||||
std::vector<int> battleGetDistances(const CStack * stack, THex hex = THex::INVALID, THex * predecessors = NULL) OVERRIDE; //returns vector of distances to [dest hex number]; if predecessors is not null, it must point to BFIELD_SIZE * sizeof(int) of allocated memory
|
std::vector<int> battleGetDistances(const CStack * stack, THex hex = THex::INVALID, THex * predecessors = NULL) OVERRIDE; //returns vector of distances to [dest hex number]; if predecessors is not null, it must point to BFIELD_SIZE * sizeof(int) of allocated memory
|
||||||
bool battleCanShoot(const CStack * stack, THex dest) OVERRIDE; //returns true if unit with id ID can shoot to dest
|
bool battleCanShoot(const CStack * stack, THex dest) OVERRIDE; //returns true if unit with id ID can shoot to dest
|
||||||
bool battleCanCastSpell() OVERRIDE; //returns true, if caller can cast a spell
|
bool battleCanCastSpell() OVERRIDE; //returns true, if caller can cast a spell
|
||||||
|
@ -1804,7 +1804,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(std::find(shadedHexes.begin(),shadedHexes.end(),myNumber) == shadedHexes.end())
|
if(std::find(occupyableHexes.begin(),occupyableHexes.end(),myNumber) == occupyableHexes.end())
|
||||||
{
|
{
|
||||||
const CStack *shere = curInt->cb->battleGetStackByPos(myNumber);
|
const CStack *shere = curInt->cb->battleGetStackByPos(myNumber);
|
||||||
const CStack *sactive = activeStack;
|
const CStack *sactive = activeStack;
|
||||||
@ -1881,7 +1881,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
|
|||||||
|
|
||||||
// Exclude directions which cannot be attacked from.
|
// Exclude directions which cannot be attacked from.
|
||||||
// Check to the left.
|
// Check to the left.
|
||||||
if (myNumber%BFIELD_WIDTH <= 1 || !vstd::contains(shadedHexes, myNumber - 1))
|
if (myNumber%BFIELD_WIDTH <= 1 || !vstd::contains(occupyableHexes, myNumber - 1))
|
||||||
{
|
{
|
||||||
sectorCursor[0] = -1;
|
sectorCursor[0] = -1;
|
||||||
}
|
}
|
||||||
@ -1898,13 +1898,13 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
|
|||||||
{
|
{
|
||||||
bool attackRow[4] = {true, true, true, true};
|
bool attackRow[4] = {true, true, true, true};
|
||||||
|
|
||||||
if (myNumber%BFIELD_WIDTH <= 1 || !vstd::contains(shadedHexes, myNumber - BFIELD_WIDTH - 2 + zigzagCorrection))
|
if (myNumber%BFIELD_WIDTH <= 1 || !vstd::contains(occupyableHexes, myNumber - BFIELD_WIDTH - 2 + zigzagCorrection))
|
||||||
attackRow[0] = false;
|
attackRow[0] = false;
|
||||||
if (!vstd::contains(shadedHexes, myNumber - BFIELD_WIDTH - 1 + zigzagCorrection))
|
if (!vstd::contains(occupyableHexes, myNumber - BFIELD_WIDTH - 1 + zigzagCorrection))
|
||||||
attackRow[1] = false;
|
attackRow[1] = false;
|
||||||
if (!vstd::contains(shadedHexes, myNumber - BFIELD_WIDTH + zigzagCorrection))
|
if (!vstd::contains(occupyableHexes, myNumber - BFIELD_WIDTH + zigzagCorrection))
|
||||||
attackRow[2] = false;
|
attackRow[2] = false;
|
||||||
if (myNumber%BFIELD_WIDTH >= BFIELD_WIDTH - 2 || !vstd::contains(shadedHexes, myNumber - BFIELD_WIDTH + 1 + zigzagCorrection))
|
if (myNumber%BFIELD_WIDTH >= BFIELD_WIDTH - 2 || !vstd::contains(occupyableHexes, myNumber - BFIELD_WIDTH + 1 + zigzagCorrection))
|
||||||
attackRow[3] = false;
|
attackRow[3] = false;
|
||||||
|
|
||||||
if (!(attackRow[0] && attackRow[1]))
|
if (!(attackRow[0] && attackRow[1]))
|
||||||
@ -1916,14 +1916,14 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!vstd::contains(shadedHexes, myNumber - BFIELD_WIDTH - 1 + zigzagCorrection))
|
if (!vstd::contains(occupyableHexes, myNumber - BFIELD_WIDTH - 1 + zigzagCorrection))
|
||||||
sectorCursor[1] = -1;
|
sectorCursor[1] = -1;
|
||||||
if (!vstd::contains(shadedHexes, myNumber - BFIELD_WIDTH + zigzagCorrection))
|
if (!vstd::contains(occupyableHexes, myNumber - BFIELD_WIDTH + zigzagCorrection))
|
||||||
sectorCursor[2] = -1;
|
sectorCursor[2] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check to the right.
|
// Check to the right.
|
||||||
if (myNumber%BFIELD_WIDTH >= BFIELD_WIDTH - 2 || !vstd::contains(shadedHexes, myNumber + 1))
|
if (myNumber%BFIELD_WIDTH >= BFIELD_WIDTH - 2 || !vstd::contains(occupyableHexes, myNumber + 1))
|
||||||
{
|
{
|
||||||
sectorCursor[3] = -1;
|
sectorCursor[3] = -1;
|
||||||
}
|
}
|
||||||
@ -1940,13 +1940,13 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
|
|||||||
{
|
{
|
||||||
bool attackRow[4] = {true, true, true, true};
|
bool attackRow[4] = {true, true, true, true};
|
||||||
|
|
||||||
if (myNumber%BFIELD_WIDTH <= 1 || !vstd::contains(shadedHexes, myNumber + BFIELD_WIDTH - 2 + zigzagCorrection))
|
if (myNumber%BFIELD_WIDTH <= 1 || !vstd::contains(occupyableHexes, myNumber + BFIELD_WIDTH - 2 + zigzagCorrection))
|
||||||
attackRow[0] = false;
|
attackRow[0] = false;
|
||||||
if (!vstd::contains(shadedHexes, myNumber + BFIELD_WIDTH - 1 + zigzagCorrection))
|
if (!vstd::contains(occupyableHexes, myNumber + BFIELD_WIDTH - 1 + zigzagCorrection))
|
||||||
attackRow[1] = false;
|
attackRow[1] = false;
|
||||||
if (!vstd::contains(shadedHexes, myNumber + BFIELD_WIDTH + zigzagCorrection))
|
if (!vstd::contains(occupyableHexes, myNumber + BFIELD_WIDTH + zigzagCorrection))
|
||||||
attackRow[2] = false;
|
attackRow[2] = false;
|
||||||
if (myNumber%BFIELD_WIDTH >= BFIELD_WIDTH - 2 || !vstd::contains(shadedHexes, myNumber + BFIELD_WIDTH + 1 + zigzagCorrection))
|
if (myNumber%BFIELD_WIDTH >= BFIELD_WIDTH - 2 || !vstd::contains(occupyableHexes, myNumber + BFIELD_WIDTH + 1 + zigzagCorrection))
|
||||||
attackRow[3] = false;
|
attackRow[3] = false;
|
||||||
|
|
||||||
if (!(attackRow[0] && attackRow[1]))
|
if (!(attackRow[0] && attackRow[1]))
|
||||||
@ -1958,9 +1958,9 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!vstd::contains(shadedHexes, myNumber + BFIELD_WIDTH + zigzagCorrection))
|
if (!vstd::contains(occupyableHexes, myNumber + BFIELD_WIDTH + zigzagCorrection))
|
||||||
sectorCursor[4] = -1;
|
sectorCursor[4] = -1;
|
||||||
if (!vstd::contains(shadedHexes, myNumber + BFIELD_WIDTH - 1 + zigzagCorrection))
|
if (!vstd::contains(occupyableHexes, myNumber + BFIELD_WIDTH - 1 + zigzagCorrection))
|
||||||
sectorCursor[5] = -1;
|
sectorCursor[5] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2389,9 +2389,9 @@ void CBattleInterface::giveCommand(ui8 action, THex tile, ui32 stack, si32 addit
|
|||||||
|
|
||||||
bool CBattleInterface::isTileAttackable(const THex & number) const
|
bool CBattleInterface::isTileAttackable(const THex & number) const
|
||||||
{
|
{
|
||||||
for(size_t b=0; b<shadedHexes.size(); ++b)
|
for(size_t b=0; b<occupyableHexes.size(); ++b)
|
||||||
{
|
{
|
||||||
if(THex::mutualPosition(shadedHexes[b], number) != -1 || shadedHexes[b] == number)
|
if(THex::mutualPosition(occupyableHexes[b], number) != -1 || occupyableHexes[b] == number)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -2497,7 +2497,7 @@ void CBattleInterface::hexLclicked(int whichOne)
|
|||||||
{
|
{
|
||||||
if(!dest || !dest->alive()) //no creature at that tile
|
if(!dest || !dest->alive()) //no creature at that tile
|
||||||
{
|
{
|
||||||
if(std::find(shadedHexes.begin(),shadedHexes.end(),whichOne)!=shadedHexes.end())// and it's in our range
|
if(std::find(occupyableHexes.begin(),occupyableHexes.end(),whichOne)!=occupyableHexes.end())// and it's in our range
|
||||||
{
|
{
|
||||||
CCS->curh->changeGraphic(1, 6); //cursor should be changed
|
CCS->curh->changeGraphic(1, 6); //cursor should be changed
|
||||||
if(activeStack->doubleWide())
|
if(activeStack->doubleWide())
|
||||||
@ -2536,16 +2536,16 @@ void CBattleInterface::hexLclicked(int whichOne)
|
|||||||
bool doubleWide = actStack->doubleWide();
|
bool doubleWide = actStack->doubleWide();
|
||||||
int destHex = whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH+1 ) +
|
int destHex = whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH+1 ) +
|
||||||
(actStack->attackerOwned && doubleWide ? 1 : 0);
|
(actStack->attackerOwned && doubleWide ? 1 : 0);
|
||||||
if(vstd::contains(shadedHexes, destHex))
|
if(vstd::contains(occupyableHexes, destHex))
|
||||||
attackFromHex = destHex;
|
attackFromHex = destHex;
|
||||||
else if(actStack->attackerOwned) //if we are attacker
|
else if(actStack->attackerOwned) //if we are attacker
|
||||||
{
|
{
|
||||||
if(vstd::contains(shadedHexes, destHex+1))
|
if(vstd::contains(occupyableHexes, destHex+1))
|
||||||
attackFromHex = destHex+1;
|
attackFromHex = destHex+1;
|
||||||
}
|
}
|
||||||
else //if we are defender
|
else //if we are defender
|
||||||
{
|
{
|
||||||
if(vstd::contains(shadedHexes, destHex-1))
|
if(vstd::contains(occupyableHexes, destHex-1))
|
||||||
attackFromHex = destHex-1;
|
attackFromHex = destHex-1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -2553,16 +2553,16 @@ void CBattleInterface::hexLclicked(int whichOne)
|
|||||||
case 7: //from bottom left
|
case 7: //from bottom left
|
||||||
{
|
{
|
||||||
int destHex = whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH-1 : BFIELD_WIDTH );
|
int destHex = whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH-1 : BFIELD_WIDTH );
|
||||||
if(vstd::contains(shadedHexes, destHex))
|
if(vstd::contains(occupyableHexes, destHex))
|
||||||
attackFromHex = destHex;
|
attackFromHex = destHex;
|
||||||
else if(actStack->attackerOwned) //if we are attacker
|
else if(actStack->attackerOwned) //if we are attacker
|
||||||
{
|
{
|
||||||
if(vstd::contains(shadedHexes, destHex+1))
|
if(vstd::contains(occupyableHexes, destHex+1))
|
||||||
attackFromHex = destHex+1;
|
attackFromHex = destHex+1;
|
||||||
}
|
}
|
||||||
else //if we are defender
|
else //if we are defender
|
||||||
{
|
{
|
||||||
if(vstd::contains(shadedHexes, destHex-1))
|
if(vstd::contains(occupyableHexes, destHex-1))
|
||||||
attackFromHex = destHex-1;
|
attackFromHex = destHex-1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -2586,16 +2586,16 @@ void CBattleInterface::hexLclicked(int whichOne)
|
|||||||
case 9: //from top left
|
case 9: //from top left
|
||||||
{
|
{
|
||||||
int destHex = whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH+1 : BFIELD_WIDTH );
|
int destHex = whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH+1 : BFIELD_WIDTH );
|
||||||
if(vstd::contains(shadedHexes, destHex))
|
if(vstd::contains(occupyableHexes, destHex))
|
||||||
attackFromHex = destHex;
|
attackFromHex = destHex;
|
||||||
else if(actStack->attackerOwned) //if we are attacker
|
else if(actStack->attackerOwned) //if we are attacker
|
||||||
{
|
{
|
||||||
if(vstd::contains(shadedHexes, destHex+1))
|
if(vstd::contains(occupyableHexes, destHex+1))
|
||||||
attackFromHex = destHex+1;
|
attackFromHex = destHex+1;
|
||||||
}
|
}
|
||||||
else //if we are defender
|
else //if we are defender
|
||||||
{
|
{
|
||||||
if(vstd::contains(shadedHexes, destHex-1))
|
if(vstd::contains(occupyableHexes, destHex-1))
|
||||||
attackFromHex = destHex-1;
|
attackFromHex = destHex-1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -2605,16 +2605,16 @@ void CBattleInterface::hexLclicked(int whichOne)
|
|||||||
bool doubleWide = actStack->doubleWide();
|
bool doubleWide = actStack->doubleWide();
|
||||||
int destHex = whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH-1 ) +
|
int destHex = whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH-1 ) +
|
||||||
(actStack->attackerOwned && doubleWide ? 1 : 0);
|
(actStack->attackerOwned && doubleWide ? 1 : 0);
|
||||||
if(vstd::contains(shadedHexes, destHex))
|
if(vstd::contains(occupyableHexes, destHex))
|
||||||
attackFromHex = destHex;
|
attackFromHex = destHex;
|
||||||
else if(actStack->attackerOwned) //if we are attacker
|
else if(actStack->attackerOwned) //if we are attacker
|
||||||
{
|
{
|
||||||
if(vstd::contains(shadedHexes, destHex+1))
|
if(vstd::contains(occupyableHexes, destHex+1))
|
||||||
attackFromHex = destHex+1;
|
attackFromHex = destHex+1;
|
||||||
}
|
}
|
||||||
else //if we are defender
|
else //if we are defender
|
||||||
{
|
{
|
||||||
if(vstd::contains(shadedHexes, destHex-1))
|
if(vstd::contains(occupyableHexes, destHex-1))
|
||||||
attackFromHex = destHex-1;
|
attackFromHex = destHex-1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -2638,16 +2638,16 @@ void CBattleInterface::hexLclicked(int whichOne)
|
|||||||
case 13: //from bottom
|
case 13: //from bottom
|
||||||
{
|
{
|
||||||
int destHex = whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH+1 );
|
int destHex = whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH+1 );
|
||||||
if(vstd::contains(shadedHexes, destHex))
|
if(vstd::contains(occupyableHexes, destHex))
|
||||||
attackFromHex = destHex;
|
attackFromHex = destHex;
|
||||||
else if(attackingHeroInstance->tempOwner == curInt->cb->getMyColor()) //if we are attacker
|
else if(attackingHeroInstance->tempOwner == curInt->cb->getMyColor()) //if we are attacker
|
||||||
{
|
{
|
||||||
if(vstd::contains(shadedHexes, destHex+1))
|
if(vstd::contains(occupyableHexes, destHex+1))
|
||||||
attackFromHex = destHex+1;
|
attackFromHex = destHex+1;
|
||||||
}
|
}
|
||||||
else //if we are defender
|
else //if we are defender
|
||||||
{
|
{
|
||||||
if(vstd::contains(shadedHexes, destHex-1))
|
if(vstd::contains(occupyableHexes, destHex-1))
|
||||||
attackFromHex = destHex-1;
|
attackFromHex = destHex-1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -2655,16 +2655,16 @@ void CBattleInterface::hexLclicked(int whichOne)
|
|||||||
case 14: //from top
|
case 14: //from top
|
||||||
{
|
{
|
||||||
int destHex = whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH-1 );
|
int destHex = whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH-1 );
|
||||||
if(vstd::contains(shadedHexes, destHex))
|
if(vstd::contains(occupyableHexes, destHex))
|
||||||
attackFromHex = destHex;
|
attackFromHex = destHex;
|
||||||
else if(attackingHeroInstance->tempOwner == curInt->cb->getMyColor()) //if we are attacker
|
else if(attackingHeroInstance->tempOwner == curInt->cb->getMyColor()) //if we are attacker
|
||||||
{
|
{
|
||||||
if(vstd::contains(shadedHexes, destHex+1))
|
if(vstd::contains(occupyableHexes, destHex+1))
|
||||||
attackFromHex = destHex+1;
|
attackFromHex = destHex+1;
|
||||||
}
|
}
|
||||||
else //if we are defender
|
else //if we are defender
|
||||||
{
|
{
|
||||||
if(vstd::contains(shadedHexes, destHex-1))
|
if(vstd::contains(occupyableHexes, destHex-1))
|
||||||
attackFromHex = destHex-1;
|
attackFromHex = destHex-1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -3207,7 +3207,8 @@ void CBattleInterface::showPieceOfWall(SDL_Surface * to, int hex, const std::vec
|
|||||||
|
|
||||||
void CBattleInterface::redrawBackgroundWithHexes(const CStack * activeStack)
|
void CBattleInterface::redrawBackgroundWithHexes(const CStack * activeStack)
|
||||||
{
|
{
|
||||||
shadedHexes = curInt->cb->battleGetAvailableHexes(activeStack, true);
|
attackableHexes.clear();
|
||||||
|
occupyableHexes = curInt->cb->battleGetAvailableHexes(activeStack, true, &attackableHexes);
|
||||||
|
|
||||||
//preparating background graphic with hexes and shaded hexes
|
//preparating background graphic with hexes and shaded hexes
|
||||||
blitAt(background, 0, 0, backgroundWithHexes);
|
blitAt(background, 0, 0, backgroundWithHexes);
|
||||||
@ -3216,10 +3217,12 @@ void CBattleInterface::redrawBackgroundWithHexes(const CStack * activeStack)
|
|||||||
|
|
||||||
if(curInt->sysOpts.printStackRange)
|
if(curInt->sysOpts.printStackRange)
|
||||||
{
|
{
|
||||||
for(size_t m=0; m<shadedHexes.size(); ++m) //rows
|
std::vector<THex> hexesToShade = occupyableHexes;
|
||||||
|
hexesToShade.insert(hexesToShade.end(), attackableHexes.begin(), attackableHexes.end());
|
||||||
|
BOOST_FOREACH(THex hex, hexesToShade)
|
||||||
{
|
{
|
||||||
int i = shadedHexes[m]/BFIELD_WIDTH; //row
|
int i = hex.getY(); //row
|
||||||
int j = shadedHexes[m]%BFIELD_WIDTH-1; //column
|
int j = hex.getX()-1; //column
|
||||||
int x = 58 + (i%2==0 ? 22 : 0) + 44*j;
|
int x = 58 + (i%2==0 ? 22 : 0) + 44*j;
|
||||||
int y = 86 + 42 * i;
|
int y = 86 + 42 * i;
|
||||||
CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, backgroundWithHexes, &genRect(cellShade->h, cellShade->w, x, y));
|
CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, backgroundWithHexes, &genRect(cellShade->h, cellShade->w, x, y));
|
||||||
|
@ -414,7 +414,8 @@ private:
|
|||||||
const CStack * stackToActivate; //when animation is playing, we should wait till the end to make the next stack active; NULL of none
|
const CStack * stackToActivate; //when animation is playing, we should wait till the end to make the next stack active; NULL of none
|
||||||
void activateStack(); //sets activeStack to stackToActivate etc.
|
void activateStack(); //sets activeStack to stackToActivate etc.
|
||||||
int mouseHoveredStack; //stack hovered by mouse; if -1 -> none
|
int mouseHoveredStack; //stack hovered by mouse; if -1 -> none
|
||||||
std::vector<THex> shadedHexes; //hexes available for active stack
|
std::vector<THex> occupyableHexes, //hexes available for active stack
|
||||||
|
attackableHexes; //hexes attackable by active stack
|
||||||
int previouslyHoveredHex; //number of hex that was hovered by the cursor a while ago
|
int previouslyHoveredHex; //number of hex that was hovered by the cursor a while ago
|
||||||
int currentlyHoveredHex; //number of hex that is supposed to be hovered (for a while it may be inappropriately set, but will be renewed soon)
|
int currentlyHoveredHex; //number of hex that is supposed to be hovered (for a while it may be inappropriately set, but will be renewed soon)
|
||||||
float getAnimSpeedMultiplier() const; //returns multiplier for number of frames in a group
|
float getAnimSpeedMultiplier() const; //returns multiplier for number of frames in a group
|
||||||
|
@ -270,7 +270,7 @@ void BattleInfo::makeBFS(THex start, bool *accessibility, THex *predecessor, int
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<THex> BattleInfo::getAccessibility(const CStack * stack, bool addOccupiable) const
|
std::vector<THex> BattleInfo::getAccessibility( const CStack * stack, bool addOccupiable, std::vector<THex> * attackable ) const
|
||||||
{
|
{
|
||||||
std::vector<THex> ret;
|
std::vector<THex> ret;
|
||||||
bool ac[BFIELD_SIZE];
|
bool ac[BFIELD_SIZE];
|
||||||
@ -330,6 +330,48 @@ std::vector<THex> BattleInfo::getAccessibility(const CStack * stack, bool addOcc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(attackable)
|
||||||
|
{
|
||||||
|
struct HLP
|
||||||
|
{
|
||||||
|
static bool meleeAttackable(THex hex, const std::vector<THex> & baseRng)
|
||||||
|
{
|
||||||
|
BOOST_FOREACH(THex h, baseRng)
|
||||||
|
{
|
||||||
|
if(THex::mutualPosition(h, hex) > 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
BOOST_FOREACH(const CStack * otherSt, stacks)
|
||||||
|
{
|
||||||
|
if(otherSt->owner == stack->owner)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::vector<THex> occupiedBySecond;
|
||||||
|
occupiedBySecond.push_back(otherSt->position);
|
||||||
|
if(otherSt->doubleWide())
|
||||||
|
occupiedBySecond.push_back(otherSt->occupiedHex());
|
||||||
|
|
||||||
|
if(battleCanShoot(stack, otherSt->position))
|
||||||
|
{
|
||||||
|
attackable->insert(attackable->end(), occupiedBySecond.begin(), occupiedBySecond.end());
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_FOREACH(THex he, occupiedBySecond)
|
||||||
|
{
|
||||||
|
if(HLP::meleeAttackable(he, ret))
|
||||||
|
attackable->push_back(he);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
bool BattleInfo::isStackBlocked(const CStack * stack) const
|
bool BattleInfo::isStackBlocked(const CStack * stack) const
|
||||||
|
@ -90,7 +90,7 @@ struct DLL_EXPORT BattleInfo : public CBonusSystemNode
|
|||||||
static bool isAccessible(THex hex, bool * accessibility, bool twoHex, bool attackerOwned, bool flying, bool lastPos); //helper for makeBFS
|
static bool isAccessible(THex hex, bool * accessibility, bool twoHex, bool attackerOwned, bool flying, bool lastPos); //helper for makeBFS
|
||||||
void makeBFS(THex start, bool*accessibility, THex *predecessor, int *dists, bool twoHex, bool attackerOwned, bool flying, bool fillPredecessors) const; //*accessibility must be prepared bool[187] array; last two pointers must point to the at least 187-elements int arrays - there is written result
|
void makeBFS(THex start, bool*accessibility, THex *predecessor, int *dists, bool twoHex, bool attackerOwned, bool flying, bool fillPredecessors) const; //*accessibility must be prepared bool[187] array; last two pointers must point to the at least 187-elements int arrays - there is written result
|
||||||
std::pair< std::vector<THex>, int > getPath(THex start, THex dest, bool*accessibility, bool flyingCreature, bool twoHex, bool attackerOwned); //returned value: pair<path, length>; length may be different than number of elements in path since flying vreatures jump between distant hexes
|
std::pair< std::vector<THex>, int > getPath(THex start, THex dest, bool*accessibility, bool flyingCreature, bool twoHex, bool attackerOwned); //returned value: pair<path, length>; length may be different than number of elements in path since flying vreatures jump between distant hexes
|
||||||
std::vector<THex> getAccessibility(const CStack * stack, bool addOccupiable) const; //returns vector of accessible tiles (taking into account the creature range)
|
std::vector<THex> getAccessibility(const CStack * stack, bool addOccupiable, std::vector<THex> * attackable = NULL) const; //returns vector of accessible tiles (taking into account the creature range)
|
||||||
|
|
||||||
bool isStackBlocked(const CStack * stack) const; //returns true if there is neighboring enemy stack
|
bool isStackBlocked(const CStack * stack) const; //returns true if there is neighboring enemy stack
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user