1 /*
2   Copyright (C) 2009 Facundo Domínguez
3 
4   This file is part of Spacejunk.
5 
6   Spacejunk is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10 
11   Foobar is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15 
16   You should have received a copy of the GNU General Public License
17   along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef STARSHIP_H
21 #define STARSHIP_H
22 
23 #include "gamebody.h"
24 #include <math.h>
25 
26 struct TrashData {
27 public:
28     real mass;
TrashDataTrashData29     TrashData(real mass): mass(mass) {};
30 };
31 
32 class Starship : public GameBody, public GraphicSeq {
33 public:
34 
35 	real getFuel();
36 	void setFuel(real fuel);
37 	void setFuelNoMass(real fuel);
38 
39     /**
40      * maximum amount of fuel the ship can carry. Its unit is kgs.
41      */
42     real maxFuel;
43 
44     /**
45      * The trash the ship is carrying.
46      */
47     std::list<TrashData> collected;
48 
49     /**
50      * Builds a ship.
51      * @param pos Ship initial position.
52      * @param vel Ship initial velocity.
53      * @param m Ship mass.
54      * @param graphicid Identifier of the image for this ship.
55      */
56     Starship(const std::string & graphicid,Vector2d pos=Vector2d(0,0),Vector2d vel=Vector2d(0,0),real m=1e3,real w=0);
57     int mitime;
58     int auxtime;
59     /**
60      * Starts impulsing the ship.
61      */
62     void turn_on_engine();
63     /**
64      * Stops impulsing the ship.
65      */
66     void turn_off_engine();
67 
68     void turn_left();
69 
70     void turn_right();
71 
72     void stop_turning();
73 
74     /**
75      * Tells whether the engine is on or not
76      * @returns true iff the engine is on.
77      */
powerOn()78     bool powerOn() {
79         return power;
80     }
81 
82     void collectTrash(GameBody* t);
83     TrashData popTrash();
84     int getTrashCount();
85 
86     void stepShip(int delta);
87 
88     void saveState();
89     Vector2d getAcceleration(real delta);
90     Vector2d getDirection();
91     void setAngle(real a);
92     void draw(int x,int y,real zoom,real angle);
93 
94     void accelerate();
95 
96     real timeToFuel(real delta);
97     real fuelToTime(real fuel);
98 
99     PhysicBody * clone();
100 
101     void copy(PhysicBody * pb) const;
102 
103     std::ostream & serialize(std::ostream & o) const;
104 
105 private:
106     /** Amount of fuel on ship. Its unit is kgs.  */
107     real fuel;
108     real shipMass;
109     bool power;
110     Vector2d dir;
111     int previous_turnoff_delta;
112     real previous_fuel;
113     Graphic flame;
114     int initcount;
115 };
116 
117 #endif // STARSHIP_H
118