forked from endless-sky/endless-sky-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSystem.h
155 lines (121 loc) · 5.11 KB
/
System.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* System.h
Copyright (c) 2014 by Michael Zahniser
Endless Sky is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later version.
Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
*/
#ifndef SYSTEM_H_
#define SYSTEM_H_
#include "StellarObject.h"
#include <QVector2D>
#include <QString>
#include <map>
#include <set>
#include <vector>
class DataNode;
class DataWriter;
class Planet;
// Class representing a star system. This includes characteristics like what
// ships enter that system, what asteroids are present, who owns the system, and
// what prices the trade goods have in that system. It also includes the stellar
// objects in each system, and the hyperspace links between systems.
class System {
public:
struct Asteroid {
QString type; int count; double energy;
Asteroid(const QString &type, int count, double energy) : type(type), count(count), energy(energy) {}
};
struct Fleet {
QString name; int period;
Fleet(const QString &name, int period) : name(name), period(period) {}
};
struct Minable {
QString type; int count; double energy;
Minable(const QString &type, int count, double energy) : type(type), count(count), energy(energy) {}
};
public:
// Load a system's description.
void Load(const DataNode &node);
void Save(DataWriter &file) const;
// Get this system's name and position (in the star map).
const QString &Name() const;
const QVector2D &Position() const;
// Get this system's government.
const QString &Government() const;
// Get a list of systems you can travel to through hyperspace from here.
const std::set<QString> &Links() const;
// Get the stellar object locations on the most recently set date.
std::vector<StellarObject> &Objects();
const std::vector<StellarObject> &Objects() const;
// Get the habitable zone's center.
double HabitableZone() const;
// Get the radius of the zone occupied by the given stellar object. This
// zone includes the object and anything that orbits around it. If this
// object is in orbit around something else, this function returns 0.
double OccupiedRadius(const StellarObject &object) const;
double OccupiedRadius() const;
double StarRadius() const;
// Get the specification of how many asteroids of each type there are.
const std::vector<Asteroid> &Asteroids() const;
// Get the specification of how many minables of each type there are.
std::vector<Minable> &Minables();
const std::vector<Minable> &Minables() const;
// Get the price of the given commodity in this system.
int Trade(const QString &commodity) const;
// Get the probabilities of various fleets entering this system.
std::vector<Fleet> &Fleets();
const std::vector<Fleet> &Fleets() const;
// Position the planets, etc.
void SetDay(double day);
// Modify the system:
void Init(const QString &name, const QVector2D &position);
void SetName(const QString &name);
void SetPosition(const QVector2D &pos);
void SetGovernment(const QString &gov);
void ToggleLink(System *other);
void ChangeLink(const QString &from, const QString &to);
void SetTrade(const QString &commodity, int value);
// Editing the stellar objects and their locations:
void Move(StellarObject *object, double dDistance, double dAngle = 0.);
void ChangeAsteroids();
void ChangeMinables();
void ChangeStar();
void ChangeSprite(StellarObject *object);
void AddPlanet();
void AddMoon(StellarObject *object, bool isStation = false);
void Randomize(bool allowHabitable, bool requireHabitable);
void Delete(StellarObject *object);
private:
void LoadObject(const DataNode &node, int parent = -1);
void SaveObject(DataWriter &file, const StellarObject &object) const;
void Recompute(StellarObject &object, bool updateOffset = true);
// Get a list of all sprites that are in use already.
std::set<QString> Used() const;
private:
// Name and position (within the star map) of this system.
QString name;
QVector2D position;
QString government;
// Hyperspace links to other systems.
std::set<QString> links;
// Stellar objects, listed in such an order that an object's parents are
// guaranteed to appear before it (so that if we traverse the vector in
// order, updating positions, an object's parents will already be at the
// proper position before that object is updated).
std::vector<StellarObject> objects;
double habitable;
QString haze;
QString music;
std::vector<Asteroid> asteroids;
std::map<QString, int> trade;
std::vector<Fleet> fleets;
std::vector<Minable> minables;
double belt;
std::list<DataNode> unparsed;
// Keep track of the current time step.
double timeStep;
};
#endif