Bring hunt in from OpenBSD. The best multi-player terminal game ever!
[dragonfly.git] / games / hunt / huntd / server.h
1 /*
2  * Copyright (c) 1983-2003, Regents of the University of California.
3  * All rights reserved.
4  * 
5  * Redistribution and use in source and binary forms, with or without 
6  * modification, are permitted provided that the following conditions are 
7  * met:
8  * 
9  * + Redistributions of source code must retain the above copyright 
10  *   notice, this list of conditions and the following disclaimer.
11  * + Redistributions in binary form must reproduce the above copyright 
12  *   notice, this list of conditions and the following disclaimer in the 
13  *   documentation and/or other materials provided with the distribution.
14  * + Neither the name of the University of California, San Francisco nor 
15  *   the names of its contributors may be used to endorse or promote 
16  *   products derived from this software without specific prior written 
17  *   permission.
18  * 
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 
20  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
22  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * $OpenBSD: server.h,v 1.9 2004/01/16 00:13:19 espie Exp $
32  * $NetBSD: hunt.h,v 1.5 1998/09/13 15:27:28 hubertf Exp $
33  * $DragonFly: src/games/hunt/huntd/server.h,v 1.1 2008/09/02 21:50:21 dillon Exp $
34  */
35
36
37 #include <stdio.h>
38 #include <sys/socket.h>
39
40 #ifndef __GNUC__
41 #define __attribute__(x)
42 #endif
43
44 /*
45  * Choose MAXPL and MAXMON carefully.  The screen is assumed to be
46  * 23 lines high and will only tolerate (MAXPL == 17 && MAXMON == 0)
47  * or (MAXPL + MAXMON <= 16).
48  */
49 #define MAXPL           14
50 #define MAXMON          2
51 #if (MAXPL + MAXMON > 16)
52 #warning "MAXPL + MAXMON is excessive"
53 #endif
54
55 #define MSGLEN          SCREEN_WIDTH
56
57 #define UBOUND          1
58 #define DBOUND          (HEIGHT - 1)
59 #define LBOUND          1
60 #define RBOUND          (WIDTH - 1)
61
62 #define NASCII          128
63
64 /* Layout of the scoreboard: */
65 #define STAT_LABEL_COL  60
66 #define STAT_VALUE_COL  74
67 #define STAT_NAME_COL   61
68 #define STAT_SCAN_COL   (STAT_NAME_COL + 5)
69 #define STAT_AMMO_ROW   0
70 #define STAT_GUN_ROW    1
71 #define STAT_DAM_ROW    2
72 #define STAT_KILL_ROW   3
73 #define STAT_PLAY_ROW   5
74 #define STAT_MON_ROW    (STAT_PLAY_ROW + MAXPL + 1)
75 #define STAT_NAME_LEN   18
76
77 /* Number of boots: */
78 #define NBOOTS          2
79
80 /* Bitmask of directions */
81 #define NORTH           01
82 #define SOUTH           02
83 #define EAST            010
84 #define WEST            020
85
86 # undef CTRL
87 #define CTRL(x) ((x) & 037)
88
89 #define BULREQ          1               /* 0 */
90 #define GRENREQ         9               /* 1 */
91 #define SATREQ          25              /* 2 */
92 #define BOMB7REQ        49              /* 3 */
93 #define BOMB9REQ        81              /* 4 */
94 #define BOMB11REQ       121             /* 5 */
95 #define BOMB13REQ       169             /* 6 */
96 #define BOMB15REQ       225             /* 7 */
97 #define BOMB17REQ       289             /* 8 */
98 #define BOMB19REQ       361             /* 9 */
99 #define BOMB21REQ       441             /* 10 */
100 #define MAXBOMB                            11
101
102 #define SLIMEREQ        5               /* 0 */
103 #define SSLIMEREQ       10              /* 1 */
104 #define SLIME2REQ       15              /* 2 */
105 #define SLIME3REQ       20              /* 3 */
106 #define MAXSLIME                           4
107
108 #define EXPLEN          16
109
110 #define _scan_char(pp)  (((pp)->p_scan < 0) ? ' ' : '*')
111 #define _cloak_char(pp) (((pp)->p_cloak < 0) ? _scan_char(pp) : '+')
112 #define stat_char(pp)   (((pp)->p_flying < 0) ? _cloak_char(pp) : FLYER)
113
114 typedef struct bullet_def       BULLET;
115 typedef struct expl_def         EXPL;
116 typedef struct player_def       PLAYER;
117 typedef struct ident_def        IDENT;
118 typedef struct regen_def        REGEN;
119
120 #define ALL_PLAYERS             ((PLAYER *)1)
121
122 struct ident_def {
123         char    i_name[NAMELEN];
124         char    i_team;
125         u_int32_t i_machine;
126         uid_t   i_uid;
127         float   i_kills;
128         int     i_entries;
129         float   i_score;
130         int     i_absorbed;
131         int     i_faced;
132         int     i_shot;
133         int     i_robbed;
134         int     i_slime;
135         int     i_missed;
136         int     i_ducked;
137         int     i_gkills, i_bkills, i_deaths, i_stillb, i_saved;
138         IDENT   *i_next;
139 };
140
141 struct player_def {
142         IDENT   *p_ident;
143         char    p_over;
144         int     p_face;
145         int     p_undershot;
146         int     p_flying;
147         int     p_flyx, p_flyy;
148         int     p_nboots;
149         FILE    *p_output;
150         int     p_fd;
151         int     p_mask;
152         int     p_damage;
153         int     p_damcap;
154         int     p_ammo;
155         int     p_ncshot;
156         int     p_scan;
157         int     p_cloak;
158         int     p_x, p_y;
159         int     p_ncount;
160         int     p_nexec;
161         long    p_nchar;
162         char    p_death[MSGLEN];
163         char    p_maze[HEIGHT][WIDTH2];
164         int     p_curx, p_cury;
165         int     p_lastx, p_lasty;
166         char    p_cbuf[BUFSIZ];
167 };
168
169 struct bullet_def {
170         int     b_x, b_y;
171         int     b_face;
172         int     b_charge;
173         char    b_type;
174         char    b_size;
175         char    b_over;
176         PLAYER  *b_owner;
177         IDENT   *b_score;
178         FLAG    b_expl;
179         BULLET  *b_next;
180 };
181
182 struct expl_def {
183         int     e_x, e_y;
184         char    e_char;
185         EXPL    *e_next;
186 };
187
188 struct regen_def {
189         int     r_x, r_y;
190         REGEN   *r_next;
191 };
192
193 struct spawn {
194         int             fd;
195         int             reading_msg;
196         struct sockaddr source;
197         socklen_t       sourcelen;
198         uid_t           uid;
199         char            name[NAMELEN+1];
200         u_int8_t        team;
201         u_int32_t       enter_status;
202         char            ttyname[NAMELEN];
203         u_int32_t       mode;
204         char            msg[BUFSIZ];
205         int             msglen;
206         struct spawn *  next;
207         struct spawn ** prevnext;
208         int             inlen;
209         char            inbuf[ sizeof (u_int32_t) + NAMELEN +
210                                sizeof (u_int8_t) + sizeof (u_int32_t) +
211                                NAMELEN + sizeof (u_int32_t) ];
212 };
213
214 extern struct spawn *   Spawn;
215
216 extern int      Socket;
217
218 /* answer.c */
219 void    answer_first(void);
220 int     answer_next(struct spawn *);
221 int     rand_dir(void);
222 void    answer_info(FILE *);
223
224 /* draw.c */
225 void    drawmaze(PLAYER *);
226 void    look(PLAYER *);
227 void    check(PLAYER *, int, int);
228 void    showstat(PLAYER *);
229 void    drawplayer(PLAYER *, FLAG);
230 void    message(PLAYER *, const char *);
231
232 /* driver.c */
233 int     rand_num(int);
234 void    checkdam(PLAYER *, PLAYER *, IDENT *, int, char);
235 void    cleanup(int);
236
237 /* execute.c */
238 void    mon_execute(PLAYER *);
239 void    execute(PLAYER *);
240 void    add_shot(int, int, int, char, int, PLAYER *, int, char);
241 BULLET *create_shot(int, int, int, char, int, int, PLAYER *, IDENT *,
242             int, char);
243 void    ammo_update(PLAYER *);
244
245 /* expl.c */
246 void    showexpl(int, int, char);
247 void    rollexpl(void);
248 void    clearwalls(void);
249 int     can_rollexpl(void);
250
251 /* makemaze.c */
252 void    makemaze(void);
253
254 /* shots.c */
255 int     can_moveshots(void);
256 void    moveshots(void);
257 PLAYER *play_at(int, int);
258 int     opposite(int, char);
259 BULLET *is_bullet(int, int);
260 void    fixshots(int, int, char);
261
262 /* terminal.c */
263 void    cgoto(PLAYER *, int, int);
264 void    outch(PLAYER *, char);
265 void    outstr(PLAYER *, const char *, int);
266 void    outyx(PLAYER *, int, int, const char *, ...)
267                         __attribute__((format (printf, 4, 5)));
268 void    clrscr(PLAYER *);
269 void    ce(PLAYER *);
270 void    sendcom(PLAYER *, int, ...);
271 void    flush(PLAYER *);
272 void    logit(int, const char *, ...)
273                         __attribute__((format (printf, 2, 3)));
274 void    logx(int, const char *, ...)
275                         __attribute__((format (printf, 2, 3)));
276
277 /* extern.c */
278 extern FLAG     Am_monitor;
279 extern char     Buf[BUFSIZ];
280 extern char     Maze[HEIGHT][WIDTH2];
281 extern char     Orig_maze[HEIGHT][WIDTH2];
282 extern fd_set   Fds_mask;
283 extern fd_set   Have_inp;
284 extern int      Nplayer;
285 extern int      Num_fds;
286 extern int      Status;
287 extern int      See_over[NASCII];
288 extern BULLET * Bullets;
289 extern EXPL *   Expl[EXPLEN];
290 extern EXPL *   Last_expl;
291 extern PLAYER   Player[MAXPL];
292 extern PLAYER * End_player;
293 extern PLAYER   Boot[NBOOTS];
294 extern IDENT *  Scores;
295 extern PLAYER   Monitor[MAXMON];
296 extern PLAYER * End_monitor;
297 extern int      volcano;
298 extern int      shot_req[MAXBOMB];
299 extern int      shot_type[MAXBOMB];
300 extern int      slime_req[MAXSLIME];