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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
/* $OpenBSD: draw.c,v 1.7 2003/06/11 08:45:33 pjanzen Exp $ */
/* $NetBSD: draw.c,v 1.2 1997/10/10 16:33:04 lukem Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* + Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* + Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* + Neither the name of the University of California, San Francisco nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include "hunt.h"
#include "server.h"
#include "conf.h"
static char translate(char);
static int player_sym(PLAYER *, int, int);
static void drawstatus(PLAYER *);
static void see(PLAYER *, int);
/*
* drawmaze:
* Draw the entire maze on a player's screen.
*/
void
drawmaze(pp)
PLAYER *pp;
{
int x;
char *sp;
int y;
char *endp;
/* Clear the client's screen: */
clrscr(pp);
/* Draw the top row of the maze: */
outstr(pp, pp->p_maze[0], WIDTH);
for (y = 1; y < HEIGHT - 1; y++) {
endp = &pp->p_maze[y][WIDTH];
for (x = 0, sp = pp->p_maze[y]; sp < endp; x++, sp++)
if (*sp != SPACE) {
cgoto(pp, y, x);
/* Draw the player as themselves */
if (pp->p_x == x && pp->p_y == y)
outch(pp, translate(*sp));
/* Possibly draw other players as team nrs */
else if (is_player(*sp))
outch(pp, player_sym(pp, y, x));
else
outch(pp, *sp);
}
}
/* Draw the last row of the maze: */
cgoto(pp, HEIGHT - 1, 0);
outstr(pp, pp->p_maze[HEIGHT - 1], WIDTH);
drawstatus(pp);
}
/*
* drawstatus - put up the status lines (this assumes the screen
* size is 80x24 with the maze being 64x24)
*/
static void
drawstatus(pp)
PLAYER *pp;
{
int i;
PLAYER *np;
outyx(pp, STAT_AMMO_ROW, STAT_LABEL_COL, "Ammo:");
ammo_update(pp);
outyx(pp, STAT_GUN_ROW, STAT_LABEL_COL, "Gun:");
outyx(pp, STAT_GUN_ROW, STAT_VALUE_COL, "%3s",
(pp->p_ncshot < conf_maxncshot) ? "ok" : "");
outyx(pp, STAT_DAM_ROW, STAT_LABEL_COL, "Damage:");
outyx(pp, STAT_DAM_ROW, STAT_VALUE_COL, "%2d/%2d",
pp->p_damage, pp->p_damcap);
outyx(pp, STAT_KILL_ROW, STAT_LABEL_COL, "Kills:");
outyx(pp, STAT_KILL_ROW, STAT_VALUE_COL, "%3d",
(pp->p_damcap - conf_maxdam) / 2);
outyx(pp, STAT_PLAY_ROW, STAT_LABEL_COL, "Player:");
for (i = STAT_PLAY_ROW + 1, np = Player; np < End_player; np++, i++) {
outyx(pp, i, STAT_NAME_COL, "%5.2f%c%-10.10s %c",
np->p_ident->i_score, stat_char(np),
np->p_ident->i_name, np->p_ident->i_team);
}
outyx(pp, STAT_MON_ROW, STAT_LABEL_COL, "Monitor:");
for (i = STAT_MON_ROW + 1, np = Monitor; np < End_monitor; np++, i++) {
outyx(pp, i++, STAT_NAME_COL, "%5.5s %-10.10s %c",
" ", np->p_ident->i_name, np->p_ident->i_team);
}
}
/*
* look
* check and update the visible area around the player
*/
void
look(pp)
PLAYER *pp;
{
int x, y;
x = pp->p_x;
y = pp->p_y;
/*
* The player is aware of all objects immediately adjacent to
* their position:
*/
check(pp, y - 1, x - 1);
check(pp, y - 1, x );
check(pp, y - 1, x + 1);
check(pp, y , x - 1);
check(pp, y , x );
check(pp, y , x + 1);
check(pp, y + 1, x - 1);
check(pp, y + 1, x );
check(pp, y + 1, x + 1);
switch (pp->p_face) {
/* The player can see down corridors in directions except behind: */
case LEFTS:
see(pp, LEFTS);
see(pp, ABOVE);
see(pp, BELOW);
break;
case RIGHT:
see(pp, RIGHT);
see(pp, ABOVE);
see(pp, BELOW);
break;
case ABOVE:
see(pp, ABOVE);
see(pp, LEFTS);
see(pp, RIGHT);
break;
case BELOW:
see(pp, BELOW);
see(pp, LEFTS);
see(pp, RIGHT);
break;
/* But they don't see too far when they are flying about: */
case FLYER:
break;
}
/* Move the cursor back over the player: */
cgoto(pp, y, x);
}
/*
* see
* Look down a corridor, or towards an open space. This
* is a simulation of visibility from the player's perspective.
*/
static void
see(pp, face)
PLAYER *pp;
int face;
{
char *sp;
int y, x;
/* Start from the player's position: */
x = pp->p_x;
y = pp->p_y;
#define seewalk(dx, dy) \
x += (dx); \
y += (dy); \
sp = &Maze[y][x]; \
while (See_over[(int)*sp]) { \
x += (dx); \
y += (dy); \
sp += ((dx) + (dy) * sizeof Maze[0]); \
check(pp, y + dx, x + dy); \
check(pp, y, x); \
check(pp, y - dx, x - dy); \
}
switch (face) {
case LEFTS:
seewalk(-1, 0); break;
case RIGHT:
seewalk(1, 0); break;
case ABOVE:
seewalk(0, -1); break;
case BELOW:
seewalk(0, 1); break;
}
}
/*
* check
* The player is aware of a cell in the maze.
* Ensure it is shown properly on their screen.
*/
void
check(pp, y, x)
PLAYER *pp;
int y, x;
{
int index;
int ch;
PLAYER *rpp;
if (pp == ALL_PLAYERS) {
for (pp = Player; pp < End_player; pp++)
check(pp, y, x);
for (pp = Monitor; pp < End_monitor; pp++)
check(pp, y, x);
return;
}
index = y * sizeof Maze[0] + x;
ch = ((char *) Maze)[index];
if (ch != ((char *) pp->p_maze)[index]) {
rpp = pp;
cgoto(rpp, y, x);
if (x == rpp->p_x && y == rpp->p_y)
outch(rpp, translate(ch));
else if (is_player(ch))
outch(rpp, player_sym(rpp, y, x));
else
outch(rpp, ch);
((char *) rpp->p_maze)[index] = ch;
}
}
/*
* showstat
* Update the status of a player on everyone's screen
*/
void
showstat(pp)
PLAYER *pp;
{
outyx(ALL_PLAYERS,
STAT_PLAY_ROW + 1 + (pp - Player), STAT_SCAN_COL,
"%c", stat_char(pp));
}
/*
* drawplayer:
* Draw the player on the screen and show him to everyone who's scanning
* unless he is cloaked.
* The 'draw' flag when false, causes the 'saved under' character to
* be drawn instead of the player; effectively un-drawing the player.
*/
void
drawplayer(pp, draw)
PLAYER *pp;
FLAG draw;
{
PLAYER *newp;
int x, y;
x = pp->p_x;
y = pp->p_y;
/* Draw or un-draw the player into the master map: */
Maze[y][x] = draw ? pp->p_face : pp->p_over;
/* The monitors can always see this player: */
for (newp = Monitor; newp < End_monitor; newp++)
check(newp, y, x);
/* Check if other players can see this player: */
for (newp = Player; newp < End_player; newp++) {
if (!draw) {
/* When un-drawing, show everyone what was under */
check(newp, y, x);
continue;
}
if (newp == pp) {
/* The player can always see themselves: */
check(newp, y, x);
continue;
}
/* Check if the other player just run out of scans */
if (newp->p_scan == 0) {
/* The other player is no longer scanning: */
newp->p_scan--;
showstat(newp);
/* Check if the other play is scannning */
} else if (newp->p_scan > 0) {
/* If this player's not cloacked, draw him: */
if (pp->p_cloak < 0)
check(newp, y, x);
/* And this uses up a scan. */
newp->p_scan--;
}
}
/* Use up one point of cloak time when drawing: */
if (draw && pp->p_cloak >= 0) {
pp->p_cloak--;
/* Check if we ran out of cloak: */
if (pp->p_cloak < 0)
showstat(pp);
}
}
/*
* message:
* Write a message at the bottom of the screen.
*/
void
message(pp, s)
PLAYER *pp;
char *s;
{
cgoto(pp, HEIGHT, 0);
outstr(pp, s, strlen(s));
ce(pp);
}
/*
* translate:
* Turn a player character into a more personal player character.
* ie: {,},!,i becomes <,>,v,^
*/
static char
translate(ch)
char ch;
{
switch (ch) {
case LEFTS:
return '<';
case RIGHT:
return '>';
case ABOVE:
return '^';
case BELOW:
return 'v';
}
return ch;
}
/*
* player_sym:
* Return the symbol for the player at (y,x) when viewed by player 'pp'.
* ie: - unteamed players appear as {,},!,i
* - unteamed monitors see all players as team digits
* - teamed players see other players on their team, as a digit
*/
static int
player_sym(pp, y, x)
PLAYER *pp;
int y, x;
{
PLAYER *npp;
npp = play_at(y, x);
if (npp->p_ident->i_team == ' ')
return Maze[y][x];
if (pp->p_ident->i_team == '*')
return npp->p_ident->i_team;
if (pp->p_ident->i_team != npp->p_ident->i_team)
return Maze[y][x];
return pp->p_ident->i_team;
}
|