Pioneer
Loading...
Searching...
No Matches
Sector.h
Go to the documentation of this file.
1// Copyright © 2008-2024 Pioneer Developers. See AUTHORS.txt for details
2// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3
4#ifndef _SECTOR_H
5#define _SECTOR_H
6
7#include "GalaxyCache.h"
8#include "RefCounted.h"
10#include "galaxy/StarSystem.h"
11#include "galaxy/SystemPath.h"
12
13#include <sigc++/signal.h>
14#include <string>
15#include <vector>
16
17class Faction;
18class Galaxy;
19
20class Sector : public RefCounted {
21 friend class GalaxyObjectCache<Sector, SystemPath::LessSectorOnly>;
22 friend class GalaxyGenerator;
23
24public:
25 // lightyears
26 static const float SIZE;
27 ~Sector();
28
29 static float DistanceBetween(RefCountedPtr<const Sector> a, int sysIdxA, RefCountedPtr<const Sector> b, int sysIdxB);
30 static float DistanceBetweenSqr(const RefCountedPtr<const Sector> a, const int sysIdxA, const RefCountedPtr<const Sector> b, const int sysIdxB);
31
32 // Sector is within a bounding rectangle - used for SectorView m_sectorCache pruning.
33 bool WithinBox(const int Xmin, const int Xmax, const int Ymin, const int Ymax, const int Zmin, const int Zmax) const;
34 bool Contains(const SystemPath &sysPath) const;
35
36 // get the SystemPath for this sector
37 SystemPath GetPath() const { return SystemPath(sx, sy, sz); }
38
39 class System {
40 public:
41 System(Sector *sector, int x, int y, int z, Uint32 si) :
42 sx(x),
43 sy(y),
44 sz(z),
45 idx(si),
46 m_sector(sector),
47 m_numStars(0),
48 m_seed(0),
49 m_customSys(nullptr),
50 m_faction(nullptr),
51 m_population(-1),
52 m_explored(StarSystem::eUNEXPLORED),
53 m_exploredTime(0.0) {}
54
55 static float DistanceBetween(const System *a, const System *b);
56
57 // Check that we've had our habitation status set
58
59 const std::string &GetName() const { return m_name; }
60 const std::vector<std::string> &GetOtherNames() const { return m_other_names; }
61 const vector3f &GetPosition() const { return m_pos; }
62 vector3f GetFullPosition() const { return Sector::SIZE * vector3f(float(sx), float(sy), float(sz)) + m_pos; };
63 unsigned GetNumStars() const { return m_numStars; }
65 {
66 assert(i < m_numStars);
67 return m_starType[i];
68 }
69 Uint32 GetSeed() const { return m_seed; }
70 const CustomSystem *GetCustomSystem() const { return m_customSys; }
71 const Faction *GetFaction() const
72 {
73 if (!m_faction) AssignFaction();
74 return m_faction;
75 }
76 fixed GetPopulation() const { return m_population; }
77 void SetPopulation(fixed pop) { m_population = pop; }
78 StarSystem::ExplorationState GetExplored() const { return m_explored; }
79 double GetExploredTime() const { return m_exploredTime; }
80 bool IsExplored() const { return m_explored != StarSystem::eUNEXPLORED; }
81 void SetExplored(StarSystem::ExplorationState e, double time);
82
83 bool IsSameSystem(const SystemPath &b) const
84 {
85 return sx == b.sectorX && sy == b.sectorY && sz == b.sectorZ && idx == b.systemIndex;
86 }
87 bool InSameSector(const SystemPath &b) const
88 {
89 return sx == b.sectorX && sy == b.sectorY && sz == b.sectorZ;
90 }
91 SystemPath GetPath() const { return SystemPath(sx, sy, sz, idx); }
92
93 const int sx, sy, sz;
94 const Uint32 idx;
95
96 private:
97 friend class Sector;
101
102 void AssignFaction() const;
103
104 Sector *m_sector;
105 std::string m_name;
106 std::vector<std::string> m_other_names;
107 vector3f m_pos;
108 unsigned m_numStars;
109 SystemBody::BodyType m_starType[4];
110 Uint32 m_seed;
111 const CustomSystem *m_customSys;
112 mutable const Faction *m_faction; // mutable because we only calculate on demand
113 fixed m_population;
115 double m_exploredTime;
116 };
117 std::vector<System> m_systems;
118 const int sx, sy, sz;
119
120 void Dump(FILE *file, const char *indent = "") const;
121
122 sigc::signal<void, Sector::System *, StarSystem::ExplorationState, double> onSetExplorationState;
123
124private:
125 Sector(const Sector &); // non-copyable
126 Sector &operator=(const Sector &); // non-assignable
127
128 RefCountedPtr<Galaxy> m_galaxy;
129 SectorCache *m_cache;
130
131 // Only SectorCache(Job) are allowed to create sectors
132 Sector(RefCountedPtr<Galaxy> galaxy, const SystemPath &path, SectorCache *cache);
133 void SetCache(SectorCache *cache)
134 {
135 assert(!m_cache);
136 m_cache = cache;
137 }
138 // sets appropriate factions for all systems in the sector
139};
140
141#endif /* _SECTOR_H */
Definition: CustomSystem.h:45
Definition: Factions.h:21
Definition: GalaxyGenerator.h:17
Definition: GalaxyCache.h:20
Definition: Galaxy.h:18
Definition: RefCounted.h:36
Definition: RefCounted.h:11
Definition: SectorGenerator.h:13
Definition: SectorGenerator.h:31
Definition: SectorGenerator.h:23
Definition: Sector.h:39
static float DistanceBetween(const System *a, const System *b)
Definition: Sector.cpp:114
const CustomSystem * GetCustomSystem() const
Definition: Sector.h:70
System(Sector *sector, int x, int y, int z, Uint32 si)
Definition: Sector.h:41
StarSystem::ExplorationState GetExplored() const
Definition: Sector.h:78
bool IsSameSystem(const SystemPath &b) const
Definition: Sector.h:83
bool InSameSector(const SystemPath &b) const
Definition: Sector.h:87
const std::vector< std::string > & GetOtherNames() const
Definition: Sector.h:60
fixed GetPopulation() const
Definition: Sector.h:76
unsigned GetNumStars() const
Definition: Sector.h:63
SystemBody::BodyType GetStarType(unsigned i) const
Definition: Sector.h:64
const vector3f & GetPosition() const
Definition: Sector.h:61
vector3f GetFullPosition() const
Definition: Sector.h:62
SystemPath GetPath() const
Definition: Sector.h:91
const Uint32 idx
Definition: Sector.h:94
const int sx
Definition: Sector.h:93
Uint32 GetSeed() const
Definition: Sector.h:69
void SetPopulation(fixed pop)
Definition: Sector.h:77
const int sy
Definition: Sector.h:93
bool IsExplored() const
Definition: Sector.h:80
const std::string & GetName() const
Definition: Sector.h:59
const Faction * GetFaction() const
Definition: Sector.h:71
void SetExplored(StarSystem::ExplorationState e, double time)
Definition: Sector.cpp:72
double GetExploredTime() const
Definition: Sector.h:79
const int sz
Definition: Sector.h:93
Definition: Sector.h:20
const int sz
Definition: Sector.h:118
static const float SIZE
Definition: Sector.h:26
SystemPath GetPath() const
Definition: Sector.h:37
const int sy
Definition: Sector.h:118
sigc::signal< void, Sector::System *, StarSystem::ExplorationState, double > onSetExplorationState
Definition: Sector.h:122
void Dump(FILE *file, const char *indent="") const
Definition: Sector.cpp:81
static float DistanceBetween(RefCountedPtr< const Sector > a, int sysIdxA, RefCountedPtr< const Sector > b, int sysIdxB)
Definition: Sector.cpp:32
bool WithinBox(const int Xmin, const int Xmax, const int Ymin, const int Ymax, const int Zmin, const int Zmax) const
Definition: Sector.cpp:48
std::vector< System > m_systems
Definition: Sector.h:117
static float DistanceBetweenSqr(const RefCountedPtr< const Sector > a, const int sysIdxA, const RefCountedPtr< const Sector > b, const int sysIdxB)
Definition: Sector.cpp:40
bool Contains(const SystemPath &sysPath) const
Definition: Sector.cpp:63
const int sx
Definition: Sector.h:118
Definition: StarSystem.h:28
ExplorationState
Definition: StarSystem.h:35
@ eUNEXPLORED
Definition: StarSystem.h:36
BodyType
Definition: SystemBody.h:25
Definition: SystemPath.h:13
Sint32 sectorZ
Definition: SystemPath.h:56
Uint32 systemIndex
Definition: SystemPath.h:57
Sint32 sectorX
Definition: SystemPath.h:54
Sint32 sectorY
Definition: SystemPath.h:55
vector3< float > vector3f
Definition: vector3.h:328