xref: /dragonfly/games/sail/pl_2.c (revision 3d33658b)
1 /*	$NetBSD: pl_2.c,v 1.13 2009/03/15 03:33:56 dholland Exp $	*/
2 
3 /*
4  * Copyright (c) 1983, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 #include <sys/cdefs.h>
33 #ifndef lint
34 #if 0
35 static char sccsid[] = "@(#)pl_2.c	8.1 (Berkeley) 5/31/93";
36 #else
37 __RCSID("$NetBSD: pl_2.c,v 1.13 2009/03/15 03:33:56 dholland Exp $");
38 #endif
39 #endif /* not lint */
40 
41 #include <signal.h>
42 #include <unistd.h>
43 #include "display.h"
44 #include "extern.h"
45 #include "player.h"
46 
47 /*ARGSUSED*/
48 void
49 newturn(int n __unused)
50 {
51 	repaired = loaded = fired = changed = 0;
52 	movebuf[0] = '\0';
53 
54 	alarm(0);
55 	if (mf->readyL & R_LOADING) {
56 		if (mf->readyL & R_DOUBLE)
57 			mf->readyL = R_LOADING;
58 		else
59 			mf->readyL = R_LOADED;
60 	}
61 	if (mf->readyR & R_LOADING) {
62 		if (mf->readyR & R_DOUBLE)
63 			mf->readyR = R_LOADING;
64 		else
65 			mf->readyR = R_LOADED;
66 	}
67 	if (!hasdriver)
68 		send_ddead();
69 
70 	display_hide_prompt();
71 	if (Sync() < 0)
72 		leave(LEAVE_SYNC);
73 	if (!hasdriver)
74 		leave(LEAVE_DRIVER);
75 	display_reshow_prompt();
76 
77 	if (turn % 50 == 0)
78 		send_alive();
79 	if (mf->FS && (!mc->rig1 || windspeed == 6))
80 		send_fs(ms, 0);
81 	if (mf->FS == 1)
82 		send_fs(ms, 2);
83 
84 	if (mf->struck)
85 		leave(LEAVE_QUIT);
86 	if (mf->captured != 0)
87 		leave(LEAVE_CAPTURED);
88 	if (windspeed == 7)
89 		leave(LEAVE_HURRICAN);
90 
91 	display_adjust_view();
92 	display_redraw();
93 
94 	signal(SIGALRM, newturn);
95 	alarm(7);
96 }
97 
98 void
99 play(void)
100 {
101 	struct ship *sp;
102 
103 	for (;;) {
104 		blockalarm();
105 		display_redraw();
106 		unblockalarm();
107 
108 		switch (sgetch("~ ", (struct ship *)0, 0)) {
109 		case 14: /* ^N */
110 			display_scroll_pagedown();
111 			break;
112 		case 16: /* ^P */
113 			display_scroll_pageup();
114 			break;
115 		case 'm':
116 			acceptmove();
117 			break;
118 		case 's':
119 			acceptsignal();
120 			break;
121 		case 'g':
122 			grapungrap();
123 			break;
124 		case 'u':
125 			unfoulplayer();
126 			break;
127 		case 'v':
128 			Msg("%s", version);
129 			break;
130 		case 'b':
131 			acceptboard();
132 			break;
133 		case 'f':
134 			acceptcombat();
135 			break;
136 		case 'l':
137 			loadplayer();
138 			break;
139 		case 'c':
140 			changesail();
141 			break;
142 		case 'r':
143 			repair();
144 			break;
145 		case 'B':
146 			Msg("'Hands to stations!'");
147 			unboard(ms, ms, 1);	/* cancel DBP's */
148 			unboard(ms, ms, 0);	/* cancel offense */
149 			break;
150 		case '\f':
151 			centerview();
152 			display_force_full_redraw();
153 			break;
154 		case 'L':
155 			mf->loadL = L_EMPTY;
156 			mf->loadR = L_EMPTY;
157 			mf->readyL = R_EMPTY;
158 			mf->readyR = R_EMPTY;
159 			Msg("Broadsides unloaded");
160 			break;
161 		case 'q':
162 			Msg("Type 'Q' to quit");
163 			break;
164 		case 'Q':
165 			leave(LEAVE_QUIT);
166 			break;
167 		case 'I':
168 			foreachship(sp)
169 				if (sp != ms)
170 					eyeball(sp);
171 			break;
172 		case 'i':
173 			if ((sp = closestenemy(ms, 0, 1)) == 0)
174 				Msg("No more ships left.");
175 			else
176 				eyeball(sp);
177 			break;
178 		case 'C':
179 			centerview();
180 			break;
181 		case 'U':
182 			upview();
183 			break;
184 		case 'D':
185 		case 'N':
186 			downview();
187 			break;
188 		case 'H':
189 			leftview();
190 			break;
191 		case 'J':
192 			rightview();
193 			break;
194 		case 'F':
195 			lookout();
196 			break;
197 		case 'S':
198 			dont_adjust = !dont_adjust;
199 			break;
200 		}
201 	}
202 }
203