1 /*
2  * SDLRoids - An Astroids clone.
3  *
4  * Copyright (c) 2000 David Hedbor <david@hedbor.org>
5  * 	based on xhyperoid by Russel Marks.
6  * 	xhyperoid is based on a Win16 game, Hyperoid by Edward Hutchins
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  */
18 
19 /*
20  * misc.h - misc defines and prototypes.
21  */
22 
23 /* extra data types and defines */
24 
25 typedef unsigned char BYTE;
26 
27 typedef struct { int x,y; } POINT;
28 typedef struct { int left,right,top,bottom; } RECT;
29 
30 
31 /* typedefs and defines */
32 #ifndef TRUE
33 #define TRUE		1
34 #define FALSE		0
35 #endif
36 
37 /* color stuff */
38 #define PALETTE_SIZE 16
39 typedef enum
40 {
41   BLACK, DKGREY, GREY, WHITE,
42   DKRED, RED, DKGREEN, GREEN, DKBLUE, BLUE,
43   DKYELLOW, YELLOW, DKCYAN, CYAN, DKMAGENTA, MAGENTA
44 } COLORS;
45 
46 enum
47 {
48   KEY_F1, KEY_TAB, KEY_S,
49   KEY_LEFT, KEY_RIGHT, KEY_DOWN, KEY_UP,
50   KEY_SPACE, KEY_ESC
51 };
52 
53 /* degrees scaled to integer math */
54 #define DEGREE_SIZE 256
55 #define DEGREE_MASK 255
56 #define DEGREE_MAX 0x4000
57 
58 /* object limits */
59 #define MAX_PTS 8
60 #define MAX_OBJS 200
61 #define MAX_COORD 0x2000
62 #define CLIP_COORD (MAX_COORD+300)
63 
64 /* timer stuff */
65 #define FPS 50
66 #define RESTART_DELAY_FRAMES 60
67 
68 /* restart modes */
69 typedef enum { RESTART_GAME, RESTART_LEVEL, RESTART_NEXTLEVEL, RESTART_DEATH } RESTART_MODE;
70 
71 /* letter scaling */
72 #define LETTER_MAX 256
73 
74 /* extra life every */
75 #define EXTRA_LIFE 100000
76 
77 /* list node */
78 typedef struct tagNODE
79 {
80   struct tagNODE  *npNext, *npPrev;
81 } NODE;
82 
83 /* list header */
84 typedef struct
85 {
86   NODE *npHead, *npTail;
87 } LIST;
88 
89 /* object descriptor */
90 typedef struct
91 {
92   NODE    Link;               /* for object list */
93   POINT   Pos;                /* position of center of object */
94   POINT   Vel;                /* velocity in logical units/update */
95   int     nMass;              /* mass of object */
96   int     nDir;               /* direction in degrees */
97   int     nSpin;              /* angular momentum degrees/update */
98   int     nCount;             /* used by different objects */
99   int     nDelay;             /* used by different objects */
100   BYTE    byColor;            /* palette color */
101   BYTE    byPts;              /* number of points in object */
102   POINT   Pts[MAX_PTS];       /* points making up an object */
103   POINT   Old[MAX_PTS];       /* last plotted location */
104 } OBJ;
105 
106 /* ship shield struct */
107 typedef struct
108 {
109   POINT   Pos;                /* position of center of object */
110   POINT   Old;		      /* old position of the object */
111   BYTE    byColor;            /* palette color */
112   int     Radius;             /* circle radius */
113 } CIRCLE;
114 
115 typedef struct {
116   OBJ 	*Player;	/* The player object */
117   CIRCLE Shield;	/* The shield circle object */
118   int 	 isSafe;	/* 1 == shields are on, 0 = shields off */
119   int 	 Bombs;         /* Number of bombs left */
120   int    Guns;          /* Number of guns */
121   float  GunRange;      /* Gun range modified */
122   int    Score; 	/* Player Score */
123   int    LastLife;     /* Last score based extra life */
124   int    Shields;       /* Shield strength */
125   int    ExtraShields;  /* Bonus shield strength */
126 } PLAYER;
127 
128 
129 /* inline macro functions */
130 
131 /* function aliases */
132 #define AddHeadObj(l,o) AddHead((l),((NODE *)o))
133 #define RemHeadObj(l) ((OBJ *)RemHead(l))
134 #define RemoveObj(l,o) Remove((l),((NODE *)o))
135 #define HeadObj(l) ((OBJ *)((l)->npHead))
136 #define NextObj(o) ((OBJ *)((o)->Link.npNext))
137 
138 
139 /* size of an array */
140 #define DIM(x) (sizeof(x)/sizeof((x)[0]))
141 
142 /* faster than MulDiv! */
143 #define MULDEG(x,y) ((int)(((long)(x)*(y))/DEGREE_MAX))
144 
145 /* DEG - convert an integer into a degree lookup index */
146 #define DEG(x) ((int)(x)&DEGREE_MASK)
147 
148 /* ACCEL - accelerate an object in a given direction */
149 #define ACCEL(o,d,s) \
150 	(((o)->Vel.x += MULDEG((s),nCos[DEG(d)])), \
151 	((o)->Vel.y += MULDEG((s),nSin[DEG(d)])))
152 
153 /* PTINRECT - a faster PtInRect */
154 #define PTINRECT(r,p) \
155 	(((r)->left <= (p).x) && ((r)->right > (p).x) && \
156 	((r)->top <= (p).y) && ((r)->bottom > (p).y))
157 
158 /* INTRECT - a faster IntersectRect that just returns the condition */
159 #define INTRECT(r1,r2) \
160 	(((r1)->right >= (r2)->left) && \
161 	((r1)->left < (r2)->right) && \
162 	((r1)->bottom >= (r2)->top) && \
163 	((r1)->top < (r2)->bottom))
164 
165 /* MKRECT - make a rect around a point */
166 #define MKRECT(r,p,s) \
167 	(((r)->left = ((p).x-(s))), ((r)->right = ((p).x+(s))), \
168 	((r)->top = ((p).y-(s))), ((r)->bottom = ((p).y+(s))))
169 
170 /* this seems to be what MulDiv does -rjm */
171 #define MulDiv(x,y,z) ((x)*(y)/(z))
172 
173 extern void BreakRoid( OBJ *, OBJ * );
174 extern void ExplodeBadguys( LIST * );
175 extern void Explode( OBJ * );
176 
177 extern char *bindir;
178