Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
StarSystem.h
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: StarSystem.h
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Various heavenly bodies
13 */
14 
15 #ifndef StarSystem_h
16 #define StarSystem_h
17 
18 #include "Types.h"
19 #include "Solid.h"
20 #include "Bitmap.h"
21 #include "Geometry.h"
22 #include "Text.h"
23 #include "term.h"
24 #include "List.h"
25 
26 // +--------------------------------------------------------------------+
27 
28 class StarSystem;
29 class Orbital;
30 class OrbitalBody;
31 class OrbitalRegion;
32 class TerrainRegion;
33 
34 class Graphic;
35 class Light;
36 class Scene;
37 
38 // +--------------------------------------------------------------------+
39 
41 {
42 public:
43  static const char* TYPENAME() { return "StarSystem"; }
44 
45  StarSystem(const char* name, Point loc, int iff=0, int s=4);
46  virtual ~StarSystem();
47 
48  int operator == (const StarSystem& s) const { return name == s.name; }
49 
50  // operations:
51  virtual void Load();
52  virtual void Create();
53  virtual void Destroy();
54 
55  virtual void Activate(Scene& scene);
56  virtual void Deactivate();
57 
58  virtual void ExecFrame();
59 
60  // accessors:
61  const char* Name() const { return name; }
62  const char* Govt() const { return govt; }
63  const char* Description() const { return description; }
64  int Affiliation() const { return affiliation; }
65  int Sequence() const { return seq; }
66  Point Location() const { return loc; }
67  int NumStars() const { return sky_stars; }
68  int NumDust() const { return sky_dust; }
69  Color Ambient() const;
70 
75 
76  Orbital* FindOrbital(const char* name);
77  OrbitalRegion* FindRegion(const char* name);
78 
79  void SetActiveRegion(OrbitalRegion* rgn);
80 
81  static void SetBaseTime(double t, bool absolute=false);
82  static double GetBaseTime();
83  static double Stardate() { return stardate; }
84  static void CalcStardate();
85  double Radius() const { return radius; }
86 
87  void SetSunlight(Color color, double brightness=1);
88  void SetBacklight(Color color, double brightness=1);
89  void RestoreTrueSunColor();
90  bool HasLinkTo(StarSystem* s) const;
91  const Text& GetDataPath() const { return datapath; }
92 
93 protected:
94  void ParseStar(TermStruct* val);
95  void ParsePlanet(TermStruct* val);
96  void ParseMoon(TermStruct* val);
97  void ParseRegion(TermStruct* val);
98  void ParseTerrain(TermStruct* val);
99  void ParseLayer(TerrainRegion* rgn, TermStruct* val);
100 
101  void CreateBody(OrbitalBody& body);
103 
104  char filename[64];
110  int seq;
112  static double stardate;
113  double radius;
115 
117  int sky_dust;
121  double sky_uscale;
122  double sky_vscale;
126  double sun_scale;
129 
134 
138 
141 
143 };
144 
145 // +--------------------------------------------------------------------+
146 
147 class Star
148 {
149 public:
150  static const char* TYPENAME() { return "Star"; }
151 
152  Star(const char* n, const Point& l, int s) : name(n), loc(l), seq(s) { }
153  virtual ~Star() { }
154 
156  O, B, A, F, G, K, M };
157 
158  int operator == (const Star& s) const { return name == s.name; }
159 
160  // accessors:
161  const char* Name() const { return name; }
162  const Point& Location() const { return loc; }
163  int Sequence() const { return seq; }
164  Color GetColor() const;
165  int GetSize() const;
166 
167  static Color GetColor(int spectral_class);
168  static int GetSize(int spectral_class);
169 
170 protected:
173  int seq;
174 };
175 
176 // +--------------------------------------------------------------------+
177 
178 class Orbital
179 {
180  friend class StarSystem;
181 
182 public:
183  static const char* TYPENAME() { return "Orbital"; }
184 
186 
187  Orbital(StarSystem* sys, const char* n, OrbitalType t, double m, double r, double o, Orbital* p=0);
188  virtual ~Orbital();
189 
190  int operator == (const Orbital& o) const { return type == o.type && name == o.name && system == o.system; }
191  int operator < (const Orbital& o) const { return loc.length() < o.loc.length(); }
192  int operator <= (const Orbital& o) const { return loc.length() <= o.loc.length(); }
193 
194  // operations:
195  virtual void Update();
196  Point PredictLocation(double delta_t);
197 
198  // accessors:
199  const char* Name() const { return name; }
200  OrbitalType Type() const { return type; }
201  int SubType() const { return subtype; }
202 
203  const char* Description() const { return description; }
204  double Mass() const { return mass; }
205  double Radius() const { return radius; }
206  double Rotation() const { return rotation; }
207  double RotationPhase()const { return theta; }
208  double Orbit() const { return orbit; }
209  bool Retrograde() const { return retro; }
210  double Phase() const { return phase; }
211  double Period() const { return period; }
212  Point Location() const { return loc; }
213  Graphic* Rep() const { return rep; }
214 
215  const Bitmap& GetMapIcon() const { return map_icon; }
216  void SetMapIcon(const Bitmap& img);
217 
218  StarSystem* System() const { return system; }
219  Orbital* Primary() const { return primary; }
221 
222 protected:
225  int subtype;
226 
228  double mass;
229  double radius;
230  double rotation;
231  double theta;
232  double orbit;
233  double phase;
234  double period;
235  double velocity;
237  bool retro;
240 
243 
245 };
246 
247 // +--------------------------------------------------------------------+
248 
249 class OrbitalBody : public Orbital
250 {
251  friend class StarSystem;
252 
253 public:
254  static const char* TYPENAME() { return "OrbitalBody"; }
255 
256  OrbitalBody(StarSystem* sys, const char* n, OrbitalType t, double m, double r, double o, Orbital* prime=0);
257  virtual ~OrbitalBody();
258 
259  // operations:
260  virtual void Update();
261 
262  // accessors:
264 
265  double Tilt() const { return tilt; }
266  double RingMin() const { return ring_min; }
267  double RingMax() const { return ring_max; }
268 
269  double LightIntensity() const { return light; }
270  Color LightColor() const { return color; }
271  bool Luminous() const { return luminous; }
272 
273 protected:
281 
282  double tscale;
283  double light;
284  double ring_min;
285  double ring_max;
286  double tilt;
292  bool luminous;
293 
295 };
296 
297 // +--------------------------------------------------------------------+
298 
299 class OrbitalRegion : public Orbital
300 {
301  friend class StarSystem;
302 
303 public:
304  static const char* TYPENAME() { return "OrbitalRegion"; }
305 
306  OrbitalRegion(StarSystem* sys, const char* n, double m, double r, double o, Orbital* prime=0);
307  virtual ~OrbitalRegion();
308 
309  double GridSpace() const { return grid; }
310  double Inclination() const { return inclination; }
311  int Asteroids() const { return asteroids; }
312  List<Text>& Links() { return links; }
313 
314 protected:
315  double grid;
316  double inclination;
319 };
320 
321 #endif StarSystem_h
322