2023-07-23 23:46:29 +02:00
|
|
|
/*
|
|
|
|
* BattleQueries.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "BattleQueries.h"
|
|
|
|
#include "MapQueries.h"
|
2023-09-05 16:22:11 +02:00
|
|
|
#include "QueriesProcessor.h"
|
2023-07-23 23:46:29 +02:00
|
|
|
|
|
|
|
#include "../CGameHandler.h"
|
|
|
|
#include "../battles/BattleProcessor.h"
|
|
|
|
|
2023-08-28 16:43:57 +02:00
|
|
|
#include "../../lib/battle/IBattleState.h"
|
2024-01-26 00:44:41 +02:00
|
|
|
#include "../../lib/battle/SideInBattle.h"
|
2024-08-31 23:04:32 +02:00
|
|
|
#include "../../lib/battle/BattleLayout.h"
|
2024-01-26 00:44:41 +02:00
|
|
|
#include "../../lib/CPlayerState.h"
|
2023-10-23 12:59:15 +02:00
|
|
|
#include "../../lib/mapObjects/CGObjectInstance.h"
|
2024-02-28 23:25:14 +02:00
|
|
|
#include "../../lib/mapObjects/CGTownInstance.h"
|
2023-10-23 12:59:15 +02:00
|
|
|
#include "../../lib/networkPacks/PacksForServer.h"
|
2023-07-23 23:46:29 +02:00
|
|
|
|
2024-09-04 16:17:22 +02:00
|
|
|
void CBattleQuery::notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const
|
2024-03-04 21:34:43 +02:00
|
|
|
{
|
|
|
|
assert(result);
|
|
|
|
|
2024-06-01 12:06:16 +02:00
|
|
|
if(result)
|
2024-09-04 16:17:22 +02:00
|
|
|
visitedObject->battleFinished(visitingHero, *result);
|
2024-03-04 21:34:43 +02:00
|
|
|
}
|
|
|
|
|
2023-08-28 16:43:57 +02:00
|
|
|
CBattleQuery::CBattleQuery(CGameHandler * owner, const IBattleInfo * bi):
|
2023-09-19 22:17:25 +02:00
|
|
|
CQuery(owner),
|
2023-08-31 17:45:52 +02:00
|
|
|
battleID(bi->getBattleID())
|
2023-07-23 23:46:29 +02:00
|
|
|
{
|
2024-08-11 22:22:35 +02:00
|
|
|
belligerents[BattleSide::ATTACKER] = bi->getSideArmy(BattleSide::ATTACKER);
|
|
|
|
belligerents[BattleSide::DEFENDER] = bi->getSideArmy(BattleSide::DEFENDER);
|
2023-07-23 23:46:29 +02:00
|
|
|
|
2024-08-11 22:22:35 +02:00
|
|
|
addPlayer(bi->getSidePlayer(BattleSide::ATTACKER));
|
|
|
|
addPlayer(bi->getSidePlayer(BattleSide::DEFENDER));
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CBattleQuery::CBattleQuery(CGameHandler * owner):
|
2023-09-19 22:17:25 +02:00
|
|
|
CQuery(owner)
|
2023-07-23 23:46:29 +02:00
|
|
|
{
|
2024-08-11 22:22:35 +02:00
|
|
|
belligerents[BattleSide::ATTACKER] = nullptr;
|
|
|
|
belligerents[BattleSide::DEFENDER] = nullptr;
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
|
2024-10-04 15:41:53 +02:00
|
|
|
bool CBattleQuery::blocksPack(const CPackForServer * pack) const
|
2023-07-23 23:46:29 +02:00
|
|
|
{
|
2024-09-04 16:32:36 +02:00
|
|
|
if(dynamic_cast<const MakeAction*>(pack) != nullptr)
|
2023-11-27 20:06:02 +02:00
|
|
|
return false;
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(dynamic_cast<const GamePause*>(pack) != nullptr)
|
2023-11-27 20:06:02 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBattleQuery::onRemoval(PlayerColor color)
|
|
|
|
{
|
2023-09-05 16:22:11 +02:00
|
|
|
assert(result);
|
|
|
|
|
2023-07-23 23:46:29 +02:00
|
|
|
if(result)
|
2023-08-31 17:45:52 +02:00
|
|
|
gh->battles->battleAfterLevelUp(battleID, *result);
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
|
2023-09-05 16:22:11 +02:00
|
|
|
void CBattleQuery::onExposure(QueryPtr topQuery)
|
|
|
|
{
|
|
|
|
// this method may be called in two cases:
|
|
|
|
// 1) when requesting battle replay (but before replay starts -> no valid result)
|
|
|
|
// 2) when aswering on levelup queries after accepting battle result -> valid result
|
|
|
|
if(result)
|
|
|
|
owner->popQuery(*this);
|
|
|
|
}
|
|
|
|
|
2024-02-28 23:25:14 +02:00
|
|
|
CBattleDialogQuery::CBattleDialogQuery(CGameHandler * owner, const IBattleInfo * bi, std::optional<BattleResult> Br):
|
2023-08-28 16:43:57 +02:00
|
|
|
CDialogQuery(owner),
|
2024-02-28 23:25:14 +02:00
|
|
|
bi(bi),
|
|
|
|
result(Br)
|
2023-07-23 23:46:29 +02:00
|
|
|
{
|
2024-08-11 22:22:35 +02:00
|
|
|
addPlayer(bi->getSidePlayer(BattleSide::ATTACKER));
|
|
|
|
addPlayer(bi->getSidePlayer(BattleSide::DEFENDER));
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBattleDialogQuery::onRemoval(PlayerColor color)
|
|
|
|
{
|
2024-06-01 12:06:16 +02:00
|
|
|
// answer to this query was already processed when handling 1st player
|
|
|
|
// this removal call for 2nd player which can be safely ignored
|
|
|
|
if (resultProcessed)
|
2024-01-26 00:44:41 +02:00
|
|
|
return;
|
|
|
|
|
2023-07-23 23:46:29 +02:00
|
|
|
assert(answer);
|
|
|
|
if(*answer == 1)
|
|
|
|
{
|
2024-08-31 23:04:32 +02:00
|
|
|
gh->battles->restartBattle(
|
2023-09-05 16:22:11 +02:00
|
|
|
bi->getBattleID(),
|
2024-08-11 22:22:35 +02:00
|
|
|
bi->getSideArmy(BattleSide::ATTACKER),
|
|
|
|
bi->getSideArmy(BattleSide::DEFENDER),
|
2023-08-28 16:43:57 +02:00
|
|
|
bi->getLocation(),
|
2024-08-11 22:22:35 +02:00
|
|
|
bi->getSideHero(BattleSide::ATTACKER),
|
|
|
|
bi->getSideHero(BattleSide::DEFENDER),
|
2024-08-31 23:04:32 +02:00
|
|
|
bi->getLayout(),
|
2023-08-28 16:43:57 +02:00
|
|
|
bi->getDefendedTown()
|
|
|
|
);
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-28 16:43:57 +02:00
|
|
|
gh->battles->endBattleConfirm(bi->getBattleID());
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
2024-06-01 12:06:16 +02:00
|
|
|
resultProcessed = true;
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|