mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Add logging to trace crash
This commit is contained in:
@@ -405,7 +405,10 @@ std::optional<BattleAction> CBattleCallback::makeSurrenderRetreatDecision(const
|
|||||||
|
|
||||||
std::shared_ptr<CPlayerBattleCallback> CBattleCallback::getBattle(const BattleID & battleID)
|
std::shared_ptr<CPlayerBattleCallback> CBattleCallback::getBattle(const BattleID & battleID)
|
||||||
{
|
{
|
||||||
|
if (activeBattles.count(battleID))
|
||||||
return activeBattles.at(battleID);
|
return activeBattles.at(battleID);
|
||||||
|
|
||||||
|
throw std::runtime_error("Failed to find battle " + std::to_string(battleID.getNum()) + " of player " + player->toString() + ". Number of ongoing battles: " + std::to_string(activeBattles.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<PlayerColor> CBattleCallback::getPlayerID() const
|
std::optional<PlayerColor> CBattleCallback::getPlayerID() const
|
||||||
@@ -415,10 +418,18 @@ std::optional<PlayerColor> CBattleCallback::getPlayerID() const
|
|||||||
|
|
||||||
void CBattleCallback::onBattleStarted(const IBattleInfo * info)
|
void CBattleCallback::onBattleStarted(const IBattleInfo * info)
|
||||||
{
|
{
|
||||||
|
if (activeBattles.count(info->getBattleID()) > 0)
|
||||||
|
throw std::runtime_error("Player " + player->toString() + " is already engaged in battle " + std::to_string(info->getBattleID().getNum()));
|
||||||
|
|
||||||
|
logGlobal->debug("Battle %d started for player %s", info->getBattleID(), player->toString());
|
||||||
activeBattles[info->getBattleID()] = std::make_shared<CPlayerBattleCallback>(info, *getPlayerID());
|
activeBattles[info->getBattleID()] = std::make_shared<CPlayerBattleCallback>(info, *getPlayerID());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBattleCallback::onBattleEnded(const BattleID & battleID)
|
void CBattleCallback::onBattleEnded(const BattleID & battleID)
|
||||||
{
|
{
|
||||||
|
if (activeBattles.count(battleID) == 0)
|
||||||
|
throw std::runtime_error("Player " + player->toString() + " is not engaged in battle " + std::to_string(battleID.getNum()));
|
||||||
|
|
||||||
|
logGlobal->debug("Battle %d ended for player %s", battleID, player->toString());
|
||||||
activeBattles.erase(battleID);
|
activeBattles.erase(battleID);
|
||||||
}
|
}
|
||||||
|
@@ -560,17 +560,15 @@ int CClient::sendRequest(const CPackForServer * request, PlayerColor player)
|
|||||||
|
|
||||||
void CClient::battleStarted(const BattleInfo * info)
|
void CClient::battleStarted(const BattleInfo * info)
|
||||||
{
|
{
|
||||||
|
std::shared_ptr<CPlayerInterface> att, def;
|
||||||
|
auto & leftSide = info->sides[0];
|
||||||
|
auto & rightSide = info->sides[1];
|
||||||
|
|
||||||
for(auto & battleCb : battleCallbacks)
|
for(auto & battleCb : battleCallbacks)
|
||||||
{
|
{
|
||||||
if(vstd::contains_if(info->sides, [&](const SideInBattle& side) {return side.color == battleCb.first; })
|
if(!battleCb.first.isValidPlayer() || battleCb.first == leftSide.color || battleCb.first == rightSide.color)
|
||||||
|| !battleCb.first.isValidPlayer())
|
|
||||||
{
|
|
||||||
battleCb.second->onBattleStarted(info);
|
battleCb.second->onBattleStarted(info);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<CPlayerInterface> att, def;
|
|
||||||
auto & leftSide = info->sides[0], & rightSide = info->sides[1];
|
|
||||||
|
|
||||||
//If quick combat is not, do not prepare interfaces for battleint
|
//If quick combat is not, do not prepare interfaces for battleint
|
||||||
auto callBattleStart = [&](PlayerColor color, ui8 side)
|
auto callBattleStart = [&](PlayerColor color, ui8 side)
|
||||||
|
Reference in New Issue
Block a user