Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.33 KB | None | 0 0
  1. int MapView::calcFirstVisibleFloor()
  2. {
  3.     int z = 7;
  4.     // return forced first visible floor
  5.     if(m_lockedFirstVisibleFloor != -1) {
  6.         z = m_lockedFirstVisibleFloor;
  7.     } else {
  8.         Position cameraPosition = getCameraPosition();
  9.  
  10.         // this could happens if the player is not known yet
  11.         if(cameraPosition.isValid()) {
  12.             // avoid rendering multifloors in far views
  13.             if(!m_multifloor) {
  14.                 z = cameraPosition.z;
  15.             } else {
  16.                 // if nothing is limiting the view, the first visible floor is 0
  17.                 int firstFloor = 0;
  18.  
  19.                 // limits to underground floors while under sea level
  20.                 if(cameraPosition.z > Otc::SEA_FLOOR)
  21.                     firstFloor = std::max<int>(cameraPosition.z - Otc::AWARE_UNDEGROUND_FLOOR_RANGE, (int)Otc::UNDERGROUND_FLOOR);
  22.  
  23.                 // loop in 3x3 tiles around the camera
  24.                 for(int ix = -1; ix <= 1 && firstFloor < cameraPosition.z; ++ix) {
  25.                     for(int iy = -1; iy <= 1 && firstFloor < cameraPosition.z; ++iy) {
  26.                         Position pos = cameraPosition.translated(ix, iy);
  27.  
  28.                         // process tiles that we can look through, e.g. windows, doors
  29.                         if((ix == 0 && iy == 0) || ((std::abs(ix) != std::abs(iy)) && g_map.isLookPossible(pos))) {
  30.                             Position upperPos = pos;
  31.                             Position coveredPos = pos;
  32.  
  33.                             while(coveredPos.coveredUp() && upperPos.up() && upperPos.z >= firstFloor) {
  34.                                 // check tiles physically above
  35.                                 TilePtr tile = g_map.getTile(upperPos);
  36.                                 if(tile && tile->limitsFloorsView(!g_map.isLookPossible(pos))) {
  37.                                     firstFloor = upperPos.z + 1;
  38.                                     break;
  39.                                 }
  40.  
  41.                                 // check tiles geometrically above
  42.                                 tile = g_map.getTile(coveredPos);
  43.                                 if(tile && tile->limitsFloorsView(g_map.isLookPossible(pos))) {
  44.                                     firstFloor = coveredPos.z + 1;
  45.                                     break;
  46.                                 }
  47.                             }
  48.                         }
  49.                     }
  50.                 }
  51.                 z = firstFloor;
  52.             }
  53.         }
  54.     }
  55.  
  56.     // just ensure the that the floor is in the valid range
  57.     z = stdext::clamp<int>(z, 0, (int)Otc::MAX_Z);
  58.     return z;
  59. }
  60.  
  61. int MapView::calcLastVisibleFloor()
  62. {
  63.     if(!m_multifloor)
  64.         return calcFirstVisibleFloor();
  65.  
  66.     int z = 7;
  67.  
  68.     Position cameraPosition = getCameraPosition();
  69.     // this could happens if the player is not known yet
  70.     if(cameraPosition.isValid()) {
  71.         // view only underground floors when below sea level
  72.         if(cameraPosition.z > Otc::SEA_FLOOR)
  73.             z = cameraPosition.z + Otc::AWARE_UNDEGROUND_FLOOR_RANGE;
  74.         else
  75.             z = Otc::SEA_FLOOR;
  76.     }
  77.  
  78.     if(m_lockedFirstVisibleFloor != -1)
  79.         z = std::max<int>(m_lockedFirstVisibleFloor, z);
  80.  
  81.     // just ensure the that the floor is in the valid range
  82.     z = stdext::clamp<int>(z, 0, (int)Otc::MAX_Z);
  83.     return z;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement