NetPacksClient.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. #include "../lib/NetPacks.h"
  2. #include "../CCallback.h"
  3. #include "Client.h"
  4. #include "CPlayerInterface.h"
  5. #include "CGameInfo.h"
  6. #include "../lib/Connection.h"
  7. #include "../hch/CGeneralTextHandler.h"
  8. #include "../hch/CDefObjInfoHandler.h"
  9. #include "../hch/CHeroHandler.h"
  10. #include "../hch/CObjectHandler.h"
  11. #include "../lib/VCMI_Lib.h"
  12. #include "../lib/map.h"
  13. #include "../lib/VCMIDirs.h"
  14. #include "../hch/CSpellHandler.h"
  15. #include "../hch/CSoundBase.h"
  16. #include "../mapHandler.h"
  17. #include "GUIClasses.h"
  18. #include <boost/bind.hpp>
  19. #include <boost/foreach.hpp>
  20. #include <boost/thread.hpp>
  21. #include <boost/thread/shared_mutex.hpp>
  22. //macro to avoid code duplication - calls given method with given arguments if interface for specific player is present
  23. #define INTERFACE_CALL_IF_PRESENT(player,function,...) \
  24. if(vstd::contains(cl->playerint,player)) \
  25. cl->playerint[player]->function(__VA_ARGS__);
  26. /*
  27. * NetPacksClient.cpp, part of VCMI engine
  28. *
  29. * Authors: listed in file AUTHORS in main folder
  30. *
  31. * License: GNU General Public License v2.0 or later
  32. * Full text of license available in license.txt file, in main folder
  33. *
  34. */
  35. void SetResources::applyCl( CClient *cl )
  36. {
  37. cl->playerint[player]->receivedResource(-1,-1);
  38. }
  39. void SetResource::applyCl( CClient *cl )
  40. {
  41. cl->playerint[player]->receivedResource(resid,val);
  42. }
  43. void SetPrimSkill::applyCl( CClient *cl )
  44. {
  45. const CGHeroInstance *h = GS(cl)->getHero(id);
  46. if(!h)
  47. {
  48. tlog1 << "Cannot find hero with ID " << id << std::endl;
  49. return;
  50. }
  51. INTERFACE_CALL_IF_PRESENT(h->tempOwner,heroPrimarySkillChanged,h,which,val);
  52. }
  53. void SetSecSkill::applyCl( CClient *cl )
  54. {
  55. //TODO: inform interface?
  56. }
  57. void HeroVisitCastle::applyCl( CClient *cl )
  58. {
  59. if(start() && !garrison() && vstd::contains(cl->playerint,GS(cl)->getHero(hid)->tempOwner))
  60. {
  61. cl->playerint[GS(cl)->getHero(hid)->tempOwner]->heroVisitsTown(GS(cl)->getHero(hid),GS(cl)->getTown(tid));
  62. }
  63. }
  64. void ChangeSpells::applyCl( CClient *cl )
  65. {
  66. //TODO: inform interface?
  67. }
  68. void SetMana::applyCl( CClient *cl )
  69. {
  70. CGHeroInstance *h = GS(cl)->getHero(hid);
  71. if(vstd::contains(cl->playerint,h->tempOwner))
  72. cl->playerint[h->tempOwner]->heroManaPointsChanged(h);
  73. }
  74. void SetMovePoints::applyCl( CClient *cl )
  75. {
  76. CGHeroInstance *h = GS(cl)->getHero(hid);
  77. if(vstd::contains(cl->playerint,h->tempOwner))
  78. cl->playerint[h->tempOwner]->heroMovePointsChanged(h);
  79. }
  80. void FoWChange::applyCl( CClient *cl )
  81. {
  82. if(!vstd::contains(cl->playerint,player))
  83. return;
  84. if(mode)
  85. cl->playerint[player]->tileRevealed(tiles);
  86. else
  87. cl->playerint[player]->tileHidden(tiles);
  88. if (cl->IGameCallback::getSelectedHero(player))//if we have selected hero...
  89. GS(cl)->calculatePaths(cl->IGameCallback::getSelectedHero(player), *cl->pathInfo);
  90. }
  91. void SetAvailableHeroes::applyCl( CClient *cl )
  92. {
  93. //TODO: inform interface?
  94. }
  95. void GiveBonus::applyCl( CClient *cl )
  96. {
  97. CGHeroInstance *h = GS(cl)->getHero(hid);
  98. if(vstd::contains(cl->playerint,h->tempOwner))
  99. cl->playerint[h->tempOwner]->heroBonusChanged(h,h->bonuses.back(),true);
  100. }
  101. void ChangeObjPos::applyFirstCl( CClient *cl )
  102. {
  103. CGObjectInstance *obj = GS(cl)->map->objects[objid];
  104. if(flags & 1)
  105. CGI->mh->hideObject(obj);
  106. }
  107. void ChangeObjPos::applyCl( CClient *cl )
  108. {
  109. CGObjectInstance *obj = GS(cl)->map->objects[objid];
  110. if(flags & 1)
  111. CGI->mh->printObject(obj);
  112. }
  113. void RemoveObject::applyFirstCl( CClient *cl )
  114. {
  115. const CGObjectInstance *o = cl->getObj(id);
  116. CGI->mh->hideObject(o);
  117. int3 pos = o->pos - o->getVisitableOffset();
  118. //notify interfaces about removal
  119. for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)
  120. {
  121. if(i->first >= PLAYER_LIMIT) continue;
  122. if(GS(cl)->players[i->first].fogOfWarMap[pos.x][pos.y][pos.z])
  123. {
  124. i->second->objectRemoved(o);
  125. }
  126. }
  127. }
  128. void RemoveObject::applyCl( CClient *cl )
  129. {
  130. if(cl->pathInfo->hero)
  131. GS(cl)->calculatePaths(cl->pathInfo->hero, *cl->pathInfo);
  132. }
  133. void TryMoveHero::applyFirstCl( CClient *cl )
  134. {
  135. CGHeroInstance *h = GS(cl)->getHero(id);
  136. //check if playerint will have the knowledge about movement - if not, directly update maphandler
  137. for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)
  138. {
  139. if(i->first >= PLAYER_LIMIT)
  140. continue;
  141. PlayerState &p = GS(cl)->players[i->first];
  142. if((p.fogOfWarMap[start.x-1][start.y][start.z] || p.fogOfWarMap[end.x-1][end.y][end.z]) && p.human)
  143. humanKnows = true;
  144. }
  145. if(result == TELEPORTATION || result == EMBARK || result == DISEMBARK || !humanKnows)
  146. CGI->mh->removeObject(h);
  147. if(result == DISEMBARK)
  148. CGI->mh->printObject(h->boat);
  149. }
  150. void TryMoveHero::applyCl( CClient *cl )
  151. {
  152. const CGHeroInstance *h = cl->getHero(id);
  153. if(result == TELEPORTATION || result == EMBARK || result == DISEMBARK)
  154. CGI->mh->printObject(h);
  155. if(result == EMBARK)
  156. CGI->mh->hideObject(h->boat);
  157. int player = h->tempOwner;
  158. if(vstd::contains(cl->playerint,player))
  159. {
  160. cl->playerint[player]->tileRevealed(fowRevealed);
  161. }
  162. //notify interfaces about move
  163. for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)
  164. {
  165. if(i->first >= PLAYER_LIMIT) continue;
  166. PlayerState &p = GS(cl)->players[i->first];
  167. if(p.fogOfWarMap[start.x-1][start.y][start.z] || p.fogOfWarMap[end.x-1][end.y][end.z])
  168. {
  169. i->second->heroMoved(*this);
  170. }
  171. }
  172. if(!humanKnows) //maphandler didn't get update from playerint, do it now
  173. { //TODO: restructure nicely
  174. CGI->mh->printObject(h);
  175. }
  176. }
  177. void SetGarrisons::applyCl( CClient *cl )
  178. {
  179. for(std::map<ui32,CCreatureSet>::iterator i = garrs.begin(); i!=garrs.end(); i++)
  180. if(vstd::contains(cl->playerint,cl->getOwner(i->first)))
  181. cl->playerint[cl->getOwner(i->first)]->garrisonChanged(cl->getObj(i->first));
  182. }
  183. void NewStructures::applyCl( CClient *cl )
  184. {
  185. CGTownInstance *town = GS(cl)->getTown(tid);
  186. BOOST_FOREACH(si32 id, bid)
  187. {
  188. if(id==13) //fort or capitol
  189. {
  190. town->defInfo = GS(cl)->capitols[town->subID];
  191. }
  192. if(id ==7)
  193. {
  194. town->defInfo = GS(cl)->forts[town->subID];
  195. }
  196. if(vstd::contains(cl->playerint,town->tempOwner))
  197. cl->playerint[town->tempOwner]->buildChanged(town,id,1);
  198. }
  199. }
  200. void RazeStructures::applyCl (CClient *cl)
  201. {
  202. CGTownInstance *town = GS(cl)->getTown(tid);
  203. BOOST_FOREACH(si32 id, bid)
  204. {
  205. if (id == 13) //fort or capitol
  206. {
  207. town->defInfo = GS(cl)->forts[town->subID];
  208. }
  209. if(vstd::contains (cl->playerint,town->tempOwner))
  210. cl->playerint[town->tempOwner]->buildChanged (town,id,2);
  211. }
  212. }
  213. void SetAvailableCreatures::applyCl( CClient *cl )
  214. {
  215. const CGDwelling *dw = static_cast<const CGDwelling*>(cl->getObj(tid));
  216. if(vstd::contains(cl->playerint,dw->tempOwner))
  217. cl->playerint[dw->tempOwner]->availableCreaturesChanged(dw);
  218. }
  219. void SetHeroesInTown::applyCl( CClient *cl )
  220. {
  221. CGTownInstance *t = GS(cl)->getTown(tid);
  222. if(vstd::contains(cl->playerint,t->tempOwner))
  223. cl->playerint[t->tempOwner]->heroInGarrisonChange(t);
  224. }
  225. void SetHeroArtifacts::applyCl( CClient *cl )
  226. {
  227. CGHeroInstance *h = GS(cl)->getHero(hid);
  228. CGameInterface *player = (vstd::contains(cl->playerint,h->tempOwner) ? cl->playerint[h->tempOwner] : NULL);
  229. if(!player)
  230. return;
  231. player->heroArtifactSetChanged(h);
  232. BOOST_FOREACH(HeroBonus *bonus, gained)
  233. {
  234. player->heroBonusChanged(h,*bonus,true);
  235. }
  236. BOOST_FOREACH(HeroBonus *bonus, lost)
  237. {
  238. player->heroBonusChanged(h,*bonus,false);
  239. }
  240. }
  241. void HeroRecruited::applyCl( CClient *cl )
  242. {
  243. CGHeroInstance *h = GS(cl)->map->heroes.back();
  244. if(h->subID != hid)
  245. {
  246. tlog1 << "Something wrong with hero recruited!\n";
  247. }
  248. CGI->mh->initHeroDef(h);
  249. CGI->mh->printObject(h);
  250. if(vstd::contains(cl->playerint,h->tempOwner))
  251. {
  252. cl->playerint[h->tempOwner]->heroCreated(h);
  253. cl->playerint[h->tempOwner]->heroInGarrisonChange(GS(cl)->getTown(tid));
  254. }
  255. }
  256. void GiveHero::applyCl( CClient *cl )
  257. {
  258. CGHeroInstance *h = GS(cl)->getHero(id);
  259. CGI->mh->initHeroDef(h);
  260. CGI->mh->printObject(h);
  261. cl->playerint[h->tempOwner]->heroCreated(h);
  262. }
  263. void GiveHero::applyFirstCl( CClient *cl )
  264. {
  265. CGI->mh->hideObject(GS(cl)->getHero(id));
  266. }
  267. void InfoWindow::applyCl( CClient *cl )
  268. {
  269. std::vector<Component*> comps;
  270. for(size_t i=0;i<components.size();i++)
  271. {
  272. comps.push_back(&components[i]);
  273. }
  274. std::string str;
  275. text.toString(str);
  276. if(vstd::contains(cl->playerint,player))
  277. cl->playerint[player]->showInfoDialog(str,comps,(soundBase::soundID)soundID);
  278. else
  279. tlog2 << "We received InfoWindow for not our player...\n";
  280. }
  281. void SetObjectProperty::applyCl( CClient *cl )
  282. {
  283. //inform all players that see this object
  284. for(std::map<ui8,CGameInterface *>::const_iterator it = cl->playerint.begin(); it != cl->playerint.end(); ++it)
  285. {
  286. if(GS(cl)->isVisible(GS(cl)->map->objects[id], it->first))
  287. INTERFACE_CALL_IF_PRESENT(it->first, objectPropertyChanged, this);
  288. }
  289. }
  290. void HeroLevelUp::applyCl( CClient *cl )
  291. {
  292. CGHeroInstance *h = GS(cl)->getHero(heroid);
  293. if(vstd::contains(cl->playerint,h->tempOwner))
  294. {
  295. boost::function<void(ui32)> callback = boost::function<void(ui32)>(boost::bind(&CCallback::selectionMade,LOCPLINT->cb,_1,id));
  296. cl->playerint[h->tempOwner]->heroGotLevel(const_cast<const CGHeroInstance*>(h),static_cast<int>(primskill),skills, callback);
  297. }
  298. }
  299. void BlockingDialog::applyCl( CClient *cl )
  300. {
  301. std::string str;
  302. text.toString(str);
  303. if(vstd::contains(cl->playerint,player))
  304. cl->playerint[player]->showBlockingDialog(str,components,id,(soundBase::soundID)soundID,selection(),cancel());
  305. else
  306. tlog2 << "We received YesNoDialog for not our player...\n";
  307. }
  308. void GarrisonDialog::applyCl(CClient *cl)
  309. {
  310. const CGHeroInstance *h = cl->getHero(hid);
  311. const CArmedInstance *obj = static_cast<const CArmedInstance*>(cl->getObj(objid));
  312. if(!vstd::contains(cl->playerint,h->getOwner()))
  313. return;
  314. boost::function<void()> callback = boost::bind(&CCallback::selectionMade,LOCPLINT->cb,0,id);
  315. cl->playerint[h->getOwner()]->showGarrisonDialog(obj,h,removableUnits,callback);
  316. }
  317. void BattleStart::applyCl( CClient *cl )
  318. {
  319. if(vstd::contains(cl->playerint,info->side1))
  320. cl->playerint[info->side1]->battleStart(&info->army1, &info->army2, info->tile, info->heroes[0], info->heroes[1], 0);
  321. if(vstd::contains(cl->playerint,info->side2))
  322. cl->playerint[info->side2]->battleStart(&info->army1, &info->army2, info->tile, info->heroes[0], info->heroes[1], 1);
  323. }
  324. void BattleNextRound::applyCl( CClient *cl )
  325. {
  326. if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
  327. cl->playerint[GS(cl)->curB->side1]->battleNewRound(round);
  328. if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
  329. cl->playerint[GS(cl)->curB->side2]->battleNewRound(round);
  330. }
  331. void BattleSetActiveStack::applyCl( CClient *cl )
  332. {
  333. CStack * activated = GS(cl)->curB->getStack(stack);
  334. int playerToCall = -1; //player that will move activated stack
  335. if( activated->hasFeatureOfType(StackFeature::HYPNOTIZED) )
  336. {
  337. playerToCall = ( GS(cl)->curB->side1 == activated->owner ? GS(cl)->curB->side2 : GS(cl)->curB->side1 );
  338. }
  339. else
  340. {
  341. playerToCall = activated->owner;
  342. }
  343. if( vstd::contains(cl->playerint, playerToCall) )
  344. boost::thread( boost::bind(&CClient::waitForMoveAndSend, cl, playerToCall) );
  345. }
  346. void BattleResult::applyFirstCl( CClient *cl )
  347. {
  348. if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
  349. cl->playerint[GS(cl)->curB->side1]->battleEnd(this);
  350. if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
  351. cl->playerint[GS(cl)->curB->side2]->battleEnd(this);
  352. }
  353. void BattleStackMoved::applyFirstCl( CClient *cl )
  354. {
  355. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleStackMoved,stack,tile,distance,ending);
  356. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleStackMoved,stack,tile,distance,ending);
  357. }
  358. void BattleStackAttacked::applyCl( CClient *cl )
  359. {
  360. std::set<BattleStackAttacked> bsa;
  361. bsa.insert(*this);
  362. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleStacksAttacked,bsa);
  363. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleStacksAttacked,bsa);
  364. }
  365. void BattleAttack::applyFirstCl( CClient *cl )
  366. {
  367. if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
  368. cl->playerint[GS(cl)->curB->side1]->battleAttack(this);
  369. if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
  370. cl->playerint[GS(cl)->curB->side2]->battleAttack(this);
  371. }
  372. void BattleAttack::applyCl( CClient *cl )
  373. {
  374. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleStacksAttacked,bsa);
  375. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleStacksAttacked,bsa);
  376. }
  377. void StartAction::applyFirstCl( CClient *cl )
  378. {
  379. cl->curbaction = new BattleAction(ba);
  380. if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
  381. cl->playerint[GS(cl)->curB->side1]->actionStarted(&ba);
  382. if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
  383. cl->playerint[GS(cl)->curB->side2]->actionStarted(&ba);
  384. }
  385. void SpellCast::applyCl( CClient *cl )
  386. {
  387. if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
  388. cl->playerint[GS(cl)->curB->side1]->battleSpellCast(this);
  389. if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
  390. cl->playerint[GS(cl)->curB->side2]->battleSpellCast(this);
  391. if(id >= 66 && id <= 69) //elemental summoning
  392. {
  393. if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
  394. cl->playerint[GS(cl)->curB->side1]->battleNewStackAppeared(GS(cl)->curB->stacks.size() - 1);
  395. if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
  396. cl->playerint[GS(cl)->curB->side2]->battleNewStackAppeared(GS(cl)->curB->stacks.size() - 1);
  397. }
  398. }
  399. void SetStackEffect::applyCl( CClient *cl )
  400. {
  401. SpellCast sc;
  402. sc.id = effect.id;
  403. sc.side = 3; //doesn't matter
  404. sc.skill = effect.level;
  405. //informing about effects
  406. if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
  407. cl->playerint[GS(cl)->curB->side1]->battleStacksEffectsSet(*this);
  408. if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
  409. cl->playerint[GS(cl)->curB->side2]->battleStacksEffectsSet(*this);
  410. }
  411. void StacksInjured::applyCl( CClient *cl )
  412. {
  413. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleStacksAttacked,stacks);
  414. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleStacksAttacked,stacks);
  415. }
  416. void BattleResultsApplied::applyCl( CClient *cl )
  417. {
  418. INTERFACE_CALL_IF_PRESENT(player1,battleResultsApplied);
  419. INTERFACE_CALL_IF_PRESENT(player2,battleResultsApplied);
  420. }
  421. void StacksHealedOrResurrected::applyCl( CClient *cl )
  422. {
  423. std::vector<std::pair<ui32, ui32> > shiftedHealed;
  424. for(int v=0; v<healedStacks.size(); ++v)
  425. {
  426. shiftedHealed.push_back(std::make_pair(healedStacks[v].stackID, healedStacks[v].healedHP));
  427. }
  428. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1, battleStacksHealedRes, shiftedHealed);
  429. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2, battleStacksHealedRes, shiftedHealed);
  430. }
  431. void ObstaclesRemoved::applyCl( CClient *cl )
  432. {
  433. //inform interfaces about removed obstacles
  434. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1, battleObstaclesRemoved, obstacles);
  435. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2, battleObstaclesRemoved, obstacles);
  436. }
  437. void CatapultAttack::applyCl( CClient *cl )
  438. {
  439. //inform interfaces about catapult attack
  440. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1, battleCatapultAttacked, *this);
  441. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2, battleCatapultAttacked, *this);
  442. }
  443. void BattleStacksRemoved::applyCl( CClient *cl )
  444. {
  445. //inform interfaces about removed stacks
  446. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1, battleStacksRemoved, *this);
  447. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2, battleStacksRemoved, *this);
  448. }
  449. CGameState* CPackForClient::GS( CClient *cl )
  450. {
  451. return cl->gs;
  452. }
  453. void EndAction::applyCl( CClient *cl )
  454. {
  455. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,actionFinished,cl->curbaction);
  456. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,actionFinished,cl->curbaction);
  457. delete cl->curbaction;
  458. cl->curbaction = NULL;
  459. }
  460. void PackageApplied::applyCl( CClient *cl )
  461. {
  462. ui8 player = GS(cl)->currentPlayer;
  463. INTERFACE_CALL_IF_PRESENT(player, requestRealized, this);
  464. if(cl->waitingRequest.get())
  465. cl->waitingRequest.setn(false);
  466. }
  467. void SystemMessage::applyCl( CClient *cl )
  468. {
  469. std::ostringstream str;
  470. str << "System message: " << text;
  471. tlog4 << str.str() << std::endl;
  472. if(LOCPLINT)
  473. LOCPLINT->cingconsole->print(str.str());
  474. }
  475. void PlayerBlocked::applyCl( CClient *cl )
  476. {
  477. INTERFACE_CALL_IF_PRESENT(player,playerBlocked,reason);
  478. }
  479. void YourTurn::applyCl( CClient *cl )
  480. {
  481. INTERFACE_CALL_IF_PRESENT(player,yourTurn);
  482. }
  483. void SaveGame::applyCl(CClient *cl)
  484. {
  485. CSaveFile save(GVCMIDirs.UserPath + "/Games/" + fname + ".vcgm1");
  486. save << *cl;
  487. }
  488. void PlayerMessage::applyCl(CClient *cl)
  489. {
  490. std::ostringstream str;
  491. str << "Player "<<(int)player<<" sends a message: " << text;
  492. tlog4 << str.str() << std::endl;
  493. if(LOCPLINT)
  494. LOCPLINT->cingconsole->print(str.str());
  495. }
  496. void SetSelection::applyCl(CClient *cl)
  497. {
  498. const CGHeroInstance *h = cl->getHero(id);
  499. if(!h)
  500. return;
  501. //CPackForClient::GS(cl)->calculatePaths(h, *cl->pathInfo);
  502. }
  503. void ShowInInfobox::applyCl(CClient *cl)
  504. {
  505. SComponent sc(c);
  506. text.toString(sc.description);
  507. if(cl->playerint[player]->human)
  508. {
  509. static_cast<CPlayerInterface*>(cl->playerint[player])->showComp(sc);
  510. }
  511. }
  512. void OpenWindow::applyCl(CClient *cl)
  513. {
  514. switch(window)
  515. {
  516. case EXCHANGE_WINDOW:
  517. {
  518. const CGHeroInstance *h = cl->getHero(id1);
  519. const CGObjectInstance *h2 = cl->getHero(id2);
  520. assert(h && h2);
  521. INTERFACE_CALL_IF_PRESENT(h->tempOwner,heroExchangeStarted, id1, id2);
  522. }
  523. break;
  524. case RECRUITMENT_FIRST:
  525. case RECRUITMENT_ALL:
  526. {
  527. const CGDwelling *dw = dynamic_cast<const CGDwelling*>(cl->getObj(id1));
  528. const CArmedInstance *dst = dynamic_cast<const CArmedInstance*>(cl->getObj(id2));
  529. INTERFACE_CALL_IF_PRESENT(dw->tempOwner,showRecruitmentDialog, dw, dst, window == RECRUITMENT_FIRST ? 0 : -1);
  530. }
  531. break;
  532. case SHIPYARD_WINDOW:
  533. {
  534. const IShipyard *sy = IShipyard::castFrom(cl->getObj(id1));
  535. INTERFACE_CALL_IF_PRESENT(sy->o->tempOwner, showShipyardDialog, sy);
  536. }
  537. break;
  538. }
  539. }
  540. void CenterView::applyCl(CClient *cl)
  541. {
  542. INTERFACE_CALL_IF_PRESENT (player, centerView, pos, focusTime);
  543. }
  544. void NewObject::applyCl(CClient *cl)
  545. {
  546. const CGObjectInstance *obj = cl->getObj(id);
  547. //notify interfaces about move
  548. for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)
  549. {
  550. //TODO: check if any covered tile is visible
  551. if(i->first >= PLAYER_LIMIT) continue;
  552. if(GS(cl)->players[i->first].fogOfWarMap[obj->pos.x][obj->pos.y][obj->pos.z])
  553. {
  554. i->second->newObject(obj);
  555. }
  556. }
  557. }
  558. void TradeComponents::applyCl(CClient *cl)
  559. {///Shop handler
  560. switch (CGI->mh->map->objects[objectid]->ID)
  561. {
  562. case 7: //Black Market
  563. break;
  564. case 95: //Tavern
  565. break;
  566. case 97: //Den of Thieves
  567. break;
  568. case 221: //Trading Post
  569. break;
  570. default:
  571. tlog2 << "Shop type not supported! \n";
  572. }
  573. }