NetPacksClient.cpp 18 KB

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