river.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. Copyright (C) 2015 Pieter Staal
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #ifndef RIVER_H
  15. #define RIVER_H
  16. #include <SFML/Graphics.hpp>
  17. using namespace sf;
  18. const Vector2i directions[9] { Vector2i(-1,-1), // North West
  19. Vector2i(0, -1), // North
  20. Vector2i(1, -1), // North East
  21. Vector2i(-1, 0), // West
  22. Vector2i(0, 0), // -
  23. Vector2i(1, 0), // East
  24. Vector2i(-1, 1), // South West
  25. Vector2i(0, 1), // South
  26. Vector2i(1, 1)}; // South East
  27. struct RiverSettings
  28. {
  29. bool *watermap;
  30. double *normalizedHeightmap;
  31. double *displayWatermap;
  32. Vector2i position;
  33. int riverCoordMod;
  34. int mapSize;
  35. };
  36. class River
  37. {
  38. public:
  39. River(RiverSettings settings);
  40. Vector2i getPos() { return position; }
  41. void setPos(Vector2i p) { position = p; }
  42. void addDirection(char direction) { generatorPath.push_back(direction); }
  43. int flow();
  44. void complete();
  45. std::vector<char>* getGeneratorPath() { return &generatorPath; }
  46. std::vector<char>* getTotalPath() { return &totalPath; }
  47. void drawOnMap();
  48. int stepBack();
  49. bool hasBeenCompleted() { return completed; }
  50. protected:
  51. private:
  52. Vector2i position;
  53. Vector2i startPosition;
  54. std::vector<char> generatorPath;
  55. std::vector<char> totalPath;
  56. bool *watermap;
  57. double *normalizedHeightmap;
  58. double *displayWatermap;
  59. int riverCoordMod;
  60. int mapSize;
  61. int branches = 0;
  62. int length = 0;
  63. bool completed = false;
  64. };
  65. #endif // RIVER_H