summaryrefslogtreecommitdiffstats
path: root/sail/pl_main.c
diff options
context:
space:
mode:
authordholland <dholland@NetBSD.org>2010-08-06 09:14:40 +0000
committerdholland <dholland@NetBSD.org>2010-08-06 09:14:40 +0000
commit240117cdf638c185d8469527e583276e546bf666 (patch)
tree5f45461542b4f87b9eb0c8e1a70e7c8f59449efd /sail/pl_main.c
parentc20418e9c57794ae8f5522f5e5ea962112bde704 (diff)
downloadbsdgames-darwin-240117cdf638c185d8469527e583276e546bf666.tar.gz
bsdgames-darwin-240117cdf638c185d8469527e583276e546bf666.tar.zst
bsdgames-darwin-240117cdf638c185d8469527e583276e546bf666.zip
Rework the game startup so it uses curses nicely. There are now menus
and stuff for picking scenarios and ships and all that.
Diffstat (limited to 'sail/pl_main.c')
-rw-r--r--sail/pl_main.c200
1 files changed, 39 insertions, 161 deletions
diff --git a/sail/pl_main.c b/sail/pl_main.c
index 619a99f1..f13f1f81 100644
--- a/sail/pl_main.c
+++ b/sail/pl_main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pl_main.c,v 1.26 2009/03/15 03:33:56 dholland Exp $ */
+/* $NetBSD: pl_main.c,v 1.27 2010/08/06 09:14:40 dholland Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -34,12 +34,11 @@
#if 0
static char sccsid[] = "@(#)pl_main.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: pl_main.c,v 1.26 2009/03/15 03:33:56 dholland Exp $");
+__RCSID("$NetBSD: pl_main.c,v 1.27 2010/08/06 09:14:40 dholland Exp $");
#endif
#endif /* not lint */
#include <err.h>
-#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -48,48 +47,18 @@ __RCSID("$NetBSD: pl_main.c,v 1.26 2009/03/15 03:33:56 dholland Exp $");
#include "display.h"
#include "extern.h"
#include "player.h"
-#include "restart.h"
-static void initialize(void);
+char myname[MAXNAMESIZE];
-/*ARGSUSED*/
-int
-pl_main(void)
-{
- initialize();
- Msg("Aye aye, Sir");
- play();
- return 0; /* for lint, play() never returns */
-}
+static void initialize(void);
-static void
-initialize(void)
+void
+pl_main_init(void)
{
- struct File *fp;
- struct ship *sp;
- char captain[80];
- char message[60];
- int load;
- int n;
- char *nameptr;
int nat[NNATION];
+ int n;
+ struct ship *sp;
- if (game < 0) {
- puts("Choose a scenario:\n");
- puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
- for (n = 0; n < NSCENE; n++) {
- /* ( */
- printf("\t%d):\t%d\t%s\t%s\n", n, scene[n].vessels,
- sync_exists(n) ? "YES" : "no",
- scene[n].name);
- }
-reprint:
- printf("\nScenario number? ");
- fflush(stdout);
- scanf("%d", &game);
- while (getchar() != '\n' && !feof(stdin))
- ;
- }
if (game < 0 || game >= NSCENE) {
errx(1, "Very funny.");
}
@@ -114,145 +83,54 @@ reprint:
signal(SIGHUP, choke);
signal(SIGINT, choke);
+ signal(SIGCHLD, child);
+}
- hasdriver = sync_exists(game);
- if (sync_open() < 0) {
- err(1, "syncfile");
- }
+void
+pl_main_uninit(void)
+{
+ struct ship *sp;
- if (hasdriver) {
- puts("Synchronizing with the other players...");
- fflush(stdout);
- if (Sync() < 0)
- leave(LEAVE_SYNC);
- }
- for (;;) {
- foreachship(sp)
- if (sp->file->captain[0] == 0 && !sp->file->struck
- && sp->file->captured == 0)
- break;
- if (sp >= ls) {
- puts("All ships taken in that scenario.");
- foreachship(sp)
- free(sp->file);
- sync_close(0);
- people = 0;
- goto reprint;
- }
- if (randomize) {
- player = sp - SHIP(0);
- } else {
- printf("%s\n\n", cc->name);
- foreachship(sp)
- printf(" %2d: %-10s %-15s (%-2d pts) %s\n",
- sp->file->index,
- countryname[sp->nationality],
- sp->shipname,
- sp->specs->pts,
- saywhat(sp, 1));
- printf("\nWhich ship (0-%d)? ", cc->vessels-1);
- fflush(stdout);
- if (scanf("%d", &player) != 1 || player < 0
- || player >= cc->vessels) {
- while (getchar() != '\n' && !feof(stdin))
- ;
- puts("Say what?");
- player = -1;
- } else
- while (getchar() != '\n' && !feof(stdin))
- ;
- if (feof(stdin)) {
- printf("\nExiting...\n");
- leave(LEAVE_QUIT);
- }
- }
- if (player < 0)
- continue;
- if (Sync() < 0)
- leave(LEAVE_SYNC);
- fp = SHIP(player)->file;
- if (fp->captain[0] || fp->struck || fp->captured != 0)
- puts("That ship is taken.");
- else
- break;
+ foreachship(sp) {
+ free(sp->file);
+ sp->file = NULL;
}
+}
- ms = SHIP(player);
- mf = ms->file;
- mc = ms->specs;
+static void
+initialize(void)
+{
+ char captain[MAXNAMESIZE];
+ char message[60];
+
+ if (game < 0 || game >= NSCENE) {
+ errx(1, "Very funny.");
+ }
send_begin(ms);
if (Sync() < 0)
leave(LEAVE_SYNC);
- signal(SIGCHLD, child);
- if (!hasdriver)
- switch (fork()) {
- case 0:
- longjmp(restart, MODE_DRIVER);
- /*NOTREACHED*/
- case -1:
- warn("fork");
- leave(LEAVE_FORK);
- break;
- default:
- hasdriver++;
- }
-
+#if 0
printf("Your ship is the %s, a %d gun %s (%s crew).\n",
ms->shipname, mc->guns, classname[mc->class],
qualname[mc->qual]);
- if ((nameptr = getenv("SAILNAME")) && *nameptr)
- strlcpy(captain, nameptr, sizeof captain);
- else {
- printf("Your name, Captain? ");
- fflush(stdout);
- if (fgets(captain, sizeof captain, stdin) == NULL)
- strcpy(captain, "no name");
- else if (*captain == '\0' || *captain == '\n')
- strcpy(captain, "no name");
- else
- captain[strlen(captain) - 1] = '\0';
- }
- send_captain(ms, captain);
- for (n = 0; n < 2; n++) {
- char buf[10];
+#endif
- printf("\nInitial broadside %s (grape, chain, round, double): ",
- n ? "right" : "left");
- fflush(stdout);
- fgets(buf, sizeof(buf), stdin);
- switch (*buf) {
- case 'g':
- load = L_GRAPE;
- break;
- case 'c':
- load = L_CHAIN;
- break;
- case 'r':
- load = L_ROUND;
- break;
- case 'd':
- load = L_DOUBLE;
- break;
- default:
- load = L_ROUND;
- }
- if (n) {
- mf->loadR = load;
- mf->readyR = R_LOADED|R_INITIAL;
- } else {
- mf->loadL = load;
- mf->readyL = R_LOADED|R_INITIAL;
- }
- }
+ strlcpy(captain, myname, sizeof(captain));
+ send_captain(ms, captain);
- printf("\n");
- fflush(stdout);
- initscreen();
display_redraw();
snprintf(message, sizeof message, "Captain %s assuming command",
captain);
send_signal(ms, message);
newturn(0);
}
+
+void
+pl_main(void)
+{
+ initialize();
+ Msg("Aye aye, Sir");
+ play();
+}