2009-03-07 17:55:56 +02:00
|
|
|
#define VCMI_DLL
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "NetPacks.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "CGeneralTextHandler.h"
|
|
|
|
#include "CDefObjInfoHandler.h"
|
|
|
|
#include "CArtHandler.h"
|
|
|
|
#include "CHeroHandler.h"
|
|
|
|
#include "CObjectHandler.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "VCMI_Lib.h"
|
|
|
|
#include "map.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "CSpellHandler.h"
|
|
|
|
#include "CCreatureHandler.h"
|
2009-03-07 17:55:56 +02:00
|
|
|
#include <boost/bind.hpp>
|
|
|
|
#include <boost/foreach.hpp>
|
2009-04-21 01:57:07 +03:00
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
2009-03-07 17:55:56 +02:00
|
|
|
#include <boost/thread.hpp>
|
|
|
|
#include <boost/thread/shared_mutex.hpp>
|
2010-12-25 21:23:30 +02:00
|
|
|
#include "CGameState.h"
|
|
|
|
#include "BattleState.h"
|
2009-03-07 17:55:56 +02:00
|
|
|
|
2009-08-22 17:39:44 +03:00
|
|
|
#undef min
|
|
|
|
#undef max
|
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* NetPacksLib.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-05-18 01:52:22 +03:00
|
|
|
#ifdef min
|
|
|
|
#undef min
|
|
|
|
#endif
|
|
|
|
#ifdef max
|
|
|
|
#undef max
|
|
|
|
#endif
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
DLL_EXPORT void SetResource::applyGs( CGameState *gs )
|
|
|
|
{
|
2009-11-13 21:04:36 +02:00
|
|
|
assert(player < PLAYER_LIMIT);
|
2009-07-16 01:46:00 +03:00
|
|
|
amax(val, 0); //new value must be >= 0
|
2009-03-09 12:37:49 +02:00
|
|
|
gs->getPlayer(player)->resources[resid] = val;
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 03:42:08 +02:00
|
|
|
DLL_EXPORT void SetResources::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
assert(player < PLAYER_LIMIT);
|
|
|
|
for(int i=0;i<res.size();i++)
|
|
|
|
gs->getPlayer(player)->resources[i] = res[i];
|
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
|
|
|
|
DLL_EXPORT void SetPrimSkill::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CGHeroInstance *hero = gs->getHero(id);
|
2010-05-02 21:20:26 +03:00
|
|
|
assert(hero);
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
if(which <4)
|
|
|
|
{
|
2010-05-02 21:20:26 +03:00
|
|
|
Bonus *skill = hero->getBonus(Selector::type(Bonus::PRIMARY_SKILL) && Selector::subtype(which) && Selector::sourceType(Bonus::HERO_BASE_SKILL));
|
|
|
|
assert(skill);
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
if(abs)
|
2010-05-02 21:20:26 +03:00
|
|
|
skill->val = val;
|
2009-03-07 17:55:56 +02:00
|
|
|
else
|
2010-05-02 21:20:26 +03:00
|
|
|
skill->val += val;
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
else if(which == 4) //XP
|
|
|
|
{
|
|
|
|
if(abs)
|
|
|
|
hero->exp = val;
|
|
|
|
else
|
|
|
|
hero->exp += val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void SetSecSkill::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CGHeroInstance *hero = gs->getHero(id);
|
2010-12-23 22:18:10 +02:00
|
|
|
hero->setSecSkillLevel(static_cast<CGHeroInstance::SecondarySkill>(which), val, abs);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void HeroVisitCastle::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CGHeroInstance *h = gs->getHero(hid);
|
|
|
|
CGTownInstance *t = gs->getTown(tid);
|
|
|
|
if(start())
|
|
|
|
{
|
|
|
|
if(garrison())
|
|
|
|
{
|
|
|
|
t->garrisonHero = h;
|
|
|
|
h->visitedTown = t;
|
|
|
|
h->inTownGarrison = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
t->visitingHero = h;
|
|
|
|
h->visitedTown = t;
|
|
|
|
h->inTownGarrison = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(garrison())
|
|
|
|
{
|
|
|
|
t->garrisonHero = NULL;
|
|
|
|
h->visitedTown = NULL;
|
|
|
|
h->inTownGarrison = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
t->visitingHero = NULL;
|
|
|
|
h->visitedTown = NULL;
|
|
|
|
h->inTownGarrison = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void ChangeSpells::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CGHeroInstance *hero = gs->getHero(hid);
|
|
|
|
|
|
|
|
if(learn)
|
|
|
|
BOOST_FOREACH(ui32 sid, spells)
|
2011-01-22 05:43:20 +02:00
|
|
|
hero->spells.insert(sid);
|
2009-03-07 17:55:56 +02:00
|
|
|
else
|
|
|
|
BOOST_FOREACH(ui32 sid, spells)
|
2011-01-22 05:43:20 +02:00
|
|
|
hero->spells.erase(sid);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void SetMana::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CGHeroInstance *hero = gs->getHero(hid);
|
2009-07-16 01:46:00 +03:00
|
|
|
amax(val, 0); //not less than 0
|
2009-03-07 17:55:56 +02:00
|
|
|
hero->mana = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void SetMovePoints::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CGHeroInstance *hero = gs->getHero(hid);
|
|
|
|
hero->movement = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void FoWChange::applyGs( CGameState *gs )
|
|
|
|
{
|
2010-08-03 15:34:06 +03:00
|
|
|
TeamState * team = gs->getPlayerTeam(player);
|
|
|
|
BOOST_FOREACH(int3 t, tiles)
|
|
|
|
team->fogOfWarMap[t.x][t.y][t.z] = mode;
|
2010-06-06 09:05:39 +03:00
|
|
|
if (mode == 0) //do not hide too much
|
|
|
|
{
|
2011-01-20 19:25:15 +02:00
|
|
|
boost::unordered_set<int3, ShashInt3> tilesRevealed;
|
2010-06-06 09:05:39 +03:00
|
|
|
for (size_t i = 0; i < gs->map->objects.size(); i++)
|
|
|
|
{
|
2010-08-03 15:34:06 +03:00
|
|
|
if (gs->map->objects[i])
|
2010-06-06 09:05:39 +03:00
|
|
|
{
|
|
|
|
switch(gs->map->objects[i]->ID)
|
|
|
|
{
|
|
|
|
case 34://hero
|
|
|
|
case 53://mine
|
|
|
|
case 98://town
|
|
|
|
case 220:
|
2010-08-19 14:03:33 +03:00
|
|
|
if(vstd::contains(team->players, gs->map->objects[i]->tempOwner)) //check owned observators
|
2010-08-03 15:34:06 +03:00
|
|
|
gs->map->objects[i]->getSightTiles(tilesRevealed);
|
2010-06-06 09:05:39 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BOOST_FOREACH(int3 t, tilesRevealed) //probably not the most optimal solution ever
|
2010-08-03 15:34:06 +03:00
|
|
|
team->fogOfWarMap[t.x][t.y][t.z] = 1;
|
2010-06-06 09:05:39 +03:00
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
DLL_EXPORT void SetAvailableHeroes::applyGs( CGameState *gs )
|
|
|
|
{
|
2010-07-08 08:52:11 +03:00
|
|
|
PlayerState *p = gs->getPlayer(player);
|
|
|
|
p->availableHeroes.clear();
|
2009-03-07 17:55:56 +02:00
|
|
|
|
2010-07-08 08:52:11 +03:00
|
|
|
for (int i = 0; i < AVAILABLE_HEROES_PER_PLAYER; i++)
|
2009-03-07 17:55:56 +02:00
|
|
|
{
|
2010-12-26 16:34:11 +02:00
|
|
|
CGHeroInstance *h = (hid[i]>=0 ? (CGHeroInstance*)gs->hpool.heroesPool[hid[i]] : NULL);
|
2010-07-08 08:52:11 +03:00
|
|
|
if(h && army[i])
|
2010-11-27 03:46:19 +02:00
|
|
|
h->setToArmy(*army[i]);
|
2010-07-08 08:52:11 +03:00
|
|
|
p->availableHeroes.push_back(h);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void GiveBonus::applyGs( CGameState *gs )
|
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
CBonusSystemNode *cbsn = NULL;
|
2010-02-10 04:56:00 +02:00
|
|
|
switch(who)
|
|
|
|
{
|
|
|
|
case HERO:
|
2010-11-19 00:06:56 +02:00
|
|
|
cbsn = gs->getHero(id);
|
2010-02-10 04:56:00 +02:00
|
|
|
break;
|
|
|
|
case PLAYER:
|
2010-11-19 00:06:56 +02:00
|
|
|
cbsn = gs->getPlayer(id);
|
2010-02-10 04:56:00 +02:00
|
|
|
break;
|
2010-06-07 08:28:12 +03:00
|
|
|
case TOWN:
|
2010-11-19 00:06:56 +02:00
|
|
|
cbsn = gs->getTown(id);
|
|
|
|
break;
|
2010-02-10 04:56:00 +02:00
|
|
|
}
|
2009-04-21 01:57:07 +03:00
|
|
|
|
2010-11-19 00:06:56 +02:00
|
|
|
assert(cbsn);
|
|
|
|
|
|
|
|
Bonus *b = new Bonus(bonus);
|
|
|
|
cbsn->addNewBonus(b);
|
|
|
|
|
|
|
|
std::string &descr = b->description;
|
2009-04-21 01:57:07 +03:00
|
|
|
|
2009-07-09 22:15:22 +03:00
|
|
|
if(!bdescr.message.size()
|
2010-05-02 21:20:26 +03:00
|
|
|
&& bonus.source == Bonus::OBJECT
|
|
|
|
&& (bonus.type == Bonus::LUCK || bonus.type == Bonus::MORALE)
|
2010-02-10 04:56:00 +02:00
|
|
|
&& gs->map->objects[bonus.id]->ID == EVENTI_TYPE) //it's morale/luck bonus from an event without description
|
2009-04-21 01:57:07 +03:00
|
|
|
{
|
|
|
|
descr = VLC->generaltexth->arraytxt[bonus.val > 0 ? 110 : 109]; //+/-%d Temporary until next battle"
|
|
|
|
boost::replace_first(descr,"%d",boost::lexical_cast<std::string>(std::abs(bonus.val)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-09 22:15:22 +03:00
|
|
|
bdescr.toString(descr);
|
2009-04-21 01:57:07 +03:00
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void ChangeObjPos::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CGObjectInstance *obj = gs->map->objects[objid];
|
|
|
|
if(!obj)
|
|
|
|
{
|
|
|
|
tlog1 << "Wrong ChangeObjPos: object " << objid << " doesn't exist!\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gs->map->removeBlockVisTiles(obj);
|
|
|
|
obj->pos = nPos;
|
|
|
|
gs->map->addBlockVisTiles(obj);
|
|
|
|
}
|
|
|
|
|
2010-01-29 22:52:45 +02:00
|
|
|
DLL_EXPORT void PlayerEndsGame::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
PlayerState *p = gs->getPlayer(player);
|
|
|
|
p->status = victory ? 2 : 1;
|
|
|
|
}
|
|
|
|
|
2010-02-10 04:56:00 +02:00
|
|
|
DLL_EXPORT void RemoveBonus::applyGs( CGameState *gs )
|
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
BonusList &bonuses = (who == HERO ? gs->getHero(whoID)->bonuses : gs->getPlayer(whoID)->bonuses);
|
2010-02-10 04:56:00 +02:00
|
|
|
|
2010-11-19 00:06:56 +02:00
|
|
|
for(BonusList::iterator i = bonuses.begin(); i != bonuses.end(); i++)
|
2010-02-10 04:56:00 +02:00
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
if((*i)->source == source && (*i)->id == id)
|
2010-02-10 04:56:00 +02:00
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
bonus = **i; //backup bonus (to show to interfaces later)
|
2010-02-10 04:56:00 +02:00
|
|
|
bonuses.erase(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
DLL_EXPORT void RemoveObject::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CGObjectInstance *obj = gs->map->objects[id];
|
2010-02-11 17:51:26 +02:00
|
|
|
//unblock tiles
|
|
|
|
if(obj->defInfo)
|
|
|
|
{
|
|
|
|
gs->map->removeBlockVisTiles(obj);
|
|
|
|
}
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
if(obj->ID==HEROI_TYPE)
|
|
|
|
{
|
|
|
|
CGHeroInstance *h = static_cast<CGHeroInstance*>(obj);
|
2010-12-20 15:04:24 +02:00
|
|
|
std::vector<ConstTransitivePtr<CGHeroInstance> >::iterator nitr = std::find(gs->map->heroes.begin(), gs->map->heroes.end(),h);
|
2009-03-07 17:55:56 +02:00
|
|
|
gs->map->heroes.erase(nitr);
|
|
|
|
int player = h->tempOwner;
|
2009-03-09 12:37:49 +02:00
|
|
|
nitr = std::find(gs->getPlayer(player)->heroes.begin(), gs->getPlayer(player)->heroes.end(), h);
|
|
|
|
gs->getPlayer(player)->heroes.erase(nitr);
|
2010-01-29 22:52:45 +02:00
|
|
|
h->tempOwner = 255; //no one owns beaten hero
|
|
|
|
|
2010-07-20 21:34:32 +03:00
|
|
|
if(CGTownInstance *t = const_cast<CGTownInstance *>(h->visitedTown))
|
2009-03-07 17:55:56 +02:00
|
|
|
{
|
|
|
|
if(h->inTownGarrison)
|
2010-07-20 21:34:32 +03:00
|
|
|
t->garrisonHero = NULL;
|
2009-03-07 17:55:56 +02:00
|
|
|
else
|
2010-07-20 21:34:32 +03:00
|
|
|
t->visitingHero = NULL;
|
2009-03-07 17:55:56 +02:00
|
|
|
h->visitedTown = NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-08 08:52:11 +03:00
|
|
|
//return hero to the pool, so he may reappear in tavern
|
|
|
|
gs->hpool.heroesPool[h->subID] = h;
|
|
|
|
if(!vstd::contains(gs->hpool.pavailable, h->subID))
|
|
|
|
gs->hpool.pavailable[h->subID] = 0xff;
|
2011-01-18 20:56:14 +02:00
|
|
|
|
|
|
|
return;
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
2010-02-12 02:53:25 +02:00
|
|
|
else if (obj->ID==CREI_TYPE && gs->map->version > CMapHeader::RoE) //only fixed monsters can be a part of quest
|
2010-02-02 19:05:03 +02:00
|
|
|
{
|
|
|
|
CGCreature *cre = static_cast<CGCreature*>(obj);
|
2010-02-07 18:05:27 +02:00
|
|
|
gs->map->monsters[cre->identifier]->pos = int3 (-1,-1,-1); //use nonexistent monster for quest :>
|
2010-02-02 19:05:03 +02:00
|
|
|
}
|
2010-12-26 16:34:11 +02:00
|
|
|
gs->map->objects[id].dellNull();
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
2009-07-18 06:13:13 +03:00
|
|
|
static int getDir(int3 src, int3 dst)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
if(dst.x+1 == src.x && dst.y+1 == src.y) //tl
|
|
|
|
{
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
else if(dst.x == src.x && dst.y+1 == src.y) //t
|
|
|
|
{
|
|
|
|
ret = 2;
|
|
|
|
}
|
|
|
|
else if(dst.x-1 == src.x && dst.y+1 == src.y) //tr
|
|
|
|
{
|
|
|
|
ret = 3;
|
|
|
|
}
|
|
|
|
else if(dst.x-1 == src.x && dst.y == src.y) //r
|
|
|
|
{
|
|
|
|
ret = 4;
|
|
|
|
}
|
|
|
|
else if(dst.x-1 == src.x && dst.y-1 == src.y) //br
|
|
|
|
{
|
|
|
|
ret = 5;
|
|
|
|
}
|
|
|
|
else if(dst.x == src.x && dst.y-1 == src.y) //b
|
|
|
|
{
|
|
|
|
ret = 6;
|
|
|
|
}
|
|
|
|
else if(dst.x+1 == src.x && dst.y-1 == src.y) //bl
|
|
|
|
{
|
|
|
|
ret = 7;
|
|
|
|
}
|
|
|
|
else if(dst.x+1 == src.x && dst.y == src.y) //l
|
|
|
|
{
|
|
|
|
ret = 8;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
void TryMoveHero::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CGHeroInstance *h = gs->getHero(id);
|
|
|
|
h->movement = movePoints;
|
2009-07-19 04:00:19 +03:00
|
|
|
|
2010-05-06 15:13:31 +03:00
|
|
|
if((result == SUCCESS || result == BLOCKING_VISIT || result == EMBARK || result == DISEMBARK) && start != end) {
|
2009-07-19 06:10:24 +03:00
|
|
|
h->moveDir = getDir(start,end);
|
2010-05-06 15:13:31 +03:00
|
|
|
}
|
2009-07-19 06:10:24 +03:00
|
|
|
|
2009-07-19 04:00:19 +03:00
|
|
|
if(result == EMBARK) //hero enters boat at dest tile
|
|
|
|
{
|
|
|
|
const TerrainTile &tt = gs->map->getTile(CGHeroInstance::convertPosition(end, false));
|
|
|
|
assert(tt.visitableObjects.size() == 1 && tt.visitableObjects.front()->ID == 8); //the only vis obj at dest is Boat
|
|
|
|
CGBoat *boat = static_cast<CGBoat*>(tt.visitableObjects.front());
|
|
|
|
|
|
|
|
gs->map->removeBlockVisTiles(boat); //hero blockvis mask will be used, we don't need to duplicate it with boat
|
|
|
|
h->boat = boat;
|
|
|
|
boat->hero = h;
|
|
|
|
}
|
2009-07-19 06:10:24 +03:00
|
|
|
else if(result == DISEMBARK) //hero leaves boat to dest tile
|
|
|
|
{
|
2010-07-20 21:34:32 +03:00
|
|
|
CGBoat *b = const_cast<CGBoat *>(h->boat);
|
|
|
|
b->direction = h->moveDir;
|
|
|
|
b->pos = start;
|
|
|
|
b->hero = NULL;
|
|
|
|
gs->map->addBlockVisTiles(b);
|
2009-07-19 06:10:24 +03:00
|
|
|
h->boat = NULL;
|
|
|
|
}
|
2009-07-19 04:00:19 +03:00
|
|
|
|
2009-07-19 06:10:24 +03:00
|
|
|
if(start!=end && (result == SUCCESS || result == TELEPORTATION || result == EMBARK || result == DISEMBARK))
|
2009-03-07 17:55:56 +02:00
|
|
|
{
|
|
|
|
gs->map->removeBlockVisTiles(h);
|
|
|
|
h->pos = end;
|
2010-07-20 21:34:32 +03:00
|
|
|
if(CGBoat *b = const_cast<CGBoat *>(h->boat))
|
|
|
|
b->pos = end;
|
2009-03-07 17:55:56 +02:00
|
|
|
gs->map->addBlockVisTiles(h);
|
|
|
|
}
|
2009-07-18 06:13:13 +03:00
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
BOOST_FOREACH(int3 t, fowRevealed)
|
2010-08-03 15:34:06 +03:00
|
|
|
gs->getPlayerTeam(h->getOwner())->fogOfWarMap[t.x][t.y][t.z] = 1;
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
2010-12-06 01:10:02 +02:00
|
|
|
// DLL_EXPORT void SetGarrisons::applyGs( CGameState *gs )
|
|
|
|
// {
|
|
|
|
// for(std::map<ui32,CCreatureSet>::iterator i = garrs.begin(); i!=garrs.end(); i++)
|
|
|
|
// {
|
|
|
|
// CArmedInstance *ai = static_cast<CArmedInstance*>(gs->map->objects[i->first]);
|
|
|
|
// ai->setToArmy(i->second);
|
|
|
|
// if(ai->ID==TOWNI_TYPE && (static_cast<CGTownInstance*>(ai))->garrisonHero) //if there is a hero in garrison then we must update also his army
|
|
|
|
// const_cast<CGHeroInstance*>((static_cast<CGTownInstance*>(ai))->garrisonHero)->setToArmy(i->second);
|
|
|
|
// else if(ai->ID==HEROI_TYPE)
|
|
|
|
// {
|
|
|
|
// CGHeroInstance *h = static_cast<CGHeroInstance*>(ai);
|
|
|
|
// CGTownInstance *t = const_cast<CGTownInstance *>(h->visitedTown);
|
|
|
|
// if(t && h->inTownGarrison)
|
|
|
|
// t->setToArmy(i->second);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2009-03-07 17:55:56 +02:00
|
|
|
|
|
|
|
DLL_EXPORT void NewStructures::applyGs( CGameState *gs )
|
|
|
|
{
|
2009-08-23 18:02:21 +03:00
|
|
|
CGTownInstance *t = gs->getTown(tid);
|
2009-03-07 17:55:56 +02:00
|
|
|
BOOST_FOREACH(si32 id,bid)
|
2009-08-23 18:02:21 +03:00
|
|
|
{
|
2009-03-07 17:55:56 +02:00
|
|
|
t->builtBuildings.insert(id);
|
2009-08-23 18:02:21 +03:00
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
t->builded = builded;
|
|
|
|
}
|
2009-09-22 17:27:46 +03:00
|
|
|
DLL_EXPORT void RazeStructures::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CGTownInstance *t = gs->getTown(tid);
|
|
|
|
BOOST_FOREACH(si32 id,bid)
|
|
|
|
{
|
|
|
|
t->builtBuildings.erase(id);
|
|
|
|
}
|
2009-09-24 20:54:02 +03:00
|
|
|
t->destroyed = destroyed; //yeaha
|
2009-09-22 17:27:46 +03:00
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
DLL_EXPORT void SetAvailableCreatures::applyGs( CGameState *gs )
|
|
|
|
{
|
2010-12-19 00:11:28 +02:00
|
|
|
CGDwelling *dw = dynamic_cast<CGDwelling*>(gs->map->objects[tid].get());
|
2009-07-26 13:43:22 +03:00
|
|
|
assert(dw);
|
|
|
|
dw->creatures = creatures;
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void SetHeroesInTown::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CGTownInstance *t = gs->getTown(tid);
|
|
|
|
|
|
|
|
CGHeroInstance *v = gs->getHero(visiting),
|
|
|
|
*g = gs->getHero(garrison);
|
|
|
|
|
|
|
|
t->visitingHero = v;
|
|
|
|
t->garrisonHero = g;
|
|
|
|
if(v)
|
|
|
|
{
|
|
|
|
v->visitedTown = t;
|
|
|
|
v->inTownGarrison = false;
|
|
|
|
gs->map->addBlockVisTiles(v);
|
|
|
|
}
|
|
|
|
if(g)
|
|
|
|
{
|
|
|
|
g->visitedTown = t;
|
|
|
|
g->inTownGarrison = true;
|
|
|
|
gs->map->removeBlockVisTiles(g);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-18 20:56:14 +02:00
|
|
|
// DLL_EXPORT void SetHeroArtifacts::applyGs( CGameState *gs )
|
|
|
|
// {
|
|
|
|
// CGHeroInstance *h = gs->getHero(hid);
|
|
|
|
// for(std::map<ui16, const CArtifact*>::const_iterator i = h->artifWorn.begin(); i != h->artifWorn.end(); i++)
|
|
|
|
// if(!vstd::contains(artifWorn,i->first) || artifWorn[i->first] != i->second)
|
|
|
|
// unequiped.push_back(i->second);
|
|
|
|
//
|
|
|
|
// for(std::map<ui16, const CArtifact*>::iterator i = artifWorn.begin(); i != artifWorn.end(); i++)
|
|
|
|
// if(!vstd::contains(h->artifWorn,i->first) || h->artifWorn[i->first] != i->second)
|
|
|
|
// {
|
|
|
|
// equiped.push_back(i->second);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// //update hero data
|
|
|
|
// h->artifacts = artifacts;
|
|
|
|
// h->artifWorn = artifWorn;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// DLL_EXPORT void SetHeroArtifacts::setArtAtPos(ui16 pos, const CArtifact* art)
|
|
|
|
// {
|
|
|
|
// if(!art)
|
|
|
|
// {
|
|
|
|
// if(pos<19)
|
|
|
|
// VLC->arth->unequipArtifact(artifWorn, pos);
|
|
|
|
// else if (pos - 19 < artifacts.size())
|
|
|
|
// artifacts.erase(artifacts.begin() + (pos - 19));
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// if (pos < 19)
|
|
|
|
// {
|
|
|
|
// VLC->arth->equipArtifact(artifWorn, pos, art);
|
|
|
|
// }
|
|
|
|
// else // Goes into the backpack.
|
|
|
|
// {
|
|
|
|
// if(pos - 19 < artifacts.size())
|
|
|
|
// artifacts.insert(artifacts.begin() + (pos - 19), art);
|
|
|
|
// else
|
|
|
|
// artifacts.push_back(art);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2009-03-07 17:55:56 +02:00
|
|
|
|
2009-04-04 01:34:31 +03:00
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
DLL_EXPORT void HeroRecruited::applyGs( CGameState *gs )
|
|
|
|
{
|
2009-08-05 03:05:37 +03:00
|
|
|
assert(vstd::contains(gs->hpool.heroesPool, hid));
|
2009-03-07 17:55:56 +02:00
|
|
|
CGHeroInstance *h = gs->hpool.heroesPool[hid];
|
|
|
|
CGTownInstance *t = gs->getTown(tid);
|
|
|
|
h->setOwner(player);
|
|
|
|
h->pos = tile;
|
|
|
|
h->movement = h->maxMovePoints(true);
|
|
|
|
|
|
|
|
gs->hpool.heroesPool.erase(hid);
|
|
|
|
if(h->id < 0)
|
|
|
|
{
|
|
|
|
h->id = gs->map->objects.size();
|
|
|
|
gs->map->objects.push_back(h);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gs->map->objects[h->id] = h;
|
|
|
|
|
|
|
|
h->initHeroDefInfo();
|
|
|
|
gs->map->heroes.push_back(h);
|
2009-03-09 12:37:49 +02:00
|
|
|
gs->getPlayer(h->getOwner())->heroes.push_back(h);
|
2009-08-01 13:08:16 +03:00
|
|
|
h->initObj();
|
2009-03-07 17:55:56 +02:00
|
|
|
gs->map->addBlockVisTiles(h);
|
2010-07-09 02:03:27 +03:00
|
|
|
|
|
|
|
if(t)
|
|
|
|
{
|
|
|
|
t->visitingHero = h;
|
|
|
|
h->visitedTown = t;
|
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
h->inTownGarrison = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void GiveHero::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CGHeroInstance *h = gs->getHero(id);
|
|
|
|
gs->map->removeBlockVisTiles(h,true);
|
|
|
|
h->setOwner(player);
|
|
|
|
h->movement = h->maxMovePoints(true);
|
|
|
|
h->initHeroDefInfo();
|
|
|
|
gs->map->heroes.push_back(h);
|
2009-03-09 12:37:49 +02:00
|
|
|
gs->getPlayer(h->getOwner())->heroes.push_back(h);
|
2009-03-07 17:55:56 +02:00
|
|
|
gs->map->addBlockVisTiles(h);
|
|
|
|
h->inTownGarrison = false;
|
|
|
|
}
|
|
|
|
|
2009-07-26 06:33:13 +03:00
|
|
|
DLL_EXPORT void NewObject::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
|
|
|
|
CGObjectInstance *o = NULL;
|
|
|
|
switch(ID)
|
|
|
|
{
|
|
|
|
case 8:
|
|
|
|
o = new CGBoat();
|
|
|
|
break;
|
2010-08-22 10:11:46 +03:00
|
|
|
case 54: //probably more options will be needed
|
|
|
|
o = new CGCreature();
|
|
|
|
{
|
2010-11-22 02:34:46 +02:00
|
|
|
//CStackInstance hlp;
|
2010-08-22 10:11:46 +03:00
|
|
|
CGCreature *cre = static_cast<CGCreature*>(o);
|
2010-11-22 02:34:46 +02:00
|
|
|
//cre->slots[0] = hlp;
|
2010-08-22 10:11:46 +03:00
|
|
|
cre->notGrowingTeam = cre->neverFlees = 0;
|
|
|
|
cre->character = 2;
|
|
|
|
cre->gainedArtifact = -1;
|
|
|
|
}
|
|
|
|
break;
|
2009-07-26 06:33:13 +03:00
|
|
|
default:
|
|
|
|
o = new CGObjectInstance();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
o->ID = ID;
|
|
|
|
o->subID = subID;
|
|
|
|
o->pos = pos;
|
|
|
|
o->defInfo = VLC->dobjinfo->gobjs[ID][subID];
|
|
|
|
id = o->id = gs->map->objects.size();
|
|
|
|
o->hoverName = VLC->generaltexth->names[ID];
|
|
|
|
|
2010-08-22 10:11:46 +03:00
|
|
|
switch(ID)
|
2010-02-21 17:03:30 +02:00
|
|
|
{
|
2010-08-22 10:11:46 +03:00
|
|
|
case 54: //cfreature
|
|
|
|
o->defInfo = VLC->dobjinfo->gobjs[ID][subID];
|
|
|
|
assert(o->defInfo);
|
|
|
|
break;
|
|
|
|
case 124://hole
|
|
|
|
const TerrainTile &t = gs->map->getTile(pos);
|
|
|
|
o->defInfo = VLC->dobjinfo->gobjs[ID][t.tertype];
|
|
|
|
assert(o->defInfo);
|
|
|
|
break;
|
2010-02-21 17:03:30 +02:00
|
|
|
}
|
|
|
|
|
2009-07-26 06:33:13 +03:00
|
|
|
gs->map->objects.push_back(o);
|
|
|
|
gs->map->addBlockVisTiles(o);
|
|
|
|
o->initObj();
|
|
|
|
assert(o->defInfo);
|
|
|
|
}
|
2010-11-10 02:06:25 +02:00
|
|
|
DLL_EXPORT void NewArtifact::applyGs( CGameState *gs )
|
|
|
|
{
|
2010-12-26 16:34:11 +02:00
|
|
|
assert(!vstd::contains(gs->map->artInstances, art));
|
2011-01-22 05:43:20 +02:00
|
|
|
gs->map->addNewArtifactInstance(art);
|
2010-12-26 16:34:11 +02:00
|
|
|
|
|
|
|
assert(!art->parents.size());
|
2011-01-18 20:56:14 +02:00
|
|
|
art->setType(art->artType);
|
2010-11-10 02:06:25 +02:00
|
|
|
}
|
2009-07-26 06:33:13 +03:00
|
|
|
|
2010-12-14 23:55:23 +02:00
|
|
|
DLL_EXPORT const CStackInstance * StackLocation::getStack()
|
|
|
|
{
|
|
|
|
if(!army->hasStackAtSlot(slot))
|
|
|
|
{
|
|
|
|
tlog2 << "Warning: " << army->nodeName() << " dont have a stack at slot " << slot << std::endl;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return &army->getStack(slot);
|
|
|
|
}
|
|
|
|
|
2010-12-26 16:34:11 +02:00
|
|
|
DLL_EXPORT const CArtifactInstance *ArtifactLocation::getArt() const
|
|
|
|
{
|
|
|
|
const ArtSlotInfo *s = getSlot();
|
2010-12-29 23:04:22 +02:00
|
|
|
if(s && s->artifact)
|
|
|
|
{
|
|
|
|
if(!s->locked)
|
|
|
|
return s->artifact;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tlog3 << "ArtifactLocation::getArt: That location is locked!\n";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2011-01-07 12:48:31 +02:00
|
|
|
return NULL;
|
2010-12-26 16:34:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT CArtifactInstance *ArtifactLocation::getArt()
|
|
|
|
{
|
|
|
|
const ArtifactLocation *t = this;
|
|
|
|
return const_cast<CArtifactInstance*>(t->getArt());
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT const ArtSlotInfo *ArtifactLocation::getSlot() const
|
|
|
|
{
|
|
|
|
return hero->getSlot(slot);
|
|
|
|
}
|
|
|
|
|
2010-11-27 03:46:19 +02:00
|
|
|
DLL_EXPORT void ChangeStackCount::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
if(absoluteValue)
|
|
|
|
sl.army->setStackCount(sl.slot, count);
|
|
|
|
else
|
|
|
|
sl.army->changeStackCount(sl.slot, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void SetStackType::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
sl.army->setStackType(sl.slot, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void EraseStack::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
sl.army->eraseStack(sl.slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void SwapStacks::applyGs( CGameState *gs )
|
|
|
|
{
|
2010-11-27 22:17:28 +02:00
|
|
|
CStackInstance *s1 = sl1.army->detachStack(sl1.slot),
|
|
|
|
*s2 = sl2.army->detachStack(sl2.slot);
|
2010-11-27 03:46:19 +02:00
|
|
|
|
2010-11-27 22:17:28 +02:00
|
|
|
sl2.army->putStack(sl2.slot, s1);
|
|
|
|
sl1.army->putStack(sl1.slot, s2);
|
2010-11-27 03:46:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void InsertNewStack::applyGs( CGameState *gs )
|
|
|
|
{
|
2010-12-06 01:10:02 +02:00
|
|
|
CStackInstance *s = new CStackInstance(stack.type, stack.count);
|
|
|
|
sl.army->putStack(sl.slot, s);
|
2010-11-27 03:46:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void RebalanceStacks::applyGs( CGameState *gs )
|
|
|
|
{
|
2010-12-06 01:10:02 +02:00
|
|
|
const CCreature *srcType = src.army->getCreature(src.slot);
|
|
|
|
TQuantity srcCount = src.army->getStackCount(src.slot);
|
|
|
|
|
|
|
|
if(srcCount == count) //moving whole stack
|
|
|
|
{
|
|
|
|
if(const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> merge
|
|
|
|
{
|
|
|
|
assert(c == srcType);
|
|
|
|
src.army->eraseStack(src.slot);
|
|
|
|
dst.army->changeStackCount(dst.slot, count);
|
|
|
|
}
|
|
|
|
else //move stack to an empty slot
|
|
|
|
{
|
|
|
|
CStackInstance *stackDetached = src.army->detachStack(src.slot);
|
|
|
|
dst.army->putStack(dst.slot, stackDetached);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> rebalance
|
|
|
|
{
|
|
|
|
assert(c == srcType);
|
|
|
|
src.army->changeStackCount(src.slot, -count);
|
|
|
|
dst.army->changeStackCount(dst.slot, count);
|
|
|
|
}
|
|
|
|
else //split stack to an empty slot
|
|
|
|
{
|
|
|
|
src.army->changeStackCount(src.slot, -count);
|
|
|
|
dst.army->addToSlot(dst.slot, srcType->idNumber, count, false);
|
|
|
|
}
|
|
|
|
}
|
2010-11-27 03:46:19 +02:00
|
|
|
}
|
|
|
|
|
2010-12-26 16:34:11 +02:00
|
|
|
DLL_EXPORT void PutArtifact::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
assert(art->canBePutAt(al));
|
2010-12-30 16:41:46 +02:00
|
|
|
al.hero->putArtifact(al.slot, art);
|
|
|
|
//art->putAt(al.hero, al.slot);
|
2010-12-26 16:34:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void EraseArtifact::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CArtifactInstance *a = al.getArt();
|
|
|
|
assert(a);
|
|
|
|
a->removeFrom(al.hero, al.slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void MoveArtifact::applyGs( CGameState *gs )
|
|
|
|
{
|
2011-01-06 22:00:19 +02:00
|
|
|
CArtifactInstance *a = src.getArt();
|
2011-01-15 04:17:56 +02:00
|
|
|
if(dst.slot < Arts::BACKPACK_START)
|
|
|
|
assert(!dst.getArt());
|
2011-01-22 05:43:20 +02:00
|
|
|
|
2011-01-15 19:58:08 +02:00
|
|
|
a->move(src, dst);
|
2010-12-26 16:34:11 +02:00
|
|
|
}
|
|
|
|
|
2011-01-22 05:43:20 +02:00
|
|
|
DLL_EXPORT void AssembledArtifact::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CGHeroInstance *h = al.hero;
|
|
|
|
const CArtifactInstance *transformedArt = al.getArt();
|
|
|
|
assert(transformedArt);
|
|
|
|
assert(vstd::contains(transformedArt->assemblyPossibilities(al.hero), builtArt));
|
|
|
|
|
|
|
|
CCombinedArtifactInstance *combinedArt = new CCombinedArtifactInstance(builtArt);
|
|
|
|
//retreive all constituents
|
|
|
|
BOOST_FOREACH(si32 constituentID, *builtArt->constituents)
|
|
|
|
{
|
|
|
|
int pos = h->getArtPos(constituentID);
|
|
|
|
assert(pos >= 0);
|
|
|
|
CArtifactInstance *constituentInstance = h->getArt(pos);
|
|
|
|
|
|
|
|
//move constituent from hero to be part of new, combined artifact
|
|
|
|
constituentInstance->removeFrom(h, pos);
|
|
|
|
combinedArt->addAsConstituent(constituentInstance, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
//put new combined artifacts
|
|
|
|
combinedArt->putAt(h, al.slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void DisassembledArtifact::applyGs( CGameState *gs )
|
|
|
|
{
|
2011-01-24 01:49:17 +02:00
|
|
|
CGHeroInstance *h = al.hero;
|
|
|
|
CCombinedArtifactInstance *disassembled = dynamic_cast<CCombinedArtifactInstance*>(al.getArt());
|
|
|
|
assert(disassembled);
|
|
|
|
|
|
|
|
std::vector<CCombinedArtifactInstance::ConstituentInfo> constituents = disassembled->constituentsInfo;
|
|
|
|
disassembled->removeFrom(h, al.slot);
|
|
|
|
BOOST_FOREACH(CCombinedArtifactInstance::ConstituentInfo &ci, constituents)
|
|
|
|
{
|
|
|
|
ci.art->detachFrom(disassembled);
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
delNull(disassembled);
|
2011-01-22 05:43:20 +02:00
|
|
|
}
|
|
|
|
|
2010-06-26 19:02:10 +03:00
|
|
|
DLL_EXPORT void SetAvailableArtifacts::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
if(id >= 0)
|
|
|
|
{
|
2010-12-19 00:11:28 +02:00
|
|
|
if(CGBlackMarket *bm = dynamic_cast<CGBlackMarket*>(gs->map->objects[id].get()))
|
2010-06-26 19:02:10 +03:00
|
|
|
{
|
|
|
|
bm->artifacts = arts;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tlog1 << "Wrong black market id!" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CGTownInstance::merchantArtifacts = arts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
DLL_EXPORT void NewTurn::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
gs->day = day;
|
|
|
|
BOOST_FOREACH(NewTurn::Hero h, heroes) //give mana/movement point
|
|
|
|
{
|
2009-04-04 01:34:31 +03:00
|
|
|
CGHeroInstance *hero = gs->getHero(h.id);
|
|
|
|
hero->movement = h.move;
|
|
|
|
hero->mana = h.mana;
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
2009-11-28 03:42:08 +02:00
|
|
|
for(std::map<ui8, std::vector<si32> >::iterator i = res.begin(); i != res.end(); i++)
|
|
|
|
{
|
|
|
|
assert(i->first < PLAYER_LIMIT);
|
|
|
|
std::vector<si32> &playerRes = gs->getPlayer(i->first)->resources;
|
|
|
|
for(int j = 0; j < i->second.size(); j++)
|
|
|
|
playerRes[j] = i->second[j];
|
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
|
|
|
|
BOOST_FOREACH(SetAvailableCreatures h, cres) //set available creatures in towns
|
|
|
|
h.applyGs(gs);
|
|
|
|
|
2010-08-26 10:23:08 +03:00
|
|
|
if (specialWeek != NO_ACTION) //first pack applied, reset all effects and aplly new
|
2010-08-22 21:21:45 +03:00
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
//TODO? won't work for battles lasting several turns (not an issue now but...)
|
|
|
|
gs->globalEffects.popBonuses(Bonus::OneDay); //works for children -> all game objs
|
2010-08-24 17:26:57 +03:00
|
|
|
|
2010-08-26 10:23:08 +03:00
|
|
|
if(gs->getDate(1)) //new week, Monday that is
|
2010-08-24 17:26:57 +03:00
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
gs->globalEffects.popBonuses(Bonus::OneWeek); //works for children -> all game objs
|
|
|
|
|
|
|
|
Bonus *b = new Bonus();
|
|
|
|
b->duration = Bonus::ONE_WEEK;
|
|
|
|
b->source = Bonus::SPECIAL_WEEK;
|
|
|
|
b->effectRange = Bonus::NO_LIMIT;
|
|
|
|
b->valType = Bonus::BASE_NUMBER; //certainly not intuitive
|
2010-08-26 10:23:08 +03:00
|
|
|
switch (specialWeek)
|
|
|
|
{
|
|
|
|
case DOUBLE_GROWTH:
|
2010-11-19 00:06:56 +02:00
|
|
|
b->val = 100;
|
|
|
|
b->type = Bonus::CREATURE_GROWTH_PERCENT;
|
2010-11-20 02:03:31 +02:00
|
|
|
b->limiter.reset(new CCreatureTypeLimiter(*VLC->creh->creatures[creatureid], false));
|
2010-08-26 10:23:08 +03:00
|
|
|
break;
|
|
|
|
case BONUS_GROWTH:
|
2010-11-19 00:06:56 +02:00
|
|
|
b->val = 5;
|
|
|
|
b->type = Bonus::CREATURE_GROWTH;
|
2010-11-20 02:03:31 +02:00
|
|
|
b->limiter.reset(new CCreatureTypeLimiter(*VLC->creh->creatures[creatureid], false));
|
2010-08-26 10:23:08 +03:00
|
|
|
break;
|
|
|
|
case DEITYOFFIRE:
|
2010-11-19 00:06:56 +02:00
|
|
|
b->val = 15;
|
|
|
|
b->type = Bonus::CREATURE_GROWTH;
|
2010-11-20 02:03:31 +02:00
|
|
|
b->limiter.reset(new CCreatureTypeLimiter(*VLC->creh->creatures[42], true));
|
2010-08-26 10:23:08 +03:00
|
|
|
break;
|
|
|
|
case PLAGUE:
|
2010-11-19 00:06:56 +02:00
|
|
|
b->val = -100; //no basic creatures
|
|
|
|
b->type = Bonus::CREATURE_GROWTH_PERCENT;
|
2010-08-26 10:23:08 +03:00
|
|
|
break;
|
|
|
|
default:
|
2010-11-19 00:06:56 +02:00
|
|
|
b->val = 0;
|
2010-08-24 17:26:57 +03:00
|
|
|
|
2010-08-26 10:23:08 +03:00
|
|
|
}
|
2010-11-19 00:06:56 +02:00
|
|
|
if (b->val)
|
|
|
|
gs->globalEffects.addNewBonus(b);
|
2010-08-24 17:26:57 +03:00
|
|
|
}
|
2010-08-22 21:21:45 +03:00
|
|
|
}
|
2010-08-26 10:23:08 +03:00
|
|
|
else //second pack is applied
|
2010-02-02 01:30:03 +02:00
|
|
|
{
|
2010-08-26 10:23:08 +03:00
|
|
|
//count days without town
|
|
|
|
for( std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
|
|
|
|
{
|
|
|
|
if(i->second.towns.size() || gs->day == 1)
|
|
|
|
i->second.daysWithoutCastle = 0;
|
|
|
|
else
|
|
|
|
i->second.daysWithoutCastle++;
|
|
|
|
}
|
2010-10-31 09:11:28 +02:00
|
|
|
if(resetBuilded) //reset amount of structures set in this turn in towns
|
|
|
|
{
|
|
|
|
BOOST_FOREACH(CGTownInstance* t, gs->map->towns)
|
|
|
|
t->builded = 0;
|
|
|
|
}
|
2010-02-02 01:30:03 +02:00
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void SetObjectProperty::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CGObjectInstance *obj = gs->map->objects[id];
|
|
|
|
if(!obj)
|
2009-08-22 16:59:15 +03:00
|
|
|
{
|
2009-03-07 17:55:56 +02:00
|
|
|
tlog1 << "Wrong object ID - property cannot be set!\n";
|
2009-08-22 16:59:15 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-02 21:20:26 +03:00
|
|
|
if(what == ObjProperty::OWNER)
|
2009-08-22 16:59:15 +03:00
|
|
|
{
|
|
|
|
if(obj->ID == TOWNI_TYPE)
|
|
|
|
{
|
|
|
|
CGTownInstance *t = static_cast<CGTownInstance*>(obj);
|
|
|
|
if(t->tempOwner < PLAYER_LIMIT)
|
|
|
|
gs->getPlayer(t->tempOwner)->towns -= t;
|
|
|
|
|
|
|
|
if(val < PLAYER_LIMIT)
|
|
|
|
gs->getPlayer(val)->towns.push_back(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
obj->setProperty(what,val);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void SetHoverName::applyGs( CGameState *gs )
|
|
|
|
{
|
2009-07-09 22:15:22 +03:00
|
|
|
name.toString(gs->map->objects[id]->hoverName);
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void HeroLevelUp::applyGs( CGameState *gs )
|
|
|
|
{
|
2010-07-08 22:10:26 +03:00
|
|
|
CGHeroInstance* h = gs->getHero(heroid);
|
|
|
|
h->level = level;
|
|
|
|
//speciality
|
2010-07-13 22:55:13 +03:00
|
|
|
h->UpdateSpeciality();
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void BattleStart::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
gs->curB = info;
|
2010-12-23 02:33:48 +02:00
|
|
|
gs->curB->localInit();
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void BattleNextRound::applyGs( CGameState *gs )
|
|
|
|
{
|
2009-05-12 06:35:51 +03:00
|
|
|
gs->curB->castSpells[0] = gs->curB->castSpells[1] = 0;
|
2009-03-07 17:55:56 +02:00
|
|
|
gs->curB->round = round;
|
|
|
|
|
|
|
|
BOOST_FOREACH(CStack *s, gs->curB->stacks)
|
|
|
|
{
|
|
|
|
s->state -= DEFENDING;
|
|
|
|
s->state -= WAITING;
|
|
|
|
s->state -= MOVED;
|
|
|
|
s->state -= HAD_MORALE;
|
2010-05-02 21:20:26 +03:00
|
|
|
s->counterAttacks = 1 + s->valOfBonuses(Bonus::ADDITIONAL_RETALIATION);
|
2009-04-16 03:28:54 +03:00
|
|
|
|
2009-08-22 17:39:44 +03:00
|
|
|
//regeneration
|
2010-05-02 21:20:26 +03:00
|
|
|
if( s->hasBonusOfType(Bonus::HP_REGENERATION) && s->alive() )
|
|
|
|
s->firstHPleft = std::min<ui32>( s->MaxHealth(), s->valOfBonuses(Bonus::HP_REGENERATION) );
|
|
|
|
if( s->hasBonusOfType(Bonus::FULL_HP_REGENERATION) && s->alive() )
|
2009-08-22 17:39:44 +03:00
|
|
|
s->firstHPleft = s->MaxHealth();
|
|
|
|
|
2009-04-16 03:28:54 +03:00
|
|
|
//remove effects and restore only those with remaining turns in duration
|
2010-08-30 21:06:17 +03:00
|
|
|
BonusList tmpEffects = s->bonuses;
|
2011-01-20 21:57:12 +02:00
|
|
|
s->bonuses.removeSpells(Bonus::SPELL_EFFECT);
|
2010-11-19 00:06:56 +02:00
|
|
|
|
|
|
|
BOOST_FOREACH(Bonus *it, tmpEffects)
|
2009-04-16 03:28:54 +03:00
|
|
|
{
|
2010-08-30 21:06:17 +03:00
|
|
|
it->turnsRemain--;
|
|
|
|
if(it->turnsRemain > 0)
|
2010-11-19 00:06:56 +02:00
|
|
|
s->addNewBonus(it);
|
2009-04-16 03:28:54 +03:00
|
|
|
}
|
2009-05-16 17:49:06 +03:00
|
|
|
|
|
|
|
//the same as above for features
|
2010-05-02 21:20:26 +03:00
|
|
|
BonusList tmpFeatures = s->bonuses;
|
|
|
|
s->bonuses.clear();
|
|
|
|
|
2010-11-19 00:06:56 +02:00
|
|
|
BOOST_FOREACH(Bonus *b, tmpFeatures)
|
2009-05-16 17:49:06 +03:00
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
if((b->duration & Bonus::N_TURNS) != 0)
|
2009-05-16 17:49:06 +03:00
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
b->turnsRemain--;
|
|
|
|
if(b->turnsRemain > 0)
|
|
|
|
s->addNewBonus(b);
|
2009-05-16 17:49:06 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
s->addNewBonus(b);
|
2009-05-16 17:49:06 +03:00
|
|
|
}
|
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void BattleSetActiveStack::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
gs->curB->activeStack = stack;
|
|
|
|
CStack *st = gs->curB->getStack(stack);
|
2011-01-18 19:23:31 +02:00
|
|
|
|
|
|
|
//remove bonuses that last until when stack gets new turn
|
|
|
|
st->bonuses.remove_if(Bonus::UntilGetsTurn);
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
if(vstd::contains(st->state,MOVED)) //if stack is moving second time this turn it must had a high morale bonus
|
|
|
|
st->state.insert(HAD_MORALE);
|
|
|
|
}
|
|
|
|
|
2009-03-07 19:08:40 +02:00
|
|
|
void BattleResult::applyGs( CGameState *gs )
|
2009-03-07 17:55:56 +02:00
|
|
|
{
|
|
|
|
for(unsigned i=0;i<gs->curB->stacks.size();i++)
|
|
|
|
delete gs->curB->stacks[i];
|
|
|
|
|
|
|
|
//remove any "until next battle" bonuses
|
|
|
|
CGHeroInstance *h;
|
2009-10-06 03:32:33 +03:00
|
|
|
h = gs->curB->heroes[0];
|
2009-03-07 17:55:56 +02:00
|
|
|
if(h)
|
2010-05-02 21:20:26 +03:00
|
|
|
h->bonuses.remove_if(Bonus::OneBattle);
|
2009-10-06 03:32:33 +03:00
|
|
|
|
|
|
|
h = gs->curB->heroes[1];
|
2009-03-07 17:55:56 +02:00
|
|
|
if(h)
|
2010-05-02 21:20:26 +03:00
|
|
|
h->bonuses.remove_if(Bonus::OneBattle);
|
2009-03-07 17:55:56 +02:00
|
|
|
|
2010-05-02 21:20:26 +03:00
|
|
|
gs->curB->belligerents[0]->battle = gs->curB->belligerents[1]->battle = NULL;
|
2010-12-26 16:34:11 +02:00
|
|
|
gs->curB.dellNull();
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
2009-03-07 19:08:40 +02:00
|
|
|
void BattleStackMoved::applyGs( CGameState *gs )
|
2009-03-07 17:55:56 +02:00
|
|
|
{
|
|
|
|
gs->curB->getStack(stack)->position = tile;
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void BattleStackAttacked::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CStack * at = gs->curB->getStack(stackAttacked);
|
2010-05-02 21:20:26 +03:00
|
|
|
at->count = newAmount;
|
2009-03-07 17:55:56 +02:00
|
|
|
at->firstHPleft = newHP;
|
|
|
|
if(killed())
|
|
|
|
at->state -= ALIVE;
|
2010-05-07 15:29:41 +03:00
|
|
|
|
|
|
|
//life drain handling
|
|
|
|
for (int g=0; g<healedStacks.size(); ++g)
|
|
|
|
{
|
|
|
|
healedStacks[g].applyGs(gs);
|
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void BattleAttack::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CStack *attacker = gs->curB->getStack(stackAttacking);
|
|
|
|
if(counter())
|
|
|
|
attacker->counterAttacks--;
|
2010-05-20 13:54:24 +03:00
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
if(shot())
|
2010-05-20 13:54:24 +03:00
|
|
|
{
|
|
|
|
//don't remove ammo if we have a working ammo cart
|
|
|
|
bool hasAmmoCart = false;
|
|
|
|
BOOST_FOREACH(const CStack * st, gs->curB->stacks)
|
|
|
|
{
|
2010-11-20 19:36:02 +02:00
|
|
|
if(st->owner == attacker->owner && st->getCreature()->idNumber == 148 && st->alive())
|
2010-05-20 13:54:24 +03:00
|
|
|
{
|
|
|
|
hasAmmoCart = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasAmmoCart)
|
|
|
|
{
|
|
|
|
attacker->shots--;
|
|
|
|
}
|
|
|
|
}
|
2009-03-24 23:28:17 +02:00
|
|
|
BOOST_FOREACH(BattleStackAttacked stackAttacked, bsa)
|
2009-03-21 14:49:58 +02:00
|
|
|
stackAttacked.applyGs(gs);
|
2009-08-07 14:22:17 +03:00
|
|
|
|
2010-05-02 21:20:26 +03:00
|
|
|
attacker->bonuses.remove_if(Bonus::UntilAttack);
|
2009-08-07 14:22:17 +03:00
|
|
|
|
2010-02-20 15:24:38 +02:00
|
|
|
for(std::vector<BattleStackAttacked>::const_iterator it = bsa.begin(); it != bsa.end(); ++it)
|
2009-08-07 14:22:17 +03:00
|
|
|
{
|
|
|
|
CStack * stack = gs->curB->getStack(it->stackAttacked, false);
|
2010-05-02 21:20:26 +03:00
|
|
|
stack->bonuses.remove_if(Bonus::UntilBeingAttacked);
|
2009-08-07 14:22:17 +03:00
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void StartAction::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
CStack *st = gs->curB->getStack(ba.stackNumber);
|
2009-09-10 14:28:34 +03:00
|
|
|
|
2010-12-04 21:15:20 +02:00
|
|
|
if(ba.actionType != BattleAction::HERO_SPELL) //don't check for stack if it's custom action by hero
|
2009-09-10 14:28:34 +03:00
|
|
|
assert(st);
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
switch(ba.actionType)
|
|
|
|
{
|
2010-12-04 21:15:20 +02:00
|
|
|
case BattleAction::DEFEND:
|
2009-03-07 17:55:56 +02:00
|
|
|
st->state.insert(DEFENDING);
|
|
|
|
break;
|
2010-12-04 21:15:20 +02:00
|
|
|
case BattleAction::WAIT:
|
2009-03-07 17:55:56 +02:00
|
|
|
st->state.insert(WAITING);
|
2009-11-21 00:35:18 +02:00
|
|
|
return;
|
2010-12-04 21:15:20 +02:00
|
|
|
case BattleAction::NO_ACTION: case BattleAction::WALK: case BattleAction::WALK_AND_ATTACK:
|
|
|
|
case BattleAction::SHOOT: case BattleAction::CATAPULT: case BattleAction::MONSTER_SPELL:
|
|
|
|
case BattleAction::BAD_MORALE: case BattleAction::STACK_HEAL:
|
2009-03-07 17:55:56 +02:00
|
|
|
st->state.insert(MOVED);
|
|
|
|
break;
|
|
|
|
}
|
2009-11-21 00:35:18 +02:00
|
|
|
|
2009-11-28 03:42:08 +02:00
|
|
|
if(st)
|
|
|
|
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)
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
2010-05-16 16:42:19 +03:00
|
|
|
DLL_EXPORT void BattleSpellCast::applyGs( CGameState *gs )
|
2009-03-07 17:55:56 +02:00
|
|
|
{
|
2010-05-02 21:20:26 +03:00
|
|
|
assert(gs->curB);
|
2009-10-06 03:32:33 +03:00
|
|
|
CGHeroInstance *h = (side) ? gs->curB->heroes[1] : gs->curB->heroes[0];
|
2010-05-11 20:09:08 +03:00
|
|
|
if(h && castedByHero)
|
2009-03-07 17:55:56 +02:00
|
|
|
{
|
2009-08-23 16:41:57 +03:00
|
|
|
int spellCost = 0;
|
|
|
|
if(gs->curB)
|
|
|
|
{
|
2010-12-19 16:39:56 +02:00
|
|
|
spellCost = gs->curB->getSpellCost(VLC->spellh->spells[id], h);
|
2009-08-23 16:41:57 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-19 16:39:56 +02:00
|
|
|
spellCost = VLC->spellh->spells[id]->costs[skill];
|
2009-08-23 16:41:57 +03:00
|
|
|
}
|
|
|
|
h->mana -= spellCost;
|
2009-03-07 17:55:56 +02:00
|
|
|
if(h->mana < 0) h->mana = 0;
|
|
|
|
}
|
2010-05-11 20:09:08 +03:00
|
|
|
if(side >= 0 && side < 2 && castedByHero)
|
2009-03-07 17:55:56 +02:00
|
|
|
{
|
2009-05-12 06:35:51 +03:00
|
|
|
gs->curB->castSpells[side]++;
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
2009-07-26 15:15:38 +03:00
|
|
|
|
2009-08-06 17:02:21 +03:00
|
|
|
|
2010-05-02 21:20:26 +03:00
|
|
|
if(id == 35 || id == 78) //dispel and dispel helpful spells
|
2009-04-21 20:32:43 +03:00
|
|
|
{
|
2010-03-03 13:18:08 +02:00
|
|
|
bool onlyHelpful = id == 78;
|
2009-08-04 20:05:49 +03:00
|
|
|
for(std::set<ui32>::const_iterator it = affectedCres.begin(); it != affectedCres.end(); ++it)
|
2009-04-21 20:32:43 +03:00
|
|
|
{
|
2009-08-04 20:05:49 +03:00
|
|
|
CStack *s = gs->curB->getStack(*it);
|
|
|
|
if(s && !vstd::contains(resisted, s->ID)) //if stack exists and it didn't resist
|
2009-05-16 17:49:06 +03:00
|
|
|
{
|
2010-08-30 21:06:17 +03:00
|
|
|
BonusList remainingEff;
|
2010-11-19 00:06:56 +02:00
|
|
|
//WTF?
|
2010-08-30 21:06:17 +03:00
|
|
|
for (BonusList::iterator it = remainingEff.begin(); it != remainingEff.end(); it++)
|
2010-03-03 13:18:08 +02:00
|
|
|
{
|
2010-12-19 16:39:56 +02:00
|
|
|
if (onlyHelpful && VLC->spellh->spells[ (*it)->id ]->positiveness != 1)
|
2010-03-03 13:18:08 +02:00
|
|
|
{
|
2010-08-30 21:06:17 +03:00
|
|
|
remainingEff.push_back(*it);
|
2010-03-03 13:18:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2011-01-20 21:57:12 +02:00
|
|
|
s->bonuses.removeSpells(Bonus::SPELL_EFFECT); //removing all effects
|
2010-08-30 21:06:17 +03:00
|
|
|
s->bonuses = remainingEff; //assigning effects that should remain
|
2010-03-03 13:18:08 +02:00
|
|
|
|
2009-08-04 20:05:49 +03:00
|
|
|
//removing all features from spells
|
2010-05-02 21:20:26 +03:00
|
|
|
BonusList tmpFeatures = s->bonuses;
|
|
|
|
s->bonuses.clear();
|
2010-11-19 00:06:56 +02:00
|
|
|
BOOST_FOREACH(Bonus *b, tmpFeatures)
|
2009-05-16 17:49:06 +03:00
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
const CSpell *sp = b->sourceSpell();
|
|
|
|
if(sp && sp->positiveness != 1) //if(b->source != HeroBonus::SPELL_EFFECT || b.positiveness != 1)
|
|
|
|
s->addNewBonus(b);
|
2009-05-16 17:49:06 +03:00
|
|
|
}
|
|
|
|
}
|
2009-04-21 20:32:43 +03:00
|
|
|
}
|
|
|
|
}
|
2009-08-06 17:02:21 +03:00
|
|
|
|
|
|
|
//elemental summoning
|
|
|
|
if(id >= 66 && id <= 69)
|
|
|
|
{
|
|
|
|
int creID;
|
|
|
|
switch(id)
|
|
|
|
{
|
|
|
|
case 66:
|
|
|
|
creID = 114; //fire elemental
|
|
|
|
break;
|
|
|
|
case 67:
|
|
|
|
creID = 113; //earth elemental
|
|
|
|
break;
|
|
|
|
case 68:
|
|
|
|
creID = 115; //water elemental
|
|
|
|
break;
|
|
|
|
case 69:
|
|
|
|
creID = 112; //air elemental
|
|
|
|
break;
|
|
|
|
}
|
2010-11-20 02:03:31 +02:00
|
|
|
// const int3 & tile = gs->curB->tile;
|
|
|
|
// TerrainTile::EterrainType ter = gs->map->terrain[tile.x][tile.y][tile.z].tertype;
|
2009-08-06 17:02:21 +03:00
|
|
|
|
|
|
|
int pos; //position of stack on the battlefield - to be calculated
|
|
|
|
|
|
|
|
bool ac[BFIELD_SIZE];
|
2011-01-07 12:48:31 +02:00
|
|
|
std::set<THex> occupyable;
|
2010-05-02 21:20:26 +03:00
|
|
|
bool twoHex = VLC->creh->creatures[creID]->isDoubleWide();
|
2010-11-19 00:06:56 +02:00
|
|
|
bool flying = VLC->creh->creatures[creID]->isFlying();// vstd::contains(VLC->creh->creatures[creID]->bonuses, Bonus::FLYING);
|
2009-08-06 17:02:21 +03:00
|
|
|
gs->curB->getAccessibilityMap(ac, twoHex, !side, true, occupyable, flying);
|
|
|
|
for(int g=0; g<BFIELD_SIZE; ++g)
|
|
|
|
{
|
|
|
|
if(g % BFIELD_WIDTH != 0 && g % BFIELD_WIDTH != BFIELD_WIDTH-1 && BattleInfo::isAccessible(g, ac, twoHex, !side, flying, true) )
|
|
|
|
{
|
|
|
|
pos = g;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-19 16:39:56 +02:00
|
|
|
CStackInstance *csi = new CStackInstance(creID, h->getPrimSkillLevel(2) * VLC->spellh->spells[id]->powers[skill]); //deleted by d-tor of summoned stack
|
2010-11-27 03:46:19 +02:00
|
|
|
csi->setArmyObj(h);
|
|
|
|
CStack * summonedStack = gs->curB->generateNewStack(*csi, gs->curB->stacks.size(), !side, 255, pos);
|
2010-05-02 21:20:26 +03:00
|
|
|
summonedStack->state.insert(SUMMONED);
|
2010-11-19 00:06:56 +02:00
|
|
|
//summonedStack->addNewBonus( makeFeature(HeroBonus::SUMMONED, HeroBonus::ONE_BATTLE, 0, 0, HeroBonus::BONUS_FROM_HERO) );
|
2009-08-06 17:02:21 +03:00
|
|
|
gs->curB->stacks.push_back(summonedStack);
|
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
2011-01-20 21:57:12 +02:00
|
|
|
void actualizeEffect(CStack * s, const std::vector<Bonus> & ef)
|
2009-05-17 18:24:50 +03:00
|
|
|
{
|
|
|
|
//actualizing features vector
|
2010-05-02 21:20:26 +03:00
|
|
|
|
2011-01-20 21:57:12 +02:00
|
|
|
BOOST_FOREACH(const Bonus &fromEffect, ef)
|
2009-05-17 18:24:50 +03:00
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
BOOST_FOREACH(Bonus *stackBonus, s->bonuses) //TODO: optimize
|
2009-05-17 18:24:50 +03:00
|
|
|
{
|
2011-01-20 21:57:12 +02:00
|
|
|
if(stackBonus->source == Bonus::SPELL_EFFECT && stackBonus->type == fromEffect.type && stackBonus->subtype == fromEffect.subtype)
|
2009-05-17 18:24:50 +03:00
|
|
|
{
|
2011-01-20 21:57:12 +02:00
|
|
|
stackBonus->turnsRemain = std::max(stackBonus->turnsRemain, fromEffect.turnsRemain);
|
2009-05-17 18:24:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
DLL_EXPORT void SetStackEffect::applyGs( CGameState *gs )
|
|
|
|
{
|
2009-03-21 14:49:58 +02:00
|
|
|
BOOST_FOREACH(ui32 id, stacks)
|
|
|
|
{
|
|
|
|
CStack *s = gs->curB->getStack(id);
|
|
|
|
if(s)
|
2009-04-17 17:01:22 +03:00
|
|
|
{
|
2011-01-20 21:57:12 +02:00
|
|
|
int id = effect.begin()->id; //effects' source ID
|
|
|
|
if(id == 47 || !s->hasBonus(Selector::source(Bonus::SPELL_EFFECT, id)))//disrupting ray or not on the list - just add
|
2009-05-16 17:49:06 +03:00
|
|
|
{
|
2011-01-20 21:57:12 +02:00
|
|
|
BOOST_FOREACH(Bonus &fromEffect, effect)
|
2009-05-16 17:49:06 +03:00
|
|
|
{
|
2011-01-20 21:57:12 +02:00
|
|
|
s->addNewBonus( new Bonus(fromEffect));
|
2009-05-16 17:49:06 +03:00
|
|
|
}
|
2009-05-17 18:24:50 +03:00
|
|
|
}
|
|
|
|
else //just actualize
|
|
|
|
{
|
|
|
|
actualizeEffect(s, effect);
|
2009-05-16 17:49:06 +03:00
|
|
|
}
|
2009-04-17 17:01:22 +03:00
|
|
|
}
|
2009-03-21 14:49:58 +02:00
|
|
|
else
|
|
|
|
tlog1 << "Cannot find stack " << id << std::endl;
|
|
|
|
}
|
2009-03-07 17:55:56 +02:00
|
|
|
}
|
|
|
|
|
2009-04-16 03:28:54 +03:00
|
|
|
DLL_EXPORT void StacksInjured::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
BOOST_FOREACH(BattleStackAttacked stackAttacked, stacks)
|
|
|
|
stackAttacked.applyGs(gs);
|
|
|
|
}
|
|
|
|
|
2009-08-04 20:05:49 +03:00
|
|
|
DLL_EXPORT void StacksHealedOrResurrected::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
for(int g=0; g<healedStacks.size(); ++g)
|
|
|
|
{
|
2009-10-17 17:32:42 +03:00
|
|
|
CStack * changedStack = gs->curB->getStack(healedStacks[g].stackID, false);
|
2009-08-17 14:22:29 +03:00
|
|
|
|
|
|
|
//checking if we resurrect a stack that is under a living stack
|
2011-01-07 12:48:31 +02:00
|
|
|
std::vector<THex> access = gs->curB->getAccessibility(changedStack, true);
|
2009-08-17 14:22:29 +03:00
|
|
|
bool acc[BFIELD_SIZE];
|
|
|
|
for(int h=0; h<BFIELD_SIZE; ++h)
|
|
|
|
acc[h] = false;
|
|
|
|
for(int h=0; h<access.size(); ++h)
|
|
|
|
acc[access[h]] = true;
|
|
|
|
if(!changedStack->alive() && !gs->curB->isAccessible(changedStack->position, acc,
|
2010-05-02 21:20:26 +03:00
|
|
|
changedStack->doubleWide(), changedStack->attackerOwned,
|
|
|
|
changedStack->hasBonusOfType(Bonus::FLYING), true))
|
2009-08-17 14:22:29 +03:00
|
|
|
return; //position is already occupied
|
|
|
|
|
|
|
|
//applying changes
|
2009-10-17 17:32:42 +03:00
|
|
|
bool resurrected = !changedStack->alive(); //indicates if stack is resurrected or just healed
|
2010-05-07 15:29:41 +03:00
|
|
|
if(resurrected)
|
2009-08-05 15:46:08 +03:00
|
|
|
{
|
|
|
|
changedStack->state.insert(ALIVE);
|
2010-01-29 18:35:05 +02:00
|
|
|
if(healedStacks[g].lowLevelResurrection)
|
2010-05-02 21:20:26 +03:00
|
|
|
changedStack->state.insert(SUMMONED);
|
2010-11-19 00:06:56 +02:00
|
|
|
//changedStack->addNewBonus( makeFeature(HeroBonus::SUMMONED, HeroBonus::ONE_BATTLE, 0, 0, HeroBonus::BONUS_FROM_HERO) );
|
2009-08-05 15:46:08 +03:00
|
|
|
}
|
2010-11-09 13:27:58 +02:00
|
|
|
//int missingHPfirst = changedStack->MaxHealth() - changedStack->firstHPleft;
|
2010-05-02 21:20:26 +03:00
|
|
|
int res = std::min( healedStacks[g].healedHP / changedStack->MaxHealth() , changedStack->baseAmount - changedStack->count );
|
|
|
|
changedStack->count += res;
|
2009-10-17 17:32:42 +03:00
|
|
|
changedStack->firstHPleft += healedStacks[g].healedHP - res * changedStack->MaxHealth();
|
2009-08-05 15:46:08 +03:00
|
|
|
if(changedStack->firstHPleft > changedStack->MaxHealth())
|
|
|
|
{
|
|
|
|
changedStack->firstHPleft -= changedStack->MaxHealth();
|
2010-05-02 21:20:26 +03:00
|
|
|
if(changedStack->baseAmount > changedStack->count)
|
2009-10-17 17:32:42 +03:00
|
|
|
{
|
2010-05-02 21:20:26 +03:00
|
|
|
changedStack->count += 1;
|
2009-10-17 17:32:42 +03:00
|
|
|
}
|
2009-08-05 15:46:08 +03:00
|
|
|
}
|
2009-10-17 17:32:42 +03:00
|
|
|
amin(changedStack->firstHPleft, changedStack->MaxHealth());
|
2009-08-04 20:05:49 +03:00
|
|
|
//removal of negative effects
|
2009-10-17 17:32:42 +03:00
|
|
|
if(resurrected)
|
2009-08-04 20:05:49 +03:00
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
|
2010-08-30 21:06:17 +03:00
|
|
|
for (BonusList::iterator it = changedStack->bonuses.begin(); it != changedStack->bonuses.end(); it++)
|
2009-08-04 20:05:49 +03:00
|
|
|
{
|
2010-12-19 16:39:56 +02:00
|
|
|
if(VLC->spellh->spells[(*it)->id]->positiveness < 0)
|
2009-08-04 20:05:49 +03:00
|
|
|
{
|
2010-08-30 21:06:17 +03:00
|
|
|
changedStack->bonuses.erase(it);
|
2009-08-04 20:05:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//removing all features from negative spells
|
2010-05-02 21:20:26 +03:00
|
|
|
BonusList tmpFeatures = changedStack->bonuses;
|
|
|
|
changedStack->bonuses.clear();
|
|
|
|
|
2010-11-19 00:06:56 +02:00
|
|
|
BOOST_FOREACH(Bonus *b, tmpFeatures)
|
2009-08-04 20:05:49 +03:00
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
const CSpell *s = b->sourceSpell();
|
2010-05-02 21:20:26 +03:00
|
|
|
if(s && s->positiveness >= 0)
|
2009-08-04 20:05:49 +03:00
|
|
|
{
|
2010-11-19 00:06:56 +02:00
|
|
|
changedStack->addNewBonus(b);
|
2009-08-04 20:05:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-19 13:59:42 +03:00
|
|
|
DLL_EXPORT void ObstaclesRemoved::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
if(gs->curB) //if there is a battle
|
|
|
|
{
|
|
|
|
for(std::set<si32>::const_iterator it = obstacles.begin(); it != obstacles.end(); ++it)
|
|
|
|
{
|
|
|
|
for(int i=0; i<gs->curB->obstacles.size(); ++i)
|
|
|
|
{
|
|
|
|
if(gs->curB->obstacles[i].uniqueID == *it) //remove this obstacle
|
|
|
|
{
|
|
|
|
gs->curB->obstacles.erase(gs->curB->obstacles.begin() + i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-01 16:54:13 +03:00
|
|
|
DLL_EXPORT void CatapultAttack::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
if(gs->curB && gs->curB->siege != 0) //if there is a battle and it's a siege
|
|
|
|
{
|
2009-09-24 16:44:55 +03:00
|
|
|
for(std::set< std::pair< std::pair< ui8, si16 >, ui8> >::const_iterator it = attackedParts.begin(); it != attackedParts.end(); ++it)
|
2009-09-07 15:30:10 +03:00
|
|
|
{
|
2009-09-24 16:44:55 +03:00
|
|
|
gs->curB->si.wallState[it->first.first] =
|
|
|
|
std::min( gs->curB->si.wallState[it->first.first] + it->second, 3 );
|
2009-09-07 15:30:10 +03:00
|
|
|
}
|
2009-09-01 16:54:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-05 17:10:26 +03:00
|
|
|
DLL_EXPORT void BattleStacksRemoved::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
if(!gs->curB)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(std::set<ui32>::const_iterator it = stackIDs.begin(); it != stackIDs.end(); ++it) //for each removed stack
|
|
|
|
{
|
|
|
|
for(int b=0; b<gs->curB->stacks.size(); ++b) //find it in vector of stacks
|
|
|
|
{
|
|
|
|
if(gs->curB->stacks[b]->ID == *it) //if found
|
|
|
|
{
|
|
|
|
gs->curB->stacks.erase(gs->curB->stacks.begin() + b); //remove
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-07 17:55:56 +02:00
|
|
|
DLL_EXPORT void YourTurn::applyGs( CGameState *gs )
|
|
|
|
{
|
|
|
|
gs->currentPlayer = player;
|
|
|
|
}
|
|
|
|
|
|
|
|
DLL_EXPORT void SetSelection::applyGs( CGameState *gs )
|
|
|
|
{
|
2009-03-09 12:37:49 +02:00
|
|
|
gs->getPlayer(player)->currentSelection = id;
|
2010-04-02 05:07:40 +03:00
|
|
|
}
|
|
|
|
|
2010-11-22 02:34:46 +02:00
|
|
|
DLL_EXPORT Component::Component(const CStackBasicDescriptor &stack)
|
2010-04-02 05:07:40 +03:00
|
|
|
:id(CREATURE), subtype(stack.type->idNumber), val(stack.count), when(0)
|
|
|
|
{
|
|
|
|
|
2009-08-13 04:03:11 +03:00
|
|
|
}
|