1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

Changes according to review

This commit is contained in:
Ivan Savenko
2023-09-18 18:17:26 +03:00
parent b7de685483
commit f1c40466d3
4 changed files with 31 additions and 29 deletions

View File

@ -347,7 +347,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
if (!hero) if (!hero)
return; return;
movementController->heroMoved(hero, details); movementController->onTryMoveHero(hero, details);
} }
void CPlayerInterface::heroKilled(const CGHeroInstance* hero) void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
@ -937,7 +937,7 @@ void CPlayerInterface::showInfoDialog(EInfoWindowMode type, const std::string &t
adventureInt->showInfoBoxMessage(components, text, timer); adventureInt->showInfoBoxMessage(components, text, timer);
// abort movement, if any. Strictly speaking unnecessary, but prevents some edge cases, like movement sound on visiting Magi Hut with "show messages in status window" on // abort movement, if any. Strictly speaking unnecessary, but prevents some edge cases, like movement sound on visiting Magi Hut with "show messages in status window" on
movementController->movementAbortRequested(); movementController->requestMovementAbort();
if (makingTurn && GH.windows().count() > 0 && LOCPLINT == this) if (makingTurn && GH.windows().count() > 0 && LOCPLINT == this)
CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID)); CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID));
@ -984,7 +984,7 @@ void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector
{ {
CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID)); CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID));
showingDialog->set(true); showingDialog->set(true);
movementController->movementAbortRequested(); // interrupt movement to show dialog movementController->requestMovementAbort(); // interrupt movement to show dialog
GH.windows().pushWindow(temp); GH.windows().pushWindow(temp);
} }
else else
@ -1007,7 +1007,7 @@ void CPlayerInterface::showYesNoDialog(const std::string &text, CFunctionList<vo
{ {
boost::unique_lock<boost::recursive_mutex> un(*pim); boost::unique_lock<boost::recursive_mutex> un(*pim);
movementController->movementAbortRequested(); movementController->requestMovementAbort();
LOCPLINT->showingDialog->setn(true); LOCPLINT->showingDialog->setn(true);
CInfoWindow::showYesNoDialog(text, components, onYes, onNo, playerID); CInfoWindow::showYesNoDialog(text, components, onYes, onNo, playerID);
} }
@ -1017,7 +1017,7 @@ void CPlayerInterface::showBlockingDialog( const std::string &text, const std::v
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
waitWhileDialog(); waitWhileDialog();
movementController->movementAbortRequested(); movementController->requestMovementAbort();
CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID)); CCS->soundh->playSound(static_cast<soundBase::soundID>(soundID));
if (!selection && cancel) //simple yes/no dialog if (!selection && cancel) //simple yes/no dialog
@ -1182,7 +1182,7 @@ void CPlayerInterface::moveHero( const CGHeroInstance *h, const CGPath& path )
if (localState->isHeroSleeping(h)) if (localState->isHeroSleeping(h))
localState->setHeroAwaken(h); localState->setHeroAwaken(h);
movementController->movementStartRequested(h, path); movementController->requestMovementStart(h, path);
} }
void CPlayerInterface::showGarrisonDialog( const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, QueryID queryID) void CPlayerInterface::showGarrisonDialog( const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, QueryID queryID)

View File

