/**********************
* ZonePosToWorldPos
*
* This function converts a percentage-based coordinate and
* a zone ID into a set of world coordinates, usable by HB.
**********************/
WoWPoint ZonePosToWorldPos(int iZoneID, float fPosX, float fPosY)
{
WoWDb.DbTable dbZone = StyxWoW.Db[ClientDb.WorldMapArea];
// Ensure the zone we're looking for is actually in the database
if (iZoneID < dbZone.MinIndex || iZoneID > dbZone.MaxIndex)
{
// Nope! The user is being silly again. Make him pay for his mistake! MWAHAHAH.
return null;
}
WoWDb.Row dbFields = dbZone.GetRow((uint)iZoneID);
// Make sure the zone is actually valid...
if (!dbFields.IsValid)
{
// Doh! The user almost tricked us into crashing that time. ALMOST.
return null;
}
// Get the zone info from the database
float fZoneTop = dbFields.GetField<float>(4);
float fZoneBottom = dbFields.GetField<float>(5);
float fZoneLeft = dbFields.GetField<float>(6);
float fZoneRight = dbFields.GetField<float>(7);
WoWPoint pPos = new WoWPoint();
// Convert from percentage-based location to world coords!
// NOTE: X and Y coords are switched when going from WoW client -> HB
pPos.X = (fPosY * (fZoneRight - fZoneLeft)) + fZoneLeft;
pPos.Y = (fPosX * (fZoneBottom - fZoneTop)) + fZoneTop;
// Grab the highest level at the specified point... Note there may be other Z levels.
Styx.Logic.Pathing.Navigator.FindHeight(pPos.X, pPos.Y, out pPos.Z);
return pPos;
}
/**********************
* WorldPosToZonePos
*
* This function converts a world coordinate pair into a zone
* ID and a set of percentage-based coordinates, usable by WoW.
**********************/
bool WorldPosToZonePos(float fPosX, float fPosY, out int iZoneID, out Vector2 vPos)
{
WoWDb.DbTable dbZone = StyxWoW.Db[ClientDb.WorldMapArea];
// NOTE: X and Y coords are switched when going from HB -> WoW Client
float fTempX = fPosY;
float fTempY = fPosX;
// Make sure we set our zone and pos to default values (0, 0)
iZoneID = -1;
vPos.X = 0.0f;
vPos.Y = 0.0f;
for (int iIndex = dbZone.MinIndex; iIndex <= dbZone.MaxIndex; iIndex++)
{
WoWDb.Row dbFields = dbZone.GetRow((uint)iIndex);
if (!dbFields.IsValid)
continue;
float fZoneTop = dbFields.GetField<float>(4);
float fZoneBottom = dbFields.GetField<float>(5);
float fZoneLeft = dbFields.GetField<float>(6);
float fZoneRight = dbFields.GetField<float>(7);
// Check if this is the right zone for the coordinates
if (fZoneTop > fTempY)
continue;
if (fZoneBottom < fTempY)
continue;
if (fZoneLeft > fTempX)
continue;
if (fZoneRight < fTempX)
continue;
// Ensure this isn't some weird zero-size zone... Divide by 0 is evil.
if (fZoneRight == fZoneLeft || fZoneBottom == fZoneTop)
{
// Oh god, we're going down! ABANDON SHIP!
return false;
}
// Looks like we've found the right zone! Convert and return.
vPos.X = (fTempX - fZoneLeft) / (fZoneRight - fZoneLeft);
vPos.Y = (fTempY - fZoneTop) / (fZoneBottom - fZoneTop);
iZoneID = iIndex;
return true;
}
// Looks like the coords we're looking for don't exist... Too bad, so sad.
return false;
}