1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Allow dismissing hero from town

This commit is contained in:
Ivan Savenko
2023-07-15 16:04:54 +03:00
parent 3e8debc243
commit 8129cbc514
3 changed files with 18 additions and 5 deletions

View File

@@ -398,7 +398,10 @@ void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
EVENT_HANDLER_CALLED_BY_CLIENT;
LOG_TRACE_PARAMS(logGlobal, "Hero %s killed handler for player %s", hero->getNameTranslated() % playerID);
localState->removeWanderingHero(hero);
// if hero is not in town garrison
if (vstd::contains(localState->getWanderingHeroes(), hero))
localState->removeWanderingHero(hero);
adventureInt->onHeroChanged(hero);
localState->erasePath(hero);
@@ -1482,6 +1485,10 @@ void CPlayerInterface::objectRemovedAfter()
{
EVENT_HANDLER_CALLED_BY_CLIENT;
adventureInt->onMapTilesChanged(boost::none);
// visiting or garrisoned hero removed - recreate castle window
if (castleInt)
openTownWindow(castleInt->town);
}
void CPlayerInterface::playerBlocked(int reason, bool start)

View File

@@ -326,9 +326,6 @@ void CHeroWindow::update(const CGHeroInstance * hero, bool redrawNeeded)
if(curHero->isMissionCritical())
noDismiss = true;
if (curHero->visitedTown)
noDismiss = true;
dismissButton->block(noDismiss);
if(curHero->valOfBonuses(Selector::type()(BonusType::BEFORE_BATTLE_REPOSITION)) == 0)

View File

@@ -1132,7 +1132,16 @@ void RemoveObject::applyGs(CGameState *gs)
PlayerState * p = gs->getPlayerState(beatenHero->tempOwner);
gs->map->heroesOnMap -= beatenHero;
p->heroes -= beatenHero;
beatenHero->detachFrom(*beatenHero->whereShouldBeAttachedOnSiege(gs));
auto * siegeNode = beatenHero->whereShouldBeAttachedOnSiege(gs);
// FIXME: workaround:
// hero should be attached to siegeNode after battle
// however this code might also be called on dismissing hero while in town
if (siegeNode && vstd::contains(beatenHero->getParentNodes(), siegeNode))
beatenHero->detachFrom(*siegeNode);
beatenHero->tempOwner = PlayerColor::NEUTRAL; //no one owns beaten hero
vstd::erase_if(beatenHero->artifactsInBackpack, [](const ArtSlotInfo& asi)
{