NetPacksClient.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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. #include "CConfigHandler.h"
  23. #include "SDL_Extensions.h"
  24. #include "CBattleInterface.h"
  25. //macro to avoid code duplication - calls given method with given arguments if interface for specific player is present
  26. #define INTERFACE_CALL_IF_PRESENT(player,function,...) \
  27. if(vstd::contains(cl->playerint,player)) \
  28. cl->playerint[player]->function(__VA_ARGS__);
  29. /*
  30. * NetPacksClient.cpp, part of VCMI engine
  31. *
  32. * Authors: listed in file AUTHORS in main folder
  33. *
  34. * License: GNU General Public License v2.0 or later
  35. * Full text of license available in license.txt file, in main folder
  36. *
  37. */
  38. void SetResources::applyCl( CClient *cl )
  39. {
  40. cl->playerint[player]->receivedResource(-1,-1);
  41. }
  42. void SetResource::applyCl( CClient *cl )
  43. {
  44. cl->playerint[player]->receivedResource(resid,val);
  45. }
  46. void SetPrimSkill::applyCl( CClient *cl )
  47. {
  48. const CGHeroInstance *h = GS(cl)->getHero(id);
  49. if(!h)
  50. {
  51. tlog1 << "Cannot find hero with ID " << id << std::endl;
  52. return;
  53. }
  54. INTERFACE_CALL_IF_PRESENT(h->tempOwner,heroPrimarySkillChanged,h,which,val);
  55. }
  56. void SetSecSkill::applyCl( CClient *cl )
  57. {
  58. //TODO: inform interface?
  59. }
  60. void HeroVisitCastle::applyCl( CClient *cl )
  61. {
  62. if(start() && !garrison() && vstd::contains(cl->playerint,GS(cl)->getHero(hid)->tempOwner))
  63. {
  64. cl->playerint[GS(cl)->getHero(hid)->tempOwner]->heroVisitsTown(GS(cl)->getHero(hid),GS(cl)->getTown(tid));
  65. }
  66. }
  67. void ChangeSpells::applyCl( CClient *cl )
  68. {
  69. //TODO: inform interface?
  70. }
  71. void SetMana::applyCl( CClient *cl )
  72. {
  73. CGHeroInstance *h = GS(cl)->getHero(hid);
  74. if(vstd::contains(cl->playerint,h->tempOwner))
  75. cl->playerint[h->tempOwner]->heroManaPointsChanged(h);
  76. }
  77. void SetMovePoints::applyCl( CClient *cl )
  78. {
  79. CGHeroInstance *h = GS(cl)->getHero(hid);
  80. if (cl->IGameCallback::getSelectedHero(LOCPLINT->playerID) == h)//if we have selected that hero
  81. {
  82. GS(cl)->calculatePaths(h, *cl->pathInfo);
  83. }
  84. if(vstd::contains(cl->playerint,h->tempOwner))
  85. cl->playerint[h->tempOwner]->heroMovePointsChanged(h);
  86. }
  87. void FoWChange::applyCl( CClient *cl )
  88. {
  89. if(!vstd::contains(cl->playerint,player))
  90. return;
  91. if(mode)
  92. cl->playerint[player]->tileRevealed(tiles);
  93. else
  94. cl->playerint[player]->tileHidden(tiles);
  95. cl->updatePaths();
  96. }
  97. void SetAvailableHeroes::applyCl( CClient *cl )
  98. {
  99. //TODO: inform interface?
  100. }
  101. void GiveBonus::applyCl( CClient *cl )
  102. {
  103. switch(who)
  104. {
  105. case HERO:
  106. {
  107. const CGHeroInstance *h = GS(cl)->getHero(id);
  108. INTERFACE_CALL_IF_PRESENT(h->tempOwner, heroBonusChanged, h, h->bonuses.back(),true);
  109. }
  110. break;
  111. case PLAYER:
  112. {
  113. const PlayerState *p = GS(cl)->getPlayer(id);
  114. INTERFACE_CALL_IF_PRESENT(id, playerBonusChanged, p->bonuses.back(), true);
  115. }
  116. break;
  117. }
  118. }
  119. void ChangeObjPos::applyFirstCl( CClient *cl )
  120. {
  121. CGObjectInstance *obj = GS(cl)->map->objects[objid];
  122. if(flags & 1)
  123. CGI->mh->hideObject(obj);
  124. }
  125. void ChangeObjPos::applyCl( CClient *cl )
  126. {
  127. CGObjectInstance *obj = GS(cl)->map->objects[objid];
  128. if(flags & 1)
  129. CGI->mh->printObject(obj);
  130. cl->updatePaths();
  131. }
  132. void PlayerEndsGame::applyCl( CClient *cl )
  133. {
  134. for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)
  135. i->second->gameOver(player, victory);
  136. }
  137. void RemoveBonus::applyCl( CClient *cl )
  138. {
  139. switch(who)
  140. {
  141. case HERO:
  142. {
  143. const CGHeroInstance *h = GS(cl)->getHero(id);
  144. INTERFACE_CALL_IF_PRESENT(h->tempOwner, heroBonusChanged, h, bonus,false);
  145. }
  146. break;
  147. case PLAYER:
  148. {
  149. const PlayerState *p = GS(cl)->getPlayer(id);
  150. INTERFACE_CALL_IF_PRESENT(id, playerBonusChanged, bonus, false);
  151. }
  152. break;
  153. }
  154. }
  155. void RemoveObject::applyFirstCl( CClient *cl )
  156. {
  157. const CGObjectInstance *o = cl->getObj(id);
  158. CGI->mh->hideObject(o);
  159. int3 pos = o->pos - o->getVisitableOffset();
  160. //notify interfaces about removal
  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. if(GS(cl)->players[i->first].fogOfWarMap[pos.x][pos.y][pos.z])
  165. {
  166. i->second->objectRemoved(o);
  167. }
  168. }
  169. }
  170. void RemoveObject::applyCl( CClient *cl )
  171. {
  172. if(cl->pathInfo->hero && cl->pathInfo->hero->id != id)
  173. GS(cl)->calculatePaths(cl->pathInfo->hero, *cl->pathInfo);
  174. }
  175. void TryMoveHero::applyFirstCl( CClient *cl )
  176. {
  177. CGHeroInstance *h = GS(cl)->getHero(id);
  178. //check if playerint will have the knowledge about movement - if not, directly update maphandler
  179. for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)
  180. {
  181. if(i->first >= PLAYER_LIMIT)
  182. continue;
  183. PlayerState &p = GS(cl)->players[i->first];
  184. if((p.fogOfWarMap[start.x-1][start.y][start.z] || p.fogOfWarMap[end.x-1][end.y][end.z]) && p.human)
  185. humanKnows = true;
  186. }
  187. if(result == TELEPORTATION || result == EMBARK || result == DISEMBARK || !humanKnows)
  188. CGI->mh->removeObject(h);
  189. if(result == DISEMBARK)
  190. CGI->mh->printObject(h->boat);
  191. }
  192. void TryMoveHero::applyCl( CClient *cl )
  193. {
  194. const CGHeroInstance *h = cl->getHero(id);
  195. if(result == TELEPORTATION || result == EMBARK || result == DISEMBARK)
  196. CGI->mh->printObject(h);
  197. if(result == EMBARK)
  198. CGI->mh->hideObject(h->boat);
  199. int player = h->tempOwner;
  200. if(vstd::contains(cl->playerint,player))
  201. {
  202. cl->playerint[player]->tileRevealed(fowRevealed);
  203. }
  204. //notify interfaces about move
  205. for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)
  206. {
  207. if(i->first >= PLAYER_LIMIT) continue;
  208. PlayerState &p = GS(cl)->players[i->first];
  209. if(p.fogOfWarMap[start.x-1][start.y][start.z] || p.fogOfWarMap[end.x-1][end.y][end.z])
  210. {
  211. i->second->heroMoved(*this);
  212. }
  213. }
  214. if(!humanKnows) //maphandler didn't get update from playerint, do it now
  215. { //TODO: restructure nicely
  216. CGI->mh->printObject(h);
  217. }
  218. }
  219. void SetGarrisons::applyCl( CClient *cl )
  220. {
  221. for(std::map<ui32,CCreatureSet>::iterator i = garrs.begin(); i!=garrs.end(); i++)
  222. if(vstd::contains(cl->playerint,cl->getOwner(i->first)))
  223. cl->playerint[cl->getOwner(i->first)]->garrisonChanged(cl->getObj(i->first));
  224. }
  225. void NewStructures::applyCl( CClient *cl )
  226. {
  227. CGTownInstance *town = GS(cl)->getTown(tid);
  228. BOOST_FOREACH(si32 id, bid)
  229. {
  230. if(id==13) //fort or capitol
  231. {
  232. town->defInfo = GS(cl)->capitols[town->subID];
  233. }
  234. if(id ==7)
  235. {
  236. town->defInfo = GS(cl)->forts[town->subID];
  237. }
  238. if(vstd::contains(cl->playerint,town->tempOwner))
  239. cl->playerint[town->tempOwner]->buildChanged(town,id,1);
  240. }
  241. }
  242. void RazeStructures::applyCl (CClient *cl)
  243. {
  244. CGTownInstance *town = GS(cl)->getTown(tid);
  245. BOOST_FOREACH(si32 id, bid)
  246. {
  247. if (id == 13) //fort or capitol
  248. {
  249. town->defInfo = GS(cl)->forts[town->subID];
  250. }
  251. if(vstd::contains (cl->playerint,town->tempOwner))
  252. cl->playerint[town->tempOwner]->buildChanged (town,id,2);
  253. }
  254. }
  255. void SetAvailableCreatures::applyCl( CClient *cl )
  256. {
  257. const CGDwelling *dw = static_cast<const CGDwelling*>(cl->getObj(tid));
  258. if(vstd::contains(cl->playerint,dw->tempOwner))
  259. cl->playerint[dw->tempOwner]->availableCreaturesChanged(dw);
  260. }
  261. void SetHeroesInTown::applyCl( CClient *cl )
  262. {
  263. CGTownInstance *t = GS(cl)->getTown(tid);
  264. if(vstd::contains(cl->playerint,t->tempOwner))
  265. cl->playerint[t->tempOwner]->heroInGarrisonChange(t);
  266. }
  267. void SetHeroArtifacts::applyCl( CClient *cl )
  268. {
  269. CGHeroInstance *h = GS(cl)->getHero(hid);
  270. CGameInterface *player = (vstd::contains(cl->playerint,h->tempOwner) ? cl->playerint[h->tempOwner] : NULL);
  271. if(!player)
  272. return;
  273. h->recreateArtBonuses();
  274. player->heroArtifactSetChanged(h);
  275. BOOST_FOREACH(Bonus bonus, gained)
  276. {
  277. player->heroBonusChanged(h,bonus,true);
  278. }
  279. BOOST_FOREACH(Bonus bonus, lost)
  280. {
  281. player->heroBonusChanged(h,bonus,false);
  282. }
  283. }
  284. void HeroRecruited::applyCl( CClient *cl )
  285. {
  286. CGHeroInstance *h = GS(cl)->map->heroes.back();
  287. if(h->subID != hid)
  288. {
  289. tlog1 << "Something wrong with hero recruited!\n";
  290. }
  291. CGI->mh->initHeroDef(h);
  292. CGI->mh->printObject(h);
  293. if(vstd::contains(cl->playerint,h->tempOwner))
  294. {
  295. cl->playerint[h->tempOwner]->heroCreated(h);
  296. cl->playerint[h->tempOwner]->heroInGarrisonChange(GS(cl)->getTown(tid));
  297. }
  298. }
  299. void GiveHero::applyCl( CClient *cl )
  300. {
  301. CGHeroInstance *h = GS(cl)->getHero(id);
  302. CGI->mh->initHeroDef(h);
  303. CGI->mh->printObject(h);
  304. cl->playerint[h->tempOwner]->heroCreated(h);
  305. }
  306. void GiveHero::applyFirstCl( CClient *cl )
  307. {
  308. CGI->mh->hideObject(GS(cl)->getHero(id));
  309. }
  310. void InfoWindow::applyCl( CClient *cl )
  311. {
  312. std::vector<Component*> comps;
  313. for(size_t i=0;i<components.size();i++)
  314. {
  315. comps.push_back(&components[i]);
  316. }
  317. std::string str;
  318. text.toString(str);
  319. if(vstd::contains(cl->playerint,player))
  320. cl->playerint[player]->showInfoDialog(str,comps,(soundBase::soundID)soundID);
  321. else
  322. tlog2 << "We received InfoWindow for not our player...\n";
  323. }
  324. void SetObjectProperty::applyCl( CClient *cl )
  325. {
  326. //inform all players that see this object
  327. for(std::map<ui8,CGameInterface *>::const_iterator it = cl->playerint.begin(); it != cl->playerint.end(); ++it)
  328. {
  329. if(GS(cl)->isVisible(GS(cl)->map->objects[id], it->first))
  330. INTERFACE_CALL_IF_PRESENT(it->first, objectPropertyChanged, this);
  331. }
  332. }
  333. void HeroLevelUp::applyCl( CClient *cl )
  334. {
  335. CGHeroInstance *h = GS(cl)->getHero(heroid);
  336. if(vstd::contains(cl->playerint,h->tempOwner))
  337. {
  338. boost::function<void(ui32)> callback = boost::function<void(ui32)>(boost::bind(&CCallback::selectionMade,LOCPLINT->cb,_1,id));
  339. cl->playerint[h->tempOwner]->heroGotLevel(const_cast<const CGHeroInstance*>(h),static_cast<int>(primskill),skills, callback);
  340. }
  341. }
  342. void BlockingDialog::applyCl( CClient *cl )
  343. {
  344. std::string str;
  345. text.toString(str);
  346. if(vstd::contains(cl->playerint,player))
  347. cl->playerint[player]->showBlockingDialog(str,components,id,(soundBase::soundID)soundID,selection(),cancel());
  348. else
  349. tlog2 << "We received YesNoDialog for not our player...\n";
  350. }
  351. void GarrisonDialog::applyCl(CClient *cl)
  352. {
  353. const CGHeroInstance *h = cl->getHero(hid);
  354. const CArmedInstance *obj = static_cast<const CArmedInstance*>(cl->getObj(objid));
  355. if(!vstd::contains(cl->playerint,h->getOwner()))
  356. return;
  357. boost::function<void()> callback = boost::bind(&CCallback::selectionMade,LOCPLINT->cb,0,id);
  358. cl->playerint[h->getOwner()]->showGarrisonDialog(obj,h,removableUnits,callback);
  359. }
  360. void BattleStart::applyCl( CClient *cl )
  361. {
  362. CPlayerInterface * att, * def;
  363. if(vstd::contains(cl->playerint, info->side1) && cl->playerint[info->side1]->human)
  364. att = static_cast<CPlayerInterface*>( cl->playerint[info->side1] );
  365. else
  366. att = NULL;
  367. if(vstd::contains(cl->playerint, info->side2) && cl->playerint[info->side2]->human)
  368. def = static_cast<CPlayerInterface*>( cl->playerint[info->side2] );
  369. else
  370. def = NULL;
  371. new CBattleInterface(info->belligerents[0], info->belligerents[1], info->heroes[0], info->heroes[1], genRect(600, 800, (conf.cc.resx - 800)/2, (conf.cc.resy - 600)/2), att, def);
  372. if(vstd::contains(cl->playerint,info->side1))
  373. cl->playerint[info->side1]->battleStart(info->belligerents[0], info->belligerents[1], info->tile, info->heroes[0], info->heroes[1], 0);
  374. if(vstd::contains(cl->playerint,info->side2))
  375. cl->playerint[info->side2]->battleStart(info->belligerents[0], info->belligerents[1], info->tile, info->heroes[0], info->heroes[1], 1);
  376. }
  377. void BattleNextRound::applyFirstCl(CClient *cl)
  378. {
  379. if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
  380. cl->playerint[GS(cl)->curB->side1]->battleNewRoundFirst(round);
  381. if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
  382. cl->playerint[GS(cl)->curB->side2]->battleNewRoundFirst(round);
  383. }
  384. void BattleNextRound::applyCl( CClient *cl )
  385. {
  386. if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
  387. cl->playerint[GS(cl)->curB->side1]->battleNewRound(round);
  388. if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
  389. cl->playerint[GS(cl)->curB->side2]->battleNewRound(round);
  390. }
  391. void BattleSetActiveStack::applyCl( CClient *cl )
  392. {
  393. CStack * activated = GS(cl)->curB->getStack(stack);
  394. int playerToCall = -1; //player that will move activated stack
  395. if( activated->hasBonusOfType(Bonus::HYPNOTIZED) )
  396. {
  397. playerToCall = ( GS(cl)->curB->side1 == activated->owner ? GS(cl)->curB->side2 : GS(cl)->curB->side1 );
  398. }
  399. else
  400. {
  401. playerToCall = activated->owner;
  402. }
  403. if( vstd::contains(cl->playerint, playerToCall) )
  404. boost::thread( boost::bind(&CClient::waitForMoveAndSend, cl, playerToCall) );
  405. }
  406. void BattleResult::applyFirstCl( CClient *cl )
  407. {
  408. if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
  409. cl->playerint[GS(cl)->curB->side1]->battleEnd(this);
  410. if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
  411. cl->playerint[GS(cl)->curB->side2]->battleEnd(this);
  412. }
  413. void BattleStackMoved::applyFirstCl( CClient *cl )
  414. {
  415. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleStackMoved,stack,tile,distance,ending);
  416. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleStackMoved,stack,tile,distance,ending);
  417. }
  418. void BattleStackAttacked::applyCl( CClient *cl )
  419. {
  420. std::vector<BattleStackAttacked> bsa;
  421. bsa.push_back(*this);
  422. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleStacksAttacked,bsa);
  423. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleStacksAttacked,bsa);
  424. }
  425. void BattleAttack::applyFirstCl( CClient *cl )
  426. {
  427. if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
  428. cl->playerint[GS(cl)->curB->side1]->battleAttack(this);
  429. if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
  430. cl->playerint[GS(cl)->curB->side2]->battleAttack(this);
  431. for (int g=0; g<bsa.size(); ++g)
  432. {
  433. for (int z=0; z<bsa[g].healedStacks.size(); ++z)
  434. {
  435. bsa[g].healedStacks[z].applyCl(cl);
  436. }
  437. }
  438. }
  439. void BattleAttack::applyCl( CClient *cl )
  440. {
  441. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleStacksAttacked,bsa);
  442. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleStacksAttacked,bsa);
  443. }
  444. void StartAction::applyFirstCl( CClient *cl )
  445. {
  446. cl->curbaction = new BattleAction(ba);
  447. if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
  448. cl->playerint[GS(cl)->curB->side1]->actionStarted(&ba);
  449. if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
  450. cl->playerint[GS(cl)->curB->side2]->actionStarted(&ba);
  451. }
  452. void SpellCast::applyCl( CClient *cl )
  453. {
  454. if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
  455. cl->playerint[GS(cl)->curB->side1]->battleSpellCast(this);
  456. if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
  457. cl->playerint[GS(cl)->curB->side2]->battleSpellCast(this);
  458. if(id >= 66 && id <= 69) //elemental summoning
  459. {
  460. if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
  461. cl->playerint[GS(cl)->curB->side1]->battleNewStackAppeared(GS(cl)->curB->stacks.size() - 1);
  462. if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
  463. cl->playerint[GS(cl)->curB->side2]->battleNewStackAppeared(GS(cl)->curB->stacks.size() - 1);
  464. }
  465. }
  466. void SetStackEffect::applyCl( CClient *cl )
  467. {
  468. SpellCast sc;
  469. sc.id = effect.id;
  470. sc.side = 3; //doesn't matter
  471. sc.skill = effect.level;
  472. //informing about effects
  473. if(cl->playerint.find(GS(cl)->curB->side1) != cl->playerint.end())
  474. cl->playerint[GS(cl)->curB->side1]->battleStacksEffectsSet(*this);
  475. if(cl->playerint.find(GS(cl)->curB->side2) != cl->playerint.end())
  476. cl->playerint[GS(cl)->curB->side2]->battleStacksEffectsSet(*this);
  477. }
  478. void StacksInjured::applyCl( CClient *cl )
  479. {
  480. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleStacksAttacked,stacks);
  481. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleStacksAttacked,stacks);
  482. }
  483. void BattleResultsApplied::applyCl( CClient *cl )
  484. {
  485. INTERFACE_CALL_IF_PRESENT(player1,battleResultsApplied);
  486. INTERFACE_CALL_IF_PRESENT(player2,battleResultsApplied);
  487. }
  488. void StacksHealedOrResurrected::applyCl( CClient *cl )
  489. {
  490. std::vector<std::pair<ui32, ui32> > shiftedHealed;
  491. for(int v=0; v<healedStacks.size(); ++v)
  492. {
  493. shiftedHealed.push_back(std::make_pair(healedStacks[v].stackID, healedStacks[v].healedHP));
  494. }
  495. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1, battleStacksHealedRes, shiftedHealed, lifeDrain, drainedFrom);
  496. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2, battleStacksHealedRes, shiftedHealed, lifeDrain, drainedFrom);
  497. }
  498. void ObstaclesRemoved::applyCl( CClient *cl )
  499. {
  500. //inform interfaces about removed obstacles
  501. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1, battleObstaclesRemoved, obstacles);
  502. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2, battleObstaclesRemoved, obstacles);
  503. }
  504. void CatapultAttack::applyCl( CClient *cl )
  505. {
  506. //inform interfaces about catapult attack
  507. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1, battleCatapultAttacked, *this);
  508. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2, battleCatapultAttacked, *this);
  509. }
  510. void BattleStacksRemoved::applyCl( CClient *cl )
  511. {
  512. //inform interfaces about removed stacks
  513. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1, battleStacksRemoved, *this);
  514. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2, battleStacksRemoved, *this);
  515. }
  516. CGameState* CPackForClient::GS( CClient *cl )
  517. {
  518. return cl->gs;
  519. }
  520. void EndAction::applyCl( CClient *cl )
  521. {
  522. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,actionFinished,cl->curbaction);
  523. INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,actionFinished,cl->curbaction);
  524. delete cl->curbaction;
  525. cl->curbaction = NULL;
  526. }
  527. void PackageApplied::applyCl( CClient *cl )
  528. {
  529. ui8 player = GS(cl)->currentPlayer;
  530. INTERFACE_CALL_IF_PRESENT(player, requestRealized, this);
  531. if(cl->waitingRequest.get())
  532. cl->waitingRequest.setn(false);
  533. }
  534. void SystemMessage::applyCl( CClient *cl )
  535. {
  536. std::ostringstream str;
  537. str << "System message: " << text;
  538. tlog4 << str.str() << std::endl;
  539. if(LOCPLINT)
  540. LOCPLINT->cingconsole->print(str.str());
  541. }
  542. void PlayerBlocked::applyCl( CClient *cl )
  543. {
  544. INTERFACE_CALL_IF_PRESENT(player,playerBlocked,reason);
  545. }
  546. void YourTurn::applyCl( CClient *cl )
  547. {
  548. INTERFACE_CALL_IF_PRESENT(player,yourTurn);
  549. }
  550. void SaveGame::applyCl(CClient *cl)
  551. {
  552. CSaveFile save(GVCMIDirs.UserPath + "/Games/" + fname + ".vcgm1");
  553. save << *cl;
  554. }
  555. void PlayerMessage::applyCl(CClient *cl)
  556. {
  557. std::ostringstream str;
  558. str << "Player "<<(int)player<<" sends a message: " << text;
  559. tlog4 << str.str() << std::endl;
  560. if(LOCPLINT)
  561. LOCPLINT->cingconsole->print(str.str());
  562. }
  563. void SetSelection::applyCl(CClient *cl)
  564. {
  565. const CGHeroInstance *h = cl->getHero(id);
  566. if(!h)
  567. return;
  568. //CPackForClient::GS(cl)->calculatePaths(h, *cl->pathInfo);
  569. }
  570. void ShowInInfobox::applyCl(CClient *cl)
  571. {
  572. SComponent sc(c);
  573. text.toString(sc.description);
  574. if(cl->playerint[player]->human)
  575. {
  576. static_cast<CPlayerInterface*>(cl->playerint[player])->showComp(sc);
  577. }
  578. }
  579. void OpenWindow::applyCl(CClient *cl)
  580. {
  581. switch(window)
  582. {
  583. case EXCHANGE_WINDOW:
  584. {
  585. const CGHeroInstance *h = cl->getHero(id1);
  586. const CGObjectInstance *h2 = cl->getHero(id2);
  587. assert(h && h2);
  588. INTERFACE_CALL_IF_PRESENT(h->tempOwner,heroExchangeStarted, id1, id2);
  589. }
  590. break;
  591. case RECRUITMENT_FIRST:
  592. case RECRUITMENT_ALL:
  593. {
  594. const CGDwelling *dw = dynamic_cast<const CGDwelling*>(cl->getObj(id1));
  595. const CArmedInstance *dst = dynamic_cast<const CArmedInstance*>(cl->getObj(id2));
  596. INTERFACE_CALL_IF_PRESENT(dw->tempOwner,showRecruitmentDialog, dw, dst, window == RECRUITMENT_FIRST ? 0 : -1);
  597. }
  598. break;
  599. case SHIPYARD_WINDOW:
  600. {
  601. const IShipyard *sy = IShipyard::castFrom(cl->getObj(id1));
  602. INTERFACE_CALL_IF_PRESENT(sy->o->tempOwner, showShipyardDialog, sy);
  603. }
  604. break;
  605. case THIEVES_GUILD:
  606. {
  607. //displays Thieves' Guild window (when hero enters Den of Thieves)
  608. const CGObjectInstance *obj = cl->getObj(id1);
  609. GH.pushInt( new CThievesGuildWindow(obj) );
  610. }
  611. break;
  612. case PUZZLE_MAP:
  613. {
  614. INTERFACE_CALL_IF_PRESENT(id1, showPuzzleMap);
  615. }
  616. break;
  617. }
  618. }
  619. void CenterView::applyCl(CClient *cl)
  620. {
  621. INTERFACE_CALL_IF_PRESENT (player, centerView, pos, focusTime);
  622. }
  623. void NewObject::applyCl(CClient *cl)
  624. {
  625. const CGObjectInstance *obj = cl->getObj(id);
  626. //notify interfaces about move
  627. for(std::map<ui8, CGameInterface*>::iterator i=cl->playerint.begin();i!=cl->playerint.end();i++)
  628. {
  629. //TODO: check if any covered tile is visible
  630. if(i->first >= PLAYER_LIMIT) continue;
  631. if(GS(cl)->players[i->first].fogOfWarMap[obj->pos.x][obj->pos.y][obj->pos.z])
  632. {
  633. i->second->newObject(obj);
  634. }
  635. }
  636. }
  637. void TradeComponents::applyCl(CClient *cl)
  638. {///Shop handler
  639. switch (CGI->mh->map->objects[objectid]->ID)
  640. {
  641. case 7: //Black Market
  642. break;
  643. case 95: //Tavern
  644. break;
  645. case 97: //Den of Thieves
  646. break;
  647. case 221: //Trading Post
  648. break;
  649. default:
  650. tlog2 << "Shop type not supported! \n";
  651. }
  652. }