Jump to content

Line of sight because of terrain differences


darkstalker

Recommended Posts

Made this because of mangos currently doesn't support LoS blocking because of ground level differences, so tried to implement it. Seems to work, at least cant shoot to the WSG graveyard from below anymore, but more testing is needed, and maybe a better way to do it if possible.

diff --git a/src/game/Object.cpp b/src/game/Object.cpp
index 687202c..13b288b 100644
--- a/src/game/Object.cpp
+++ b/src/game/Object.cpp
@@ -1275,8 +1275,32 @@ bool WorldObject::IsWithinLOS(float ox, float oy, float oz) const
{
    float x,y,z;
    GetPosition(x,y,z);
+    z += 2.0f;
+    oz += 2.0f;
+
+    // check for line of sight because of terrain height differences
+    Map const *map = GetBaseMap();
+    float dx = ox - x, dy = oy - y, dz = oz - z;
+    float dist = sqrt(dx*dx + dy*dy + dz*dz);
+    if (dist > ATTACK_DISTANCE && dist < MAX_VISIBILITY_DISTANCE)
+    {
+        uint32 steps = uint32(dist / TERRAIN_LOS_STEP_DISTANCE);
+        float step_dist = dist / (float)steps;  // to make sampling intervals symmetric in both directions
+        float inc_factor = step_dist / dist;
+        float incx = dx*inc_factor, incy = dy*inc_factor, incz = dz*inc_factor;
+        float px = x, py = y, pz = z;
+        for (; steps; --steps)
+        {
+            if (map->GetHeight(px, py, pz, false) > pz)
+                return false;  // found intersection with ground
+            px += incx;
+            py += incy;
+            pz += incz;
+        }
+    }
+
    VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
-    return vMapManager->isInLineOfSight(GetMapId(), x, y, z+2.0f, ox, oy, oz+2.0f);
+    return vMapManager->isInLineOfSight(GetMapId(), x, y, z, ox, oy, oz);
}

bool WorldObject::GetDistanceOrder(WorldObject const* obj1, WorldObject const* obj2, bool is3D /* = true */) const
diff --git a/src/game/Object.h b/src/game/Object.h
index 4707f47..3678140 100644
--- a/src/game/Object.h
+++ b/src/game/Object.h
@@ -39,6 +39,7 @@

#define DEFAULT_WORLD_OBJECT_SIZE   0.388999998569489f      // player size, also currently used (correctly?) for any non Unit world objects
#define MAX_STEALTH_DETECT_RANGE    45.0f
+#define TERRAIN_LOS_STEP_DISTANCE   3.0f

enum TypeMask
{

edit: updated patch to fix some problems (los block in only one direction because of asymmetric sampling)

Link to comment
Share on other sites

Maybe i'm not fully up to speed, but since when does terrain count as LoS?

http://www.wowwiki.com/Line_of_sight

Uh...sorry for this but your own link to wowwiki states it there maybe I read it wrong but I don't think so LOS or Line of sight is a direct line to your enemy with out obsrtuctions IE: if the ground is in the way you don't have line of sight....so terrain is part of line of sight just as much as that bolder your hiding behind or the tree your girlfriend is targeting you from....:eek:

Link to comment
Share on other sites

"Terrain (that is, dirt and trees) only block Line of Sight indoors. All dirt and most trees do NOT block spells or abilities when fighting outdoors."

Last time i checked the warsong graveyard is outdoors. Yet some confirmation from retail would be nice, my knowledge is from pre TBC on that topic.

Link to comment
Share on other sites

"Terrain (that is, dirt and trees) only block Line of Sight indoors. All dirt and most trees do NOT block spells or abilities when fighting outdoors."

Last time i checked the warsong graveyard is outdoors. Yet some confirmation from retail would be nice, my knowledge is from pre TBC on that topic.

Yes...and the graveyard is up a cliff from the main battle ground so dirt would keep you from having line of sight :eek:

also if you can't see them to click on them then you don't have line of sight.....

Link to comment
Share on other sites

I have noticed LoS being blocked by uneven terrain.

# Uneven terrain, staircases, walls, and other environmental details can obstruct LOS, causing ranged actions to fail.

This is pretty clear. Uneven terrain blocks LoS.

# Terrain (that is, dirt and trees) only block Line of Sight indoors. All dirt and most trees do NOT block spells or abilities when fighting outdoors.

I'm fairly certain this is only referring to objects, such as dirt or trees which it mentions (this I can confirm)

However, until this is tested on retail for sure, better wait.

Link to comment
Share on other sites

Yes, you cant shoot up the stairs, but graveyards in Warsong Gulch are different. On retail, you can shoot/cast whatever you like from bottom to peoples who is ressing at the graveyard (even if it is through ground). The same case is that peoples up at graveyard could cast spells on peoples under the graveyard (through ground).

Link to comment
Share on other sites

the wowiki page in line of sight is contradictory, and maybe outdated like most of the content there. I'm just following common sense here

anyway i dont care much about being a bug-to-bug copy of retail, if you like this patch just use it. I would like more ppl to test it on live servers to see if it causes problems.

Link to comment
Share on other sites

the wowiki page in line of sight is contradictory, and maybe outdated like most of the content there. I'm just following common sense here

anyway i dont care much about being a bug-to-bug copy of retail, if you like this patch just use it. I would like more ppl to test it on live servers to see if it causes problems.

Thank you darkstalker for me with 5 people it works pretty good. :D

Link to comment
Share on other sites

  • 2 months later...

I've used it for months, and works fine. Only problem i found is that sometimes mobs manage to move below ground level and you're out of los in that instant.

And there is another problem not specific to this, but for all LoS calculations itself, that the spell target destination is not the same the client displays, that means in client you usually see the spell landing on mob's head, but mangos seems to calculate target destination at feet. Maybe some extra information is needed (dbc?) for the hit position, or i just missing something.

An obvious improvement would be to not use this on indoor zones where ground isnt there, but don't know how to do that.

Link to comment
Share on other sites

  • 2 months later...
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use