]> git.localhorst.tv Git - blobs.git/blob - src/world/Planet.hpp
more stolen stuff
[blobs.git] / src / world / Planet.hpp
1 #ifndef BLOBS_WORLD_PLANET_HPP_
2 #define BLOBS_WORLD_PLANET_HPP_
3
4 #include "Tile.hpp"
5
6 #include <cassert>
7 #include <memory>
8
9
10 namespace blobs {
11 namespace world {
12
13 struct Tile;
14
15 /// A planet has six surfaces, numbered 0 to 5, each with tiles from
16 /// +radius to -radius.
17 class Planet {
18
19 public:
20         explicit Planet(int radius);
21         ~Planet();
22
23         Planet(Planet &&);
24         Planet &operator =(Planet &&);
25
26         Planet(const Planet &) = delete;
27         Planet &operator =(const Planet &) = delete;
28
29 public:
30         /// Get the tile at given surface and coordinates.
31         Tile &TileAt(int surface, int x, int y) {
32                 return tiles[IndexOf(surface, x, y)];
33         }
34         const Tile &TileAt(int surface, int x, int y) const {
35                 return tiles[IndexOf(surface, x, y)];
36         }
37
38         /// Convert coordinates into a tile index.
39         int IndexOf(int surface, int x, int y) const {
40                 assert(0 <= surface && surface <= 5);
41                 assert(-radius <= x && x <= radius);
42                 assert(-radius <= y && y <= radius);
43                 return surface * SurfaceArea() + ToOffset(y) * SideLength() + ToOffset(x);
44         }
45         /// Convert coordinate into offset
46         int ToOffset(int c) const {
47                 return c + radius;
48         }
49         /// The "radius" of the planet.
50         int Radius() const {
51                 return radius;
52         }
53         /// The length of the side of each surface.
54         int SideLength() const {
55                 return 2 * radius + 1;
56         }
57         /// The area (or number of tiles) of one surface
58         int SurfaceArea() const {
59                 return SideLength() * SideLength();
60         }
61         /// Total area of all surfaces combined.
62         int TotalArea() const {
63                 return 6 * SurfaceArea();
64         }
65
66 private:
67         int radius;
68         std::unique_ptr<Tile []> tiles;
69
70 };
71
72 void GenerateTest(Planet &);
73
74 }
75 }
76
77 #endif