mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
* fixed some issues with hero moving; actualizing hero position is still broken :(
This commit is contained in:
parent
7b3c270dfc
commit
d530bd057d
@ -598,7 +598,7 @@ void CTerrainRect::clickLeft(tribool down)
|
|||||||
{
|
{
|
||||||
if ( (currentPath->endPos()) == mp)
|
if ( (currentPath->endPos()) == mp)
|
||||||
{ //move
|
{ //move
|
||||||
LOCPLINT->cb->moveHero(0,currentPath->endPos());//todo - move selected hero
|
LOCPLINT->cb->moveHero(0,currentPath->endPos(), 1);//todo - move selected hero
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -608,7 +608,9 @@ void CTerrainRect::clickLeft(tribool down)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const CHeroInstance * currentHero = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].first;
|
const CHeroInstance * currentHero = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].first;
|
||||||
currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(currentHero->pos,mp,currentHero);
|
int3 bufpos = currentHero->pos;
|
||||||
|
//bufpos.x-=1;
|
||||||
|
currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(bufpos,mp,currentHero,1);
|
||||||
}
|
}
|
||||||
void CTerrainRect::clickRight(tribool down)
|
void CTerrainRect::clickRight(tribool down)
|
||||||
{
|
{
|
||||||
|
@ -40,7 +40,7 @@ void CCallback::newTurn()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool CCallback::moveHero(int ID, int3 destPoint, int idtype)
|
bool CCallback::moveHero(int ID, int3 destPoint, int idtype, unsigned char posType)
|
||||||
{
|
{
|
||||||
if(ID<0 || ID>CGI->heroh->heroInstances.size())
|
if(ID<0 || ID>CGI->heroh->heroInstances.size())
|
||||||
return false;
|
return false;
|
||||||
@ -50,7 +50,7 @@ bool CCallback::moveHero(int ID, int3 destPoint, int idtype)
|
|||||||
return false;
|
return false;
|
||||||
if(destPoint.z<0 || destPoint.z>CGI->mh->ttiles[0][0].size()-1)
|
if(destPoint.z<0 || destPoint.z>CGI->mh->ttiles[0][0].size()-1)
|
||||||
return false;
|
return false;
|
||||||
CPath * ourPath = CGI->pathf->getPath(CGI->heroh->heroInstances[ID]->pos, destPoint, CGI->heroh->heroInstances[ID]);
|
CPath * ourPath = CGI->pathf->getPath(CGI->heroh->heroInstances[ID]->pos, destPoint, CGI->heroh->heroInstances[ID], posType);
|
||||||
if(!ourPath)
|
if(!ourPath)
|
||||||
return false;
|
return false;
|
||||||
for(int i=ourPath->nodes.size()-1; i>0; i--)
|
for(int i=ourPath->nodes.size()-1; i>0; i--)
|
||||||
|
@ -22,7 +22,7 @@ protected:
|
|||||||
int player;
|
int player;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool moveHero(int ID, int3 destPoint, int idtype=0);//idtype: 0-position in vector; 1-ID of hero
|
bool moveHero(int ID, int3 destPoint, int idtype=0, unsigned char posType=0);//idtype: 0-position in vector; 1-ID of hero
|
||||||
|
|
||||||
int howManyTowns();
|
int howManyTowns();
|
||||||
const CTownInstance * getTownInfo(int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID
|
const CTownInstance * getTownInfo(int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID
|
||||||
|
@ -673,6 +673,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
|
|||||||
}
|
}
|
||||||
LOCPLINT->adventureInt->update(); //updating screen
|
LOCPLINT->adventureInt->update(); //updating screen
|
||||||
CGI->screenh->updateScreen();
|
CGI->screenh->updateScreen();
|
||||||
|
LOCPLINT->adventureInt->anim++;
|
||||||
SDL_framerateDelay(mainFPSmng); //for animation purposes
|
SDL_framerateDelay(mainFPSmng); //for animation purposes
|
||||||
} //for(int i=1; i<32; i+=4)
|
} //for(int i=1; i<32; i+=4)
|
||||||
//main moving done
|
//main moving done
|
||||||
|
@ -4,19 +4,23 @@
|
|||||||
#include "CGameInfo.h"
|
#include "CGameInfo.h"
|
||||||
#include "hch\CAmbarCendamo.h"
|
#include "hch\CAmbarCendamo.h"
|
||||||
#include "mapHandler.h"
|
#include "mapHandler.h"
|
||||||
int3 CPath::endPos()
|
|
||||||
{
|
|
||||||
return int3(nodes[0].coord.x,nodes[0].coord.y,nodes[0].coord.z);
|
|
||||||
}
|
|
||||||
int3 CPath::startPos()
|
int3 CPath::startPos()
|
||||||
{
|
{
|
||||||
return int3(nodes[nodes.size()-1].coord.x,nodes[nodes.size()-1].coord.y,nodes[nodes.size()-1].coord.z);
|
return int3(nodes[nodes.size()-1].coord.x,nodes[nodes.size()-1].coord.y,nodes[nodes.size()-1].coord.z);
|
||||||
}
|
}
|
||||||
|
int3 CPath::endPos()
|
||||||
|
{
|
||||||
|
return int3(nodes[0].coord.x,nodes[0].coord.y,nodes[0].coord.z);
|
||||||
|
}
|
||||||
|
|
||||||
CPath * CPathfinder::getPath(const int3 &src, const int3 &dest, const CHeroInstance * hero) //TODO: test it (seems to be finished, but relies on unwritten functions :()
|
CPath * CPathfinder::getPath(int3 src, int3 dest, const CHeroInstance * hero, unsigned char type) //TODO: test it (seems to be finished, but relies on unwritten functions :()
|
||||||
{
|
{
|
||||||
if(src.z!=dest.z) //first check
|
if(src.z!=dest.z) //first check
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if(type==1) //calibrating
|
||||||
|
{
|
||||||
|
src.x-=1;
|
||||||
|
}
|
||||||
|
|
||||||
//graph initialization
|
//graph initialization
|
||||||
graph.resize(CGI->ac->map.width);
|
graph.resize(CGI->ac->map.width);
|
||||||
|
@ -29,8 +29,8 @@ class CPathfinder
|
|||||||
private:
|
private:
|
||||||
std::vector< std::vector<CPathNode *> > graph;
|
std::vector< std::vector<CPathNode *> > graph;
|
||||||
public:
|
public:
|
||||||
CPath * getPath(const int3 & src, const int3 & dest, const CHeroInstance * hero); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists
|
CPath * getPath(int3 src, int3 dest, const CHeroInstance * hero, unsigned char type=0); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists; type - type of calculation: 0 - positions are normal positions of hero; 1 - given places are tiles blocked by hero
|
||||||
CPath * getPath(const int3 & src, const int3 & dest, const CHeroInstance * hero, int (*getDist)(int3 & a, int3 & b)); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists; uses getDist to calculate distance
|
CPath * getPath(const int3 & src, const int3 & dest, const CHeroInstance * hero, int (*getDist)(int3 & a, int3 & b), unsigned char type=0); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists; uses getDist to calculate distance; type - type of calculation: 0 - positions are normal positions of hero; 1 - given places are tiles blocked by hero
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //CPATHFINDER_H
|
#endif //CPATHFINDER_H
|
Loading…
Reference in New Issue
Block a user