xref: /openbsd/games/trek/play.c (revision b39c5158)
1 /*	$OpenBSD: play.c,v 1.5 2009/10/27 23:59:27 deraadt 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 <stdio.h>
34 #include <setjmp.h>
35 #include "trek.h"
36 #include "getpar.h"
37 
38 /*
39 **  INSTRUCTION READ AND MAIN PLAY LOOP
40 **
41 **	Well folks, this is it.  Here we have the guts of the game.
42 **	This routine executes moves.  It sets up per-move variables,
43 **	gets the command, and executes the command.  After the command,
44 **	it calls events() to use up time, attack() to have Klingons
45 **	attack if the move was not free, and checkcond() to check up
46 **	on how we are doing after the move.
47 */
48 
49 const struct cvntab	Comtab[] =
50 {
51 	{ "abandon",		"",		abandon,	0 },
52 	{ "ca",			"pture",	capture,	0 },
53 	{ "cl",			"oak",		shield,		-1 },
54 	{ "c",			"omputer",	computer,	0 },
55 	{ "da",			"mages",	dcrept,		0 },
56 	{ "destruct",		"",		destruct,	0 },
57 	{ "do",			"ck",		dock,		0 },
58 	{ "help",		"",		help,		0 },
59 	{ "i",			"mpulse",	impulse,	0 },
60 	{ "l",			"rscan",	lrscan,		0 },
61 	{ "m",			"ove",		dowarp,		0 },
62 	{ "p",			"hasers",	phaser,		0 },
63 	{ "ram",		"",		dowarp,		1 },
64 	{ "dump",		"",		dumpgame,	0 },
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 
77 void
78 myreset(v)
79 	int v;
80 {
81 	extern jmp_buf env;
82 
83 	longjmp(env, 1);
84 }
85 
86 void
87 play()
88 {
89 	const struct cvntab	*r;
90 
91 	while (1)
92 	{
93 		Move.free = 1;
94 		Move.time = 0.0;
95 		Move.shldchg = 0;
96 		Move.newquad = 0;
97 		Move.resting = 0;
98 		skiptonl(0);
99 		r = getcodpar("\nCommand", Comtab);
100 		(*r->value)(r->value2);
101 		events(0);
102 		attack(0);
103 		checkcond();
104 	}
105 }
106