2007-08-27 17:15:03 +03:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "CCallback.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "lib/CCreatureHandler.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "client/CGameInfo.h"
|
|
|
|
#include "lib/CGameState.h"
|
2010-12-25 21:23:30 +02:00
|
|
|
#include "lib/BattleState.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "client/CPlayerInterface.h"
|
2008-08-30 00:41:32 +03:00
|
|
|
#include "client/Client.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "lib/map.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "lib/CBuildingHandler.h"
|
|
|
|
#include "lib/CDefObjInfoHandler.h"
|
|
|
|
#include "lib/CGeneralTextHandler.h"
|
|
|
|
#include "lib/CHeroHandler.h"
|
|
|
|
#include "lib/CObjectHandler.h"
|
2008-07-27 20:07:37 +03:00
|
|
|
#include "lib/Connection.h"
|
2008-07-28 15:44:08 +03:00
|
|
|
#include "lib/NetPacks.h"
|
2010-04-06 11:59:24 +03:00
|
|
|
#include "client/mapHandler.h"
|
2008-08-30 00:41:32 +03:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include <boost/thread.hpp>
|
2008-08-05 02:04:15 +03:00
|
|
|
#include <boost/thread/shared_mutex.hpp>
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "lib/CSpellHandler.h"
|
|
|
|
#include "lib/CArtHandler.h"
|
2008-08-04 18:56:36 +03:00
|
|
|
#ifdef min
|
|
|
|
#undef min
|
|
|
|
#endif
|
|
|
|
#ifdef max
|
|
|
|
#undef max
|
|
|
|
#endif
|
2008-03-14 20:24:37 +02:00
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* CCallback.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-03-07 00:11:17 +02:00
|
|
|
template <ui16 N> bool isType(CPack *pack)
|
|
|
|
{
|
|
|
|
return pack->getType() == N;
|
|
|
|
}
|
|
|
|
|
2010-06-30 22:27:35 +03:00
|
|
|
bool CCallback::teleportHero(const CGHeroInstance *who, const CGTownInstance *where)
|
|
|
|
{
|
|
|
|
CastleTeleportHero pack(who->id, where->id, 1);
|
|
|
|
sendRequest(&pack);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-04 02:53:18 +03:00
|
|
|
bool CCallback::moveHero(const CGHeroInstance *h, int3 dst)
|
2009-03-12 20:50:36 +02:00
|
|
|
{
|
2009-03-20 20:51:48 +02:00
|
|
|
MoveHero pack(dst,h->id);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2007-08-30 13:11:53 +03:00
|
|
|
return true;
|
2007-08-29 15:18:31 +03:00
|
|
|
}
|
2007-12-25 18:25:53 +02:00
|
|
|
void CCallback::selectionMade(int selection, int asker)
|
|
|
|
{
|
2009-03-20 20:51:48 +02:00
|
|
|
QueryReply pack(asker,selection);
|
|
|
|
*cl->serv << &pack;
|
2007-12-25 18:25:53 +02:00
|
|
|
}
|
2010-07-10 19:50:23 +03:00
|
|
|
void CCallback::recruitCreatures(const CGObjectInstance *obj, ui32 ID, ui32 amount, si32 level/*=-1*/)
|
2008-04-11 20:41:02 +03:00
|
|
|
{
|
2010-05-15 11:33:32 +03:00
|
|
|
if(player!=obj->tempOwner && obj->ID != 106)
|
|
|
|
return;
|
2009-03-20 20:51:48 +02:00
|
|
|
|
2010-07-10 19:50:23 +03:00
|
|
|
RecruitCreatures pack(obj->id,ID,amount,level);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-04-11 20:41:02 +03:00
|
|
|
}
|
2007-09-14 16:11:10 +03:00
|
|
|
|
2008-05-23 22:50:11 +03:00
|
|
|
|
|
|
|
bool CCallback::dismissCreature(const CArmedInstance *obj, int stackPos)
|
|
|
|
{
|
2010-05-02 21:20:26 +03:00
|
|
|
if(((player>=0) && obj->tempOwner != player) || (obj->stacksCount()<2 && obj->needsLastStack()))
|
2008-05-31 23:37:54 +03:00
|
|
|
return false;
|
2009-03-20 20:51:48 +02:00
|
|
|
|
|
|
|
DisbandCreature pack(stackPos,obj->id);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-05-31 23:37:54 +03:00
|
|
|
return true;
|
2008-05-23 22:50:11 +03:00
|
|
|
}
|
2008-05-31 23:37:54 +03:00
|
|
|
bool CCallback::upgradeCreature(const CArmedInstance *obj, int stackPos, int newID)
|
2008-05-23 22:50:11 +03:00
|
|
|
{
|
2009-03-20 20:51:48 +02:00
|
|
|
UpgradeCreature pack(stackPos,obj->id,newID);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-05-23 22:50:11 +03:00
|
|
|
return false;
|
|
|
|
}
|
2008-07-27 20:07:37 +03:00
|
|
|
void CCallback::endTurn()
|
|
|
|
{
|
2009-10-31 18:33:11 +02:00
|
|
|
tlog5 << "Player " << (unsigned)player << " ended his turn." << std::endl;
|
2009-03-20 20:51:48 +02:00
|
|
|
EndTurn pack;
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack); //report that we ended turn
|
2008-07-27 20:07:37 +03:00
|
|
|
}
|
2008-09-26 17:16:01 +03:00
|
|
|
UpgradeInfo CCallback::getUpgradeInfo(const CArmedInstance *obj, int stackPos) const
|
2008-05-23 22:50:11 +03:00
|
|
|
{
|
2008-08-20 22:02:48 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2010-07-15 06:04:57 +03:00
|
|
|
return gs->getUpgradeInfo(obj->getStack(stackPos));
|
2008-05-23 22:50:11 +03:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:16:01 +03:00
|
|
|
const StartInfo * CCallback::getStartInfo() const
|
2008-06-30 03:06:41 +03:00
|
|
|
{
|
2008-08-20 22:02:48 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2008-06-30 03:06:41 +03:00
|
|
|
return gs->scenarioOps;
|
|
|
|
}
|
|
|
|
|
2009-08-23 16:41:57 +03:00
|
|
|
int CCallback::getSpellCost(const CSpell * sp, const CGHeroInstance * caster) const
|
|
|
|
{
|
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
|
|
|
|
//if there is a battle
|
|
|
|
if(gs->curB)
|
|
|
|
return gs->curB->getSpellCost(sp, caster);
|
|
|
|
|
|
|
|
//if there is no battle
|
2010-03-11 01:16:30 +02:00
|
|
|
return caster->getSpellCost(sp);
|
2009-08-23 16:41:57 +03:00
|
|
|
}
|
|
|
|
|
2010-11-15 09:15:10 +02:00
|
|
|
int CCallback::estimateSpellDamage(const CSpell * sp, const CGHeroInstance * hero) const
|
2009-11-08 16:44:58 +02:00
|
|
|
{
|
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
|
2010-11-15 09:15:10 +02:00
|
|
|
if(!gs->curB) //no battle
|
|
|
|
{
|
|
|
|
if (hero) //but we see hero's spellbook
|
|
|
|
return gs->curB->calculateSpellDmg(sp, hero, NULL, hero->getSpellSchoolLevel(sp), hero->getPrimSkillLevel(2));
|
|
|
|
else
|
|
|
|
return 0; //mage guild
|
|
|
|
}
|
|
|
|
//gs->getHero(gs->currentPlayer)
|
2009-11-08 16:44:58 +02:00
|
|
|
const CGHeroInstance * ourHero = gs->curB->heroes[0]->tempOwner == player ? gs->curB->heroes[0] : gs->curB->heroes[1];
|
2010-02-24 20:11:08 +02:00
|
|
|
return gs->curB->calculateSpellDmg(sp, ourHero, NULL, ourHero->getSpellSchoolLevel(sp), ourHero->getPrimSkillLevel(2));
|
2009-11-08 16:44:58 +02:00
|
|
|
}
|
|
|
|
|
2010-02-01 19:51:33 +02:00
|
|
|
void CCallback::getThievesGuildInfo(SThievesGuildInfo & thi, const CGObjectInstance * obj)
|
|
|
|
{
|
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
|
|
|
|
if(obj == NULL)
|
|
|
|
return;
|
|
|
|
|
2010-07-09 02:03:27 +03:00
|
|
|
if(obj->ID == TOWNI_TYPE || obj->ID == 95) //it is a town or adv map tavern
|
2010-02-01 19:51:33 +02:00
|
|
|
{
|
|
|
|
gs->obtainPlayersStats(thi, gs->players[player].towns.size());
|
|
|
|
}
|
|
|
|
else if(obj->ID == 97) //Den of Thieves
|
|
|
|
{
|
|
|
|
gs->obtainPlayersStats(thi, 20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:16:01 +03:00
|
|
|
int CCallback::howManyTowns() const
|
2007-09-18 16:30:26 +03:00
|
|
|
{
|
2008-08-20 22:02:48 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
return gs->players[player].towns.size();
|
2007-09-18 16:30:26 +03:00
|
|
|
}
|
2009-08-23 16:41:57 +03:00
|
|
|
|
2008-09-26 17:16:01 +03:00
|
|
|
const CGTownInstance * CCallback::getTownInfo(int val, bool mode) const //mode = 0 -> val = serial; mode = 1 -> val = ID
|
2007-09-18 16:30:26 +03:00
|
|
|
{
|
2008-08-20 22:02:48 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2007-09-18 16:30:26 +03:00
|
|
|
if (!mode)
|
2009-08-01 13:08:16 +03:00
|
|
|
{
|
2010-12-20 15:04:24 +02:00
|
|
|
const std::vector<ConstTransitivePtr<CGTownInstance> > &towns = gs->players[gs->currentPlayer].towns;
|
2009-08-01 13:08:16 +03:00
|
|
|
if(val < towns.size())
|
|
|
|
return towns[val];
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-07-06 05:10:26 +03:00
|
|
|
else if(mode == 1)
|
2007-09-18 16:30:26 +03:00
|
|
|
{
|
2010-07-06 05:10:26 +03:00
|
|
|
const CGObjectInstance *obj = getObjectInfo(val);
|
|
|
|
if(!obj)
|
|
|
|
return NULL;
|
|
|
|
if(obj->ID != TOWNI_TYPE)
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return static_cast<const CGTownInstance *>(obj);
|
2007-09-18 16:30:26 +03:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-07-20 05:56:35 +03:00
|
|
|
|
|
|
|
bool CCallback::getTownInfo( const CGObjectInstance *town, InfoAboutTown &dest ) const
|
|
|
|
{
|
2010-03-21 00:17:19 +02:00
|
|
|
if(!isVisible(town, player)) //it's not a town or it's not visible for layer
|
2009-07-20 05:56:35 +03:00
|
|
|
return false;
|
|
|
|
|
2010-03-21 00:17:19 +02:00
|
|
|
bool detailed = hasAccess(town->tempOwner);
|
|
|
|
|
2010-08-13 13:46:08 +03:00
|
|
|
//TODO vision support
|
2010-03-21 00:17:19 +02:00
|
|
|
if(town->ID == TOWNI_TYPE)
|
|
|
|
dest.initFromTown(static_cast<const CGTownInstance *>(town), detailed);
|
|
|
|
else if(town->ID == 33 || town->ID == 219)
|
|
|
|
dest.initFromGarrison(static_cast<const CGGarrison *>(town), detailed);
|
|
|
|
else
|
|
|
|
return false;
|
2009-07-20 05:56:35 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-06 15:13:31 +03:00
|
|
|
int3 CCallback::guardingCreaturePosition (int3 pos) const
|
|
|
|
{
|
|
|
|
return gs->guardingCreaturePosition(pos);
|
|
|
|
}
|
|
|
|
|
2009-04-09 18:05:20 +03:00
|
|
|
int CCallback::howManyHeroes(bool includeGarrisoned) const
|
2007-09-14 16:11:10 +03:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2009-04-09 18:05:20 +03:00
|
|
|
return cl->getHeroCount(player,includeGarrisoned);
|
2007-09-14 16:11:10 +03:00
|
|
|
}
|
2008-09-26 17:16:01 +03:00
|
|
|
const CGHeroInstance * CCallback::getHeroInfo(int val, int mode) const //mode = 0 -> val = serial; mode = 1 -> val = ID
|
2007-09-14 16:11:10 +03:00
|
|
|
{
|
2008-12-21 21:17:35 +02:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx); //TODO use me?
|
2008-08-27 13:19:18 +03:00
|
|
|
//if (gs->currentPlayer!=player) //TODO: checking if we are allowed to give that info
|
|
|
|
// return NULL;
|
|
|
|
if (!mode) //esrial id
|
2008-12-23 15:59:03 +02:00
|
|
|
{
|
|
|
|
if(val<gs->players[player].heroes.size())
|
|
|
|
{
|
2008-01-20 18:24:03 +02:00
|
|
|
return gs->players[player].heroes[val];
|
2008-12-23 15:59:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2008-08-27 13:19:18 +03:00
|
|
|
else if(mode==1) //it's hero type id
|
2007-09-14 16:11:10 +03:00
|
|
|
{
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t i=0; i < gs->players[player].heroes.size(); ++i)
|
2007-09-14 16:11:10 +03:00
|
|
|
{
|
2008-12-23 15:59:03 +02:00
|
|
|
if (gs->players[player].heroes[i]->type->ID==val)
|
|
|
|
{
|
2007-09-14 16:11:10 +03:00
|
|
|
return gs->players[player].heroes[i];
|
2008-12-23 15:59:03 +02:00
|
|
|
}
|
2007-09-14 16:11:10 +03:00
|
|
|
}
|
|
|
|
}
|
2008-08-27 13:19:18 +03:00
|
|
|
else //object id
|
|
|
|
{
|
2010-12-19 00:11:28 +02:00
|
|
|
return static_cast<const CGHeroInstance*>(gs->map->objects[val].get());
|
2008-08-27 13:19:18 +03:00
|
|
|
}
|
2007-09-14 16:11:10 +03:00
|
|
|
return NULL;
|
2007-09-16 20:21:23 +03:00
|
|
|
}
|
2007-09-18 16:30:26 +03:00
|
|
|
|
2009-07-30 15:49:45 +03:00
|
|
|
const CGObjectInstance * CCallback::getObjectInfo(int ID) const
|
|
|
|
{
|
2010-07-06 05:10:26 +03:00
|
|
|
//TODO: check for visibility
|
2009-07-30 15:49:45 +03:00
|
|
|
return gs->map->objects[ID];
|
|
|
|
}
|
|
|
|
|
2009-07-20 04:47:49 +03:00
|
|
|
bool CCallback::getHeroInfo( const CGObjectInstance *hero, InfoAboutHero &dest ) const
|
|
|
|
{
|
|
|
|
const CGHeroInstance *h = dynamic_cast<const CGHeroInstance *>(hero);
|
|
|
|
if(!h || !isVisible(h->getPosition(false))) //it's not a hero or it's not visible for layer
|
|
|
|
return false;
|
|
|
|
|
2010-08-13 13:46:08 +03:00
|
|
|
//TODO vision support
|
2010-03-21 00:17:19 +02:00
|
|
|
dest.initFromHero(h, hasAccess(h->tempOwner));
|
2009-07-20 04:47:49 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:16:01 +03:00
|
|
|
int CCallback::getResourceAmount(int type) const
|
2007-09-16 20:21:23 +03:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2007-12-01 14:50:33 +02:00
|
|
|
return gs->players[player].resources[type];
|
2007-09-18 16:30:26 +03:00
|
|
|
}
|
2008-09-26 17:16:01 +03:00
|
|
|
std::vector<si32> CCallback::getResourceAmount() const
|
2008-05-12 08:46:04 +03:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2008-05-12 08:46:04 +03:00
|
|
|
return gs->players[player].resources;
|
|
|
|
}
|
2008-09-26 17:16:01 +03:00
|
|
|
int CCallback::getDate(int mode) const
|
2007-09-18 16:30:26 +03:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2008-07-25 20:28:28 +03:00
|
|
|
return gs->getDate(mode);
|
2007-10-05 21:10:33 +03:00
|
|
|
}
|
2008-09-26 17:16:01 +03:00
|
|
|
std::vector < std::string > CCallback::getObjDescriptions(int3 pos) const
|
2008-07-29 12:53:27 +03:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2008-07-29 12:53:27 +03:00
|
|
|
std::vector<std::string> ret;
|
2008-09-12 11:51:46 +03:00
|
|
|
if(!isVisible(pos,player))
|
|
|
|
return ret;
|
2008-07-30 20:51:19 +03:00
|
|
|
BOOST_FOREACH(const CGObjectInstance * obj, gs->map->terrain[pos.x][pos.y][pos.z].blockingObjects)
|
2008-12-22 19:48:41 +02:00
|
|
|
ret.push_back(obj->getHoverText());
|
2008-07-29 12:53:27 +03:00
|
|
|
return ret;
|
|
|
|
}
|
2008-09-26 17:16:01 +03:00
|
|
|
bool CCallback::verifyPath(CPath * path, bool blockSea) const
|
2007-10-05 21:16:22 +03:00
|
|
|
{
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t i=0; i < path->nodes.size(); ++i)
|
2007-10-05 21:16:22 +03:00
|
|
|
{
|
2010-08-16 16:51:31 +03:00
|
|
|
if ( CGI->mh->map->terrain[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].blocked
|
|
|
|
&& (! (CGI->mh->map->terrain[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].visitable)))
|
2007-10-05 21:16:22 +03:00
|
|
|
return false; //path is wrong - one of the tiles is blocked
|
|
|
|
|
|
|
|
if (blockSea)
|
|
|
|
{
|
|
|
|
if (i==0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (
|
2010-08-16 16:51:31 +03:00
|
|
|
((CGI->mh->map->terrain[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tertype==TerrainTile::water)
|
2007-10-05 21:16:22 +03:00
|
|
|
&&
|
2010-08-16 16:51:31 +03:00
|
|
|
(CGI->mh->map->terrain[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tertype!=TerrainTile::water))
|
2007-10-05 21:16:22 +03:00
|
|
|
||
|
2010-08-16 16:51:31 +03:00
|
|
|
((CGI->mh->map->terrain[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tertype!=TerrainTile::water)
|
2007-10-05 21:16:22 +03:00
|
|
|
&&
|
2010-08-16 16:51:31 +03:00
|
|
|
(CGI->mh->map->terrain[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tertype==TerrainTile::water))
|
2007-10-05 23:38:14 +03:00
|
|
|
||
|
2010-08-16 16:51:31 +03:00
|
|
|
(CGI->mh->map->terrain[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tertype==TerrainTile::rock)
|
2007-10-05 21:16:22 +03:00
|
|
|
|
|
|
|
)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2007-10-05 21:10:33 +03:00
|
|
|
|
2008-09-26 17:16:01 +03:00
|
|
|
std::vector< std::vector< std::vector<unsigned char> > > & CCallback::getVisibilityMap() const
|
2007-10-16 20:46:01 +03:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2010-08-03 15:34:06 +03:00
|
|
|
return gs->getPlayerTeam(player)->fogOfWarMap;
|
2007-10-20 00:12:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-26 17:16:01 +03:00
|
|
|
bool CCallback::isVisible(int3 pos, int Player) const
|
2007-10-20 00:12:37 +03:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2010-02-10 04:56:00 +02:00
|
|
|
return gs->map->isInTheMap(pos) && gs->isVisible(pos, Player);
|
2007-10-20 00:12:37 +03:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:16:01 +03:00
|
|
|
std::vector < const CGTownInstance *> CCallback::getTownsInfo(bool onlyOur) const
|
2008-02-18 23:14:28 +02:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2008-02-18 23:14:28 +02:00
|
|
|
std::vector < const CGTownInstance *> ret = std::vector < const CGTownInstance *>();
|
2008-07-25 20:28:28 +03:00
|
|
|
for ( std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
|
2008-02-18 23:14:28 +02:00
|
|
|
{
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t j=0; j < (*i).second.towns.size(); ++j)
|
2008-02-18 23:14:28 +02:00
|
|
|
{
|
2010-02-26 13:18:09 +02:00
|
|
|
if ((*i).first==player
|
|
|
|
|| (isVisible((*i).second.towns[j],player) && !onlyOur))
|
2008-02-18 23:14:28 +02:00
|
|
|
{
|
|
|
|
ret.push_back((*i).second.towns[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // for ( std::map<int, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
|
|
|
|
return ret;
|
|
|
|
}
|
2008-09-26 17:16:01 +03:00
|
|
|
std::vector < const CGHeroInstance *> CCallback::getHeroesInfo(bool onlyOur) const
|
2007-10-20 00:12:37 +03:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2008-08-02 00:41:38 +03:00
|
|
|
std::vector < const CGHeroInstance *> ret;
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t i=0;i<gs->map->heroes.size();i++)
|
2007-10-20 00:12:37 +03:00
|
|
|
{
|
2008-08-02 00:41:38 +03:00
|
|
|
if( (gs->map->heroes[i]->tempOwner==player) ||
|
|
|
|
(isVisible(gs->map->heroes[i]->getPosition(false),player) && !onlyOur) )
|
2007-10-20 00:12:37 +03:00
|
|
|
{
|
2008-08-02 00:41:38 +03:00
|
|
|
ret.push_back(gs->map->heroes[i]);
|
2007-10-20 00:12:37 +03:00
|
|
|
}
|
2008-08-02 00:41:38 +03:00
|
|
|
}
|
2007-10-20 00:12:37 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:16:01 +03:00
|
|
|
bool CCallback::isVisible(int3 pos) const
|
2007-10-20 00:12:37 +03:00
|
|
|
{
|
2008-08-20 22:02:48 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2007-10-20 00:12:37 +03:00
|
|
|
return isVisible(pos,player);
|
2007-10-24 22:54:35 +03:00
|
|
|
}
|
2007-11-19 00:58:28 +02:00
|
|
|
|
2009-07-20 05:56:35 +03:00
|
|
|
bool CCallback::isVisible( const CGObjectInstance *obj, int Player ) const
|
2008-08-30 00:41:32 +03:00
|
|
|
{
|
2009-07-30 15:49:45 +03:00
|
|
|
return gs->isVisible(obj, Player);
|
2008-08-30 00:41:32 +03:00
|
|
|
}
|
2009-07-30 15:49:45 +03:00
|
|
|
|
2008-09-26 17:16:01 +03:00
|
|
|
int CCallback::getMyColor() const
|
2007-12-01 14:50:33 +02:00
|
|
|
{
|
|
|
|
return player;
|
|
|
|
}
|
2009-07-30 15:49:45 +03:00
|
|
|
|
2008-09-26 17:16:01 +03:00
|
|
|
int CCallback::getHeroSerial(const CGHeroInstance * hero) const
|
2007-12-06 21:06:07 +02:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2008-12-21 21:17:35 +02:00
|
|
|
for (size_t i=0; i<gs->players[player].heroes.size();i++)
|
2007-12-06 21:06:07 +02:00
|
|
|
{
|
|
|
|
if (gs->players[player].heroes[i]==hero)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2009-07-30 15:49:45 +03:00
|
|
|
|
2008-09-26 17:16:01 +03:00
|
|
|
const CCreatureSet* CCallback::getGarrison(const CGObjectInstance *obj) const
|
2008-01-28 16:01:09 +02:00
|
|
|
{
|
2008-08-20 22:02:48 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2009-04-12 03:58:41 +03:00
|
|
|
const CArmedInstance *armi = dynamic_cast<const CArmedInstance*>(obj);
|
|
|
|
if(!armi)
|
2008-01-28 22:58:19 +02:00
|
|
|
return NULL;
|
2009-04-12 03:58:41 +03:00
|
|
|
else
|
2010-05-02 21:20:26 +03:00
|
|
|
return armi;
|
2008-01-28 16:01:09 +02:00
|
|
|
}
|
2008-01-26 21:36:31 +02:00
|
|
|
|
2009-04-12 03:58:41 +03:00
|
|
|
int CCallback::swapCreatures(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2)
|
2008-01-26 21:36:31 +02:00
|
|
|
{
|
2009-03-20 20:51:48 +02:00
|
|
|
ArrangeStacks pack(1,p1,p2,s1->id,s2->id,0);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-04-13 14:05:39 +03:00
|
|
|
return 0;
|
2008-01-26 21:36:31 +02:00
|
|
|
}
|
2008-01-27 18:07:27 +02:00
|
|
|
|
2009-04-12 03:58:41 +03:00
|
|
|
int CCallback::mergeStacks(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2)
|
|
|
|
{
|
2009-03-20 20:51:48 +02:00
|
|
|
ArrangeStacks pack(2,p1,p2,s1->id,s2->id,0);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-04-13 14:05:39 +03:00
|
|
|
return 0;
|
2008-01-30 00:47:43 +02:00
|
|
|
}
|
2009-04-12 03:58:41 +03:00
|
|
|
int CCallback::splitStack(const CArmedInstance *s1, const CArmedInstance *s2, int p1, int p2, int val)
|
2008-01-30 00:47:43 +02:00
|
|
|
{
|
2009-03-20 20:51:48 +02:00
|
|
|
ArrangeStacks pack(3,p1,p2,s1->id,s2->id,val);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-04-19 19:15:04 +03:00
|
|
|
return 0;
|
2008-01-30 00:47:43 +02:00
|
|
|
}
|
|
|
|
|
2008-01-27 18:07:27 +02:00
|
|
|
bool CCallback::dismissHero(const CGHeroInstance *hero)
|
|
|
|
{
|
2008-08-02 00:41:38 +03:00
|
|
|
if(player!=hero->tempOwner) return false;
|
2009-03-20 20:51:48 +02:00
|
|
|
|
|
|
|
DismissHero pack(hero->id);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-08-02 00:41:38 +03:00
|
|
|
return true;
|
2008-01-27 18:07:27 +02:00
|
|
|
}
|
|
|
|
|
2010-08-03 14:36:52 +03:00
|
|
|
// int CCallback::getMySerial() const
|
|
|
|
// {
|
|
|
|
// boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
// return gs->players[player].serial;
|
|
|
|
// }
|
2007-11-19 00:58:28 +02:00
|
|
|
|
2009-03-29 15:02:37 +03:00
|
|
|
bool CCallback::swapArtifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2)
|
2008-01-30 12:55:43 +02:00
|
|
|
{
|
2010-08-12 18:54:25 +03:00
|
|
|
if(player!=hero1->tempOwner && player!=hero2->tempOwner)
|
2008-01-30 12:55:43 +02:00
|
|
|
return false;
|
2009-03-29 15:02:37 +03:00
|
|
|
|
2009-04-04 01:34:31 +03:00
|
|
|
ExchangeArtifacts ea(hero1->id, hero2->id, pos1, pos2);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&ea);
|
2008-01-30 12:55:43 +02:00
|
|
|
return true;
|
|
|
|
}
|
2007-11-19 00:58:28 +02:00
|
|
|
|
2010-02-16 16:39:56 +02:00
|
|
|
/**
|
|
|
|
* Assembles or disassembles a combination artifact.
|
|
|
|
* @param hero Hero holding the artifact(s).
|
|
|
|
* @param artifactSlot The worn slot ID of the combination- or constituent artifact.
|
|
|
|
* @param assemble True for assembly operation, false for disassembly.
|
|
|
|
* @param assembleTo If assemble is true, this represents the artifact ID of the combination
|
|
|
|
* artifact to assemble to. Otherwise it's not used.
|
|
|
|
*/
|
|
|
|
bool CCallback::assembleArtifacts (const CGHeroInstance * hero, ui16 artifactSlot, bool assemble, ui32 assembleTo)
|
|
|
|
{
|
|
|
|
if (player != hero->tempOwner)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AssembleArtifacts aa(hero->id, artifactSlot, assemble, assembleTo);
|
|
|
|
sendRequest(&aa);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-01 14:21:15 +03:00
|
|
|
bool CCallback::buildBuilding(const CGTownInstance *town, si32 buildingID)
|
2008-03-21 02:03:31 +02:00
|
|
|
{
|
|
|
|
CGTownInstance * t = const_cast<CGTownInstance *>(town);
|
2008-05-03 18:30:11 +03:00
|
|
|
|
2008-08-01 14:21:15 +03:00
|
|
|
if(town->tempOwner!=player)
|
2008-03-23 03:01:17 +02:00
|
|
|
return false;
|
2010-12-20 23:22:53 +02:00
|
|
|
const CBuilding *b = CGI->buildh->buildings[t->subID][buildingID];
|
2009-08-05 12:46:55 +03:00
|
|
|
for(int i=0;i<b->resources.size();i++)
|
2008-08-01 14:21:15 +03:00
|
|
|
if(b->resources[i] > gs->players[player].resources[i])
|
|
|
|
return false; //lack of resources
|
|
|
|
|
2009-03-20 20:51:48 +02:00
|
|
|
BuildStructure pack(town->id,buildingID);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-03-21 02:03:31 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-22 22:14:40 +02:00
|
|
|
int CBattleCallback::battleGetBattlefieldType()
|
2008-03-10 22:19:41 +02:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2010-12-25 03:43:40 +02:00
|
|
|
//return gs->battleGetBattlefieldType();
|
|
|
|
|
|
|
|
if(!gs->curB)
|
|
|
|
{
|
|
|
|
tlog2<<"battleGetBattlefieldType called when there is no battle!"<<std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return gs->curB->battlefieldType;
|
2008-03-10 22:19:41 +02:00
|
|
|
}
|
|
|
|
|
2010-12-24 23:44:48 +02:00
|
|
|
int CBattleCallback::battleGetObstaclesAtTile(THex tile) //returns bitfield
|
2008-04-13 14:05:39 +03:00
|
|
|
{
|
|
|
|
//TODO - write
|
|
|
|
return -1;
|
|
|
|
}
|
2009-02-09 16:50:32 +02:00
|
|
|
|
2010-12-22 22:14:40 +02:00
|
|
|
std::vector<CObstacleInstance> CBattleCallback::battleGetAllObstacles()
|
2009-02-09 16:50:32 +02:00
|
|
|
{
|
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
if(gs->curB)
|
|
|
|
return gs->curB->obstacles;
|
|
|
|
else
|
|
|
|
return std::vector<CObstacleInstance>();
|
|
|
|
}
|
|
|
|
|
2010-12-22 22:14:40 +02:00
|
|
|
const CStack* CBattleCallback::battleGetStackByID(int ID, bool onlyAlive)
|
2008-04-07 20:51:46 +03:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
if(!gs->curB) return NULL;
|
2009-08-05 15:46:08 +03:00
|
|
|
return gs->curB->getStack(ID, onlyAlive);
|
2008-04-07 20:51:46 +03:00
|
|
|
}
|
|
|
|
|
2010-12-22 22:14:40 +02:00
|
|
|
int CBattleCallback::battleMakeAction(BattleAction* action)
|
2008-09-29 00:01:49 +03:00
|
|
|
{
|
2010-12-08 22:17:05 +02:00
|
|
|
assert(action->actionType == BattleAction::HERO_SPELL);
|
2009-03-20 20:51:48 +02:00
|
|
|
MakeCustomAction mca(*action);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&mca);
|
2008-09-29 00:01:49 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-07 12:48:31 +02:00
|
|
|
const CStack* CBattleCallback::battleGetStackByPos(THex pos, bool onlyAlive)
|
2008-06-11 04:58:18 +03:00
|
|
|
{
|
2008-08-20 22:02:48 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2011-01-07 12:48:31 +02:00
|
|
|
return gs->curB->battleGetStack(pos, onlyAlive);
|
2008-06-11 04:58:18 +03:00
|
|
|
}
|
|
|
|
|
2011-01-09 19:41:46 +02:00
|
|
|
THex CBattleCallback::battleGetPos(int stack)
|
2008-03-29 12:59:18 +02:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2009-02-14 15:49:30 +02:00
|
|
|
if(!gs->curB)
|
|
|
|
{
|
|
|
|
tlog2<<"battleGetPos called when there is no battle!"<<std::endl;
|
2011-01-09 19:41:46 +02:00
|
|
|
return THex::INVALID;
|
2009-02-14 15:49:30 +02:00
|
|
|
}
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t g=0; g<gs->curB->stacks.size(); ++g)
|
2008-03-29 12:59:18 +02:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
if(gs->curB->stacks[g]->ID == stack)
|
|
|
|
return gs->curB->stacks[g]->position;
|
2008-03-29 12:59:18 +02:00
|
|
|
}
|
2011-01-09 19:41:46 +02:00
|
|
|
return THex::INVALID;
|
2008-04-07 20:51:46 +03:00
|
|
|
}
|
|
|
|
|
2011-01-08 20:33:40 +02:00
|
|
|
std::vector<const CStack*> CBattleCallback::battleGetStacks(bool onlyAlive /*= true*/)
|
2008-03-14 20:24:37 +02:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2010-12-06 01:10:02 +02:00
|
|
|
std::vector<const CStack*> ret;
|
2008-09-05 19:08:25 +03:00
|
|
|
if(!gs->curB) //there is no battle
|
|
|
|
{
|
2010-12-06 01:10:02 +02:00
|
|
|
tlog2<<"battleGetStacks called when there is no battle!"<<std::endl;
|
2008-09-05 19:08:25 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-06 01:10:02 +02:00
|
|
|
BOOST_FOREACH(const CStack *s, gs->curB->stacks)
|
2011-01-08 20:33:40 +02:00
|
|
|
if(s->alive() || !onlyAlive)
|
|
|
|
ret.push_back(s);
|
2010-12-06 01:10:02 +02:00
|
|
|
|
2008-03-14 20:24:37 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-22 22:14:40 +02:00
|
|
|
void CBattleCallback::getStackQueue( std::vector<const CStack *> &out, int howMany )
|
2008-12-20 19:08:51 +02:00
|
|
|
{
|
2009-02-14 15:49:30 +02:00
|
|
|
if(!gs->curB)
|
|
|
|
{
|
2009-09-07 05:29:44 +03:00
|
|
|
tlog2 << "battleGetStackQueue called when there is not battle!" << std::endl;
|
|
|
|
return;
|
2009-02-14 15:49:30 +02:00
|
|
|
}
|
2009-09-07 05:29:44 +03:00
|
|
|
gs->curB->getStackQueue(out, howMany);
|
2008-12-20 19:08:51 +02:00
|
|
|
}
|
|
|
|
|
2011-01-07 12:48:31 +02:00
|
|
|
std::vector<THex> CBattleCallback::battleGetAvailableHexes(const CStack * stack, bool addOccupiable)
|
2008-03-29 12:59:18 +02:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2009-02-14 15:49:30 +02:00
|
|
|
if(!gs->curB)
|
|
|
|
{
|
|
|
|
tlog2<<"battleGetAvailableHexes called when there is no battle!"<<std::endl;
|
2011-01-07 12:48:31 +02:00
|
|
|
return std::vector<THex>();
|
2009-02-14 15:49:30 +02:00
|
|
|
}
|
2011-01-07 12:48:31 +02:00
|
|
|
return gs->curB->getAccessibility(stack, addOccupiable);
|
2008-08-06 02:33:08 +03:00
|
|
|
//return gs->battleGetRange(ID);
|
2008-03-29 12:59:18 +02:00
|
|
|
}
|
|
|
|
|
2011-01-07 12:48:31 +02:00
|
|
|
bool CBattleCallback::battleCanShoot(const CStack * stack, THex dest)
|
2008-08-02 18:08:03 +03:00
|
|
|
{
|
2009-02-14 15:49:30 +02:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2008-11-17 20:47:43 +02:00
|
|
|
|
2009-09-04 17:11:42 +03:00
|
|
|
if(!gs->curB) return false;
|
2009-08-21 22:31:41 +03:00
|
|
|
|
2011-01-07 12:48:31 +02:00
|
|
|
return gs->curB->battleCanShoot(stack, dest);
|
2008-08-02 18:08:03 +03:00
|
|
|
}
|
2008-08-16 11:47:41 +03:00
|
|
|
|
2010-12-22 22:14:40 +02:00
|
|
|
bool CBattleCallback::battleCanCastSpell()
|
2009-04-16 17:01:27 +03:00
|
|
|
{
|
|
|
|
if(!gs->curB) //there is no battle
|
|
|
|
return false;
|
|
|
|
|
2011-01-09 19:41:46 +02:00
|
|
|
if(gs->curB->sides[0] == player)
|
2010-08-19 14:03:33 +03:00
|
|
|
return gs->curB->castSpells[0] == 0 && gs->curB->heroes[0] && gs->curB->heroes[0]->getArt(17);
|
2009-04-16 17:01:27 +03:00
|
|
|
else
|
2010-08-19 14:03:33 +03:00
|
|
|
return gs->curB->castSpells[1] == 0 && gs->curB->heroes[1] && gs->curB->heroes[1]->getArt(17);
|
2009-04-16 17:01:27 +03:00
|
|
|
}
|
|
|
|
|
2010-12-22 22:14:40 +02:00
|
|
|
bool CBattleCallback::battleCanFlee()
|
2009-08-16 16:44:17 +03:00
|
|
|
{
|
2011-01-07 12:48:31 +02:00
|
|
|
return gs->curB->battleCanFlee(player);
|
2009-08-16 16:44:17 +03:00
|
|
|
}
|
|
|
|
|
2010-12-22 22:14:40 +02:00
|
|
|
const CGTownInstance *CBattleCallback::battleGetDefendedTown()
|
2009-08-24 15:55:05 +03:00
|
|
|
{
|
2011-01-07 12:48:31 +02:00
|
|
|
if(!gs->curB || gs->curB->town == NULL)
|
2009-08-24 15:55:05 +03:00
|
|
|
return NULL;
|
|
|
|
|
2011-01-07 12:48:31 +02:00
|
|
|
return gs->curB->town;
|
2009-08-24 15:55:05 +03:00
|
|
|
}
|
|
|
|
|
2010-12-22 22:14:40 +02:00
|
|
|
ui8 CBattleCallback::battleGetWallState(int partOfWall)
|
2009-08-26 17:09:55 +03:00
|
|
|
{
|
|
|
|
if(!gs->curB || gs->curB->siege == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return gs->curB->si.wallState[partOfWall];
|
|
|
|
}
|
|
|
|
|
2011-01-09 19:41:46 +02:00
|
|
|
int CBattleCallback::battleGetWallUnderHex(THex hex)
|
2009-09-01 16:54:13 +03:00
|
|
|
{
|
|
|
|
if(!gs->curB || gs->curB->siege == 0)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return gs->curB->hexToWallPart(hex);
|
|
|
|
}
|
|
|
|
|
2011-01-08 20:33:40 +02:00
|
|
|
TDmgRange CBattleCallback::battleEstimateDamage(const CStack * attacker, const CStack * defender, TDmgRange * retaliationDmg)
|
2009-08-29 20:09:07 +03:00
|
|
|
{
|
|
|
|
if(!gs->curB)
|
|
|
|
return std::make_pair(0, 0);
|
|
|
|
|
|
|
|
const CGHeroInstance * attackerHero, * defenderHero;
|
2011-01-08 20:33:40 +02:00
|
|
|
bool shooting = battleCanShoot(attacker, defender->position);
|
2009-08-29 20:09:07 +03:00
|
|
|
|
2011-01-09 19:41:46 +02:00
|
|
|
if(gs->curB->sides[0] == player)
|
2009-08-29 20:09:07 +03:00
|
|
|
{
|
2009-10-06 03:32:33 +03:00
|
|
|
attackerHero = gs->curB->heroes[0];
|
|
|
|
defenderHero = gs->curB->heroes[1];
|
2009-08-29 20:09:07 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-06 03:32:33 +03:00
|
|
|
attackerHero = gs->curB->heroes[1];
|
|
|
|
defenderHero = gs->curB->heroes[0];
|
2009-08-29 20:09:07 +03:00
|
|
|
}
|
|
|
|
|
2011-01-08 20:33:40 +02:00
|
|
|
TDmgRange ret = gs->curB->calculateDmgRange(attacker, defender, attackerHero, defenderHero, shooting, 0, false);
|
2009-08-29 20:09:07 +03:00
|
|
|
|
2011-01-08 20:33:40 +02:00
|
|
|
if(retaliationDmg)
|
|
|
|
{
|
|
|
|
if(shooting)
|
|
|
|
{
|
|
|
|
retaliationDmg->first = retaliationDmg->second = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui32 TDmgRange::* pairElems[] = {&TDmgRange::first, &TDmgRange::second};
|
|
|
|
for (int i=0; i<2; ++i)
|
|
|
|
{
|
|
|
|
BattleStackAttacked bsa;
|
|
|
|
bsa.damageAmount = ret.*pairElems[i];
|
|
|
|
retaliationDmg->*pairElems[!i] = gs->curB->calculateDmgRange(defender, attacker, bsa.newAmount, attacker->count, attackerHero, defenderHero, false, false, false).*pairElems[!i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2009-08-29 20:09:07 +03:00
|
|
|
}
|
|
|
|
|
2010-12-22 22:14:40 +02:00
|
|
|
ui8 CBattleCallback::battleGetSiegeLevel()
|
2009-09-02 17:10:19 +03:00
|
|
|
{
|
|
|
|
if(!gs->curB)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return gs->curB->siege;
|
|
|
|
}
|
|
|
|
|
2010-12-22 22:14:40 +02:00
|
|
|
const CGHeroInstance * CBattleCallback::battleGetFightingHero(ui8 side) const
|
2009-11-08 16:44:58 +02:00
|
|
|
{
|
|
|
|
if(!gs->curB)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return gs->curB->heroes[side];
|
|
|
|
}
|
|
|
|
|
2010-12-22 22:14:40 +02:00
|
|
|
template <typename T>
|
|
|
|
void CBattleCallback::sendRequest(const T* request)
|
|
|
|
{
|
|
|
|
//TODO? should be part of CClient but it would have to be very tricky cause template/serialization issues
|
|
|
|
if(waitTillRealize)
|
|
|
|
cl->waitingRequest.set(true);
|
|
|
|
|
|
|
|
*cl->serv << request;
|
|
|
|
|
|
|
|
if(waitTillRealize)
|
|
|
|
cl->waitingRequest.waitWhileTrue();
|
|
|
|
}
|
|
|
|
|
2008-08-16 11:47:41 +03:00
|
|
|
void CCallback::swapGarrisonHero( const CGTownInstance *town )
|
|
|
|
{
|
|
|
|
if(town->tempOwner != player) return;
|
2009-03-20 20:51:48 +02:00
|
|
|
|
|
|
|
GarrisonHeroSwap pack(town->id);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-08-25 13:25:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCallback::buyArtifact(const CGHeroInstance *hero, int aid)
|
|
|
|
{
|
|
|
|
if(hero->tempOwner != player) return;
|
2009-03-20 20:51:48 +02:00
|
|
|
|
|
|
|
BuyArtifact pack(hero->id,aid);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-08-28 20:36:34 +03:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:16:01 +03:00
|
|
|
std::vector < const CGObjectInstance * > CCallback::getBlockingObjs( int3 pos ) const
|
2008-08-28 20:36:34 +03:00
|
|
|
{
|
|
|
|
std::vector<const CGObjectInstance *> ret;
|
2008-08-30 00:41:32 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2009-02-01 16:11:41 +02:00
|
|
|
if(!gs->map->isInTheMap(pos) || !isVisible(pos))
|
|
|
|
return ret;
|
2008-08-28 20:36:34 +03:00
|
|
|
BOOST_FOREACH(const CGObjectInstance * obj, gs->map->terrain[pos.x][pos.y][pos.z].blockingObjects)
|
|
|
|
ret.push_back(obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-09-26 17:16:01 +03:00
|
|
|
std::vector < const CGObjectInstance * > CCallback::getVisitableObjs( int3 pos ) const
|
2008-08-28 20:36:34 +03:00
|
|
|
{
|
|
|
|
std::vector<const CGObjectInstance *> ret;
|
2008-08-30 00:41:32 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2009-02-01 16:11:41 +02:00
|
|
|
if(!gs->map->isInTheMap(pos) || !isVisible(pos))
|
|
|
|
return ret;
|
2008-08-28 20:36:34 +03:00
|
|
|
BOOST_FOREACH(const CGObjectInstance * obj, gs->map->terrain[pos.x][pos.y][pos.z].visitableObjects)
|
|
|
|
ret.push_back(obj);
|
|
|
|
return ret;
|
2008-09-07 06:38:37 +03:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:16:01 +03:00
|
|
|
std::vector < const CGObjectInstance * > CCallback::getFlaggableObjects(int3 pos) const
|
|
|
|
{
|
2009-02-01 16:11:41 +02:00
|
|
|
if(!isVisible(pos))
|
2008-09-26 17:16:01 +03:00
|
|
|
return std::vector < const CGObjectInstance * >();
|
|
|
|
|
|
|
|
std::vector < const CGObjectInstance * > ret;
|
|
|
|
|
2010-12-17 20:47:07 +02:00
|
|
|
const std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > & objs = CGI->mh->ttiles[pos.x][pos.y][pos.z].objects;
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t b=0; b<objs.size(); ++b)
|
2008-09-26 17:16:01 +03:00
|
|
|
{
|
|
|
|
if(objs[b].first->tempOwner!=254 && !((objs[b].first->defInfo->blockMap[pos.y - objs[b].first->pos.y + 5] >> (objs[b].first->pos.x - pos.x)) & 1))
|
|
|
|
ret.push_back(CGI->mh->ttiles[pos.x][pos.y][pos.z].objects[b].first);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int3 CCallback::getMapSize() const
|
|
|
|
{
|
|
|
|
return CGI->mh->sizes;
|
|
|
|
}
|
|
|
|
|
2010-05-18 10:01:54 +03:00
|
|
|
void CCallback::trade(const CGObjectInstance *market, int mode, int id1, int id2, int val1, const CGHeroInstance *hero/* = NULL*/)
|
2008-09-07 06:38:37 +03:00
|
|
|
{
|
2010-05-18 10:01:54 +03:00
|
|
|
TradeOnMarketplace pack;
|
|
|
|
pack.market = market;
|
|
|
|
pack.hero = hero;
|
|
|
|
pack.mode = mode;
|
|
|
|
pack.r1 = id1;
|
|
|
|
pack.r2 = id2;
|
|
|
|
pack.val = val1;
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-09-18 16:54:54 +03:00
|
|
|
}
|
|
|
|
|
2008-09-19 11:16:19 +03:00
|
|
|
void CCallback::setFormation(const CGHeroInstance * hero, bool tight)
|
2008-09-18 16:54:54 +03:00
|
|
|
{
|
2010-05-02 21:20:26 +03:00
|
|
|
const_cast<CGHeroInstance*>(hero)-> formation = tight;
|
2009-03-20 20:51:48 +02:00
|
|
|
SetFormation pack(hero->id,tight);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2008-10-19 02:20:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCallback::setSelection(const CArmedInstance * obj)
|
|
|
|
{
|
2008-12-27 03:01:59 +02:00
|
|
|
SetSelection ss;
|
|
|
|
ss.player = player;
|
|
|
|
ss.id = obj->id;
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&ss);
|
2009-09-13 01:17:23 +03:00
|
|
|
|
|
|
|
if(obj->ID == HEROI_TYPE)
|
|
|
|
{
|
|
|
|
cl->gs->calculatePaths(static_cast<const CGHeroInstance *>(obj), *cl->pathInfo);
|
|
|
|
//nasty workaround. TODO: nice workaround
|
|
|
|
cl->gs->getPlayer(player)->currentSelection = obj->id;
|
|
|
|
}
|
2008-10-26 22:58:34 +02:00
|
|
|
}
|
|
|
|
|
2010-07-09 02:03:27 +03:00
|
|
|
void CCallback::recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero)
|
2008-10-26 22:58:34 +02:00
|
|
|
{
|
|
|
|
ui8 i=0;
|
2009-03-09 12:37:49 +02:00
|
|
|
for(; i<gs->players[player].availableHeroes.size(); i++)
|
|
|
|
{
|
2008-10-26 22:58:34 +02:00
|
|
|
if(gs->players[player].availableHeroes[i] == hero)
|
2009-03-09 12:37:49 +02:00
|
|
|
{
|
2010-07-09 02:03:27 +03:00
|
|
|
HireHero pack(i,townOrTavern->id);
|
|
|
|
pack.player = player;
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pack);
|
2009-03-09 12:37:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-10-26 22:58:34 +02:00
|
|
|
}
|
|
|
|
|
2010-07-09 02:03:27 +03:00
|
|
|
std::vector<const CGHeroInstance *> CCallback::getAvailableHeroes(const CGObjectInstance * townOrTavern) const
|
2008-10-26 22:58:34 +02:00
|
|
|
{
|
|
|
|
std::vector<const CGHeroInstance *> ret(gs->players[player].availableHeroes.size());
|
|
|
|
std::copy(gs->players[player].availableHeroes.begin(),gs->players[player].availableHeroes.end(),ret.begin());
|
|
|
|
return ret;
|
2009-02-20 17:44:49 +02:00
|
|
|
}
|
|
|
|
|
2009-03-13 16:16:53 +02:00
|
|
|
const TerrainTile * CCallback::getTileInfo( int3 tile ) const
|
2009-02-20 17:44:49 +02:00
|
|
|
{
|
2009-05-22 22:20:30 +03:00
|
|
|
if(!gs->map->isInTheMap(tile))
|
|
|
|
{
|
|
|
|
tlog1 << tile << "is outside the map! (call to getTileInfo)\n";
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-03-13 16:16:53 +02:00
|
|
|
if(!isVisible(tile, player)) return NULL;
|
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2009-02-20 17:44:49 +02:00
|
|
|
return &gs->map->getTile(tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCallback::canBuildStructure( const CGTownInstance *t, int ID )
|
|
|
|
{
|
|
|
|
return gs->canBuildStructure(t,ID);
|
2009-12-30 09:49:25 +02:00
|
|
|
}
|
|
|
|
|
2009-12-29 15:40:16 +02:00
|
|
|
std::set<int> CCallback::getBuildingRequiments( const CGTownInstance *t, int ID )
|
|
|
|
{
|
|
|
|
return gs->getBuildingRequiments(t,ID);
|
2009-03-19 16:17:19 +02:00
|
|
|
}
|
|
|
|
|
2009-06-11 20:21:06 +03:00
|
|
|
bool CCallback::getPath(int3 src, int3 dest, const CGHeroInstance * hero, CPath &ret)
|
2009-03-19 16:17:19 +02:00
|
|
|
{
|
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2009-06-11 20:21:06 +03:00
|
|
|
return gs->getPath(src,dest,hero, ret);
|
2009-03-28 02:38:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCallback::save( const std::string &fname )
|
|
|
|
{
|
|
|
|
cl->save(fname);
|
2009-04-04 22:26:41 +03:00
|
|
|
}
|
|
|
|
|
2009-04-05 17:37:14 +03:00
|
|
|
|
|
|
|
void CCallback::sendMessage(const std::string &mess)
|
|
|
|
{
|
|
|
|
PlayerMessage pm(player, mess);
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&pm);
|
2009-05-12 06:35:51 +03:00
|
|
|
}
|
2009-07-20 04:47:49 +03:00
|
|
|
|
2009-07-26 06:33:13 +03:00
|
|
|
void CCallback::buildBoat( const IShipyard *obj )
|
|
|
|
{
|
|
|
|
BuildBoat bb;
|
|
|
|
bb.objid = obj->o->id;
|
2009-08-04 02:53:18 +03:00
|
|
|
sendRequest(&bb);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCallback::CCallback( CGameState * GS, int Player, CClient *C )
|
2010-12-22 22:14:40 +02:00
|
|
|
:CBattleCallback(GS, Player, C)
|
2009-08-04 02:53:18 +03:00
|
|
|
{
|
|
|
|
waitTillRealize = false;
|
2009-07-26 06:33:13 +03:00
|
|
|
}
|
|
|
|
|
2009-08-27 11:04:32 +03:00
|
|
|
const CMapHeader * CCallback::getMapHeader() const
|
|
|
|
{
|
|
|
|
return gs->map;
|
|
|
|
}
|
|
|
|
|
2009-08-30 15:47:40 +03:00
|
|
|
const CGPathNode * CCallback::getPathInfo( int3 tile )
|
|
|
|
{
|
|
|
|
return &cl->pathInfo->nodes[tile.x][tile.y][tile.z];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCallback::getPath2( int3 dest, CGPath &ret )
|
|
|
|
{
|
2009-10-23 05:11:45 +03:00
|
|
|
if (!gs->map->isInTheMap(dest))
|
|
|
|
return false;
|
|
|
|
|
2009-09-07 05:29:44 +03:00
|
|
|
const CGHeroInstance *h = cl->IGameCallback::getSelectedHero(player);
|
|
|
|
assert(cl->pathInfo->hero == h);
|
|
|
|
if(cl->pathInfo->hpos != h->getPosition(false)) //hero position changed, must update paths
|
|
|
|
{
|
|
|
|
recalculatePaths();
|
|
|
|
}
|
2009-08-30 15:47:40 +03:00
|
|
|
return cl->pathInfo->getPath(dest, ret);
|
|
|
|
}
|
|
|
|
|
2009-09-07 05:29:44 +03:00
|
|
|
void CCallback::recalculatePaths()
|
|
|
|
{
|
|
|
|
gs->calculatePaths(cl->IGameCallback::getSelectedHero(player), *cl->pathInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCallback::calculatePaths( const CGHeroInstance *hero, CPathsInfo &out, int3 src /*= int3(-1,-1,-1)*/, int movement /*= -1*/ )
|
|
|
|
{
|
|
|
|
gs->calculatePaths(hero, out, src, movement);
|
|
|
|
}
|
|
|
|
|
2010-02-10 04:56:00 +02:00
|
|
|
int3 CCallback::getGrailPos( float &outKnownRatio )
|
|
|
|
{
|
2010-02-18 16:09:16 +02:00
|
|
|
if (CGObelisk::obeliskCount == 0)
|
|
|
|
{
|
|
|
|
outKnownRatio = 0.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-06 16:14:10 +03:00
|
|
|
outKnownRatio = (float)CGObelisk::visited[gs->getPlayerTeam(player)->id] / CGObelisk::obeliskCount;
|
2010-02-18 16:09:16 +02:00
|
|
|
}
|
2010-02-10 04:56:00 +02:00
|
|
|
return gs->map->grailPos;
|
|
|
|
}
|
|
|
|
|
2010-02-21 17:03:30 +02:00
|
|
|
void CCallback::dig( const CGObjectInstance *hero )
|
|
|
|
{
|
|
|
|
DigWithHero dwh;
|
|
|
|
dwh.id = hero->id;
|
|
|
|
sendRequest(&dwh);
|
|
|
|
}
|
|
|
|
|
2010-03-11 01:16:30 +02:00
|
|
|
void CCallback::castSpell(const CGHeroInstance *hero, int spellID, const int3 &pos)
|
|
|
|
{
|
|
|
|
CastAdvSpell cas;
|
|
|
|
cas.hid = hero->id;
|
|
|
|
cas.sid = spellID;
|
|
|
|
cas.pos = pos;
|
|
|
|
sendRequest(&cas);
|
|
|
|
}
|
|
|
|
|
2010-03-21 00:17:19 +02:00
|
|
|
bool CCallback::hasAccess(int playerId) const
|
|
|
|
{
|
2010-08-13 13:46:08 +03:00
|
|
|
return gs->getPlayerRelations( playerId, player ) || player < 0;
|
2010-03-21 00:17:19 +02:00
|
|
|
}
|
|
|
|
|
2011-01-07 12:48:31 +02:00
|
|
|
si8 CBattleCallback::battleHasDistancePenalty( const CStack * stack, THex destHex )
|
2010-04-06 16:19:54 +03:00
|
|
|
{
|
2011-01-07 12:48:31 +02:00
|
|
|
return gs->curB->hasDistancePenalty(stack, destHex);
|
2010-04-06 16:19:54 +03:00
|
|
|
}
|
|
|
|
|
2011-01-07 12:48:31 +02:00
|
|
|
si8 CBattleCallback::battleHasWallPenalty( const CStack * stack, THex destHex )
|
2010-04-06 16:19:54 +03:00
|
|
|
{
|
2011-01-07 12:48:31 +02:00
|
|
|
return gs->curB->hasWallPenalty(stack, destHex);
|
2010-04-06 16:19:54 +03:00
|
|
|
}
|
|
|
|
|
2011-01-07 12:48:31 +02:00
|
|
|
si8 CBattleCallback::battleCanTeleportTo(const CStack * stack, THex destHex, int telportLevel)
|
2010-05-07 17:05:48 +03:00
|
|
|
{
|
2011-01-07 12:48:31 +02:00
|
|
|
return gs->curB->canTeleportTo(stack, destHex, telportLevel);
|
2010-05-07 17:05:48 +03:00
|
|
|
}
|
|
|
|
|
2010-05-08 01:10:32 +03:00
|
|
|
int CCallback::getPlayerStatus(int player) const
|
|
|
|
{
|
|
|
|
const PlayerState *ps = gs->getPlayer(player, false);
|
|
|
|
if(!ps)
|
|
|
|
return -1;
|
|
|
|
return ps->status;
|
|
|
|
}
|
2010-07-09 02:03:27 +03:00
|
|
|
|
|
|
|
std::string CCallback::getTavernGossip(const CGObjectInstance * townOrTavern) const
|
|
|
|
{
|
|
|
|
return "GOSSIP TEST";
|
|
|
|
}
|
|
|
|
|
2010-08-16 12:54:09 +03:00
|
|
|
std::vector < const CGObjectInstance * > CCallback::getMyObjects() const
|
|
|
|
{
|
|
|
|
std::vector < const CGObjectInstance * > ret;
|
|
|
|
for (int g=0; g<gs->map->objects.size(); ++g)
|
|
|
|
{
|
|
|
|
if (gs->map->objects[g]->tempOwner == LOCPLINT->playerID)
|
|
|
|
{
|
|
|
|
ret.push_back(gs->map->objects[g]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector < const CGDwelling * > CCallback::getMyDwellings() const
|
|
|
|
{
|
|
|
|
std::vector < const CGDwelling * > ret;
|
|
|
|
BOOST_FOREACH(CGDwelling * dw, gs->getPlayer(player)->dwellings)
|
|
|
|
{
|
|
|
|
ret.push_back(dw);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCallback::getPlayerRelations( ui8 color1, ui8 color2 ) const
|
|
|
|
{
|
|
|
|
return gs->getPlayerRelations(color1, color2);
|
|
|
|
}
|
|
|
|
|
2009-07-20 05:56:35 +03:00
|
|
|
InfoAboutTown::InfoAboutTown()
|
|
|
|
{
|
|
|
|
tType = NULL;
|
|
|
|
details = NULL;
|
|
|
|
fortLevel = 0;
|
|
|
|
owner = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
InfoAboutTown::~InfoAboutTown()
|
|
|
|
{
|
|
|
|
delete details;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InfoAboutTown::initFromTown( const CGTownInstance *t, bool detailed )
|
|
|
|
{
|
2009-10-25 21:32:02 +02:00
|
|
|
obj = t;
|
2010-12-06 01:10:02 +02:00
|
|
|
army = ArmyDescriptor(t, detailed);
|
2009-07-20 05:56:35 +03:00
|
|
|
built = t->builded;
|
|
|
|
fortLevel = t->fortLevel();
|
|
|
|
name = t->name;
|
|
|
|
tType = t->town;
|
|
|
|
owner = t->tempOwner;
|
|
|
|
|
|
|
|
if(detailed)
|
|
|
|
{
|
|
|
|
//include details about hero
|
|
|
|
details = new Details;
|
|
|
|
details->goldIncome = t->dailyIncome();
|
|
|
|
details->customRes = vstd::contains(t->builtBuildings, 15);
|
|
|
|
details->hallLevel = t->hallLevel();
|
|
|
|
details->garrisonedHero = t->garrisonHero;
|
|
|
|
}
|
2010-12-06 01:10:02 +02:00
|
|
|
//TODO: adjust undetailed info about army to our count of thieves guilds
|
2009-10-23 05:11:45 +03:00
|
|
|
}
|
2010-03-21 00:17:19 +02:00
|
|
|
|
|
|
|
void InfoAboutTown::initFromGarrison(const CGGarrison *garr, bool detailed)
|
|
|
|
{
|
|
|
|
obj = garr;
|
|
|
|
fortLevel = 0;
|
2010-12-06 01:10:02 +02:00
|
|
|
army = ArmyDescriptor(garr, detailed);
|
2010-03-21 00:17:19 +02:00
|
|
|
name = CGI->generaltexth->names[33]; // "Garrison"
|
|
|
|
owner = garr->tempOwner;
|
|
|
|
built = false;
|
|
|
|
tType = NULL;
|
|
|
|
|
|
|
|
// Show detailed info only to owning player.
|
|
|
|
if(detailed)
|
|
|
|
{
|
|
|
|
details = new InfoAboutTown::Details;
|
|
|
|
details->customRes = false;
|
|
|
|
details->garrisonedHero = false;
|
|
|
|
details->goldIncome = -1;
|
|
|
|
details->hallLevel = -1;
|
|
|
|
}
|
2010-12-22 22:14:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CBattleCallback::hasAccess( int playerId ) const
|
|
|
|
{
|
|
|
|
return playerId == player || player < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CBattleCallback::CBattleCallback(CGameState *GS, int Player, CClient *C )
|
|
|
|
{
|
|
|
|
gs = GS;
|
|
|
|
player = Player;
|
|
|
|
cl = C;
|
2011-01-08 20:33:40 +02:00
|
|
|
}
|
|
|
|
|
2011-01-09 19:41:46 +02:00
|
|
|
std::vector<int> CBattleCallback::battleGetDistances(const CStack * stack, THex hex /*= THex::INVALID*/, THex * predecessors /*= NULL*/)
|
2011-01-08 20:33:40 +02:00
|
|
|
{
|
|
|
|
if(!hex.isValid())
|
|
|
|
hex = stack->position;
|
|
|
|
|
|
|
|
std::vector<int> ret;
|
|
|
|
bool ac[BFIELD_SIZE];
|
2011-01-09 19:41:46 +02:00
|
|
|
THex pr[BFIELD_SIZE];
|
|
|
|
int dist[BFIELD_SIZE];
|
2011-01-08 20:33:40 +02:00
|
|
|
gs->curB->makeBFS(stack->position, ac, pr, dist, stack->doubleWide(), stack->attackerOwned, stack->hasBonusOfType(Bonus::FLYING), false);
|
|
|
|
|
|
|
|
for(int i=0; i<BFIELD_SIZE; ++i)
|
|
|
|
{
|
|
|
|
if(pr[i] == -1)
|
|
|
|
ret.push_back(-1);
|
|
|
|
else
|
|
|
|
ret.push_back(dist[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(predecessors)
|
|
|
|
{
|
2011-01-09 19:41:46 +02:00
|
|
|
memcpy(predecessors, pr, BFIELD_SIZE * sizeof(THex));
|
2011-01-08 20:33:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-02-10 16:44:21 +02:00
|
|
|
CBattleCallback::ESpellCastProblem CBattleCallback::battleCanCastThisSpell( const CSpell * spell )
|
|
|
|
{
|
|
|
|
if(!battleCanCastSpell())
|
|
|
|
return GENERAL_CASTING_PROBLEM;
|
|
|
|
|
|
|
|
int spellIDs[] = {66, 67, 68, 69}; //IDs of summon elemental spells (fire, earth, water, air)
|
|
|
|
int creIDs[] = {114, 113, 115, 112}; //(fire, earth, water, air)
|
|
|
|
|
|
|
|
int * idp = std::find(spellIDs, spellIDs + ARRAY_COUNT(spellIDs), spell->id);
|
|
|
|
int arpos = idp - spellIDs;
|
|
|
|
if(arpos < ARRAY_COUNT(spellIDs))
|
|
|
|
{
|
|
|
|
//check if there are summoned elementals of other type
|
|
|
|
BOOST_FOREACH ( const CStack * st, gs->curB->stacks)
|
|
|
|
{
|
|
|
|
if (vstd::contains(st->state, SUMMONED) && st->getCreature()->idNumber != creIDs[arpos])
|
|
|
|
{
|
|
|
|
return ANOTHER_ELEMENTAL_SUMMONED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
2011-02-12 18:12:48 +02:00
|
|
|
|
|
|
|
si8 CBattleCallback::battleGetTacticDist()
|
|
|
|
{
|
|
|
|
if (!gs->curB)
|
|
|
|
{
|
|
|
|
tlog1 << "battleGetTacticDist called when no battle!\n";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gs->curB->sides[gs->curB->tacticsSide] == player)
|
|
|
|
{
|
|
|
|
return gs->curB->tacticDistance;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui8 CBattleCallback::battleGetMySide()
|
|
|
|
{
|
|
|
|
if (!gs->curB)
|
|
|
|
{
|
|
|
|
tlog1 << "battleGetMySide called when no battle!\n";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gs->curB->sides[1] == player;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CBattleCallback::battleMakeTacticAction( BattleAction * action )
|
|
|
|
{
|
|
|
|
MakeAction ma;
|
|
|
|
ma.ba = *action;
|
|
|
|
sendRequest(&ma);
|
|
|
|
return true;
|
|
|
|
}
|