NetPacksClient.cpp 19 KB

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