| 1 |
|
| 2 |
|
| 3 |
#ifndef SHIPS_H |
| 4 |
#define SHIPS_H |
| 5 |
|
| 6 |
#include <list> |
| 7 |
|
| 8 |
#include <SDL/SDL.h> |
| 9 |
|
| 10 |
#include "actions.h" |
| 11 |
#include "coordinate.h" |
| 12 |
|
| 13 |
class Planet; |
| 14 |
class Player; |
| 15 |
class Selection; |
| 16 |
|
| 17 |
class Ship { |
| 18 |
public: |
| 19 |
enum ShipStates { RESIDENT, MOVING, DEAD }; |
| 20 |
|
| 21 |
private: |
| 22 |
Player *owner; |
| 23 |
Planet *planet; |
| 24 |
Coordinate location; |
| 25 |
Coordinate orbitLocation; |
| 26 |
bool selected; |
| 27 |
double speed; |
| 28 |
|
| 29 |
ShipStates shipState; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
Coordinate fromLocation, toLocation; |
| 34 |
Uint32 fromTime, toTime; |
| 35 |
|
| 36 |
public: |
| 37 |
Ship( Player*, Planet*, Uint32 ); |
| 38 |
|
| 39 |
void die(); |
| 40 |
|
| 41 |
void moveTo( Uint32, Planet * const, ActionQueue* ); |
| 42 |
|
| 43 |
void render( Uint32 color ) const; |
| 44 |
void renderSelection( ) const; |
| 45 |
|
| 46 |
double distance( Ship* ); |
| 47 |
|
| 48 |
void setLocation( double x, double y ); |
| 49 |
void setLocation( const Coordinate& ); |
| 50 |
Coordinate getLocation() const; |
| 51 |
ShipStates getShipState() const; |
| 52 |
void setSelected( bool selected ); |
| 53 |
bool getSelected() const; |
| 54 |
double getSpeed() const; |
| 55 |
Player *getOwner() const; |
| 56 |
Planet *getPlanet() const; |
| 57 |
|
| 58 |
double getDirection() const; |
| 59 |
|
| 60 |
void update(Uint32); |
| 61 |
}; |
| 62 |
|
| 63 |
class Ships : public std::list< Ship* > { |
| 64 |
public: |
| 65 |
|
| 66 |
void removeDeadShips(); |
| 67 |
|
| 68 |
void update(Uint32); |
| 69 |
void render( Uint32 color ) const; |
| 70 |
|
| 71 |
void moveTo(Uint32, Planet* destination, ActionQueue* actionQueue ); |
| 72 |
int numberSelectedShips(); |
| 73 |
|
| 74 |
void select( Selection* selection ); |
| 75 |
void selectAll(); |
| 76 |
|
| 77 |
int countResidents(); |
| 78 |
Ship* getRandomShip(); |
| 79 |
Ship* getRandomResidentShip(); |
| 80 |
Ship* getRandomNearbyResidentShip( Ship* other ); |
| 81 |
Ship* getNearestResidentShip( Planet* c ); |
| 82 |
}; |
| 83 |
|
| 84 |
class ShipMovementAction : public Action { |
| 85 |
private: |
| 86 |
Ship* ship; |
| 87 |
Planet* destination; |
| 88 |
public: |
| 89 |
ShipMovementAction(); |
| 90 |
ShipMovementAction( Ship* ship, Planet* planet ); |
| 91 |
void execute( const Uint32& time ); |
| 92 |
}; |
| 93 |
|
| 94 |
class DeadShipRemovalFunctor { |
| 95 |
public: |
| 96 |
bool operator()(Ship* &s) { |
| 97 |
return s->getShipState() == Ship::DEAD; |
| 98 |
} |
| 99 |
}; |
| 100 |
|
| 101 |
#endif |