Guest User

Untitled

a guest
May 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. bool Creature::canSee(const Position& myPos, const Position& pos, uint32_t viewRangeX, uint32_t viewRangeY)
  2. {
  3.     if(myPos.z <= 7)
  4.     {
  5.         //we are on ground level or above (7 -> 0)
  6.         //view is from 7 -> 0
  7.         if(pos.z > 7)
  8.             return false;
  9.     }
  10.     else if(myPos.z >= 8)
  11.     {
  12.         //we are underground (8 -> 15)
  13.         //view is +/- 2 from the floor we stand on
  14.         if(std::abs(myPos.z - pos.z) > 2)
  15.             return false;
  16.     }
  17.  
  18.     int32_t offsetz = myPos.z - pos.z;
  19.     return (((uint32_t)pos.x >= myPos.x - viewRangeX + offsetz) && ((uint32_t)pos.x <= myPos.x + viewRangeX + offsetz) &&
  20.         ((uint32_t)pos.y >= myPos.y - viewRangeY + offsetz) && ((uint32_t)pos.y <= myPos.y + viewRangeY + offsetz));
  21. }
Add Comment
Please, Sign In to add comment