NetPacksLib.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  1. #define VCMI_DLL
  2. #include "NetPacks.h"
  3. #include "CGeneralTextHandler.h"
  4. #include "CDefObjInfoHandler.h"
  5. #include "CArtHandler.h"
  6. #include "CHeroHandler.h"
  7. #include "CObjectHandler.h"
  8. #include "VCMI_Lib.h"
  9. #include "map.h"
  10. #include "CSpellHandler.h"
  11. #include "CCreatureHandler.h"
  12. #include <boost/bind.hpp>
  13. #include <boost/foreach.hpp>
  14. #include <boost/lexical_cast.hpp>
  15. #include <boost/algorithm/string/replace.hpp>
  16. #include <boost/thread.hpp>
  17. #include <boost/thread/shared_mutex.hpp>
  18. #include "CGameState.h"
  19. #include "BattleState.h"
  20. #undef min
  21. #undef max
  22. /*
  23. * NetPacksLib.cpp, part of VCMI engine
  24. *
  25. * Authors: listed in file AUTHORS in main folder
  26. *
  27. * License: GNU General Public License v2.0 or later
  28. * Full text of license available in license.txt file, in main folder
  29. *
  30. */
  31. #ifdef min
  32. #undef min
  33. #endif
  34. #ifdef max
  35. #undef max
  36. #endif
  37. DLL_EXPORT void SetResource::applyGs( CGameState *gs )
  38. {
  39. assert(player < PLAYER_LIMIT);
  40. amax(val, 0); //new value must be >= 0
  41. gs->getPlayer(player)->resources[resid] = val;
  42. }
  43. DLL_EXPORT void SetResources::applyGs( CGameState *gs )
  44. {
  45. assert(player < PLAYER_LIMIT);
  46. for(int i=0;i<res.size();i++)
  47. gs->getPlayer(player)->resources[i] = res[i];
  48. }
  49. DLL_EXPORT void SetPrimSkill::applyGs( CGameState *gs )
  50. {
  51. CGHeroInstance *hero = gs->getHero(id);
  52. assert(hero);
  53. if(which <4)
  54. {
  55. Bonus *skill = hero->getBonus(Selector::type(Bonus::PRIMARY_SKILL) && Selector::subtype(which) && Selector::sourceType(Bonus::HERO_BASE_SKILL));
  56. assert(skill);
  57. if(abs)
  58. skill->val = val;
  59. else
  60. skill->val += val;
  61. }
  62. else if(which == 4) //XP
  63. {
  64. if(abs)
  65. hero->exp = val;
  66. else
  67. hero->exp += val;
  68. }
  69. }
  70. DLL_EXPORT void SetSecSkill::applyGs( CGameState *gs )
  71. {
  72. CGHeroInstance *hero = gs->getHero(id);
  73. hero->setSecSkillLevel(static_cast<CGHeroInstance::SecondarySkill>(which), val, abs);
  74. }
  75. DLL_EXPORT void HeroVisitCastle::applyGs( CGameState *gs )
  76. {
  77. CGHeroInstance *h = gs->getHero(hid);
  78. CGTownInstance *t = gs->getTown(tid);
  79. if(start())
  80. t->setVisitingHero(h);
  81. else
  82. t->setVisitingHero(NULL);
  83. }
  84. DLL_EXPORT void ChangeSpells::applyGs( CGameState *gs )
  85. {
  86. CGHeroInstance *hero = gs->getHero(hid);
  87. if(learn)
  88. BOOST_FOREACH(ui32 sid, spells)
  89. hero->spells.insert(sid);
  90. else
  91. BOOST_FOREACH(ui32 sid, spells)
  92. hero->spells.erase(sid);
  93. }
  94. DLL_EXPORT void SetMana::applyGs( CGameState *gs )
  95. {
  96. CGHeroInstance *hero = gs->getHero(hid);
  97. amax(val, 0); //not less than 0
  98. hero->mana = val;
  99. }
  100. DLL_EXPORT void SetMovePoints::applyGs( CGameState *gs )
  101. {
  102. CGHeroInstance *hero = gs->getHero(hid);
  103. hero->movement = val;
  104. }
  105. DLL_EXPORT void FoWChange::applyGs( CGameState *gs )
  106. {
  107. TeamState * team = gs->getPlayerTeam(player);
  108. BOOST_FOREACH(int3 t, tiles)
  109. team->fogOfWarMap[t.x][t.y][t.z] = mode;
  110. if (mode == 0) //do not hide too much
  111. {
  112. boost::unordered_set<int3, ShashInt3> tilesRevealed;
  113. for (size_t i = 0; i < gs->map->objects.size(); i++)
  114. {
  115. if (gs->map->objects[i])
  116. {
  117. switch(gs->map->objects[i]->ID)
  118. {
  119. case 34://hero
  120. case 53://mine
  121. case 98://town
  122. case 220:
  123. if(vstd::contains(team->players, gs->map->objects[i]->tempOwner)) //check owned observators
  124. gs->map->objects[i]->getSightTiles(tilesRevealed);
  125. break;
  126. }
  127. }
  128. }
  129. BOOST_FOREACH(int3 t, tilesRevealed) //probably not the most optimal solution ever
  130. team->fogOfWarMap[t.x][t.y][t.z] = 1;
  131. }
  132. }
  133. DLL_EXPORT void SetAvailableHeroes::applyGs( CGameState *gs )
  134. {
  135. PlayerState *p = gs->getPlayer(player);
  136. p->availableHeroes.clear();
  137. for (int i = 0; i < AVAILABLE_HEROES_PER_PLAYER; i++)
  138. {
  139. CGHeroInstance *h = (hid[i]>=0 ? (CGHeroInstance*)gs->hpool.heroesPool[hid[i]] : NULL);
  140. if(h && army[i])
  141. h->setToArmy(army[i]);
  142. p->availableHeroes.push_back(h);
  143. }
  144. }
  145. DLL_EXPORT void GiveBonus::applyGs( CGameState *gs )
  146. {
  147. CBonusSystemNode *cbsn = NULL;
  148. switch(who)
  149. {
  150. case HERO:
  151. cbsn = gs->getHero(id);
  152. break;
  153. case PLAYER:
  154. cbsn = gs->getPlayer(id);
  155. break;
  156. case TOWN:
  157. cbsn = gs->getTown(id);
  158. break;
  159. }
  160. assert(cbsn);
  161. Bonus *b = new Bonus(bonus);
  162. cbsn->addNewBonus(b);
  163. std::string &descr = b->description;
  164. if(!bdescr.message.size()
  165. && bonus.source == Bonus::OBJECT
  166. && (bonus.type == Bonus::LUCK || bonus.type == Bonus::MORALE)
  167. && gs->map->objects[bonus.sid]->ID == EVENTI_TYPE) //it's morale/luck bonus from an event without description
  168. {
  169. descr = VLC->generaltexth->arraytxt[bonus.val > 0 ? 110 : 109]; //+/-%d Temporary until next battle"
  170. boost::replace_first(descr,"%d",boost::lexical_cast<std::string>(std::abs(bonus.val)));
  171. }
  172. else
  173. {
  174. bdescr.toString(descr);
  175. }
  176. }
  177. DLL_EXPORT void ChangeObjPos::applyGs( CGameState *gs )
  178. {
  179. CGObjectInstance *obj = gs->map->objects[objid];
  180. if(!obj)
  181. {
  182. tlog1 << "Wrong ChangeObjPos: object " << objid << " doesn't exist!\n";
  183. return;
  184. }
  185. gs->map->removeBlockVisTiles(obj);
  186. obj->pos = nPos;
  187. gs->map->addBlockVisTiles(obj);
  188. }
  189. DLL_EXPORT void PlayerEndsGame::applyGs( CGameState *gs )
  190. {
  191. PlayerState *p = gs->getPlayer(player);
  192. p->status = victory ? 2 : 1;
  193. }
  194. DLL_EXPORT void RemoveBonus::applyGs( CGameState *gs )
  195. {
  196. BonusList &bonuses = (who == HERO ? gs->getHero(whoID)->bonuses : gs->getPlayer(whoID)->bonuses);
  197. for(BonusList::iterator i = bonuses.begin(); i != bonuses.end(); i++)
  198. {
  199. if((*i)->source == source && (*i)->sid == id)
  200. {
  201. bonus = **i; //backup bonus (to show to interfaces later)
  202. bonuses.erase(i);
  203. break;
  204. }
  205. }
  206. }
  207. DLL_EXPORT void RemoveObject::applyGs( CGameState *gs )
  208. {
  209. CGObjectInstance *obj = gs->map->objects[id];
  210. //unblock tiles
  211. if(obj->defInfo)
  212. {
  213. gs->map->removeBlockVisTiles(obj);
  214. }
  215. if(obj->ID==HEROI_TYPE)
  216. {
  217. CGHeroInstance *h = static_cast<CGHeroInstance*>(obj);
  218. PlayerState *p = gs->getPlayer(h->tempOwner);
  219. gs->map->heroes -= h;
  220. p->heroes -= h;
  221. h->detachFrom(h->whereShouldBeAttached(gs));
  222. h->tempOwner = 255; //no one owns beaten hero
  223. if(h->visitedTown)
  224. {
  225. if(h->inTownGarrison)
  226. h->visitedTown->garrisonHero = NULL;
  227. else
  228. h->visitedTown->visitingHero = NULL;
  229. h->visitedTown = NULL;
  230. }
  231. //return hero to the pool, so he may reappear in tavern
  232. gs->hpool.heroesPool[h->subID] = h;
  233. if(!vstd::contains(gs->hpool.pavailable, h->subID))
  234. gs->hpool.pavailable[h->subID] = 0xff;
  235. gs->map->objects[id] = NULL;
  236. return;
  237. }
  238. // else if (obj->ID==CREI_TYPE && gs->map->version > CMapHeader::RoE) //only fixed monsters can be a part of quest
  239. // {
  240. // CGCreature *cre = static_cast<CGCreature*>(obj);
  241. // gs->map->monsters[cre->identifier]->pos = int3 (-1,-1,-1); //use nonexistent monster for quest :>
  242. // }
  243. gs->map->objects[id].dellNull();
  244. }
  245. static int getDir(int3 src, int3 dst)
  246. {
  247. int ret = -1;
  248. if(dst.x+1 == src.x && dst.y+1 == src.y) //tl
  249. {
  250. ret = 1;
  251. }
  252. else if(dst.x == src.x && dst.y+1 == src.y) //t
  253. {
  254. ret = 2;
  255. }
  256. else if(dst.x-1 == src.x && dst.y+1 == src.y) //tr
  257. {
  258. ret = 3;
  259. }
  260. else if(dst.x-1 == src.x && dst.y == src.y) //r
  261. {
  262. ret = 4;
  263. }
  264. else if(dst.x-1 == src.x && dst.y-1 == src.y) //br
  265. {
  266. ret = 5;
  267. }
  268. else if(dst.x == src.x && dst.y-1 == src.y) //b
  269. {
  270. ret = 6;
  271. }
  272. else if(dst.x+1 == src.x && dst.y-1 == src.y) //bl
  273. {
  274. ret = 7;
  275. }
  276. else if(dst.x+1 == src.x && dst.y == src.y) //l
  277. {
  278. ret = 8;
  279. }
  280. return ret;
  281. }
  282. void TryMoveHero::applyGs( CGameState *gs )
  283. {
  284. CGHeroInstance *h = gs->getHero(id);
  285. h->movement = movePoints;
  286. if((result == SUCCESS || result == BLOCKING_VISIT || result == EMBARK || result == DISEMBARK) && start != end) {
  287. h->moveDir = getDir(start,end);
  288. }
  289. if(result == EMBARK) //hero enters boat at dest tile
  290. {
  291. const TerrainTile &tt = gs->map->getTile(CGHeroInstance::convertPosition(end, false));
  292. assert(tt.visitableObjects.size() == 1 && tt.visitableObjects.front()->ID == 8); //the only vis obj at dest is Boat
  293. CGBoat *boat = static_cast<CGBoat*>(tt.visitableObjects.front());
  294. gs->map->removeBlockVisTiles(boat); //hero blockvis mask will be used, we don't need to duplicate it with boat
  295. h->boat = boat;
  296. boat->hero = h;
  297. }
  298. else if(result == DISEMBARK) //hero leaves boat to dest tile
  299. {
  300. CGBoat *b = const_cast<CGBoat *>(h->boat);
  301. b->direction = h->moveDir;
  302. b->pos = start;
  303. b->hero = NULL;
  304. gs->map->addBlockVisTiles(b);
  305. h->boat = NULL;
  306. }
  307. if(start!=end && (result == SUCCESS || result == TELEPORTATION || result == EMBARK || result == DISEMBARK))
  308. {
  309. gs->map->removeBlockVisTiles(h);
  310. h->pos = end;
  311. if(CGBoat *b = const_cast<CGBoat *>(h->boat))
  312. b->pos = end;
  313. gs->map->addBlockVisTiles(h);
  314. }
  315. BOOST_FOREACH(int3 t, fowRevealed)
  316. gs->getPlayerTeam(h->getOwner())->fogOfWarMap[t.x][t.y][t.z] = 1;
  317. }
  318. DLL_EXPORT void NewStructures::applyGs( CGameState *gs )
  319. {
  320. CGTownInstance *t = gs->getTown(tid);
  321. BOOST_FOREACH(si32 id,bid)
  322. {
  323. t->builtBuildings.insert(id);
  324. }
  325. t->builded = builded;
  326. t->recreateBuildingsBonuses();
  327. }
  328. DLL_EXPORT void RazeStructures::applyGs( CGameState *gs )
  329. {
  330. CGTownInstance *t = gs->getTown(tid);
  331. BOOST_FOREACH(si32 id,bid)
  332. {
  333. t->builtBuildings.erase(id);
  334. }
  335. t->destroyed = destroyed; //yeaha
  336. t->recreateBuildingsBonuses();
  337. }
  338. DLL_EXPORT void SetAvailableCreatures::applyGs( CGameState *gs )
  339. {
  340. CGDwelling *dw = dynamic_cast<CGDwelling*>(gs->map->objects[tid].get());
  341. assert(dw);
  342. dw->creatures = creatures;
  343. }
  344. DLL_EXPORT void SetHeroesInTown::applyGs( CGameState *gs )
  345. {
  346. CGTownInstance *t = gs->getTown(tid);
  347. CGHeroInstance *v = gs->getHero(visiting),
  348. *g = gs->getHero(garrison);
  349. bool newVisitorComesFromGarrison = v && v == t->garrisonHero;
  350. bool newGarrisonComesFromVisiting = g && g == t->visitingHero;
  351. if(newVisitorComesFromGarrison)
  352. t->setGarrisonedHero(NULL);
  353. if(newGarrisonComesFromVisiting)
  354. t->setVisitingHero(NULL);
  355. if(!newGarrisonComesFromVisiting || v)
  356. t->setVisitingHero(v);
  357. if(!newVisitorComesFromGarrison || g)
  358. t->setGarrisonedHero(g);
  359. if(v)
  360. {
  361. gs->map->addBlockVisTiles(v);
  362. }
  363. if(g)
  364. {
  365. gs->map->removeBlockVisTiles(g);
  366. }
  367. }
  368. DLL_EXPORT void HeroRecruited::applyGs( CGameState *gs )
  369. {
  370. assert(vstd::contains(gs->hpool.heroesPool, hid));
  371. CGHeroInstance *h = gs->hpool.heroesPool[hid];
  372. CGTownInstance *t = gs->getTown(tid);
  373. PlayerState *p = gs->getPlayer(player);
  374. h->setOwner(player);
  375. h->pos = tile;
  376. h->movement = h->maxMovePoints(true);
  377. gs->hpool.heroesPool.erase(hid);
  378. if(h->id < 0)
  379. {
  380. h->id = gs->map->objects.size();
  381. gs->map->objects.push_back(h);
  382. }
  383. else
  384. gs->map->objects[h->id] = h;
  385. h->initHeroDefInfo();
  386. gs->map->heroes.push_back(h);
  387. p->heroes.push_back(h);
  388. h->attachTo(p);
  389. h->initObj();
  390. gs->map->addBlockVisTiles(h);
  391. if(t)
  392. {
  393. t->setVisitingHero(h);
  394. }
  395. }
  396. DLL_EXPORT void GiveHero::applyGs( CGameState *gs )
  397. {
  398. CGHeroInstance *h = gs->getHero(id);
  399. gs->map->removeBlockVisTiles(h,true);
  400. h->setOwner(player);
  401. h->movement = h->maxMovePoints(true);
  402. h->initHeroDefInfo();
  403. gs->map->heroes.push_back(h);
  404. gs->getPlayer(h->getOwner())->heroes.push_back(h);
  405. gs->map->addBlockVisTiles(h);
  406. h->inTownGarrison = false;
  407. }
  408. DLL_EXPORT void NewObject::applyGs( CGameState *gs )
  409. {
  410. CGObjectInstance *o = NULL;
  411. switch(ID)
  412. {
  413. case 8:
  414. o = new CGBoat();
  415. break;
  416. case 54: //probably more options will be needed
  417. o = new CGCreature();
  418. {
  419. //CStackInstance hlp;
  420. CGCreature *cre = static_cast<CGCreature*>(o);
  421. //cre->slots[0] = hlp;
  422. cre->notGrowingTeam = cre->neverFlees = 0;
  423. cre->character = 2;
  424. cre->gainedArtifact = -1;
  425. }
  426. break;
  427. default:
  428. o = new CGObjectInstance();
  429. break;
  430. }
  431. o->ID = ID;
  432. o->subID = subID;
  433. o->pos = pos;
  434. o->defInfo = VLC->dobjinfo->gobjs[ID][subID];
  435. id = o->id = gs->map->objects.size();
  436. o->hoverName = VLC->generaltexth->names[ID];
  437. switch(ID)
  438. {
  439. case 54: //cfreature
  440. o->defInfo = VLC->dobjinfo->gobjs[ID][subID];
  441. assert(o->defInfo);
  442. break;
  443. case 124://hole
  444. const TerrainTile &t = gs->map->getTile(pos);
  445. o->defInfo = VLC->dobjinfo->gobjs[ID][t.tertype];
  446. assert(o->defInfo);
  447. break;
  448. }
  449. gs->map->objects.push_back(o);
  450. gs->map->addBlockVisTiles(o);
  451. o->initObj();
  452. assert(o->defInfo);
  453. }
  454. DLL_EXPORT void NewArtifact::applyGs( CGameState *gs )
  455. {
  456. assert(!vstd::contains(gs->map->artInstances, art));
  457. gs->map->addNewArtifactInstance(art);
  458. assert(!art->parents.size());
  459. art->setType(art->artType);
  460. }
  461. DLL_EXPORT const CStackInstance * StackLocation::getStack()
  462. {
  463. if(!army->hasStackAtSlot(slot))
  464. {
  465. tlog2 << "Warning: " << army->nodeName() << " dont have a stack at slot " << slot << std::endl;
  466. return NULL;
  467. }
  468. return &army->getStack(slot);
  469. }
  470. DLL_EXPORT const CArtifactInstance *ArtifactLocation::getArt() const
  471. {
  472. const ArtSlotInfo *s = getSlot();
  473. if(s && s->artifact)
  474. {
  475. if(!s->locked)
  476. return s->artifact;
  477. else
  478. {
  479. tlog3 << "ArtifactLocation::getArt: That location is locked!\n";
  480. return NULL;
  481. }
  482. }
  483. return NULL;
  484. return NULL;
  485. }
  486. DLL_EXPORT CArtifactInstance *ArtifactLocation::getArt()
  487. {
  488. const ArtifactLocation *t = this;
  489. return const_cast<CArtifactInstance*>(t->getArt());
  490. }
  491. DLL_EXPORT const ArtSlotInfo *ArtifactLocation::getSlot() const
  492. {
  493. return hero->getSlot(slot);
  494. }
  495. DLL_EXPORT void ChangeStackCount::applyGs( CGameState *gs )
  496. {
  497. if(absoluteValue)
  498. sl.army->setStackCount(sl.slot, count);
  499. else
  500. sl.army->changeStackCount(sl.slot, count);
  501. }
  502. DLL_EXPORT void SetStackType::applyGs( CGameState *gs )
  503. {
  504. sl.army->setStackType(sl.slot, type);
  505. }
  506. DLL_EXPORT void EraseStack::applyGs( CGameState *gs )
  507. {
  508. sl.army->eraseStack(sl.slot);
  509. }
  510. DLL_EXPORT void SwapStacks::applyGs( CGameState *gs )
  511. {
  512. CStackInstance *s1 = sl1.army->detachStack(sl1.slot),
  513. *s2 = sl2.army->detachStack(sl2.slot);
  514. sl2.army->putStack(sl2.slot, s1);
  515. sl1.army->putStack(sl1.slot, s2);
  516. }
  517. DLL_EXPORT void InsertNewStack::applyGs( CGameState *gs )
  518. {
  519. CStackInstance *s = new CStackInstance(stack.type, stack.count);
  520. sl.army->putStack(sl.slot, s);
  521. }
  522. DLL_EXPORT void RebalanceStacks::applyGs( CGameState *gs )
  523. {
  524. const CCreature *srcType = src.army->getCreature(src.slot);
  525. TQuantity srcCount = src.army->getStackCount(src.slot);
  526. if(srcCount == count) //moving whole stack
  527. {
  528. if(const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> merge
  529. {
  530. assert(c == srcType);
  531. src.army->eraseStack(src.slot);
  532. dst.army->changeStackCount(dst.slot, count);
  533. }
  534. else //move stack to an empty slot
  535. {
  536. CStackInstance *stackDetached = src.army->detachStack(src.slot);
  537. dst.army->putStack(dst.slot, stackDetached);
  538. }
  539. }
  540. else
  541. {
  542. if(const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> rebalance
  543. {
  544. assert(c == srcType);
  545. src.army->changeStackCount(src.slot, -count);
  546. dst.army->changeStackCount(dst.slot, count);
  547. }
  548. else //split stack to an empty slot
  549. {
  550. src.army->changeStackCount(src.slot, -count);
  551. dst.army->addToSlot(dst.slot, srcType->idNumber, count, false);
  552. }
  553. }
  554. }
  555. DLL_EXPORT void PutArtifact::applyGs( CGameState *gs )
  556. {
  557. assert(art->canBePutAt(al));
  558. al.hero->putArtifact(al.slot, art);
  559. }
  560. DLL_EXPORT void EraseArtifact::applyGs( CGameState *gs )
  561. {
  562. CArtifactInstance *a = al.getArt();
  563. assert(a);
  564. a->removeFrom(al.hero, al.slot);
  565. }
  566. DLL_EXPORT void MoveArtifact::applyGs( CGameState *gs )
  567. {
  568. CArtifactInstance *a = src.getArt();
  569. if(dst.slot < Arts::BACKPACK_START)
  570. assert(!dst.getArt());
  571. a->move(src, dst);
  572. }
  573. DLL_EXPORT void AssembledArtifact::applyGs( CGameState *gs )
  574. {
  575. CGHeroInstance *h = al.hero;
  576. const CArtifactInstance *transformedArt = al.getArt();
  577. assert(transformedArt);
  578. assert(vstd::contains(transformedArt->assemblyPossibilities(al.hero), builtArt));
  579. CCombinedArtifactInstance *combinedArt = new CCombinedArtifactInstance(builtArt);
  580. gs->map->addNewArtifactInstance(combinedArt);
  581. //retreive all constituents
  582. BOOST_FOREACH(si32 constituentID, *builtArt->constituents)
  583. {
  584. int pos = h->getArtPos(constituentID);
  585. assert(pos >= 0);
  586. CArtifactInstance *constituentInstance = h->getArt(pos);
  587. //move constituent from hero to be part of new, combined artifact
  588. constituentInstance->removeFrom(h, pos);
  589. combinedArt->addAsConstituent(constituentInstance, pos);
  590. if(!vstd::contains(combinedArt->artType->possibleSlots, al.slot) && vstd::contains(combinedArt->artType->possibleSlots, pos))
  591. al.slot = pos;
  592. }
  593. //put new combined artifacts
  594. combinedArt->putAt(h, al.slot);
  595. }
  596. DLL_EXPORT void DisassembledArtifact::applyGs( CGameState *gs )
  597. {
  598. CGHeroInstance *h = al.hero;
  599. CCombinedArtifactInstance *disassembled = dynamic_cast<CCombinedArtifactInstance*>(al.getArt());
  600. assert(disassembled);
  601. std::vector<CCombinedArtifactInstance::ConstituentInfo> constituents = disassembled->constituentsInfo;
  602. disassembled->removeFrom(h, al.slot);
  603. BOOST_FOREACH(CCombinedArtifactInstance::ConstituentInfo &ci, constituents)
  604. {
  605. disassembled->detachFrom(ci.art);
  606. ci.art->putAt(h, ci.slot >= 0 ? ci.slot : al.slot); //-1 is slot of main constituent -> it'll replace combined artifact in its pos
  607. }
  608. gs->map->eraseArtifactInstance(disassembled);
  609. }
  610. DLL_EXPORT void SetAvailableArtifacts::applyGs( CGameState *gs )
  611. {
  612. if(id >= 0)
  613. {
  614. if(CGBlackMarket *bm = dynamic_cast<CGBlackMarket*>(gs->map->objects[id].get()))
  615. {
  616. bm->artifacts = arts;
  617. }
  618. else
  619. {
  620. tlog1 << "Wrong black market id!" << std::endl;
  621. }
  622. }
  623. else
  624. {
  625. CGTownInstance::merchantArtifacts = arts;
  626. }
  627. }
  628. DLL_EXPORT void NewTurn::applyGs( CGameState *gs )
  629. {
  630. gs->day = day;
  631. BOOST_FOREACH(NewTurn::Hero h, heroes) //give mana/movement point
  632. {
  633. CGHeroInstance *hero = gs->getHero(h.id);
  634. hero->movement = h.move;
  635. hero->mana = h.mana;
  636. }
  637. for(std::map<ui8, std::vector<si32> >::iterator i = res.begin(); i != res.end(); i++)
  638. {
  639. assert(i->first < PLAYER_LIMIT);
  640. std::vector<si32> &playerRes = gs->getPlayer(i->first)->resources;
  641. for(int j = 0; j < i->second.size(); j++)
  642. playerRes[j] = i->second[j];
  643. }
  644. BOOST_FOREACH(SetAvailableCreatures h, cres) //set available creatures in towns
  645. h.applyGs(gs);
  646. if (specialWeek != NO_ACTION) //first pack applied, reset all effects and aplly new
  647. {
  648. //TODO? won't work for battles lasting several turns (not an issue now but...)
  649. gs->globalEffects.popBonuses(Bonus::OneDay); //works for children -> all game objs
  650. if(gs->getDate(1)) //new week, Monday that is
  651. {
  652. gs->globalEffects.popBonuses(Bonus::OneWeek); //works for children -> all game objs
  653. Bonus *b = new Bonus();
  654. b->duration = Bonus::ONE_WEEK;
  655. b->source = Bonus::SPECIAL_WEEK;
  656. b->effectRange = Bonus::NO_LIMIT;
  657. b->valType = Bonus::BASE_NUMBER; //certainly not intuitive
  658. switch (specialWeek)
  659. {
  660. case DOUBLE_GROWTH:
  661. b->val = 100;
  662. b->type = Bonus::CREATURE_GROWTH_PERCENT;
  663. b->limiter.reset(new CCreatureTypeLimiter(*VLC->creh->creatures[creatureid], false));
  664. break;
  665. case BONUS_GROWTH:
  666. b->val = 5;
  667. b->type = Bonus::CREATURE_GROWTH;
  668. b->limiter.reset(new CCreatureTypeLimiter(*VLC->creh->creatures[creatureid], false));
  669. break;
  670. case DEITYOFFIRE:
  671. b->val = 15;
  672. b->type = Bonus::CREATURE_GROWTH;
  673. b->limiter.reset(new CCreatureTypeLimiter(*VLC->creh->creatures[42], true));
  674. break;
  675. case PLAGUE:
  676. b->val = -100; //no basic creatures
  677. b->type = Bonus::CREATURE_GROWTH_PERCENT;
  678. break;
  679. default:
  680. b->val = 0;
  681. }
  682. if (b->val)
  683. gs->globalEffects.addNewBonus(b);
  684. }
  685. }
  686. else //second pack is applied
  687. {
  688. //count days without town
  689. for( std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
  690. {
  691. if(i->second.towns.size() || gs->day == 1)
  692. i->second.daysWithoutCastle = 0;
  693. else
  694. i->second.daysWithoutCastle++;
  695. }
  696. if(resetBuilded) //reset amount of structures set in this turn in towns
  697. {
  698. BOOST_FOREACH(CGTownInstance* t, gs->map->towns)
  699. t->builded = 0;
  700. }
  701. }
  702. }
  703. DLL_EXPORT void SetObjectProperty::applyGs( CGameState *gs )
  704. {
  705. CGObjectInstance *obj = gs->map->objects[id];
  706. if(!obj)
  707. {
  708. tlog1 << "Wrong object ID - property cannot be set!\n";
  709. return;
  710. }
  711. CArmedInstance *cai = dynamic_cast<CArmedInstance *>(obj);
  712. if(what == ObjProperty::OWNER && cai)
  713. {
  714. if(obj->ID == TOWNI_TYPE)
  715. {
  716. CGTownInstance *t = static_cast<CGTownInstance*>(obj);
  717. if(t->tempOwner < PLAYER_LIMIT)
  718. gs->getPlayer(t->tempOwner)->towns -= t;
  719. if(val < PLAYER_LIMIT)
  720. gs->getPlayer(val)->towns.push_back(t);
  721. }
  722. CBonusSystemNode *nodeToMove = cai->whatShouldBeAttached();
  723. nodeToMove->detachFrom(cai->whereShouldBeAttached(gs));
  724. obj->setProperty(what,val);
  725. nodeToMove->attachTo(cai->whereShouldBeAttached(gs));
  726. }
  727. else //not an armed instance
  728. {
  729. obj->setProperty(what,val);
  730. }
  731. }
  732. DLL_EXPORT void SetHoverName::applyGs( CGameState *gs )
  733. {
  734. name.toString(gs->map->objects[id]->hoverName);
  735. }
  736. DLL_EXPORT void HeroLevelUp::applyGs( CGameState *gs )
  737. {
  738. CGHeroInstance* h = gs->getHero(heroid);
  739. h->level = level;
  740. //speciality
  741. h->UpdateSpeciality();
  742. }
  743. DLL_EXPORT void BattleStart::applyGs( CGameState *gs )
  744. {
  745. gs->curB = info;
  746. gs->curB->localInit();
  747. }
  748. DLL_EXPORT void BattleNextRound::applyGs( CGameState *gs )
  749. {
  750. gs->curB->castSpells[0] = gs->curB->castSpells[1] = 0;
  751. gs->curB->round = round;
  752. BOOST_FOREACH(CStack *s, gs->curB->stacks)
  753. {
  754. s->state -= DEFENDING;
  755. s->state -= WAITING;
  756. s->state -= MOVED;
  757. s->state -= HAD_MORALE;
  758. s->counterAttacks = 1 + s->valOfBonuses(Bonus::ADDITIONAL_RETALIATION);
  759. //regeneration
  760. if( s->hasBonusOfType(Bonus::HP_REGENERATION) && s->alive() )
  761. s->firstHPleft = std::min<ui32>( s->MaxHealth(), s->valOfBonuses(Bonus::HP_REGENERATION) );
  762. if( s->hasBonusOfType(Bonus::FULL_HP_REGENERATION) && s->alive() )
  763. s->firstHPleft = s->MaxHealth();
  764. s->battleTurnPassed();
  765. }
  766. }
  767. DLL_EXPORT void BattleSetActiveStack::applyGs( CGameState *gs )
  768. {
  769. gs->curB->activeStack = stack;
  770. CStack *st = gs->curB->getStack(stack);
  771. //remove bonuses that last until when stack gets new turn
  772. st->bonuses.remove_if(Bonus::UntilGetsTurn);
  773. if(vstd::contains(st->state,MOVED)) //if stack is moving second time this turn it must had a high morale bonus
  774. st->state.insert(HAD_MORALE);
  775. }
  776. void BattleResult::applyGs( CGameState *gs )
  777. {
  778. for(unsigned i=0;i<gs->curB->stacks.size();i++)
  779. delete gs->curB->stacks[i];
  780. //remove any "until next battle" bonuses
  781. CGHeroInstance *h;
  782. h = gs->curB->heroes[0];
  783. if(h)
  784. h->bonuses.remove_if(Bonus::OneBattle);
  785. h = gs->curB->heroes[1];
  786. if(h)
  787. h->bonuses.remove_if(Bonus::OneBattle);
  788. if (STACK_EXP)
  789. {
  790. if (exp[0]) //checking local array is easier than dereferencing this crap twice
  791. gs->curB->belligerents[0]->giveStackExp(exp[0]);
  792. if (exp[1])
  793. gs->curB->belligerents[1]->giveStackExp(exp[1]);
  794. }
  795. gs->curB->belligerents[0]->battle = gs->curB->belligerents[1]->battle = NULL;
  796. gs->curB.dellNull();
  797. }
  798. void BattleStackMoved::applyGs( CGameState *gs )
  799. {
  800. gs->curB->getStack(stack)->position = tile;
  801. }
  802. DLL_EXPORT void BattleStackAttacked::applyGs( CGameState *gs )
  803. {
  804. CStack * at = gs->curB->getStack(stackAttacked);
  805. at->count = newAmount;
  806. at->firstHPleft = newHP;
  807. if(killed())
  808. at->state -= ALIVE;
  809. //life drain handling
  810. for (int g=0; g<healedStacks.size(); ++g)
  811. {
  812. healedStacks[g].applyGs(gs);
  813. }
  814. }
  815. DLL_EXPORT void BattleAttack::applyGs( CGameState *gs )
  816. {
  817. CStack *attacker = gs->curB->getStack(stackAttacking);
  818. if(counter())
  819. attacker->counterAttacks--;
  820. if(shot())
  821. {
  822. //don't remove ammo if we have a working ammo cart
  823. bool hasAmmoCart = false;
  824. BOOST_FOREACH(const CStack * st, gs->curB->stacks)
  825. {
  826. if(st->owner == attacker->owner && st->getCreature()->idNumber == 148 && st->alive())
  827. {
  828. hasAmmoCart = true;
  829. break;
  830. }
  831. }
  832. if (!hasAmmoCart)
  833. {
  834. attacker->shots--;
  835. }
  836. }
  837. BOOST_FOREACH(BattleStackAttacked stackAttacked, bsa)
  838. stackAttacked.applyGs(gs);
  839. attacker->bonuses.remove_if(Bonus::UntilAttack);
  840. for(std::vector<BattleStackAttacked>::const_iterator it = bsa.begin(); it != bsa.end(); ++it)
  841. {
  842. CStack * stack = gs->curB->getStack(it->stackAttacked, false);
  843. stack->bonuses.remove_if(Bonus::UntilBeingAttacked);
  844. }
  845. }
  846. DLL_EXPORT void StartAction::applyGs( CGameState *gs )
  847. {
  848. CStack *st = gs->curB->getStack(ba.stackNumber);
  849. if(ba.actionType == BattleAction::END_TACTIC_PHASE)
  850. {
  851. gs->curB->tacticDistance = 0;
  852. return;
  853. }
  854. if(ba.actionType != BattleAction::HERO_SPELL) //don't check for stack if it's custom action by hero
  855. {
  856. assert(st);
  857. }
  858. else
  859. {
  860. gs->curB->usedSpellsHistory[ba.side].push_back(VLC->spellh->spells[ba.additionalInfo]);
  861. }
  862. switch(ba.actionType)
  863. {
  864. case BattleAction::DEFEND:
  865. st->state.insert(DEFENDING);
  866. break;
  867. case BattleAction::WAIT:
  868. st->state.insert(WAITING);
  869. return;
  870. case BattleAction::NO_ACTION: case BattleAction::WALK: case BattleAction::WALK_AND_ATTACK:
  871. case BattleAction::SHOOT: case BattleAction::CATAPULT: case BattleAction::MONSTER_SPELL:
  872. case BattleAction::BAD_MORALE: case BattleAction::STACK_HEAL:
  873. st->state.insert(MOVED);
  874. break;
  875. }
  876. if(st)
  877. st->state -= WAITING; //if stack was waiting it has made move, so it won't be "waiting" anymore (if the action was WAIT, then we have returned)
  878. }
  879. DLL_EXPORT void BattleSpellCast::applyGs( CGameState *gs )
  880. {
  881. assert(gs->curB);
  882. CGHeroInstance *h = (side) ? gs->curB->heroes[1] : gs->curB->heroes[0];
  883. if(h && castedByHero)
  884. {
  885. int spellCost = 0;
  886. if(gs->curB)
  887. {
  888. spellCost = gs->curB->getSpellCost(VLC->spellh->spells[id], h);
  889. }
  890. else
  891. {
  892. spellCost = VLC->spellh->spells[id]->costs[skill];
  893. }
  894. h->mana -= spellCost;
  895. if(h->mana < 0) h->mana = 0;
  896. }
  897. if(side >= 0 && side < 2 && castedByHero)
  898. {
  899. gs->curB->castSpells[side]++;
  900. }
  901. if(id == 35 || id == 78) //dispel and dispel helpful spells
  902. {
  903. bool onlyHelpful = id == 78;
  904. for(std::set<ui32>::const_iterator it = affectedCres.begin(); it != affectedCres.end(); ++it)
  905. {
  906. CStack *s = gs->curB->getStack(*it);
  907. if(s && !vstd::contains(resisted, s->ID)) //if stack exists and it didn't resist
  908. {
  909. if(onlyHelpful)
  910. s->popBonuses(Selector::positiveSpellEffects);
  911. else
  912. s->popBonuses(Selector::sourceType(Bonus::SPELL_EFFECT));
  913. }
  914. }
  915. }
  916. //elemental summoning
  917. if(id >= 66 && id <= 69)
  918. {
  919. int creID;
  920. switch(id)
  921. {
  922. case 66:
  923. creID = 114; //fire elemental
  924. break;
  925. case 67:
  926. creID = 113; //earth elemental
  927. break;
  928. case 68:
  929. creID = 115; //water elemental
  930. break;
  931. case 69:
  932. creID = 112; //air elemental
  933. break;
  934. }
  935. // const int3 & tile = gs->curB->tile;
  936. // TerrainTile::EterrainType ter = gs->map->terrain[tile.x][tile.y][tile.z].tertype;
  937. int pos; //position of stack on the battlefield - to be calculated
  938. bool ac[BFIELD_SIZE];
  939. std::set<THex> occupyable;
  940. bool twoHex = VLC->creh->creatures[creID]->isDoubleWide();
  941. bool flying = VLC->creh->creatures[creID]->isFlying();// vstd::contains(VLC->creh->creatures[creID]->bonuses, Bonus::FLYING);
  942. gs->curB->getAccessibilityMap(ac, twoHex, !side, true, occupyable, flying);
  943. for(int g=0; g<BFIELD_SIZE; ++g)
  944. {
  945. if(g % BFIELD_WIDTH != 0 && g % BFIELD_WIDTH != BFIELD_WIDTH-1 && BattleInfo::isAccessible(g, ac, twoHex, !side, flying, true) )
  946. {
  947. pos = g;
  948. break;
  949. }
  950. }
  951. CStackInstance *csi = new CStackInstance(creID, h->getPrimSkillLevel(2) * VLC->spellh->spells[id]->powers[skill]); //deleted by d-tor of summoned stack
  952. csi->setArmyObj(h);
  953. CStack * summonedStack = gs->curB->generateNewStack(*csi, gs->curB->stacks.size(), !side, 255, pos);
  954. summonedStack->state.insert(SUMMONED);
  955. summonedStack->attachTo(csi);
  956. summonedStack->postInit();
  957. //summonedStack->addNewBonus( makeFeature(HeroBonus::SUMMONED, HeroBonus::ONE_BATTLE, 0, 0, HeroBonus::BONUS_FROM_HERO) );
  958. gs->curB->stacks.push_back(summonedStack);
  959. }
  960. }
  961. void actualizeEffect(CStack * s, const std::vector<Bonus> & ef)
  962. {
  963. //actualizing features vector
  964. BOOST_FOREACH(const Bonus &fromEffect, ef)
  965. {
  966. BOOST_FOREACH(Bonus *stackBonus, s->bonuses) //TODO: optimize
  967. {
  968. if(stackBonus->source == Bonus::SPELL_EFFECT && stackBonus->type == fromEffect.type && stackBonus->subtype == fromEffect.subtype)
  969. {
  970. stackBonus->turnsRemain = std::max(stackBonus->turnsRemain, fromEffect.turnsRemain);
  971. }
  972. }
  973. }
  974. }
  975. DLL_EXPORT void SetStackEffect::applyGs( CGameState *gs )
  976. {
  977. BOOST_FOREACH(ui32 id, stacks)
  978. {
  979. CStack *s = gs->curB->getStack(id);
  980. if(s)
  981. {
  982. int id = effect.begin()->sid; //effects' source ID
  983. if(id == 47 || !s->hasBonus(Selector::source(Bonus::SPELL_EFFECT, id)))//disrupting ray or not on the list - just add
  984. {
  985. BOOST_FOREACH(Bonus &fromEffect, effect)
  986. {
  987. s->addNewBonus( new Bonus(fromEffect));
  988. }
  989. }
  990. else //just actualize
  991. {
  992. actualizeEffect(s, effect);
  993. }
  994. }
  995. else
  996. tlog1 << "Cannot find stack " << id << std::endl;
  997. }
  998. }
  999. DLL_EXPORT void StacksInjured::applyGs( CGameState *gs )
  1000. {
  1001. BOOST_FOREACH(BattleStackAttacked stackAttacked, stacks)
  1002. stackAttacked.applyGs(gs);
  1003. }
  1004. DLL_EXPORT void StacksHealedOrResurrected::applyGs( CGameState *gs )
  1005. {
  1006. for(int g=0; g<healedStacks.size(); ++g)
  1007. {
  1008. CStack * changedStack = gs->curB->getStack(healedStacks[g].stackID, false);
  1009. //checking if we resurrect a stack that is under a living stack
  1010. std::vector<THex> access = gs->curB->getAccessibility(changedStack, true);
  1011. bool acc[BFIELD_SIZE];
  1012. for(int h=0; h<BFIELD_SIZE; ++h)
  1013. acc[h] = false;
  1014. for(int h=0; h<access.size(); ++h)
  1015. acc[access[h]] = true;
  1016. if(!changedStack->alive() && !gs->curB->isAccessible(changedStack->position, acc,
  1017. changedStack->doubleWide(), changedStack->attackerOwned,
  1018. changedStack->hasBonusOfType(Bonus::FLYING), true))
  1019. return; //position is already occupied
  1020. //applying changes
  1021. bool resurrected = !changedStack->alive(); //indicates if stack is resurrected or just healed
  1022. if(resurrected)
  1023. {
  1024. changedStack->state.insert(ALIVE);
  1025. if(healedStacks[g].lowLevelResurrection)
  1026. changedStack->state.insert(SUMMONED);
  1027. //changedStack->addNewBonus( makeFeature(HeroBonus::SUMMONED, HeroBonus::ONE_BATTLE, 0, 0, HeroBonus::BONUS_FROM_HERO) );
  1028. }
  1029. //int missingHPfirst = changedStack->MaxHealth() - changedStack->firstHPleft;
  1030. int res = std::min( healedStacks[g].healedHP / changedStack->MaxHealth() , changedStack->baseAmount - changedStack->count );
  1031. changedStack->count += res;
  1032. changedStack->firstHPleft += healedStacks[g].healedHP - res * changedStack->MaxHealth();
  1033. if(changedStack->firstHPleft > changedStack->MaxHealth())
  1034. {
  1035. changedStack->firstHPleft -= changedStack->MaxHealth();
  1036. if(changedStack->baseAmount > changedStack->count)
  1037. {
  1038. changedStack->count += 1;
  1039. }
  1040. }
  1041. amin(changedStack->firstHPleft, changedStack->MaxHealth());
  1042. //removal of negative effects
  1043. if(resurrected)
  1044. {
  1045. for (BonusList::iterator it = changedStack->bonuses.begin(); it != changedStack->bonuses.end(); it++)
  1046. {
  1047. if(VLC->spellh->spells[(*it)->sid]->positiveness < 0)
  1048. {
  1049. changedStack->bonuses.erase(it);
  1050. }
  1051. }
  1052. //removing all features from negative spells
  1053. BonusList tmpFeatures = changedStack->bonuses;
  1054. changedStack->bonuses.clear();
  1055. BOOST_FOREACH(Bonus *b, tmpFeatures)
  1056. {
  1057. const CSpell *s = b->sourceSpell();
  1058. if(s && s->positiveness >= 0)
  1059. {
  1060. changedStack->addNewBonus(b);
  1061. }
  1062. }
  1063. }
  1064. }
  1065. }
  1066. DLL_EXPORT void ObstaclesRemoved::applyGs( CGameState *gs )
  1067. {
  1068. if(gs->curB) //if there is a battle
  1069. {
  1070. for(std::set<si32>::const_iterator it = obstacles.begin(); it != obstacles.end(); ++it)
  1071. {
  1072. for(int i=0; i<gs->curB->obstacles.size(); ++i)
  1073. {
  1074. if(gs->curB->obstacles[i].uniqueID == *it) //remove this obstacle
  1075. {
  1076. gs->curB->obstacles.erase(gs->curB->obstacles.begin() + i);
  1077. break;
  1078. }
  1079. }
  1080. }
  1081. }
  1082. }
  1083. DLL_EXPORT void CatapultAttack::applyGs( CGameState *gs )
  1084. {
  1085. if(gs->curB && gs->curB->siege != 0) //if there is a battle and it's a siege
  1086. {
  1087. for(std::set< std::pair< std::pair< ui8, si16 >, ui8> >::const_iterator it = attackedParts.begin(); it != attackedParts.end(); ++it)
  1088. {
  1089. gs->curB->si.wallState[it->first.first] =
  1090. std::min( gs->curB->si.wallState[it->first.first] + it->second, 3 );
  1091. }
  1092. }
  1093. }
  1094. DLL_EXPORT void BattleStacksRemoved::applyGs( CGameState *gs )
  1095. {
  1096. if(!gs->curB)
  1097. return;
  1098. for(std::set<ui32>::const_iterator it = stackIDs.begin(); it != stackIDs.end(); ++it) //for each removed stack
  1099. {
  1100. for(int b=0; b<gs->curB->stacks.size(); ++b) //find it in vector of stacks
  1101. {
  1102. if(gs->curB->stacks[b]->ID == *it) //if found
  1103. {
  1104. gs->curB->stacks.erase(gs->curB->stacks.begin() + b); //remove
  1105. break;
  1106. }
  1107. }
  1108. }
  1109. }
  1110. DLL_EXPORT void YourTurn::applyGs( CGameState *gs )
  1111. {
  1112. gs->currentPlayer = player;
  1113. }
  1114. DLL_EXPORT void SetSelection::applyGs( CGameState *gs )
  1115. {
  1116. gs->getPlayer(player)->currentSelection = id;
  1117. }
  1118. DLL_EXPORT Component::Component(const CStackBasicDescriptor &stack)
  1119. :id(CREATURE), subtype(stack.type->idNumber), val(stack.count), when(0)
  1120. {
  1121. }