NetPacksLib.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  1. #define VCMI_DLL
  2. #include "NetPacks.h"
  3. #include "../hch/CGeneralTextHandler.h"
  4. #include "../hch/CDefObjInfoHandler.h"
  5. #include "../hch/CArtHandler.h"
  6. #include "../hch/CHeroHandler.h"
  7. #include "../hch/CObjectHandler.h"
  8. #include "VCMI_Lib.h"
  9. #include "map.h"
  10. #include "../hch/CSpellHandler.h"
  11. #include <boost/bind.hpp>
  12. #include <boost/foreach.hpp>
  13. #include <boost/lexical_cast.hpp>
  14. #include <boost/algorithm/string/replace.hpp>
  15. #include <boost/thread.hpp>
  16. #include <boost/thread/shared_mutex.hpp>
  17. #undef min
  18. #undef max
  19. /*
  20. * NetPacksLib.cpp, part of VCMI engine
  21. *
  22. * Authors: listed in file AUTHORS in main folder
  23. *
  24. * License: GNU General Public License v2.0 or later
  25. * Full text of license available in license.txt file, in main folder
  26. *
  27. */
  28. #ifdef min
  29. #undef min
  30. #endif
  31. #ifdef max
  32. #undef max
  33. #endif
  34. DLL_EXPORT void SetResource::applyGs( CGameState *gs )
  35. {
  36. assert(player < PLAYER_LIMIT);
  37. amax(val, 0); //new value must be >= 0
  38. gs->getPlayer(player)->resources[resid] = val;
  39. }
  40. DLL_EXPORT void SetResources::applyGs( CGameState *gs )
  41. {
  42. assert(player < PLAYER_LIMIT);
  43. for(int i=0;i<res.size();i++)
  44. gs->getPlayer(player)->resources[i] = res[i];
  45. }
  46. DLL_EXPORT void SetPrimSkill::applyGs( CGameState *gs )
  47. {
  48. CGHeroInstance *hero = gs->getHero(id);
  49. if(which <4)
  50. {
  51. if(abs)
  52. hero->primSkills[which] = val;
  53. else
  54. hero->primSkills[which] += val;
  55. }
  56. else if(which == 4) //XP
  57. {
  58. if(abs)
  59. hero->exp = val;
  60. else
  61. hero->exp += val;
  62. }
  63. }
  64. DLL_EXPORT void SetSecSkill::applyGs( CGameState *gs )
  65. {
  66. CGHeroInstance *hero = gs->getHero(id);
  67. if(hero->getSecSkillLevel(which) == 0)
  68. {
  69. hero->secSkills.push_back(std::pair<int,int>(which, val));
  70. }
  71. else
  72. {
  73. for(unsigned i=0;i<hero->secSkills.size();i++)
  74. {
  75. if(hero->secSkills[i].first == which)
  76. {
  77. if(abs)
  78. hero->secSkills[i].second = val;
  79. else
  80. hero->secSkills[i].second += val;
  81. if(hero->secSkills[i].second > 3) //workaround to avoid crashes when same sec skill is given more than once
  82. {
  83. tlog1 << "Warning: Skill " << which << " increased over limit! Decreasing to Expert.\n";
  84. hero->secSkills[i].second = 3;
  85. }
  86. }
  87. }
  88. }
  89. }
  90. DLL_EXPORT void HeroVisitCastle::applyGs( CGameState *gs )
  91. {
  92. CGHeroInstance *h = gs->getHero(hid);
  93. CGTownInstance *t = gs->getTown(tid);
  94. if(start())
  95. {
  96. if(garrison())
  97. {
  98. t->garrisonHero = h;
  99. h->visitedTown = t;
  100. h->inTownGarrison = true;
  101. }
  102. else
  103. {
  104. t->visitingHero = h;
  105. h->visitedTown = t;
  106. h->inTownGarrison = false;
  107. }
  108. }
  109. else
  110. {
  111. if(garrison())
  112. {
  113. t->garrisonHero = NULL;
  114. h->visitedTown = NULL;
  115. h->inTownGarrison = false;
  116. }
  117. else
  118. {
  119. t->visitingHero = NULL;
  120. h->visitedTown = NULL;
  121. h->inTownGarrison = false;
  122. }
  123. }
  124. }
  125. DLL_EXPORT void ChangeSpells::applyGs( CGameState *gs )
  126. {
  127. CGHeroInstance *hero = gs->getHero(hid);
  128. if(learn)
  129. BOOST_FOREACH(ui32 sid, spells)
  130. hero->spells.insert(sid);
  131. else
  132. BOOST_FOREACH(ui32 sid, spells)
  133. hero->spells.erase(sid);
  134. }
  135. DLL_EXPORT void SetMana::applyGs( CGameState *gs )
  136. {
  137. CGHeroInstance *hero = gs->getHero(hid);
  138. amax(val, 0); //not less than 0
  139. hero->mana = val;
  140. }
  141. DLL_EXPORT void SetMovePoints::applyGs( CGameState *gs )
  142. {
  143. CGHeroInstance *hero = gs->getHero(hid);
  144. hero->movement = val;
  145. }
  146. DLL_EXPORT void FoWChange::applyGs( CGameState *gs )
  147. {
  148. BOOST_FOREACH(int3 t, tiles)
  149. gs->getPlayer(player)->fogOfWarMap[t.x][t.y][t.z] = mode;
  150. }
  151. DLL_EXPORT void SetAvailableHeroes::applyGs( CGameState *gs )
  152. {
  153. gs->getPlayer(player)->availableHeroes.clear();
  154. CGHeroInstance *h = (hid1>=0 ? gs->hpool.heroesPool[hid1] : NULL);
  155. gs->getPlayer(player)->availableHeroes.push_back(h);
  156. if(h && flags & 1)
  157. {
  158. h->army.slots.clear();
  159. h->army.slots[0] = std::pair<ui32,si32>(VLC->creh->nameToID[h->type->refTypeStack[0]],1);
  160. }
  161. h = (hid2>=0 ? gs->hpool.heroesPool[hid2] : NULL);
  162. gs->getPlayer(player)->availableHeroes.push_back(h);
  163. if(flags & 2)
  164. {
  165. h->army.slots.clear();
  166. h->army.slots[0] = std::pair<ui32,si32>(VLC->creh->nameToID[h->type->refTypeStack[0]],1);
  167. }
  168. }
  169. DLL_EXPORT void GiveBonus::applyGs( CGameState *gs )
  170. {
  171. CGHeroInstance *h = gs->getHero(hid);
  172. h->bonuses.push_back(bonus);
  173. std::string &descr = h->bonuses.back().description;
  174. if(!bdescr.message.size()
  175. && bonus.source == HeroBonus::OBJECT
  176. && (bonus.type == HeroBonus::LUCK || bonus.type == HeroBonus::MORALE || bonus.type == HeroBonus::MORALE_AND_LUCK)
  177. && gs->map->objects[bonus.id]->ID == 26) //it's morale/luck bonus from an event without description
  178. {
  179. descr = VLC->generaltexth->arraytxt[bonus.val > 0 ? 110 : 109]; //+/-%d Temporary until next battle"
  180. boost::replace_first(descr,"%d",boost::lexical_cast<std::string>(std::abs(bonus.val)));
  181. }
  182. else
  183. {
  184. bdescr.toString(descr);
  185. }
  186. }
  187. DLL_EXPORT void ChangeObjPos::applyGs( CGameState *gs )
  188. {
  189. CGObjectInstance *obj = gs->map->objects[objid];
  190. if(!obj)
  191. {
  192. tlog1 << "Wrong ChangeObjPos: object " << objid << " doesn't exist!\n";
  193. return;
  194. }
  195. gs->map->removeBlockVisTiles(obj);
  196. obj->pos = nPos;
  197. gs->map->addBlockVisTiles(obj);
  198. }
  199. DLL_EXPORT void PlayerEndsGame::applyGs( CGameState *gs )
  200. {
  201. PlayerState *p = gs->getPlayer(player);
  202. p->status = victory ? 2 : 1;
  203. }
  204. DLL_EXPORT void RemoveObject::applyGs( CGameState *gs )
  205. {
  206. CGObjectInstance *obj = gs->map->objects[id];
  207. if(obj->ID==HEROI_TYPE)
  208. {
  209. CGHeroInstance *h = static_cast<CGHeroInstance*>(obj);
  210. std::vector<CGHeroInstance*>::iterator nitr = std::find(gs->map->heroes.begin(), gs->map->heroes.end(),h);
  211. gs->map->heroes.erase(nitr);
  212. int player = h->tempOwner;
  213. nitr = std::find(gs->getPlayer(player)->heroes.begin(), gs->getPlayer(player)->heroes.end(), h);
  214. gs->getPlayer(player)->heroes.erase(nitr);
  215. h->tempOwner = 255; //no one owns beaten hero
  216. if(h->visitedTown)
  217. {
  218. if(h->inTownGarrison)
  219. h->visitedTown->garrisonHero = NULL;
  220. else
  221. h->visitedTown->visitingHero = NULL;
  222. h->visitedTown = NULL;
  223. }
  224. //TODO: add to the pool?
  225. }
  226. else if (obj->ID==CREI_TYPE) //only fixed monsters can be a part of quest
  227. {
  228. CGCreature *cre = static_cast<CGCreature*>(obj);
  229. gs->map->monsters[cre->identifier] = NULL;
  230. }
  231. gs->map->objects[id] = NULL;
  232. //unblock tiles
  233. if(obj->defInfo)
  234. {
  235. gs->map->removeBlockVisTiles(obj);
  236. }
  237. }
  238. static int getDir(int3 src, int3 dst)
  239. {
  240. int ret = -1;
  241. if(dst.x+1 == src.x && dst.y+1 == src.y) //tl
  242. {
  243. ret = 1;
  244. }
  245. else if(dst.x == src.x && dst.y+1 == src.y) //t
  246. {
  247. ret = 2;
  248. }
  249. else if(dst.x-1 == src.x && dst.y+1 == src.y) //tr
  250. {
  251. ret = 3;
  252. }
  253. else if(dst.x-1 == src.x && dst.y == src.y) //r
  254. {
  255. ret = 4;
  256. }
  257. else if(dst.x-1 == src.x && dst.y-1 == src.y) //br
  258. {
  259. ret = 5;
  260. }
  261. else if(dst.x == src.x && dst.y-1 == src.y) //b
  262. {
  263. ret = 6;
  264. }
  265. else if(dst.x+1 == src.x && dst.y-1 == src.y) //bl
  266. {
  267. ret = 7;
  268. }
  269. else if(dst.x+1 == src.x && dst.y == src.y) //l
  270. {
  271. ret = 8;
  272. }
  273. return ret;
  274. }
  275. void TryMoveHero::applyGs( CGameState *gs )
  276. {
  277. CGHeroInstance *h = gs->getHero(id);
  278. h->movement = movePoints;
  279. if((result == SUCCESS || result == BLOCKING_VISIT || result == EMBARK || result == DISEMBARK) && start != end)
  280. h->moveDir = getDir(start,end);
  281. if(result == EMBARK) //hero enters boat at dest tile
  282. {
  283. const TerrainTile &tt = gs->map->getTile(CGHeroInstance::convertPosition(end, false));
  284. assert(tt.visitableObjects.size() == 1 && tt.visitableObjects.front()->ID == 8); //the only vis obj at dest is Boat
  285. CGBoat *boat = static_cast<CGBoat*>(tt.visitableObjects.front());
  286. gs->map->removeBlockVisTiles(boat); //hero blockvis mask will be used, we don't need to duplicate it with boat
  287. h->boat = boat;
  288. boat->hero = h;
  289. }
  290. else if(result == DISEMBARK) //hero leaves boat to dest tile
  291. {
  292. h->boat->direction = h->moveDir;
  293. h->boat->pos = start;
  294. h->boat->hero = NULL;
  295. gs->map->addBlockVisTiles(h->boat);
  296. h->boat = NULL;
  297. }
  298. if(start!=end && (result == SUCCESS || result == TELEPORTATION || result == EMBARK || result == DISEMBARK))
  299. {
  300. gs->map->removeBlockVisTiles(h);
  301. h->pos = end;
  302. if(h->boat)
  303. h->boat->pos = end;
  304. gs->map->addBlockVisTiles(h);
  305. }
  306. BOOST_FOREACH(int3 t, fowRevealed)
  307. gs->getPlayer(h->getOwner())->fogOfWarMap[t.x][t.y][t.z] = 1;
  308. }
  309. DLL_EXPORT void SetGarrisons::applyGs( CGameState *gs )
  310. {
  311. for(std::map<ui32,CCreatureSet>::iterator i = garrs.begin(); i!=garrs.end(); i++)
  312. {
  313. CArmedInstance *ai = static_cast<CArmedInstance*>(gs->map->objects[i->first]);
  314. ai->army = i->second;
  315. if(ai->ID==TOWNI_TYPE && (static_cast<CGTownInstance*>(ai))->garrisonHero) //if there is a hero in garrison then we must update also his army
  316. const_cast<CGHeroInstance*>((static_cast<CGTownInstance*>(ai))->garrisonHero)->army = i->second;
  317. else if(ai->ID==HEROI_TYPE)
  318. {
  319. CGHeroInstance *h = static_cast<CGHeroInstance*>(ai);
  320. if(h->visitedTown && h->inTownGarrison)
  321. h->visitedTown->army = i->second;
  322. }
  323. }
  324. }
  325. DLL_EXPORT void NewStructures::applyGs( CGameState *gs )
  326. {
  327. CGTownInstance *t = gs->getTown(tid);
  328. BOOST_FOREACH(si32 id,bid)
  329. {
  330. t->builtBuildings.insert(id);
  331. }
  332. t->builded = builded;
  333. }
  334. DLL_EXPORT void RazeStructures::applyGs( CGameState *gs )
  335. {
  336. CGTownInstance *t = gs->getTown(tid);
  337. BOOST_FOREACH(si32 id,bid)
  338. {
  339. t->builtBuildings.erase(id);
  340. }
  341. t->destroyed = destroyed; //yeaha
  342. }
  343. DLL_EXPORT void SetAvailableCreatures::applyGs( CGameState *gs )
  344. {
  345. CGDwelling *dw = dynamic_cast<CGDwelling*>(gs->map->objects[tid]);
  346. assert(dw);
  347. dw->creatures = creatures;
  348. }
  349. DLL_EXPORT void SetHeroesInTown::applyGs( CGameState *gs )
  350. {
  351. CGTownInstance *t = gs->getTown(tid);
  352. CGHeroInstance *v = gs->getHero(visiting),
  353. *g = gs->getHero(garrison);
  354. t->visitingHero = v;
  355. t->garrisonHero = g;
  356. if(v)
  357. {
  358. v->visitedTown = t;
  359. v->inTownGarrison = false;
  360. gs->map->addBlockVisTiles(v);
  361. }
  362. if(g)
  363. {
  364. g->visitedTown = t;
  365. g->inTownGarrison = true;
  366. gs->map->removeBlockVisTiles(g);
  367. }
  368. }
  369. DLL_EXPORT void SetHeroArtifacts::applyGs( CGameState *gs )
  370. {
  371. CGHeroInstance *h = gs->getHero(hid);
  372. std::vector<ui32> equiped, unequiped;
  373. for(std::map<ui16,ui32>::const_iterator i = h->artifWorn.begin(); i != h->artifWorn.end(); i++)
  374. if(!vstd::contains(artifWorn,i->first) || artifWorn[i->first] != i->second)
  375. unequiped.push_back(i->second);
  376. for(std::map<ui16,ui32>::const_iterator i = artifWorn.begin(); i != artifWorn.end(); i++)
  377. if(!vstd::contains(h->artifWorn,i->first) || h->artifWorn[i->first] != i->second)
  378. equiped.push_back(i->second);
  379. BOOST_FOREACH(ui32 id, equiped)
  380. {
  381. //if hero already had equipped at least one artifact of that type, don't give any new bonuses
  382. if(h->getArtPos(id) >= 0)
  383. continue;
  384. CArtifact &art = VLC->arth->artifacts[id];
  385. for(std::list<HeroBonus>::iterator i = art.bonuses.begin(); i != art.bonuses.end(); i++)
  386. {
  387. gained.push_back(&*i);
  388. h->bonuses.push_back(*i);
  389. }
  390. }
  391. //update hero data
  392. h->artifacts = artifacts;
  393. h->artifWorn = artifWorn;
  394. //remove bonus from unequipped artifact
  395. BOOST_FOREACH(ui32 id, unequiped)
  396. {
  397. //if hero still has equipped at least one artifact of that type, don't remove bonuses
  398. if(h->getArtPos(id) >= 0)
  399. continue;
  400. while(1)
  401. {
  402. std::list<HeroBonus>::iterator hlp = std::find_if(h->bonuses.begin(),h->bonuses.end(),boost::bind(HeroBonus::IsFrom,_1,HeroBonus::ARTIFACT,id));
  403. if(hlp != h->bonuses.end())
  404. {
  405. lost.push_back(&*hlp);
  406. h->bonuses.erase(hlp);
  407. }
  408. else
  409. {
  410. break;
  411. }
  412. }
  413. }
  414. }
  415. DLL_EXPORT void SetHeroArtifacts::setArtAtPos(ui16 pos, int art)
  416. {
  417. if(art<0)
  418. {
  419. if(pos<19)
  420. artifWorn.erase(pos);
  421. else
  422. artifacts.erase(artifacts.begin() + (pos - 19));
  423. }
  424. else
  425. {
  426. if (pos < 19) {
  427. artifWorn[pos] = art;
  428. } else { // Goes into the backpack.
  429. if(pos - 19 < artifacts.size())
  430. artifacts.insert(artifacts.begin() + (pos - 19), art);
  431. else
  432. artifacts.push_back(art);
  433. }
  434. }
  435. }
  436. DLL_EXPORT void HeroRecruited::applyGs( CGameState *gs )
  437. {
  438. assert(vstd::contains(gs->hpool.heroesPool, hid));
  439. CGHeroInstance *h = gs->hpool.heroesPool[hid];
  440. CGTownInstance *t = gs->getTown(tid);
  441. h->setOwner(player);
  442. h->pos = tile;
  443. h->movement = h->maxMovePoints(true);
  444. gs->hpool.heroesPool.erase(hid);
  445. if(h->id < 0)
  446. {
  447. h->id = gs->map->objects.size();
  448. gs->map->objects.push_back(h);
  449. }
  450. else
  451. gs->map->objects[h->id] = h;
  452. h->initHeroDefInfo();
  453. gs->map->heroes.push_back(h);
  454. gs->getPlayer(h->getOwner())->heroes.push_back(h);
  455. h->initObj();
  456. gs->map->addBlockVisTiles(h);
  457. t->visitingHero = h;
  458. h->visitedTown = t;
  459. h->inTownGarrison = false;
  460. }
  461. DLL_EXPORT void GiveHero::applyGs( CGameState *gs )
  462. {
  463. CGHeroInstance *h = gs->getHero(id);
  464. gs->map->removeBlockVisTiles(h,true);
  465. h->setOwner(player);
  466. h->movement = h->maxMovePoints(true);
  467. h->initHeroDefInfo();
  468. gs->map->heroes.push_back(h);
  469. gs->getPlayer(h->getOwner())->heroes.push_back(h);
  470. gs->map->addBlockVisTiles(h);
  471. h->inTownGarrison = false;
  472. }
  473. DLL_EXPORT void NewObject::applyGs( CGameState *gs )
  474. {
  475. CGObjectInstance *o = NULL;
  476. switch(ID)
  477. {
  478. case 8:
  479. o = new CGBoat();
  480. break;
  481. default:
  482. o = new CGObjectInstance();
  483. break;
  484. }
  485. o->ID = ID;
  486. o->subID = subID;
  487. o->pos = pos;
  488. o->defInfo = VLC->dobjinfo->gobjs[ID][subID];
  489. id = o->id = gs->map->objects.size();
  490. o->hoverName = VLC->generaltexth->names[ID];
  491. gs->map->objects.push_back(o);
  492. gs->map->addBlockVisTiles(o);
  493. o->initObj();
  494. assert(o->defInfo);
  495. }
  496. DLL_EXPORT void NewTurn::applyGs( CGameState *gs )
  497. {
  498. gs->day = day;
  499. BOOST_FOREACH(NewTurn::Hero h, heroes) //give mana/movement point
  500. {
  501. CGHeroInstance *hero = gs->getHero(h.id);
  502. hero->movement = h.move;
  503. hero->mana = h.mana;
  504. }
  505. for(std::map<ui8, std::vector<si32> >::iterator i = res.begin(); i != res.end(); i++)
  506. {
  507. assert(i->first < PLAYER_LIMIT);
  508. std::vector<si32> &playerRes = gs->getPlayer(i->first)->resources;
  509. for(int j = 0; j < i->second.size(); j++)
  510. playerRes[j] = i->second[j];
  511. }
  512. BOOST_FOREACH(SetAvailableCreatures h, cres) //set available creatures in towns
  513. h.applyGs(gs);
  514. if(resetBuilded) //reset amount of structures set in this turn in towns
  515. BOOST_FOREACH(CGTownInstance* t, gs->map->towns)
  516. t->builded = 0;
  517. BOOST_FOREACH(CGHeroInstance *h, gs->map->heroes)
  518. h->bonuses.remove_if(HeroBonus::OneDay);
  519. if(gs->getDate(1) == 7) //new week
  520. BOOST_FOREACH(CGHeroInstance *h, gs->map->heroes)
  521. h->bonuses.remove_if(HeroBonus::OneWeek);
  522. //count days without town
  523. for( std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
  524. {
  525. if(i->second.towns.size() || gs->day == 1)
  526. i->second.daysWithoutCastle = 0;
  527. else
  528. i->second.daysWithoutCastle++;
  529. }
  530. }
  531. DLL_EXPORT void SetObjectProperty::applyGs( CGameState *gs )
  532. {
  533. CGObjectInstance *obj = gs->map->objects[id];
  534. if(!obj)
  535. {
  536. tlog1 << "Wrong object ID - property cannot be set!\n";
  537. return;
  538. }
  539. if(what == 1)
  540. {
  541. if(obj->ID == TOWNI_TYPE)
  542. {
  543. CGTownInstance *t = static_cast<CGTownInstance*>(obj);
  544. if(t->tempOwner < PLAYER_LIMIT)
  545. gs->getPlayer(t->tempOwner)->towns -= t;
  546. if(val < PLAYER_LIMIT)
  547. gs->getPlayer(val)->towns.push_back(t);
  548. }
  549. }
  550. obj->setProperty(what,val);
  551. }
  552. DLL_EXPORT void SetHoverName::applyGs( CGameState *gs )
  553. {
  554. name.toString(gs->map->objects[id]->hoverName);
  555. }
  556. DLL_EXPORT void HeroLevelUp::applyGs( CGameState *gs )
  557. {
  558. gs->getHero(heroid)->level = level;
  559. }
  560. DLL_EXPORT void BattleStart::applyGs( CGameState *gs )
  561. {
  562. gs->curB = info;
  563. }
  564. DLL_EXPORT void BattleNextRound::applyGs( CGameState *gs )
  565. {
  566. gs->curB->castSpells[0] = gs->curB->castSpells[1] = 0;
  567. gs->curB->round = round;
  568. BOOST_FOREACH(CStack *s, gs->curB->stacks)
  569. {
  570. s->state -= DEFENDING;
  571. s->state -= WAITING;
  572. s->state -= MOVED;
  573. s->state -= HAD_MORALE;
  574. s->counterAttacks = 1 + s->valOfFeatures(StackFeature::ADDITIONAL_RETALIATION);
  575. //regeneration
  576. if( s->hasFeatureOfType(StackFeature::HP_REGENERATION) && s->alive() )
  577. s->firstHPleft = std::min<ui32>( s->MaxHealth(), s->valOfFeatures(StackFeature::HP_REGENERATION) );
  578. if( s->hasFeatureOfType(StackFeature::FULL_HP_REGENERATION) && s->alive() )
  579. s->firstHPleft = s->MaxHealth();
  580. //remove effects and restore only those with remaining turns in duration
  581. std::vector<CStack::StackEffect> tmpEffects = s->effects;
  582. s->effects.clear();
  583. for(int i=0; i < tmpEffects.size(); i++)
  584. {
  585. tmpEffects[i].turnsRemain--;
  586. if(tmpEffects[i].turnsRemain > 0)
  587. s->effects.push_back(tmpEffects[i]);
  588. }
  589. //the same as above for features
  590. std::vector<StackFeature> tmpFeatures = s->features;
  591. s->features.clear();
  592. for(int i=0; i < tmpFeatures.size(); i++)
  593. {
  594. if((tmpFeatures[i].duration & StackFeature::N_TURNS) != 0)
  595. {
  596. tmpFeatures[i].turnsRemain--;
  597. if(tmpFeatures[i].turnsRemain > 0)
  598. s->features.push_back(tmpFeatures[i]);
  599. }
  600. else
  601. {
  602. s->features.push_back(tmpFeatures[i]);
  603. }
  604. }
  605. }
  606. }
  607. DLL_EXPORT void BattleSetActiveStack::applyGs( CGameState *gs )
  608. {
  609. gs->curB->activeStack = stack;
  610. CStack *st = gs->curB->getStack(stack);
  611. if(vstd::contains(st->state,MOVED)) //if stack is moving second time this turn it must had a high morale bonus
  612. st->state.insert(HAD_MORALE);
  613. }
  614. void BattleResult::applyGs( CGameState *gs )
  615. {
  616. for(unsigned i=0;i<gs->curB->stacks.size();i++)
  617. delete gs->curB->stacks[i];
  618. //remove any "until next battle" bonuses
  619. CGHeroInstance *h;
  620. h = gs->curB->heroes[0];
  621. if(h)
  622. h->bonuses.remove_if(HeroBonus::OneBattle);
  623. h = gs->curB->heroes[1];
  624. if(h)
  625. h->bonuses.remove_if(HeroBonus::OneBattle);
  626. delete gs->curB;
  627. gs->curB = NULL;
  628. }
  629. void BattleStackMoved::applyGs( CGameState *gs )
  630. {
  631. gs->curB->getStack(stack)->position = tile;
  632. }
  633. DLL_EXPORT void BattleStackAttacked::applyGs( CGameState *gs )
  634. {
  635. CStack * at = gs->curB->getStack(stackAttacked);
  636. at->amount = newAmount;
  637. at->firstHPleft = newHP;
  638. if(killed())
  639. at->state -= ALIVE;
  640. }
  641. DLL_EXPORT void BattleAttack::applyGs( CGameState *gs )
  642. {
  643. CStack *attacker = gs->curB->getStack(stackAttacking);
  644. if(counter())
  645. attacker->counterAttacks--;
  646. if(shot())
  647. attacker->shots--;
  648. BOOST_FOREACH(BattleStackAttacked stackAttacked, bsa)
  649. stackAttacked.applyGs(gs);
  650. for(int g=0; g<attacker->features.size(); ++g)
  651. {
  652. if((attacker->features[g].duration & StackFeature::UNTIL_ATTACK) != 0)
  653. {
  654. attacker->features.erase(attacker->features.begin() + g);
  655. g = 0;
  656. }
  657. }
  658. for(std::set<BattleStackAttacked>::const_iterator it = bsa.begin(); it != bsa.end(); ++it)
  659. {
  660. CStack * stack = gs->curB->getStack(it->stackAttacked, false);
  661. for(int g=0; g<stack->features.size(); ++g)
  662. {
  663. if((stack->features[g].duration & StackFeature::UNITL_BEING_ATTACKED) != 0)
  664. {
  665. stack->features.erase(stack->features.begin() + g);
  666. g = 0;
  667. }
  668. }
  669. }
  670. }
  671. DLL_EXPORT void StartAction::applyGs( CGameState *gs )
  672. {
  673. CStack *st = gs->curB->getStack(ba.stackNumber);
  674. if(ba.actionType != 1) //don't check for stack if it's custom action by hero
  675. assert(st);
  676. switch(ba.actionType)
  677. {
  678. case 3:
  679. st->state.insert(DEFENDING);
  680. break;
  681. case 8:
  682. st->state.insert(WAITING);
  683. return;
  684. case 2: case 6: case 7: case 9: case 10: case 11:
  685. st->state.insert(MOVED);
  686. break;
  687. }
  688. if(st)
  689. 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)
  690. }
  691. DLL_EXPORT void SpellCast::applyGs( CGameState *gs )
  692. {
  693. CGHeroInstance *h = (side) ? gs->curB->heroes[1] : gs->curB->heroes[0];
  694. if(h)
  695. {
  696. int spellCost = 0;
  697. if(gs->curB)
  698. {
  699. spellCost = gs->curB->getSpellCost(&VLC->spellh->spells[id], h);
  700. }
  701. else
  702. {
  703. spellCost = VLC->spellh->spells[id].costs[skill];
  704. }
  705. h->mana -= spellCost;
  706. if(h->mana < 0) h->mana = 0;
  707. }
  708. if(side >= 0 && side < 2)
  709. {
  710. gs->curB->castSpells[side]++;
  711. }
  712. if(gs->curB && id == 35) //dispel
  713. {
  714. for(std::set<ui32>::const_iterator it = affectedCres.begin(); it != affectedCres.end(); ++it)
  715. {
  716. CStack *s = gs->curB->getStack(*it);
  717. if(s && !vstd::contains(resisted, s->ID)) //if stack exists and it didn't resist
  718. {
  719. s->effects.clear(); //removing all effects
  720. //removing all features from spells
  721. std::vector<StackFeature> tmpFeatures = s->features;
  722. s->features.clear();
  723. for(int i=0; i < tmpFeatures.size(); i++)
  724. {
  725. if(tmpFeatures[i].source != StackFeature::SPELL_EFFECT)
  726. {
  727. s->features.push_back(tmpFeatures[i]);
  728. }
  729. }
  730. }
  731. }
  732. }
  733. //elemental summoning
  734. if(id >= 66 && id <= 69)
  735. {
  736. int creID;
  737. switch(id)
  738. {
  739. case 66:
  740. creID = 114; //fire elemental
  741. break;
  742. case 67:
  743. creID = 113; //earth elemental
  744. break;
  745. case 68:
  746. creID = 115; //water elemental
  747. break;
  748. case 69:
  749. creID = 112; //air elemental
  750. break;
  751. }
  752. const int3 & tile = gs->curB->tile;
  753. TerrainTile::EterrainType ter = gs->map->terrain[tile.x][tile.y][tile.z].tertype;
  754. int pos; //position of stack on the battlefield - to be calculated
  755. bool ac[BFIELD_SIZE];
  756. std::set<int> occupyable;
  757. bool twoHex = vstd::contains(VLC->creh->creatures[creID].abilities, StackFeature::DOUBLE_WIDE);
  758. bool flying = vstd::contains(VLC->creh->creatures[creID].abilities, StackFeature::FLYING);
  759. gs->curB->getAccessibilityMap(ac, twoHex, !side, true, occupyable, flying);
  760. for(int g=0; g<BFIELD_SIZE; ++g)
  761. {
  762. if(g % BFIELD_WIDTH != 0 && g % BFIELD_WIDTH != BFIELD_WIDTH-1 && BattleInfo::isAccessible(g, ac, twoHex, !side, flying, true) )
  763. {
  764. pos = g;
  765. break;
  766. }
  767. }
  768. CStack * summonedStack = gs->curB->generateNewStack(h, creID, h->getPrimSkillLevel(2) * VLC->spellh->spells[id].powers[skill], gs->curB->stacks.size(), !side, 255, ter, pos);
  769. summonedStack->features.push_back( makeFeature(StackFeature::SUMMONED, StackFeature::WHOLE_BATTLE, 0, 0, StackFeature::BONUS_FROM_HERO) );
  770. gs->curB->stacks.push_back(summonedStack);
  771. }
  772. }
  773. static inline StackFeature featureGenerator(StackFeature::ECombatFeatures type, si16 subtype, si32 value, ui16 turnsRemain, si32 additionalInfo = 0)
  774. {
  775. return makeFeature(type, StackFeature::N_TURNS, subtype, value, StackFeature::SPELL_EFFECT, turnsRemain, additionalInfo);
  776. }
  777. static std::vector<StackFeature> stackEffectToFeature(const CStack::StackEffect & sse)
  778. {
  779. std::vector<StackFeature> sf;
  780. switch(sse.id)
  781. {
  782. case 27: //shield
  783. sf.push_back(featureGenerator(StackFeature::GENERAL_DAMAGE_REDUCTION, 0, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  784. break;
  785. case 28: //air shield
  786. sf.push_back(featureGenerator(StackFeature::GENERAL_DAMAGE_REDUCTION, 1, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  787. break;
  788. case 30: //protection from air
  789. sf.push_back(featureGenerator(StackFeature::SPELL_DAMAGE_REDUCTION, 0, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  790. break;
  791. case 31: //protection from fire
  792. sf.push_back(featureGenerator(StackFeature::SPELL_DAMAGE_REDUCTION, 1, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  793. break;
  794. case 32: //protection from water
  795. sf.push_back(featureGenerator(StackFeature::SPELL_DAMAGE_REDUCTION, 2, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  796. break;
  797. case 33: //protection from earth
  798. sf.push_back(featureGenerator(StackFeature::SPELL_DAMAGE_REDUCTION, 3, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  799. break;
  800. case 34: //anti-magic
  801. sf.push_back(featureGenerator(StackFeature::LEVEL_SPELL_IMMUNITY, 0, VLC->spellh->spells[sse.id].powers[sse.level] - 1, sse.turnsRemain));
  802. break;
  803. case 41: //bless
  804. sf.push_back(featureGenerator(StackFeature::ALWAYS_MAXIMUM_DAMAGE, -1, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  805. break;
  806. case 42: //curse
  807. sf.push_back(featureGenerator(StackFeature::ALWAYS_MINIMUM_DAMAGE, -1, -1 * VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain, sse.level >= 2 ? 20 : 0));
  808. break;
  809. case 43: //bloodlust
  810. sf.push_back(featureGenerator(StackFeature::ATTACK_BONUS, 0, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  811. break;
  812. case 44: //precision
  813. sf.push_back(featureGenerator(StackFeature::ATTACK_BONUS, 1, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  814. break;
  815. case 45: //weakness
  816. sf.push_back(featureGenerator(StackFeature::ATTACK_BONUS, -1, -1 * VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  817. break;
  818. case 46: //stone skin
  819. sf.push_back(featureGenerator(StackFeature::DEFENCE_BONUS, -1, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  820. break;
  821. case 47: //disrupting ray
  822. sf.push_back(featureGenerator(StackFeature::DEFENCE_BONUS, -1, -1 * VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  823. break;
  824. case 48: //prayer
  825. sf.push_back(featureGenerator(StackFeature::ATTACK_BONUS, 0, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  826. sf.push_back(featureGenerator(StackFeature::DEFENCE_BONUS, 0, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  827. sf.push_back(featureGenerator(StackFeature::SPEED_BONUS, 0, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  828. break;
  829. case 49: //mirth
  830. sf.push_back(featureGenerator(StackFeature::MORALE_BONUS, 0, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  831. break;
  832. case 50: //sorrow
  833. sf.push_back(featureGenerator(StackFeature::MORALE_BONUS, 0, -1 * VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  834. break;
  835. case 51: //fortune
  836. sf.push_back(featureGenerator(StackFeature::LUCK_BONUS, 0, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  837. break;
  838. case 52: //misfortune
  839. sf.push_back(featureGenerator(StackFeature::LUCK_BONUS, 0, -1 * VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  840. break;
  841. case 53: //haste
  842. sf.push_back(featureGenerator(StackFeature::SPEED_BONUS, 0, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  843. break;
  844. case 54: //slow
  845. sf.push_back(featureGenerator(StackFeature::SPEED_BONUS, 0, 0, sse.turnsRemain, -1 * ( 100 - VLC->spellh->spells[sse.id].powers[sse.level] ) ));
  846. break;
  847. case 55: //slayer
  848. sf.push_back(featureGenerator(StackFeature::SLAYER, 0, sse.level, sse.turnsRemain));
  849. break;
  850. case 56: //frenzy
  851. sf.push_back(featureGenerator(StackFeature::SLAYER, 0, sse.level, sse.turnsRemain));
  852. break;
  853. case 58: //counterstrike
  854. sf.push_back(featureGenerator(StackFeature::ADDITIONAL_RETALIATION, 0, VLC->spellh->spells[sse.id].powers[sse.level], sse.turnsRemain));
  855. break;
  856. case 59: //bersek
  857. sf.push_back(featureGenerator(StackFeature::ATTACKS_NEAREST_CREATURE, 0, sse.level, sse.turnsRemain));
  858. break;
  859. case 60: //hypnotize
  860. sf.push_back(featureGenerator(StackFeature::HYPNOTIZED, 0, sse.level, sse.turnsRemain));
  861. break;
  862. case 61: //forgetfulness
  863. sf.push_back(featureGenerator(StackFeature::SLAYER, 0, sse.level, sse.turnsRemain));
  864. break;
  865. case 62: //blind
  866. sf.push_back(makeFeature(StackFeature::NOT_ACTIVE, StackFeature::UNITL_BEING_ATTACKED | StackFeature::N_TURNS, 0, 0, StackFeature::SPELL_EFFECT, sse.turnsRemain, 0));
  867. sf.push_back(makeFeature(StackFeature::GENERAL_ATTACK_REDUCTION, StackFeature::UNTIL_ATTACK | StackFeature::N_TURNS, 0, VLC->spellh->spells[sse.id].powers[sse.level], StackFeature::SPELL_EFFECT, sse.turnsRemain, 0));
  868. break;
  869. }
  870. //setting positiveness
  871. for(int g=0; g<sf.size(); ++g)
  872. {
  873. sf[g].positiveness = VLC->spellh->spells[sse.id].positiveness;
  874. }
  875. return sf;
  876. }
  877. void actualizeEffect(CStack * s, CStack::StackEffect & ef)
  878. {
  879. //actualizing effects vector
  880. for(int g=0; g<s->effects.size(); ++g)
  881. {
  882. if(s->effects[g].id == ef.id)
  883. {
  884. s->effects[g].turnsRemain = std::max(s->effects[g].turnsRemain, ef.turnsRemain);
  885. }
  886. }
  887. //actualizing features vector
  888. std::vector<StackFeature> sf = stackEffectToFeature(ef);
  889. for(int b=0; b<sf.size(); ++b)
  890. {
  891. for(int g=0; g<s->features.size(); ++g)
  892. {
  893. if(s->features[g].source == StackFeature::SPELL_EFFECT && s->features[g].type == sf[b].type && s->features[g].subtype == sf[b].subtype)
  894. {
  895. s->features[g].turnsRemain = std::max(s->features[g].turnsRemain, ef.turnsRemain);
  896. }
  897. }
  898. }
  899. }
  900. bool containsEff(const std::vector<CStack::StackEffect> & vec, int effectId)
  901. {
  902. for(int g=0; g<vec.size(); ++g)
  903. {
  904. if(vec[g].id == effectId)
  905. return true;
  906. }
  907. return false;
  908. }
  909. DLL_EXPORT void SetStackEffect::applyGs( CGameState *gs )
  910. {
  911. BOOST_FOREACH(ui32 id, stacks)
  912. {
  913. CStack *s = gs->curB->getStack(id);
  914. if(s)
  915. {
  916. if(effect.id == 42 || !containsEff(s->effects, effect.id))//disrupting ray or not on the list - just add
  917. {
  918. s->effects.push_back(effect);
  919. std::vector<StackFeature> sf = stackEffectToFeature(effect);
  920. for(int n=0; n<sf.size(); ++n)
  921. {
  922. s->features.push_back(sf[n]);
  923. }
  924. }
  925. else //just actualize
  926. {
  927. actualizeEffect(s, effect);
  928. }
  929. }
  930. else
  931. tlog1 << "Cannot find stack " << id << std::endl;
  932. }
  933. }
  934. DLL_EXPORT void StacksInjured::applyGs( CGameState *gs )
  935. {
  936. BOOST_FOREACH(BattleStackAttacked stackAttacked, stacks)
  937. stackAttacked.applyGs(gs);
  938. }
  939. DLL_EXPORT void StacksHealedOrResurrected::applyGs( CGameState *gs )
  940. {
  941. for(int g=0; g<healedStacks.size(); ++g)
  942. {
  943. CStack * changedStack = gs->curB->getStack(healedStacks[g].stackID, false);
  944. //checking if we resurrect a stack that is under a living stack
  945. std::vector<int> access = gs->curB->getAccessibility(changedStack->ID, true);
  946. bool acc[BFIELD_SIZE];
  947. for(int h=0; h<BFIELD_SIZE; ++h)
  948. acc[h] = false;
  949. for(int h=0; h<access.size(); ++h)
  950. acc[access[h]] = true;
  951. if(!changedStack->alive() && !gs->curB->isAccessible(changedStack->position, acc,
  952. changedStack->hasFeatureOfType(StackFeature::DOUBLE_WIDE), changedStack->attackerOwned,
  953. changedStack->hasFeatureOfType(StackFeature::FLYING), true))
  954. return; //position is already occupied
  955. //applying changes
  956. bool resurrected = !changedStack->alive(); //indicates if stack is resurrected or just healed
  957. if(!changedStack->alive())
  958. {
  959. changedStack->state.insert(ALIVE);
  960. if(healedStacks[g].lowLevelResurrection)
  961. changedStack->features.push_back( makeFeature(StackFeature::SUMMONED, StackFeature::WHOLE_BATTLE, 0, 0, StackFeature::BONUS_FROM_HERO) );
  962. }
  963. int missingHPfirst = changedStack->MaxHealth() - changedStack->firstHPleft;
  964. int res = std::min( healedStacks[g].healedHP / changedStack->MaxHealth() , changedStack->baseAmount - changedStack->amount );
  965. changedStack->amount += res;
  966. changedStack->firstHPleft += healedStacks[g].healedHP - res * changedStack->MaxHealth();
  967. if(changedStack->firstHPleft > changedStack->MaxHealth())
  968. {
  969. changedStack->firstHPleft -= changedStack->MaxHealth();
  970. if(changedStack->baseAmount > changedStack->amount)
  971. {
  972. changedStack->amount += 1;
  973. }
  974. }
  975. amin(changedStack->firstHPleft, changedStack->MaxHealth());
  976. //removal of negative effects
  977. if(resurrected)
  978. {
  979. for(int h=0; h<changedStack->effects.size(); ++h)
  980. {
  981. if(VLC->spellh->spells[changedStack->effects[h].id].positiveness < 0)
  982. {
  983. changedStack->effects.erase(changedStack->effects.begin() + h);
  984. }
  985. }
  986. //removing all features from negative spells
  987. std::vector<StackFeature> tmpFeatures = changedStack->features;
  988. changedStack->features.clear();
  989. for(int i=0; i < tmpFeatures.size(); i++)
  990. {
  991. if(tmpFeatures[i].source != StackFeature::SPELL_EFFECT || tmpFeatures[i].positiveness >= 0)
  992. {
  993. changedStack->features.push_back(tmpFeatures[i]);
  994. }
  995. }
  996. }
  997. }
  998. }
  999. DLL_EXPORT void ObstaclesRemoved::applyGs( CGameState *gs )
  1000. {
  1001. if(gs->curB) //if there is a battle
  1002. {
  1003. for(std::set<si32>::const_iterator it = obstacles.begin(); it != obstacles.end(); ++it)
  1004. {
  1005. for(int i=0; i<gs->curB->obstacles.size(); ++i)
  1006. {
  1007. if(gs->curB->obstacles[i].uniqueID == *it) //remove this obstacle
  1008. {
  1009. gs->curB->obstacles.erase(gs->curB->obstacles.begin() + i);
  1010. break;
  1011. }
  1012. }
  1013. }
  1014. }
  1015. }
  1016. DLL_EXPORT void CatapultAttack::applyGs( CGameState *gs )
  1017. {
  1018. if(gs->curB && gs->curB->siege != 0) //if there is a battle and it's a siege
  1019. {
  1020. for(std::set< std::pair< std::pair< ui8, si16 >, ui8> >::const_iterator it = attackedParts.begin(); it != attackedParts.end(); ++it)
  1021. {
  1022. gs->curB->si.wallState[it->first.first] =
  1023. std::min( gs->curB->si.wallState[it->first.first] + it->second, 3 );
  1024. }
  1025. }
  1026. }
  1027. DLL_EXPORT void BattleStacksRemoved::applyGs( CGameState *gs )
  1028. {
  1029. if(!gs->curB)
  1030. return;
  1031. for(std::set<ui32>::const_iterator it = stackIDs.begin(); it != stackIDs.end(); ++it) //for each removed stack
  1032. {
  1033. for(int b=0; b<gs->curB->stacks.size(); ++b) //find it in vector of stacks
  1034. {
  1035. if(gs->curB->stacks[b]->ID == *it) //if found
  1036. {
  1037. gs->curB->stacks.erase(gs->curB->stacks.begin() + b); //remove
  1038. break;
  1039. }
  1040. }
  1041. }
  1042. }
  1043. DLL_EXPORT void YourTurn::applyGs( CGameState *gs )
  1044. {
  1045. gs->currentPlayer = player;
  1046. }
  1047. DLL_EXPORT void SetSelection::applyGs( CGameState *gs )
  1048. {
  1049. gs->getPlayer(player)->currentSelection = id;
  1050. }