1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/client/NetPacksClient.cpp

944 lines
28 KiB
C++
Raw Normal View History

/*
* NetPacksClient.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"
2009-03-07 17:55:56 +02:00
#include "../lib/NetPacks.h"
#include "../lib/filesystem/Filesystem.h"
#include "../lib/filesystem/FileInfo.h"
2009-03-07 17:55:56 +02:00
#include "../CCallback.h"
2009-05-20 13:08:56 +03:00
#include "Client.h"
#include "CPlayerInterface.h"
#include "CGameInfo.h"
#include "../lib/serializer/Connection.h"
#include "../lib/serializer/BinarySerializer.h"
#include "../lib/CGeneralTextHandler.h"
#include "../lib/CHeroHandler.h"
2009-03-07 17:55:56 +02:00
#include "../lib/VCMI_Lib.h"
2013-04-07 13:48:07 +03:00
#include "../lib/mapping/CMap.h"
#include "../lib/VCMIDirs.h"
#include "../lib/spells/CSpellHandler.h"
#include "../lib/CSoundBase.h"
#include "../lib/StartInfo.h"
2010-04-06 11:59:24 +03:00
#include "mapHandler.h"
#include "windows/GUIClasses.h"
#include "../lib/CConfigHandler.h"
#include "gui/SDL_Extensions.h"
#include "battle/CBattleInterface.h"
2013-04-07 13:48:07 +03:00
#include "../lib/mapping/CCampaignHandler.h"
#include "../lib/CGameState.h"
#include "../lib/CStack.h"
#include "../lib/battle/BattleInfo.h"
#include "../lib/GameConstants.h"
#include "../lib/CPlayerState.h"
#include "gui/CGuiHandler.h"
#include "widgets/MiscWidgets.h"
#include "widgets/AdventureMapClasses.h"
#include "CMT.h"
#include "CServerHandler.h"
2009-03-07 17:55:56 +02:00
// TODO: as Tow suggested these template should all be part of CClient
// This will require rework spectator interface properly though
template<typename T, typename ... Args, typename ... Args2>
bool callOnlyThatInterface(CClient * cl, PlayerColor player, void (T::*ptr)(Args...), Args2 && ...args)
{
if(vstd::contains(cl->playerint, player))
{
((*cl->playerint[player]).*ptr)(std::forward<Args2>(args)...);
return true;
}
return false;
}
template<typename T, typename ... Args, typename ... Args2>
bool callInterfaceIfPresent(CClient * cl, PlayerColor player, void (T::*ptr)(Args...), Args2 && ...args)
{
bool called = callOnlyThatInterface(cl, player, ptr, std::forward<Args2>(args)...);
return called;
}
template<typename T, typename ... Args, typename ... Args2>
void callOnlyThatBattleInterface(CClient * cl, PlayerColor player, void (T::*ptr)(Args...), Args2 && ...args)
{
if(vstd::contains(cl->battleints,player))
((*cl->battleints[player]).*ptr)(std::forward<Args2>(args)...);
if(cl->additionalBattleInts.count(player))
{
for(auto bInt : cl->additionalBattleInts[player])
((*bInt).*ptr)(std::forward<Args2>(args)...);
}
}
template<typename T, typename ... Args, typename ... Args2>
void callBattleInterfaceIfPresent(CClient * cl, PlayerColor player, void (T::*ptr)(Args...), Args2 && ...args)
{
callOnlyThatInterface(cl, player, ptr, std::forward<Args2>(args)...);
}
//calls all normal interfaces and privileged ones, playerints may be updated when iterating over it, so we need a copy
template<typename T, typename ... Args, typename ... Args2>
void callAllInterfaces(CClient * cl, void (T::*ptr)(Args...), Args2 && ...args)
{
for(auto pInt : cl->playerint)
((*pInt.second).*ptr)(std::forward<Args2>(args)...);
}
//calls all normal interfaces and privileged ones, playerints may be updated when iterating over it, so we need a copy
template<typename T, typename ... Args, typename ... Args2>
void callBattleInterfaceIfPresentForBothSides(CClient * cl, void (T::*ptr)(Args...), Args2 && ...args)
{
callOnlyThatBattleInterface(cl, cl->gameState()->curB->sides[0].color, ptr, std::forward<Args2>(args)...);
callOnlyThatBattleInterface(cl, cl->gameState()->curB->sides[1].color, ptr, std::forward<Args2>(args)...);
if(settings["session"]["spectate"].Bool() && !settings["session"]["spectate-skip-battle"].Bool() && LOCPLINT->battleInt)
{
callOnlyThatBattleInterface(cl, PlayerColor::SPECTATOR, ptr, std::forward<Args2>(args)...);
}
}
2016-10-28 23:37:20 +02:00
void SetResources::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
//todo: inform on actual resource set transfered
callInterfaceIfPresent(cl, player, &IGameEventsReceiver::receivedResource);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void SetPrimSkill::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
const CGHeroInstance *h = cl->getHero(id);
if(!h)
{
2017-08-11 13:38:10 +02:00
logNetwork->error("Cannot find hero with ID %d", id.getNum());
return;
}
callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroPrimarySkillChanged, h, which, val);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void SetSecSkill::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
const CGHeroInstance *h = cl->getHero(id);
if(!h)
{
2017-08-11 13:38:10 +02:00
logNetwork->error("Cannot find hero with ID %d", id.getNum());
return;
}
callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroSecondarySkillChanged, h, which, val);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void HeroVisitCastle::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
const CGHeroInstance *h = cl->getHero(hid);
if(start())
2009-03-07 17:55:56 +02:00
{
callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroVisitsTown, h, GS(cl)->getTown(tid));
2009-03-07 17:55:56 +02:00
}
}
2016-10-28 23:37:20 +02:00
void ChangeSpells::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
//TODO: inform interface?
}
2016-10-28 23:37:20 +02:00
void SetMana::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
const CGHeroInstance *h = cl->getHero(hid);
callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroManaPointsChanged, h);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void SetMovePoints::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
const CGHeroInstance *h = cl->getHero(hid);
cl->invalidatePaths();
callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroMovePointsChanged, h);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void FoWChange::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
for(auto &i : cl->playerint)
{
if(cl->getPlayerRelations(i.first, player) == PlayerRelations::SAME_PLAYER && waitForDialogs && LOCPLINT == i.second.get())
{
LOCPLINT->waitWhileDialog();
}
if(cl->getPlayerRelations(i.first, player) != PlayerRelations::ENEMIES)
{
if(mode)
i.second->tileRevealed(tiles);
else
i.second->tileHidden(tiles);
}
}
2011-09-03 05:54:33 +03:00
cl->invalidatePaths();
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void SetAvailableHeroes::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
//TODO: inform interface?
}
2018-03-10 23:19:36 +02:00
static void dispatchGarrisonChange(CClient * cl, ObjectInstanceID army1, ObjectInstanceID army2)
{
2018-03-10 23:19:36 +02:00
auto obj1 = cl->getObj(army1);
if(!obj1)
{
logNetwork->error("Cannot find army with ID %d", army1.getNum());
return;
}
callInterfaceIfPresent(cl, obj1->tempOwner, &IGameEventsReceiver::garrisonsChanged, army1, army2);
if(army2 != ObjectInstanceID() && army2 != army1)
{
auto obj2 = cl->getObj(army2);
if(!obj2)
{
logNetwork->error("Cannot find army with ID %d", army2.getNum());
return;
}
if(obj1->tempOwner != obj2->tempOwner)
callInterfaceIfPresent(cl, obj2->tempOwner, &IGameEventsReceiver::garrisonsChanged, army1, army2);
}
}
void ChangeStackCount::applyCl(CClient * cl)
{
dispatchGarrisonChange(cl, army, ObjectInstanceID());
}
2018-03-10 23:19:36 +02:00
void SetStackType::applyCl(CClient * cl)
{
2018-03-10 23:19:36 +02:00
dispatchGarrisonChange(cl, army, ObjectInstanceID());
}
2018-03-10 23:19:36 +02:00
void EraseStack::applyCl(CClient * cl)
{
2018-03-10 23:19:36 +02:00
dispatchGarrisonChange(cl, army, ObjectInstanceID());
}
2018-03-10 23:19:36 +02:00
void SwapStacks::applyCl(CClient * cl)
{
2018-03-10 23:19:36 +02:00
dispatchGarrisonChange(cl, srcArmy, dstArmy);
}
2018-03-10 23:19:36 +02:00
void InsertNewStack::applyCl(CClient * cl)
{
2018-03-10 23:19:36 +02:00
dispatchGarrisonChange(cl, army, ObjectInstanceID());
}
2018-03-10 23:19:36 +02:00
void RebalanceStacks::applyCl(CClient * cl)
{
2018-03-10 23:19:36 +02:00
dispatchGarrisonChange(cl, srcArmy, dstArmy);
}
void BulkRebalanceStacks::applyCl(CClient * cl)
{
if(!moves.empty())
{
auto destArmy = moves[0].srcArmy == moves[0].dstArmy
? ObjectInstanceID()
: moves[0].dstArmy;
dispatchGarrisonChange(cl, moves[0].srcArmy, destArmy);
}
}
void BulkSmartRebalanceStacks::applyCl(CClient * cl)
{
if(!moves.empty())
{
assert(moves[0].srcArmy == moves[0].dstArmy);
dispatchGarrisonChange(cl, moves[0].srcArmy, ObjectInstanceID());
}
else if(!changes.empty())
{
dispatchGarrisonChange(cl, changes[0].army, ObjectInstanceID());
}
}
2016-10-28 23:37:20 +02:00
void PutArtifact::applyCl(CClient *cl)
{
callInterfaceIfPresent(cl, al.owningPlayer(), &IGameEventsReceiver::artifactPut, al);
}
2016-10-28 23:37:20 +02:00
void EraseArtifact::applyCl(CClient *cl)
{
callInterfaceIfPresent(cl, al.owningPlayer(), &IGameEventsReceiver::artifactRemoved, al);
}
2016-10-28 23:37:20 +02:00
void MoveArtifact::applyCl(CClient *cl)
{
callInterfaceIfPresent(cl, src.owningPlayer(), &IGameEventsReceiver::artifactMoved, src, dst);
if(src.owningPlayer() != dst.owningPlayer())
callInterfaceIfPresent(cl, dst.owningPlayer(), &IGameEventsReceiver::artifactMoved, src, dst);
}
2016-10-28 23:37:20 +02:00
void AssembledArtifact::applyCl(CClient *cl)
2011-01-22 05:43:20 +02:00
{
callInterfaceIfPresent(cl, al.owningPlayer(), &IGameEventsReceiver::artifactAssembled, al);
2011-01-22 05:43:20 +02:00
}
2016-10-28 23:37:20 +02:00
void DisassembledArtifact::applyCl(CClient *cl)
2011-01-22 05:43:20 +02:00
{
callInterfaceIfPresent(cl, al.owningPlayer(), &IGameEventsReceiver::artifactDisassembled, al);
2011-01-22 05:43:20 +02:00
}
void HeroVisit::applyCl(CClient * cl)
{
auto hero = cl->getHero(heroId);
auto obj = cl->getObj(objId, false);
callInterfaceIfPresent(cl, player, &IGameEventsReceiver::heroVisit, hero, obj, starting);
}
2016-10-28 23:37:20 +02:00
void NewTurn::applyCl(CClient *cl)
{
2011-09-03 05:54:33 +03:00
cl->invalidatePaths();
}
2016-10-28 23:37:20 +02:00
void GiveBonus::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
2011-09-03 05:54:33 +03:00
cl->invalidatePaths();
switch(who)
{
case HERO:
{
const CGHeroInstance *h = GS(cl)->getHero(ObjectInstanceID(id));
callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroBonusChanged, h, *h->getBonusList().back(), true);
}
break;
case PLAYER:
{
const PlayerState *p = GS(cl)->getPlayerState(PlayerColor(id));
callInterfaceIfPresent(cl, PlayerColor(id), &IGameEventsReceiver::playerBonusChanged, *p->getBonusList().back(), true);
}
break;
}
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void ChangeObjPos::applyFirstCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
CGObjectInstance *obj = GS(cl)->getObjInstance(objid);
if(flags & 1 && CGI->mh)
2009-03-07 17:55:56 +02:00
CGI->mh->hideObject(obj);
}
2016-10-28 23:37:20 +02:00
void ChangeObjPos::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
CGObjectInstance *obj = GS(cl)->getObjInstance(objid);
if(flags & 1 && CGI->mh)
2009-03-07 17:55:56 +02:00
CGI->mh->printObject(obj);
2010-03-11 01:16:30 +02:00
2011-09-03 05:54:33 +03:00
cl->invalidatePaths();
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void PlayerEndsGame::applyCl(CClient *cl)
{
callAllInterfaces(cl, &IGameEventsReceiver::gameOver, player, victoryLossCheckResult);
// In auto testing mode we always close client if red player won or lose
if(!settings["session"]["testmap"].isNull() && player == PlayerColor(0))
handleQuit(settings["session"]["spectate"].Bool()); // if spectator is active ask to close client or not
}
2016-10-28 23:37:20 +02:00
void RemoveBonus::applyCl(CClient *cl)
{
2011-09-03 05:54:33 +03:00
cl->invalidatePaths();
switch(who)
{
case HERO:
{
const CGHeroInstance *h = GS(cl)->getHero(ObjectInstanceID(id));
callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroBonusChanged, h, bonus, false);
}
break;
case PLAYER:
{
//const PlayerState *p = GS(cl)->getPlayerState(id);
callInterfaceIfPresent(cl, PlayerColor(id), &IGameEventsReceiver::playerBonusChanged, bonus, false);
}
break;
}
}
2016-10-28 23:37:20 +02:00
void RemoveObject::applyFirstCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
const CGObjectInstance *o = cl->getObj(id);
if(CGI->mh)
CGI->mh->hideObject(o, true);
//notify interfaces about removal
2013-03-03 20:06:03 +03:00
for(auto i=cl->playerint.begin(); i!=cl->playerint.end(); i++)
2009-03-07 17:55:56 +02:00
{
//below line contains little cheat for AI so it will be aware of deletion of enemy heroes that moved or got re-covered by FoW
//TODO: loose requirements as next AI related crashes appear, for example another player collects object that got re-covered by FoW, unsure if AI code workarounds this
if(GS(cl)->isVisible(o, i->first) || (!cl->getPlayerState(i->first)->human && o->ID == Obj::HERO && o->tempOwner != i->first))
i->second->objectRemoved(o);
2009-03-07 17:55:56 +02:00
}
}
2016-10-28 23:37:20 +02:00
void RemoveObject::applyCl(CClient *cl)
{
2011-09-03 05:54:33 +03:00
cl->invalidatePaths();
}
2016-10-28 23:37:20 +02:00
void TryMoveHero::applyFirstCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
CGHeroInstance *h = GS(cl)->getHero(id);
//check if playerint will have the knowledge about movement - if not, directly update maphandler
2013-03-03 20:06:03 +03:00
for(auto i=cl->playerint.begin(); i!=cl->playerint.end(); i++)
{
auto ps = GS(cl)->getPlayerState(i->first);
if(ps && (GS(cl)->isVisible(start - int3(1, 0, 0), i->first) || GS(cl)->isVisible(end - int3(1, 0, 0), i->first)))
{
if(ps->human)
humanKnows = true;
}
}
if(!CGI->mh)
return;
if(result == TELEPORTATION || result == EMBARK || result == DISEMBARK || !humanKnows)
2016-11-07 23:19:53 +02:00
CGI->mh->hideObject(h, result == EMBARK && humanKnows);
if(result == DISEMBARK)
CGI->mh->printObject(h->boat);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void TryMoveHero::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
const CGHeroInstance *h = cl->getHero(id);
2011-09-03 05:54:33 +03:00
cl->invalidatePaths();
2009-03-07 17:55:56 +02:00
if(CGI->mh)
2011-06-21 19:00:19 +03:00
{
if(result == TELEPORTATION || result == EMBARK || result == DISEMBARK)
CGI->mh->printObject(h, result == DISEMBARK);
if(result == EMBARK)
CGI->mh->hideObject(h->boat);
}
2013-03-03 20:06:03 +03:00
PlayerColor player = h->tempOwner;
2009-03-07 17:55:56 +02:00
for(auto &i : cl->playerint)
if(cl->getPlayerRelations(i.first, player) != PlayerRelations::ENEMIES)
i.second->tileRevealed(fowRevealed);
2009-03-07 17:55:56 +02:00
//notify interfaces about move
auto gs = cl->gameState();
2013-03-03 20:06:03 +03:00
for(auto i=cl->playerint.begin(); i!=cl->playerint.end(); i++)
2009-03-07 17:55:56 +02:00
{
if(i->first != PlayerColor::SPECTATOR && gs->checkForStandardLoss(i->first)) // Do not notify vanquished player's interface
continue;
if(GS(cl)->isVisible(start - int3(1, 0, 0), i->first)
|| GS(cl)->isVisible(end - int3(1, 0, 0), i->first))
2009-03-07 17:55:56 +02:00
{
// src and dst of enemy hero move may be not visible => 'verbose' should be false
const bool verbose = cl->getPlayerRelations(i->first, player) != PlayerRelations::ENEMIES;
i->second->heroMoved(*this, verbose);
2009-03-07 17:55:56 +02:00
}
}
//maphandler didn't get update from playerint, do it now
//TODO: restructure nicely
if(!humanKnows && CGI->mh)
CGI->mh->printObject(h);
2009-03-07 17:55:56 +02:00
}
bool TryMoveHero::stopMovement() const
{
return result != SUCCESS && result != EMBARK && result != DISEMBARK && result != TELEPORTATION;
}
2016-10-28 23:37:20 +02:00
void NewStructures::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
CGTownInstance *town = GS(cl)->getTown(tid);
for(const auto & id : bid)
{
callInterfaceIfPresent(cl, town->tempOwner, &IGameEventsReceiver::buildChanged, town, id, 1);
2009-03-07 17:55:56 +02:00
}
}
void RazeStructures::applyCl (CClient *cl)
{
CGTownInstance *town = GS(cl)->getTown(tid);
for(const auto & id : bid)
{
callInterfaceIfPresent(cl, town->tempOwner, &IGameEventsReceiver::buildChanged, town, id, 2);
}
}
2009-03-07 17:55:56 +02:00
2016-10-28 23:37:20 +02:00
void SetAvailableCreatures::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
const CGDwelling *dw = static_cast<const CGDwelling*>(cl->getObj(tid));
2010-05-15 11:33:32 +03:00
//inform order about the change
2013-03-03 20:06:03 +03:00
PlayerColor p;
if(dw->ID == Obj::WAR_MACHINE_FACTORY) //War Machines Factory is not flaggable, it's "owned" by visitor
2010-05-15 11:33:32 +03:00
p = cl->getTile(dw->visitablePos())->visitableObjects.back()->tempOwner;
else
p = dw->tempOwner;
callInterfaceIfPresent(cl, p, &IGameEventsReceiver::availableCreaturesChanged, dw);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void SetHeroesInTown::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
CGTownInstance *t = GS(cl)->getTown(tid);
CGHeroInstance *hGarr = GS(cl)->getHero(this->garrison);
CGHeroInstance *hVisit = GS(cl)->getHero(this->visiting);
//inform all players that see this object
for(auto i = cl->playerint.cbegin(); i != cl->playerint.cend(); ++i)
{
if(i->first >= PlayerColor::PLAYER_LIMIT)
continue;
if(GS(cl)->isVisible(t, i->first) ||
(hGarr && GS(cl)->isVisible(hGarr, i->first)) ||
(hVisit && GS(cl)->isVisible(hVisit, i->first)))
{
cl->playerint[i->first]->heroInGarrisonChange(t);
}
}
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void HeroRecruited::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
CGHeroInstance *h = GS(cl)->map->heroesOnMap.back();
2009-03-07 17:55:56 +02:00
if(h->subID != hid)
{
2017-08-10 18:39:27 +02:00
logNetwork->error("Something wrong with hero recruited!");
2009-03-07 17:55:56 +02:00
}
bool needsPrinting = true;
if(callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroCreated, h))
2009-03-07 17:55:56 +02:00
{
2010-07-09 02:03:27 +03:00
if(const CGTownInstance *t = GS(cl)->getTown(tid))
{
callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroInGarrisonChange, t);
needsPrinting = false;
}
}
if(needsPrinting && CGI->mh)
CGI->mh->printObject(h);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void GiveHero::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
CGHeroInstance *h = GS(cl)->getHero(id);
if(CGI->mh)
CGI->mh->printObject(h);
callInterfaceIfPresent(cl, h->tempOwner, &IGameEventsReceiver::heroCreated, h);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void GiveHero::applyFirstCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
if(CGI->mh)
CGI->mh->hideObject(GS(cl)->getHero(id));
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void InfoWindow::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
std::string str;
text.toString(str);
if(!callInterfaceIfPresent(cl, player, &CGameInterface::showInfoDialog, str,components,(soundBase::soundID)soundID))
2017-08-10 18:39:27 +02:00
logNetwork->warn("We received InfoWindow for not our player...");
}
2009-03-07 17:55:56 +02:00
2021-03-23 16:47:07 +02:00
void SetObjectProperty::applyCl(CClient * cl)
{
//inform all players that see this object
for(auto it = cl->playerint.cbegin(); it != cl->playerint.cend(); ++it)
{
if(GS(cl)->isVisible(GS(cl)->getObjInstance(id), it->first))
callInterfaceIfPresent(cl, it->first, &IGameEventsReceiver::objectPropertyChanged, this);
}
}
2016-10-28 23:37:20 +02:00
void HeroLevelUp::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
const CGHeroInstance * hero = cl->getHero(heroId);
assert(hero);
callOnlyThatInterface(cl, player, &CGameInterface::heroGotLevel, hero, primskill, skills, queryID);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void CommanderLevelUp::applyCl(CClient *cl)
{
const CGHeroInstance * hero = cl->getHero(heroId);
assert(hero);
const CCommanderInstance * commander = hero->commander;
assert(commander);
assert(commander->armyObj); //is it possible for Commander to exist beyond armed instance?
callOnlyThatInterface(cl, player, &CGameInterface::commanderGotLevel, commander, skills, queryID);
}
2009-03-07 17:55:56 +02:00
2016-10-28 23:37:20 +02:00
void BlockingDialog::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
std::string str;
text.toString(str);
if(!callOnlyThatInterface(cl, player, &CGameInterface::showBlockingDialog, str, components, queryID, (soundBase::soundID)soundID, selection(), cancel()))
2017-08-10 18:39:27 +02:00
logNetwork->warn("We received YesNoDialog for not our player...");
}
2009-03-07 17:55:56 +02:00
void GarrisonDialog::applyCl(CClient *cl)
{
const CGHeroInstance *h = cl->getHero(hid);
const CArmedInstance *obj = static_cast<const CArmedInstance*>(cl->getObj(objid));
callOnlyThatInterface(cl, h->getOwner(), &CGameInterface::showGarrisonDialog, obj, h, removableUnits, queryID);
}
void ExchangeDialog::applyCl(CClient *cl)
{
callInterfaceIfPresent(cl, player, &IGameEventsReceiver::heroExchangeStarted, hero1, hero2, queryID);
}
2016-10-28 23:37:20 +02:00
void TeleportDialog::applyCl(CClient *cl)
{
callOnlyThatInterface(cl, player, &CGameInterface::showTeleportDialog, channel, exits, impassable, queryID);
}
void MapObjectSelectDialog::applyCl(CClient * cl)
{
callOnlyThatInterface(cl, player, &CGameInterface::showMapObjectSelectDialog, queryID, icon, title, description, objects);
}
2016-10-28 23:37:20 +02:00
void BattleStart::applyFirstCl(CClient *cl)
2013-09-14 22:09:35 +03:00
{
// Cannot use the usual code because curB is not set yet
callOnlyThatBattleInterface(cl, info->sides[0].color, &IBattleEventsReceiver::battleStartBefore, info->sides[0].armyObject, info->sides[1].armyObject,
2013-09-14 22:09:35 +03:00
info->tile, info->sides[0].hero, info->sides[1].hero);
callOnlyThatBattleInterface(cl, info->sides[1].color, &IBattleEventsReceiver::battleStartBefore, info->sides[0].armyObject, info->sides[1].armyObject,
2013-09-14 22:09:35 +03:00
info->tile, info->sides[0].hero, info->sides[1].hero);
callOnlyThatBattleInterface(cl, PlayerColor::SPECTATOR, &IBattleEventsReceiver::battleStartBefore, info->sides[0].armyObject, info->sides[1].armyObject,
info->tile, info->sides[0].hero, info->sides[1].hero);
2013-09-14 22:09:35 +03:00
}
2016-10-28 23:37:20 +02:00
void BattleStart::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
2010-12-23 02:33:48 +02:00
cl->battleStarted(info);
2009-03-07 17:55:56 +02:00
}
void BattleNextRound::applyFirstCl(CClient *cl)
{
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleNewRoundFirst, round);
}
2016-10-28 23:37:20 +02:00
void BattleNextRound::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleNewRound, round);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void BattleSetActiveStack::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
if(!askPlayerInterface)
return;
2016-10-28 23:37:20 +02:00
const CStack *activated = GS(cl)->curB->battleGetStackByID(stack);
2013-03-03 20:06:03 +03:00
PlayerColor playerToCall; //player that will move activated stack
2016-10-28 23:37:20 +02:00
if (activated->hasBonusOfType(Bonus::HYPNOTIZED))
2009-08-18 14:49:34 +03:00
{
2016-10-28 23:37:20 +02:00
playerToCall = (GS(cl)->curB->sides[0].color == activated->owner
? GS(cl)->curB->sides[1].color
2016-10-28 23:37:20 +02:00
: GS(cl)->curB->sides[0].color);
2009-08-18 14:49:34 +03:00
}
else
{
playerToCall = activated->owner;
}
2017-11-16 13:15:43 +02:00
cl->startPlayerBattleAction(playerToCall);
2009-03-07 17:55:56 +02:00
}
void BattleLogMessage::applyCl(CClient * cl)
{
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleLogMessage, lines);
}
void BattleTriggerEffect::applyCl(CClient * cl)
{
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleTriggerEffect, *this);
}
void BattleUpdateGateState::applyFirstCl(CClient * cl)
{
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleGateStateChanged, state);
}
2016-10-28 23:37:20 +02:00
void BattleResult::applyFirstCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleEnd, this);
cl->battleFinished();
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void BattleStackMoved::applyFirstCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
const CStack * movedStack = GS(cl)->curB->battleGetStackByID(stack);
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleStackMoved, movedStack, tilesToMove, distance);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void BattleAttack::applyFirstCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleAttack, this);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void BattleAttack::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleStacksAttacked, bsa);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void StartAction::applyFirstCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
cl->curbaction = boost::make_optional(ba);
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::actionStarted, ba);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void BattleSpellCast::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleSpellCast, this);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void SetStackEffect::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
//informing about effects
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleStacksEffectsSet, *this);
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void StacksInjured::applyCl(CClient *cl)
{
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleStacksAttacked, stacks);
}
2016-10-28 23:37:20 +02:00
void BattleResultsApplied::applyCl(CClient *cl)
{
callInterfaceIfPresent(cl, player1, &IGameEventsReceiver::battleResultsApplied);
callInterfaceIfPresent(cl, player2, &IGameEventsReceiver::battleResultsApplied);
callInterfaceIfPresent(cl, PlayerColor::SPECTATOR, &IGameEventsReceiver::battleResultsApplied);
}
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
void BattleUnitsChanged::applyCl(CClient * cl)
{
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleUnitsChanged, changedStacks, customEffects);
}
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
void BattleObstaclesChanged::applyCl(CClient *cl)
{
//inform interfaces about removed obstacles
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleObstaclesChanged, changes);
}
2016-10-28 23:37:20 +02:00
void CatapultAttack::applyCl(CClient *cl)
2009-09-01 16:54:13 +03:00
{
//inform interfaces about catapult attack
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::battleCatapultAttacked, *this);
2009-09-01 16:54:13 +03:00
}
2016-10-28 23:37:20 +02:00
CGameState* CPackForClient::GS(CClient *cl)
2009-03-07 17:55:56 +02:00
{
return cl->gs;
}
2016-10-28 23:37:20 +02:00
void EndAction::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
callBattleInterfaceIfPresentForBothSides(cl, &IBattleEventsReceiver::actionFinished, *cl->curbaction);
cl->curbaction.reset();
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void PackageApplied::applyCl(CClient *cl)
{
callInterfaceIfPresent(cl, player, &IGameEventsReceiver::requestRealized, this);
2017-07-12 16:02:25 +02:00
if(!CClient::waitingRequest.tryRemovingElement(requestID))
logNetwork->warn("Surprising server message! PackageApplied for unknown requestID!");
}
2016-10-28 23:37:20 +02:00
void SystemMessage::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
std::ostringstream str;
str << "System message: " << text;
2017-08-11 13:38:10 +02:00
logNetwork->error(str.str()); // usually used to receive error messages from server
if(LOCPLINT && !settings["session"]["hideSystemMessages"].Bool())
LOCPLINT->cingconsole->print(str.str());
2009-03-07 17:55:56 +02:00
}
2016-10-28 23:37:20 +02:00
void PlayerBlocked::applyCl(CClient *cl)
{
callInterfaceIfPresent(cl, player, &IGameEventsReceiver::playerBlocked, reason, startOrEnd == BLOCKADE_STARTED);
}
2016-10-28 23:37:20 +02:00
void YourTurn::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
logNetwork->debug("Server gives turn to %s", player.getStr());
callAllInterfaces(cl, &IGameEventsReceiver::playerStartsTurn, player);
callOnlyThatInterface(cl, player, &CGameInterface::yourTurn);
2009-03-07 17:55:56 +02:00
}
void SaveGameClient::applyCl(CClient *cl)
{
const auto stem = FileInfo::GetPathStem(fname);
CResourceHandler::get("local")->createResource(stem.to_string() + ".vcgm1");
2012-06-09 22:58:17 +03:00
try
{
CSaveFile save(*CResourceHandler::get()->getResourceName(ResourceID(stem.to_string(), EResType::CLIENT_SAVEGAME)));
cl->saveCommonState(save);
2012-06-09 22:58:17 +03:00
save << *cl;
}
catch(std::exception &e)
{
2017-08-11 13:38:10 +02:00
logNetwork->error("Failed to save game:%s", e.what());
2012-06-09 22:58:17 +03:00
}
}
2009-03-07 17:55:56 +02:00
void PlayerMessageClient::applyCl(CClient *cl)
2009-03-07 17:55:56 +02:00
{
2017-08-12 13:36:04 +02:00
logNetwork->debug("Player %s sends a message: %s", player.getStr(), text);
std::ostringstream str;
if(player.isSpectator())
str << "Spectator: " << text;
else
str << cl->getPlayerState(player)->nodeName() <<": " << text;
if(LOCPLINT)
LOCPLINT->cingconsole->print(str.str());
2009-03-07 17:55:56 +02:00
}
void ShowInInfobox::applyCl(CClient *cl)
{
callInterfaceIfPresent(cl, player, &IGameEventsReceiver::showComp, c, text.toString());
2009-05-12 06:35:51 +03:00
}
void AdvmapSpellCast::applyCl(CClient *cl)
{
2011-09-03 05:54:33 +03:00
cl->invalidatePaths();
auto caster = cl->getHero(casterID);
if(caster)
//consider notifying other interfaces that see hero?
callInterfaceIfPresent(cl, caster->getOwner(), &IGameEventsReceiver::advmapSpellCast, caster, spellID);
else
logNetwork->error("Invalid hero instance");
}
void ShowWorldViewEx::applyCl(CClient * cl)
{
callOnlyThatInterface(cl, player, &CGameInterface::showWorldViewEx, objectPositions);
}
void OpenWindow::applyCl(CClient *cl)
{
switch(window)
{
case RECRUITMENT_FIRST:
case RECRUITMENT_ALL:
{
const CGDwelling *dw = dynamic_cast<const CGDwelling*>(cl->getObj(ObjectInstanceID(id1)));
const CArmedInstance *dst = dynamic_cast<const CArmedInstance*>(cl->getObj(ObjectInstanceID(id2)));
callInterfaceIfPresent(cl, dst->tempOwner, &IGameEventsReceiver::showRecruitmentDialog, dw, dst, window == RECRUITMENT_FIRST ? 0 : -1);
}
break;
case SHIPYARD_WINDOW:
{
const IShipyard *sy = IShipyard::castFrom(cl->getObj(ObjectInstanceID(id1)));
callInterfaceIfPresent(cl, sy->o->tempOwner, &IGameEventsReceiver::showShipyardDialog, sy);
}
break;
2010-02-07 17:06:14 +02:00
case THIEVES_GUILD:
{
//displays Thieves' Guild window (when hero enters Den of Thieves)
const CGObjectInstance *obj = cl->getObj(ObjectInstanceID(id2));
callInterfaceIfPresent(cl, PlayerColor(id1), &IGameEventsReceiver::showThievesGuildWindow, obj);
2010-02-07 17:06:14 +02:00
}
break;
case UNIVERSITY_WINDOW:
{
//displays University window (when hero enters University on adventure map)
const IMarket *market = IMarket::castFrom(cl->getObj(ObjectInstanceID(id1)));
const CGHeroInstance *hero = cl->getHero(ObjectInstanceID(id2));
callInterfaceIfPresent(cl, hero->tempOwner, &IGameEventsReceiver::showUniversityWindow, market, hero);
}
break;
2010-05-18 10:01:54 +03:00
case MARKET_WINDOW:
{
//displays Thieves' Guild window (when hero enters Den of Thieves)
const CGObjectInstance *obj = cl->getObj(ObjectInstanceID(id1));
const CGHeroInstance *hero = cl->getHero(ObjectInstanceID(id2));
2010-05-18 10:01:54 +03:00
const IMarket *market = IMarket::castFrom(obj);
callInterfaceIfPresent(cl, cl->getTile(obj->visitablePos())->visitableObjects.back()->tempOwner, &IGameEventsReceiver::showMarketWindow, market, hero);
2010-05-18 10:01:54 +03:00
}
break;
case HILL_FORT_WINDOW:
{
//displays Hill fort window
const CGObjectInstance *obj = cl->getObj(ObjectInstanceID(id1));
const CGHeroInstance *hero = cl->getHero(ObjectInstanceID(id2));
callInterfaceIfPresent(cl, cl->getTile(obj->visitablePos())->visitableObjects.back()->tempOwner, &IGameEventsReceiver::showHillFortWindow, obj, hero);
}
break;
case PUZZLE_MAP:
{
callInterfaceIfPresent(cl, PlayerColor(id1), &IGameEventsReceiver::showPuzzleMap);
}
break;
2010-07-09 02:03:27 +03:00
case TAVERN_WINDOW:
const CGObjectInstance *obj1 = cl->getObj(ObjectInstanceID(id1)),
*obj2 = cl->getObj(ObjectInstanceID(id2));
callInterfaceIfPresent(cl, obj1->tempOwner, &IGameEventsReceiver::showTavernWindow, obj2);
break;
}
}
void CenterView::applyCl(CClient *cl)
{
callInterfaceIfPresent(cl, player, &IGameEventsReceiver::centerView, pos, focusTime);
}
void NewObject::applyCl(CClient *cl)
{
cl->invalidatePaths();
2010-06-24 15:10:45 +03:00
const CGObjectInstance *obj = cl->getObj(id);
if(CGI->mh)
CGI->mh->printObject(obj, true);
2013-03-03 20:06:03 +03:00
for(auto i=cl->playerint.begin(); i!=cl->playerint.end(); i++)
{
2011-09-03 05:54:33 +03:00
if(GS(cl)->isVisible(obj, i->first))
i->second->newObject(obj);
}
}
void SetAvailableArtifacts::applyCl(CClient *cl)
{
if(id < 0) //artifact merchants globally
{
callAllInterfaces(cl, &IGameEventsReceiver::availableArtifactsChanged, nullptr);
}
else
{
const CGBlackMarket *bm = dynamic_cast<const CGBlackMarket *>(cl->getObj(ObjectInstanceID(id)));
assert(bm);
callInterfaceIfPresent(cl, cl->getTile(bm->visitablePos())->visitableObjects.back()->tempOwner, &IGameEventsReceiver::availableArtifactsChanged, bm);
}
}
void EntitiesChanged::applyCl(CClient *cl)
{
cl->invalidatePaths();
}