NetPacksClient.cpp 18 KB

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