]> git.localhorst.tv Git - space.git/blob - src/world/Universe.h
5b3fccaf51dd896535ab35b232caec2b83615e45
[space.git] / src / world / Universe.h
1 #ifndef SPACE_UNIVERSE_H_
2 #define SPACE_UNIVERSE_H_
3
4 #include "../entity/Ship.h"
5 #include "../graphics/Vector.h"
6
7 #include <list>
8 #include <vector>
9
10
11 namespace space {
12
13 class Universe {
14
15 public:
16         Universe(Vector<int> size, Vector<int> secSize, Vector<int> areaSize);
17         ~Universe();
18
19         Universe(const Universe &) = delete;
20         Universe &operator =(const Universe &) = delete;
21
22 public:
23         const Vector<int> size;
24         const Vector<int> secSize;
25         const Vector<int> areaSize;
26
27 public:
28         class Area;
29
30         class Sector {
31
32         public:
33                 Sector(const Universe &univ, Vector<int> coords)
34                 : univ(univ), coords(coords) { }
35
36         public:
37                 Vector<int> SectorCoords() const { return coords; }
38                 Vector<int> AreaCoords() const { return univ.areaSize * coords; }
39
40                 Area AreaAt(Vector<int> ac) const { return univ.AreaAt(AreaCoords() + ac); }
41
42         private:
43                 const Universe &univ;
44                 Vector<int> coords;
45
46         };
47
48         class Area {
49
50         public:
51                 Area(const Universe &univ, Vector<int> coords)
52                 : univ(univ), coords(coords) { }
53
54         public:
55                 Vector<int> SectorCoords() const { return coords / univ.areaSize; }
56                 Vector<int> AreaCoords() const { return coords; }
57
58                 Sector ParentSector() const { return univ.SectorAt(SectorCoords()); }
59
60         private:
61                 const Universe &univ;
62                 Vector<int> coords;
63
64         };
65
66 public:
67         Sector SectorAt(Vector<int> coords) const { return Sector(*this, coords); }
68         Area AreaAt(Vector<int> coords) const { return Area(*this, coords); }
69
70 public:
71         Ship *AddShip(const Ship &);
72         const std::list<Ship> &Ships() const { return ships; }
73
74         int AddResource(const Resource &);
75         const Resource &GetResource(int id) const { return resources[id]; }
76
77 public:
78         void Update(float deltaT);
79
80 private:
81         std::list<Ship> ships;
82         std::vector<Resource> resources;
83
84 };
85
86 }
87
88 #endif