xref: /original-bsd/games/trek/play.c (revision ebf693c1)
1 /*
2  * Copyright (c) 1980, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)play.c	8.1 (Berkeley) 05/31/93";
10 #endif /* not lint */
11 
12 # include	"trek.h"
13 # include	"getpar.h"
14 # include	<setjmp.h>
15 
16 /*
17 **  INSTRUCTION READ AND MAIN PLAY LOOP
18 **
19 **	Well folks, this is it.  Here we have the guts of the game.
20 **	This routine executes moves.  It sets up per-move variables,
21 **	gets the command, and executes the command.  After the command,
22 **	it calls events() to use up time, attack() to have Klingons
23 **	attack if the move was not free, and checkcond() to check up
24 **	on how we are doing after the move.
25 */
26 extern int	abandon(), capture(), shield(), computer(), dcrept(),
27 		destruct(), dock(), help(), impulse(), lrscan(),
28 		warp(), dumpgame(), rest(), srscan(),
29 		myreset(), torped(), visual(), setwarp(), undock(), phaser();
30 
31 struct cvntab	Comtab[] =
32 {
33 	"abandon",		"",			abandon,	0,
34 	"ca",			"pture",		capture,	0,
35 	"cl",			"oak",			shield,	-1,
36 	"c",			"omputer",		computer,	0,
37 	"da",			"mages",		dcrept,	0,
38 	"destruct",		"",			destruct,	0,
39 	"do",			"ck",			dock,		0,
40 	"help",			"",			help,		0,
41 	"i",			"mpulse",		impulse,	0,
42 	"l",			"rscan",		lrscan,	0,
43 	"m",			"ove",			warp,		0,
44 	"p",			"hasers",		phaser,	0,
45 	"ram",			"",			warp,		1,
46 	"dump",			"",			dumpgame,	0,
47 	"r",			"est",			rest,		0,
48 	"sh",			"ield",			shield,	0,
49 	"s",			"rscan",		srscan,	0,
50 	"st",			"atus",			srscan,	-1,
51 	"terminate",		"",			myreset,	0,
52 	"t",			"orpedo",		torped,	0,
53 	"u",			"ndock",		undock,	0,
54 	"v",			"isual",		visual,	0,
55 	"w",			"arp",			setwarp,	0,
56 	0
57 };
58 
59 myreset()
60 {
61 	extern jmp_buf env;
62 
63 	longjmp(env, 1);
64 }
65 
66 play()
67 {
68 	struct cvntab		*r;
69 
70 	while (1)
71 	{
72 		Move.free = 1;
73 		Move.time = 0.0;
74 		Move.shldchg = 0;
75 		Move.newquad = 0;
76 		Move.resting = 0;
77 		skiptonl(0);
78 		r = getcodpar("\nCommand", Comtab);
79 		(*r->value)(r->value2);
80 		events(0);
81 		attack(0);
82 		checkcond();
83 	}
84 }
85