| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910 | #include "StdInc.h"#include "../lib/NetPacks.h"#include "../CCallback.h"#include "Client.h"#include "CPlayerInterface.h"#include "CGameInfo.h"#include "../lib/Connection.h"#include "../lib/CGeneralTextHandler.h"#include "../lib/CDefObjInfoHandler.h"#include "../lib/CHeroHandler.h"#include "../lib/CObjectHandler.h"#include "../lib/VCMI_Lib.h"#include "../lib/map.h"#include "../lib/VCMIDirs.h"#include "../lib/CSpellHandler.h"#include "CSoundBase.h"#include "mapHandler.h"#include "GUIClasses.h"#include "CConfigHandler.h"#include "UIFramework/SDL_Extensions.h"#include "BattleInterface/CBattleInterface.h"#include "../lib/CCampaignHandler.h"#include "../lib/CGameState.h"#include "../lib/BattleState.h"#include "../lib/GameConstants.h"#include "UIFramework/CGuiHandler.h"//macros to avoid code duplication - calls given method with given arguments if interface for specific player is present//awaiting variadic templates...#define CALL_IN_PRIVILAGED_INTS(function, ...)										\	do																				\	{																				\		BOOST_FOREACH(IGameEventsReceiver *ger, cl->privilagedGameEventReceivers)	\			ger->function(__VA_ARGS__);												\	} while(0)#define CALL_ONLY_THAT_INTERFACE(player, function, ...)		\		do													\		{													\		if(vstd::contains(cl->playerint,player))			\			cl->playerint[player]->function(__VA_ARGS__);	\		}while(0)#define INTERFACE_CALL_IF_PRESENT(player,function,...) 				\		do															\		{															\			CALL_ONLY_THAT_INTERFACE(player, function, __VA_ARGS__);\			CALL_IN_PRIVILAGED_INTS(function, __VA_ARGS__);			\		} while(0)#define CALL_ONLY_THT_BATTLE_INTERFACE(player,function, ...) 	\	do															\	{															\		if(vstd::contains(cl->battleints,player))				\			cl->battleints[player]->function(__VA_ARGS__);		\	} while (0);#define BATTLE_INTERFACE_CALL_RECEIVERS(function,...) 	\	do															\	{															\		BOOST_FOREACH(IBattleEventsReceiver *ber, cl->privilagedBattleEventReceivers)\			ber->function(__VA_ARGS__);							\	} while(0)#define BATTLE_INTERFACE_CALL_IF_PRESENT(player,function,...) 	\	do															\	{															\		CALL_ONLY_THAT_INTERFACE(player, function, __VA_ARGS__);\		BATTLE_INTERFACE_CALL_RECEIVERS(function, __VA_ARGS__);	\	} while(0)//calls all normal interfaces and privilaged ones, playerints may be updated when iterating over it, so we need a copy#define CALL_IN_ALL_INTERFACES(function, ...)							\	do																	\	{																	\		std::map<ui8, CGameInterface*> ints = cl->playerint;			\		for(std::map<ui8, CGameInterface*>::iterator i = ints.begin(); i != ints.end(); i++)\			CALL_ONLY_THAT_INTERFACE(i->first, function, __VA_ARGS__);	\	} while(0)#define BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(function,...) 				\	CALL_ONLY_THT_BATTLE_INTERFACE(GS(cl)->curB->sides[0], function, __VA_ARGS__)	\	CALL_ONLY_THT_BATTLE_INTERFACE(GS(cl)->curB->sides[1], function, __VA_ARGS__)	\	BATTLE_INTERFACE_CALL_RECEIVERS(function, __VA_ARGS__)/* * 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 * */void SetResources::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(player,receivedResource,-1,-1);}void SetResource::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(player,receivedResource,resid,val);}void SetPrimSkill::applyCl( CClient *cl ){	const CGHeroInstance *h = cl->getHero(id);	if(!h)	{		tlog1 << "Cannot find hero with ID " << id << std::endl;		return;	}	INTERFACE_CALL_IF_PRESENT(h->tempOwner,heroPrimarySkillChanged,h,which,val);}void SetSecSkill::applyCl( CClient *cl ){	const CGHeroInstance *h = cl->getHero(id);	if(!h)	{		tlog1 << "Cannot find hero with ID " << id << std::endl;		return;	}	INTERFACE_CALL_IF_PRESENT(h->tempOwner,heroSecondarySkillChanged,h,which,val);}void HeroVisitCastle::applyCl( CClient *cl ){	const CGHeroInstance *h = cl->getHero(hid);	if(start())	{		INTERFACE_CALL_IF_PRESENT(h->tempOwner, heroVisitsTown, h, GS(cl)->getTown(tid));	}}void ChangeSpells::applyCl( CClient *cl ){	//TODO: inform interface?}void SetMana::applyCl( CClient *cl ){	const CGHeroInstance *h = cl->getHero(hid);	INTERFACE_CALL_IF_PRESENT(h->tempOwner, heroManaPointsChanged, h);}void SetMovePoints::applyCl( CClient *cl ){	const CGHeroInstance *h = cl->getHero(hid);	cl->invalidatePaths(h);	INTERFACE_CALL_IF_PRESENT(h->tempOwner, heroMovePointsChanged, h);}void FoWChange::applyCl( CClient *cl ){	BOOST_FOREACH(auto &i, cl->playerint)		if(cl->getPlayerRelations(i.first, player) > 0) //ally or the same player 		{			if(mode)				i.second->tileRevealed(tiles);			else				i.second->tileHidden(tiles);		}	cl->invalidatePaths();}void SetAvailableHeroes::applyCl( CClient *cl ){	//TODO: inform interface?}void ChangeStackCount::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(sl.army->tempOwner, stackChagedCount, sl, count, absoluteValue);}void SetStackType::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(sl.army->tempOwner, stackChangedType, sl, *type);}void EraseStack::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(sl.army->tempOwner, stacksErased, sl);}void SwapStacks::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(sl1.army->tempOwner, stacksSwapped, sl1, sl2);	if(sl1.army->tempOwner != sl2.army->tempOwner)		INTERFACE_CALL_IF_PRESENT(sl2.army->tempOwner, stacksSwapped, sl1, sl2);}void InsertNewStack::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(sl.army->tempOwner,newStackInserted,sl, *sl.getStack());}void RebalanceStacks::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(src.army->tempOwner, stacksRebalanced, src, dst, count);	if(src.army->tempOwner != dst.army->tempOwner)		INTERFACE_CALL_IF_PRESENT(dst.army->tempOwner,stacksRebalanced, src, dst, count);}void PutArtifact::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(al.owningPlayer(), artifactPut, al);}void EraseArtifact::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(al.owningPlayer(), artifactRemoved, al);}void MoveArtifact::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(src.owningPlayer(), artifactMoved, src, dst);	if(src.owningPlayer() != dst.owningPlayer())		INTERFACE_CALL_IF_PRESENT(src.owningPlayer(), artifactMoved, src, dst);}void AssembledArtifact::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(al.owningPlayer(), artifactAssembled, al);}void DisassembledArtifact::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(al.owningPlayer(), artifactDisassembled, al);}void HeroVisit::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(hero->tempOwner, heroVisit, hero, obj, starting);}void NewTurn::applyCl( CClient *cl ){	cl->invalidatePaths();}void GiveBonus::applyCl( CClient *cl ){	cl->invalidatePaths();	switch(who)	{	case HERO:		{			const CGHeroInstance *h = GS(cl)->getHero(id);			INTERFACE_CALL_IF_PRESENT(h->tempOwner, heroBonusChanged, h, *h->getBonusList().back(),true);		}		break;	case PLAYER:		{			const PlayerState *p = GS(cl)->getPlayer(id);			INTERFACE_CALL_IF_PRESENT(id, playerBonusChanged, *p->getBonusList().back(), true);		}		break;	}}void ChangeObjPos::applyFirstCl( CClient *cl ){	CGObjectInstance *obj = GS(cl)->map->objects[objid];	if(flags & 1)		CGI->mh->hideObject(obj);}void ChangeObjPos::applyCl( CClient *cl ){	CGObjectInstance *obj = GS(cl)->map->objects[objid];	if(flags & 1)		CGI->mh->printObject(obj);	cl->invalidatePaths();}void PlayerEndsGame::applyCl( CClient *cl ){	CALL_IN_ALL_INTERFACES(gameOver, player, victory);}void RemoveBonus::applyCl( CClient *cl ){	cl->invalidatePaths();	switch(who)	{	case HERO:		{			const CGHeroInstance *h = GS(cl)->getHero(id);			INTERFACE_CALL_IF_PRESENT(h->tempOwner, heroBonusChanged, h, bonus,false);		}		break;	case PLAYER:		{			//const PlayerState *p = GS(cl)->getPlayer(id);			INTERFACE_CALL_IF_PRESENT(id, playerBonusChanged, bonus, false);		}		break;	}}void UpdateCampaignState::applyCl( CClient *cl ){	cl->stopConnection();	if(camp->mapsRemaining.size())		cl->proposeNextMission(camp);	else		cl->finishCampaign(camp);}void RemoveObject::applyFirstCl( CClient *cl ){	const CGObjectInstance *o = cl->getObj(id);	CGI->mh->hideObject(o);	int3 pos = o->visitablePos();	//notify interfaces about removal	for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)	{		if(GS(cl)->isVisible(o, i->first))			i->second->objectRemoved(o);	}}void RemoveObject::applyCl( CClient *cl ){	cl->invalidatePaths();}void TryMoveHero::applyFirstCl( CClient *cl ){	CGHeroInstance *h = GS(cl)->getHero(id);	//check if playerint will have the knowledge about movement - if not, directly update maphandler	for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)	{		if(i->first >= GameConstants::PLAYER_LIMIT)			continue;		TeamState *t = GS(cl)->getPlayerTeam(i->first);		if((t->fogOfWarMap[start.x-1][start.y][start.z] || t->fogOfWarMap[end.x-1][end.y][end.z])				&& GS(cl)->getPlayer(i->first)->human)			humanKnows = true;	}	if(result == TELEPORTATION  ||  result == EMBARK  ||  result == DISEMBARK  ||  !humanKnows)		CGI->mh->removeObject(h);	if(result == DISEMBARK)		CGI->mh->printObject(h->boat);}void TryMoveHero::applyCl( CClient *cl ){	const CGHeroInstance *h = cl->getHero(id);	cl->invalidatePaths();	if(result == TELEPORTATION  ||  result == EMBARK  ||  result == DISEMBARK)	{		CGI->mh->printObject(h);	}	if(result == EMBARK)		CGI->mh->hideObject(h->boat);	int player = h->tempOwner;	BOOST_FOREACH(auto &i, cl->playerint)		if(cl->getPlayerRelations(i.first, player) > 0) //ally or the same player 			i.second->tileRevealed(fowRevealed);	//notify interfaces about move	for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)	{		if(i->first >= GameConstants::PLAYER_LIMIT) continue;		TeamState *t = GS(cl)->getPlayerTeam(i->first);		if(t->fogOfWarMap[start.x-1][start.y][start.z] || t->fogOfWarMap[end.x-1][end.y][end.z])		{			i->second->heroMoved(*this);		}	}	if(!humanKnows) //maphandler didn't get update from playerint, do it now	{				//TODO: restructure nicely		CGI->mh->printObject(h);	}}void NewStructures::applyCl( CClient *cl ){	CGTownInstance *town = GS(cl)->getTown(tid);	BOOST_FOREACH(si32 id, bid)	{		if(id==13) //fort or capitol		{			town->defInfo = GS(cl)->capitols[town->subID];		}		if(id ==7)		{			town->defInfo = GS(cl)->forts[town->subID];		}		if(vstd::contains(cl->playerint,town->tempOwner))			cl->playerint[town->tempOwner]->buildChanged(town,id,1);	}}void RazeStructures::applyCl (CClient *cl){	CGTownInstance *town = GS(cl)->getTown(tid);	BOOST_FOREACH(si32 id, bid)	{		if (id == 13) //fort or capitol		{			town->defInfo = GS(cl)->forts[town->subID];		}		if(vstd::contains (cl->playerint,town->tempOwner))			cl->playerint[town->tempOwner]->buildChanged (town,id,2);	}}void SetAvailableCreatures::applyCl( CClient *cl ){	const CGDwelling *dw = static_cast<const CGDwelling*>(cl->getObj(tid));	//inform order about the change	int p = -1;	if(dw->ID == 106) //War Machines Factory is not flaggable, it's "owned" by visitor		p = cl->getTile(dw->visitablePos())->visitableObjects.back()->tempOwner;	else		p = dw->tempOwner;	INTERFACE_CALL_IF_PRESENT(p, availableCreaturesChanged, dw);}void SetHeroesInTown::applyCl( CClient *cl ){	CGTownInstance *t = GS(cl)->getTown(tid);	if(vstd::contains(cl->playerint,t->tempOwner))		cl->playerint[t->tempOwner]->heroInGarrisonChange(t);}// void SetHeroArtifacts::applyCl( CClient *cl )// {// 	tlog1 << "SetHeroArtifacts :(\n";// //// // 	CGHeroInstance *h = GS(cl)->getHero(hid);// // 	CGameInterface *player = (vstd::contains(cl->playerint,h->tempOwner) ? cl->playerint[h->tempOwner] : NULL);// // 	if(!player)// // 		return;//// 	//h->recreateArtBonuses();// 	//player->heroArtifactSetChanged(h);//// // 	BOOST_FOREACH(Bonus bonus, gained)// // 	{// // 		player->heroBonusChanged(h,bonus,true);// // 	}// // 	BOOST_FOREACH(Bonus bonus, lost)// // 	{// // 		player->heroBonusChanged(h,bonus,false);// // 	}// }void HeroRecruited::applyCl( CClient *cl ){	CGHeroInstance *h = GS(cl)->map->heroes.back();	if(h->subID != hid)	{		tlog1 << "Something wrong with hero recruited!\n";	}	CGI->mh->initHeroDef(h);	CGI->mh->printObject(h);	if(vstd::contains(cl->playerint,h->tempOwner))	{		cl->playerint[h->tempOwner]->heroCreated(h);		if(const CGTownInstance *t = GS(cl)->getTown(tid))			cl->playerint[h->tempOwner]->heroInGarrisonChange(t);	}}void GiveHero::applyCl( CClient *cl ){	CGHeroInstance *h = GS(cl)->getHero(id);	CGI->mh->initHeroDef(h);	CGI->mh->printObject(h);	cl->playerint[h->tempOwner]->heroCreated(h);}void GiveHero::applyFirstCl( CClient *cl ){	CGI->mh->hideObject(GS(cl)->getHero(id));}void InfoWindow::applyCl( CClient *cl ){	std::vector<Component*> comps;	for(size_t i=0;i<components.size();i++)	{		comps.push_back(&components[i]);	}	std::string str;	text.toString(str);	if(vstd::contains(cl->playerint,player))		cl->playerint[player]->showInfoDialog(str,comps,(soundBase::soundID)soundID);	else		tlog2 << "We received InfoWindow for not our player...\n";}void SetObjectProperty::applyCl( CClient *cl ){	//inform all players that see this object	for(std::map<ui8,CGameInterface *>::const_iterator it = cl->playerint.begin(); it != cl->playerint.end(); ++it)	{		if(GS(cl)->isVisible(GS(cl)->map->objects[id], it->first))			INTERFACE_CALL_IF_PRESENT(it->first, objectPropertyChanged, this);	}}void HeroLevelUp::applyCl( CClient *cl ){	CGHeroInstance *h = GS(cl)->getHero(heroid);	if(vstd::contains(cl->playerint,h->tempOwner))	{		boost::function<void(ui32)> callback = boost::function<void(ui32)>(boost::bind(&CCallback::selectionMade,cl->callbacks[h->tempOwner].get(),_1,id));		cl->playerint[h->tempOwner]->heroGotLevel(const_cast<const CGHeroInstance*>(h),static_cast<int>(primskill),skills, callback);	}}void BlockingDialog::applyCl( CClient *cl ){	std::string str;	text.toString(str);	if(vstd::contains(cl->playerint,player))		cl->playerint[player]->showBlockingDialog(str,components,id,(soundBase::soundID)soundID,selection(),cancel());	else		tlog2 << "We received YesNoDialog for not our player...\n";}void GarrisonDialog::applyCl(CClient *cl){	const CGHeroInstance *h = cl->getHero(hid);	const CArmedInstance *obj = static_cast<const CArmedInstance*>(cl->getObj(objid));	if(!vstd::contains(cl->playerint,h->getOwner()))		return;	boost::function<void()> callback = boost::bind(&CCallback::selectionMade,cl->callbacks[h->getOwner()].get(),0,id);	cl->playerint[h->getOwner()]->showGarrisonDialog(obj,h,removableUnits,callback);}void BattleStart::applyCl( CClient *cl ){	cl->battleStarted(info);}void BattleNextRound::applyFirstCl(CClient *cl){	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleNewRoundFirst,round);}void BattleNextRound::applyCl( CClient *cl ){	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleNewRound,round);}void BattleSetActiveStack::applyCl( CClient *cl ){	CStack * activated = GS(cl)->curB->getStack(stack);	int playerToCall = -1; //player that will move activated stack	if( activated->hasBonusOfType(Bonus::HYPNOTIZED) )	{		playerToCall = ( GS(cl)->curB->sides[0] == activated->owner ? GS(cl)->curB->sides[1] : GS(cl)->curB->sides[0] );	}	else	{		playerToCall = activated->owner;	}	if( vstd::contains(cl->battleints, playerToCall) )		boost::thread( boost::bind(&CClient::waitForMoveAndSend, cl, playerToCall) );}void BattleTriggerEffect::applyCl(CClient * cl){	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleTriggerEffect, *this);}void BattleObstaclePlaced::applyCl(CClient * cl){	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleObstaclePlaced, obstacle);}void BattleResult::applyFirstCl( CClient *cl ){	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleEnd,this);}void BattleStackMoved::applyFirstCl( CClient *cl ){	const CStack * movedStack = GS(cl)->curB->getStack(stack);	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleStackMoved,movedStack,tilesToMove,distance);}//void BattleStackAttacked::( CClient *cl )void BattleStackAttacked::applyFirstCl( CClient *cl ){	std::vector<BattleStackAttacked> bsa;	bsa.push_back(*this);	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleStacksAttacked,bsa);}void BattleAttack::applyFirstCl( CClient *cl ){	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleAttack,this);	for (int g=0; g<bsa.size(); ++g)	{		for (int z=0; z<bsa[g].healedStacks.size(); ++z)		{			bsa[g].healedStacks[z].applyCl(cl);		}	}}void BattleAttack::applyCl( CClient *cl ){	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleStacksAttacked,bsa);}void StartAction::applyFirstCl( CClient *cl ){	cl->curbaction = new BattleAction(ba);	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(actionStarted, &ba);}void BattleSpellCast::applyCl( CClient *cl ){	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleSpellCast,this);}void SetStackEffect::applyCl( CClient *cl ){	//informing about effects	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleStacksEffectsSet,*this);}void StacksInjured::applyCl( CClient *cl ){	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleStacksAttacked,stacks);}void BattleResultsApplied::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(player1, battleResultsApplied);	INTERFACE_CALL_IF_PRESENT(player2, battleResultsApplied);	INTERFACE_CALL_IF_PRESENT(254, battleResultsApplied);	if(GS(cl)->initialOpts->mode == StartInfo::DUEL)	{		cl->terminate = true;		CloseServer cs;		*cl->serv << &cs;	}}void StacksHealedOrResurrected::applyCl( CClient *cl ){	std::vector<std::pair<ui32, ui32> > shiftedHealed;	for(int v=0; v<healedStacks.size(); ++v)	{		shiftedHealed.push_back(std::make_pair(healedStacks[v].stackID, healedStacks[v].healedHP));	}	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleStacksHealedRes, shiftedHealed, lifeDrain, tentHealing, drainedFrom);}void ObstaclesRemoved::applyCl( CClient *cl ){	//inform interfaces about removed obstacles	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleObstaclesRemoved, obstacles);}void CatapultAttack::applyCl( CClient *cl ){	//inform interfaces about catapult attack	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleCatapultAttacked, *this);}void BattleStacksRemoved::applyCl( CClient *cl ){	//inform interfaces about removed stacks	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleStacksRemoved, *this);}void BattleStackAdded::applyCl( CClient *cl ){	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(battleNewStackAppeared, GS(cl)->curB->stacks.back());}CGameState* CPackForClient::GS( CClient *cl ){	return cl->gs;}void EndAction::applyCl( CClient *cl ){	BATTLE_INTERFACE_CALL_IF_PRESENT_FOR_BOTH_SIDES(actionFinished, cl->curbaction);	delete cl->curbaction;	cl->curbaction = NULL;}void PackageApplied::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(player, requestRealized, this);	if(!cl->waitingRequest.tryRemovingElement(requestID))		tlog3 << "Surprising server message!\n";}void SystemMessage::applyCl( CClient *cl ){	std::ostringstream str;	str << "System message: " << text;	tlog4 << str.str() << std::endl;	if(LOCPLINT)		LOCPLINT->cingconsole->print(str.str());}void PlayerBlocked::applyCl( CClient *cl ){	INTERFACE_CALL_IF_PRESENT(player,playerBlocked,reason);}void YourTurn::applyCl( CClient *cl ){	CALL_IN_ALL_INTERFACES(playerStartsTurn, player);	CALL_ONLY_THAT_INTERFACE(player,yourTurn);}void SaveGame::applyCl(CClient *cl){	CSaveFile save(GVCMIDirs.UserPath + "/Games/" + fname + ".vcgm1");	save << *cl;}void PlayerMessage::applyCl(CClient *cl){	std::ostringstream str;	str << "Player "<<(int)player<<" sends a message: " << text;	tlog4 << str.str() << std::endl;	if(LOCPLINT)		LOCPLINT->cingconsole->print(str.str());}void SetSelection::applyCl(CClient *cl){	const CGHeroInstance *h = cl->getHero(id);	if(!h)		return;	//CPackForClient::GS(cl)->calculatePaths(h, *cl->pathInfo);}void ShowInInfobox::applyCl(CClient *cl){	CComponent sc(c);	text.toString(sc.description);	INTERFACE_CALL_IF_PRESENT(player,showComp, sc);}void AdvmapSpellCast::applyCl(CClient *cl){	cl->invalidatePaths();	//consider notifying other interfaces that see hero?	INTERFACE_CALL_IF_PRESENT(caster->getOwner(),advmapSpellCast, caster, spellID);}void OpenWindow::applyCl(CClient *cl){	switch(window)	{	case EXCHANGE_WINDOW:		{			const CGHeroInstance *h = cl->getHero(id1);			const CGObjectInstance *h2 = cl->getHero(id2);			assert(h && h2);			INTERFACE_CALL_IF_PRESENT(h->tempOwner,heroExchangeStarted, id1, id2);		}		break;	case RECRUITMENT_FIRST:	case RECRUITMENT_ALL:		{			const CGDwelling *dw = dynamic_cast<const CGDwelling*>(cl->getObj(id1));			const CArmedInstance *dst = dynamic_cast<const CArmedInstance*>(cl->getObj(id2));			INTERFACE_CALL_IF_PRESENT(dst->tempOwner,showRecruitmentDialog, dw, dst, window == RECRUITMENT_FIRST ? 0 : -1);		}		break;	case SHIPYARD_WINDOW:		{			const IShipyard *sy = IShipyard::castFrom(cl->getObj(id1));			INTERFACE_CALL_IF_PRESENT(sy->o->tempOwner, showShipyardDialog, sy);		}		break;	case THIEVES_GUILD:		{			//displays Thieves' Guild window (when hero enters Den of Thieves)			const CGObjectInstance *obj = cl->getObj(id2);			INTERFACE_CALL_IF_PRESENT(id1, showThievesGuildWindow, obj);		}		break;	case UNIVERSITY_WINDOW:		{			//displays University window (when hero enters University on adventure map)			const IMarket *market = IMarket::castFrom(cl->getObj(id1));			const CGHeroInstance *hero = cl->getHero(id2);			INTERFACE_CALL_IF_PRESENT(hero->tempOwner,showUniversityWindow, market, hero);		}		break;	case MARKET_WINDOW:		{			//displays Thieves' Guild window (when hero enters Den of Thieves)			const CGObjectInstance *obj = cl->getObj(id1);			const CGHeroInstance *hero = cl->getHero(id2);			const IMarket *market = IMarket::castFrom(obj);			INTERFACE_CALL_IF_PRESENT(cl->getTile(obj->visitablePos())->visitableObjects.back()->tempOwner, showMarketWindow, market, hero);		}		break;	case HILL_FORT_WINDOW:		{			//displays Hill fort window			const CGObjectInstance *obj = cl->getObj(id1);			const CGHeroInstance *hero = cl->getHero(id2);			INTERFACE_CALL_IF_PRESENT(cl->getTile(obj->visitablePos())->visitableObjects.back()->tempOwner, showHillFortWindow, obj, hero);		}		break;	case PUZZLE_MAP:		{			INTERFACE_CALL_IF_PRESENT(id1, showPuzzleMap);		}		break;	case TAVERN_WINDOW:		const CGObjectInstance *obj1 = cl->getObj(id1),								*obj2 = cl->getObj(id2);		INTERFACE_CALL_IF_PRESENT(obj1->tempOwner, showTavernWindow, obj2);		break;	}}void CenterView::applyCl(CClient *cl){	INTERFACE_CALL_IF_PRESENT (player, centerView, pos, focusTime);}void NewObject::applyCl(CClient *cl){	cl->updatePaths();	const CGObjectInstance *obj = cl->getObj(id);	CGI->mh->printObject(obj);	for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)	{		if(GS(cl)->isVisible(obj, i->first))			i->second->newObject(obj);	}}void SetAvailableArtifacts::applyCl(CClient *cl){	if(id < 0) //artifact merchants globally	{		for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)			i->second->availableArtifactsChanged(NULL);	}	else	{		const CGBlackMarket *bm = dynamic_cast<const CGBlackMarket *>(cl->getObj(id));		assert(bm);		INTERFACE_CALL_IF_PRESENT(cl->getTile(bm->visitablePos())->visitableObjects.back()->tempOwner, availableArtifactsChanged, bm);	}}void TradeComponents::applyCl(CClient *cl){///Shop handler	switch (CGI->mh->map->objects[objectid]->ID)	{		case 7: //Black Market			break;		case 95: //Tavern			break;		case 97: //Den of Thieves			break;		case 221: //Trading Post			break;		default:			tlog2 << "Shop type not supported! \n";	}}
 |