Guest User

Untitled

a guest
Nov 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.46 KB | None | 0 0
  1.  
  2. /* Crow:
  3.     This function is a really heavy height check that is used for getting all types of height checks!
  4.     Since it is in the object class, we can skip any actual variables and instead use our current position.
  5.     This function gets map height and also checks the position of WMO's so that the height is set to the WMO height
  6.     based on the Z position that is given. If no Z position is given, but x and y positions are given, we will instead
  7.     use basic map heights as our Z position. */
  8. float Object::GetCHeightForPosition(bool checkwater, float x, float y, float z)
  9. {
  10.     if(!IsInWorld())
  11.         return 0.0f;
  12.  
  13.     MapMgr* mgr = GetMapMgr();
  14.     float offset = 0.02156f;
  15.     if(x == 0.0f && y == 0.0f)
  16.     {
  17.         x = GetPositionX();
  18.         y = GetPositionY();
  19.     }
  20.  
  21.     if(z == 0.0f)
  22.         z = GetPositionZ();
  23.  
  24.     if(!mgr->GetBaseMap() || !mgr->GetBaseMap()->GetMapTerrain())
  25.         return z;
  26.  
  27.     float waterheight = mgr->GetWaterHeight(x, y);
  28.     float mapheight = mgr->GetLandHeight(x, y);
  29.     if(!mgr->CanUseCollision(this))
  30.     {
  31.         if(checkwater)
  32.             if(waterheight > mapheight)
  33.                 return waterheight+offset;
  34.         return mapheight+offset;
  35.     }
  36.  
  37.     float vmapheight = CollideInterface.GetHeight(GetMapId(), x, y, z);
  38.     if(IS_INSTANCE(mgr->GetMapId()) || !sWorld.CalculatedHeightChecks)
  39.     {
  40.         if(vmapheight != NO_WMO_HEIGHT)
  41.         {
  42.             if(checkwater)
  43.                 if(waterheight > vmapheight)
  44.                     return waterheight+offset;
  45.             return vmapheight+offset;
  46.         }
  47.  
  48.         if(checkwater)
  49.             if(waterheight > mapheight)
  50.                 return waterheight+offset;
  51.         return mapheight+offset;
  52.     }
  53.  
  54.     float phx = 0.0f;
  55.     float phy = 0.0f;
  56.     float phz = 0.0f;
  57.     float CMapHeight = NO_LAND_HEIGHT;
  58.     CollideInterface.GetFirstPoint(GetMapId(), x, y, z-50.0f, x, y, z+50.0f, phx, phy, CMapHeight, 0.0f);
  59.  
  60.     // Mapheight first.
  61.     if(mapheight != NO_LAND_HEIGHT)
  62.     {
  63.         if(mapheight-2.0f < z)
  64.         {
  65.             if(mapheight+2.0f > z) // Accurate map height
  66.             {
  67.                 if(checkwater)
  68.                     if(waterheight > mapheight)
  69.                         return waterheight+offset;
  70.                 return mapheight+offset;
  71.             }
  72.  
  73.             if(!CollideInterface.GetFirstPoint(GetMapId(), x, y, mapheight, x, y, z, phx, phy, phz, 0.0f))
  74.             {
  75.                 if(checkwater)
  76.                     if(waterheight > mapheight)
  77.                         return waterheight+offset;
  78.                 return mapheight+offset; // No breaks inbetween us, so its the right height, we're just a bunch of fuckers!
  79.             }
  80.  
  81.             // TODO
  82.         }
  83.         else
  84.         {
  85.             // TODO
  86.         }
  87.     }
  88.  
  89.     // Now Vmap Height
  90.     if(vmapheight != NO_WMO_HEIGHT)
  91.     {
  92.         if(vmapheight-2.0f < z)
  93.         {
  94.             if(vmapheight+2.0f > z) // Accurate map height
  95.             {
  96.                 if(checkwater)
  97.                     if(waterheight > vmapheight)
  98.                         return waterheight+offset;
  99.                 return vmapheight+offset;
  100.             }
  101.  
  102.             if(!CollideInterface.GetFirstPoint(GetMapId(), x, y, vmapheight, x, y, z, phx, phy, phz, 0.0f))
  103.             {
  104.                 if(checkwater)
  105.                     if(waterheight > vmapheight)
  106.                         return waterheight+offset;
  107.                 return vmapheight+offset; // No breaks inbetween us, so its the right height, we're just a bunch of fuckers!
  108.             }
  109.  
  110.             if(phz > z)
  111.             {
  112.                 if(vmapheight < z)
  113.                 {
  114.                     float mmapheight = NavMeshInterface.GetWalkingHeight(GetMapId(), x, y, z, vmapheight);
  115.                     if(mmapheight != MMAP_UNAVAILABLE)
  116.                     {
  117.                         if(checkwater)
  118.                             if(waterheight > mmapheight)
  119.                                 return waterheight+offset;
  120.                         return mmapheight+offset;
  121.                     }
  122.                 }
  123.             }
  124.             else
  125.             {
  126.                 float mmapheight = NavMeshInterface.GetWalkingHeight(GetMapId(), x, y, z, phz);
  127.                 if(mmapheight != MMAP_UNAVAILABLE)
  128.                 {
  129.                     if(checkwater)
  130.                         if(waterheight > mmapheight)
  131.                             return waterheight+offset;
  132.                     return mmapheight+offset;
  133.                 }
  134.             }
  135.         }
  136.         else
  137.         {
  138.             float mmapheight = NavMeshInterface.GetWalkingHeight(GetMapId(), x, y, z, vmapheight);
  139.             if(mmapheight != MMAP_UNAVAILABLE)
  140.             {
  141.                 if(checkwater)
  142.                     if(waterheight > mmapheight)
  143.                         return waterheight+offset;
  144.                 return mmapheight+offset;
  145.             }
  146.         }
  147.     }
  148.  
  149.     // I think it's safe to say, no one is ever perfect.
  150.     if((CMapHeight != z+50.0f) && (CMapHeight != z-50.0f))
  151.     {
  152.         if(checkwater)
  153.             if(waterheight > CMapHeight)
  154.                 return waterheight+offset;
  155.         return CMapHeight+offset;
  156.     }
  157.  
  158.     if(checkwater)
  159.         return waterheight;
  160.     return z;
  161.  
  162. /*
  163.     // Crow: WE SHOULD GET HIGHEST REASONABLE VALUE BASED ON Z AND THE CALCULATIONS BELOW
  164.     // For now return the lowest reasonable one!
  165.     if(ccollidemapheight != NO_WMO_HEIGHT)
  166.     {
  167.         if(checkwater == true)
  168.         {
  169.             float wz = mgr->GetWaterHeight(x, y);
  170.             if(wz > ccollidemapheight && !(wz > (WMO_MAX_HEIGHT/2)))
  171.                 ccollidemapheight = wz;
  172.         }
  173.  
  174.         if(ccollidemapheight < cvmapheight && ccollidemapheight+3.0f > cvmapheight || ccollidemapheight < cmapheight && ccollidemapheight+3.0f > cmapheight)
  175.             return ccollidemapheight + ((z-1.0f > ccollidemapheight) ? 1.0f : 0.21563f);
  176.     }
  177.  
  178.     if(cvmapheight != NO_WMO_HEIGHT)
  179.     {
  180.         if(checkwater == true)
  181.         {
  182.             float wz = mgr->GetWaterHeight(x, y);
  183.             if(wz > cvmapheight && !(wz > (WMO_MAX_HEIGHT/2)))
  184.                 cvmapheight = wz;
  185.         }
  186.  
  187.         if(cvmapheight < ccollidemapheight && cvmapheight+3.0f > ccollidemapheight || cvmapheight < cmapheight && cvmapheight+3.0f > cmapheight)
  188.             return cvmapheight + ((z-1.0f > cvmapheight) ? 1.0f : 0.21563f);
  189.     }
  190.  
  191.     if(checkwater == true)
  192.     {
  193.         float wz = mgr->GetWaterHeight(x, y);
  194.         if(wz > cmapheight && !(wz > (WMO_MAX_HEIGHT/2)))
  195.             cmapheight = wz;
  196.     }
  197.  
  198.     return cmapheight + ((z-1.0f > cmapheight) ? 1.0f : 0.21563f);
  199.  
  200.     float offset = 10.0f;
  201.     if(vmapheight < z) // Make sure we don't have some shit.
  202.     {
  203.         if(mgr->CanUseCollision(this))
  204.         {
  205.             if(CollideInterface.IsIndoor(GetMapId(), x, y, z))
  206.                 offset = 5.0f;
  207.  
  208.             float pointx = 0.0f;
  209.             float pointy = 0.0f;
  210.             float pointz = 0.0f;
  211.             if(CollideInterface.GetFirstPoint(GetMapId(), x, y, vmapheight+2.0f, x, y, z, pointx, pointy, pointz, 0.0f)) // Meaning there is a break inbetween us.
  212.             {
  213.                 if(pointz+2.0f < vmapheight) // Distance is more than a roof.
  214.                 {
  215.                     float pointz2 = 0.0f;
  216.                     if(CollideInterface.GetFirstPoint(GetMapId(), x, y, vmapheight+2.0f, x, y, pointz, pointx, pointy, pointz2, 0.0f)) // Meaning there is a break inbetween us.
  217.                     {
  218.                         if(pointz2+2.0f < pointz) // Distance is more than a roof.
  219.                         {
  220.                             float pointz3 = 0.0f;
  221.                             if(CollideInterface.GetFirstPoint(GetMapId(), x, y, pointz, x, y, pointz2, pointx, pointy, pointz3, 0.0f)) // Meaning there is a break inbetween us.
  222.                                 vmapheight = pointz3;
  223.                         }
  224.                         else
  225.                             vmapheight = pointz2;
  226.                     }
  227.                     else
  228.                         vmapheight = pointz;
  229.                 }
  230.                 else
  231.                     vmapheight = pointz;
  232.             }
  233.  
  234.             if(CollideInterface.GetFirstPoint(GetMapId(), x, y, z+offset, x, y, vmapheight, pointx, pointy, pointz, 0.0f)) // Meaning there is a break inbetween us.
  235.             {
  236.                 if(pointz+2.0f < vmapheight) // Distance is more than a roof.
  237.                 {
  238.                     float pointz2 = 0.0f;
  239.                     if(CollideInterface.GetFirstPoint(GetMapId(), x, y, z+offset, x, y, pointz, pointx, pointy, pointz2, 0.0f)) // Meaning there is a break inbetween us.
  240.                     {
  241.                         if(pointz2+2.0f < pointz) // Distance is more than a roof.
  242.                         {
  243.                             float pointz3 = 0.0f;
  244.                             if(CollideInterface.GetFirstPoint(GetMapId(), x, y, pointz, x, y, pointz2, pointx, pointy, pointz3, 0.0f)) // Meaning there is a break inbetween us.
  245.                                 vmapheight = pointz3;
  246.                         }
  247.                         else
  248.                             vmapheight = pointz2;
  249.                     }
  250.                     else
  251.                         vmapheight = pointz;
  252.                 }
  253.                 else
  254.                     vmapheight = pointz;
  255.             }
  256.         }
  257.     }
  258.     else if(z+2.0f < vmapheight)
  259.     {
  260.         if(mgr->CanUseCollision(this))
  261.         {
  262.             if(CollideInterface.IsIndoor(GetMapId(), x, y, z))
  263.                 offset = 5.0f; // Use a smaller offset
  264.  
  265.             float pointx = 0.0f;
  266.             float pointy = 0.0f;
  267.             float pointz = 0.0f;
  268.             if(CollideInterface.GetFirstPoint(GetMapId(), x, y, z+2.0f, x, y, vmapheight, pointx, pointy, pointz, 0.0f)) // Meaning there is a break inbetween us.
  269.             {
  270.                 if(pointz+2.0f < vmapheight) // Distance is more than a roof.
  271.                 {
  272.                     float pointz2 = 0.0f;
  273.                     if(CollideInterface.GetFirstPoint(GetMapId(), x, y, pointz+2.0f, x, y, vmapheight, pointx, pointy, pointz2, 0.0f)) // Meaning there is a break inbetween us.
  274.                     {
  275.                         if(pointz2+2.0f < pointz) // Distance is more than a roof.
  276.                         {
  277.                             float pointz3 = 0.0f;
  278.                             if(CollideInterface.GetFirstPoint(GetMapId(), x, y, pointz2+2.0f, x, y, pointz, pointx, pointy, pointz3, 0.0f)) // Meaning there is a break inbetween us.
  279.                                 vmapheight = pointz3;
  280.                         }
  281.                         else
  282.                             vmapheight = pointz2;
  283.                     }
  284.                     else
  285.                         vmapheight = pointz;
  286.                 }
  287.                 else
  288.                     vmapheight = pointz;
  289.             }
  290.  
  291.             if(CollideInterface.GetFirstPoint(GetMapId(), x, y, vmapheight+offset, x, y, z, pointx, pointy, pointz, 0.0f)) // Meaning there is a break inbetween us.
  292.             {
  293.                 if(pointz+2.0f < vmapheight) // Distance is more than a roof.
  294.                 {
  295.                     float pointz2 = 0.0f;
  296.                     if(CollideInterface.GetFirstPoint(GetMapId(), x, y, vmapheight+offset, x, y, pointz, pointx, pointy, pointz2, 0.0f)) // Meaning there is a break inbetween us.
  297.                     {
  298.                         if(pointz2+2.0f < pointz) // Distance is more than a roof.
  299.                         {
  300.                             float pointz3 = 0.0f;
  301.                             if(CollideInterface.GetFirstPoint(GetMapId(), x, y, pointz, x, y, pointz2, pointx, pointy, pointz3, 0.0f)) // Meaning there is a break inbetween us.
  302.                                 vmapheight = pointz3;
  303.                         }
  304.                         else
  305.                             vmapheight = pointz2;
  306.                     }
  307.                     else
  308.                         vmapheight = pointz;
  309.                 }
  310.                 else
  311.                     vmapheight = pointz;
  312.             }
  313.         }
  314.     }
  315.  
  316.     if(checkwater == true) // Crow: Pretty sure this is all we need.
  317.     {
  318.         float wz = mgr->GetWaterHeight(x, y);
  319.         if(wz > vmapheight)
  320.             vmapheight = wz;
  321.     }
  322.  
  323.     return vmapheight+0.00321f; // We have a direct offset*/
  324. }
Add Comment
Please, Sign In to add comment