Skip to content

Commit

Permalink
[10438] Fix GetHeight() to return height within actual search distanc…
Browse files Browse the repository at this point in the history
…e only.

Good news: Fixes fishing bobber
Bad news: Mobs follow into the air again unless larger search distance is used
  • Loading branch information
Lynx3d committed Sep 3, 2010
1 parent 928f361 commit cc1843b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/game/Map.cpp
Expand Up @@ -1015,12 +1015,13 @@ float Map::GetHeight(float x, float y, float z, bool pUseVmaps, float maxSearchD
{
// find raw .map surface under Z coordinates
float mapHeight;
float z2 = z + 2.f;
if(GridMap *gmap = const_cast<Map*>(this)->GetGrid(x, y))
{
float _mapheight = gmap->getHeight(x,y);

// look from a bit higher pos to find the floor, ignore under surface case
if(z + 2.0f > _mapheight)
if(z2 > _mapheight)
mapHeight = _mapheight;
else
mapHeight = VMAP_INVALID_HEIGHT_VALUE;
Expand All @@ -1035,7 +1036,7 @@ float Map::GetHeight(float x, float y, float z, bool pUseVmaps, float maxSearchD
if(vmgr->isHeightCalcEnabled())
{
// look from a bit higher pos to find the floor
vmapHeight = vmgr->getHeight(GetId(), x, y, z + 2.0f, maxSearchDist);
vmapHeight = vmgr->getHeight(GetId(), x, y, z2, maxSearchDist);
}
else
vmapHeight = VMAP_INVALID_HEIGHT_VALUE;
Expand Down Expand Up @@ -1063,6 +1064,12 @@ float Map::GetHeight(float x, float y, float z, bool pUseVmaps, float maxSearchD
else
return vmapHeight; // we have only vmapHeight (if have)
}
else if (pUseVmaps && z2 - mapHeight > maxSearchDist)
{
// with vmaps we can only give definite result up to maxSearchDist,
// in other cases mapHeight might or might not be the true height.
return VMAP_INVALID_HEIGHT_VALUE;
}

return mapHeight;
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10437"
#define REVISION_NR "10438"
#endif // __REVISION_NR_H__

7 comments on commit cc1843b

@Fabi
Copy link
Contributor

@Fabi Fabi commented on cc1843b Sep 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float z2 = z + 2.f;??

must be float z2 = z + 2.0f; or not?

@roby10
Copy link

@roby10 roby10 commented on cc1843b Sep 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to : if(z + 2.0f > _mapheight)

it must be 2.0f

@Fabi
Copy link
Contributor

@Fabi Fabi commented on cc1843b Sep 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh also I'm right :)

@Lynx3d
Copy link
Contributor Author

@Lynx3d Lynx3d commented on cc1843b Sep 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sigh
Just an old habit of mine, and no, it is not a mistake.

@Fabi
Copy link
Contributor

@Fabi Fabi commented on cc1843b Sep 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is 2.f no mistake? 2.0f is the same and, but 2.f is not the coding standard

@roby10
Copy link

@roby10 roby10 commented on cc1843b Sep 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the "." is a mistake ... it would be 2f or 2.0f ? haha am i wrong?

@vermie
Copy link
Contributor

@vermie vermie commented on cc1843b Sep 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are interchangeable, it's just an older convention.

Please sign in to comment.