]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hunt/huntd/execute.c
1 /* $NetBSD: execute.c,v 1.4 2004/01/27 20:30:29 jsm Exp $ */
3 * Copyright (c) 1983-2003, Regents of the University of California.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * + Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * + Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * + Neither the name of the University of California, San Francisco nor
16 * the names of its contributors may be used to endorse or promote
17 * products derived from this software without specific prior written
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
35 __RCSID("$NetBSD: execute.c,v 1.4 2004/01/27 20:30:29 jsm Exp $");
41 static void cloak(PLAYER
*);
42 static void face(PLAYER
*, int);
43 static void fire(PLAYER
*, int);
44 static void fire_slime(PLAYER
*, int);
45 static void move_player(PLAYER
*, int);
46 static void pickup(PLAYER
*, int, int, int, int);
47 static void scan(PLAYER
*);
53 * Execute a single monitor command
61 ch
= pp
->p_cbuf
[pp
->p_ncount
++];
67 (void) strcpy(pp
->p_death
, "| Quit |");
75 * Execute a single command
83 ch
= pp
->p_cbuf
[pp
->p_ncount
++];
86 if (pp
->p_flying
>= 0) {
92 (void) strcpy(pp
->p_death
, "| Quit |");
104 move_player(pp
, LEFTS
);
110 move_player(pp
, BELOW
);
116 move_player(pp
, ABOVE
);
122 move_player(pp
, RIGHT
);
129 fire(pp
, 0); /* SHOT */
133 fire(pp
, 1); /* GRENADE */
137 fire(pp
, 2); /* SATCHEL */
141 fire(pp
, 3); /* 7x7 BOMB */
144 fire(pp
, 4); /* 9x9 BOMB */
147 fire(pp
, 5); /* 11x11 BOMB */
150 fire(pp
, 6); /* 13x13 BOMB */
153 fire(pp
, 7); /* 15x15 BOMB */
156 fire(pp
, 8); /* 17x17 BOMB */
159 fire(pp
, 9); /* 19x19 BOMB */
162 fire(pp
, 10); /* 21x21 BOMB */
166 fire_slime(pp
, 0); /* SLIME */
169 fire_slime(pp
, 1); /* SSLIME */
185 (void) strcpy(pp
->p_death
, "| Quit |");
192 * Execute a move in the given direction
223 switch (Maze
[y
][x
]) {
240 if (dir
== pp
->p_face
)
241 pickup(pp
, y
, x
, 2, Maze
[y
][x
]);
242 else if (opposite(dir
, pp
->p_face
))
243 pickup(pp
, y
, x
, 95, Maze
[y
][x
]);
245 pickup(pp
, y
, x
, 50, Maze
[y
][x
]);
259 bp
= is_bullet(y
, x
);
269 if (dir
!= pp
->p_face
)
272 newp
= play_at(y
, x
);
273 checkdam(newp
, pp
, pp
->p_ident
, STABDAM
, KNIFE
);
278 newp
= play_at(y
, x
);
279 message(newp
, "Oooh, there's a short guy waving at you!");
280 message(pp
, "You couldn't quite reach him!");
286 if (Maze
[y
][x
] == BOOT
)
290 for (newp
= Boot
; newp
< &Boot
[NBOOTS
]; newp
++) {
291 if (newp
->p_flying
< 0)
293 if (newp
->p_y
== y
&& newp
->p_x
== x
) {
295 if (newp
->p_undershot
)
296 fixshots(y
, x
, newp
->p_over
);
299 if (pp
->p_nboots
== 2)
300 message(pp
, "Wow! A pair of boots!");
302 message(pp
, "You can hobble around on one boot.");
309 if (pp
->p_ncshot
> 0)
310 if (--pp
->p_ncshot
== MAXNCSHOT
) {
311 cgoto(pp
, STAT_GUN_ROW
, STAT_VALUE_COL
);
312 outstr(pp
, " ok", 3);
314 if (pp
->p_undershot
) {
315 fixshots(pp
->p_y
, pp
->p_x
, pp
->p_over
);
316 pp
->p_undershot
= FALSE
;
318 drawplayer(pp
, FALSE
);
319 pp
->p_over
= Maze
[y
][x
];
322 drawplayer(pp
, TRUE
);
328 * Change the direction the player is facing
335 if (pp
->p_face
!= dir
) {
337 drawplayer(pp
, TRUE
);
343 * Fire a shot of the given type in the given direction
353 if (req_index
< 0 || req_index
>= MAXBOMB
)
354 message(pp
, "What you do?");
356 while (req_index
>= 0 && pp
->p_ammo
< shot_req
[req_index
])
359 message(pp
, "Not enough charges.");
362 if (pp
->p_ncshot
> MAXNCSHOT
)
364 if (pp
->p_ncshot
++ == MAXNCSHOT
) {
365 cgoto(pp
, STAT_GUN_ROW
, STAT_VALUE_COL
);
368 pp
->p_ammo
-= shot_req
[req_index
];
369 (void) sprintf(Buf
, "%3d", pp
->p_ammo
);
370 cgoto(pp
, STAT_AMMO_ROW
, STAT_VALUE_COL
);
373 add_shot(shot_type
[req_index
], pp
->p_y
, pp
->p_x
, pp
->p_face
,
374 shot_req
[req_index
], pp
, FALSE
, pp
->p_face
);
375 pp
->p_undershot
= TRUE
;
378 * Show the object to everyone
380 showexpl(pp
->p_y
, pp
->p_x
, shot_type
[req_index
]);
381 for (pp
= Player
; pp
< End_player
; pp
++)
382 sendcom(pp
, REFRESH
);
384 for (pp
= Monitor
; pp
< End_monitor
; pp
++)
385 sendcom(pp
, REFRESH
);
392 * Fire a slime shot in the given direction
395 fire_slime(pp
, req_index
)
402 if (req_index
< 0 || req_index
>= MAXSLIME
)
403 message(pp
, "What you do?");
405 while (req_index
>= 0 && pp
->p_ammo
< slime_req
[req_index
])
408 message(pp
, "Not enough charges.");
411 if (pp
->p_ncshot
> MAXNCSHOT
)
413 if (pp
->p_ncshot
++ == MAXNCSHOT
) {
414 cgoto(pp
, STAT_GUN_ROW
, STAT_VALUE_COL
);
417 pp
->p_ammo
-= slime_req
[req_index
];
418 (void) sprintf(Buf
, "%3d", pp
->p_ammo
);
419 cgoto(pp
, STAT_AMMO_ROW
, STAT_VALUE_COL
);
422 add_shot(SLIME
, pp
->p_y
, pp
->p_x
, pp
->p_face
,
423 slime_req
[req_index
] * SLIME_FACTOR
, pp
, FALSE
, pp
->p_face
);
424 pp
->p_undershot
= TRUE
;
427 * Show the object to everyone
429 showexpl(pp
->p_y
, pp
->p_x
, SLIME
);
430 for (pp
= Player
; pp
< End_player
; pp
++)
431 sendcom(pp
, REFRESH
);
433 for (pp
= Monitor
; pp
< End_monitor
; pp
++)
434 sendcom(pp
, REFRESH
);
441 * Create a shot with the given properties
444 add_shot(type
, y
, x
, face
, charge
, owner
, expl
, over
)
469 for (size
= 3; size
< MAXBOMB
; size
++)
470 if (shot_req
[size
] >= charge
)
479 bp
= create_shot(type
, y
, x
, face
, charge
, size
, owner
,
480 (owner
== NULL
) ? NULL
: owner
->p_ident
, expl
, over
);
481 bp
->b_next
= Bullets
;
486 create_shot(type
, y
, x
, face
, charge
, size
, owner
, score
, expl
, over
)
499 bp
= (BULLET
*) malloc(sizeof (BULLET
)); /* NOSTRICT */
502 message(owner
, "Out of memory");
509 bp
->b_charge
= charge
;
523 * Turn on or increase length of a cloak
529 if (pp
->p_ammo
<= 0) {
530 message(pp
, "No more charges");
534 if (pp
->p_nboots
> 0) {
535 message(pp
, "Boots are too noisy to cloak!");
539 (void) sprintf(Buf
, "%3d", --pp
->p_ammo
);
540 cgoto(pp
, STAT_AMMO_ROW
, STAT_VALUE_COL
);
543 pp
->p_cloak
+= CLOAKLEN
;
553 * Turn on or increase length of a scan
559 if (pp
->p_ammo
<= 0) {
560 message(pp
, "No more charges");
563 (void) sprintf(Buf
, "%3d", --pp
->p_ammo
);
564 cgoto(pp
, STAT_AMMO_ROW
, STAT_VALUE_COL
);
567 pp
->p_scan
+= SCANLEN
;
569 if (pp
->p_cloak
>= 0)
577 * check whether the object blew up or whether he picked it up
580 pickup(pp
, y
, x
, prob
, obj
)
598 if (rand_num(100) < prob
)
599 add_shot(obj
, y
, x
, LEFTS
, req
, (PLAYER
*) NULL
,
603 (void) sprintf(Buf
, "%3d", pp
->p_ammo
);
604 cgoto(pp
, STAT_AMMO_ROW
, STAT_VALUE_COL
);