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"
|
|
|
|
|
|
|
|
#include "../CGameHandler.h"
|
|
|
|
#include "../battles/BattleProcessor.h"
|
|
|
|
|
2023-08-28 16:43:57 +02:00
|
|
|
#include "../../lib/battle/IBattleState.h"
|
2023-07-23 23:46:29 +02:00
|
|
|
|
|
|
|
void CBattleQuery::notifyObjectAboutRemoval(const CObjectVisitQuery & objectVisit) const
|
|
|
|
{
|
|
|
|
if(result)
|
|
|
|
objectVisit.visitedObject->battleFinished(objectVisit.visitingHero, *result);
|
|
|
|
}
|
|
|
|
|
2023-08-28 16:43:57 +02:00
|
|
|
CBattleQuery::CBattleQuery(CGameHandler * owner, const IBattleInfo * bi):
|
|
|
|
CGhQuery(owner),
|
|
|
|
bi(bi)
|
2023-07-23 23:46:29 +02:00
|
|
|
{
|
2023-08-28 16:43:57 +02:00
|
|
|
belligerents[0] = bi->getSideArmy(0);
|
|
|
|
belligerents[1] = bi->getSideArmy(1);
|
2023-07-23 23:46:29 +02:00
|
|
|
|
2023-08-28 16:43:57 +02:00
|
|
|
addPlayer(bi->getSidePlayer(0));
|
|
|
|
addPlayer(bi->getSidePlayer(1));
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CBattleQuery::CBattleQuery(CGameHandler * owner):
|
|
|
|
CGhQuery(owner), bi(nullptr)
|
|
|
|
{
|
|
|
|
belligerents[0] = belligerents[1] = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CBattleQuery::blocksPack(const CPack * pack) const
|
|
|
|
{
|
|
|
|
const char * name = typeid(*pack).name();
|
2023-08-16 23:51:50 +02:00
|
|
|
return strcmp(name, typeid(MakeAction).name()) != 0;
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBattleQuery::onRemoval(PlayerColor color)
|
|
|
|
{
|
|
|
|
if(result)
|
2023-08-28 16:43:57 +02:00
|
|
|
gh->battles->battleAfterLevelUp(bi->getBattleID(), *result);
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
|
2023-08-28 16:43:57 +02:00
|
|
|
CBattleDialogQuery::CBattleDialogQuery(CGameHandler * owner, const IBattleInfo * bi):
|
|
|
|
CDialogQuery(owner),
|
|
|
|
bi(bi)
|
2023-07-23 23:46:29 +02:00
|
|
|
{
|
2023-08-28 16:43:57 +02:00
|
|
|
addPlayer(bi->getSidePlayer(0));
|
|
|
|
addPlayer(bi->getSidePlayer(1));
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBattleDialogQuery::onRemoval(PlayerColor color)
|
|
|
|
{
|
|
|
|
assert(answer);
|
|
|
|
if(*answer == 1)
|
|
|
|
{
|
2023-08-28 16:43:57 +02:00
|
|
|
gh->startBattlePrimary(
|
|
|
|
bi->getSideArmy(0),
|
|
|
|
bi->getSideArmy(1),
|
|
|
|
bi->getLocation(),
|
|
|
|
bi->getSideHero(0),
|
|
|
|
bi->getSideHero(1),
|
|
|
|
bi->isCreatureBank(),
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|