1 /* Minable.h 2 Copyright (c) 2016 by Michael Zahniser 3 4 Endless Sky is free software: you can redistribute it and/or modify it under the 5 terms of the GNU General Public License as published by the Free Software 6 Foundation, either version 3 of the License, or (at your option) any later version. 7 8 Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 */ 12 13 #ifndef MINABLE_H_ 14 #define MINABLE_H_ 15 16 #include "Body.h" 17 18 #include "Angle.h" 19 20 #include <list> 21 #include <map> 22 #include <memory> 23 #include <string> 24 #include <vector> 25 26 class DataNode; 27 class Effect; 28 class Flotsam; 29 class Outfit; 30 class Projectile; 31 class Visual; 32 33 34 35 // Class representing an asteroid or other minable object that orbits in an 36 // ellipse around the system center. 37 class Minable : public Body { 38 public: 39 /* Inherited from Body: 40 Frame GetFrame(int step = -1) const; 41 const Mask &GetMask(int step = -1) const; 42 const Point &Position() const; 43 const Point &Velocity() const; 44 const Angle &Facing() const; 45 Point Unit() const; */ 46 47 // Load a definition of a minable object. 48 void Load(const DataNode &node); 49 const std::string &Name() const; 50 51 // Place a minable object with up to the given energy level, on a random 52 // orbit and a random position along that orbit. 53 void Place(double energy, double beltRadius); 54 55 // Move the object forward one step. If it has been reduced to zero hull, it 56 // will "explode" instead of moving, creating flotsam and explosion effects. 57 // In that case it will return false, meaning it should be deleted. 58 bool Move(std::vector<Visual> &visuals, std::list<std::shared_ptr<Flotsam>> &flotsam); 59 60 // Damage this object (because a projectile collided with it). 61 void TakeDamage(const Projectile &projectile); 62 63 // Determine what flotsam this asteroid will create. 64 const std::map<const Outfit *, int> &Payload() const; 65 66 67 private: 68 std::string name; 69 // Current angular position relative to the focus of the elliptical orbit, 70 // in radians. An angle of zero is the periapsis point. 71 double theta; 72 // Eccentricity of the orbit. 0 is circular and 1 is a parabola. 73 double eccentricity; 74 // Angular momentum (radius^2 * angular velocity) will always be conserved. 75 // The object's mass can be ignored, because it is a constant. 76 double angularMomentum; 77 // Scale of the orbit. This is the orbital radius when theta is 90 degrees. 78 // The periapsis and apoapsis radii are scale / (1 +- eccentricity). 79 double scale; 80 // Rotation of the orbit - that is, the angle of periapsis - in radians. 81 double rotation; 82 // Rate of spin of the object. 83 Angle spin; 84 85 // Cache the current orbital radius. It can be calculated from theta and the 86 // parameters above, but this avoids having to calculate every radius twice. 87 double radius; 88 89 // Remaining "hull" strength of the object, before it is destroyed. 90 double hull = 1000.; 91 // Material released when this object is destroyed. Each payload item only 92 // has a 25% chance of surviving, meaning that usually the yield is much 93 // lower than the defined limit but occasionally you get quite lucky. 94 std::map<const Outfit *, int> payload; 95 // Explosion effects created when this object is destroyed. 96 std::map<const Effect *, int> explosions; 97 }; 98 99 100 101 #endif 102