2007-08-27 17:15:03 +03:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "CCallback.h"
|
2007-08-29 13:05:50 +03:00
|
|
|
#include "CPathfinder.h"
|
2007-08-30 13:11:53 +03:00
|
|
|
#include "hch\CHeroHandler.h"
|
2007-08-29 15:18:31 +03:00
|
|
|
#include "CGameInfo.h"
|
2007-08-30 13:11:53 +03:00
|
|
|
#include "hch\CAmbarCendamo.h"
|
2007-08-29 15:18:31 +03:00
|
|
|
#include "mapHandler.h"
|
2007-08-30 13:11:53 +03:00
|
|
|
#include "CGameState.h"
|
|
|
|
#include "CGameInterface.h"
|
2007-08-27 17:15:03 +03:00
|
|
|
|
|
|
|
bool CCallback::moveHero(int ID, int3 destPoint)
|
|
|
|
{
|
2007-08-29 15:18:31 +03:00
|
|
|
if(ID<0 || ID>CGI->heroh->heroInstances.size())
|
|
|
|
return false;
|
|
|
|
if(destPoint.x<0 || destPoint.x>CGI->ac->map.width)
|
|
|
|
return false;
|
|
|
|
if(destPoint.y<0 || destPoint.y>CGI->ac->map.height)
|
|
|
|
return false;
|
|
|
|
if(destPoint.z<0 || destPoint.z>CGI->mh->ttiles[0][0].size()-1)
|
|
|
|
return false;
|
|
|
|
CPath * ourPath = CGI->pathf->getPath(CGI->heroh->heroInstances[ID]->pos, destPoint, CGI->heroh->heroInstances[ID]);
|
|
|
|
if(!ourPath)
|
|
|
|
return false;
|
2007-09-13 16:34:59 +03:00
|
|
|
for(int i=ourPath->nodes.size()-1; i>0; i--)
|
2007-08-30 13:11:53 +03:00
|
|
|
{
|
|
|
|
int3 stpos, endpos;
|
|
|
|
stpos = int3(ourPath->nodes[i].x, ourPath->nodes[i].y, CGI->heroh->heroInstances[ID]->pos.z);
|
2007-09-13 16:34:59 +03:00
|
|
|
endpos = int3(ourPath->nodes[i-1].x, ourPath->nodes[i-1].y, CGI->heroh->heroInstances[ID]->pos.z);
|
2007-08-30 13:11:53 +03:00
|
|
|
HeroMoveDetails curd;
|
|
|
|
curd.src = stpos;
|
|
|
|
curd.dst = endpos;
|
|
|
|
curd.heroID = ID;
|
|
|
|
curd.owner = CGI->heroh->heroInstances[ID]->owner;
|
2007-09-13 16:34:59 +03:00
|
|
|
//if(CGI->heroh->heroInstances[ID]->movement>=CGI->mh->getCost(stpos, endpos, CGI->heroh->heroInstances[ID]))
|
2007-08-30 13:11:53 +03:00
|
|
|
{ //performing move
|
2007-09-15 18:44:08 +03:00
|
|
|
int nn=0; //number of interfece of currently browsed player
|
|
|
|
for(std::map<int, PlayerState>::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing
|
2007-08-30 13:11:53 +03:00
|
|
|
{
|
2007-09-15 18:44:08 +03:00
|
|
|
if(j->second.fogOfWarMap[stpos.x][stpos.y][stpos.z] || j->second.fogOfWarMap[endpos.x][endpos.y][endpos.z])
|
2007-08-30 13:11:53 +03:00
|
|
|
{ //player should be notified
|
2007-09-15 18:44:08 +03:00
|
|
|
CGI->playerint[nn]->heroMoved(curd);
|
2007-08-30 13:11:53 +03:00
|
|
|
}
|
2007-09-15 18:44:08 +03:00
|
|
|
++nn;
|
|
|
|
break; //for testing only
|
2007-08-30 13:11:53 +03:00
|
|
|
}
|
|
|
|
}
|
2007-09-13 16:34:59 +03:00
|
|
|
//else
|
2007-09-15 18:44:08 +03:00
|
|
|
//return true; //move ended - no more movement points
|
2007-08-30 13:11:53 +03:00
|
|
|
}
|
|
|
|
return true;
|
2007-08-29 15:18:31 +03:00
|
|
|
}
|
2007-09-14 16:11:10 +03:00
|
|
|
|
|
|
|
|
|
|
|
int CCallback::howManyHeroes(int player)
|
|
|
|
{
|
|
|
|
if (gs->currentPlayer!=player) //TODO: checking if we are allowed to give that info
|
|
|
|
return -1;
|
|
|
|
return gs->players[player].heroes.size();
|
|
|
|
}
|
|
|
|
const CHeroInstance * CCallback::getHeroInfo(int player, int val, bool mode) //mode = 0 -> val = serial; mode = 1 -> val = ID
|
|
|
|
{
|
|
|
|
if (gs->currentPlayer!=player) //TODO: checking if we are allowed to give that info
|
|
|
|
return NULL;
|
|
|
|
if (!mode)
|
|
|
|
return gs->players[player].heroes[val];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i=0; i<gs->players[player].heroes.size();i++)
|
|
|
|
{
|
|
|
|
if (gs->players[player].heroes[i]->type->ID==val)
|
|
|
|
return gs->players[player].heroes[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2007-09-16 20:21:23 +03:00
|
|
|
}
|
|
|
|
int CCallback::getResourceAmount(int type)
|
|
|
|
{
|
|
|
|
return gs->players[gs->currentPlayer].resources[type];
|
2007-09-14 16:11:10 +03:00
|
|
|
}
|