1 /* Flotsam.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 FLOTSAM_H_ 14 #define FLOTSAM_H_ 15 16 #include "Angle.h" 17 #include "Body.h" 18 #include "Point.h" 19 20 #include <string> 21 #include <vector> 22 23 class Effect; 24 class Outfit; 25 class Ship; 26 class Visual; 27 28 29 30 class Flotsam : public Body { 31 public: 32 // Constructors for flotsam carrying either a commodity or an outfit. 33 Flotsam(const std::string &commodity, int count); 34 Flotsam(const Outfit *outfit, int count); 35 36 /* Functions provided by the Body base class: 37 Frame GetFrame(int step = -1) const; 38 const Point &Position() const; 39 const Point &Velocity() const; 40 const Angle &Facing() const; 41 Point Unit() const; 42 */ 43 44 // Place this flotsam, and set the given ship as its source. This is a 45 // separate function because a ship may queue up flotsam to dump but take 46 // several frames before it finishes dumping it all. 47 void Place(const Ship &source); 48 // Place flotsam coming from something other than a ship. Optionally specify 49 // the maximum relative velocity, or the exact relative velocity as a vector. 50 void Place(const Body &source, double maxVelocity = .5); 51 void Place(const Body &source, const Point &dv); 52 53 // Move the object one time-step forward. 54 void Move(std::vector<Visual> &visuals); 55 56 // This is the one ship that cannot pick up this flotsam. 57 const Ship *Source() const; 58 // This is what the flotsam contains: 59 const std::string &CommodityType() const; 60 const Outfit *OutfitType() const; 61 int Count() const; 62 // This is how big one "unit" of the flotsam is (in tons). If a ship has 63 // less than this amount of space, it can't pick up anything here. 64 double UnitSize() const; 65 66 // Transfer contents to the collector ship. The flotsam velocity is 67 // stabilized in proportion to the amount being transferred. 68 int TransferTo(Ship *collector); 69 70 71 public: 72 // Amount of tons that is expected per box. 73 static const int TONS_PER_BOX; 74 75 76 private: 77 Angle spin; 78 int lifetime = 0; 79 double drag = 0.999; 80 81 const Ship *source = nullptr; 82 std::string commodity; 83 const Outfit *outfit = nullptr; 84 int count = 0; 85 }; 86 87 88 89 #endif 90