File: ships.h

package info (click to toggle)
qonk 0.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,076 kB
  • ctags: 2,026
  • sloc: cpp: 14,978; sh: 3,464; makefile: 200
file content (101 lines) | stat: -rw-r--r-- 1,969 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2005 by Anthony Liekens anthony@liekens.net

#ifndef SHIPS_H
#define SHIPS_H

#include <list>

#include <SDL/SDL.h>

#include "actions.h"
#include "coordinate.h"

class Planet;
class Player;
class Selection;

class Ship {
public:
  enum ShipStates { RESIDENT, MOVING, DEAD };
  
private:
  Player *owner;
  Planet *planet;
  Coordinate location;
  Coordinate orbitLocation;
  bool selected;
  double speed;
  
  ShipStates shipState;
  
  // for movement purposes only
  
  Coordinate fromLocation, toLocation;
  Uint32 fromTime, toTime;
	
public:
  Ship( Player*, Planet*, Uint32 );
  
  void die();
  
  void moveTo( Uint32, Planet * const, ActionQueue* );
  
  void render( Uint32 color ) const;
  void renderSelection( ) const;
  
  double distance( Ship* );
  
  void setLocation( double x, double y );
  void setLocation( const Coordinate& );
  Coordinate getLocation() const;
  ShipStates getShipState() const;
  void setSelected( bool selected );
  bool getSelected() const;
  double getSpeed() const;
  Player *getOwner() const;
  Planet *getPlanet() const;

  double getDirection() const;
  
  void update(Uint32);
};

class Ships : public std::list< Ship* > {
public:

  void removeDeadShips();

  void update(Uint32);
  void render( Uint32 color ) const;
  
  void moveTo(Uint32, Planet* destination, ActionQueue* actionQueue );
  int numberSelectedShips();

  void select( Selection* selection );
  void selectAll();
	
  int countResidents();
  Ship* getRandomShip();
  Ship* getRandomResidentShip();
  Ship* getRandomNearbyResidentShip( Ship* other );
  Ship* getNearestResidentShip( Planet* c );
};

class ShipMovementAction : public Action {
private:
	Ship* ship;
	Planet* destination;
public:
  ShipMovementAction();
  ShipMovementAction( Ship* ship, Planet* planet );
  void execute( const Uint32& time );
};

class DeadShipRemovalFunctor {
public:
  bool operator()(Ship* &s) {
    return s->getShipState() == Ship::DEAD;
  }
};

#endif