NetPacksClient.cpp 19 KB

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