mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
Work on pathfinder: torn the code out from CGameState into a separate class. It can use Subterranean Gates and Boats. Removed code for handling Fly spell effect. It didn't work as supposed anyway.
This commit is contained in:
@@ -572,17 +572,24 @@ void CTerrainRect::showPath(const SDL_Rect * extRect, SDL_Surface * to)
|
||||
|
||||
for (size_t i=0; i < currentPath->nodes.size()-1; ++i)
|
||||
{
|
||||
const int3 &curPos = currentPath->nodes[i].coord, &nextPos = currentPath->nodes[i+1].coord;
|
||||
if(curPos.z != adventureInt->position.z)
|
||||
continue;
|
||||
|
||||
int pn=-1;//number of picture
|
||||
if (i==0) //last tile
|
||||
{
|
||||
int x = 32*(currentPath->nodes[i].coord.x-adventureInt->position.x)+CGI->mh->offsetX + pos.x,
|
||||
y = 32*(currentPath->nodes[i].coord.y-adventureInt->position.y)+CGI->mh->offsetY + pos.y;
|
||||
int x = 32*(curPos.x-adventureInt->position.x)+CGI->mh->offsetX + pos.x,
|
||||
y = 32*(curPos.y-adventureInt->position.y)+CGI->mh->offsetY + pos.y;
|
||||
if (x<0 || y<0 || x>pos.w || y>pos.h)
|
||||
continue;
|
||||
pn=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
const int3 &prevPos = currentPath->nodes[i-1].coord;
|
||||
std::vector<CGPathNode> & cv = currentPath->nodes;
|
||||
|
||||
/* Vector directions
|
||||
* 0 1 2
|
||||
* \ | /
|
||||
@@ -595,20 +602,25 @@ void CTerrainRect::showPath(const SDL_Rect * extRect, SDL_Surface * to)
|
||||
* /
|
||||
* is id1=7, id2=5 (pns[7][5])
|
||||
*/
|
||||
std::vector<CGPathNode> & cv = currentPath->nodes;
|
||||
int id1=(cv[i].coord.x-cv[i+1].coord.x+1)+3*(cv[i].coord.y-cv[i+1].coord.y+1); //Direction of entering vector
|
||||
int id2=(cv[i-1].coord.x-cv[i].coord.x+1)+3*(cv[i-1].coord.y-cv[i].coord.y+1); //Direction of exiting vector
|
||||
|
||||
pn=pns[id1][id2];
|
||||
|
||||
bool pathContinuous = curPos.areNeighbours(nextPos) && curPos.areNeighbours(prevPos);
|
||||
if(pathContinuous && cv[i].land == cv[i+1].land)
|
||||
{
|
||||
int id1=(curPos.x-nextPos.x+1)+3*(curPos.y-nextPos.y+1); //Direction of entering vector
|
||||
int id2=(cv[i-1].coord.x-curPos.x+1)+3*(cv[i-1].coord.y-curPos.y+1); //Direction of exiting vector
|
||||
pn=pns[id1][id2];
|
||||
}
|
||||
else //path discontinuity or sea/land transition (eg. when moving through Subterranean Gate or Boat)
|
||||
{
|
||||
pn = 0;
|
||||
}
|
||||
}
|
||||
if (currentPath->nodes[i].turns)
|
||||
pn+=25;
|
||||
if (pn>=0)
|
||||
{
|
||||
CDefEssential * arrows = graphics->heroMoveArrows;
|
||||
int x = 32*(currentPath->nodes[i].coord.x-adventureInt->position.x)+CGI->mh->offsetX + pos.x,
|
||||
y = 32*(currentPath->nodes[i].coord.y-adventureInt->position.y)+CGI->mh->offsetY + pos.y;
|
||||
int x = 32*(curPos.x-adventureInt->position.x)+CGI->mh->offsetX + pos.x,
|
||||
y = 32*(curPos.y-adventureInt->position.y)+CGI->mh->offsetY + pos.y;
|
||||
if (x<0 || y<0 || x>pos.w || y>pos.h)
|
||||
continue;
|
||||
int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
|
||||
@@ -690,7 +702,7 @@ void CTerrainRect::show(SDL_Surface * to)
|
||||
|
||||
//SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6));
|
||||
//SDL_FreeSurface(teren);
|
||||
if (currentPath && adventureInt->position.z==currentPath->startPos().z) //drawing path
|
||||
if (currentPath/* && adventureInt->position.z==currentPath->startPos().z*/) //drawing path
|
||||
{
|
||||
showPath(&pos, to);
|
||||
}
|
||||
@@ -1655,7 +1667,7 @@ void CAdvMapInt::tileLClicked(const int3 &mp)
|
||||
LOCPLINT->moveHero(currentHero,*terrain.currentPath);
|
||||
return;
|
||||
}
|
||||
else if(mp.z == currentHero->pos.z) //remove old path and find a new one if we clicked on the map level on which hero is present
|
||||
else/* if(mp.z == currentHero->pos.z)*/ //remove old path and find a new one if we clicked on the map level on which hero is present
|
||||
{
|
||||
CGPath &path = LOCPLINT->paths[currentHero];
|
||||
terrain.currentPath = &path;
|
||||
@@ -1840,11 +1852,13 @@ void CAdvMapInt::tileHovered(const int3 &tile)
|
||||
}
|
||||
else //no objs
|
||||
{
|
||||
if(accessible && pnode->accessible != CGPathNode::FLYABLE)
|
||||
if(accessible/* && pnode->accessible != CGPathNode::FLYABLE*/)
|
||||
{
|
||||
if (guardingCreature) {
|
||||
if (guardingCreature)
|
||||
{
|
||||
CCS->curh->changeGraphic(0, 5 + turns*6);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
if(pnode->land)
|
||||
{
|
||||
if(LOCPLINT->cb->getTile(h->getPosition(false))->tertype != TerrainTile::water)
|
||||
|
||||
@@ -486,6 +486,12 @@ void MusicEntry::load(musicBase::musicID ID)
|
||||
|
||||
music = Mix_LoadMUS(filename.c_str());
|
||||
|
||||
if(!music)
|
||||
{
|
||||
tlog3 << "Warning: Cannot open " << filename << ": " << Mix_GetError() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
//The assertion will fail if old MSVC libraries pack .dll is used
|
||||
assert(Mix_GetMusicType(music) == MUS_MP3_MAD);
|
||||
|
||||
@@ -259,25 +259,32 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details)
|
||||
{
|
||||
//We may need to change music - select new track, music handler will change it if needed
|
||||
CCS->musich->playMusic(CCS->musich->terrainMusics[LOCPLINT->cb->getTile(ho->visitablePos())->tertype]);
|
||||
if(details.result == TryMoveHero::TELEPORTATION || details.start == details.end)
|
||||
|
||||
if(details.result == TryMoveHero::TELEPORTATION)
|
||||
{
|
||||
if(adventureInt->terrain.currentPath)
|
||||
eraseCurrentPathOf(ho);
|
||||
return; //teleport - no fancy moving animation
|
||||
if(adventureInt->terrain.currentPath->nodes.size() && adventureInt->terrain.currentPath->nodes.back().coord == CGHeroInstance::convertPosition(hp, false))
|
||||
removeLastNodeFromPath(ho);
|
||||
// else
|
||||
// eraseCurrentPathOf(ho);
|
||||
return; //teleport - no fancy moving animation
|
||||
//TODO: smooth disappear / appear effect
|
||||
}
|
||||
|
||||
if ((details.result != TryMoveHero::SUCCESS && details.result != TryMoveHero::FAILED) //hero didn't change tile but visit succeeded
|
||||
if(details.start == details.end) //last step
|
||||
{
|
||||
eraseCurrentPathOf(ho);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ho->pos != details.end //hero didn't change tile but visit succeeded
|
||||
|| directlyAttackingCreature) // or creature was attacked from endangering tile.
|
||||
{
|
||||
eraseCurrentPathOf(ho);
|
||||
}
|
||||
else if(adventureInt->terrain.currentPath && details.result == TryMoveHero::SUCCESS) //&& hero is moving
|
||||
else if(adventureInt->terrain.currentPath && ho->pos == details.end) //&& hero is moving
|
||||
{
|
||||
//remove one node from the path (the one we went)
|
||||
adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
|
||||
if(!adventureInt->terrain.currentPath->nodes.size()) //if it was the last one, remove entire path
|
||||
eraseCurrentPathOf(ho);
|
||||
removeLastNodeFromPath(ho);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1127,6 +1134,10 @@ bool CPlayerInterface::moveHero( const CGHeroInstance *h, CGPath path )
|
||||
|
||||
for(int i=path.nodes.size()-1; i>0 && (stillMoveHero.data == CONTINUE_MOVE || curTile->blocked); i--)
|
||||
{
|
||||
//changing z coordinate means we're moving through subterranean gate -> it's done automatically upon the visit, so we don't have to request that move here
|
||||
if(path.nodes[i-1].coord.z != path.nodes[i].coord.z)
|
||||
continue;
|
||||
|
||||
//stop sending move requests if the next node can't be reached at the current turn (hero exhausted his move points)
|
||||
if(path.nodes[i-1].turns)
|
||||
{
|
||||
@@ -1143,7 +1154,8 @@ bool CPlayerInterface::moveHero( const CGHeroInstance *h, CGPath path )
|
||||
{
|
||||
newTerrain = cb->getTile(CGHeroInstance::convertPosition(path.nodes[i].coord, false))->tertype;
|
||||
|
||||
if (newTerrain != currentTerrain) {
|
||||
if (newTerrain != currentTerrain)
|
||||
{
|
||||
CCS->soundh->stopSound(sh);
|
||||
sh = CCS->soundh->playSound(CCS->soundh->horseSounds[newTerrain], -1);
|
||||
currentTerrain = newTerrain;
|
||||
@@ -2024,6 +2036,13 @@ void CPlayerInterface::eraseCurrentPathOf( const CGHeroInstance * ho, bool check
|
||||
adventureInt->terrain.currentPath = NULL;
|
||||
}
|
||||
|
||||
void CPlayerInterface::removeLastNodeFromPath(const CGHeroInstance *ho)
|
||||
{
|
||||
adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1);
|
||||
if(!adventureInt->terrain.currentPath->nodes.size()) //if it was the last one, remove entire path
|
||||
eraseCurrentPathOf(ho);
|
||||
}
|
||||
|
||||
CGPath * CPlayerInterface::getAndVerifyPath(const CGHeroInstance * h)
|
||||
{
|
||||
if(vstd::contains(paths,h)) //hero has assigned path
|
||||
|
||||
@@ -256,6 +256,7 @@ public:
|
||||
void movementPxStep( const TryMoveHero &details, int i, const int3 &hp, const CGHeroInstance * ho );//performing step of movement
|
||||
void finishMovement( const TryMoveHero &details, const int3 &hp, const CGHeroInstance * ho ); //finish movement
|
||||
void eraseCurrentPathOf( const CGHeroInstance * ho, bool checkForExistanceOfPath = true );
|
||||
void removeLastNodeFromPath(const CGHeroInstance *ho);
|
||||
CGPath *getAndVerifyPath( const CGHeroInstance * h );
|
||||
void acceptTurn(); //used during hot seat after your turn message is close
|
||||
void tryDiggging(const CGHeroInstance *h);
|
||||
|
||||
@@ -1059,7 +1059,7 @@ void CMapHandler::getTerrainDescr( const int3 &pos, std::string & out, bool terN
|
||||
}
|
||||
}
|
||||
|
||||
if(t.siodmyTajemniczyBajt & 128)
|
||||
if(t.hasFavourableWinds())
|
||||
out = CGI->generaltexth->names[225]; //Favourable Winds
|
||||
else if(terName)
|
||||
out = CGI->generaltexth->terrainNames[t.tertype];
|
||||
|
||||
Reference in New Issue
Block a user