WorldUpdate.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "WorldUpdate.h"
  2. WorldUpdate::WorldUpdate(int type,
  3. int dimensionId,
  4. Framework::Vec3<int> minAffected,
  5. Framework::Vec3<int> maxAffected)
  6. : ReferenceCounter(),
  7. affectedDimensionId(dimensionId),
  8. minAffected(minAffected),
  9. maxAffected(maxAffected),
  10. type(type)
  11. {}
  12. void WorldUpdate::writeAndCheck(Framework::StreamWriter* zWriter)
  13. {
  14. zWriter->schreibe((char*)&type, 4);
  15. this->write(zWriter);
  16. zWriter->schreibe((char*)&type, 4);
  17. }
  18. int WorldUpdate::getAffectedDimension() const
  19. {
  20. return affectedDimensionId;
  21. }
  22. const Framework::Vec3<int>& WorldUpdate::getMinAffectedPoint() const
  23. {
  24. return minAffected;
  25. }
  26. const Framework::Vec3<int>& WorldUpdate::getMaxAffectedPoint() const
  27. {
  28. return maxAffected;
  29. }
  30. int WorldUpdate::getType() const
  31. {
  32. return type;
  33. }
  34. int WorldUpdate::distanceTo(int x, int y) const
  35. {
  36. int xDist = MIN(abs(x - minAffected.x), abs(x - maxAffected.x));
  37. int yDist = MIN(abs(y - minAffected.y), abs(y - maxAffected.y));
  38. if (x >= minAffected.x && x <= maxAffected.x) xDist = 0;
  39. if (y >= minAffected.y && y <= maxAffected.y) yDist = 0;
  40. return MIN(xDist, yDist);
  41. }