1/*	$OpenBSD: play.c,v 1.8 2017/05/26 19:19:23 tedu Exp $	*/
2/*	$NetBSD: play.c,v 1.3 1995/04/22 10:59:18 cgd Exp $	*/
3
4/*
5 * Copyright (c) 1980, 1993
6 *	The Regents of the University of California.  All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 *    may be used to endorse or promote products derived from this software
18 *    without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <setjmp.h>
34#include <stdio.h>
35
36#include "getpar.h"
37#include "trek.h"
38
39/*
40**  INSTRUCTION READ AND MAIN PLAY LOOP
41**
42**	Well folks, this is it.  Here we have the guts of the game.
43**	This routine executes moves.  It sets up per-move variables,
44**	gets the command, and executes the command.  After the command,
45**	it calls events() to use up time, attack() to have Klingons
46**	attack if the move was not free, and checkcond() to check up
47**	on how we are doing after the move.
48*/
49
50const struct cvntab	Comtab[] =
51{
52	{ "abandon",		"",		abandon,	0 },
53	{ "ca",			"pture",	capture,	0 },
54	{ "cl",			"oak",		shield,		-1 },
55	{ "c",			"omputer",	computer,	0 },
56	{ "da",			"mages",	dcrept,		0 },
57	{ "destruct",		"",		destruct,	0 },
58	{ "do",			"ck",		dock,		0 },
59	{ "help",		"",		help,		0 },
60	{ "i",			"mpulse",	impulse,	0 },
61	{ "l",			"rscan",	lrscan,		0 },
62	{ "m",			"ove",		dowarp,		0 },
63	{ "p",			"hasers",	phaser,		0 },
64	{ "ram",		"",		dowarp,		1 },
65	{ "r",			"est",		rest,		0 },
66	{ "sh",			"ield",		shield,		0 },
67	{ "s",			"rscan",	srscan,		0 },
68	{ "st",			"atus",		srscan,		-1 },
69	{ "terminate",		"",		myreset,	0 },
70	{ "t",			"orpedo",	torped,		0 },
71	{ "u",			"ndock",	undock,		0 },
72	{ "v",			"isual",	visual,		0 },
73	{ "w",			"arp",		setwarp,	0 },
74	{ NULL,			NULL,		NULL,		0 }
75};
76
77void
78myreset(int v)
79{
80	extern jmp_buf env;
81
82	longjmp(env, 1);
83}
84
85void
86play(void)
87{
88	const struct cvntab	*r;
89
90	while (1)
91	{
92		Move.free = 1;
93		Move.time = 0.0;
94		Move.shldchg = 0;
95		Move.newquad = 0;
96		Move.resting = 0;
97		skiptonl(0);
98		r = getcodpar("\nCommand", Comtab);
99		(*r->value)(r->value2);
100		events(0);
101		attack(0);
102		checkcond();
103	}
104}
105