1 /*
2 * XPilot NG, a multiplayer space war game.
3 *
4 * Copyright (C) 1991-2001 by
5 *
6 * Bj�rn Stabell <bjoern@xpilot.org>
7 * Ken Ronny Schouten <ken@xpilot.org>
8 * Bert Gijsbers <bert@xpilot.org>
9 * Dick Balaska <dick@xpilot.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26 #ifndef SHIPSHAPE_H
27 #define SHIPSHAPE_H
28
29 #ifndef TYPES_H
30 /* need position */
31 #include "types.h"
32 #include "const.h"
33 #endif
34
35 #ifndef CLICK_H
36 # include "click.h"
37 #endif
38
39 /*
40 * Please don't change any of these maxima.
41 * It will create incompatibilities and frustration.
42 */
43 #define MIN_SHIP_PTS 3
44 #define MAX_SHIP_PTS 24
45 /* SSHACK needs to double the vertices */
46 #define MAX_SHIP_PTS2 (MAX_SHIP_PTS * 2)
47 #define MAX_GUN_PTS 3
48 #define MAX_LIGHT_PTS 3
49 #define MAX_RACK_PTS 4
50
51 typedef struct {
52 clpos_t *pts[MAX_SHIP_PTS2]; /* the shape rotated many ways */
53 int num_points; /* total points in object */
54 int num_orig_points; /* points before SSHACK */
55 clpos_t cashed_pts[MAX_SHIP_PTS2];
56 int cashed_dir;
57 } shape_t;
58
59 typedef struct { /* Defines wire-obj, i.e. ship */
60 clpos_t *pts[MAX_SHIP_PTS2]; /* the shape rotated many ways */
61 int num_points; /* total points in object */
62 int num_orig_points; /* points before SSHACK */
63 clpos_t cashed_pts[MAX_SHIP_PTS2];
64 int cashed_dir;
65
66 clpos_t engine[RES]; /* Engine position */
67 clpos_t m_gun[RES]; /* Main gun position */
68 int num_l_gun,
69 num_r_gun,
70 num_l_rgun,
71 num_r_rgun; /* number of additional cannons */
72 clpos_t *l_gun[MAX_GUN_PTS], /* Additional cannon positions, left*/
73 *r_gun[MAX_GUN_PTS], /* Additional cannon positions, right*/
74 *l_rgun[MAX_GUN_PTS], /* Additional rear cannon positions, left*/
75 *r_rgun[MAX_GUN_PTS]; /* Additional rear cannon positions, right*/
76 int num_l_light, /* Number of lights */
77 num_r_light;
78 clpos_t *l_light[MAX_LIGHT_PTS], /* Left and right light positions */
79 *r_light[MAX_LIGHT_PTS];
80 int num_m_rack; /* Number of missile racks */
81 clpos_t *m_rack[MAX_RACK_PTS];
82 int shield_radius; /* Radius of shield used by client. */
83
84 #ifdef _NAMEDSHIPS
85 char* name;
86 char* author;
87 #endif
88 } shipshape_t;
89
90
ipos2clpos(ipos_t pos)91 static inline clpos_t ipos2clpos(ipos_t pos)
92 {
93 clpos_t pt;
94
95 pt.cx = PIXEL_TO_CLICK(pos.x);
96 pt.cy = PIXEL_TO_CLICK(pos.y);
97
98 return pt;
99 }
100
clpos2position(clpos_t pt)101 static inline position_t clpos2position(clpos_t pt)
102 {
103 position_t pos;
104
105 pos.x = CLICK_TO_FLOAT(pt.cx);
106 pos.y = CLICK_TO_FLOAT(pt.cy);
107
108 return pos;
109 }
110
111 extern shipshape_t *Default_ship(void);
112 extern void Free_ship_shape(shipshape_t *ship);
113 extern shipshape_t *Parse_shape_str(char *str);
114 extern shipshape_t *Convert_shape_str(char *str);
115 extern void Calculate_shield_radius(shipshape_t *ship);
116 extern int Validate_shape_str(char *str);
117 extern void Convert_ship_2_string(shipshape_t *ship, char *buf, char *ext,
118 unsigned shape_version);
119 extern void Rotate_point(clpos_t pt[RES]);
120 extern void Rotate_position(position_t pt[RES]);
121 extern clpos_t *Shape_get_points(shape_t *s, int dir);
122
123 static inline clpos_t
Ship_get_point_clpos(shipshape_t * ship,int i,int dir)124 Ship_get_point_clpos(shipshape_t *ship, int i, int dir)
125 {
126 return ship->pts[i][dir];
127 }
128 static inline clpos_t
Ship_get_engine_clpos(shipshape_t * ship,int dir)129 Ship_get_engine_clpos(shipshape_t *ship, int dir)
130 {
131 return ship->engine[dir];
132 }
133 static inline clpos_t
Ship_get_m_gun_clpos(shipshape_t * ship,int dir)134 Ship_get_m_gun_clpos(shipshape_t *ship, int dir)
135 {
136 return ship->m_gun[dir];
137 }
138 static inline clpos_t
Ship_get_l_gun_clpos(shipshape_t * ship,int gun,int dir)139 Ship_get_l_gun_clpos(shipshape_t *ship, int gun, int dir)
140 {
141 return ship->l_gun[gun][dir];
142 }
143 static inline clpos_t
Ship_get_r_gun_clpos(shipshape_t * ship,int gun,int dir)144 Ship_get_r_gun_clpos(shipshape_t *ship, int gun, int dir)
145 {
146 return ship->r_gun[gun][dir];
147 }
148 static inline clpos_t
Ship_get_l_rgun_clpos(shipshape_t * ship,int gun,int dir)149 Ship_get_l_rgun_clpos(shipshape_t *ship, int gun, int dir)
150 {
151 return ship->l_rgun[gun][dir];
152 }
153 static inline clpos_t
Ship_get_r_rgun_clpos(shipshape_t * ship,int gun,int dir)154 Ship_get_r_rgun_clpos(shipshape_t *ship, int gun, int dir)
155 {
156 return ship->r_rgun[gun][dir];
157 }
158 static inline clpos_t
Ship_get_l_light_clpos(shipshape_t * ship,int l,int dir)159 Ship_get_l_light_clpos(shipshape_t *ship, int l, int dir)
160 {
161 return ship->l_light[l][dir];
162 }
163 static inline clpos_t
Ship_get_r_light_clpos(shipshape_t * ship,int l,int dir)164 Ship_get_r_light_clpos(shipshape_t *ship, int l, int dir)
165 {
166 return ship->r_light[l][dir];
167 }
168 static inline clpos_t
Ship_get_m_rack_clpos(shipshape_t * ship,int rack,int dir)169 Ship_get_m_rack_clpos(shipshape_t *ship, int rack, int dir)
170 {
171 return ship->m_rack[rack][dir];
172 }
173
174
175 static inline position_t
Ship_get_point_position(shipshape_t * ship,int i,int dir)176 Ship_get_point_position(shipshape_t *ship, int i, int dir)
177 {
178 return clpos2position(Ship_get_point_clpos(ship, i, dir));
179 }
180 static inline position_t
Ship_get_engine_position(shipshape_t * ship,int dir)181 Ship_get_engine_position(shipshape_t *ship, int dir)
182 {
183 return clpos2position(Ship_get_engine_clpos(ship, dir));
184 }
185 static inline position_t
Ship_get_m_gun_position(shipshape_t * ship,int dir)186 Ship_get_m_gun_position(shipshape_t *ship, int dir)
187 {
188 return clpos2position(Ship_get_m_gun_clpos(ship, dir));
189 }
190 static inline position_t
Ship_get_l_gun_position(shipshape_t * ship,int gun,int dir)191 Ship_get_l_gun_position(shipshape_t *ship, int gun, int dir)
192 {
193 return clpos2position(Ship_get_l_gun_clpos(ship, gun, dir));
194 }
195 static inline position_t
Ship_get_r_gun_position(shipshape_t * ship,int gun,int dir)196 Ship_get_r_gun_position(shipshape_t *ship, int gun, int dir)
197 {
198 return clpos2position(Ship_get_r_gun_clpos(ship, gun, dir));
199 }
200 static inline position_t
Ship_get_l_rgun_position(shipshape_t * ship,int gun,int dir)201 Ship_get_l_rgun_position(shipshape_t *ship, int gun, int dir)
202 {
203 return clpos2position(Ship_get_l_rgun_clpos(ship, gun, dir));
204 }
205 static inline position_t
Ship_get_r_rgun_position(shipshape_t * ship,int gun,int dir)206 Ship_get_r_rgun_position(shipshape_t *ship, int gun, int dir)
207 {
208 return clpos2position(Ship_get_r_rgun_clpos(ship, gun, dir));
209 }
210 static inline position_t
Ship_get_l_light_position(shipshape_t * ship,int l,int dir)211 Ship_get_l_light_position(shipshape_t *ship, int l, int dir)
212 {
213 return clpos2position(Ship_get_l_light_clpos(ship, l, dir));
214 }
215 static inline position_t
Ship_get_r_light_position(shipshape_t * ship,int l,int dir)216 Ship_get_r_light_position(shipshape_t *ship, int l, int dir)
217 {
218 return clpos2position(Ship_get_r_light_clpos(ship, l, dir));
219 }
220 static inline position_t
Ship_get_m_rack_position(shipshape_t * ship,int rack,int dir)221 Ship_get_m_rack_position(shipshape_t *ship, int rack, int dir)
222 {
223 return clpos2position(Ship_get_m_rack_clpos(ship, rack, dir));
224 }
225
226 #endif
227