diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 29cb9bd67..ec4e89c34 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -248,6 +248,33 @@ void CPlayerInterface::initGameInterface(std::shared_ptr ENV, std:: // always recreate advmap interface to avoid possible memory-corruption bugs adventureInt.reset(new CAdventureMapInterface()); } + +void CPlayerInterface::playerStartsTurn(PlayerColor player) +{ + EVENT_HANDLER_CALLED_BY_CLIENT; + if (!vstd::contains (GH.listInt, adventureInt)) + { + GH.popInts ((int)GH.listInt.size()); //after map load - remove everything else + GH.pushInt (adventureInt); + } + else + { + while (GH.listInt.front() != adventureInt && !dynamic_cast(GH.listInt.front().get())) //don't remove dialogs that expect query answer + GH.popInts(1); + } + + if(CSH->howManyPlayerInterfaces() == 1) + { + GH.curInt = this; + adventureInt->startTurn(); + } + if (player != playerID && this == LOCPLINT) + { + waitWhileDialog(); + adventureInt->aiTurnStarted(); + } +} + void CPlayerInterface::yourTurn() { EVENT_HANDLER_CALLED_BY_CLIENT; @@ -301,10 +328,59 @@ void CPlayerInterface::yourTurn() adventureInt->startTurn(); } } - acceptTurn(); } +void CPlayerInterface::acceptTurn() +{ + if (settings["session"]["autoSkip"].Bool()) + { + while(CInfoWindow *iw = dynamic_cast(GH.topInt().get())) + iw->close(); + } + + if(CSH->howManyPlayerInterfaces() > 1) + { + waitWhileDialog(); // wait for player to accept turn in hot-seat mode + + adventureInt->startTurn(); + } + + adventureInt->initializeNewTurn(); + + // warn player if he has no town + if (cb->howManyTowns() == 0) + { + auto playerColor = *cb->getPlayerID(); + + std::vector components; + components.emplace_back(Component::EComponentType::FLAG, playerColor.getNum(), 0, 0); + MetaString text; + + const auto & optDaysWithoutCastle = cb->getPlayerState(playerColor)->daysWithoutCastle; + + if(optDaysWithoutCastle) + { + auto daysWithoutCastle = optDaysWithoutCastle.value(); + if (daysWithoutCastle < 6) + { + text.addTxt(MetaString::ARRAY_TXT,128); //%s, you only have %d days left to capture a town or you will be banished from this land. + text.addReplacement(MetaString::COLOR, playerColor.getNum()); + text.addReplacement(7 - daysWithoutCastle); + } + else if (daysWithoutCastle == 6) + { + text.addTxt(MetaString::ARRAY_TXT,129); //%s, this is your last day to capture a town or you will be banished from this land. + text.addReplacement(MetaString::COLOR, playerColor.getNum()); + } + + showInfoDialogAndWait(components, text); + } + else + logGlobal->warn("Player has no towns, but daysWithoutCastle is not set"); + } +} + void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose) { EVENT_HANDLER_CALLED_BY_CLIENT; @@ -1685,56 +1761,6 @@ void CPlayerInterface::advmapSpellCast(const CGHeroInstance * caster, int spellI CCS->soundh->playSound(castSoundPath); } -void CPlayerInterface::acceptTurn() -{ - if (settings["session"]["autoSkip"].Bool()) - { - while(CInfoWindow *iw = dynamic_cast(GH.topInt().get())) - iw->close(); - } - - if(CSH->howManyPlayerInterfaces() > 1) - { - waitWhileDialog(); // wait for player to accept turn in hot-seat mode - - adventureInt->startTurn(); - } - - adventureInt->initializeNewTurn(); - - // warn player if he has no town - if (cb->howManyTowns() == 0) - { - auto playerColor = *cb->getPlayerID(); - - std::vector components; - components.emplace_back(Component::EComponentType::FLAG, playerColor.getNum(), 0, 0); - MetaString text; - - const auto & optDaysWithoutCastle = cb->getPlayerState(playerColor)->daysWithoutCastle; - - if(optDaysWithoutCastle) - { - auto daysWithoutCastle = optDaysWithoutCastle.value(); - if (daysWithoutCastle < 6) - { - text.addTxt(MetaString::ARRAY_TXT,128); //%s, you only have %d days left to capture a town or you will be banished from this land. - text.addReplacement(MetaString::COLOR, playerColor.getNum()); - text.addReplacement(7 - daysWithoutCastle); - } - else if (daysWithoutCastle == 6) - { - text.addTxt(MetaString::ARRAY_TXT,129); //%s, this is your last day to capture a town or you will be banished from this land. - text.addReplacement(MetaString::COLOR, playerColor.getNum()); - } - - showInfoDialogAndWait(components, text); - } - else - logGlobal->warn("Player has no towns, but daysWithoutCastle is not set"); - } -} - void CPlayerInterface::tryDiggging(const CGHeroInstance * h) { int msgToShow = -1; @@ -1948,32 +1974,6 @@ void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al) } } -void CPlayerInterface::playerStartsTurn(PlayerColor player) -{ - EVENT_HANDLER_CALLED_BY_CLIENT; - if (!vstd::contains (GH.listInt, adventureInt)) - { - GH.popInts ((int)GH.listInt.size()); //after map load - remove everything else - GH.pushInt (adventureInt); - } - else - { - while (GH.listInt.front() != adventureInt && !dynamic_cast(GH.listInt.front().get())) //don't remove dialogs that expect query answer - GH.popInts(1); - } - - if(CSH->howManyPlayerInterfaces() == 1) - { - GH.curInt = this; - adventureInt->startTurn(); - } - if (player != playerID && this == LOCPLINT) - { - waitWhileDialog(); - adventureInt->aiTurnStarted(); - } -} - void CPlayerInterface::waitForAllDialogs(bool unlockPim) { while(!dialogs.empty()) diff --git a/client/adventureMap/CAdventureMapInterface.cpp b/client/adventureMap/CAdventureMapInterface.cpp index 7406a7ccd..a938555ee 100644 --- a/client/adventureMap/CAdventureMapInterface.cpp +++ b/client/adventureMap/CAdventureMapInterface.cpp @@ -984,11 +984,6 @@ bool CAdventureMapInterface::isActive() return active & ~CIntObject::KEYBOARD; } -void CAdventureMapInterface::startHotSeatWait(PlayerColor Player) -{ - state = EGameStates::WAITING; -} - void CAdventureMapInterface::onMapTilesChanged(boost::optional> positions) { if (positions) @@ -997,6 +992,35 @@ void CAdventureMapInterface::onMapTilesChanged(boost::optionalupdate(); } +void CAdventureMapInterface::startHotSeatWait(PlayerColor Player) +{ + state = EGameStates::WAITING; +} + +void CAdventureMapInterface::aiTurnStarted() +{ + if(settings["session"]["spectate"].Bool()) + return; + + adjustActiveness(true); + mapAudio->onEnemyTurnStarted(); + adventureInt->minimap->setAIRadar(true); + adventureInt->infoBar->startEnemyTurn(LOCPLINT->cb->getCurrentPlayer()); + adventureInt->minimap->showAll(screen);//force refresh on inactive object + adventureInt->infoBar->showAll(screen);//force refresh on inactive object +} + +void CAdventureMapInterface::adjustActiveness(bool aiTurnStart) +{ + bool wasActive = isActive(); + + if(wasActive) + deactivate(); + adventureInt->duringAITurn = aiTurnStart; + if(wasActive) + activate(); +} + void CAdventureMapInterface::onCurrentPlayerChanged(PlayerColor Player) { selection = nullptr; @@ -1438,30 +1462,6 @@ const IShipyard * CAdventureMapInterface::ourInaccessibleShipyard(const CGObject return ret; } -void CAdventureMapInterface::aiTurnStarted() -{ - if(settings["session"]["spectate"].Bool()) - return; - - adjustActiveness(true); - mapAudio->onEnemyTurnStarted(); - adventureInt->minimap->setAIRadar(true); - adventureInt->infoBar->startEnemyTurn(LOCPLINT->cb->getCurrentPlayer()); - adventureInt->minimap->showAll(screen);//force refresh on inactive object - adventureInt->infoBar->showAll(screen);//force refresh on inactive object -} - -void CAdventureMapInterface::adjustActiveness(bool aiTurnStart) -{ - bool wasActive = isActive(); - - if(wasActive) - deactivate(); - adventureInt->duringAITurn = aiTurnStart; - if(wasActive) - activate(); -} - void CAdventureMapInterface::exitWorldView() { mode = EAdvMapMode::NORMAL; diff --git a/client/adventureMap/CAdventureMapInterface.h b/client/adventureMap/CAdventureMapInterface.h index da4a618d3..2f2d86c75 100644 --- a/client/adventureMap/CAdventureMapInterface.h +++ b/client/adventureMap/CAdventureMapInterface.h @@ -185,7 +185,7 @@ public: /// Called by PlayerInterface when town state changed and town list must be updated void onTownChanged(const CGTownInstance * town); - /// Called when map audio should be paused, e.g. on combat or town scren access + /// Called when map audio should be paused, e.g. on combat or town screen access void onAudioPaused(); /// Called when map audio should be resume, opposite to onPaused diff --git a/lib/int3.h b/lib/int3.h index 8d5b51854..aa060703a 100644 --- a/lib/int3.h +++ b/lib/int3.h @@ -182,17 +182,6 @@ public: } }; -template<> -struct std::hash { - size_t operator()(int3 const& pos) const - { - size_t ret = std::hash()(pos.x); - vstd::hash_combine(ret, pos.y); - vstd::hash_combine(ret, pos.z); - return ret; - } -}; - template int3 findClosestTile (Container & container, int3 dest) { @@ -214,3 +203,15 @@ int3 findClosestTile (Container & container, int3 dest) } VCMI_LIB_NAMESPACE_END + + +template<> +struct std::hash { + size_t operator()(VCMI_LIB_WRAP_NAMESPACE(int3) const& pos) const + { + size_t ret = std::hash()(pos.x); + VCMI_LIB_WRAP_NAMESPACE(vstd)::hash_combine(ret, pos.y); + VCMI_LIB_WRAP_NAMESPACE(vstd)::hash_combine(ret, pos.z); + return ret; + } +};