1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

vcmi: really correct obstacle trigger

Now obstacle trigger really matches H3
This commit is contained in:
Konstantin
2023-03-27 16:11:17 +03:00
parent 8c1d6c8e13
commit 9a229d6e48
5 changed files with 32 additions and 19 deletions

View File

@@ -1398,6 +1398,11 @@ int CGameHandler::moveStack(int stack, BattleHex dest)
//initing necessary tables
auto accessibility = getAccesibility(curStack);
std::set<BattleHex> passed;
//Ignore obstacles on starting position
passed.insert(curStack->getPosition());
if(curStack->doubleWide())
passed.insert(curStack->occupiedHex());
//shifting destination (if we have double wide stack and we can occupy dest but not be exactly there)
if(!stackAtEnd && curStack->doubleWide() && !accessibility.accessible(dest, curStack))
@@ -1590,10 +1595,12 @@ int CGameHandler::moveStack(int stack, BattleHex dest)
if(otherHex.isValid() && !obstacle2.empty())
obstacleHit = true;
}
if(!obstacleHit)
passed.insert(hex);
}
}
if (tiles.size() > 0)
if (!tiles.empty())
{
//commit movement
BattleStackMoved sm;
@@ -1609,7 +1616,12 @@ int CGameHandler::moveStack(int stack, BattleHex dest)
if (curStack->getPosition() != dest)
{
if(stackIsMoving && start != curStack->getPosition())
stackIsMoving = handleDamageFromObstacle(curStack, stackIsMoving);
{
stackIsMoving = handleDamageFromObstacle(curStack, stackIsMoving, passed);
passed.insert(curStack->getPosition());
if(curStack->doubleWide())
passed.insert(curStack->occupiedHex());
}
if (gateStateChanging)
{
if (curStack->getPosition() == openGateAtHex)
@@ -1637,7 +1649,7 @@ int CGameHandler::moveStack(int stack, BattleHex dest)
}
//handling obstacle on the final field (separate, because it affects both flying and walking stacks)
handleDamageFromObstacle(curStack);
handleDamageFromObstacle(curStack, false, passed);
return ret;
}
@@ -5288,13 +5300,13 @@ void CGameHandler::stackTurnTrigger(const CStack *st)
}
}
bool CGameHandler::handleDamageFromObstacle(const CStack * curStack, bool stackIsMoving)
bool CGameHandler::handleDamageFromObstacle(const CStack * curStack, bool stackIsMoving, const std::set<BattleHex> & passed)
{
if(!curStack->alive())
return false;
bool containDamageFromMoat = false;
bool movementStoped = false;
for(auto & obstacle : getAllAffectedObstaclesByStack(curStack))
bool movementStopped = false;
for(auto & obstacle : getAllAffectedObstaclesByStack(curStack, passed))
{
if(obstacle->obstacleType == CObstacleInstance::SPELL_CREATED)
{
@@ -5305,7 +5317,7 @@ bool CGameHandler::handleDamageFromObstacle(const CStack * curStack, bool stackI
if(!spellObstacle)
COMPLAIN_RET("Invalid obstacle instance");
if(spellObstacle->trigger)
if(spellObstacle->triggersEffects())
{
const bool oneTimeObstacle = spellObstacle->removeOnTrigger;
@@ -5369,13 +5381,13 @@ bool CGameHandler::handleDamageFromObstacle(const CStack * curStack, bool stackI
return false;
if((obstacle->stopsMovement() && stackIsMoving))
movementStoped = true;
movementStopped = true;
}
if(stackIsMoving)
return curStack->alive() && !movementStoped;
else
return curStack->alive();
return curStack->alive() && !movementStopped;
return curStack->alive();
}
void CGameHandler::handleTimeEvents()