NetPacksLib.cpp 33 KB

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