1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

* resolving #23 with adding it to callback

This commit is contained in:
mateuszb 2007-10-05 18:10:33 +00:00
parent df3b0f56d9
commit 49565e6b45
6 changed files with 49 additions and 1 deletions

View File

@ -161,4 +161,11 @@ int CCallback::getDate(int mode)
case 3:
return ((gs->day-1)/28)+1;
}
}
}
std::vector < std::string > CCallback::getObjDescriptions(int3 pos)
{
if(gs->players[player].fogOfWarMap[pos.x][pos.y][pos.z])
return CGI->mh->getObjDescriptions(pos);
else return std::vector< std::string > ();
}

View File

@ -23,6 +23,7 @@ protected:
public:
bool moveHero(int ID, int3 destPoint, int idtype=0, unsigned char posType=0);//idtype: 0-position in vector; 1-ID of hero
std::vector < std::string > getObjDescriptions(int3 pos); //returns descriptions of objects at pos in order from the lowest to the highest
int howManyTowns();
const CTownInstance * getTownInfo(int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID

View File

@ -47,6 +47,26 @@ int internalFunc(void * callback)
readed>>heronum>>dest;
cb->moveHero(heronum, dest);
break;
case 'D': //pos description
readed>>src;
CGI->mh->getObjDescriptions(src);
break;
case 'T': //test rect
readed>>src;
for(int g=0; g<8; ++g)
{
for(int v=0; v<8; ++v)
{
int3 csrc = src;
csrc.y+=g;
csrc.x+=v;
if(CGI->mh->getObjDescriptions(csrc).size())
std::cout<<'x';
else
std::cout<<'o';
}
std::cout<<std::endl;
}
}
//SDL_Delay(100);
}

View File

@ -14,6 +14,8 @@ void CObjectHandler::loadObjects()
{
CObject nobj;
CGeneralTextHandler::loadToIt(nobj.name,buf,it,3);
if(nobj.name.size() && (nobj.name[nobj.name.size()-1]=='/10' || nobj.name[nobj.name.size()-1]=='/13'))
nobj.name = nobj.name.substr(0, nobj.name.size()-1);
objects.push_back(nobj);
}
}

View File

@ -946,3 +946,20 @@ int CMapHandler::getCost(int3 &a, int3 &b, const CHeroInstance *hero)
//TODO: use hero's pathfinding skill during calculating cost
return ret;
}
std::vector < std::string > CMapHandler::getObjDescriptions(int3 pos)
{
std::vector < std::pair<CObjectInstance*,SDL_Rect> > objs = ttiles[pos.x][pos.y][pos.z].objects;
std::vector<std::string> ret;
for(int g=0; g<objs.size(); ++g)
{
if( (5-(objs[g].first->pos.y-pos.y-1)) >= 0 && (5-(objs[g].first->pos.y-pos.y-1)) < 6 && (objs[g].first->pos.x-pos.x-1) >= 0 && (objs[g].first->pos.x-pos.x-1)<7 && objs[g].first->defObjInfoNumber!=-1 &&
(((CGI->dobjinfo->objs[objs[g].first->defObjInfoNumber].blockMap[5-(objs[g].first->pos.y-pos.y-1)])>>((objs[g].first->pos.x-pos.x-1)))&1)==0
) //checking position blocking
{
unsigned char * blm = CGI->dobjinfo->objs[objs[g].first->defObjInfoNumber].blockMap;
ret.push_back(CGI->objh->objects[CGI->ac->map.defy[objs[g].first->defNumber].bytes[16]].name);
}
}
return ret;
}

View File

@ -77,6 +77,7 @@ public:
SDL_Surface * getVisBitmap(int x, int y, std::vector< std::vector<char> > & visibility);
int getCost(int3 & a, int3 & b, const CHeroInstance * hero);
std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position
void init();
SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0);
SDL_Surface * terrBitmap(int x, int y);