mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-03 13:01:33 +02:00
Reodered methods in file to group similar code
This commit is contained in:
parent
7db67a3101
commit
20de44d4a5
@ -248,6 +248,33 @@ void CPlayerInterface::initGameInterface(std::shared_ptr<Environment> 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<CInfoWindow*>(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<CInfoWindow *>(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<Component> 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<CInfoWindow *>(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<Component> 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<CInfoWindow*>(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())
|
||||
|
@ -984,11 +984,6 @@ bool CAdventureMapInterface::isActive()
|
||||
return active & ~CIntObject::KEYBOARD;
|
||||
}
|
||||
|
||||
void CAdventureMapInterface::startHotSeatWait(PlayerColor Player)
|
||||
{
|
||||
state = EGameStates::WAITING;
|
||||
}
|
||||
|
||||
void CAdventureMapInterface::onMapTilesChanged(boost::optional<std::unordered_set<int3>> positions)
|
||||
{
|
||||
if (positions)
|
||||
@ -997,6 +992,35 @@ void CAdventureMapInterface::onMapTilesChanged(boost::optional<std::unordered_se
|
||||
minimap->update();
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -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
|
||||
|
23
lib/int3.h
23
lib/int3.h
@ -182,17 +182,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct std::hash<int3> {
|
||||
size_t operator()(int3 const& pos) const
|
||||
{
|
||||
size_t ret = std::hash<int>()(pos.x);
|
||||
vstd::hash_combine(ret, pos.y);
|
||||
vstd::hash_combine(ret, pos.z);
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Container>
|
||||
int3 findClosestTile (Container & container, int3 dest)
|
||||
{
|
||||
@ -214,3 +203,15 @@ int3 findClosestTile (Container & container, int3 dest)
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
|
||||
template<>
|
||||
struct std::hash<VCMI_LIB_WRAP_NAMESPACE(int3)> {
|
||||
size_t operator()(VCMI_LIB_WRAP_NAMESPACE(int3) const& pos) const
|
||||
{
|
||||
size_t ret = std::hash<int>()(pos.x);
|
||||
VCMI_LIB_WRAP_NAMESPACE(vstd)::hash_combine(ret, pos.y);
|
||||
VCMI_LIB_WRAP_NAMESPACE(vstd)::hash_combine(ret, pos.z);
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user