1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

* fixed bug crashing server when hero was moving near bottom or right edge of the map

* a few improvements in CMinimap.
This commit is contained in:
mateuszb 2009-03-13 14:16:53 +00:00
parent 5bbc50fc12
commit 227d48c12b
5 changed files with 53 additions and 16 deletions

View File

@ -116,7 +116,8 @@ void CMinimap::draw()
//draw heroes
std::vector <const CGHeroInstance *> hh = LOCPLINT->cb->getHeroesInfo(false);
int mw = map[0]->w, mh = map[0]->h,
wo = mw/mapSizes.x, ho = mh/mapSizes.y;
wo = mw/mapSizes.x, ho = mh/mapSizes.y,
woShifted = wo, hoShifted = ho; //for better minimap rendering on L-sized maps
for (size_t i=0; i < hh.size(); ++i)
{
@ -146,9 +147,34 @@ void CMinimap::draw()
if(!dynamic_cast< const CGHeroInstance * >(oo[v])) //heroes have been printed
{
int3 maplgp ( (x*mw)/mapSizes.x, (y*mh)/mapSizes.y, LOCPLINT->adventureInt->position.z );
for (int ii=0; ii<wo; ii++)
if(wo * mapSizes.x != mw) //miniap size in X is not multiple of map size in X
{
for (int jj=0; jj<ho; jj++)
std::vector < const CGObjectInstance * > op1x = LOCPLINT->cb->getFlaggableObjects(int3(x+1, y, LOCPLINT->adventureInt->position.z));
if(op1x.size()!=0)
{
woShifted = wo + 1;
}
else
{
woShifted = wo;
}
}
if(ho * mapSizes.y != mh) //miniap size in Y is not multiple of map size in Y
{
std::vector < const CGObjectInstance * > op1y = LOCPLINT->cb->getFlaggableObjects(int3(x, y+1, LOCPLINT->adventureInt->position.z));
if(op1y.size()!=0)
{
hoShifted = ho + 1;
}
else
{
hoShifted = ho;
}
}
for (int ii=0; ii<woShifted; ii++) //rendering flaggable objects
{
for (int jj=0; jj<hoShifted; jj++)
{
if(oo[v]->tempOwner == 255)
SDL_PutPixelWithoutRefresh(temps,maplgp.x+ii,maplgp.y+jj,graphics->neutralColor->r,
@ -189,9 +215,13 @@ void CMinimap::redraw(int level)// (level==-1) => redraw all levels
{
int mx=(mapSizes.x*x)/pos.w;
int my=(mapSizes.y*y)/pos.h;
if (CGI->mh->ttiles[mx][my][i].tileInfo->blocked && (!CGI->mh->ttiles[mx][my][i].tileInfo->visitable))
SDL_PutPixelWithoutRefresh(pom,x,y,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b);
else SDL_PutPixelWithoutRefresh(pom,x,y,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b);
const TerrainTile * tile = LOCPLINT->cb->getTileInfo(int3(mx, my, i));
if(tile)
{
if (tile->blocked && (!tile->visitable))
SDL_PutPixelWithoutRefresh(pom, x, y, colorsBlocked[tile->tertype].r, colorsBlocked[tile->tertype].g, colorsBlocked[tile->tertype].b);
else SDL_PutPixelWithoutRefresh(pom, x, y, colors[tile->tertype].r, colors[tile->tertype].g, colors[tile->tertype].b);
}
}
}
map.push_back(pom);
@ -222,6 +252,7 @@ void CMinimap::redraw(int level)// (level==-1) => redraw all levels
}
//FoW end
}
void CMinimap::updateRadar()
{}
void CMinimap::clickRight (tribool down)
@ -291,6 +322,14 @@ void CMinimap::showTile(const int3 &pos)
{
if ((pos.x*wo+ii<this->pos.w) && (pos.y*ho+jj<this->pos.h))
CSDL_Ext::SDL_PutPixelWithoutRefresh(FoW[pos.z],pos.x*wo+ii,pos.y*ho+jj,0,0,0,0);
const TerrainTile * tile = LOCPLINT->cb->getTileInfo(pos);
if(tile)
{
if (tile->blocked && (!tile->visitable))
SDL_PutPixelWithoutRefresh(map[pos.z], pos.x*wo+ii, pos.y*ho+jj, colorsBlocked[tile->tertype].r, colorsBlocked[tile->tertype].g, colorsBlocked[tile->tertype].b);
else SDL_PutPixelWithoutRefresh(map[pos.z], pos.x*wo+ii, pos.y*ho+jj, colors[tile->tertype].r, colors[tile->tertype].g, colors[tile->tertype].b);
}
}
}
}

View File

@ -660,8 +660,10 @@ std::vector<const CGHeroInstance *> CCallback::getAvailableHeroes(const CGTownIn
return ret;
}
const TerrainTile * CCallback::getTileInfo( int3 tile )
const TerrainTile * CCallback::getTileInfo( int3 tile ) const
{
if(!isVisible(tile, player)) return NULL;
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
return &gs->map->getTile(tile);
}

View File

@ -72,7 +72,7 @@ public:
virtual std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const =0;
virtual int3 getMapSize() const =0; //returns size of map - z is 1 for one - level map and 2 for two level map
virtual std::vector<const CGHeroInstance *> getAvailableHeroes(const CGTownInstance * town) const =0; //heroes that can be recruited
virtual const TerrainTile * getTileInfo(int3 tile) = 0;
virtual const TerrainTile * getTileInfo(int3 tile) const = 0;
virtual int canBuildStructure(const CGTownInstance *t, int ID) =0;//// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements
//battle
@ -162,7 +162,7 @@ public:
std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
std::vector<const CGHeroInstance *> getAvailableHeroes(const CGTownInstance * town) const; //heroes that can be recruited
const TerrainTile * getTileInfo(int3 tile);
const TerrainTile * getTileInfo(int3 tile) const;
int canBuildStructure(const CGTownInstance *t, int ID);//// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements
//battle

View File

@ -1334,9 +1334,9 @@ std::set<int3> CGameState::tilesToReveal(int3 pos, int radious, int player) cons
return ret;
}
for (int xd = std::max<int>(pos.x - radious , 0); xd <= std::min<int>(pos.x + radious, map->width); xd++)
for (int xd = std::max<int>(pos.x - radious , 0); xd <= std::min<int>(pos.x + radious, map->width-1); xd++)
{
for (int yd = std::max<int>(pos.y - radious, 0); std::min<int>(yd <= pos.y + radious, map->height); yd++)
for (int yd = std::max<int>(pos.y - radious, 0); yd <= std::min<int>( pos.y + radious, map->height-1); yd++)
{
double distance = pos.dist2d(int3(xd,yd,pos.z)) - 0.5;
if(distance <= radious && (player<0 || players.find(player)->second.fogOfWarMap[xd][yd][pos.z]==0))

View File

@ -1243,11 +1243,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
{
boost::unique_lock<boost::recursive_mutex> un(*pim);
int3 buff = details.ho->pos;
buff.x-=11;
buff.y-=9;
buff = repairScreenPos(buff);
LOCPLINT->adventureInt->position = buff; //actualizing screen pos
adventureInt->centerOn(details.ho->pos); //actualizing screen pos
if(adventureInt == curint)
adventureInt->minimap.draw();