2008-12-27 03:01:59 +02:00
|
|
|
#define VCMI_DLL
|
|
|
|
#include "IGameCallback.h"
|
2009-05-21 03:55:30 +03:00
|
|
|
#include "../lib/CGameState.h"
|
|
|
|
#include "../lib/map.h"
|
2008-12-27 03:01:59 +02:00
|
|
|
#include "../hch/CObjectHandler.h"
|
2009-02-08 08:42:15 +02:00
|
|
|
#include "../StartInfo.h"
|
2009-04-16 03:28:54 +03:00
|
|
|
#include "../hch/CArtHandler.h"
|
|
|
|
#include "../lib/VCMI_Lib.h"
|
2008-12-27 03:01:59 +02:00
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* IGameCallback.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-12-27 03:01:59 +02:00
|
|
|
const CGObjectInstance* IGameCallback::getObj(int objid)
|
|
|
|
{
|
2009-03-09 12:37:49 +02:00
|
|
|
if(objid < 0 || objid >= gs->map->objects.size())
|
|
|
|
{
|
|
|
|
tlog1 << "Cannot get object with id " << objid << std::endl;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else if (!gs->map->objects[objid])
|
|
|
|
{
|
|
|
|
tlog1 << "Cannot get object with id " << objid << ". Object was removed.\n";
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-12-27 03:01:59 +02:00
|
|
|
return gs->map->objects[objid];
|
|
|
|
}
|
|
|
|
const CGHeroInstance* IGameCallback::getHero(int objid)
|
|
|
|
{
|
2009-03-09 12:37:49 +02:00
|
|
|
const CGObjectInstance *obj = getObj(objid);
|
|
|
|
if(obj)
|
|
|
|
return dynamic_cast<const CGHeroInstance*>(obj);
|
|
|
|
else
|
|
|
|
return NULL;
|
2008-12-27 03:01:59 +02:00
|
|
|
}
|
|
|
|
const CGTownInstance* IGameCallback::getTown(int objid)
|
|
|
|
{
|
2009-03-09 12:37:49 +02:00
|
|
|
const CGObjectInstance *obj = getObj(objid);
|
|
|
|
if(obj)
|
|
|
|
return dynamic_cast<const CGTownInstance*>(gs->map->objects[objid]);
|
|
|
|
else
|
|
|
|
return NULL;
|
2008-12-27 03:01:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int IGameCallback::getOwner(int heroID)
|
|
|
|
{
|
|
|
|
return gs->map->objects[heroID]->tempOwner;
|
|
|
|
}
|
|
|
|
int IGameCallback::getResource(int player, int which)
|
|
|
|
{
|
|
|
|
return gs->players.find(player)->second.resources[which];
|
|
|
|
}
|
|
|
|
int IGameCallback::getDate(int mode)
|
|
|
|
{
|
|
|
|
return gs->getDate(mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
const CGHeroInstance* IGameCallback::getSelectedHero( int player )
|
|
|
|
{
|
|
|
|
return getHero(gs->players.find(player)->second.currentSelection);
|
2009-02-08 08:42:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const PlayerSettings * IGameCallback::getPlayerSettings( int color )
|
|
|
|
{
|
|
|
|
return &gs->scenarioOps->getIthPlayersSettings(color);
|
2009-02-14 21:12:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int IGameCallback::getHeroCount( int player, bool includeGarrisoned )
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
if(includeGarrisoned)
|
2009-03-09 12:37:49 +02:00
|
|
|
return gs->getPlayer(player)->heroes.size();
|
2009-02-14 21:12:40 +02:00
|
|
|
else
|
2009-03-09 12:37:49 +02:00
|
|
|
for(int i=0; i < gs->getPlayer(player)->heroes.size(); i++)
|
|
|
|
if(!gs->getPlayer(player)->heroes[i]->inTownGarrison)
|
2009-02-14 21:12:40 +02:00
|
|
|
ret++;
|
|
|
|
return ret;
|
2009-03-14 13:25:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void IGameCallback::getTilesInRange( std::set<int3> &tiles, int3 pos, int radious, int player/*=-1*/, int mode/*=0*/ )
|
|
|
|
{
|
|
|
|
if(player >= PLAYER_LIMIT)
|
|
|
|
{
|
|
|
|
tlog1 << "Illegal call to getTilesInRange!\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int xd = std::max<int>(pos.x - radious , 0); xd <= std::min<int>(pos.x + radious, gs->map->width - 1); xd++)
|
|
|
|
{
|
|
|
|
for (int yd = std::max<int>(pos.y - radious, 0); yd <= std::min<int>(pos.y + radious, gs->map->height - 1); yd++)
|
|
|
|
{
|
|
|
|
double distance = pos.dist2d(int3(xd,yd,pos.z)) - 0.5;
|
|
|
|
if(distance <= radious)
|
|
|
|
{
|
|
|
|
if(player < 0
|
|
|
|
|| (mode == 1 && gs->players.find(player)->second.fogOfWarMap[xd][yd][pos.z]==0)
|
|
|
|
|| (mode == -1 && gs->players.find(player)->second.fogOfWarMap[xd][yd][pos.z]==1)
|
|
|
|
)
|
|
|
|
tiles.insert(int3(xd,yd,pos.z));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IGameCallback::isAllowed( int type, int id )
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return gs->map->allowedSpell[id];
|
2009-04-16 03:28:54 +03:00
|
|
|
case 1:
|
|
|
|
return gs->map->allowedArtifact[id];
|
2009-03-14 13:25:25 +02:00
|
|
|
default:
|
|
|
|
tlog1 << "Wrong call to IGameCallback::isAllowed!\n";
|
2009-03-14 19:19:53 +02:00
|
|
|
return false;
|
2009-03-14 13:25:25 +02:00
|
|
|
}
|
2009-04-16 03:28:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void IGameCallback::getAllowedArts(std::vector<CArtifact*> &out, std::vector<CArtifact*> CArtHandler::*arts)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < (VLC->arth->*arts).size(); i++)
|
|
|
|
{
|
|
|
|
CArtifact *art = (VLC->arth->*arts)[i];
|
|
|
|
if(isAllowed(1,art->id))
|
|
|
|
{
|
|
|
|
out.push_back(art);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IGameCallback::getAllowed(std::vector<CArtifact*> &out, int flags)
|
|
|
|
{
|
2009-05-07 20:20:41 +03:00
|
|
|
if(flags & CArtifact::ART_TREASURE)
|
2009-04-16 03:28:54 +03:00
|
|
|
getAllowedArts(out,&CArtHandler::treasures);
|
2009-05-07 20:20:41 +03:00
|
|
|
if(flags & CArtifact::ART_MINOR)
|
2009-04-16 03:28:54 +03:00
|
|
|
getAllowedArts(out,&CArtHandler::minors);
|
2009-05-07 20:20:41 +03:00
|
|
|
if(flags & CArtifact::ART_MAJOR)
|
2009-04-16 03:28:54 +03:00
|
|
|
getAllowedArts(out,&CArtHandler::majors);
|
2009-05-07 20:20:41 +03:00
|
|
|
if(flags & CArtifact::ART_RELIC)
|
2009-04-16 03:28:54 +03:00
|
|
|
getAllowedArts(out,&CArtHandler::relics);
|
2009-05-21 03:55:30 +03:00
|
|
|
}
|