1 /*
2 ** Copyright (C) 1993-2013 Mark B. Hanson (mbh@panix.com)
3 **
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2, or (at your option)
7 ** any later version.
8 **
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ** GNU General Public License for more details.
13 **
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 // @(#)$Id: ship.h 1344 2013-04-05 21:18:39Z mark $
19 
20 #ifdef	XSC_SHIP_H
21 
22 class Ship;
23 
24 #else	// XSC_SHIP_H
25 #define	XSC_SHIP_H
26 
27 #include "castle.h"
28 #include "ething.h"
29 #include "king.h"
30 #include "laser.h"
31 #include "minefield.h"
32 #include "stats.h"
33 #include "xything.h"
34 
35 const int NUM_SHIP_POINTS = 16;
36 
37 extern const struct coords ship_points[NUM_SHIP_POINTS];
38 
39 
40 class Ship : public virtual Ething {
41 private:
42     enum ship_states {
43 	SHIP_LIVING,
44 	SHIP_EXPLODING,
45 	SHIP_RESTING,
46 	SHIP_DEAD
47     };
48     enum ship_states state;
49 
50     bool user_rotating_cw;
51     bool user_rotating_ccw;
52     bool user_thrusting;
53     int max_shots;
54     Laser *lasers;
55     Ething *segments;
56     Stamp time_of_death;
57     Stamp pause_start;
58     Stamp pause_sum;
59     coords *split_points;
60 
61     float initial_x(void);
62     float initial_y(void);
63 
64     void bounce(Castle *);
65 
66 public:
67     Ship(void);
68     ~Ship(void);
69 
70     void render(const bool);
71 
72     void move(Castle *, King *, Minefield *, Stats *);
73     void turn(void);
74     void fire(void) const;
75     void resize(const int, const int);
76     bool hit(Xything *);
77     void reincarnate(void);
78 
79     void rotate_cw(const enum key_state);
80     void rotate_ccw(const key_state);
81     void thrust(const key_state);
82     bool rotating_cw(void) const;
83     bool rotating_ccw(void) const;
84     bool thrusting(void) const;
85     bool alive(void) const;
86     void pause(const bool);
87 };
88 
89 
90 inline void
rotate_cw(const enum key_state n)91 Ship::rotate_cw(const enum key_state n)
92 {
93     user_rotating_cw = (n == KEY_DOWN);
94 } // Ship::rotate_cw
95 
96 
97 inline void
rotate_ccw(const key_state n)98 Ship::rotate_ccw(const key_state n)
99 {
100     user_rotating_ccw = (n == KEY_DOWN);
101 } // Ship::rotate_ccw
102 
103 
104 inline void
thrust(const key_state n)105 Ship::thrust(const key_state n)
106 {
107     user_thrusting = (n == KEY_DOWN);
108 } // Ship::thrust
109 
110 
111 inline bool
rotating_cw(void)112 Ship::rotating_cw(void) const
113 {
114     return user_rotating_cw;
115 } // Ship::rotating_cw
116 
117 
118 inline bool
rotating_ccw(void)119 Ship::rotating_ccw(void) const
120 {
121     return user_rotating_ccw;
122 } // Ship::rotating_ccw
123 
124 
125 inline bool
thrusting(void)126 Ship::thrusting(void) const
127 {
128     return user_thrusting;
129 } // Ship::thrusting
130 
131 
132 inline bool
alive(void)133 Ship::alive(void) const
134 {
135     return (state == SHIP_LIVING);
136 } // Ship::alive
137 
138 
139 inline void
pause(const bool pause_state)140 Ship::pause(const bool pause_state)
141 {
142     if (pause_state) {
143 	pause_start = time_now;
144     } else {
145 	pause_sum += time_now - pause_start;
146     }
147 } // Ship::pause
148 
149 #endif	// XSC_SHIP_H
150