X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/97e04d4fb9d218f2fb01cc75da027de2f4035be8..ac993d78a557211a3c93c9e8f76d8e14e501932d:/sail/pl_5.c diff --git a/sail/pl_5.c b/sail/pl_5.c index 3d763f3f..d149b933 100644 --- a/sail/pl_5.c +++ b/sail/pl_5.c @@ -1,4 +1,4 @@ -/* $NetBSD: pl_5.c,v 1.9 2001/01/04 02:43:32 jwise Exp $ */ +/* $NetBSD: pl_5.c,v 1.25 2009/03/15 03:33:56 dholland Exp $ */ /* * Copyright (c) 1983, 1993 @@ -12,11 +12,7 @@ * 2. 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -38,27 +34,31 @@ #if 0 static char sccsid[] = "@(#)pl_5.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: pl_5.c,v 1.9 2001/01/04 02:43:32 jwise Exp $"); +__RCSID("$NetBSD: pl_5.c,v 1.25 2009/03/15 03:33:56 dholland Exp $"); #endif #endif /* not lint */ +#include +#include +#include +#include +#include "extern.h" #include "player.h" +#include "display.h" #define turnfirst(x) (*x == 'r' || *x == 'l') -void acceptmove(void); -void acceptboard(void); -static void parties(int *, struct ship *, int, int); +static void parties(struct ship *, int *, int, int); void acceptmove(void) { int ta; int ma; - char af; - int moved = 0; + bool af; + bool moved = false; int vma, dir; - char prompt[60]; + char promptstr[60]; char buf[60], last = '\0'; char *p; @@ -69,8 +69,9 @@ acceptmove(void) ta = maxturns(ms, &af); ma = maxmove(ms, mf->dir, 0); - sprintf(prompt, "move (%d,%c%d): ", ma, af ? '\'' : ' ', ta); - sgetstr(prompt, buf, sizeof buf); + snprintf(promptstr, sizeof(promptstr), + "move (%d,%c%d): ", ma, af ? '\'' : ' ', ta); + sgetstr(promptstr, buf, sizeof buf); dir = mf->dir; vma = ma; for (p = buf; *p; p++) @@ -114,14 +115,14 @@ acceptmove(void) *p-- = '\0'; } last = '0'; - moved = 1; + moved = true; ma -= *p - '0'; vma -= *p - '0'; if ((ta < 0 && moved) || (vma < 0 && moved)) *p-- = '\0'; break; default: - if (!isspace(*p)) { + if (!isspace((unsigned char)*p)) { Msg("Input error."); *p-- = '\0'; } @@ -131,7 +132,7 @@ acceptmove(void) Msg("Movement error."); if (ta < 0 && moved) { if (mf->FS == 1) { - Write(W_FS, ms, 0, 0, 0, 0); + send_fs(ms, 0); Msg("No hands to set full sails."); } } else if (ma >= 0) @@ -139,15 +140,15 @@ acceptmove(void) } if (af && !moved) { if (mf->FS == 1) { - Write(W_FS, ms, 0, 0, 0, 0); + send_fs(ms, 0); Msg("No hands to set full sails."); } } if (*buf) - strcpy(movebuf, buf); + strlcpy(movebuf, buf, sizeof(movebuf)); else - strcpy(movebuf, "d"); - Writestr(W_MOVE, ms, movebuf); + strlcpy(movebuf, "d", sizeof(movebuf)); + send_move(ms, movebuf); Msg("Helm: %s.", movebuf); } @@ -188,36 +189,34 @@ acceptboard(void) if (meleeing(ms, sp) && crew[2]) { c = sgetch("How many more to board the $$? ", sp, 1); - parties(crew, sp, 0, c); + parties(sp, crew, 0, c); } else if ((fouled2(ms, sp) || grappled2(ms, sp)) && crew[2]) { - c = sgetch("Crew sections to board the $$ (3 max) ?", sp, 1); - parties(crew, sp, 0, c); + c = sgetch("Crew sections to board the $$ (3 max) ?", + sp, 1); + parties(sp, crew, 0, c); } } if (crew[2]) { c = sgetch("How many sections to repel boarders? ", (struct ship *)0, 1); - parties(crew, ms, 1, c); + parties(ms, crew, 1, c); } - blockalarm(); - draw_slot(); - unblockalarm(); } static void -parties(int *crew, struct ship *to, int isdefense, int buf) +parties(struct ship *to, int *crew, int isdefense, int buf) { - int k, j, men; + int k, j, men; struct BP *ptr; int temp[3]; for (k = 0; k < 3; k++) temp[k] = crew[k]; if (isdigit(buf)) { - ptr = isdefense ? to->file->DBP : to->file->OBP; + ptr = isdefense ? to->file->DBP : to->file->OBP; for (j = 0; j < NBP && ptr[j].turnsent; j++) ; - if (!ptr[j].turnsent && buf > '0') { + if (j < NBP && !ptr[j].turnsent && buf > '0') { men = 0; for (k = 0; k < 3 && buf > '0'; k++) { men += crew[k] @@ -228,30 +227,22 @@ parties(int *crew, struct ship *to, int isdefense, int buf) } if (buf > '0') Msg("Sending all crew sections."); - Write(isdefense ? W_DBP : W_OBP, ms, - j, turn, to->file->index, men); if (isdefense) { - wmove(slot_w, 2, 0); + send_dbp(ms, j, turn, to->file->index, men); + } else { + send_obp(ms, j, turn, to->file->index, men); + } + if (isdefense) { for (k=0; k < NBP; k++) - if (temp[k] && !crew[k]) - waddch(slot_w, k + '1'); - else - wmove(slot_w, 2, 1 + k); - mvwaddstr(slot_w, 3, 0, "DBP"); + display_set_dbp(k, + temp[k] && !crew[k]); makemsg(ms, "repelling boarders"); } else { - wmove(slot_w, 0, 0); for (k=0; k < NBP; k++) - if (temp[k] && !crew[k]) - waddch(slot_w, k + '1'); - else - wmove(slot_w, 0, 1 + k); - mvwaddstr(slot_w, 1, 0, "OBP"); + display_set_obp(k, + temp[k] && !crew[k]); makesignal(ms, "boarding the $$", to); } - blockalarm(); - wrefresh(slot_w); - unblockalarm(); } else Msg("Sending no crew sections."); }