2007-08-27 17:15:03 +03:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "CCallback.h"
|
2009-05-20 13:08:56 +03:00
|
|
|
#include "client/CGameInfo.h"
|
|
|
|
#include "lib/CGameState.h"
|
|
|
|
#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"
|
2008-03-21 02:03:31 +02:00
|
|
|
#include "hch/CBuildingHandler.h"
|
2008-08-30 00:41:32 +03:00
|
|
|
#include "hch/CDefObjInfoHandler.h"
|
|
|
|
#include "hch/CHeroHandler.h"
|
2008-07-02 11:39:56 +03:00
|
|
|
#include "hch/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"
|
2008-08-30 00:41:32 +03:00
|
|
|
#include "mapHandler.h"
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include <boost/thread.hpp>
|
2008-08-05 02:04:15 +03:00
|
|
|
#include <boost/thread/shared_mutex.hpp>
|
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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-09-07 06:38:37 +03:00
|
|
|
int gcd(int x, int y)
|
|
|
|
{
|
|
|
|
int temp;
|
|
|
|
if (y > x)
|
2008-11-15 15:44:32 +02:00
|
|
|
std::swap(x,y);
|
2008-09-07 06:38:37 +03:00
|
|
|
while (y != 0)
|
|
|
|
{
|
|
|
|
temp = y;
|
|
|
|
y = x-y;
|
|
|
|
x = temp;
|
|
|
|
if (y > x)
|
2008-11-15 15:44:32 +02:00
|
|
|
std::swap(x,y);
|
2008-09-07 06:38:37 +03:00
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
2008-07-28 15:44:08 +03:00
|
|
|
HeroMoveDetails::HeroMoveDetails(int3 Src, int3 Dst, CGHeroInstance*Ho)
|
|
|
|
:src(Src),dst(Dst),ho(Ho)
|
|
|
|
{
|
|
|
|
owner = ho->getOwner();
|
|
|
|
};
|
2009-03-07 00:11:17 +02:00
|
|
|
|
|
|
|
template <ui16 N> bool isType(CPack *pack)
|
|
|
|
{
|
|
|
|
return pack->getType() == N;
|
|
|
|
}
|
|
|
|
|
2009-03-12 20:50:36 +02:00
|
|
|
bool CCallback::moveHero(const CGHeroInstance *h, int3 dst) const
|
|
|
|
{
|
2009-03-20 20:51:48 +02:00
|
|
|
MoveHero pack(dst,h->id);
|
|
|
|
*cl->serv << &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
|
|
|
}
|
2008-08-10 07:46:16 +03:00
|
|
|
void CCallback::recruitCreatures(const CGObjectInstance *obj, ui32 ID, ui32 amount)
|
2008-04-11 20:41:02 +03:00
|
|
|
{
|
2008-08-10 07:46:16 +03:00
|
|
|
if(player!=obj->tempOwner) return;
|
2009-03-20 20:51:48 +02:00
|
|
|
|
|
|
|
RecruitCreatures pack(obj->id,ID,amount);
|
|
|
|
*cl->serv << &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)
|
|
|
|
{
|
2009-04-14 17:19:46 +03:00
|
|
|
if(((player>=0) && obj->tempOwner != player) || (obj->army.slots.size()<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);
|
|
|
|
*cl->serv << &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);
|
|
|
|
*cl->serv << &pack;
|
2008-05-23 22:50:11 +03:00
|
|
|
return false;
|
|
|
|
}
|
2008-07-27 20:07:37 +03:00
|
|
|
void CCallback::endTurn()
|
|
|
|
{
|
2009-03-20 20:51:48 +02:00
|
|
|
tlog5 << "Player " << (unsigned)player << " end his turn." << std::endl;
|
|
|
|
EndTurn pack;
|
|
|
|
*cl->serv << &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);
|
2008-08-15 15:11:42 +03:00
|
|
|
return gs->getUpgradeInfo(const_cast<CArmedInstance*>(obj),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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
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)
|
|
|
|
return gs->players[gs->currentPlayer].towns[val];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//TODO: add some smart ID to the CTownInstance
|
|
|
|
|
|
|
|
|
|
|
|
//for (int i=0; i<gs->players[gs->currentPlayer].towns.size();i++)
|
|
|
|
//{
|
|
|
|
// if (gs->players[gs->currentPlayer].towns[i]->someID==val)
|
|
|
|
// return gs->players[gs->currentPlayer].towns[i];
|
|
|
|
//}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
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
|
|
|
|
{
|
|
|
|
return static_cast<CGHeroInstance*>(gs->map->objects[val]);
|
|
|
|
}
|
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
|
|
|
|
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
|
|
|
{
|
2008-07-29 12:53:27 +03:00
|
|
|
if ( CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->blocked
|
|
|
|
&& (! (CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->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 (
|
2009-05-07 20:20:41 +03:00
|
|
|
((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype==TerrainTile::water)
|
2007-10-05 21:16:22 +03:00
|
|
|
&&
|
2009-05-07 20:20:41 +03:00
|
|
|
(CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype!=TerrainTile::water))
|
2007-10-05 21:16:22 +03:00
|
|
|
||
|
2009-05-07 20:20:41 +03:00
|
|
|
((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype!=TerrainTile::water)
|
2007-10-05 21:16:22 +03:00
|
|
|
&&
|
2009-05-07 20:20:41 +03:00
|
|
|
(CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==TerrainTile::water))
|
2007-10-05 23:38:14 +03:00
|
|
|
||
|
2009-05-07 20:20:41 +03:00
|
|
|
(CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->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);
|
2007-10-16 20:46:01 +03:00
|
|
|
return gs->players[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);
|
2007-10-20 00:12:37 +03:00
|
|
|
return gs->players[Player].fogOfWarMap[pos.x][pos.y][pos.z];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2008-08-30 00:41:32 +03:00
|
|
|
if ( ( isVisible((*i).second.towns[j],player) ) || (*i).first==player)
|
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
|
|
|
|
2008-09-26 17:16:01 +03:00
|
|
|
bool CCallback::isVisible( CGObjectInstance *obj, int Player ) const
|
2008-08-30 00:41:32 +03:00
|
|
|
{
|
|
|
|
//object is visible when at least one blocked tile is visible
|
|
|
|
for(int fx=0; fx<8; ++fx)
|
|
|
|
{
|
|
|
|
for(int fy=0; fy<6; ++fy)
|
|
|
|
{
|
|
|
|
int3 pos = obj->pos + int3(fx-7,fy-5,0);
|
|
|
|
if(gs->map->isInTheMap(pos)
|
|
|
|
&& !((obj->defInfo->blockMap[fy] >> (7 - fx)) & 1)
|
|
|
|
&& isVisible(pos,Player) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2008-09-26 17:16:01 +03:00
|
|
|
int CCallback::getMyColor() const
|
2007-12-01 14:50:33 +02:00
|
|
|
{
|
|
|
|
return player;
|
|
|
|
}
|
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;
|
|
|
|
}
|
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
|
|
|
|
return &armi->army;
|
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);
|
|
|
|
*cl->serv << &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);
|
|
|
|
*cl->serv << &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);
|
|
|
|
*cl->serv << &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);
|
|
|
|
*cl->serv << &pack;
|
2008-08-02 00:41:38 +03:00
|
|
|
return true;
|
2008-01-27 18:07:27 +02:00
|
|
|
}
|
|
|
|
|
2008-09-26 17:16:01 +03:00
|
|
|
int CCallback::getMySerial() const
|
2007-12-01 14:50:33 +02: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].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
|
|
|
{
|
2008-08-20 22:02:48 +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-03-29 15:02:37 +03:00
|
|
|
*cl->serv << &ea;
|
2008-01-30 12:55:43 +02:00
|
|
|
return true;
|
|
|
|
}
|
2007-11-19 00:58:28 +02:00
|
|
|
|
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;
|
2008-08-01 14:21:15 +03:00
|
|
|
CBuilding *b = CGI->buildh->buildings[t->subID][buildingID];
|
2008-03-21 02:03:31 +02:00
|
|
|
for(int i=0;i<7;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);
|
|
|
|
*cl->serv << &pack;
|
2008-03-21 02:03:31 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-03-10 22:19:41 +02:00
|
|
|
int CCallback::battleGetBattlefieldType()
|
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2009-02-09 16:50:32 +02:00
|
|
|
return gs->battleGetBattlefieldType();
|
2008-03-10 22:19:41 +02:00
|
|
|
}
|
|
|
|
|
2008-04-13 14:05:39 +03:00
|
|
|
int CCallback::battleGetObstaclesAtTile(int tile) //returns bitfield
|
|
|
|
{
|
|
|
|
//TODO - write
|
|
|
|
return -1;
|
|
|
|
}
|
2009-02-09 16:50:32 +02:00
|
|
|
|
|
|
|
std::vector<CObstacleInstance> CCallback::battleGetAllObstacles()
|
|
|
|
{
|
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
if(gs->curB)
|
|
|
|
return gs->curB->obstacles;
|
|
|
|
else
|
|
|
|
return std::vector<CObstacleInstance>();
|
|
|
|
}
|
|
|
|
|
2008-04-07 20:51:46 +03:00
|
|
|
int CCallback::battleGetStack(int pos)
|
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
return gs->battleGetStack(pos);
|
2008-04-07 20:51:46 +03:00
|
|
|
}
|
|
|
|
|
2008-07-02 11:39:56 +03:00
|
|
|
CStack* CCallback::battleGetStackByID(int ID)
|
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;
|
|
|
|
return gs->curB->getStack(ID);
|
2008-04-07 20:51:46 +03:00
|
|
|
}
|
|
|
|
|
2008-09-29 00:01:49 +03:00
|
|
|
int CCallback::battleMakeAction(BattleAction* action)
|
|
|
|
{
|
2009-03-20 20:51:48 +02:00
|
|
|
MakeCustomAction mca(*action);
|
|
|
|
*cl->serv << &mca;
|
2008-09-29 00:01:49 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-02 11:39:56 +03:00
|
|
|
CStack* CCallback::battleGetStackByPos(int pos)
|
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);
|
2008-06-11 04:58:18 +03:00
|
|
|
return battleGetStackByID(battleGetStack(pos));
|
|
|
|
}
|
|
|
|
|
2008-03-29 12:59:18 +02:00
|
|
|
int CCallback::battleGetPos(int stack)
|
|
|
|
{
|
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;
|
|
|
|
return -1;
|
|
|
|
}
|
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
|
|
|
}
|
2008-04-07 20:51:46 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-03-14 20:24:37 +02:00
|
|
|
std::map<int, CStack> CCallback::battleGetStacks()
|
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
2008-03-14 20:24:37 +02:00
|
|
|
std::map<int, CStack> ret;
|
2008-09-05 19:08:25 +03:00
|
|
|
if(!gs->curB) //there is no battle
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t g=0; g<gs->curB->stacks.size(); ++g)
|
2008-03-14 20:24:37 +02:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
ret[gs->curB->stacks[g]->ID] = *(gs->curB->stacks[g]);
|
2008-03-14 20:24:37 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-12-20 19:08:51 +02:00
|
|
|
std::vector<CStack> CCallback::battleGetStackQueue()
|
|
|
|
{
|
2009-02-14 15:49:30 +02:00
|
|
|
if(!gs->curB)
|
|
|
|
{
|
|
|
|
tlog2<<"battleGetStackQueue called when there is not battle!"<<std::endl;
|
|
|
|
return std::vector<CStack>();
|
|
|
|
}
|
2008-12-20 19:08:51 +02:00
|
|
|
return gs->curB->getStackQueue();
|
|
|
|
}
|
|
|
|
|
2008-03-23 19:25:38 +02:00
|
|
|
CCreature CCallback::battleGetCreature(int number)
|
|
|
|
{
|
2008-12-21 21:17:35 +02:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx); //TODO use me?
|
2009-02-14 15:49:30 +02:00
|
|
|
if(!gs->curB)
|
|
|
|
{
|
|
|
|
tlog2<<"battleGetCreature called when there is no battle!"<<std::endl;
|
|
|
|
}
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t h=0; h<gs->curB->stacks.size(); ++h)
|
2008-03-24 15:25:11 +02:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
if(gs->curB->stacks[h]->ID == number) //creature found
|
|
|
|
return *(gs->curB->stacks[h]->creature);
|
2008-03-24 15:25:11 +02:00
|
|
|
}
|
2008-08-04 12:05:52 +03:00
|
|
|
#ifndef __GNUC__
|
2008-04-11 20:41:02 +03:00
|
|
|
throw new std::exception("Cannot find the creature");
|
2008-08-04 12:05:52 +03:00
|
|
|
#else
|
|
|
|
throw new std::exception();
|
|
|
|
#endif
|
2008-03-23 19:25:38 +02:00
|
|
|
}
|
|
|
|
|
2009-02-05 16:44:27 +02:00
|
|
|
std::vector<int> CCallback::battleGetAvailableHexes(int ID, 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;
|
|
|
|
return std::vector<int>();
|
|
|
|
}
|
2009-02-05 16:44:27 +02:00
|
|
|
return gs->curB->getAccessibility(ID, addOccupiable);
|
2008-08-06 02:33:08 +03:00
|
|
|
//return gs->battleGetRange(ID);
|
2008-03-29 12:59:18 +02:00
|
|
|
}
|
|
|
|
|
2008-04-07 20:51:46 +03:00
|
|
|
bool CCallback::battleIsStackMine(int ID)
|
|
|
|
{
|
2009-02-14 15:49:30 +02:00
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
if(!gs->curB)
|
|
|
|
{
|
|
|
|
tlog2<<"battleIsStackMine called when there is no battle!"<<std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
2008-12-21 21:17:35 +02:00
|
|
|
for(size_t h=0; h<gs->curB->stacks.size(); ++h)
|
2008-04-07 20:51:46 +03:00
|
|
|
{
|
2008-08-05 02:04:15 +03:00
|
|
|
if(gs->curB->stacks[h]->ID == ID) //creature found
|
|
|
|
return gs->curB->stacks[h]->owner == player;
|
2008-04-07 20:51:46 +03:00
|
|
|
}
|
|
|
|
return false;
|
2009-04-16 17:01:27 +03:00
|
|
|
}
|
2008-11-01 00:41:22 +02:00
|
|
|
bool CCallback::battleCanShoot(int ID, int 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
|
|
|
CStack *our = battleGetStackByID(ID), *dst = battleGetStackByPos(dest);
|
2009-02-14 15:49:30 +02:00
|
|
|
if(!our || !dst || !gs->curB) return false;
|
2008-11-17 20:47:43 +02:00
|
|
|
|
2009-05-16 17:49:06 +03:00
|
|
|
//for(size_t g=0; g<our->effects.size(); ++g)
|
|
|
|
//{
|
|
|
|
// if(61 == our->effects[g].id) //forgetfulness
|
|
|
|
// return false;
|
|
|
|
//}
|
|
|
|
if(our->hasFeatureOfType(StackFeature::FORGETFULL)) //forgetfulness
|
|
|
|
return false;
|
2008-11-17 20:47:43 +02:00
|
|
|
|
2009-05-08 19:55:04 +03:00
|
|
|
if(our->hasFeatureOfType(StackFeature::SHOOTER)//it's shooter
|
2008-10-11 16:14:52 +03:00
|
|
|
&& our->owner != dst->owner
|
|
|
|
&& dst->alive()
|
|
|
|
&& !gs->curB->isStackBlocked(ID)
|
2008-11-01 00:41:22 +02:00
|
|
|
&& our->shots
|
2008-10-11 16:14:52 +03:00
|
|
|
)
|
2008-08-02 18:08:03 +03:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2008-08-16 11:47:41 +03:00
|
|
|
|
2009-04-16 17:01:27 +03:00
|
|
|
bool CCallback::battleCanCastSpell()
|
|
|
|
{
|
|
|
|
if(!gs->curB) //there is no battle
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(gs->curB->side1 == player)
|
2009-05-12 06:35:51 +03:00
|
|
|
return gs->curB->castSpells[0] == 0 && gs->getHero(gs->curB->hero1)->getArt(17);
|
2009-04-16 17:01:27 +03:00
|
|
|
else
|
2009-05-12 06:35:51 +03:00
|
|
|
return gs->curB->castSpells[1] == 0 && gs->getHero(gs->curB->hero2)->getArt(17);
|
2009-04-16 17:01:27 +03:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
*cl->serv << &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);
|
|
|
|
*cl->serv << &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
|
|
|
void CCallback::getMarketOffer( int t1, int t2, int &give, int &rec, int mode/*=0*/ ) const
|
2008-09-07 06:38:37 +03:00
|
|
|
{
|
|
|
|
if(mode) return; //TODO - support
|
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
//if(gs->resVals[t1] >= gs->resVals[t2])
|
2009-05-07 20:20:41 +03:00
|
|
|
float r = gs->resVals[t1], //price of given resource
|
|
|
|
g = gs->resVals[t2] / gs->getMarketEfficiency(player,mode); //price of wanted resource
|
|
|
|
if(r>g) //if given resource is more expensive than wanted
|
2008-09-07 06:38:37 +03:00
|
|
|
{
|
2008-09-09 04:40:43 +03:00
|
|
|
rec = ceil(r / g);
|
2008-09-07 06:38:37 +03:00
|
|
|
give = 1;
|
|
|
|
}
|
2009-05-07 20:20:41 +03:00
|
|
|
else //if wanted resource is more expensive
|
2008-09-07 06:38:37 +03:00
|
|
|
{
|
2008-09-09 04:40:43 +03:00
|
|
|
give = ceil(g / r);
|
2008-09-07 06:38:37 +03:00
|
|
|
rec = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-09-07 06:38:37 +03:00
|
|
|
void CCallback::trade( int mode, int id1, int id2, int val1 )
|
|
|
|
{
|
|
|
|
int p1, p2;
|
|
|
|
getMarketOffer(id1,id2,p1,p2,mode);
|
2009-03-20 20:51:48 +02:00
|
|
|
TradeOnMarketplace pack(player,mode,id1,id2,val1);
|
|
|
|
*cl->serv << &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
|
|
|
{
|
2008-09-19 11:16:19 +03:00
|
|
|
const_cast<CGHeroInstance*>(hero)->army.formation = tight;
|
2009-03-20 20:51:48 +02:00
|
|
|
SetFormation pack(hero->id,tight);
|
|
|
|
*cl->serv << &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-03-09 12:37:49 +02:00
|
|
|
*cl->serv << &ss;
|
2008-10-26 22:58:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCallback::recruitHero(const CGTownInstance *town, const CGHeroInstance *hero)
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2009-03-20 20:51:48 +02:00
|
|
|
HireHero pack(i,town->id);
|
|
|
|
*cl->serv << &pack;
|
2009-03-09 12:37:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-10-26 22:58:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<const CGHeroInstance *> CCallback::getAvailableHeroes(const CGTownInstance * town) const
|
|
|
|
{
|
|
|
|
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-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-03-19 16:17:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CPath * CCallback::getPath( int3 src, int3 dest, const CGHeroInstance * hero )
|
|
|
|
{
|
|
|
|
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
|
|
|
return gs->getPath(src,dest,hero);
|
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);
|
|
|
|
*cl->serv << ±
|
2009-05-12 06:35:51 +03:00
|
|
|
}
|