nrelease - fix/improve livecd
[dragonfly.git] / games / trek / play.c
1 /*      @(#)play.c      8.1 (Berkeley) 5/31/93                          */
2 /*      $NetBSD: play.c,v 1.12 2009/08/12 08:54:54 dholland 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 static void myreset(int) __dead2;
39
40 /*
41 **  INSTRUCTION READ AND MAIN PLAY LOOP
42 **
43 **      Well folks, this is it.  Here we have the guts of the game.
44 **      This routine executes moves.  It sets up per-move variables,
45 **      gets the command, and executes the command.  After the command,
46 **      it calls events() to use up time, attack() to have Klingons
47 **      attack if the move was not free, and checkcond() to check up
48 **      on how we are doing after the move.
49 */
50
51 extern jmp_buf env;
52
53 static const struct cvntab Comtab[] = {
54         { "abandon",            "",             abandon,        0 },
55         { "ca",                 "pture",        capture,        0 },
56         { "cl",                 "oak",          shield,         -1 },
57         { "c",                  "omputer",      computer,       0 },
58         { "da",                 "mages",        dcrept,         0 },
59         { "destruct",           "",             destruct,       0 },
60         { "do",                 "ck",           dock,           0 },
61         { "help",               "",             help,           0 },
62         { "i",                  "mpulse",       impulse,        0 },
63         { "l",                  "rscan",        lrscan,         0 },
64         { "m",                  "ove",          dowarp,         0 },
65         { "p",                  "hasers",       phaser,         0 },
66         { "ram",                "",             dowarp,         1 },
67         { "dump",               "",             dumpgame,       0 },
68         { "r",                  "est",          rest,           0 },
69         { "sh",                 "ield",         shield,         0 },
70         { "s",                  "rscan",        srscan,         0 },
71         { "st",                 "atus",         srscan,         -1 },
72         { "terminate",          "",             myreset,        0 },
73         { "t",                  "orpedo",       torped,         0 },
74         { "u",                  "ndock",        undock,         0 },
75         { "v",                  "isual",        visual,         0 },
76         { "w",                  "arp",          setwarp,        0 },
77         { NULL,                 NULL,           NULL,           0 }
78 };
79
80 /*ARGSUSED*/
81 static void
82 myreset(int v __unused)
83 {
84
85         longjmp(env, 1);
86 }
87
88 void
89 play(void)
90 {
91         const struct cvntab             *r;
92
93         while (1) {
94                 Move.free = 1;
95                 Move.time = 0.0;
96                 Move.shldchg = 0;
97                 Move.newquad = 0;
98                 Move.resting = 0;
99                 skiptonl(0);
100                 r = getcodpar("\nCommand", Comtab);
101                 (*r->value)(r->value2);
102                 events(0);
103                 attack(0);
104                 checkcond();
105         }
106 }