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

Prevents first aid tents from melee attacking;

Moves attack possibility checks to battle callback (for consistency with shooting checks);
This commit is contained in:
Fay 2015-04-09 21:49:11 +02:00
parent d32461d9d1
commit 1cb54689cf
3 changed files with 27 additions and 2 deletions

View File

@ -2153,9 +2153,9 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
case WALK_AND_ATTACK: case WALK_AND_ATTACK:
case ATTACK_AND_RETURN: case ATTACK_AND_RETURN:
{ {
if (shere && !ourStack && shere->alive()) if (curInt->cb->battleCanAttack(sactive, shere, myNumber))
{ {
if (isTileAttackable(myNumber)) if (isTileAttackable(myNumber)) // move isTileAttackable to be part of battleCanAttack?
{ {
setBattleCursor(myNumber); // temporary - needed for following function :( setBattleCursor(myNumber); // temporary - needed for following function :(
BattleHex attackFromHex = fromWhichHexAttack(myNumber); BattleHex attackFromHex = fromWhichHexAttack(myNumber);

View File

@ -775,6 +775,29 @@ std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const CStack
return ret; return ret;
} }
bool CBattleInfoCallback::battleCanAttack(const CStack * stack, const CStack * target, BattleHex dest) const
{
RETURN_IF_NOT_BATTLE(false);
if(battleTacticDist())
return false;
if (!stack || !target)
return false;
if (stack->owner == target->owner)
return false;
auto &id = stack->getCreature()->idNumber;
if (id == CreatureID::FIRST_AID_TENT || id == CreatureID::CATAPULT)
return false;
if (!target->alive())
return false;
return true;
}
bool CBattleInfoCallback::battleCanShoot(const CStack * stack, BattleHex dest) const bool CBattleInfoCallback::battleCanShoot(const CStack * stack, BattleHex dest) const
{ {
RETURN_IF_NOT_BATTLE(false); RETURN_IF_NOT_BATTLE(false);

View File

@ -252,6 +252,8 @@ public:
int battleGetSurrenderCost(PlayerColor Player) const; //returns cost of surrendering battle, -1 if surrendering is not possible int battleGetSurrenderCost(PlayerColor Player) const; //returns cost of surrendering battle, -1 if surrendering is not possible
ReachabilityInfo::TDistances battleGetDistances(const CStack * stack, BattleHex hex = BattleHex::INVALID, BattleHex * predecessors = nullptr) const; //returns vector of distances to [dest hex number] ReachabilityInfo::TDistances battleGetDistances(const CStack * stack, BattleHex hex = BattleHex::INVALID, BattleHex * predecessors = nullptr) const; //returns vector of distances to [dest hex number]
std::set<BattleHex> battleGetAttackedHexes(const CStack* attacker, BattleHex destinationTile, BattleHex attackerPos = BattleHex::INVALID) const; std::set<BattleHex> battleGetAttackedHexes(const CStack* attacker, BattleHex destinationTile, BattleHex attackerPos = BattleHex::INVALID) 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 battleCanShoot(const CStack * stack, BattleHex dest) const; //determines if stack with given ID shoot at the selected destination bool battleCanShoot(const CStack * stack, BattleHex dest) const; //determines if stack with given ID shoot at the selected destination
bool battleIsStackBlocked(const CStack * stack) const; //returns true if there is neighboring enemy stack bool battleIsStackBlocked(const CStack * stack) const; //returns true if there is neighboring enemy stack
std::set<const CStack*> batteAdjacentCreatures (const CStack * stack) const; std::set<const CStack*> batteAdjacentCreatures (const CStack * stack) const;