1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

Merge pull request #1783 from vcmi/beta

Merge beta -> develop
This commit is contained in:
Ivan Savenko
2023-03-27 21:21:25 +03:00
committed by GitHub
18 changed files with 75 additions and 49 deletions

View File

@@ -1401,6 +1401,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))
@@ -1593,10 +1598,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;
@@ -1612,7 +1619,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)
@@ -1640,7 +1652,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;
}
@@ -5301,13 +5313,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)
{
@@ -5318,7 +5330,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;
@@ -5336,9 +5348,9 @@ bool CGameHandler::handleDamageFromObstacle(const CStack * curStack, bool stackI
ObstacleChanges changeInfo;
changeInfo.id = spellObstacle->uniqueID;
if (oneTimeObstacle)
changeInfo.operation = ObstacleChanges::EOperation::ACTIVATE_AND_REMOVE;
changeInfo.operation = ObstacleChanges::EOperation::REMOVE;
else
changeInfo.operation = ObstacleChanges::EOperation::ACTIVATE_AND_UPDATE;
changeInfo.operation = ObstacleChanges::EOperation::UPDATE;
SpellCreatedObstacle changedObstacle;
changedObstacle.uniqueID = spellObstacle->uniqueID;
@@ -5382,13 +5394,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()