2023-07-23 23:46:29 +02:00
|
|
|
/*
|
|
|
|
* MapQueries.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 "MapQueries.h"
|
|
|
|
|
|
|
|
#include "QueriesProcessor.h"
|
|
|
|
#include "../CGameHandler.h"
|
2024-04-26 12:26:33 +02:00
|
|
|
#include "../TurnTimerHandler.h"
|
2023-10-23 12:59:15 +02:00
|
|
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
2024-09-04 16:32:36 +02:00
|
|
|
#include "../../lib/mapObjects/MiscObjects.h"
|
2023-10-23 12:59:15 +02:00
|
|
|
#include "../../lib/networkPacks/PacksForServer.h"
|
2023-07-23 23:46:29 +02:00
|
|
|
|
2023-10-07 01:44:37 +02:00
|
|
|
TimerPauseQuery::TimerPauseQuery(CGameHandler * owner, PlayerColor player):
|
2023-09-19 22:17:25 +02:00
|
|
|
CQuery(owner)
|
2023-08-28 02:42:05 +02:00
|
|
|
{
|
|
|
|
addPlayer(player);
|
|
|
|
}
|
|
|
|
|
2024-10-04 15:41:53 +02:00
|
|
|
bool TimerPauseQuery::blocksPack(const CPackForServer *pack) const
|
2023-08-28 02:42:05 +02:00
|
|
|
{
|
|
|
|
return blockAllButReply(pack);
|
|
|
|
}
|
|
|
|
|
2023-10-07 01:44:37 +02:00
|
|
|
void TimerPauseQuery::onAdding(PlayerColor color)
|
2023-08-28 02:42:05 +02:00
|
|
|
{
|
2024-04-26 12:15:39 +02:00
|
|
|
gh->turnTimerHandler->setTimerEnabled(color, false);
|
2023-08-28 02:42:05 +02:00
|
|
|
}
|
|
|
|
|
2023-10-07 01:44:37 +02:00
|
|
|
void TimerPauseQuery::onRemoval(PlayerColor color)
|
2023-08-28 02:42:05 +02:00
|
|
|
{
|
2024-04-26 12:15:39 +02:00
|
|
|
gh->turnTimerHandler->setTimerEnabled(color, true);
|
2023-08-28 02:42:05 +02:00
|
|
|
}
|
|
|
|
|
2023-10-07 01:44:37 +02:00
|
|
|
bool TimerPauseQuery::endsByPlayerAnswer() const
|
2023-08-28 02:42:05 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-09-04 16:17:22 +02:00
|
|
|
void CGarrisonDialogQuery::notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const
|
2023-07-23 23:46:29 +02:00
|
|
|
{
|
2024-09-04 16:17:22 +02:00
|
|
|
visitedObject->garrisonDialogClosed(visitingHero);
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CGarrisonDialogQuery::CGarrisonDialogQuery(CGameHandler * owner, const CArmedInstance * up, const CArmedInstance * down):
|
|
|
|
CDialogQuery(owner)
|
|
|
|
{
|
|
|
|
exchangingArmies[0] = up;
|
|
|
|
exchangingArmies[1] = down;
|
|
|
|
|
|
|
|
addPlayer(up->tempOwner);
|
|
|
|
addPlayer(down->tempOwner);
|
|
|
|
}
|
|
|
|
|
2024-10-04 15:41:53 +02:00
|
|
|
bool CGarrisonDialogQuery::blocksPack(const CPackForServer * pack) const
|
2023-07-23 23:46:29 +02:00
|
|
|
{
|
|
|
|
std::set<ObjectInstanceID> ourIds;
|
|
|
|
ourIds.insert(this->exchangingArmies[0]->id);
|
|
|
|
ourIds.insert(this->exchangingArmies[1]->id);
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(auto stacks = dynamic_cast<const ArrangeStacks*>(pack))
|
2023-07-23 23:46:29 +02:00
|
|
|
return !vstd::contains(ourIds, stacks->id1) || !vstd::contains(ourIds, stacks->id2);
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(auto stacks = dynamic_cast<const BulkSplitStack*>(pack))
|
2023-07-23 23:46:29 +02:00
|
|
|
return !vstd::contains(ourIds, stacks->srcOwner);
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(auto stacks = dynamic_cast<const BulkMergeStacks*>(pack))
|
2023-07-23 23:46:29 +02:00
|
|
|
return !vstd::contains(ourIds, stacks->srcOwner);
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(auto stacks = dynamic_cast<const BulkSmartSplitStack*>(pack))
|
2023-07-23 23:46:29 +02:00
|
|
|
return !vstd::contains(ourIds, stacks->srcOwner);
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(auto stacks = dynamic_cast<const BulkMoveArmy*>(pack))
|
2023-07-23 23:46:29 +02:00
|
|
|
return !vstd::contains(ourIds, stacks->srcArmy) || !vstd::contains(ourIds, stacks->destArmy);
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(auto arts = dynamic_cast<const ExchangeArtifacts*>(pack))
|
2023-07-23 23:46:29 +02:00
|
|
|
{
|
2023-10-14 21:00:39 +02:00
|
|
|
if(auto id1 = arts->src.artHolder)
|
|
|
|
if(!vstd::contains(ourIds, id1))
|
2023-07-23 23:46:29 +02:00
|
|
|
return true;
|
|
|
|
|
2023-10-14 21:00:39 +02:00
|
|
|
if(auto id2 = arts->dst.artHolder)
|
|
|
|
if(!vstd::contains(ourIds, id2))
|
2023-07-23 23:46:29 +02:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2024-09-04 16:32:36 +02:00
|
|
|
if(auto dismiss = dynamic_cast<const DisbandCreature*>(pack))
|
2023-07-23 23:46:29 +02:00
|
|
|
return !vstd::contains(ourIds, dismiss->id);
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(auto arts = dynamic_cast<const BulkExchangeArtifacts*>(pack))
|
2023-07-23 23:46:29 +02:00
|
|
|
return !vstd::contains(ourIds, arts->srcHero) || !vstd::contains(ourIds, arts->dstHero);
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(auto arts = dynamic_cast<const ManageBackpackArtifacts*>(pack))
|
2024-03-06 15:16:35 +02:00
|
|
|
return !vstd::contains(ourIds, arts->artHolder);
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(auto art = dynamic_cast<const EraseArtifactByClient*>(pack))
|
2023-07-23 23:46:29 +02:00
|
|
|
{
|
2023-10-14 21:00:39 +02:00
|
|
|
if(auto id = art->al.artHolder)
|
|
|
|
return !vstd::contains(ourIds, id);
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(auto dismiss = dynamic_cast<const AssembleArtifacts*>(pack))
|
2023-07-23 23:46:29 +02:00
|
|
|
return !vstd::contains(ourIds, dismiss->heroID);
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(auto upgrade = dynamic_cast<const UpgradeCreature*>(pack))
|
2023-07-23 23:46:29 +02:00
|
|
|
return !vstd::contains(ourIds, upgrade->id);
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(auto formation = dynamic_cast<const SetFormation*>(pack))
|
2023-07-23 23:46:29 +02:00
|
|
|
return !vstd::contains(ourIds, formation->hid);
|
|
|
|
|
|
|
|
return CDialogQuery::blocksPack(pack);
|
|
|
|
}
|
|
|
|
|
2024-09-04 16:17:22 +02:00
|
|
|
void CBlockingDialogQuery::notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const
|
2023-07-23 23:46:29 +02:00
|
|
|
{
|
|
|
|
assert(answer);
|
2024-09-04 17:14:56 +02:00
|
|
|
caller->blockingDialogAnswered(visitingHero, *answer);
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:14:56 +02:00
|
|
|
CBlockingDialogQuery::CBlockingDialogQuery(CGameHandler * owner, const IObjectInterface * caller, const BlockingDialog & bd):
|
|
|
|
CDialogQuery(owner),
|
|
|
|
caller(caller)
|
2023-07-23 23:46:29 +02:00
|
|
|
{
|
|
|
|
this->bd = bd;
|
|
|
|
addPlayer(bd.player);
|
|
|
|
}
|
|
|
|
|
2023-09-28 00:17:05 +02:00
|
|
|
OpenWindowQuery::OpenWindowQuery(CGameHandler * owner, const CGHeroInstance *hero, EOpenWindowMode mode):
|
|
|
|
CDialogQuery(owner),
|
|
|
|
mode(mode)
|
|
|
|
{
|
|
|
|
addPlayer(hero->getOwner());
|
|
|
|
}
|
|
|
|
|
2023-09-28 11:16:42 +02:00
|
|
|
void OpenWindowQuery::onExposure(QueryPtr topQuery)
|
|
|
|
{
|
|
|
|
//do nothing - wait for reply
|
|
|
|
}
|
|
|
|
|
2024-10-04 15:41:53 +02:00
|
|
|
bool OpenWindowQuery::blocksPack(const CPackForServer *pack) const
|
2023-09-28 00:17:05 +02:00
|
|
|
{
|
2023-10-04 16:24:19 +02:00
|
|
|
if (mode == EOpenWindowMode::RECRUITMENT_FIRST || mode == EOpenWindowMode::RECRUITMENT_ALL)
|
|
|
|
{
|
2024-09-04 16:32:36 +02:00
|
|
|
if(dynamic_cast<const RecruitCreatures*>(pack) != nullptr)
|
2023-10-04 16:24:19 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// If hero has no free slots, he might get some stacks merged automatically
|
2024-09-04 16:32:36 +02:00
|
|
|
if(dynamic_cast<const ArrangeStacks*>(pack) != nullptr)
|
2023-10-04 16:24:19 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-09-28 00:17:05 +02:00
|
|
|
if (mode == EOpenWindowMode::TAVERN_WINDOW)
|
|
|
|
{
|
2024-09-04 16:32:36 +02:00
|
|
|
if(dynamic_cast<const HireHero*>(pack) != nullptr)
|
2023-09-28 00:17:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-09-28 11:16:42 +02:00
|
|
|
if (mode == EOpenWindowMode::UNIVERSITY_WINDOW)
|
|
|
|
{
|
2024-09-04 16:32:36 +02:00
|
|
|
if(dynamic_cast<const TradeOnMarketplace*>(pack) != nullptr)
|
2023-09-28 11:16:42 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-09-28 00:17:05 +02:00
|
|
|
if (mode == EOpenWindowMode::MARKET_WINDOW)
|
|
|
|
{
|
2024-09-04 16:32:36 +02:00
|
|
|
if(dynamic_cast<const ExchangeArtifacts*>(pack) != nullptr)
|
2023-09-28 00:17:05 +02:00
|
|
|
return false;
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(dynamic_cast<const BulkExchangeArtifacts*>(pack) != nullptr)
|
2024-01-16 16:22:40 +02:00
|
|
|
return false;
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(dynamic_cast<const ManageBackpackArtifacts*>(pack) != nullptr)
|
2024-03-07 16:52:50 +02:00
|
|
|
return false;
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(dynamic_cast<const AssembleArtifacts*>(pack))
|
2023-09-28 00:17:05 +02:00
|
|
|
return false;
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(dynamic_cast<const EraseArtifactByClient*>(pack))
|
2023-09-28 00:17:05 +02:00
|
|
|
return false;
|
|
|
|
|
2024-09-04 16:32:36 +02:00
|
|
|
if(dynamic_cast<const TradeOnMarketplace*>(pack) != nullptr)
|
2023-09-28 00:17:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CDialogQuery::blocksPack(pack);
|
|
|
|
}
|
|
|
|
|
2024-09-04 16:17:22 +02:00
|
|
|
void CTeleportDialogQuery::notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const
|
2023-07-23 23:46:29 +02:00
|
|
|
{
|
2024-09-04 16:17:22 +02:00
|
|
|
auto obj = dynamic_cast<const CGTeleport*>(visitedObject);
|
2023-07-23 23:46:29 +02:00
|
|
|
if(obj)
|
2024-09-04 16:17:22 +02:00
|
|
|
obj->teleportDialogAnswered(visitingHero, *answer, td.exits);
|
2023-07-23 23:46:29 +02:00
|
|
|
else
|
|
|
|
logGlobal->error("Invalid instance in teleport query");
|
|
|
|
}
|
|
|
|
|
|
|
|
CTeleportDialogQuery::CTeleportDialogQuery(CGameHandler * owner, const TeleportDialog & td):
|
|
|
|
CDialogQuery(owner)
|
|
|
|
{
|
|
|
|
this->td = td;
|
2023-09-15 21:18:36 +02:00
|
|
|
addPlayer(gh->getHero(td.hero)->getOwner());
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CHeroLevelUpDialogQuery::CHeroLevelUpDialogQuery(CGameHandler * owner, const HeroLevelUp & Hlu, const CGHeroInstance * Hero):
|
|
|
|
CDialogQuery(owner), hero(Hero)
|
|
|
|
{
|
|
|
|
hlu = Hlu;
|
|
|
|
addPlayer(hero->tempOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHeroLevelUpDialogQuery::onRemoval(PlayerColor color)
|
|
|
|
{
|
|
|
|
assert(answer);
|
|
|
|
logGlobal->trace("Completing hero level-up query. %s gains skill %d", hero->getObjectName(), answer.value());
|
|
|
|
gh->levelUpHero(hero, hlu.skills[*answer]);
|
|
|
|
}
|
|
|
|
|
2024-09-04 16:17:22 +02:00
|
|
|
void CHeroLevelUpDialogQuery::notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const
|
2023-07-23 23:46:29 +02:00
|
|
|
{
|
2024-09-04 16:17:22 +02:00
|
|
|
visitedObject->heroLevelUpDone(visitingHero);
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CCommanderLevelUpDialogQuery::CCommanderLevelUpDialogQuery(CGameHandler * owner, const CommanderLevelUp & Clu, const CGHeroInstance * Hero):
|
|
|
|
CDialogQuery(owner), hero(Hero)
|
|
|
|
{
|
|
|
|
clu = Clu;
|
|
|
|
addPlayer(hero->tempOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCommanderLevelUpDialogQuery::onRemoval(PlayerColor color)
|
|
|
|
{
|
|
|
|
assert(answer);
|
|
|
|
logGlobal->trace("Completing commander level-up query. Commander of hero %s gains skill %s", hero->getObjectName(), answer.value());
|
|
|
|
gh->levelUpCommander(hero->commander, clu.skills[*answer]);
|
|
|
|
}
|
|
|
|
|
2024-09-04 16:17:22 +02:00
|
|
|
void CCommanderLevelUpDialogQuery::notifyObjectAboutRemoval(const CGObjectInstance * visitedObject, const CGHeroInstance * visitingHero) const
|
2023-07-23 23:46:29 +02:00
|
|
|
{
|
2024-09-04 16:17:22 +02:00
|
|
|
visitedObject->heroLevelUpDone(visitingHero);
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CHeroMovementQuery::CHeroMovementQuery(CGameHandler * owner, const TryMoveHero & Tmh, const CGHeroInstance * Hero, bool VisitDestAfterVictory):
|
2023-09-19 22:17:25 +02:00
|
|
|
CQuery(owner), tmh(Tmh), visitDestAfterVictory(VisitDestAfterVictory), hero(Hero)
|
2023-07-23 23:46:29 +02:00
|
|
|
{
|
|
|
|
players.push_back(hero->tempOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHeroMovementQuery::onExposure(QueryPtr topQuery)
|
|
|
|
{
|
|
|
|
assert(players.size() == 1);
|
|
|
|
|
|
|
|
if(visitDestAfterVictory && hero->tempOwner == players[0]) //hero still alive, so he won with the guard
|
|
|
|
//TODO what if there were H4-like escape? we should also check pos
|
|
|
|
{
|
|
|
|
logGlobal->trace("Hero %s after victory over guard finishes visit to %s", hero->getNameTranslated(), tmh.end.toString());
|
|
|
|
//finish movement
|
|
|
|
visitDestAfterVictory = false;
|
|
|
|
gh->visitObjectOnTile(*gh->getTile(hero->convertToVisitablePos(tmh.end)), hero);
|
|
|
|
}
|
|
|
|
|
|
|
|
owner->popIfTop(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHeroMovementQuery::onRemoval(PlayerColor color)
|
|
|
|
{
|
|
|
|
PlayerBlocked pb;
|
|
|
|
pb.player = color;
|
|
|
|
pb.reason = PlayerBlocked::ONGOING_MOVEMENT;
|
|
|
|
pb.startOrEnd = PlayerBlocked::BLOCKADE_ENDED;
|
2024-10-04 20:59:51 +02:00
|
|
|
gh->sendAndApply(pb);
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHeroMovementQuery::onAdding(PlayerColor color)
|
|
|
|
{
|
|
|
|
PlayerBlocked pb;
|
|
|
|
pb.player = color;
|
|
|
|
pb.reason = PlayerBlocked::ONGOING_MOVEMENT;
|
|
|
|
pb.startOrEnd = PlayerBlocked::BLOCKADE_STARTED;
|
2024-10-04 20:59:51 +02:00
|
|
|
gh->sendAndApply(pb);
|
2023-07-23 23:46:29 +02:00
|
|
|
}
|