NetPacksClient.cpp 19 KB

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