TreeTemplate.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "TreeTemplate.h"
  2. TreeTemplate::TreeTemplate(float propability, const BlockType* zWoodType, const BlockType* zLeaveType, int minHeight, int maxHeight)
  3. : GenerationTemplate(propability, 0, 1, Framework::Vec3<int>(-2, -2, 0), Framework::Vec3<int>(5, 5, maxHeight)),
  4. zWoodType(zWoodType),
  5. zLeaveType(zLeaveType),
  6. minHeight(minHeight),
  7. maxHeight(maxHeight)
  8. {}
  9. GeneratedStructure* TreeTemplate::generateAt(Framework::Vec3<int> location, Noise* zNoise)
  10. {
  11. double noise = zNoise->getNoise((double)location.x + 40, (double)location.y + 70, (double)location.z - 20);
  12. int height = (int)(minHeight + (noise * (maxHeight - minHeight)));
  13. GeneratedStructure* generated = new GeneratedStructure(dynamic_cast<GenerationTemplate*>(getThis()), location, Framework::Vec3<int>(5, 5, height), Framework::Vec3<int>(-2, -2, 0) + location);
  14. for (int x = 1; x < 4; x++)
  15. {
  16. for (int y = 1; y < 4; y++)
  17. {
  18. generated->setBlockAt(zLeaveType->getId(), Framework::Vec3<int>(x, y, height - 1));
  19. generated->setBlockAt(zLeaveType->getId(), Framework::Vec3<int>(x, y, height - 5));
  20. }
  21. }
  22. for (int z = height - 2; z >= height - 4; z--)
  23. {
  24. for (int x = 1; x < 4; x++)
  25. {
  26. generated->setBlockAt(zLeaveType->getId(), Framework::Vec3<int>(x, 0, z));
  27. generated->setBlockAt(zLeaveType->getId(), Framework::Vec3<int>(0, x, z));
  28. generated->setBlockAt(zLeaveType->getId(), Framework::Vec3<int>(x, 4, z));
  29. generated->setBlockAt(zLeaveType->getId(), Framework::Vec3<int>(4, x, z));
  30. for (int y = 1; y < 4; y++)
  31. generated->setBlockAt(zLeaveType->getId(), Framework::Vec3<int>(x, y, z));
  32. }
  33. }
  34. for (int i = 0; i < height - 1; i++)
  35. generated->setBlockAt(zWoodType->getId(), Framework::Vec3<int>(2, 2, i));
  36. return generated;
  37. }