@ -60,11 +60,17 @@ void HeroMovementController::onBattleStarted()
// when battle starts, game will send battleStart pack *before* movement confirmation // when battle starts, game will send battleStart pack *before* movement confirmation
// and since network thread wait for battle intro to play, movement confirmation will only happen after intro // and since network thread wait for battle intro to play, movement confirmation will only happen after intro
// leading to several bugs, such as blocked input during intro // leading to several bugs, such as blocked input during intro
movementAbortRequested(); requestMovementAbort();
} }
void HeroMovementController::showTeleportDialog(const CGHeroInstance * hero, TeleportChannelID channel, TTeleportExitsList exits, bool impassable, QueryID askID) void HeroMovementController::showTeleportDialog(const CGHeroInstance * hero, TeleportChannelID channel, TTeleportExitsList exits, bool impassable, QueryID askID)
{ {
if (impassable || exits.empty()) //FIXME: why we even have this dialog in such case?
{
LOCPLINT->cb->selectionMade(-1, askID);
return;
}
// Player entered teleporter // Player entered teleporter
// Check whether hero that has entered teleporter has paths that goes through teleporter and select appropriate exit // Check whether hero that has entered teleporter has paths that goes through teleporter and select appropriate exit
// othervice, ask server to select one randomly by sending invalid (-1) value as answer // othervice, ask server to select one randomly by sending invalid (-1) value as answer
@ -139,7 +145,7 @@ void HeroMovementController::updatePath(const CGHeroInstance * hero, const TryMo
} }
} }
void HeroMovementController::heroMoved(const CGHeroInstance * hero, const TryMoveHero & details) void HeroMovementController::onTryMoveHero(const CGHeroInstance * hero, const TryMoveHero & details)
{ {
// Server initiated movement -> start movement animation // Server initiated movement -> start movement animation
// Note that this movement is not necessarily of owned heroes - other players movement will also pass through this method // Note that this movement is not necessarily of owned heroes - other players movement will also pass through this method
@ -167,7 +173,7 @@ void HeroMovementController::heroMoved(const CGHeroInstance * hero, const TryMov
if(details.stopMovement()) if(details.stopMovement())
{ {
if(duringMovement) if(duringMovement)
endHeroMove(hero); endMove(hero);
return; return;
} }
@ -233,27 +239,23 @@ void HeroMovementController::onMoveHeroApplied()
bool wantStop = stoppingMovement; bool wantStop = stoppingMovement;
bool canStop = !canMove || canHeroStopAtNode(LOCPLINT->localState->getPath(hero).currNode()); bool canStop = !canMove || canHeroStopAtNode(LOCPLINT->localState->getPath(hero).currNode());
if(!canMove) if(!canMove || (wantStop && canStop))
{ {
endHeroMove(hero); endMove(hero);
}
else if(wantStop && canStop)
{
endHeroMove(hero);
} }
else else
{ {
moveHeroOnce(hero, LOCPLINT->localState->getPath(hero)); moveOnce(hero, LOCPLINT->localState->getPath(hero));
} }
} }
void HeroMovementController::movementAbortRequested() void HeroMovementController::requestMovementAbort()
{ {
if(duringMovement) if(duringMovement)
endHeroMove(currentlyMovingHero); endMove(currentlyMovingHero);
} }
void HeroMovementController::endHeroMove(const CGHeroInstance * hero) void HeroMovementController::endMove(const CGHeroInstance * hero)
{ {
assert(duringMovement == true); assert(duringMovement == true);
assert(currentlyMovingHero != nullptr); assert(currentlyMovingHero != nullptr);
@ -331,17 +333,17 @@ bool HeroMovementController::canHeroStopAtNode(const CGPathNode & node) const
return true; return true;
} }
void HeroMovementController::movementStartRequested(const CGHeroInstance * h, const CGPath & path) void HeroMovementController::requestMovementStart(const CGHeroInstance * h, const CGPath & path)
{ {
assert(duringMovement == false); assert(duringMovement == false);
duringMovement = true; duringMovement = true;
currentlyMovingHero = h; currentlyMovingHero = h;
CCS->curh->hide(); CCS->curh->hide();
moveHeroOnce(h, path); moveOnce(h, path);
} }
void HeroMovementController::moveHeroOnce(const CGHeroInstance * h, const CGPath & path) void HeroMovementController::moveOnce(const CGHeroInstance * h, const CGPath & path)
{ {
// Moves hero once, sends request to server and immediately returns // Moves hero once, sends request to server and immediately returns
// movement alongside paths will be done on receiving response from server // movement alongside paths will be done on receiving response from server

View File

@ -43,9 +43,9 @@ class HeroMovementController
void updatePath(const CGHeroInstance * hero, const TryMoveHero & details); void updatePath(const CGHeroInstance * hero, const TryMoveHero & details);
/// Moves hero 1 tile / path node /// Moves hero 1 tile / path node
void moveHeroOnce(const CGHeroInstance * h, const CGPath & path); void moveOnce(const CGHeroInstance * h, const CGPath & path);
void endHeroMove(const CGHeroInstance * h); void endMove(const CGHeroInstance * h);
AudioPath getMovementSoundFor(const CGHeroInstance * hero, int3 posPrev, int3 posNext, EPathNodeAction moveType); AudioPath getMovementSoundFor(const CGHeroInstance * hero, int3 posPrev, int3 posNext, EPathNodeAction moveType);
void updateMovementSound(const CGHeroInstance * hero, int3 posPrev, int3 posNext, EPathNodeAction moveType); void updateMovementSound(const CGHeroInstance * hero, int3 posPrev, int3 posNext, EPathNodeAction moveType);
@ -66,9 +66,9 @@ public:
void onPlayerTurnStarted(); void onPlayerTurnStarted();
void onBattleStarted(); void onBattleStarted();
void showTeleportDialog(const CGHeroInstance * hero, TeleportChannelID channel, TTeleportExitsList exits, bool impassable, QueryID askID); void showTeleportDialog(const CGHeroInstance * hero, TeleportChannelID channel, TTeleportExitsList exits, bool impassable, QueryID askID);
void heroMoved(const CGHeroInstance * hero, const TryMoveHero & details); void onTryMoveHero(const CGHeroInstance * hero, const TryMoveHero & details);
// UI handlers // UI handlers
void movementStartRequested(const CGHeroInstance * h, const CGPath & path); void requestMovementStart(const CGHeroInstance * h, const CGPath & path);
void movementAbortRequested(); void requestMovementAbort();
}; };

View File

@ -1139,7 +1139,7 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, boo
if(h->movementPointsRemaining() < cost && dst != h->pos && !teleporting) if(h->movementPointsRemaining() < cost && dst != h->pos && !teleporting)
complainRet("Hero doesn't have any movement points left!"); complainRet("Hero doesn't have any movement points left!");
if (transit && !canFly && !CGTeleport::isTeleport(t.topVisitableObj())) if (transit && !canFly && !(canWalkOnSea && t.terType->isWater()))
complainRet("Hero cannot transit over this tile!"); complainRet("Hero cannot transit over this tile!");
//several generic blocks of code //several generic blocks of code
@ -1259,7 +1259,7 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, boo
if (CGTeleport::isTeleport(t.topVisitableObj())) if (CGTeleport::isTeleport(t.topVisitableObj()))
visitDest = DONT_VISIT_DEST; visitDest = DONT_VISIT_DEST;
if (canFly) if (canFly || (canWalkOnSea && t.terType->isWater()))
{ {
lookForGuards = IGNORE_GUARDS; lookForGuards = IGNORE_GUARDS;
visitDest = DONT_VISIT_DEST; visitDest = DONT_VISIT_DEST;