NetPacksClient.cpp 18 KB

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