2009-03-07 17:55:56 +02:00
|
|
|
#include "../lib/NetPacks.h"
|
|
|
|
#include "../CCallback.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "Client.h"
|
|
|
|
#include "CPlayerInterface.h"
|
|
|
|
#include "CGameInfo.h"
|
2009-03-28 20:46:20 +02:00
|
|
|
#include "../lib/Connection.h"
|
2009-03-07 17:55:56 +02:00
|
|
|
#include "../hch/CGeneralTextHandler.h"
|
|
|
|
#include "../hch/CDefObjInfoHandler.h"
|
|
|
|
#include "../hch/CHeroHandler.h"
|
|
|
|
#include "../hch/CObjectHandler.h"
|
|
|
|
#include "../lib/VCMI_Lib.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "../lib/map.h"
|
2009-10-10 08:47:59 +03:00
|
|
|
#include "../lib/VCMIDirs.h"
|
2009-03-07 17:55:56 +02:00
|
|
|
#include "../hch/CSpellHandler.h"
|
2009-04-22 21:48:56 +03:00
|
|
|
#include "../hch/CSoundBase.h"
|
2009-03-07 17:55:56 +02:00
|
|
|
#include "../mapHandler.h"
|
2009-05-19 21:23:04 +03:00
|
|
|
#include "GUIClasses.h"
|
2009-03-07 17:55:56 +02:00
|
|
|
#include <boost/bind.hpp>
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include <boost/thread.hpp>
|
|
|
|
#include <boost/thread/shared_mutex.hpp>
|
2010-02-19 18:02:34 +02:00
|
|
|
#include "CConfigHandler.h"
|
|
|
|
#include "SDL_Extensions.h"
|
|
|
|
#include "CBattleInterface.h"
|
2009-03-07 17:55:56 +02:00
|
|
|
|
|
|
|
//macro to avoid code duplication - calls given method with given arguments if interface for specific player is present
|
|
|
|
#define INTERFACE_CALL_IF_PRESENT(player,function,...) \
|
|
|
|
if(vstd::contains(cl->playerint,player)) \
|
|
|
|
cl->playerint[player]->function(__VA_ARGS__);
|
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2009-03-07 17:55:56 +02:00
|
|
|
|
|
|
|
void SetResources::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
cl->playerint[player]->receivedResource(-1,-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetResource::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
cl->playerint[player]->receivedResource(resid,val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetPrimSkill::applyCl( CClient *cl )
|
|
|
|
{
|
2009-03-19 16:17:19 +02:00
|
|
|
const CGHeroInstance *h = GS(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);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetSecSkill::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
//TODO: inform interface?
|
|
|
|
}
|
|
|
|
|
|
|
|
void HeroVisitCastle::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
if(start() && !garrison() && vstd::contains(cl->playerint,GS(cl)->getHero(hid)->tempOwner))
|
|
|
|
{
|
|
|
|
cl->playerint[GS(cl)->getHero(hid)->tempOwner]->heroVisitsTown(GS(cl)->getHero(hid),GS(cl)->getTown(tid));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChangeSpells::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
//TODO: inform interface?
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMana::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
CGHeroInstance *h = GS(cl)->getHero(hid);
|
|
|
|
if(vstd::contains(cl->playerint,h->tempOwner))
|
|
|
|
cl->playerint[h->tempOwner]->heroManaPointsChanged(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMovePoints::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
CGHeroInstance *h = GS(cl)->getHero(hid);
|
|
|
|
if(vstd::contains(cl->playerint,h->tempOwner))
|
|
|
|
cl->playerint[h->tempOwner]->heroMovePointsChanged(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FoWChange::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
if(!vstd::contains(cl->playerint,player))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(mode)
|
|
|
|
cl->playerint[player]->tileRevealed(tiles);
|
|
|
|
else
|
|
|
|
cl->playerint[player]->tileHidden(tiles);
|
2009-12-31 13:04:29 +02:00
|
|
|
|
2010-01-25 23:25:14 +02:00
|
|
|
if (cl->IGameCallback::getSelectedHero(player))//if we have selected hero...
|
|
|
|
GS(cl)->calculatePaths(cl->IGameCallback::getSelectedHero(player), *cl->pathInfo);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetAvailableHeroes::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
//TODO: inform interface?
|
|
|
|
}
|
|
|
|
|
|
|
|
void GiveBonus::applyCl( CClient *cl )
|
|
|
|
{
|
2010-02-10 04:56:00 +02:00
|
|
|
switch(who)
|
|
|
|
{
|
|
|
|
case HERO:
|
|
|
|
{
|
|
|
|
const CGHeroInstance *h = GS(cl)->getHero(id);
|
|
|
|
INTERFACE_CALL_IF_PRESENT(h->tempOwner, heroBonusChanged, h, h->bonuses.back(),true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PLAYER:
|
|
|
|
{
|
|
|
|
const PlayerState *p = GS(cl)->getPlayer(id);
|
|
|
|
INTERFACE_CALL_IF_PRESENT(id, playerBonusChanged, p->bonuses.back(), true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2010-01-29 22:52:45 +02:00
|
|
|
void PlayerEndsGame::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)
|
|
|
|
i->second->gameOver(player, victory);
|
|
|
|
}
|
|
|
|
|
2010-02-10 04:56:00 +02:00
|
|
|
void RemoveBonus::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
void RemoveObject::applyFirstCl( CClient *cl )
|
|
|
|
{
|
2009-08-04 02:53:18 +03:00
|
|
|
const CGObjectInstance *o = cl->getObj(id);
|
|
|
|
CGI->mh->hideObject(o);
|
|
|
|
|
|
|
|
int3 pos = o->pos - o->getVisitableOffset();
|
|
|
|
//notify interfaces about removal
|
|
|
|
for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)
|
2009-03-07 17:55:56 +02:00
|
|
|
{
|
2009-08-04 02:53:18 +03:00
|
|
|
if(i->first >= PLAYER_LIMIT) continue;
|
|
|
|
if(GS(cl)->players[i->first].fogOfWarMap[pos.x][pos.y][pos.z])
|
|
|
|
{
|
|
|
|
i->second->objectRemoved(o);
|
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-07 19:08:40 +02:00
|
|
|
void RemoveObject::applyCl( CClient *cl )
|
|
|
|
{
|
2010-02-02 01:30:03 +02:00
|
|
|
if(cl->pathInfo->hero && cl->pathInfo->hero->id != id)
|
2009-11-13 18:02:25 +02:00
|
|
|
GS(cl)->calculatePaths(cl->pathInfo->hero, *cl->pathInfo);
|
2009-03-07 19:08:40 +02:00
|
|
|
}
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
void TryMoveHero::applyFirstCl( CClient *cl )
|
|
|
|
{
|
2009-07-19 06:10:24 +03:00
|
|
|
CGHeroInstance *h = GS(cl)->getHero(id);
|
2009-12-28 06:08:24 +02:00
|
|
|
|
|
|
|
//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 >= PLAYER_LIMIT)
|
|
|
|
continue;
|
|
|
|
PlayerState &p = GS(cl)->players[i->first];
|
|
|
|
if((p.fogOfWarMap[start.x-1][start.y][start.z] || p.fogOfWarMap[end.x-1][end.y][end.z]) && p.human)
|
|
|
|
humanKnows = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(result == TELEPORTATION || result == EMBARK || result == DISEMBARK || !humanKnows)
|
2009-07-19 06:10:24 +03:00
|
|
|
CGI->mh->removeObject(h);
|
|
|
|
|
|
|
|
|
|
|
|
if(result == DISEMBARK)
|
|
|
|
CGI->mh->printObject(h->boat);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TryMoveHero::applyCl( CClient *cl )
|
|
|
|
{
|
2009-07-03 22:57:14 +03:00
|
|
|
const CGHeroInstance *h = cl->getHero(id);
|
2009-03-07 17:55:56 +02:00
|
|
|
|
2009-07-19 06:10:24 +03:00
|
|
|
if(result == TELEPORTATION || result == EMBARK || result == DISEMBARK)
|
2009-07-03 22:57:14 +03:00
|
|
|
CGI->mh->printObject(h);
|
2009-07-19 06:10:24 +03:00
|
|
|
|
|
|
|
if(result == EMBARK)
|
|
|
|
CGI->mh->hideObject(h->boat);
|
|
|
|
|
2009-07-03 22:57:14 +03:00
|
|
|
int player = h->tempOwner;
|
2009-03-07 17:55:56 +02:00
|
|
|
|
|
|
|
if(vstd::contains(cl->playerint,player))
|
|
|
|
{
|
|
|
|
cl->playerint[player]->tileRevealed(fowRevealed);
|
|
|
|
}
|
|
|
|
|
|
|
|
//notify interfaces about move
|
|
|
|
for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)
|
|
|
|
{
|
|
|
|
if(i->first >= PLAYER_LIMIT) continue;
|
2009-12-28 06:08:24 +02:00
|
|
|
PlayerState &p = GS(cl)->players[i->first];
|
|
|
|
if(p.fogOfWarMap[start.x-1][start.y][start.z] || p.fogOfWarMap[end.x-1][end.y][end.z])
|
2009-03-07 17:55:56 +02:00
|
|
|
{
|
2009-07-03 22:57:14 +03:00
|
|
|
i->second->heroMoved(*this);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
}
|
2009-12-28 06:08:24 +02:00
|
|
|
|
|
|
|
if(!humanKnows) //maphandler didn't get update from playerint, do it now
|
|
|
|
{ //TODO: restructure nicely
|
|
|
|
CGI->mh->printObject(h);
|
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetGarrisons::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
for(std::map<ui32,CCreatureSet>::iterator i = garrs.begin(); i!=garrs.end(); i++)
|
|
|
|
if(vstd::contains(cl->playerint,cl->getOwner(i->first)))
|
|
|
|
cl->playerint[cl->getOwner(i->first)]->garrisonChanged(cl->getObj(i->first));
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2009-09-22 17:27:46 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
|
|
|
|
void SetAvailableCreatures::applyCl( CClient *cl )
|
|
|
|
{
|
2009-07-26 13:43:22 +03:00
|
|
|
const CGDwelling *dw = static_cast<const CGDwelling*>(cl->getObj(tid));
|
|
|
|
if(vstd::contains(cl->playerint,dw->tempOwner))
|
|
|
|
cl->playerint[dw->tempOwner]->availableCreaturesChanged(dw);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2009-04-04 01:34:31 +03:00
|
|
|
CGHeroInstance *h = GS(cl)->getHero(hid);
|
|
|
|
CGameInterface *player = (vstd::contains(cl->playerint,h->tempOwner) ? cl->playerint[h->tempOwner] : NULL);
|
|
|
|
if(!player)
|
|
|
|
return;
|
|
|
|
|
|
|
|
player->heroArtifactSetChanged(h);
|
|
|
|
|
|
|
|
BOOST_FOREACH(HeroBonus *bonus, gained)
|
|
|
|
{
|
|
|
|
player->heroBonusChanged(h,*bonus,true);
|
|
|
|
}
|
|
|
|
BOOST_FOREACH(HeroBonus *bonus, lost)
|
|
|
|
{
|
|
|
|
player->heroBonusChanged(h,*bonus,false);
|
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2009-08-01 13:08:16 +03:00
|
|
|
CGI->mh->printObject(h);
|
2009-03-07 17:55:56 +02:00
|
|
|
if(vstd::contains(cl->playerint,h->tempOwner))
|
|
|
|
{
|
|
|
|
cl->playerint[h->tempOwner]->heroCreated(h);
|
|
|
|
cl->playerint[h->tempOwner]->heroInGarrisonChange(GS(cl)->getTown(tid));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
2009-07-09 22:15:22 +03:00
|
|
|
std::string str;
|
|
|
|
text.toString(str);
|
2009-03-07 17:55:56 +02:00
|
|
|
|
|
|
|
if(vstd::contains(cl->playerint,player))
|
2009-04-30 13:53:06 +03:00
|
|
|
cl->playerint[player]->showInfoDialog(str,comps,(soundBase::soundID)soundID);
|
2009-03-07 17:55:56 +02:00
|
|
|
else
|
|
|
|
tlog2 << "We received InfoWindow for not our player...\n";
|
|
|
|
}
|
|
|
|
|
2009-07-30 15:49:45 +03:00
|
|
|
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)
|
|
|
|
{
|
2009-07-31 14:20:53 +03:00
|
|
|
if(GS(cl)->isVisible(GS(cl)->map->objects[id], it->first))
|
2009-07-30 15:49:45 +03:00
|
|
|
INTERFACE_CALL_IF_PRESENT(it->first, objectPropertyChanged, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
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,LOCPLINT->cb,_1,id));
|
2009-05-01 17:37:25 +03:00
|
|
|
cl->playerint[h->tempOwner]->heroGotLevel(const_cast<const CGHeroInstance*>(h),static_cast<int>(primskill),skills, callback);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-11 04:32:50 +03:00
|
|
|
void BlockingDialog::applyCl( CClient *cl )
|
2009-03-07 17:55:56 +02:00
|
|
|
{
|
2009-07-09 22:15:22 +03:00
|
|
|
std::string str;
|
|
|
|
text.toString(str);
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
if(vstd::contains(cl->playerint,player))
|
2009-04-30 13:53:06 +03:00
|
|
|
cl->playerint[player]->showBlockingDialog(str,components,id,(soundBase::soundID)soundID,selection(),cancel());
|
2009-03-07 17:55:56 +02:00
|
|
|
else
|
|
|
|
tlog2 << "We received YesNoDialog for not our player...\n";
|
|
|
|
}
|
|
|
|
|
2009-04-12 03:58:41 +03:00
|
|
|
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,LOCPLINT->cb,0,id);
|
2009-09-09 20:49:03 +03:00
|
|
|
cl->playerint[h->getOwner()]->showGarrisonDialog(obj,h,removableUnits,callback);
|
2009-04-12 03:58:41 +03:00
|
|
|
}
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
void BattleStart::applyCl( CClient *cl )
|
|
|
|
{
|
2010-02-19 18:02:34 +02:00
|
|
|
CPlayerInterface * att, * def;
|
|
|
|
if(vstd::contains(cl->playerint, info->side1) && cl->playerint[info->side1]->human)
|
|
|
|
att = static_cast<CPlayerInterface*>( cl->playerint[info->side1] );
|
|
|
|
else
|
|
|
|
att = NULL;
|
|
|
|
|
|
|
|
if(vstd::contains(cl->playerint, info->side2) && cl->playerint[info->side2]->human)
|
|
|
|
def = static_cast<CPlayerInterface*>( cl->playerint[info->side2] );
|
|
|
|
else
|
|
|
|
def = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
new CBattleInterface(&info->army1, &info->army2, info->heroes[0], info->heroes[1], genRect(600, 800, (conf.cc.resx - 800)/2, (conf.cc.resy - 600)/2), att, def);
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
if(vstd::contains(cl->playerint,info->side1))
|
2009-10-06 03:32:33 +03:00
|
|
|
cl->playerint[info->side1]->battleStart(&info->army1, &info->army2, info->tile, info->heroes[0], info->heroes[1], 0);
|
2009-03-07 17:55:56 +02:00
|
|
|
|
|
|
|
if(vstd::contains(cl->playerint,info->side2))
|
2009-10-06 03:32:33 +03:00
|
|
|
cl->playerint[info->side2]->battleStart(&info->army1, &info->army2, info->tile, info->heroes[0], info->heroes[1], 1);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BattleNextRound::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
|
|
|
|
cl->playerint[GS(cl)->curB->side1]->battleNewRound(round);
|
|
|
|
if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
|
|
|
|
cl->playerint[GS(cl)->curB->side2]->battleNewRound(round);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BattleSetActiveStack::applyCl( CClient *cl )
|
|
|
|
{
|
2009-08-18 14:49:34 +03:00
|
|
|
CStack * activated = GS(cl)->curB->getStack(stack);
|
|
|
|
int playerToCall = -1; //player that will move activated stack
|
|
|
|
if( activated->hasFeatureOfType(StackFeature::HYPNOTIZED) )
|
|
|
|
{
|
|
|
|
playerToCall = ( GS(cl)->curB->side1 == activated->owner ? GS(cl)->curB->side2 : GS(cl)->curB->side1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
playerToCall = activated->owner;
|
|
|
|
}
|
|
|
|
if( vstd::contains(cl->playerint, playerToCall) )
|
|
|
|
boost::thread( boost::bind(&CClient::waitForMoveAndSend, cl, playerToCall) );
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BattleResult::applyFirstCl( CClient *cl )
|
|
|
|
{
|
|
|
|
if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
|
|
|
|
cl->playerint[GS(cl)->curB->side1]->battleEnd(this);
|
|
|
|
if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
|
|
|
|
cl->playerint[GS(cl)->curB->side2]->battleEnd(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BattleStackMoved::applyFirstCl( CClient *cl )
|
|
|
|
{
|
2009-03-31 23:47:53 +03:00
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleStackMoved,stack,tile,distance,ending);
|
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleStackMoved,stack,tile,distance,ending);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BattleStackAttacked::applyCl( CClient *cl )
|
|
|
|
{
|
2009-03-21 14:49:58 +02:00
|
|
|
std::set<BattleStackAttacked> bsa;
|
|
|
|
bsa.insert(*this);
|
2009-03-07 17:55:56 +02:00
|
|
|
|
2009-03-21 14:49:58 +02:00
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleStacksAttacked,bsa);
|
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleStacksAttacked,bsa);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BattleAttack::applyFirstCl( CClient *cl )
|
|
|
|
{
|
|
|
|
if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
|
|
|
|
cl->playerint[GS(cl)->curB->side1]->battleAttack(this);
|
|
|
|
if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
|
|
|
|
cl->playerint[GS(cl)->curB->side2]->battleAttack(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BattleAttack::applyCl( CClient *cl )
|
|
|
|
{
|
2009-03-21 14:49:58 +02:00
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleStacksAttacked,bsa);
|
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleStacksAttacked,bsa);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void StartAction::applyFirstCl( CClient *cl )
|
|
|
|
{
|
|
|
|
cl->curbaction = new BattleAction(ba);
|
|
|
|
if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
|
|
|
|
cl->playerint[GS(cl)->curB->side1]->actionStarted(&ba);
|
|
|
|
if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
|
|
|
|
cl->playerint[GS(cl)->curB->side2]->actionStarted(&ba);
|
|
|
|
}
|
|
|
|
|
2009-05-12 06:35:51 +03:00
|
|
|
void SpellCast::applyCl( CClient *cl )
|
2009-03-07 17:55:56 +02:00
|
|
|
{
|
|
|
|
if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
|
2009-05-12 06:35:51 +03:00
|
|
|
cl->playerint[GS(cl)->curB->side1]->battleSpellCast(this);
|
2009-03-07 17:55:56 +02:00
|
|
|
if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
|
2009-05-12 06:35:51 +03:00
|
|
|
cl->playerint[GS(cl)->curB->side2]->battleSpellCast(this);
|
2009-08-06 17:02:21 +03:00
|
|
|
|
|
|
|
if(id >= 66 && id <= 69) //elemental summoning
|
|
|
|
{
|
|
|
|
if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
|
|
|
|
cl->playerint[GS(cl)->curB->side1]->battleNewStackAppeared(GS(cl)->curB->stacks.size() - 1);
|
|
|
|
if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
|
|
|
|
cl->playerint[GS(cl)->curB->side2]->battleNewStackAppeared(GS(cl)->curB->stacks.size() - 1);
|
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetStackEffect::applyCl( CClient *cl )
|
|
|
|
{
|
2009-05-12 06:35:51 +03:00
|
|
|
SpellCast sc;
|
2009-03-07 17:55:56 +02:00
|
|
|
sc.id = effect.id;
|
|
|
|
sc.side = 3; //doesn't matter
|
|
|
|
sc.skill = effect.level;
|
2009-03-21 18:03:07 +02:00
|
|
|
|
|
|
|
//informing about effects
|
|
|
|
if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
|
|
|
|
cl->playerint[GS(cl)->curB->side1]->battleStacksEffectsSet(*this);
|
|
|
|
if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
|
|
|
|
cl->playerint[GS(cl)->curB->side2]->battleStacksEffectsSet(*this);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
2009-04-16 03:28:54 +03:00
|
|
|
void StacksInjured::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleStacksAttacked,stacks);
|
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleStacksAttacked,stacks);
|
|
|
|
}
|
|
|
|
|
2009-08-04 02:53:18 +03:00
|
|
|
void BattleResultsApplied::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
INTERFACE_CALL_IF_PRESENT(player1,battleResultsApplied);
|
|
|
|
INTERFACE_CALL_IF_PRESENT(player2,battleResultsApplied);
|
|
|
|
}
|
|
|
|
|
2009-08-05 15:46:08 +03:00
|
|
|
void StacksHealedOrResurrected::applyCl( CClient *cl )
|
|
|
|
{
|
2009-08-06 08:08:17 +03:00
|
|
|
std::vector<std::pair<ui32, ui32> > shiftedHealed;
|
2009-08-05 15:46:08 +03:00
|
|
|
for(int v=0; v<healedStacks.size(); ++v)
|
|
|
|
{
|
|
|
|
shiftedHealed.push_back(std::make_pair(healedStacks[v].stackID, healedStacks[v].healedHP));
|
|
|
|
}
|
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1, battleStacksHealedRes, shiftedHealed);
|
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2, battleStacksHealedRes, shiftedHealed);
|
|
|
|
}
|
|
|
|
|
2009-08-19 13:59:42 +03:00
|
|
|
void ObstaclesRemoved::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
//inform interfaces about removed obstacles
|
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1, battleObstaclesRemoved, obstacles);
|
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2, battleObstaclesRemoved, obstacles);
|
|
|
|
}
|
|
|
|
|
2009-09-01 16:54:13 +03:00
|
|
|
void CatapultAttack::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
//inform interfaces about catapult attack
|
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1, battleCatapultAttacked, *this);
|
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2, battleCatapultAttacked, *this);
|
|
|
|
}
|
|
|
|
|
2009-09-05 17:10:26 +03:00
|
|
|
void BattleStacksRemoved::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
//inform interfaces about removed stacks
|
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1, battleStacksRemoved, *this);
|
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2, battleStacksRemoved, *this);
|
|
|
|
}
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
CGameState* CPackForClient::GS( CClient *cl )
|
|
|
|
{
|
|
|
|
return cl->gs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EndAction::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,actionFinished,cl->curbaction);
|
|
|
|
INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,actionFinished,cl->curbaction);
|
|
|
|
|
|
|
|
delete cl->curbaction;
|
|
|
|
cl->curbaction = NULL;
|
|
|
|
}
|
|
|
|
|
2009-04-16 03:28:54 +03:00
|
|
|
void PackageApplied::applyCl( CClient *cl )
|
|
|
|
{
|
2009-08-30 15:47:40 +03:00
|
|
|
ui8 player = GS(cl)->currentPlayer;
|
|
|
|
INTERFACE_CALL_IF_PRESENT(player, requestRealized, this);
|
2009-08-04 02:53:18 +03:00
|
|
|
if(cl->waitingRequest.get())
|
|
|
|
cl->waitingRequest.setn(false);
|
2009-04-16 03:28:54 +03:00
|
|
|
}
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
void SystemMessage::applyCl( CClient *cl )
|
|
|
|
{
|
2009-04-04 22:26:41 +03:00
|
|
|
std::ostringstream str;
|
2009-04-11 04:32:50 +03:00
|
|
|
str << "System message: " << text;
|
2009-04-04 22:26:41 +03:00
|
|
|
|
|
|
|
tlog4 << str.str() << std::endl;
|
|
|
|
if(LOCPLINT)
|
|
|
|
LOCPLINT->cingconsole->print(str.str());
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
2009-08-04 02:53:18 +03:00
|
|
|
void PlayerBlocked::applyCl( CClient *cl )
|
|
|
|
{
|
|
|
|
INTERFACE_CALL_IF_PRESENT(player,playerBlocked,reason);
|
|
|
|
}
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
void YourTurn::applyCl( CClient *cl )
|
|
|
|
{
|
2009-12-28 06:08:24 +02:00
|
|
|
INTERFACE_CALL_IF_PRESENT(player,yourTurn);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
2009-03-28 20:46:20 +02:00
|
|
|
void SaveGame::applyCl(CClient *cl)
|
|
|
|
{
|
2009-10-10 08:47:59 +03:00
|
|
|
CSaveFile save(GVCMIDirs.UserPath + "/Games/" + fname + ".vcgm1");
|
2009-03-28 20:46:20 +02:00
|
|
|
save << *cl;
|
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
|
|
|
|
void PlayerMessage::applyCl(CClient *cl)
|
|
|
|
{
|
2009-04-04 22:26:41 +03:00
|
|
|
std::ostringstream str;
|
|
|
|
str << "Player "<<(int)player<<" sends a message: " << text;
|
|
|
|
|
|
|
|
tlog4 << str.str() << std::endl;
|
|
|
|
if(LOCPLINT)
|
|
|
|
LOCPLINT->cingconsole->print(str.str());
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
2009-08-30 15:47:40 +03:00
|
|
|
void SetSelection::applyCl(CClient *cl)
|
|
|
|
{
|
|
|
|
const CGHeroInstance *h = cl->getHero(id);
|
|
|
|
if(!h)
|
|
|
|
return;
|
|
|
|
|
2009-09-13 01:17:23 +03:00
|
|
|
//CPackForClient::GS(cl)->calculatePaths(h, *cl->pathInfo);
|
2009-08-30 15:47:40 +03:00
|
|
|
}
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
void ShowInInfobox::applyCl(CClient *cl)
|
|
|
|
{
|
|
|
|
SComponent sc(c);
|
2009-07-09 22:15:22 +03:00
|
|
|
text.toString(sc.description);
|
2009-03-07 17:55:56 +02:00
|
|
|
if(cl->playerint[player]->human)
|
|
|
|
{
|
|
|
|
static_cast<CPlayerInterface*>(cl->playerint[player])->showComp(sc);
|
|
|
|
}
|
2009-05-12 06:35:51 +03:00
|
|
|
}
|
2009-06-16 14:18:14 +03:00
|
|
|
|
2009-07-06 22:41:27 +03:00
|
|
|
void OpenWindow::applyCl(CClient *cl)
|
2009-06-16 14:18:14 +03:00
|
|
|
{
|
2009-07-06 22:41:27 +03:00
|
|
|
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:
|
2009-07-26 13:43:22 +03:00
|
|
|
case RECRUITMENT_ALL:
|
2009-07-06 22:41:27 +03:00
|
|
|
{
|
|
|
|
const CGDwelling *dw = dynamic_cast<const CGDwelling*>(cl->getObj(id1));
|
2009-07-26 13:43:22 +03:00
|
|
|
const CArmedInstance *dst = dynamic_cast<const CArmedInstance*>(cl->getObj(id2));
|
|
|
|
INTERFACE_CALL_IF_PRESENT(dw->tempOwner,showRecruitmentDialog, dw, dst, window == RECRUITMENT_FIRST ? 0 : -1);
|
2009-07-06 22:41:27 +03:00
|
|
|
}
|
2009-07-26 06:33:13 +03:00
|
|
|
break;
|
|
|
|
case SHIPYARD_WINDOW:
|
|
|
|
{
|
|
|
|
const IShipyard *sy = IShipyard::castFrom(cl->getObj(id1));
|
|
|
|
INTERFACE_CALL_IF_PRESENT(sy->o->tempOwner, 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(id1);
|
|
|
|
GH.pushInt( new CThievesGuildWindow(obj) );
|
|
|
|
}
|
|
|
|
break;
|
2010-02-10 04:56:00 +02:00
|
|
|
case PUZZLE_MAP:
|
|
|
|
{
|
|
|
|
INTERFACE_CALL_IF_PRESENT(id1, showPuzzleMap);
|
|
|
|
}
|
|
|
|
break;
|
2009-07-06 22:41:27 +03:00
|
|
|
}
|
|
|
|
|
2009-06-16 14:18:14 +03:00
|
|
|
}
|
2009-07-26 06:33:13 +03:00
|
|
|
|
2009-08-11 10:50:29 +03:00
|
|
|
void CenterView::applyCl(CClient *cl)
|
|
|
|
{
|
2009-08-13 04:03:11 +03:00
|
|
|
INTERFACE_CALL_IF_PRESENT (player, centerView, pos, focusTime);
|
2009-08-11 10:50:29 +03:00
|
|
|
}
|
|
|
|
|
2009-07-26 06:33:13 +03:00
|
|
|
void NewObject::applyCl(CClient *cl)
|
|
|
|
{
|
|
|
|
const CGObjectInstance *obj = cl->getObj(id);
|
|
|
|
//notify interfaces about move
|
|
|
|
for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)
|
|
|
|
{
|
|
|
|
//TODO: check if any covered tile is visible
|
|
|
|
if(i->first >= PLAYER_LIMIT) continue;
|
|
|
|
if(GS(cl)->players[i->first].fogOfWarMap[obj->pos.x][obj->pos.y][obj->pos.z])
|
|
|
|
{
|
|
|
|
i->second->newObject(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-03 14:16:42 +03:00
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
2009-10-04 05:02:45 +03:00
|
|
|
}
|